uses
  'UfebsConst';

function ARM_KBR(Xml, Ufebs: Variant; FEDAuthor: String; FEDDate: TDateTime): String;
begin
  Result := FEDAuthor + FormatDateTime('yyyymmdd', FEDDate) +
    IntToStr(Ufebs.EDNo) + '.dat';
end; {End ARM_KBR}

function ARM_KBR_XML(Xml, Ufebs: Variant; FEDAuthor: String; FEDDate: TDateTime): String;
begin
  Result := FEDAuthor + FormatDateTime('yyyymmdd', FEDDate) +
    IntToStr(Ufebs.EDNo) + '.xml';
end; {End ARM_KBR_XML}

function TPK_RABIS(Xml, Ufebs: Variant; FEDAuthor: String; FEDDate: TDateTime): String;
var
  FileName: String;
  FileNumber: Integer;
begin
  FileName := ExtractFilePath(Xml.documentElement.getAttribute('INI_FILE')) + 'TPK_RABIS.NNN';
  with TStringList.Create do
  try
    if FileExists(FileName) then
      LoadFromFile(FileName);
    if IndexOfName(FormatDateTime('yyyy-mm-dd', FEDDate)) < 0 then
      FileNumber := 1
    else
      FileNumber := StrToInt(Values[FormatDateTime('yyyy-mm-dd', FEDDate)]) + 1;
    Values[FormatDateTime('yyyy-mm-dd', FEDDate)] := IntToStr(FileNumber);
    Result := 'i' + FormatDateTime('dd', FEDDate) + Copy(FEDAuthor, 3, 2) +
      Copy(FEDAuthor, 8, 3) + '.' + IntToSS(FileNumber, 36, 3);
    SaveToFile(FileName);
  finally
    Free;
  end;
end; {End TPK_RABIS}

function DDMPPEDK(Xml, Ufebs: Variant; FEDAuthor: String; FEDDate: TDateTime): String;
var
  i: Integer;
  FileName: String;
  FileNumber: Integer;
  Nodes: Variant;
begin
  Result := FormatDateTime('dd', FEDDate) + IntToSS(StrToInt(
    FormatDateTime('mm', FEDDate)), 16, 1);
  with Xml.documentElement do
  begin
    FileName := ExtractFilePath(getAttribute('INI_FILE')) + 'DDMPPEDK.XXX';
    with TStringList.Create do
    try
      if FileExists(FileName) then
        LoadFromFile(FileName);
      if IndexOfName(FormatDateTime('yyyy-mm-dd', FEDDate)) < 0 then
        FileNumber := 1
      else
        FileNumber := StrToInt(Values[FormatDateTime('yyyy-mm-dd', FEDDate)]) + 1;
      Values[FormatDateTime('yyyy-mm-dd', FEDDate)] := IntToStr(FileNumber);
      Result := Result + Format('%0.2d%', [FileNumber]);
      SaveToFile(FileName);
    finally
      Free;
    end;

    if UpperCase(ChangeFileExt(ExtractFileName(
      getAttribute('INI_FILE')), '')) = 'UFEBSED210' then
      Result := Result + '00j.'
    else
      Result := Result + 'edk.';
  end;
  with Xml.documentElement, TStringList.Create do
  try
    with CreateOleObject('Microsoft.XmlDom') do
    begin
      if not Load(ExtractFilePath(Xml.documentElement.getAttribute('INI_FILE')) + 'UfebsUnload.cfg') then
        raise('Ошибка при зачитывании файла конфигурации выгрузки');
      Nodes := documentElement.childNodes;
    end;

    for i := 0 to Nodes.length - 1 do
      Add(Nodes.item[i].attributes.getNamedItem('name').nodeValue +
        '=' + Nodes.item[i].attributes.getNamedItem('value').nodeValue);

    Result := Result + Copy(Trim(Values['Идентификатор составителя']), 8, 3);
  finally
    Free;
  end;
end; {End DDMPPEDK}

function TPK_YOC_RABIS2(Xml, Ufebs: Variant; FEDAuthor: String; FEDDate: TDateTime): String;
var
  FileName: String;
  FileNumber: Integer;
begin
  FileName := ExtractFilePath(Xml.documentElement.getAttribute('INI_FILE')) + 'TPK_YOC_RABIS2.NNN';
  with TStringList.Create do
  try
    if FileExists(FileName) then
      LoadFromFile(FileName);
    if IndexOfName(FormatDateTime('yyyy-mm-dd', FEDDate)) < 0 then
      FileNumber := 1
    else
      FileNumber := StrToInt(Values[FormatDateTime('yyyy-mm-dd', FEDDate)]) + 1;
    Values[FormatDateTime('yyyy-mm-dd', FEDDate)] := IntToStr(FileNumber);
    //Exchange #2229
    case Ufebs.EDType of
      edtED101, edtED102, edtED103, edtED104, edtED105, edtPacketEPD:
        Result := 'A2';
      edtED211: Result := 'U2';
      edtED221: Result := 'V2';
    else
      Result := 'B2';
    end;
    Result := Result +
      IntToSS(StrToInt(FormatDateTime('dd', FEDDate)), 32, 1) +
      IntToSS(FileNumber, 36, 2) + Copy(FEDAuthor, 1, 2) +
      Copy(IntToSS(StrToInt(Copy(FEDAuthor, 8, 3)), 36, 2), 1, 1) + '.' +
      Copy(IntToSS(StrToInt(Copy(FEDAuthor, 8, 3)), 36, 2), 2, 1) +
      IntToSS(StrToInt('0' + Copy(FEDAuthor, 3, 2)), 36, 2);
    SaveToFile(FileName);
  finally
    Free;
  end;
end; {End TPK_YOC_RABIS2}

begin
end.