const
  FFileName = 'C:\Temp\ExportExpInSrcChange.xml';
  cFileVer = '1.0';

var
  FAzkIsLogin, FDebuger, FlagLim, FlagAss: Boolean;
  DocumentClass_Id: Integer;
  FileGuid, IniPath, {FileLog, FileInfo, }FileOut, Key, Str: String;
  Xml, Data, Head, Line: Variant;
  ProgressBar: TProgressBar;
  Form, FmExp, FmIn, FmSrc: TFormCustom;
  FmRecipient, FmDirection, FmReceiver, FmCounteragent, FmOperType,
    FmAssignSource: TFormCustomList;
  FmTerritory: TFormCustomTree;
  FmKadmd, FmKadmi: TFormKbk;
  FmEstimate: TFormCustomTree;
  edtDir, edtEstimate, edtRecipient, edtDirection,
  edtTerritory, edtReceiver, edtKadmd, edtCounteragent, edtKadmi,
    edtOperType, edtAssignSource: TEdit;
  cmbForm: TComboBox;
  dtmBeginDate, dtmEndDate: TDateTimeEh;
  chkRepeat: TCheckBox;

procedure FillHeadFile;
var
  Xml: Variant;
begin
  Data.setAttribute('FINYEAR', Budget_Year);
  Data.setAttribute('DOCUMENTCLASS', DocumentClass_Id);
  Data.setAttribute('FILEDATE', FormatDateTime('yyyy-mm-dd', Now));
  Data.setAttribute('FILEVER', cFileVer);
  Data.setAttribute('FILEGUID', FileGuid);
  Data.setAttribute('DATE1', FormatDateTime('dd.mm.yyyy', dtmBeginDate.Date));
  Data.setAttribute('DATE2', FormatDateTime('dd.mm.yyyy', dtmEndDate.Date));
  Sql := 'Select B.Period, B.Territory_Id, T.Caption' +
    ' From Budget B' +
    ' Join Territory T On T.Id = B.Territory_Id' +
    ' Where B.Id = ?';
  Xml := QueryXml(Sql, [Budget_Id]);
  if Xml.documentElement.childNodes.length <> 0 then
  begin
    Xml := Xml.documentElement.childNodes.items[0];
    Data.setAttribute('TERRITORY_ID', Xml.getAttribute('TERRITORY_ID'));
    Data.setAttribute('CAPTION', Xml.getAttribute('CAPTION'));
    Data.setAttribute('PERIOD', Xml.getAttribute('PERIOD'));
  end;
end;

procedure getFlagAssLim(Node: Variant);
var
  Xml: Variant;
begin

  Xml := CreateOleObject('Microsoft.XmlDom');
  Xml := Xml.appendChild(Xml.createElement('BUDGETLINE'));
  Xml.setAttribute('action', 'check_bring_lim_ass');
  Xml.setAttribute('ESTIMATE_ID', Node.getAttribute('EST_ID'));
  Xml.setAttribute('RECIPIENT_ID', Node.getAttribute('RECIPIENT_ID'));
  Xml.setAttribute('KFSR_CODE', Node.getAttribute('KFSR_CODE'));
  Xml.setAttribute('KCSR_CODE', Node.getAttribute('KCSR_CODE'));
  Xml.setAttribute('KVR_CODE', Node.getAttribute('KVR_CODE'));
  Xml.setAttribute('KESR_CODE', Node.getAttribute('KESR_CODE'));
  Xml.setAttribute('KADMR_CODE', Node.getAttribute('KADMR_CODE'));
  Xml.setAttribute('KDF_CODE', Node.getAttribute('KDF_CODE'));
  Xml.setAttribute('KDE_CODE', Node.getAttribute('KDE_CODE'));
  Xml.setAttribute('KDR_CODE', Node.getAttribute('KDR_CODE'));
  Xml.setAttribute('FSR_ID',  Node.getAttribute('FSR_ID'));

  // exchange #2389
  // для версии АЦК-финансы 2.29.0.80 обязательно требуется передавать код цели
  // без этого возникает сбой!
  Xml.setAttribute( 'PURPOSEFULGRANT_ID',
                    VarTostr( Node.getAttribute('PURPOSEFULGRANT_ID')));

  Xml := Xml.ownerDocument;
  Xml.loadXml(ExecXml(Xml.xml));
  FlagLim := (Xml.documentElement.getAttribute('result') and 1) > 0;
  FlagAss := (Xml.documentElement.getAttribute('result') and 2) > 0;

end; {End getFlagAssLim}

procedure UpdateExtFlag(Name: String; Nodes: Variant);
var
  i: Integer;
begin
  Form.SimpleText := 'Изменение статуса строк у документов ...';
  with TStringList.create do
  try
    for i := 0 to Nodes.length - 1 do
    begin
      Add(Nodes.item[i].getAttribute('ID'));
      Nodes.item[i].removeAttribute('ID');
      if Count = 500 then
      begin
        ExecProc(Name, ['action', 'update_extflag',
          'VALUE', 1, 'ID_LIST', CommaText], Budget_Id);
        Clear;
      end;
    end;
    if Count > 0 then
      ExecProc(Name, ['action', 'update_extflag',
        'VALUE', 1, 'ID_LIST', CommaText], Budget_Id);
  finally
    Free;
    Form.SimpleText := '';
  end;
end; {End UpdateExtFlag}

begin
end.
