Monday, 31 August 2015

Requisition Lines to Gen Journal Post

OBJECT Codeunit 37001021 GLTranManagement
{
  OBJECT-PROPERTIES
  {
    Date=08/20/15;
    Time=[ 8:36:13 AM];
    Modified=Yes;
    Version List=SER7.00;
  }
  PROPERTIES
  {
    Permissions=TableData 37001008=rimd;
    OnRun=BEGIN
          END;

  }
  CODE
  {
    VAR
      GLSetup@1102602029 : Record 98;
      SalesSetup@1102602003 : Record 311;
      PurchSetup@1102602034 : Record 312;
      InvenSetup@1102602045 : Record 313;
      PayrollSetup@1102602066 : Record 37032335;
      AVSetup@1102633003 : Record 37055303;
      GLAccount@1102602037 : Record 15;
      BusinessRuleHeader@1102602036 : Record 37001000;
      GLDimensions@1102602035 : Record 37001026;
      SourceCodeSetup@1102602032 : Record 242;
      SourceCodes@1102602031 : Record 230;
      PayrollPostingGroup@1102602067 : Record 37032322;
      Fund@1102602021 : Record 37001020;
      AllocationManagement@1102602025 : Codeunit 37001040;
      WorkflowManagement@1102602001 : Codeunit 37001100;
      FundManagement@1102602002 : Codeunit 37001020;
      NavigatorManagement@1102602038 : Codeunit 37001022;
      LDBManagement@1102602049 : Codeunit 37001019;
      GenJnlPostLine@1102602020 : Codeunit 12;
      ItemJnlPostLine@1102602019 : Codeunit 22;
      NoSeriesMgt@1102602018 : Codeunit 396;
      xferCustomFields@1102602017 : Codeunit 37001030;
      ArchiveManagement@1102602022 : Codeunit 5063;
      DimMgt@1102602013 : Codeunit 408;
      GetFAAccountNo@1102602030 : Codeunit 5602;
      MakeFALedgerEntry@1102602028 : Codeunit 5604;
      DLManagement@1102634000 : Codeunit 37086500;
      InvestmentManagement@1102602048 : Codeunit 37086600;
      ExchAccGLJnlLine@1102633002 : Codeunit 366;
      Window@1102602000 : Dialog;
      LineNo@1102602023 : Integer;
      SNText01@1102602016 : TextConst 'ENU=There are no purchase review documents to process.  Please select the appropriate Decision and enter Target No. to process documents.;FRA=Il n''y a pas de documents de r‚vision des achats … traiter..  Veuillez s‚lectionner la ®ÿD‚cisionÿ¯ appropri‚e et saisir le Nø cible pour traiter les documents.;ESM=No hay documentos de revisi¢n de compras que procesar. Seleccione la decisi¢n apropiada y capture el n£m. de objetivo para procesar los documentos.;ENC=There are no purchase review documents to process.  Please select the appropriate Decision and enter Target No. to process documents.';
      SNText02@1102602015 : TextConst 'ENU=No line were eligible for posting encumbrances - check line statuses.;FRA=Aucune ligne ne permet la comptabilisation des charges- v‚rifier les statuts de ligne.;ESM=No hubo l¡neas seleccionadas para contabilizar grav menes Æ verificar los estatus de las l¡neas.;ENC=No line were eligible for posting encumbrances - check line statuses.';
      SNText03@1102602014 : TextConst 'ENU=The Purchase Order %1 you are appending to does not exist.;FRA=La commande %1 que vous joigniez n''existe pas.;ESM=El orden de compra %1 a la que anexa no existe.;ENC=The Purchase Order %1 you are appending to does not exist.';
      SNText04@1102602042 : TextConst 'ENU=You cannot cancel a %1 purchase line.;FRA=Vous ne pouvez pas annuler une ligne d''achat %1.;ESM=No puede cancelar una compra en l¡nea %1.;ENC=You cannot cancel a %1 purchase line.';
      SNText05@1102602012 : TextConst 'ENU=Advanced Budgeting is not licensed or activated in Source Codes.;FRA="Pas de licence ou d''activation dans les codes source pour le ®ÿBudget avanc‚ÿ¯ ";ESM=El presupuesto avanzado no tiene autorizaci¢n ni activaci¢n de C¢digos de fuentes.;ENC=Advanced Budgeting is not licensed or activated in Source Codes.';
      SNText06@1102602011 : TextConst 'ENU=You cannot cancel a submitted for approval purchase line, Document %1 Line %2.;FRA=Vous ne pouvez pas annuler une ligne d''achat envoy‚e pour approbation, Document %1 ligne %2.;ESM=No puede cancelar una l¡nea de compra sometida a aprobaci¢n, Documento %1 L¡nea %2.;ENC=You cannot cancel a submitted for approval purchase line, Document %1 Line %2.';
      SNText07@1102602010 : TextConst 'ENU=Reversed Requisition Fulfillment & Canceled line, Document %1 Line %2.;FRA=R‚alisation de demande invers‚e et ligne annul‚e, document %1, ligne %2.;ESM=Realizaci¢n de requisici¢n revertida y l¡nea cancelada, Documento %1 L¡nea %2.;ENC=Reversed Requisition Fulfillment & Canceled line, Document %1 Line %2.';
      SNText08@1102602009 : TextConst 'ENU=Use Delete instead of Cancel Line for purchase line, Document %1 Line %2.;FRA=Utiliser ®ÿSupprimerÿ¯ plut“t que ®ÿAnnuler la ligneÿ¯ pour une ligne d''achat, document %1 , ligne %2.;ESM=Usar eliminar en lugar de cancelar l¡nea para la l¡nea de compra, documento %1 l¡nea %2.;ENC=Use Delete instead of Cancel Line for purchase line, Document %1 Line %2.';
      SNText09@1102602008 : TextConst 'ENU=You cannot cancel a new purchase line, Document %1 Line %2 - Delete Line instead.;FRA=Vous ne pouvez pas annuler une nouvelle ligne d''achat, Document %1 ligne %2 - supprimez plut“t cette ligne.;ESM=No puede cancelar una nueva l¡nea de compra, Documento %1 L¡nea %2 Æ Suprima la l¡nea.;ENC=You cannot cancel a new purchase line, Document %1 Line %2 - Delete Line instead.';
      SNText10@1102602007 : TextConst 'ENU=Commitment Posting is not activated.;FRA=La comptabilisation des engagements n''est pas activ‚e.;ESM=Registro de compromiso no est  activado.;ENC=Commitment Posting is not activated.';
      SNText11@1102602006 : TextConst 'ENU=Encumbrance Posting is not activated.;FRA=La validation des charges n''est pas activ‚e.;ESM=No est  activado el registro del gravamen.;ENC=Encumbrance Posting is not activated.';
      SNText12@1102602005 : TextConst 'ENU=There are no lines with status New and an Amount to check.;FRA=Il n''y a pas de lignes avec le statut ®ÿNouveauÿ¯ et un montant … v‚rifier.;ESM=No hay l¡neas con estatus nuevo ni una cantidad que revisar.;ENC=There are no lines with status New and an Amount to check.';
      SNText13@1102602004 : TextConst 'ENU=Nothing to Submit.;FRA=Rien … envoyer.;ESM=Nada por enviar.;ENC=Nothing to Submit.';
      SNText14@1102602027 : TextConst 'ENU=Requisition %1 has submitted lines - cannot be deleted.;FRA=La demande %1 a des lignes envoy‚es - ne peuvent pas ˆtre supprim‚es.;ESM=La requisici¢n %1 tiene l¡neas enviadas- no se puede borrar.;ENC=Requisition %1 has submitted lines - cannot be deleted.';
      SNText15@1102602026 : TextConst 'ENU=There is nothing to cancel for Line %1.  Delete line instead.;FRA=Il n''y a rien … annuler sur la ligne %1. Supprimez plut“t la ligne.;ESM=No hay nada que cancelar de la l¡nea %1. Elimine la l¡nea.;ENC=There is nothing to cancel for Line %1.  Delete line instead.';
      SNText16@1102602024 : TextConst 'ENU=You cannot cancel a Requisition %1 Line %2 that is %3.;FRA=Vous ne pouvez pas annuler une demande %1 ligne %2 qui soit %3.;ESM=No puede cancelar una Requisici¢n %1 L¡nea %2 que es %3.;ENC=You cannot cancel a Requisition %1 Line %2 that is %3.';
      SNText17@1102602039 : TextConst 'ENU=You cannot cancel a Deposit %1 Line %2 that is %3.;FRA=Vous ne pouvez pas annuler un d‚p“t %1 ligne %2 qui soit %3.;ESM=No puede cancelar una L¡nea %2 de un Dep¢sito %1 que es %3.;ENC=You cannot cancel a Deposit %1 Line %2 that is %3.';
      SNText18@1102602040 : TextConst 'ENU=There are no lines to check.;FRA=Il n''y a pas de lignes … v‚rifier.;ESM=No hay l¡neas que revisar.;ENC=There are no lines to check.';
      SNText19@1102602041 : TextConst 'ENU=There are no lines to cancel.;FRA=Il n''y a pas de lignes … annuler.;ESM=No hay l¡neas que cancelar.;ENC=There are no lines to cancel.';
      SNText20@1102602043 : TextConst 'ENU=There are outstanding Orders that must be fully Invoiced or Canceled first.;FRA=Il y a des commandes en suspens qui doivent ˆtre d''abord totalement factur‚es ou annul‚es.;ESM=Hay ¢rdenes pendientes que primero se deben facturar o cancelar en su totalidad.;ENC=There are outstanding Orders that must be fully Invoiced or Canceled first.';
      SNText21@1102602044 : TextConst 'ENU=Should Blanket Order %1, Line No. %2 be re-encumbered?;FRA=La commande ouverte %1, ligne Nø %2, devrait-elle ˆtre re-grev‚eÿ?;ESM=¨Se debe gravar de nuevo la orden abierta %1, l¡nea n£m. %2?;ENC=Should Blanket Order %1, Line No. %2 be re-encumbered?';
      SNText22@1102602047 : TextConst 'ENU="Blanket Order Status %1 is not valid ";FRA=L''‚tat de la commande ouverte %1 n''est pas valide;ESM=El estado de la orden abierta %1 no es v lida;ENC=Blanket Order Status %1 is not valid';
      SNText23@1102602061 : TextConst 'ENU=The line has been submitted for approval.  Confirm cancellation?;FRA=La ligne a ‚t‚ envoy‚e pour approbation.  Confirmer l''annulationÿ?;ESM=La l¡nea fue presentada para su aprobaci¢n. ¨Confirma la cancelaci¢n?;ENC=The line has been submitted for approval.  Confirm cancellation?';
      SNText24@1102602062 : TextConst 'ENU=Cancel Line has been stopped.  Document %1 Line %2.;FRA=L''annulation de ligne a ‚t‚ stopp‚..  Document %1 ligne %2.;ESM=Se detuvo Cancelar l¡nea. Documento %1 l¡nea %2.;ENC=Cancel Line has been stopped.  Document %1 Line %2.';
      SNText25@1102602046 : TextConst 'ENU="Posting is not allowed for proposed Vendors.  Vendor No.=%1.";FRA="Comptabilisation non autoris‚e pour les vendeurs propos‚s.  Vendeur Nø = %1.";ESM="No se permite la contabilizaci¢n de proveedores propuestos.  Proveedor n£m.=%1.";ENC="Posting is not allowed for proposed Vendors.  Vendor No.=%1."';
      SNText26@1102602063 : TextConst 'ENU="Processing is not allowed for proposed Vendors.  Vendor No.=%1.";FRA="Le traitement n''est pas autoris‚ pour les vendeurs propos‚s.  Vendeur Nø = %1.";ESM="No se permite el procesamiento de los proveedores propuestos.  Proveedor n£m.=%1.";ENC="Processing is not allowed for proposed Vendors.  Vendor No.=%1."';
      SNText27@1102602064 : TextConst 'ENU=No lines were eligible for posting commitments - check line statuses.;FRA=Aucune ligne ne permet la comptabilisation des engagements - v‚rifier les statuts de ligne.;ESM=No hubo l¡neas seleccionadas para contabilizar compromisos Æ verificar los estatus de las l¡neas.;ENC=No lines were eligible for posting commitments - check line statuses.';
      SNText28@1102602065 : TextConst 'ENU="Purchase tolerance check failed.  Document No.=%1, Line No.=%2.";FRA="La v‚rification de la tol‚rance d''achat a ‚chou‚.  Document Nø = %1, ligne Nø = %2.";ESM="La revisi¢n de la tolerancia de compra fall¢. Documento n£m.=%1, L¡nea n£m.=%2.";ENC="Purchase tolerance check failed.  Document No.=%1, Line No.=%2."';
      SNText29@1102602068 : TextConst 'ENU=Reclassification not permitted for document %1, line %2.;FRA=Reclassification interdite pour le document %1, ligne %2.;ESM=Reclasificaci¢n no permitida para este documento %1, l¡nea %2.;ENC=Reclassification not permitted for document %1, line %2.';
      SNText30@1102602074 : TextConst 'ENU=Status must be Approval Pending, Transfer Budget Pending or Disapproved.;FRA=Le statut doit ˆtre ®ÿEn attente d''approbationÿ¯, ®ÿEn attente de virement budg‚taireÿ¯ ou ®ÿD‚sapprouv‚ÿ¯;ESM=El estatus debe ser Pendiente de aprobaci¢n, pendiente de transferencia presupuestaria o desaprobado(a).;ENC=Status must be Approval Pending, Transfer Budget Pending or Disapproved.';
      SNText31@1102602076 : TextConst 'ENU=There are no lines to reset.;FRA=Il n''y a pas de lignes … r‚initialiser.;ESM=No hay l¡neas que reprogramar.;ENC=There are no lines to reset.';
      SNText32@1102602052 : TextConst 'ENU=You cannot cancel a new sales line, Document %1 Line %2 - Delete Line instead.;FRA=Vous ne pouvez pas annuler une nouvelle ligne de ventes, Document %1 ligne %2 - supprimez plut“t cette ligne.;ESM=No puede cancelar una nueva l¡nea de venta, Documento %1 L¡nea %2 - Suprima la l¡nea.;ENC=You cannot cancel a new sales line, Document %1 Line %2 - Delete Line instead.';
      SNText33@1102602050 : TextConst 'ENU=You cannot cancel a %1 sales line.;FRA=Vous ne pouvez pas annuler une ligne de ventes %1.;ESM=No puede cancelar una l¡nea de ventas %1.;ENC=You cannot cancel a %1 sales line.';
      SNText34@1102602053 : TextConst 'ENU=There are %1 failed validations.  Preview Distributions to resolve.;FRA=Il y a eu %1 validations en ‚chec.  Pr‚visualiser les distributions … r‚soudre.;ESM=Hay %1 validaciones fallidas. Previsualice Distribuciones por resolver.;ENC=There are %1 failed validations.  Preview Distributions to resolve.';
      SNText36@1102628003 : TextConst 'ENU=The document has been submitted for approval.  Confirm cancellation?;ENC=The document has been submitted for approval.  Confirm cancellation?';
      SNText37@1102628002 : TextConst 'ENU=Cancel Document has been stopped.  %1 %2.;ENC=Cancel Document has been stopped.  %1 %2.';
      SNText38@1102628001 : TextConst 'ENU=You cannot reset document a %1 %2 that is %3 %4.;ENC="There is nothing to cancel for %1 %2. "';
      SNText39@1102628000 : TextConst 'ENU=You cannot cancel a %1 %2 that is %3 %4.;ENC=You cannot cancel a Requisition %1 Line %2 that is %3.';
      CommitmentDescription@1102602069 : TextConst 'ENU=Reserve for Commitments;FRA=R‚server pour les engagements;ESM=Reserva para obligaciones;ENC=Reserve for Commitments';
      EncumbranceDescription@1102602070 : TextConst 'ENU=Reserve for Encumbrances;FRA=R‚serve pour les charges;ESM=Reserva para grav menes;ENC=Reserve for Encumbrances';
      BatchValidationProcessing@1102602051 : Boolean;
      ConversionDescription@1102633000 : TextConst 'ENU=Conversion of  %1 to %2.;FRA=Conversion de  %1 en %2.;ESM=Conversi¢n de %1 a %2.;ENC=Conversion of  %1 to %2.';
      Workflow@1000000000 : Record 37001100;

    PROCEDURE GenerateDistBuffer@1102602000(VAR GenJnlLine@1102602000 : TEMPORARY Record 81);
    BEGIN
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);
    END;

    PROCEDURE GenerateDistBufferTemp@1102633000(VAR GenJnlLine@1102602000 : TEMPORARY Record 81;VAR TempLineDistBuffer@1102628000 : TEMPORARY Record 37001008);
    VAR
      GenJnlLine2@1102633000 : TEMPORARY Record 81;
    BEGIN
      IF ProcessPRININTPAYTrxTemp(GenJnlLine, TempLineDistBuffer) THEN
        EXIT;

      GenJnlLine2 := GenJnlLine;
      IF (GenJnlLine2."Account Type" = GenJnlLine2."Account Type"::"G/L Account") AND
         (GenJnlLine2."Bal. Account Type" = GenJnlLine2."Bal. Account Type"::"G/L Account") THEN BEGIN
        GenJnlLine2."Bal. Account No." := '';
      END;
      LDBManagement.GenerateDistBufferTemp(GenJnlLine2,TempLineDistBuffer);
      GenJnlLine."Ctl. Fund No." := GenJnlLine2."Ctl. Fund No.";
    END;

    PROCEDURE DeleteLineDistributionBuffer@1102602016(InternalControlNo@1102602000 : Code[50]);
    VAR
      LineDistributionBuffer@1102602001 : Record 37001008;
      ValidationBuffer@1102602002 : Record 37001007;
    BEGIN
      IF InternalControlNo = '' THEN EXIT;
      LDBManagement.DeleteLineDistributionBuffer(InternalControlNo);
    END;

    PROCEDURE GenerateICN@1102602049() ICN : Code[50];
    VAR
      DateText@1102602004 : Text;
      TimeText@1102602003 : Text;
      TempTime@1102602002 : Time;
      NewTime@1102602001 : Time;
    BEGIN
      TempTime := TIME;
      REPEAT
        NewTime := TIME
      UNTIL NewTime <> TempTime;

      DateText := FORMAT(TODAY,6,'<Year,2><Month,2><Day,2>');
      TimeText := FORMAT(TIME,11,'<Hours24,2><Filler Character,0><Minutes,2><Seconds,2><Second dec.>');

      ICN := DELCHR(DateText+TimeText,'=',' .');
      ICN := COPYSTR(USERID,1,MAXSTRLEN(ICN) - STRLEN(ICN)) + ICN;
      EXIT(ICN);
    END;

    PROCEDURE GenDistBufferSalesLine@1102602070(SalesLine@1102602000 : Record 37);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
      GenPostSetup@1102602002 : Record 252;
      SalesHeader@1102633000 : Record 36;
    BEGIN
      DeleteLineDistributionBuffer(SalesLine."Internal Control No.");
      IF (SalesLine.Type = SalesLine.Type::" ") OR
         (SalesLine."No." = '') OR
         (SalesLine."Document Type" = SalesLine."Document Type"::Quote) OR
         (SalesLine.Status >= SalesLine.Status::Disapproved) THEN
        EXIT;

      LDBManagement.LDBSalesLineTOGenJnlLine(GenJnlLine,SalesLine);
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);

      IF SalesLine."Line Discount Amount" <> 0 THEN BEGIN
        SalesSetup.GET;
        IF SalesSetup."Discount Posting" IN [SalesSetup."Discount Posting"::"Line Discounts",
                                             SalesSetup."Discount Posting"::"All Discounts"] THEN BEGIN
          SalesLine.TESTFIELD("Gen. Prod. Posting Group");
          IF GenPostSetup.GET(SalesLine."Gen. Bus. Posting Group",SalesLine."Gen. Prod. Posting Group") THEN BEGIN
            IF GenPostSetup."Sales Line Disc. Account" <> '' THEN BEGIN
              GenJnlLine."Account No." := GenPostSetup."Sales Line Disc. Account";
              SalesHeader.GET(SalesLine."Document Type",SalesLine."Document No.");
              IF SalesHeader."Prices Including VAT" AND (SalesLine."VAT %" <> 0) THEN
                GenJnlLine.VALIDATE(Amount,SalesLine."Line Discount Amount" / (1 + SalesLine."VAT %" / 100))
              ELSE
                GenJnlLine.VALIDATE(Amount,SalesLine."Line Discount Amount");
              LDBManagement.GenerateDistBuffer(GenJnlLine,TRUE,20000,BatchValidationProcessing);
            END;
          END;
        END;
      END;
    END;

    PROCEDURE GenDistBufferPurchaseLine@1102602032(PurchaseLine@1102602000 : Record 39);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
      GenPostSetup@1102602002 : Record 252;
      PurchaseHeader@1102633000 : Record 38;
    BEGIN
      DeleteLineDistributionBuffer(PurchaseLine."Internal Control No.");
      IF (PurchaseLine.Type = PurchaseLine.Type::" ") OR
         (PurchaseLine."No." = '') OR
         (PurchaseLine."Document Type" = PurchaseLine."Document Type"::Quote) OR
         (PurchaseLine.Status >= PurchaseLine.Status::Disapproved) THEN
        EXIT;

      LDBManagement.LDBPurchaseLineTOGenJnlLine(GenJnlLine,PurchaseLine);
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);

      IF PurchaseLine."Line Discount Amount" <> 0 THEN BEGIN
        PurchSetup.GET;
        IF PurchSetup."Discount Posting" IN [PurchSetup."Discount Posting"::"Line Discounts",
                                             PurchSetup."Discount Posting"::"All Discounts"] THEN BEGIN
          PurchaseLine.TESTFIELD("Gen. Prod. Posting Group");
          IF GenPostSetup.GET(PurchaseLine."Gen. Bus. Posting Group",PurchaseLine."Gen. Prod. Posting Group") THEN BEGIN
            IF GenPostSetup."Purch. Line Disc. Account" <> '' THEN BEGIN
              GenJnlLine."Account No." := GenPostSetup."Purch. Line Disc. Account";
              PurchaseHeader.GET(PurchaseLine."Document Type",PurchaseLine."Document No.");
              IF PurchaseHeader."Prices Including VAT" AND (PurchaseLine."VAT %" <> 0) THEN
                GenJnlLine.VALIDATE(Amount,-PurchaseLine."Line Discount Amount" / (1 + PurchaseLine."VAT %" / 100))
              ELSE
                GenJnlLine.VALIDATE(Amount,-PurchaseLine."Line Discount Amount");
              LDBManagement.GenerateDistBuffer(GenJnlLine,TRUE,20000,BatchValidationProcessing);
            END;
          END;
        END;
      END;
    END;

    PROCEDURE GenDistBufferRequisitionLine@1102602035(RequisitionLine@1102602000 : Record 37001091);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
    BEGIN
      DeleteLineDistributionBuffer(RequisitionLine."Internal Control No.");
      IF (RequisitionLine.Type = RequisitionLine.Type::" ") OR
         (RequisitionLine."No." = '') OR
         (RequisitionLine.Status >= RequisitionLine.Status::Disapproved) THEN
        EXIT;

      LDBManagement.LDBRequisitionLineTOGenJnlLine(GenJnlLine,RequisitionLine);
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);
    END;

    PROCEDURE GenDistBufferGenJnlLine@1102602038(FromGenJnlLine@1102602000 : Record 81);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
    BEGIN
      DeleteLineDistributionBuffer(FromGenJnlLine."Internal Control No.");
      IF FromGenJnlLine."Account No." = '' THEN
        EXIT;

      IF ProcessPRININTPAYTrx(FromGenJnlLine) THEN
        EXIT;

      LDBManagement.LDBGenJnlLineTOGenJnlLine(GenJnlLine,FromGenJnlLine);
      WITH GenJnlLine DO
        IF ("Account Type" IN ["Account Type"::Customer,"Account Type"::Vendor,"Account Type"::"Bank Account"]) AND
           ("Account No." <> '') AND
           ("Bal. Account Type" IN ["Bal. Account Type"::"G/L Account"]) AND
           ("Bal. Account No." <> '') AND
           ("Journal Template Name" <> '') AND ("Journal Batch Name" <> '') THEN BEGIN
          ExchAccGLJnlLine.RUN(GenJnlLine);
        END;
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);
    END;

    PROCEDURE GenDistBufferGenJnlAllocLine@1102602004(GenJnlAllocation@1102602000 : Record 221);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
    BEGIN
      DeleteLineDistributionBuffer(GenJnlAllocation."Internal Control No.");
      IF (GenJnlAllocation."Account No." = '') OR (GenJnlAllocation.Amount = 0) THEN
        EXIT;

      LDBManagement.LDBGenJnlAllocTOGenJnlLine(GenJnlLine,GenJnlAllocation);
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);
    END;

    PROCEDURE GenDistBufferItemJnlLine@1102602039(ItemJnlLine@1102602000 : Record 83);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
    BEGIN
      DeleteLineDistributionBuffer(ItemJnlLine."Internal Control No.");
      IF (ItemJnlLine."Item No." = '') OR
         (ItemJnlLine."Entry Type" >= ItemJnlLine."Entry Type"::Transfer) THEN
        EXIT;

      LDBManagement.LDBItemJnlLineTOGenJnlLine(GenJnlLine,ItemJnlLine);
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);
    END;

    PROCEDURE "//------------------------------TBL Amos 19/01/15-------------------------------------------------------------------------------"@1000000004();
    BEGIN
    END;

    PROCEDURE GenDistBufferFAJnlLine@1000000003(FAJnlLine@1102602000 : Record 5621);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
    BEGIN
      DeleteLineDistributionBuffer(FAJnlLine."Internal Control No.");
      IF (FAJnlLine."FA No." = '') THEN
        EXIT;

      LDBManagement.LDBFAJnlLineTOGenJnlLine(GenJnlLine,FAJnlLine);
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);
    END;

    PROCEDURE "//------------------------------TBL Amos 19/01/15 End---------------------------------------------------------------------------"@1000000005();
    BEGIN
    END;

    PROCEDURE GenDistBufferPayrollJnlLine@1102602014(PayrollJnlLine@1102602000 : Record 37032302);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
      PayrollJnlLinePost@1102633001 : Codeunit 37032302;
    BEGIN
      DeleteLineDistributionBuffer(PayrollJnlLine."Internal Control No.");
      IF (PayrollJnlLine."Employee No." = '') OR
         (PayrollJnlLine."G/L Post Type" = PayrollJnlLine."G/L Post Type"::"Do not post to G/L") OR
         ((PayrollJnlLine."Payroll Amount" = 0) AND
          (PayrollJnlLine."Payroll Control Type" <> PayrollJnlLine."Payroll Control Type"::"Net Pay")) THEN
        EXIT;

      PayrollJnlLinePost.FixupPayrollJnlLineRec(PayrollJnlLine);

      LDBManagement.LDBPayrollJnlLineTOGenJnlLine(GenJnlLine,PayrollJnlLine);
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);
    END;

    PROCEDURE GenDistBufferDLJnlLine@1102633007(DLJnlLine@1102602000 : Record 37086518);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
      Loan@1102602025 : Record 37086504;
      Client@1102602028 : Record 37086500;
      ClientDepositAccount@1102633019 : Record 37086501;
      LoanPostingGroup@1102602009 : Record 37086515;
      DepositPostingGroup@1102633003 : Record 37086514;
      Bank@1102634001 : Record 270;
      BankAccountPostingGroup@1102634004 : Record 277;
      DepositAccountProgram@1102634003 : Record 37086503;
      DimensionManagement@1102634005 : Codeunit 408;
      AccountType@1102602012 : 'G/L Account,Customer,Vendor,Bank Account';
      AccountNo@1102602010 : Code[20];
      AmountToPost@1102602011 : Decimal;
      InLineNo@1102602027 : Integer;
      InLDBGenerate@1102602026 : Boolean;
      CHRG@1102633018 : TextConst 'ENU=CHRG;FRA=CHRG;ESM=CHRG;ENC=CHRG';
      "L TRANSFER"@1102633017 : TextConst 'ENU=L TRANSFER;FRA=L TRANSFER;ESM=TRANSFERENCIA AL LIBRO;ENC=L TRANSFER';
      "LN IN ACCR"@1102633016 : TextConst 'ENU=LN IN ACCR;FRA=LN IN ACCR;ESM=LN IN ACCR;ENC=LN IN ACCR';
      FEE@1102633015 : TextConst 'ENU=FEE;FRA=FRAIS;ESM=COMISIêN;ENC=FEE';
      "FEE PAY"@1102633014 : TextConst 'ENU=FEE PAY;FRA=PAIEMENT DES FRAIS;ESM=PAGO DE COMISIêN;ENC=FEE PAY';
      "PRIN ADV"@1102633013 : TextConst 'ENU=PRIN ADV;FRA=PRIN ADV;ESM=ADEL CAP;ENC=PRIN ADV';
      "PRIN INT PAY"@1102633012 : TextConst 'ENU=PRIN INT PAY;FRA=PRIN INT PAY;ESM=PAGO INT CAP;ENC=PRIN INT PAY';
      "PRIN PAY"@1102633011 : TextConst 'ENU=PRIN PAY;FRA=PRIN PAY;ESM=PRIN PAY;ENC=PRIN PAY';
      "INT PAY"@1102633010 : TextConst 'ENU=INT PAY;FRA=INT PAY;ESM=INT PAY;ENC=INT PAY';
      "WR OFF PRN"@1102633009 : TextConst 'ENU=WR OFF PRN;FRA=WR OFF PRN;ESM=WR OFF PRN;ENC=WR OFF PRN';
      "WR OFF INT"@1102633008 : TextConst 'ENU=WR OFF INT;FRA=WR OFF INT;ESM=WR OFF INT;ENC=WR OFF INT';
      "WR OFF FEE"@1102634000 : TextConst 'ENU=WR OFF FEE;FRA=Frais d''amortissement;ESM=DEDUC. FISCAL DE COMISIêN;ENC=WR OFF FEE';
      "DEP PRIN"@1102633007 : TextConst 'ENU=DEP PRIN;FRA=DEP PRIN;ESM=DEP DE CAP;ENC=DEP PRIN';
      "DEP PRIN PD"@1102633006 : TextConst 'ENU=DEP PRIN PD;FRA=DEP PRIN PD;ESM=DEP DE CAP PAG;ENC=DEP PRIN PD';
      "DEP INT"@1102633005 : TextConst 'ENU=DEP INT;FRA=DEP INT;ESM=DEP INT;ENC=DEP INT';
      "DEP INT PD"@1102633004 : TextConst 'ENU=DEP INT PD;FRA=DEP INT PD;ESM=DEP INT PD;ENC=DEP INT PD';
      "RET INT"@1102633002 : TextConst 'ENU=RET INT;FRA=RET INT;ESM=INT RET;ENC=RET INT';
      "RET INT PD"@1102633001 : TextConst 'ENU=RET INT PD;FRA=RET INT PD;ESM=INT RET PD;ENC=RET INT PD';
      "D TRANSFER"@1102633000 : TextConst 'ENU=D TRANSFER;FRA=D TRANSFER;ESM="TRANSFERENCIA D ";ENC=D TRANSFER';
      "AR PYMNT"@1102634002 : TextConst 'ENU=AR PYMNT';
    BEGIN
      DeleteLineDistributionBuffer(DLJnlLine."Internal Control No.");
      IF DLJnlLine.EmptyLine THEN
        EXIT;

      GLSetup.GET;

      CASE DLJnlLine.Type OF
        DLJnlLine.Type::Loan:
          BEGIN
            WITH DLJnlLine DO
              IF ("System Entry Type Code" = "L TRANSFER") AND (("Client No." = '') OR ("New Client No." = '') OR
                 ("Client Account No." = '') OR ("New Client Account No." = '')) THEN
                EXIT;

            LoanPostingGroup.GET(DLJnlLine."Posting Group");
            AccountType := AccountType::"G/L Account";

            CASE DLJnlLine."System Entry Type Code" OF
              "L TRANSFER","PRIN ADV","PRIN INT PAY","PRIN PAY",CHRG,"WR OFF PRN" :
                AccountNo := LoanPostingGroup."Loans Receivable Account";
              FEE:            AccountNo := LoanPostingGroup."Loan Fees Receivable Account";
              "FEE PAY":      AccountNo := LoanPostingGroup."Loan Fees Receivable Account";
              "WR OFF INT" :  AccountNo := LoanPostingGroup."Interest Receivable Account";
              "WR OFF FEE" :  AccountNo := LoanPostingGroup."Loan Fees Receivable Account";
              "LN IN ACCR" :  AccountNo := LoanPostingGroup."Interest Income Account";
              "INT PAY" :     AccountNo := LoanPostingGroup."Interest Receivable Account";
            END;

            AmountToPost := DLJnlLine.Amount;
            IF DLJnlLine."System Entry Type Code" IN ["FEE PAY", "PRIN PAY", "INT PAY", "LN IN ACCR",
              "WR OFF INT", "WR OFF PRN","WR OFF FEE"] THEN
              AmountToPost := -AmountToPost
            ELSE IF DLJnlLine."System Entry Type Code" IN ["L TRANSFER"] THEN
              AmountToPost := -DLJnlLine.Amount
            ELSE IF DLJnlLine."System Entry Type Code" = "PRIN INT PAY" THEN
              AmountToPost := -DLJnlLine."Principal Amount";

            LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
            IF (DLJnlLine."System Entry Type Code" = "PRIN ADV") AND (DLJnlLine."Pay-to Vendor No." <> '') THEN BEGIN
              GenJnlLine."Bal. Account Type" := GenJnlLine."Bal. Account Type"::Vendor;
              GenJnlLine."Bal. Account No." := DLJnlLine."Pay-to Vendor No.";
              GenJnlLine."Document Type" := GenJnlLine."Document Type"::Invoice;
            END;
            InLDBGenerate := TRUE;
            InLineNo := 10000;
            LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);

            IF DLJnlLine."System Entry Type Code" IN ["L TRANSFER"] THEN BEGIN
              AccountType := AccountType::"G/L Account";
              AccountNo := LoanPostingGroup."Interest Receivable Account";
              AmountToPost := DLJnlLine."Interest Amount";
              IF AmountToPost <> 0 THEN BEGIN
                LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
                InLDBGenerate := TRUE;
                InLineNo := InLineNo + 100000;
                LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
              END;
            END ELSE IF DLJnlLine."System Entry Type Code" = "PRIN INT PAY" THEN BEGIN
              AccountType := AccountType::"G/L Account";
              AccountNo := LoanPostingGroup."Interest Receivable Account";
              AmountToPost := -DLJnlLine."Interest Amount";
              IF AmountToPost <> 0 THEN BEGIN
                LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
                InLDBGenerate := TRUE;
                InLineNo := InLineNo + 100000;
                LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
              END;
            END;

            IF (DLJnlLine."Bal. Account No." <> '') AND
              NOT ((DLJnlLine."System Entry Type Code" = "PRIN ADV") AND (DLJnlLine."Pay-to Vendor No." <> ''))
            THEN BEGIN
              IF DLJnlLine."Bal. Account Type" = DLJnlLine."Bal. Account Type"::"Deposit Account" THEN BEGIN
                ClientDepositAccount.GET(DLJnlLine."Bal. Account No.");
                ClientDepositAccount.TESTFIELD("Deposit Account Program No.");
                DepositPostingGroup.GET(ClientDepositAccount."Deposit Posting Group");
                DepositAccountProgram.GET(ClientDepositAccount."Deposit Account Program No.");
                DepositAccountProgram.TESTFIELD("Bank Account No.");
                Loan.GET(DLJnlLine."Client Account No.");
                Loan.TESTFIELD("Loan Bank Account No.");
                IF Loan."Loan Bank Account No." <> DepositAccountProgram."Bank Account No." THEN BEGIN
                  AccountType := AccountType::"Bank Account";
                  AccountNo := DepositAccountProgram."Bank Account No.";
                  AmountToPost := -DLJnlLine.Amount;
                  LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
                  InLDBGenerate := TRUE;
                  InLineNo := InLineNo + 100000;
                  LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);

                  AccountType := AccountType::"Bank Account";
                  AccountNo := Loan."Loan Bank Account No.";
                  AmountToPost := DLJnlLine.Amount;
                  LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
                  InLDBGenerate := TRUE;
                  InLineNo := InLineNo + 100000;
                  LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
                END;

                DepositPostingGroup.GET(ClientDepositAccount."Deposit Posting Group");
                DLJnlLine."Bal. Account Type" := DLJnlLine."Bal. Account Type"::"G/L Account";
                DLJnlLine."Bal. Account No." := DepositPostingGroup."Deposits Payable Account";
              END;
              AccountType := DLJnlLine."Bal. Account Type";
              AccountNo := DLJnlLine."Bal. Account No.";
              AmountToPost := DLJnlLine.Amount;
              IF DLJnlLine."System Entry Type Code" IN [CHRG,FEE,"PRIN ADV"] THEN
                AmountToPost := -AmountToPost
              ELSE
                AmountToPost := AmountToPost;

              IF DLJnlLine."Bal. Account Type" = DLJnlLine."Bal. Account Type"::"Bank Account" THEN BEGIN
                Bank.GET(DLJnlLine."Bal. Account No.");
                IF (GLSetup."G/L Cash Posting Method" = GLSetup."G/L Cash Posting Method"::Traditional) THEN BEGIN
                  DLJnlLine.VALIDATE("Fund No.", Bank."G/L Cash Control Fund");
                  BankAccountPostingGroup.GET(Bank."Bank Acc. Posting Group");
                  IF GLSetup."G/L Cash Dimensions" = GLSetup."G/L Cash Dimensions"::"Bank Posting Group" THEN
                    DimensionManagement.DIMBankPostGroupTOGenJnlLine(BankAccountPostingGroup,GenJnlLine)
                  ELSE
                    DLManagement.DIMDLJnlLineToGenJnlLine(DLJnlLine,GenJnlLine);
                END;
              END;

              LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
              InLDBGenerate := TRUE;
              InLineNo := InLineNo + 100000;
              LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
            END;

            IF DLJnlLine."System Entry Type Code" = "L TRANSFER" THEN BEGIN
              DLManagement.CopyRequiredTransferFields(DLJnlLine);
              DLManagement.TransferNewFields(DLJnlLine);
              LoanPostingGroup.GET(DLJnlLine."New Posting Group");
              AccountNo := LoanPostingGroup."Loans Receivable Account";
              AccountType := AccountType::"G/L Account";
              AmountToPost := DLJnlLine.Amount;
              LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
              InLDBGenerate := TRUE;
              InLineNo := InLineNo + 100000;
              LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
            END;
            InLDBGenerate := FALSE;
          END;
        DLJnlLine.Type::Deposit:
          BEGIN

            WITH DLJnlLine DO
              IF ("System Entry Type Code" = "D TRANSFER") AND (("Client No." = '') OR ("New Client No." = '') OR
                 ("Client Account No." = '') OR ("New Client Account No." = '')) THEN
                EXIT;

            DepositPostingGroup.GET(DLJnlLine."Posting Group");
            ClientDepositAccount.GET(DLJnlLine."Client Account No.");
            AccountType := AccountType::"G/L Account";

            CASE DLJnlLine."System Entry Type Code" OF
              "DEP PRIN" : AccountNo := DepositPostingGroup."Deposits Payable Account";
              "DEP PRIN PD" : AccountNo := DepositPostingGroup."Deposits Payable Account";
              "DEP INT" :
                BEGIN
                  IF ClientDepositAccount."Interest Action" IN [ClientDepositAccount."Interest Action"::Reinvest,
                    ClientDepositAccount."Interest Action"::Retain] THEN BEGIN
                    AccountNo := DepositPostingGroup."Deposits Payable Account";
                    END
                  ELSE IF ClientDepositAccount."Interest Action" IN [ClientDepositAccount."Interest Action"::Payout] THEN BEGIN
                    AccountNo := DepositPostingGroup."Deposit Encumbrance Account";
                  END;
                END;
              "DEP INT PD" : ;
              "RET INT" : AccountNo := DepositPostingGroup."Interest Payable Account";
              "RET INT PD" : AccountNo := DepositPostingGroup."Interest Payable Account";
              "D TRANSFER" : AccountNo := DepositPostingGroup."Deposits Payable Account";
              "AR PYMNT" : AccountNo := DepositPostingGroup."Deposits Payable Account";
            END;

            AmountToPost := DLJnlLine.Amount;
            IF DLJnlLine."System Entry Type Code" IN ["DEP PRIN", "DEP INT", "RET INT"] THEN
              AmountToPost := -AmountToPost
            ELSE IF DLJnlLine."System Entry Type Code" IN ["D TRANSFER"] THEN
              AmountToPost := -AmountToPost;

            LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
            InLDBGenerate := TRUE;
            InLineNo := 10000;
            LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);

            IF DLJnlLine."System Entry Type Code" IN ["D TRANSFER"] THEN BEGIN
              AccountType := AccountType::"G/L Account";
              AccountNo := LoanPostingGroup."Interest Receivable Account";
              AmountToPost := DLJnlLine."Interest Amount";
              IF AmountToPost <> 0 THEN BEGIN
                LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
                InLDBGenerate := TRUE;
                InLineNo := InLineNo + 100000;
                LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
              END;
            END;

            IF DLJnlLine."Bal. Account No." <> '' THEN BEGIN
              AccountType := DLJnlLine."Bal. Account Type";
              AccountNo := DLJnlLine."Bal. Account No.";
              AmountToPost := DLJnlLine.Amount;
              IF DLJnlLine."System Entry Type Code" IN ["DEP PRIN", "DEP INT", "RET INT"] THEN
                AmountToPost := AmountToPost
              ELSE
                AmountToPost := -AmountToPost;

              IF DLJnlLine."Bal. Account Type" = DLJnlLine."Bal. Account Type"::"Bank Account" THEN BEGIN
                Bank.GET(DLJnlLine."Bal. Account No.");
                IF (GLSetup."G/L Cash Posting Method" = GLSetup."G/L Cash Posting Method"::Traditional) THEN BEGIN
                  DLJnlLine.VALIDATE("Fund No.", Bank."G/L Cash Control Fund");
                  BankAccountPostingGroup.GET(Bank."Bank Acc. Posting Group");
                  IF GLSetup."G/L Cash Dimensions" = GLSetup."G/L Cash Dimensions"::"Bank Posting Group" THEN
                    DimensionManagement.DIMBankPostGroupTOGenJnlLine(BankAccountPostingGroup,GenJnlLine)
                  ELSE
                    DLManagement.DIMDLJnlLineToGenJnlLine(DLJnlLine,GenJnlLine);
                END;
              END;

              LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
              InLDBGenerate := TRUE;
              InLineNo := InLineNo + 100000;
              LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
            END;

            IF DLJnlLine."System Entry Type Code" = "D TRANSFER" THEN BEGIN
              DLManagement.CopyRequiredTransferFields(DLJnlLine);
              DLManagement.TransferNewFields(DLJnlLine);
              DepositPostingGroup.GET(DLJnlLine."New Posting Group");
              AccountNo := DepositPostingGroup."Deposits Payable Account";
              AccountType := AccountType::"G/L Account";
              AmountToPost := DLJnlLine.Amount;
              LDBManagement.LDBDLJnlLineTOGenJnlLine(GenJnlLine,DLJnlLine,AccountType,AccountNo,AmountToPost);
              InLDBGenerate := TRUE;
              InLineNo := InLineNo + 100000;
              LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
            END;
            InLDBGenerate := FALSE;

          END;
      END;
    END;

    PROCEDURE GenDistBufferInvestmentJnlLine@1102602001(InvestJnlLine@1102602000 : Record 37086613);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
      Investment@1102602013 : Record 37086600;
      Investment2@1102634002 : Record 37086600;
      Loan@1102602025 : Record 37086504;
      Institution@1102602029 : Record 37086603;
      Client@1102602028 : Record 37086500;
      InvestPostingGroup@1102602009 : Record 37086610;
      InvestPostingGroup2@1102634003 : Record 37086610;
      Bank@1102634000 : Record 270;
      InvestmentJnlBatch@1102634001 : Record 37086612;
      AccountType@1102602012 : 'G/L Account,Customer,Vendor,Bank Account,Investment,Loan';
      AccountNo@1102602010 : Code[20];
      AmountToPost@1102602011 : Decimal;
      "BASIS ADJ"@1102602023 : TextConst 'ENU=BASIS ADJ;FRA=BASIS ADJ;ESM=BASIS ADJ;ENC=BASIS ADJ';
      BGHT@1102602022 : TextConst 'ENU=BGHT;FRA=BGHT;ESM=BGHT;ENC=BGHT';
      "I CHRG"@1102602020 : TextConst 'ENU=I CHRG;FRA=I FRAIS;ESM=CARGO I;ENC=I CHRG';
      "I TRANSFER"@1102602019 : TextConst 'ENU=I TRANSFER;FRA=I TRANSFRER;ESM=TRASPASO;ENC=I TRANSFER';
      INT@1102602018 : TextConst 'ENU=INT;FRA=INT;ESM=INT;ENC=INT';
      "INT ACCR"@1102602017 : TextConst 'ENU=INT ACCR;FRA=INT ACCR;ESM=INT ACCR;ENC=INT ACCR';
      "MV ACCRUAL"@1102602014 : TextConst 'ENU=MV ACCRUAL;FRA=MV Ú RECEVOIR;ESM=ACUMULADO DE MV;ENC=MV ACCRUAL';
      SOLD@1102602004 : TextConst 'ENU=SOLD;FRA=VENDU;ESM=VENDIDO(A);ENC=SOLD';
      "WR OFF INV"@1102602024 : TextConst 'ENU=WR OFF INV;FRA=WR OFF INV;ESM=WR OFF INV;ENC=WR OFF INV';
      InLineNo@1102602027 : Integer;
      InLDBGenerate@1102602026 : Boolean;
      "BGHT I"@1102602031 : TextConst 'ENU=BGHT I;FRA=BGHT I;ESM=BGHT I;ENC=BGHT I';
      "REINV DIV"@1102602036 : TextConst 'ENU=REINV DIV;FRA=REINV DIV;ESM=REINV DIV;ENC=REINV DIV';
      "REINV INT"@1102602035 : TextConst 'ENU=REINV INT;FRA=REINV INT;ESM=REINV INT;ENC=REINV INT';
      DIVIDEND@1102602034 : TextConst 'ENU=DIVIDEND;FRA=DIVIDEND;ESM=DIVIDEND;ENC=DIVIDEND';
      "MGT FEE"@1102602033 : TextConst 'ENU=MGT FEE;FRA=FRAIS DE GESTION;ESM=CUOTA ADMêN.;ENC=MGT FEE';
      "CAP GAIN"@1102602032 : TextConst 'ENU=CAP GAIN;FRA=CAP GAIN;ESM="GANANCIA CAP ";ENC=CAP GAIN';
      "MV ADJ"@1000000000 : TextConst 'ENU=MV ADJ;FRA=AJUSTEMENT MV;ESM=AJ DE MV;ENC=MV ADJ';
    BEGIN
      DeleteLineDistributionBuffer(InvestJnlLine."Internal Control No.");
      IF InvestJnlLine.EmptyLine THEN
        EXIT;

      WITH InvestJnlLine DO
        IF ("System Entry Type Code" = "I TRANSFER") AND ("Investment No." = '') AND ("New Investment No." = '') THEN
          EXIT;

      InvestPostingGroup.GET(InvestJnlLine."Investment Posting Group");
      AccountType := AccountType::"G/L Account";

      CASE InvestJnlLine."System Entry Type Code" OF
        "BASIS ADJ" :   AccountNo := InvestPostingGroup."Basis Adjustment Account";
        BGHT :
          BEGIN
            AccountNo := InvestPostingGroup."Investment Account";
            Investment.GET(InvestJnlLine."Investment No.");
          END;
        "BGHT I" :      AccountNo := InvestPostingGroup."Interest Receivable Account";
        "CAP GAIN" :    AccountNo := InvestPostingGroup."Realized Gain/Loss Account";
        DIVIDEND :      AccountNo := InvestPostingGroup."Dividend Income Account";
        "I CHRG" :      AccountNo := InvestPostingGroup."Expense Account";
        INT :           AccountNo := InvestPostingGroup."Interest Income Account";
        "INT ACCR" :    AccountNo := InvestPostingGroup."Interest Income Account";
        "MGT FEE" :     AccountNo := InvestPostingGroup."Management Fee Expense Account";
        "MV ACCRUAL" :  AccountNo := InvestPostingGroup."Market Value Adj. Account";
        "MV ADJ" :
          IF InvestJnlLine."Client No." = '' THEN
            AccountNo := InvestPostingGroup."Unrealized Gain/Loss Account"
          ELSE BEGIN
            Client.GET(InvestJnlLine."Client No.");
            AccountNo := InvestPostingGroup."Investment Encumbrance Account";
          END;
        "REINV INT" :   AccountNo := InvestPostingGroup."Reinvested Interest Account";
        "REINV DIV" :   AccountNo := InvestPostingGroup."Reinvested Dividend Account";
        SOLD,"I TRANSFER","WR OFF INV" :
          AccountNo := InvestPostingGroup."Investment Account";
      END;

      AmountToPost := InvestJnlLine.Amount;
      IF InvestJnlLine."System Entry Type Code" IN [INT,"INT ACCR",DIVIDEND,"MV ADJ"] THEN
        AmountToPost := -AmountToPost
      ELSE IF InvestJnlLine."System Entry Type Code" IN [SOLD,"I TRANSFER","WR OFF INV"] THEN
        AmountToPost := -InvestJnlLine."Purchase Cost"
      ELSE IF InvestJnlLine."System Entry Type Code" IN ["REINV DIV","REINV INT","CAP GAIN"] THEN
        AmountToPost := -AmountToPost;

      LDBManagement.LDBInvestJnlLineTOGenJnlLine(GenJnlLine,InvestJnlLine,AccountType,AccountNo,AmountToPost);
      InLDBGenerate := TRUE;
      InLineNo := 10000;
      LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);

      IF InvestJnlLine."System Entry Type Code" IN [SOLD,"I TRANSFER","WR OFF INV"] THEN BEGIN
        AccountType := AccountType::"G/L Account";
        AccountNo := InvestPostingGroup."Basis Adjustment Account";
        AmountToPost := -InvestJnlLine."Basis Cost";
        IF AmountToPost <> 0 THEN BEGIN
          LDBManagement.LDBInvestJnlLineTOGenJnlLine(GenJnlLine,InvestJnlLine,AccountType,AccountNo,AmountToPost);
          InLDBGenerate := TRUE;
          InLineNo := InLineNo + 100000;
          LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
        END;
        AccountType := AccountType::"G/L Account";
        AccountNo := InvestPostingGroup."Unrealized Gain/Loss Account";
        AmountToPost := InvestJnlLine."Unrealized Gain Amount";
        IF AmountToPost <> 0 THEN BEGIN
          LDBManagement.LDBInvestJnlLineTOGenJnlLine(GenJnlLine,InvestJnlLine,AccountType,AccountNo,AmountToPost);
          InLDBGenerate := TRUE;
          InLineNo := InLineNo + 100000;
          LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
        END;

        AccountType := AccountType::"G/L Account";
        AccountNo := InvestPostingGroup."Realized Gain/Loss Account";
        AmountToPost := 0;
        IF InvestJnlLine."System Entry Type Code" IN [SOLD,"WR OFF INV","I TRANSFER"] THEN
          AmountToPost := -InvestJnlLine.Amount + InvestJnlLine."Purchase Cost" + InvestJnlLine."Basis Cost"
            - InvestJnlLine."Unrealized Gain Amount";
          AmountToPost := -InvestJnlLine.Amount + InvestJnlLine."Purchase Cost" + InvestJnlLine."Basis Cost"
            - InvestJnlLine."Unrealized Gain Amount";
        IF AmountToPost <> 0 THEN BEGIN
          LDBManagement.LDBInvestJnlLineTOGenJnlLine(GenJnlLine,InvestJnlLine,AccountType,AccountNo,AmountToPost);
          InLDBGenerate := TRUE;
          InLineNo := InLineNo + 100000;
          LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
        END;
      END ELSE IF (InvestJnlLine."System Entry Type Code" IN ["REINV INT","REINV DIV","CAP GAIN", "MGT FEE"]) AND
                  (InvestJnlLine."Client No." <> '') THEN BEGIN
        Client.GET(InvestJnlLine."Client No.");
        AccountType := AccountType::"G/L Account";
        AccountNo := InvestPostingGroup."Investment Encumbrance Account";
        AmountToPost := InvestJnlLine.Amount;
        IF AmountToPost <> 0 THEN BEGIN
          LDBManagement.LDBInvestJnlLineTOGenJnlLine(GenJnlLine,InvestJnlLine,AccountType,AccountNo,AmountToPost);
          InLDBGenerate := TRUE;
          InLineNo := InLineNo + 100000;
          LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
        END;
      END;

      IF InvestJnlLine."Bal. Account No." <> '' THEN BEGIN
        IF InvestJnlLine."Bal. Account Type" = InvestJnlLine."Bal. Account Type"::Investment THEN BEGIN
          AccountType := AccountType::"G/L Account";
          Investment.GET(InvestJnlLine."Bal. Account No.");
          InvestPostingGroup.GET(Investment."Investment Posting Group");
          AccountNo := InvestPostingGroup."Investment Account";
        END ELSE BEGIN
          AccountType := InvestJnlLine."Bal. Account Type";
          AccountNo := InvestJnlLine."Bal. Account No.";
        END;
        AmountToPost := InvestJnlLine.Amount;
        IF InvestJnlLine."System Entry Type Code" IN [BGHT,"I CHRG","BASIS ADJ","MV ACCRUAL","MGT FEE","BGHT I"] THEN
          AmountToPost := -AmountToPost
        ELSE IF (InvestJnlLine."System Entry Type Code" IN ["REINV INT","REINV DIV","CAP GAIN"]) AND
          (InvestJnlLine."Client No." <> '') THEN
          AmountToPost := -AmountToPost
        ELSE
          AmountToPost := AmountToPost;

        IF InvestJnlLine."Bal. Account Type" = InvestJnlLine."Bal. Account Type"::"Bank Account" THEN BEGIN
          Bank.GET(InvestJnlLine."Bal. Account No.");
          IF (GLSetup."G/L Cash Posting Method" = GLSetup."G/L Cash Posting Method"::Traditional) THEN
            InvestJnlLine.VALIDATE("Fund No.", Bank."G/L Cash Control Fund");
        END;

        LDBManagement.LDBInvestJnlLineTOGenJnlLine(GenJnlLine,InvestJnlLine,AccountType,AccountNo,AmountToPost);
        InLDBGenerate := TRUE;
        InLineNo := InLineNo + 100000;
        LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);

        IF (InvestJnlLine."System Entry Type Code" IN ["REINV INT","REINV DIV","CAP GAIN", "MGT FEE"]) AND
           (InvestJnlLine."Client No." <> '')  THEN BEGIN
          InvestJnlLine."Client No." := '';

          IF InvestJnlLine."Institution No." <> '' THEN BEGIN
            Institution.GET(InvestJnlLine."Institution No.");
            IF Institution."Investment Bal. Account Type" = Institution."Investment Bal. Account Type"::Investment THEN BEGIN
              Investment2.GET(Institution."Investment Bal. Account No.");
              Investment2.TESTFIELD("Investment Posting Group");
              InvestPostingGroup2.GET(Investment2."Investment Posting Group");
              InvestPostingGroup2.TESTFIELD("Investment Account");

              GenJnlLine.VALIDATE("Account Type", GenJnlLine."Account Type"::"G/L Account");
              GenJnlLine.VALIDATE("Account No.", InvestPostingGroup2."Investment Account");
              END
            ELSE BEGIN
              GenJnlLine.VALIDATE("Account Type",Institution."Investment Bal. Account Type");
              GenJnlLine.VALIDATE("Account No.",Institution."Investment Bal. Account No.");
            END;
            END
          ELSE IF (InvestJnlLine."Journal Template Name" <> '') AND (InvestJnlLine."Journal Batch Name" <> '') THEN BEGIN
            InvestmentJnlBatch.GET(InvestJnlLine."Journal Template Name", InvestJnlLine."Journal Batch Name");
            IF InvestmentJnlBatch."Bal. Account Type" = InvestmentJnlBatch."Bal. Account Type"::Investment THEN BEGIN
              Investment2.GET(InvestmentJnlBatch."Bal. Account No.");
              Investment2.TESTFIELD("Investment Posting Group");
              InvestPostingGroup2.GET(Investment2."Investment Posting Group");
              InvestPostingGroup2.TESTFIELD("Investment Account");

              GenJnlLine.VALIDATE("Account Type", GenJnlLine."Account Type"::"G/L Account");
              GenJnlLine.VALIDATE("Account No.", InvestPostingGroup2."Investment Account");
              END
            ELSE BEGIN
              GenJnlLine.VALIDATE("Account Type",InvestmentJnlBatch."Bal. Account Type");
              GenJnlLine.VALIDATE("Account No.",InvestmentJnlBatch."Bal. Account No.");
            END;
            END
          ELSE BEGIN
            DeleteLineDistributionBuffer(InvestJnlLine."Internal Control No.");
          END;
          AmountToPost := InvestJnlLine.Amount;
          LDBManagement.LDBInvestJnlLineTOGenJnlLine(GenJnlLine,InvestJnlLine,AccountType,AccountNo,AmountToPost);
          InLDBGenerate := TRUE;
          InLineNo := InLineNo + 100000;
          LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
        END;
      END;

      IF InvestJnlLine."System Entry Type Code" = "I TRANSFER" THEN BEGIN
        InvestmentManagement.CopyRequiredTransferFields(InvestJnlLine);
        InvestmentManagement.TransferNewFields(InvestJnlLine);
        InvestPostingGroup.GET(InvestJnlLine."New Investment Posting Group");
        AccountNo := InvestPostingGroup."Investment Account";
        AccountType := AccountType::"G/L Account";
        AmountToPost := InvestJnlLine.Amount;
        LDBManagement.LDBInvestJnlLineTOGenJnlLine(GenJnlLine,InvestJnlLine,AccountType,AccountNo,AmountToPost);
        InLDBGenerate := TRUE;
        InLineNo := InLineNo + 100000;
        LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);

        AccountType := AccountType::"G/L Account";
        AccountNo := InvestPostingGroup."Basis Adjustment Account";
        AmountToPost := -InvestJnlLine.Amount + InvestJnlLine."Purchase Cost" + InvestJnlLine."Basis Cost";
        IF AmountToPost <> 0 THEN BEGIN
          LDBManagement.LDBInvestJnlLineTOGenJnlLine(GenJnlLine,InvestJnlLine,AccountType,AccountNo,AmountToPost);
          InLDBGenerate := TRUE;
          InLineNo := InLineNo + 100000;
          LDBManagement.GenerateDistBuffer(GenJnlLine,InLDBGenerate,InLineNo,BatchValidationProcessing);
        END;
      END;
      InLDBGenerate := FALSE;
    END;

    PROCEDURE GenDistBufferBankRecLine@1102633002();
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
    BEGIN
      {DeleteLineDistributionBuffer(BankRecLine."Internal Control No.");
      IF (BankRecLine."Record Type" <> BankRecLine."Record Type"::Adjustment) OR (BankRecLine.Amount = 0) THEN
        EXIT;

      LDBManagement.LDBBankRecLineTOGenJnlLine(GenJnlLine,BankRecLine);
      LDBManagement.GenerateDistBuffer(GenJnlLine,FALSE,0,BatchValidationProcessing);}
    END;

    PROCEDURE GenDistBufferVersionLineDetail@1102602073(BVVersionLineDetail@1102602000 : Record 37065315);
    VAR
      GenJnlLine@1102602001 : TEMPORARY Record 81;
      BVManagement@1102634001 : Codeunit 37065300;
    BEGIN
      IF (BVVersionLineDetail.Amount = 0) AND (BVVersionLineDetail.Quantity = 0) THEN
        EXIT;

      LDBManagement.LDBVersionLineDtlTOGenJnlLine(GenJnlLine,BVVersionLineDetail);
      LDBManagement.GenerateDistBuffer(GenJnlLine,TRUE,BVVersionLineDetail."Entry No.",BatchValidationProcessing);
    END;

    PROCEDURE SetBatchValidationProcessing@1102602005();
    BEGIN
      BatchValidationProcessing := TRUE;
    END;

    PROCEDURE DisplayBatchValidationErrors@1102602007(SourceCode@1102602001 : Code[10];TemplateName@1102602002 : Code[10];BatchName@1102602003 : Code[10]);
    VAR
      ValidationBuffer@1102602000 : Record 37001007;
    BEGIN
      ValidationBuffer.SETCURRENTKEY("Source Code");
      ValidationBuffer.SETRANGE("Source Code",SourceCode);
      ValidationBuffer.SETRANGE("Journal Template Name",TemplateName);
      ValidationBuffer.SETRANGE("Journal Batch Name",BatchName);
      IF ValidationBuffer.FINDFIRST THEN
        MESSAGE(SNText34,ValidationBuffer.COUNT);

      BatchValidationProcessing := FALSE;
    END;

    PROCEDURE UpdateLineDistDocumentNo@1102602065(CurrentDocNo@1102602001 : Code[20];PostingDocNo@1102602002 : Code[20];JournalTemplateName@1102633001 : Code[10];JournalBatchName@1102633000 : Code[10]);
    VAR
      LineDistributionBuffer@1102602003 : Record 37001008;
    BEGIN
      IF (CurrentDocNo = '') OR (PostingDocNo = '') OR (CurrentDocNo = PostingDocNo) THEN
        EXIT;

      WITH LineDistributionBuffer DO BEGIN
        SETCURRENTKEY("Document No.");
        SETRANGE("Document No.",CurrentDocNo);
        SETRANGE("Journal Template Name",JournalTemplateName);
        SETRANGE("Journal Batch Name",JournalBatchName);
        IF FINDSET(TRUE,FALSE) THEN
          REPEAT
            "Document No." := PostingDocNo;
            MODIFY;
          UNTIL NOT FINDFIRST;
      END;
    END;

    PROCEDURE PreviewDistributionsJournal@1102633001(TemplateName@1102633000 : Code[10];BatchName@1102633001 : Code[10];SourceCode@1102633002 : Code[10]);
    VAR
      LineDistributionBuffer@1102602001 : Record 37001008;
      LineDistributions@1102634000 : Page 37001007;
    BEGIN
      LineDistributionBuffer.FILTERGROUP(6);
      LineDistributionBuffer.SETCURRENTKEY("Journal Template Name","Journal Batch Name","Source Code");
      LineDistributionBuffer.SETRANGE("Journal Template Name",TemplateName);
      LineDistributionBuffer.SETRANGE("Journal Batch Name",BatchName);
      LineDistributionBuffer.SETRANGE("Source Code",SourceCode);
      LineDistributionBuffer.FILTERGROUP(0);

      LineDistributions.SETTABLEVIEW(LineDistributionBuffer);
      LineDistributions.RUN;
    END;

    PROCEDURE PreviewDistributionsDocument@1102633003(DocumentNo@1102633002 : Code[20];SourceCode@1102633000 : Code[10]);
    VAR
      LineDistributionBuffer@1102602002 : Record 37001008;
      LineDistributions@1102634000 : Page 37001007;
    BEGIN
      LineDistributionBuffer.FILTERGROUP(6);
      LineDistributionBuffer.SETCURRENTKEY("Document No.");
      LineDistributionBuffer.SETRANGE("Document No.",DocumentNo);
      LineDistributionBuffer.SETRANGE("Source Code",SourceCode);
      LineDistributionBuffer.FILTERGROUP(0);

      LineDistributions.SETTABLEVIEW(LineDistributionBuffer);
      LineDistributions.RUN;
    END;

    PROCEDURE ReverseCommitmentPost@1102602028(InternalControlNo@1102602000 : Code[50];DocumentNo@1102602005 : Code[20];PostingDate@1102602006 : Date;AllocationNo@1102602007 : Code[10]);
    VAR
      GLEntry@1102602001 : Record 17;
      GenJnlLine@1102602003 : Record 81;
      GLEntry2@1102602009 : Record 17;
      CurrExchRate@1102633001 : Record 330;
      PurchaseRequisitionLine@1102634002 : Record 37001091;
      RemainingAmountToReverse@1102602008 : Decimal;
      RemainingQuantityToReverse@1102634001 : Decimal;
      RemainingBudgetedQtyToReverse@1102634000 : Decimal;
      GLAccountFilter@1102602011 : Code[250];
      ReserveAccountNo@1102633000 : Code[20];
      Complete@1102602010 : Boolean;
    BEGIN
      WITH GLEntry DO BEGIN
        IF NOT FINDLAST THEN
          EXIT;
        GLSetup.GET;

        SETCURRENTKEY("Transaction Type","Internal Control No.");
        SETRANGE("Transaction Type","Transaction Type"::Commitment);
        SETRANGE("Internal Control No.",InternalControlNo);
        SETFILTER("Entry Type",'<>%1&<>%2',GLEntry."Entry Type"::Interfund,GLEntry."Entry Type"::Calculated);
        SETRANGE("Entry No.",1,"Entry No.");

        IF FINDLAST THEN
          ReserveAccountNo := "G/L Account No."
        ELSE
          EXIT;

        IF NOT FINDFIRST THEN
          EXIT;

        SETRANGE("Transaction No.","Transaction No.");
        REPEAT
          RemainingAmountToReverse := 0;
          GLEntry2.COPY(GLEntry);
          GLEntry2.SETRANGE("G/L Account No.","G/L Account No.");
          GLEntry2.SETRANGE("Transaction No.");
          IF GLEntry2.FINDSET(FALSE,FALSE) THEN
            REPEAT
              RemainingAmountToReverse := RemainingAmountToReverse + GLEntry2.Amount;
              RemainingQuantityToReverse := RemainingQuantityToReverse + GLEntry2.Quantity;
              RemainingBudgetedQtyToReverse := RemainingBudgetedQtyToReverse + GLEntry2."Budgeted Quantity";
            UNTIL GLEntry2.NEXT = 0;

          IF (Amount > 0) AND (RemainingAmountToReverse <= 0) THEN BEGIN
            RemainingAmountToReverse := 0;
            RemainingQuantityToReverse := 0;
            RemainingBudgetedQtyToReverse := 0;
          END;
          IF (Amount < 0) AND (RemainingAmountToReverse >= 0) THEN BEGIN
            RemainingAmountToReverse := 0;
            RemainingQuantityToReverse := 0;
            RemainingBudgetedQtyToReverse := 0;
          END;

          RemainingAmountToReverse := ABS(RemainingAmountToReverse);
          RemainingQuantityToReverse := ABS(RemainingQuantityToReverse);
          RemainingBudgetedQtyToReverse := ABS(RemainingBudgetedQtyToReverse);

          IF RemainingAmountToReverse <> 0 THEN BEGIN
            xferCustomFields.GLEntryTOGenJnlLine(GenJnlLine,GLEntry,FALSE,FALSE);
            GenJnlLine."Source Table ID" := DATABASE::"Purchase Requisition Line";
            GenJnlLine."Document No." := DocumentNo;
            GenJnlLine."Posting Date" := PostingDate;
            GenJnlLine."Document Date" := PostingDate;

            GenJnlLine."Allocation No." := AllocationNo;
            IF ("G/L Account No." = ReserveAccountNo) AND (NOT FundManagement.CheckAPDistributed) THEN BEGIN
              GenJnlLine."Allocation No." := '';
            END;
            IF (GenJnlLine."Allocation No." <> '') AND
               ((GenJnlLine."Account No." <> ReserveAccountNo) OR FundManagement.CheckAPDimensionByInvoiceLine) THEN BEGIN
              PurchaseRequisitionLine.SETCURRENTKEY("Internal Control No.");
              PurchaseRequisitionLine.SETRANGE("Internal Control No.","Internal Control No.");
              IF PurchaseRequisitionLine.FINDFIRST THEN BEGIN
                DimMgt.DIMRequistionLineTOGenJnlLine(PurchaseRequisitionLine,GenJnlLine);
              END;
            END;

            GenJnlLine."Gen. Posting Type" := GenJnlLine."Gen. Posting Type"::Default;
            GenJnlLine."Gen. Bus. Posting Group" := '';
            GenJnlLine."Gen. Prod. Posting Group" := '';
            GenJnlLine."VAT Posting" := GenJnlLine."VAT Posting"::"Manual VAT Entry";
            GenJnlLine."VAT %" := 0;
            GenJnlLine."VAT Amount" := 0;
            GenJnlLine."VAT Base Amount" := GenJnlLine.Amount;
            GenJnlLine."VAT Bus. Posting Group" := '';
            GenJnlLine."VAT Prod. Posting Group" := '';

            IF Amount > 0 THEN BEGIN
              GenJnlLine.VALIDATE(Amount,-RemainingAmountToReverse);
              GenJnlLine.Quantity := -RemainingQuantityToReverse;
              GenJnlLine."Budgeted Quantity" := -RemainingBudgetedQtyToReverse;
            END ELSE BEGIN
              GenJnlLine.VALIDATE(Amount, RemainingAmountToReverse);
              GenJnlLine.Quantity := RemainingQuantityToReverse;
              GenJnlLine."Budgeted Quantity" := RemainingBudgetedQtyToReverse;
            END;

            IF "G/L Account No." = ReserveAccountNo THEN BEGIN
              GenJnlLine.Quantity := 0;
              GenJnlLine."Budgeted Quantity" := 0;
            END;

            GenJnlLine."Original Currency Code" := "Original Currency Code";
            IF GenJnlLine."Original Currency Code" IN ['',GLSetup."LCY Code"] THEN BEGIN
              GenJnlLine."Original Currency Amount" := GenJnlLine.Amount;
            END ELSE IF Amount = -GenJnlLine.Amount THEN BEGIN
              GenJnlLine."Original Currency Amount" := -"Original Currency Amount";
            END ELSE IF AllocationNo = '' THEN BEGIN
              GenJnlLine."Original Currency Amount" := -"Original Currency Amount";
            END ELSE BEGIN
              GenJnlLine."Original Currency Amount" :=
                ROUND(CurrExchRate.ExchangeAmtLCYToFCY(
                      "Posting Date","Original Currency Code",GenJnlLine.Amount,
                        CurrExchRate.ExchangeRate("Posting Date","Original Currency Code")));
            END;
            GenJnlLine."Source Currency Code" := GenJnlLine."Original Currency Code";
            GenJnlLine."Source Currency Amount" := GenJnlLine."Original Currency Amount";

            GenJnlPostLine.RunWithCheck(GenJnlLine);
          END;

          IF AllocationNo <> '' THEN BEGIN
            IF GLAccountFilter = '' THEN
              GLAccountFilter := "G/L Account No."
            ELSE
              GLAccountFilter := GLAccountFilter + '|' + "G/L Account No.";

            Complete := FALSE;
            REPEAT
              IF NEXT = 0 THEN BEGIN
                FINDLAST;
                Complete := TRUE;
              END ELSE IF STRPOS(GLAccountFilter,"G/L Account No.") = 0 THEN BEGIN
                NEXT(-1);
                Complete := TRUE;
              END;
            UNTIL Complete;
          END;

        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE ReverseEncumbrancePost@1102602019(InternalControlNo@1102602000 : Code[50];DocumentNo@1102602005 : Code[20];PostingDate@1102602006 : Date;FullReverse@1102602010 : Boolean;PartialReverse@1102602004 : Boolean;MaximumAmountToReverse@1102602002 : Decimal;AllocationNo@1102602013 : Code[10];VAR GenJnlPostLine2@1102633003 : Codeunit 12);
    VAR
      GLEntry@1102602001 : Record 17;
      GLEntry2@1102602008 : Record 17;
      GenJnlLine@1102602003 : Record 81;
      CurrExchRate@1102633004 : Record 330;
      PurchaseLine@1102634004 : Record 39;
      RemainingAmountToReverse@1102602007 : Decimal;
      RemainingQuantityToReverse@1102634000 : Decimal;
      RemainingBudgetedQtyToReverse@1102634001 : Decimal;
      RemainingAmountDebitAllocation@1102633002 : Decimal;
      AmountToReverse@1102602009 : Decimal;
      QuantityToReverse@1102634002 : Decimal;
      BudgetedQuantityToReverse@1102634003 : Decimal;
      GLAccountFilter@1102602014 : Code[250];
      ReserveAccountNo@1102633000 : Code[20];
      Complete@1102602015 : Boolean;
      LineAllocationWithGLAccounts@1102633001 : Boolean;
    BEGIN
      WITH GLEntry DO BEGIN
        IF NOT FINDLAST THEN
          EXIT;
        GLSetup.GET;

        SETCURRENTKEY("Transaction Type","Internal Control No.","Transaction No.","Entry No.","Entry Type");
        SETRANGE("Transaction Type","Transaction Type"::Encumbrance);
        SETRANGE("Internal Control No.",InternalControlNo);
        SETFILTER("Entry Type",'<>%1&<>%2',GLEntry."Entry Type"::Interfund,GLEntry."Entry Type"::Calculated);
        SETRANGE("Entry No.",1,"Entry No.");

        IF FINDLAST THEN
          ReserveAccountNo := "G/L Account No."
        ELSE
          EXIT;

        IF NOT FINDFIRST THEN
          EXIT;

        MaximumAmountToReverse := ABS(MaximumAmountToReverse);
        IF AllocationNo <> '' THEN BEGIN
          LineAllocationWithGLAccounts := AllocationManagement.GLAccountsOnLineAllocation(AllocationNo,PostingDate);
          RemainingAmountDebitAllocation := MaximumAmountToReverse;
        END;

        SETRANGE("Transaction No.","Transaction No.");
        REPEAT

          IF PartialReverse OR FullReverse THEN BEGIN
            MaximumAmountToReverse := ABS(MaximumAmountToReverse);

            RemainingAmountToReverse := 0;
            GLEntry2.COPY(GLEntry);
            GLEntry2.SETRANGE("G/L Account No.","G/L Account No.");
            GLEntry2.SETRANGE("Transaction No.");
            IF GLEntry2.FINDSET(FALSE,FALSE) THEN
              REPEAT
                RemainingAmountToReverse := RemainingAmountToReverse  + GLEntry2.Amount;
                RemainingQuantityToReverse := RemainingQuantityToReverse + GLEntry2.Quantity;
                RemainingBudgetedQtyToReverse := RemainingBudgetedQtyToReverse + GLEntry2."Budgeted Quantity";
              UNTIL GLEntry2.NEXT = 0;

            IF (Amount > 0) AND (RemainingAmountToReverse <= 0) THEN BEGIN
              RemainingAmountToReverse := 0;
              RemainingQuantityToReverse := 0;
              RemainingBudgetedQtyToReverse := 0;
            END;
            IF (Amount < 0) AND (RemainingAmountToReverse >= 0) THEN BEGIN
              RemainingAmountToReverse := 0;
              RemainingQuantityToReverse := 0;
              RemainingBudgetedQtyToReverse := 0;
            END;

            RemainingAmountToReverse := ABS(RemainingAmountToReverse);
            RemainingQuantityToReverse := ABS(RemainingQuantityToReverse);
            RemainingBudgetedQtyToReverse := ABS(RemainingBudgetedQtyToReverse);

            IF FullReverse THEN BEGIN
              AmountToReverse := RemainingAmountToReverse;
              QuantityToReverse := RemainingQuantityToReverse;
              BudgetedQuantityToReverse := RemainingBudgetedQtyToReverse;
            END ELSE IF RemainingAmountToReverse < MaximumAmountToReverse THEN BEGIN
              AmountToReverse := RemainingAmountToReverse;
              QuantityToReverse := RemainingQuantityToReverse;
              BudgetedQuantityToReverse := RemainingBudgetedQtyToReverse;
            END ELSE BEGIN
              AmountToReverse := MaximumAmountToReverse;
              QuantityToReverse := 0;
              IF RemainingQuantityToReverse <> 0 THEN
                QuantityToReverse := RemainingQuantityToReverse * (MaximumAmountToReverse / RemainingAmountToReverse) ;
              BudgetedQuantityToReverse := 0;
              IF RemainingBudgetedQtyToReverse <> 0 THEN
                BudgetedQuantityToReverse := RemainingBudgetedQtyToReverse * (MaximumAmountToReverse / RemainingAmountToReverse) ;
            END;

            IF LineAllocationWithGLAccounts AND (Amount > 0) AND (AmountToReverse > 0) THEN BEGIN
              IF AmountToReverse > RemainingAmountDebitAllocation THEN
                AmountToReverse := RemainingAmountDebitAllocation;
              RemainingAmountDebitAllocation -= AmountToReverse;
            END;
          END;

          IF AmountToReverse <> 0 THEN BEGIN
            xferCustomFields.GLEntryTOGenJnlLine(GenJnlLine,GLEntry,FALSE,FALSE);
            GenJnlLine."Source Table ID" := DATABASE::"Purchase Line";
            GenJnlLine."Document No." := DocumentNo;
            GenJnlLine."Posting Date" := PostingDate;
            GenJnlLine."Document Date" := PostingDate;

            GenJnlLine."Allocation No." := AllocationNo;
            IF ("G/L Account No." = ReserveAccountNo) AND (NOT FundManagement.CheckAPDistributed) THEN BEGIN
              GenJnlLine."Allocation No." := '';
            END;
            IF (GenJnlLine."Allocation No." <> '') AND
               ((GenJnlLine."Account No." <> ReserveAccountNo) OR FundManagement.CheckAPDimensionByInvoiceLine) THEN BEGIN
              PurchaseLine.SETCURRENTKEY("Internal Control No.");
              PurchaseLine.SETRANGE("Internal Control No.","Internal Control No.");
              IF PurchaseLine.FINDFIRST THEN BEGIN
                DimMgt.DIMPurchLineTOGenJnlLine(PurchaseLine,GenJnlLine);
              END;
            END;

            GenJnlLine."Gen. Posting Type" := GenJnlLine."Gen. Posting Type"::Default;
            GenJnlLine."Gen. Bus. Posting Group" := '';
            GenJnlLine."Gen. Prod. Posting Group" := '';
            GenJnlLine."VAT Posting" := GenJnlLine."VAT Posting"::"Manual VAT Entry";
            GenJnlLine."VAT %" := 0;
            GenJnlLine."VAT Amount" := 0;
            GenJnlLine."VAT Base Amount" := GenJnlLine.Amount;
            GenJnlLine."VAT Bus. Posting Group" := '';
            GenJnlLine."VAT Prod. Posting Group" := '';

            IF PartialReverse OR FullReverse THEN BEGIN
              IF Amount > 0 THEN BEGIN
                GenJnlLine.VALIDATE(Amount,-AmountToReverse);
                GenJnlLine.Quantity := -QuantityToReverse;
                GenJnlLine."Budgeted Quantity" := -BudgetedQuantityToReverse;
              END ELSE BEGIN
                GenJnlLine.VALIDATE(Amount, AmountToReverse);
                GenJnlLine.Quantity := QuantityToReverse;
                GenJnlLine."Budgeted Quantity" := BudgetedQuantityToReverse;
              END;
            END;

            IF "G/L Account No." = ReserveAccountNo THEN BEGIN
              GenJnlLine.Quantity := 0;
              GenJnlLine."Budgeted Quantity" := 0;
            END;

            GenJnlLine."Original Currency Code" := "Original Currency Code";
            IF GenJnlLine."Original Currency Code" IN ['',GLSetup."LCY Code"] THEN BEGIN
              GenJnlLine."Original Currency Amount" := GenJnlLine.Amount;
            END ELSE IF Amount = -GenJnlLine.Amount THEN BEGIN
              GenJnlLine."Original Currency Amount" := -"Original Currency Amount";
            END ELSE IF AllocationNo = '' THEN BEGIN
              GenJnlLine."Original Currency Amount" := -"Original Currency Amount";
            END ELSE BEGIN
              GenJnlLine."Original Currency Amount" :=
                ROUND(CurrExchRate.ExchangeAmtLCYToFCY(
                      "Posting Date","Original Currency Code",GenJnlLine.Amount,
                        CurrExchRate.ExchangeRate("Posting Date","Original Currency Code")));
            END;
            GenJnlLine."Source Currency Code" := GenJnlLine."Original Currency Code";
            GenJnlLine."Source Currency Amount" := GenJnlLine."Original Currency Amount";

            GenJnlPostLine2.RunWithCheck(GenJnlLine);
          END;

          IF AllocationNo <> '' THEN BEGIN
            IF GLAccountFilter = '' THEN
              GLAccountFilter := "G/L Account No."
            ELSE
              GLAccountFilter := GLAccountFilter + '|' + "G/L Account No.";

            Complete := FALSE;
            REPEAT
              IF NEXT = 0 THEN BEGIN
                FINDLAST;
                Complete := TRUE;
              END ELSE IF STRPOS(GLAccountFilter,"G/L Account No.") = 0 THEN BEGIN
                NEXT(-1);
                Complete := TRUE;
              END;
            UNTIL Complete;
          END;

        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE RequisitionSubmit@45(VAR RequisitionHeader@1102602000 : Record 37001090);
    VAR
      RequisitionLine@1102602012 : Record 37001091;
      SubmitOccured@1102634000 : Boolean;
    BEGIN
      WITH RequisitionHeader DO
        IF "Document Status" <> "Document Status"::New THEN
          EXIT;

      WITH RequisitionLine DO BEGIN
        SETRANGE("Document No.",RequisitionHeader."No.");
        IF COUNT = 0 THEN
          EXIT;

        //Transaction-Level Approval Logic
        SETFILTER(Type,'<>%1',Type::" ");
        SETFILTER("No.",'<>%1','');
        SETFILTER(Quantity,'<>0');
        SETRANGE(Status,Status::New);

        IF FINDSET(FALSE,FALSE) THEN BEGIN
          // Check for Document-Level Approval Rules that generate Error Messages

          IF NavigatorManagement.DocumentLevelApprovalsLicensed("Source Code") THEN BEGIN
            WorkflowManagement.DocumentApprovalCheck(
              DATABASE::"Purchase Requisition Header",RequisitionHeader."Internal Control No.",TRUE);
          END;
          REPEAT
            RequisitionSubmitLine(RequisitionLine);
         //   ERROR(format(Status));   //Amos
              SubmitOccured := TRUE;

      //     additional code for committed chacha  : meant for disposition, commented awaiting further ddata and testing
             {
              Workflow.RESET;
              Workflow.SETRANGE(Workflow.Code,'01');
              IF Workflow.Active   THEN BEGIN
                 //add code to post to gl    or function



                RequisitionLine.Status:=RequisitionLine.Status::Committed;
                RequisitionLine.MODIFY;
                END
       //end of additional code
               }

          UNTIL NEXT = 0;

          IF NavigatorManagement.ApprovalsLicensed("Source Code") OR NavigatorManagement.BudgetLicensed("Source Code") THEN
            WorkflowManagement.InsertEmailLedgEntry;
        END;

        RequisitionSubmitDocument(RequisitionHeader,SubmitOccured);  //Document-Level Approval Logic
        IF NOT SubmitOccured THEN
          MESSAGE(SNText27);
      END;
                                                             //**
    END;

    PROCEDURE RequisitionSubmitLine@1102602034(VAR RequisitionLine@1102602000 : Record 37001091);
    BEGIN
      PurchSetup.GET;
      WITH RequisitionLine DO BEGIN
        IF (Type = Type::" ") OR ("No." = '') THEN
          EXIT;

        IF PurchSetup."Post Commitments" THEN BEGIN
           IF NOT (Status IN [Status::New,Status::Approved]) THEN
            EXIT;
        END ELSE IF Status <> Status::New THEN BEGIN
          EXIT;
        END;

        "Previous Status" := Status;
        "Purchaser Code" := SetPurchaserCode("Internal Control No.");
        MODIFY;

        IF NavigatorManagement.BudgetLicensed("Source Code") THEN BEGIN
          Status := WorkflowManagement.BudgetCheck("Internal Control No.",FALSE);
        END;

        IF NavigatorManagement.ApprovalsLicensed("Source Code") AND (Status <> Status::"Transfer Budget Pending") THEN BEGIN
          Status := WorkflowManagement.TransactionApprovalCheck("Internal Control No.");
        END;
        MODIFY;

        DocumentHistoryWriteLine(DATABASE::"Purchase Requisition Line","Document No.",'',"Internal Control No.",8);
      END;
    END;

    PROCEDURE RequisitionSubmitDocument@1102634008(VAR RequisitionHeader@1102602000 : Record 37001090;VAR SubmitOccured@1102634001 : Boolean);
    VAR
      RequisitionLine@1102602012 : Record 37001091;
      InTransactionApprovalProcess@1102634000 : Boolean;
    BEGIN
      WITH RequisitionLine DO BEGIN                                  //**
        SETRANGE("Document No.",RequisitionHeader."No.");
        IF COUNT = 0 THEN
          EXIT;

        //Document-Level Approval Logic
        SETFILTER(Type,'<>%1',Type::" ");
        SETFILTER("No.",'<>%1','');
        SETFILTER(Quantity,'<>0');
        SETRANGE(Status,Status::New,Status::"Transfer Budget Pending");
        InTransactionApprovalProcess := FINDSET(FALSE,FALSE);
      END;

      WITH RequisitionHeader DO BEGIN
        IF NOT InTransactionApprovalProcess THEN BEGIN
        //chacha- code  for the workflow approval , testing
          IF NavigatorManagement.DocumentLevelApprovalsLicensed("Source Code") THEN BEGIN
            "Document Status" :=
              WorkflowManagement.DocumentApprovalCheck(DATABASE::"Purchase Requisition Header","Internal Control No.",FALSE);
            WorkflowManagement.InsertEmailLedgEntry;
          END ELSE BEGIN
            "Document Status" := "Document Status"::Approved;
          END;
          MODIFY;
          SubmitOccured := TRUE;

          IF "Document Status" = "Document Status"::Approved THEN BEGIN
          //commitment -chacha
            DocumentHistoryWriteLine(DATABASE::"Purchase Requisition Header","No.",'',"Internal Control No.",10);
            DeleteLineDistributionBuffer("Internal Control No.");
            PurchSetup.GET;
            // smh
            IF PurchSetup."Post Commitments" THEN BEGIN
              RequisitionCommitmentPost(RequisitionHeader);
            END;
          END;
        END;
      END;
    END;

    PROCEDURE RequisitionCommitmentPost@1102634003(VAR RequisitionHeader@1102634000 : Record 37001090);
    VAR
      RequisitionLine@1102634005 : Record 37001091;
      GenJnlLine@1102634006 : Record 81;
      GLRegisterNo@1102634001 : Integer;
    BEGIN
      PurchSetup.GET;
      IF NOT PurchSetup."Post Commitments" THEN BEGIN
        MESSAGE(SNText10);
        EXIT;
      END;

      WITH RequisitionLine DO BEGIN
        SETRANGE("Document No.",RequisitionHeader."No.");
        SETFILTER(Type,'<>%1',Type::" ");
        SETFILTER("No.",'<>%1','');
        SETFILTER(Quantity,'<>0');
        SETRANGE(Status,Status::Approved);
        IF FINDSET(TRUE,FALSE) THEN BEGIN
          REPEAT
            LDBManagement.LDBRequisitionLineTOGenJnlLine(GenJnlLine,RequisitionLine);
            GenJnlLine."Gen. Posting Type" := GenJnlLine."Gen. Posting Type"::Default;
            GenJnlLine."Gen. Bus. Posting Group" := '';
            GenJnlLine."Gen. Prod. Posting Group" := '';
            GenJnlLine."VAT Posting" := GenJnlLine."VAT Posting"::"Manual VAT Entry";
            GenJnlLine."VAT %" := 0;
            GenJnlLine."VAT Amount" := 0;
            GenJnlLine."VAT Base Amount" := GenJnlLine.Amount;
            GenJnlLine."VAT Bus. Posting Group" := '';
            GenJnlLine."VAT Prod. Posting Group" := '';
            GenJnlLine."Bal. Account Type" := GenJnlLine."Bal. Account Type"::"G/L Account";
            GenJnlLine."Bal. Account No." := '';

            GenJnlPostLine.RunWithCheck(GenJnlLine);
            GLRegisterNo := GenJnlLine."G/L Register No.";

            RequisitionCommitmentBalEntry(GenJnlLine,RequisitionLine);
            GenJnlPostLine.RunWithCheck(GenJnlLine);
            IF GLRegisterNo = 0 THEN
              GLRegisterNo := GenJnlLine."G/L Register No.";
            FundManagement.CheckFundBalance(GLRegisterNo);

            Status := Status::Committed;
            MODIFY;
            DeleteLineDistributionBuffer("Internal Control No.");
          UNTIL NEXT = 0;
        END;
      END;

      WITH RequisitionHeader DO BEGIN
        "Document Status" := "Document Status"::Committed;
        MODIFY;
        DeleteLineDistributionBuffer("Internal Control No.");
      END;
    END;

    PROCEDURE RequisitionCommitmentBalEntry@1102602027(VAR GenJnlLine@1102602000 : Record 81;RequisitionLine@1102602003 : Record 37001091);
    VAR
      Vendor@1102602002 : Record 23;
      VendorPostingGroup@1102602004 : Record 93;
      RequisitionHeader@1102633000 : Record 37001090;
      PostGroup@1102602005 : Code[10];
    BEGIN
      PurchSetup.GET;
      IF NOT PurchSetup."Post Commitments" THEN
        EXIT;

      WITH GenJnlLine DO BEGIN
        IF FundManagement.CheckAPDistributed THEN
          "Allocation No." := RequisitionLine."Allocation No."
        ELSE
          "Allocation No." := '';

        IF RequisitionLine."Buy-from Vendor No." <> '' THEN BEGIN
          Vendor.GET(RequisitionLine."Buy-from Vendor No.");
          IF Vendor."Proposed Vendor" THEN
            PostGroup := PurchSetup."Default Vendor Posting Group"
          ELSE BEGIN
            Vendor.TESTFIELD("Vendor Posting Group");
            PostGroup := Vendor."Vendor Posting Group";
          END;
        END ELSE
          PostGroup := PurchSetup."Default Vendor Posting Group";

        VendorPostingGroup.GET(PostGroup);
        VendorPostingGroup.TESTFIELD("Reserve for Commitments Acc.");

        "Account Type" := "Account Type"::"G/L Account";
        VALIDATE("Account No.",VendorPostingGroup."Reserve for Commitments Acc.");

        RequisitionHeader.GET(RequisitionLine."Document No.");
        IF RequisitionHeader."Prices Including VAT" AND (RequisitionLine."VAT %" <> 0) THEN
          VALIDATE(Amount, -RequisitionLine.Amount / (1 + RequisitionLine."VAT %" / 100))
        ELSE
          VALIDATE(Amount,-RequisitionLine.Amount);
        VALIDATE("Currency Code",RequisitionLine."Currency Code");
        VALIDATE("Amount (LCY)");
        Quantity := 0;
        "Budgeted Quantity" := 0;

        IF NOT FundManagement.CheckAPDistributed THEN
          VALIDATE("Fund No.","Ctl. Fund No.");

        "System-Created Entry" := TRUE;

        Description := CommitmentDescription;
        DimMgt.DIMRequistionLineTOGenJnlLine(RequisitionLine,GenJnlLine);
        IF NOT FundManagement.CheckAPDistributed THEN BEGIN
          IF AVSetup.READPERMISSION AND AVSetup.GET THEN BEGIN
            CASE AVSetup."Subaward Dimension No." - 1 OF
              1 : VALIDATE("Shortcut Dimension 1 Code", '');
              2 : VALIDATE("Shortcut Dimension 2 Code", '');
              3 : VALIDATE("Shortcut Dimension 3 Code", '');
              4 : VALIDATE("Shortcut Dimension 4 Code", '');
              5 : VALIDATE("Shortcut Dimension 5 Code", '');
              6 : VALIDATE("Shortcut Dimension 6 Code", '');
              7 : VALIDATE("Shortcut Dimension 7 Code", '');
              8 : VALIDATE("Shortcut Dimension 8 Code", '');
            END;
            CASE AVSetup."Restriction Dimension No." - 1 OF
              1 : VALIDATE("Shortcut Dimension 1 Code", '');
              2 : VALIDATE("Shortcut Dimension 2 Code", '');
              3 : VALIDATE("Shortcut Dimension 3 Code", '');
              4 : VALIDATE("Shortcut Dimension 4 Code", '');
              5 : VALIDATE("Shortcut Dimension 5 Code", '');
              6 : VALIDATE("Shortcut Dimension 6 Code", '');
              7 : VALIDATE("Shortcut Dimension 7 Code", '');
              8 : VALIDATE("Shortcut Dimension 8 Code", '');
            END;
          END;
        END;
      END;
    END;

    PROCEDURE PurchaseSubmit@1102602026(PurchaseHeader@1102602000 : Record 38);
    VAR
      PurchaseLine@1102602012 : Record 39;
      SubmitOccured@1102634000 : Boolean;
    BEGIN
      WITH PurchaseHeader DO
        IF "Document Status" <> "Document Status"::New THEN
          EXIT;

      WITH PurchaseLine DO BEGIN
        SETRANGE("Document Type",PurchaseHeader."Document Type");
        SETRANGE("Document No.",PurchaseHeader."No.");
        IF COUNT = 0 THEN
          EXIT;

        SETFILTER(Type,'<>%1',Type::" ");
        SETFILTER("No.",'<>%1','');
        SETFILTER(Quantity,'<>0');
        SETRANGE(Status,Status::New);

        IF FINDSET(FALSE,FALSE) THEN BEGIN
          // Check for Document-Level Approval Rules that generate Error Messages
          IF NavigatorManagement.DocumentLevelApprovalsLicensed("Source Code") THEN BEGIN
            WorkflowManagement.DocumentApprovalCheck(DATABASE::"Purchase Header",PurchaseHeader."Internal Control No.",TRUE);
          END;

          REPEAT
            IF "Change Order" AND (Quantity < 0) THEN BEGIN
              PurchaseChangeOrder(PurchaseLine)
            END ELSE BEGIN
              PurchaseSubmitLine(PurchaseLine);
            END;
            SubmitOccured := TRUE;
          UNTIL NEXT = 0;

          IF NavigatorManagement.ApprovalsLicensed("Source Code") OR NavigatorManagement.BudgetLicensed("Source Code") THEN
            WorkflowManagement.InsertEmailLedgEntry;
        END;

        PurchaseSubmitDocument(PurchaseHeader,SubmitOccured);  //Document-Level Approval Logic
        IF NOT SubmitOccured THEN
          MESSAGE(SNText02);
      END;
    END;

    PROCEDURE PurchaseSubmitLine@1102602029(VAR PurchaseLine@1102602000 : Record 39);
    BEGIN
      PurchSetup.GET;

      WITH PurchaseLine DO BEGIN
        IF (Type = Type::" ") OR ("No." = '') THEN
          EXIT;

        IF PurchSetup."Post Encumbrances" THEN BEGIN
          IF NOT (Status IN [Status::New,Status::Approved]) THEN
            EXIT;
        END ELSE IF Status <> Status::New THEN BEGIN
          EXIT;
        END;

        IF NOT CheckProcurementTolerance(PurchaseLine) THEN BEGIN
          MESSAGE(SNText28,"Document No.","Line No.");
          EXIT;
        END;

        IF (PurchSetup."Workflow Processing" = PurchSetup."Workflow Processing"::"All Lines") OR (Status < Status::Approved) THEN BEGIN
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN BEGIN
            Status := WorkflowManagement.BudgetCheck("Internal Control No.",FALSE);
          END;
          IF NavigatorManagement.ApprovalsLicensed("Source Code") AND (Status <> Status::"Transfer Budget Pending") THEN BEGIN
            Status := WorkflowManagement.TransactionApprovalCheck("Internal Control No.");
          END;
          MODIFY;
        END;

        DocumentHistoryWriteLine(DATABASE::"Purchase Line","Document No.",'',"Internal Control No.",8);
      END;
    END;

    PROCEDURE PurchaseSubmitDocument@1102634023(VAR PurchaseHeader@1102634001 : Record 38;VAR SubmitOccured@1102634000 : Boolean);
    VAR
      PurchaseLine@1102634002 : Record 39;
      InTransactionApprovalProcess@1102634003 : Boolean;
    BEGIN
      WITH PurchaseLine DO BEGIN
        SETRANGE("Document No.",PurchaseHeader."No.");
        IF COUNT = 0 THEN
          EXIT;

        //Document-Level Approval Logic
        SETFILTER(Type,'<>%1',Type::" ");
        SETFILTER("No.",'<>%1','');
        SETFILTER(Quantity,'<>0');
        SETRANGE(Status,Status::New,Status::"Transfer Budget Pending");
        InTransactionApprovalProcess := FINDSET(FALSE,FALSE);
      END;

      WITH PurchaseHeader DO BEGIN
        IF NOT InTransactionApprovalProcess THEN BEGIN
          IF NavigatorManagement.DocumentLevelApprovalsLicensed("Source Code") THEN BEGIN
            "Document Status" := WorkflowManagement.DocumentApprovalCheck(DATABASE::"Purchase Header","Internal Control No.",FALSE);
            WorkflowManagement.InsertEmailLedgEntry;
          END ELSE BEGIN
            "Document Status" := "Document Status"::Approved;
          END;
          MODIFY;
          SubmitOccured := TRUE;

          IF "Document Status" = "Document Status"::Approved THEN BEGIN
            DocumentHistoryWriteLine(DATABASE::"Purchase Header","No.",'',"Internal Control No.",10);
            DeleteLineDistributionBuffer("Internal Control No.");
            PurchSetup.GET;
            IF PurchSetup."Post Encumbrances" THEN BEGIN
              PurchaseEncumbrancePost(PurchaseHeader);
            END;
          END;
        END;
      END;
    END;

    PROCEDURE PurchaseEncumbrancePost@1102634009(VAR PurchaseHeader@1102634000 : Record 38);
    VAR
      PurchaseLine@1102634001 : Record 39;
      BlanketOrderLine@1102634008 : Record 39;
      GenJnlLine@1102634007 : Record 81;
      RequisitionLine@1102634006 : Record 37001091;
      GLRegisterNo@1102634002 : Integer;
    BEGIN
      WITH PurchaseHeader DO
        IF NOT ("Document Type" IN ["Document Type"::Order,"Document Type"::"Blanket Order"]) THEN
          EXIT;

      PurchSetup.GET;
      IF NOT PurchSetup."Post Encumbrances" THEN BEGIN
        MESSAGE(SNText11);
        EXIT;
      END;

      WITH PurchaseLine DO BEGIN
        SETRANGE("Document No.",PurchaseHeader."No.");
        SETFILTER(Type,'<>%1',Type::" ");
        SETFILTER("No.",'<>%1','');
        SETFILTER(Quantity,'<>0');
        SETFILTER(Status,'%1|%2|%3',Status::New,Status::Approved,Status::Disapproved);
        IF FINDSET(TRUE,FALSE) THEN BEGIN
          REPEAT

            IF "Change Order" THEN BEGIN
              PurchaseChangeOrder(PurchaseLine);
            END;

            IF BlanketOrderLine.GET("Document Type"::"Blanket Order","Blanket Order No.","Blanket Order Line No.") THEN BEGIN
              ReverseEncumbrancePost(BlanketOrderLine."Internal Control No.", "Document No.", PurchaseHeader."Posting Date", FALSE, TRUE
      ,
                                     Quantity*BlanketOrderLine."Unit Cost (LCY)", BlanketOrderLine."Allocation No.", GenJnlPostLine);
            END;

            IF RequisitionLine.GET(PurchaseLine."Purchase Requisition No.",PurchaseLine."Purchase Requisition Line No.") THEN BEGIN
              IF Status = Status::Disapproved THEN BEGIN
                RequisitionLine."Previous Status" := RequisitionLine.Status;
                RequisitionLine.Status := RequisitionLine.Status::Committed;
                RequisitionLine.Decision := RequisitionLine.Decision::" ";
                RequisitionLine."Target No." := '';
                RequisitionLine."Fulfillment Doc. No." := '';
                RequisitionLine."Fulfillment Doc. Line No." := 0;
                RequisitionLine.MODIFY;
                GenDistBufferRequisitionLine(RequisitionLine);
              END ELSE BEGIN
                ReverseCommitmentPost(RequisitionLine."Internal Control No.", "Document No.", PurchaseHeader."Posting Date",
                                      "Allocation No.");
              END;
            END;

            LDBManagement.LDBPurchaseLineTOGenJnlLine(GenJnlLine,PurchaseLine);
            GenJnlLine."VAT Posting" := GenJnlLine."VAT Posting"::"Manual VAT Entry";
            GenJnlLine."VAT %" := 0;
            GenJnlLine."VAT Amount" := 0;
            GenJnlLine."VAT Base Amount" := GenJnlLine.Amount;
            GenJnlLine."VAT Bus. Posting Group" := '';
            GenJnlLine."VAT Prod. Posting Group" := '';
            GenJnlLine."Bal. Account Type" := GenJnlLine."Bal. Account Type"::"G/L Account";
            GenJnlLine."Bal. Account No." := '';

            GenJnlPostLine.RunWithCheck(GenJnlLine);
            GLRegisterNo := GenJnlLine."G/L Register No.";

            PurchaseEncumbranceBalEntry(GenJnlLine,PurchaseLine);
            GenJnlPostLine.RunWithCheck(GenJnlLine);
            IF GLRegisterNo = 0 THEN
              GLRegisterNo := GenJnlLine."G/L Register No.";
            FundManagement.CheckFundBalance(GLRegisterNo);

            Status := Status::Encumbered;
            MODIFY;
            DeleteLineDistributionBuffer("Internal Control No.");
          UNTIL NEXT = 0;
        END;
      END;

      WITH PurchaseHeader DO BEGIN
        "Document Status" := "Document Status"::Encumbered;
        MODIFY;
        DeleteLineDistributionBuffer("Internal Control No.");
      END;
    END;

    PROCEDURE PurchaseEncumbranceBalEntry@1102602025(VAR GenJnlLine@1102602000 : Record 81;PurchaseLine@1102602003 : Record 39);
    VAR
      Vendor@1102602002 : Record 23;
      VendorPostingGroup@1102602004 : Record 93;
      PurchaseHeader@1102633000 : Record 38;
      PostGroup@1102602005 : Code[10];
    BEGIN
      PurchSetup.GET;
      IF NOT PurchSetup."Post Encumbrances" THEN
        EXIT;

      WITH GenJnlLine DO BEGIN
        "Allocation No." := '';
        IF FundManagement.CheckAPDistributed THEN BEGIN
          "Allocation No." := PurchaseLine."Allocation No.";
        END;

        Vendor.GET(PurchaseLine."Buy-from Vendor No.");
        Vendor.TESTFIELD("Vendor Posting Group");
        VendorPostingGroup.GET(Vendor."Vendor Posting Group");
        VendorPostingGroup.TESTFIELD("Reserve for Encumbrances Acc.");

        "Account Type" := "Account Type"::"G/L Account";
        VALIDATE("Account No.",VendorPostingGroup."Reserve for Encumbrances Acc.");

        PurchaseHeader.GET(PurchaseLine."Document Type",PurchaseLine."Document No.");
        IF PurchaseHeader."Prices Including VAT" AND (PurchaseLine."VAT %" <> 0) THEN BEGIN
          VALIDATE(Amount, -(PurchaseLine."Line Amount"+PurchaseLine."Line Discount Amount"{+PurchaseLine."Tax To Be Expensed"}) /
                            (1 + PurchaseLine."VAT %" / 100))
        END ELSE BEGIN
          VALIDATE(Amount,-(PurchaseLine."Line Amount"+PurchaseLine."Line Discount Amount"{+PurchaseLine."Tax To Be Expensed"}));
        END;

        VALIDATE("Currency Code",PurchaseLine."Currency Code");
        VALIDATE("Amount (LCY)");
        Quantity := 0;
        "Budgeted Quantity" := 0;

        IF NOT FundManagement.CheckAPDistributed THEN BEGIN
          VALIDATE("Fund No.","Ctl. Fund No.");
        END;

        Description := EncumbranceDescription;
        "Gen. Posting Type" := "Gen. Posting Type"::Purchase;
        "Gen. Bus. Posting Group" := PurchaseLine."Gen. Bus. Posting Group";
        "Gen. Prod. Posting Group" := PurchaseLine."Gen. Prod. Posting Group";
        "VAT Calculation Type" := PurchaseLine."VAT Calculation Type";
        "Source Type" := "Source Type"::Vendor;
        "Source No." := PurchaseLine."Buy-from Vendor No.";
        "System-Created Entry" := TRUE;

        IF FundManagement.CheckAPDimensionByInvoiceLine THEN BEGIN
          DimMgt.DIMPurchLineTOGenJnlLine(PurchaseLine,GenJnlLine)
        END ELSE BEGIN
          DimMgt.DIMVendPostGroupTOGenJnlLine(VendorPostingGroup,GenJnlLine);
        END;

        IF NOT FundManagement.CheckAPDistributed THEN BEGIN
          IF AVSetup.READPERMISSION AND AVSetup.GET THEN BEGIN
            CASE AVSetup."Subaward Dimension No." - 1 OF
              1 : VALIDATE("Shortcut Dimension 1 Code", '');
              2 : VALIDATE("Shortcut Dimension 2 Code", '');
              3 : VALIDATE("Shortcut Dimension 3 Code", '');
              4 : VALIDATE("Shortcut Dimension 4 Code", '');
              5 : VALIDATE("Shortcut Dimension 5 Code", '');
              6 : VALIDATE("Shortcut Dimension 6 Code", '');
              7 : VALIDATE("Shortcut Dimension 7 Code", '');
              8 : VALIDATE("Shortcut Dimension 8 Code", '');
            END;
            CASE AVSetup."Restriction Dimension No." - 1 OF
              1 : VALIDATE("Shortcut Dimension 1 Code", '');
              2 : VALIDATE("Shortcut Dimension 2 Code", '');
              3 : VALIDATE("Shortcut Dimension 3 Code", '');
              4 : VALIDATE("Shortcut Dimension 4 Code", '');
              5 : VALIDATE("Shortcut Dimension 5 Code", '');
              6 : VALIDATE("Shortcut Dimension 6 Code", '');
              7 : VALIDATE("Shortcut Dimension 7 Code", '');
              8 : VALIDATE("Shortcut Dimension 8 Code", '');
            END;
          END;
        END;

        GenerateDistBuffer(GenJnlLine);
        LDBManagement.CheckFailedValidation(GenJnlLine);
      END;
    END;

    PROCEDURE PurchaseReEncumberLine@1102602024(PurchaseLine@1102602000 : Record 39;QtyToEncumber@1102602004 : Decimal);
    VAR
      GenJnlLine@1102602011 : Record 81;
      RequisitionLine@1102602003 : Record 37001091;
      GLRegisterNo@1102628000 : Integer;
    BEGIN
      PurchSetup.GET;
      IF NOT PurchSetup."Post Encumbrances" THEN
        EXIT;

      WITH PurchaseLine DO BEGIN
        IF (Type = Type::" ") OR ("No." = '') OR (QtyToEncumber <= 0) THEN
          EXIT;

        IF Amount <> 0 THEN BEGIN
          LDBManagement.LDBPurchaseLineTOGenJnlLine(GenJnlLine,PurchaseLine);
          GenJnlLine.VALIDATE(Amount,PurchaseLine."Direct Unit Cost" * QtyToEncumber);
          GenJnlLine."VAT Posting" := GenJnlLine."VAT Posting"::"Manual VAT Entry";
          GenJnlLine."VAT %" := 0;
          GenJnlLine."VAT Amount" := 0;
          GenJnlLine."VAT Base Amount" := GenJnlLine.Amount;
          GenJnlLine."VAT Bus. Posting Group" := '';
          GenJnlLine."VAT Prod. Posting Group" := '';
          GenJnlLine."Bal. Account Type" := GenJnlLine."Bal. Account Type"::"G/L Account";
          GenJnlLine."Bal. Account No." := '';

          GenJnlPostLine.RunWithCheck(GenJnlLine);
          GLRegisterNo := GenJnlLine."G/L Register No.";

          PurchaseEncumbranceBalEntry(GenJnlLine,PurchaseLine);
          GenJnlLine.VALIDATE(Amount,-PurchaseLine."Direct Unit Cost" * QtyToEncumber);
          GenJnlPostLine.RunWithCheck(GenJnlLine);
          IF GLRegisterNo = 0 THEN
            GLRegisterNo := GenJnlLine."G/L Register No.";
          FundManagement.CheckFundBalance(GLRegisterNo);
        END;

        DeleteLineDistributionBuffer("Internal Control No.");
      END;
    END;

    PROCEDURE PurchaseChangeOrder@1102602006(VAR PurchaseLine@1102602000 : Record 39);
    VAR
      PurchaseLineToChange@1102602001 : Record 39;
      TempStatus@1102602002 : 'New,Approval Pending,Transfer Budget Pending,Approved,Disapproved,,Encumbered,Partial Received,Received,Invoiced,,Canceled';
    BEGIN
      WITH PurchaseLine DO BEGIN
        IF "Document Type" <> "Document Type"::"Blanket Order" THEN
          EXIT;

        PurchaseLineToChange.GET(PurchaseLine."Document Type",PurchaseLine."Document No.",PurchaseLine."Change Line No.");
        IF NOT (PurchaseLineToChange.Status IN [PurchaseLineToChange.Status::Encumbered,
                                                PurchaseLineToChange.Status::"Partial Received",
                                                PurchaseLineToChange.Status::Received]) THEN
          ERROR(SNText22);

        //Decrease Qty and Encumberance
        IF Quantity <= 0 THEN BEGIN
          IF ABS(Quantity) > PurchaseLineToChange."Qty. to Draw Down" THEN
            Quantity := -PurchaseLineToChange."Qty. to Draw Down";
          PurchaseLineToChange.Quantity += Quantity;
          ReverseEncumbrancePost(PurchaseLineToChange."Internal Control No.","Document No.",TODAY,
                                 FALSE,TRUE,Quantity*PurchaseLineToChange."Unit Cost (LCY)",PurchaseLineToChange."Allocation No.",
                                 GenJnlPostLine);

        //Increase Qty and Encumberance
        END ELSE IF Status = Status::Approved THEN BEGIN
          PurchaseLineToChange.Quantity += Quantity;
          PurchaseReEncumberLine(PurchaseLineToChange,"Change Order Quantity");
        END;

        TempStatus := PurchaseLineToChange.Status;
        PurchaseLineToChange.Status := PurchaseLineToChange.Status::New;
        PurchaseLineToChange.VALIDATE(Quantity);
        PurchaseLineToChange.InitQtyToReceive;
        PurchaseLineToChange.InitQtyToShip;
        PurchaseLineToChange.InitQtyToInvoice;
        PurchaseLineToChange.Status := TempStatus;
        PurchaseLineToChange.MODIFY;

        "Change Order Quantity" := Quantity;
        Status := Status::New;
        VALIDATE(Quantity, 0);
        Status := Status::Canceled;
        MODIFY;
        DeleteLineDistributionBuffer("Internal Control No.");

      END;
    END;

    PROCEDURE GenJournalSubmit@1102602023(TempGenJnlLine@1102602000 : Record 81);
    VAR
      GenJnlLine@1102602011 : Record 81;
    BEGIN
      WITH GenJnlLine DO BEGIN    //**
        SETRANGE("Journal Template Name",TempGenJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempGenJnlLine."Journal Batch Name");
        SETFILTER("Account No.",'<>%1','');
        SETRANGE(Status,Status::New);
        SETFILTER(Amount,'<>0');

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText13);
          EXIT;
        END;

        REPEAT
          TESTFIELD("Document No.");
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN
            Status := WorkflowManagement.BudgetCheck("Internal Control No.",FALSE);

          IF NavigatorManagement.ApprovalsLicensed("Source Code") AND
             (Status <> Status::"Transfer Budget Pending") THEN
            Status := WorkflowManagement.TransactionApprovalCheck("Internal Control No.");

          CheckAutomaticApproval("Source Code",Status,"Document Post Status");

          MODIFY;
          VALIDATE(Status);

          IF Status > Status::Approved THEN
            DeleteLineDistributionBuffer("Internal Control No.");
        UNTIL NEXT = 0;

        IF NavigatorManagement.ApprovalsLicensed("Source Code") OR NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.InsertEmailLedgEntry;
      END;
    END;

    PROCEDURE "-----TBL Amos--08/01/15---------------------------------------------------------------------------------------------------------"@1000000000();
    BEGIN
    END;

    PROCEDURE FixedAssetJournalSubmit@1000000001(TempFixedAssetJnlLine@1102602000 : Record 5621);
    VAR
      FixedAssetJnlLine@1102602011 : Record 5621;
      GenJnlLine@1102602001 : Record 81;
    BEGIN

      WITH FixedAssetJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempFixedAssetJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempFixedAssetJnlLine."Journal Batch Name");
        SETFILTER("FA No.",'<>%1','');
        SETRANGE(Status,Status::New);
        SETFILTER(Amount,'<>0');


        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText13);
          EXIT;
        END;

        REPEAT
          TESTFIELD("Document No.");
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN
            Status := WorkflowManagement.BudgetCheck("Internal Control No.",FALSE);

          IF NavigatorManagement.ApprovalsLicensed("Source Code") AND (Status <> Status::"Transfer Budget Pending") THEN
            Status := WorkflowManagement.TransactionApprovalCheck("Internal Control No.");

          CheckAutomaticApproval( "Source Code",Status,"Document Post Status");

          MODIFY;
          VALIDATE(Status);

          IF Status > Status::Approved THEN
            DeleteLineDistributionBuffer("Internal Control No.");
        UNTIL NEXT = 0;

        IF NavigatorManagement.ApprovalsLicensed("Source Code") OR NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.InsertEmailLedgEntry;
      END;
    END;

    PROCEDURE "----TBL Amos--08/01/15------ -----------------end-------------------------------------------------------------------------------"@1000000002();
    BEGIN
    END;

    PROCEDURE ItemJournalSubmit@1102602013(TempItemJnlLine@1102602000 : Record 83);
    VAR
      ItemJnlLine@1102602011 : Record 83;
      GenJnlLine@1102602001 : Record 81;
    BEGIN
      WITH ItemJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempItemJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempItemJnlLine."Journal Batch Name");
        SETFILTER("Item No.",'<>%1','');
        SETRANGE(Status,Status::New);
        SETFILTER(Quantity,'<>0');

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText13);
          EXIT;
        END;

        REPEAT
          TESTFIELD("Document No.");
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN
            Status := WorkflowManagement.BudgetCheck("Internal Control No.",FALSE);
          IF NavigatorManagement.ApprovalsLicensed("Source Code") AND
             (Status <> Status::"Transfer Budget Pending") THEN
            Status := WorkflowManagement.TransactionApprovalCheck("Internal Control No.");
          CheckAutomaticApproval("Source Code",Status, "Document Post Status");

          MODIFY;
          VALIDATE(Status);

          IF Status > Status::Approved THEN
            DeleteLineDistributionBuffer("Internal Control No.");
        UNTIL NEXT = 0;

        IF NavigatorManagement.ApprovalsLicensed("Source Code") OR NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.InsertEmailLedgEntry;
      END;
    END;

    PROCEDURE PayrollJournalSubmit@1102602045(TempPayrollJnlLine@1102602000 : Record 37032302);
    VAR
      PayrollJnlLine@1102602011 : Record 37032302;
      GenJnlLine@1102602001 : Record 81;
    BEGIN
      WITH PayrollJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempPayrollJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempPayrollJnlLine."Journal Batch Name");
        SETFILTER("Employee No.",'<>%1','');
        SETRANGE(Status,Status::New);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText13);
          EXIT;
        END;

        REPEAT
          TESTFIELD("Document No.");
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN
            Status := WorkflowManagement.BudgetCheck("Internal Control No.",FALSE);
          IF NavigatorManagement.ApprovalsLicensed("Source Code") AND
             (Status <> Status::"Transfer Budget Pending") THEN
            Status := WorkflowManagement.TransactionApprovalCheck("Internal Control No.");
          CheckAutomaticApproval("Source Code",Status,"Document Post Status");
          MODIFY;
          VALIDATE(Status);

          IF Status > Status::Approved THEN
            DeleteLineDistributionBuffer("Internal Control No.");
        UNTIL NEXT = 0;

        IF NavigatorManagement.ApprovalsLicensed("Source Code") OR NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.InsertEmailLedgEntry;
      END;
    END;

    PROCEDURE SalesSubmit@1102602083(SalesHeader@1102602000 : Record 36);
    VAR
      SalesLine@1102602012 : Record 37;
    BEGIN
      SalesSetup.GET;
      WITH SalesLine DO BEGIN
        SETRANGE("Document Type",SalesHeader."Document Type");
        SETRANGE("Document No.",SalesHeader."No.");
        SETFILTER(Type,'<>%1',Type::" ");
        SETFILTER("No.",'<>%1','');
        SETFILTER(Quantity,'<>0');
        SETRANGE(Status,Status::New);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText13);
          EXIT;
        END;

        REPEAT
          IF NavigatorManagement.ApprovalsLicensed("Source Code") THEN
            Status := WorkflowManagement.TransactionApprovalCheck("Internal Control No.");
          CheckAutomaticApproval2("Source Code",Status);
          MODIFY;

          IF Status > Status::Approved THEN
            DeleteLineDistributionBuffer("Internal Control No.");
        UNTIL NEXT = 0;

        IF NavigatorManagement.ApprovalsLicensed("Source Code") OR NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.InsertEmailLedgEntry;
      END;
    END;

    PROCEDURE CheckProcurementTolerance@1102602043(PurchaseLine@1102602000 : Record 39) : Boolean;
    VAR
      PurchaseHeader@1102602008 : Record 38;
      PurchaseRequisitionLine@1102602001 : Record 37001091;
      PurchRcptLine@1102602002 : Record 121;
      PurchaseLine2@1102602003 : Record 39;
      Currency@1102602005 : Record 4;
      CurrExchRate@1102602006 : Record 330;
      ToleranceAmount@1102602004 : Decimal;
      ForeignCurrencyMaxAmount@1102602007 : Decimal;
    BEGIN
      PurchSetup.GET;
      WITH PurchaseLine DO BEGIN
        CASE "Document Type" OF
          PurchaseLine."Document Type"::Order,PurchaseLine."Document Type"::"Blanket Order" :
            BEGIN
              IF (PurchSetup."Purch. Order Tolerance %" = 0) AND (PurchSetup."Max. Purch. Order Tolerance" = 0) THEN
                EXIT(TRUE);
              IF "Purchase Requisition No." = '' THEN
                EXIT(TRUE);

              PurchaseRequisitionLine.GET("Purchase Requisition No.","Purchase Requisition Line No.");
              ToleranceAmount := ABS(PurchaseRequisitionLine.Amount * (PurchSetup."Purch. Order Tolerance %" / 100));
              IF "Currency Code" = '' THEN BEGIN
                IF (ToleranceAmount > PurchSetup."Max. Purch. Order Tolerance") OR
                   (PurchSetup."Purch. Order Tolerance %" = 0) THEN
                  ToleranceAmount := PurchSetup."Max. Purch. Order Tolerance";
              END ELSE BEGIN
                PurchaseHeader.GET("Document Type","Document No.");
                Currency.GET("Currency Code");
                Currency.TESTFIELD("Amount Rounding Precision");
                ForeignCurrencyMaxAmount := ROUND(CurrExchRate.ExchangeAmtLCYToFCY(PurchaseHeader."Posting Date","Currency Code",
                  PurchSetup."Max. Purch. Order Tolerance",PurchaseHeader."Currency Factor"),Currency."Unit-Amount Rounding Precision");
                IF (ToleranceAmount > ForeignCurrencyMaxAmount) OR
                   (PurchSetup."Purch. Order Tolerance %" = 0) THEN
                  ToleranceAmount := ForeignCurrencyMaxAmount;
              END;

              IF (PurchaseRequisitionLine.Amount + ToleranceAmount - "Line Amount") >= 0 THEN
                EXIT(TRUE);
            END;

          PurchaseLine."Document Type"::Invoice:
            BEGIN
              IF (PurchSetup."Purch. Invoice Tolerance %" = 0) AND (PurchSetup."Max. Purch. Invoice Tolerance" = 0) THEN
                EXIT(TRUE);
              IF "Receipt No." = '' THEN
                EXIT(TRUE);

              PurchRcptLine.GET("Receipt No.","Receipt Line No.");
              PurchaseLine2.GET(PurchaseLine."Document Type"::Order,"Purchase Order No.","Purchase Order Line No.");
              ToleranceAmount :=
                ABS(ROUND((PurchRcptLine.Quantity / PurchaseLine2.Quantity) * PurchaseLine2.Amount *
                          (PurchSetup."Purch. Invoice Tolerance %" / 100)));
              IF "Currency Code" = '' THEN BEGIN
                IF (ToleranceAmount > PurchSetup."Max. Purch. Invoice Tolerance") OR
                   (PurchSetup."Purch. Invoice Tolerance %" = 0) THEN
                  ToleranceAmount := PurchSetup."Max. Purch. Invoice Tolerance";
              END ELSE BEGIN
                PurchaseHeader.GET("Document Type","Document No.");
                Currency.GET("Currency Code");
                Currency.TESTFIELD("Amount Rounding Precision");
                ForeignCurrencyMaxAmount := ROUND(CurrExchRate.ExchangeAmtLCYToFCY(PurchaseHeader."Posting Date","Currency Code",
                PurchSetup."Max. Purch. Invoice Tolerance",PurchaseHeader."Currency Factor"),Currency."Unit-Amount Rounding Precision");
                IF (ToleranceAmount > ForeignCurrencyMaxAmount) OR
                   (PurchSetup."Purch. Invoice Tolerance %" = 0) THEN
                  ToleranceAmount := ForeignCurrencyMaxAmount;
              END;

              IF (ROUND((PurchRcptLine.Quantity/PurchaseLine2.Quantity) * PurchaseLine2.Amount) +
                         ToleranceAmount - "Line Amount") >= 0 THEN
                EXIT(TRUE);
            END;
          ELSE
            EXIT(TRUE);
        END;
      END;
      EXIT(FALSE);
    END;

    PROCEDURE RequisitionBudgetCheck@47(RequisitionHeader@1102602000 : Record 37001090;LineNo@1102602001 : Integer);
    VAR
      RequisitionLine@1102602002 : Record 37001091;
      GenJnlLine@1102602003 : Record 81;
    BEGIN
      WITH RequisitionLine DO BEGIN
        SETRANGE("Document No.",RequisitionHeader."No.");
        SETRANGE(Status,Status::New);
        SETFILTER(Type,'<>%1',Type::" ");
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(FALSE,FALSE) THEN BEGIN
          MESSAGE(SNText18);
          EXIT;
        END;

        IF NOT NavigatorManagement.BudgetLicensed("Source Code") THEN
          ERROR(SNText05);

        REPEAT
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN
            WorkflowManagement.BudgetCheck("Internal Control No.",TRUE);
        UNTIL NEXT = 0;

        IF NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.BudgetCheckDisplay('','',"Source Code","Document No.",LineNo);
      END;
    END;

    PROCEDURE PurchaseBudgetCheck@1102602011(PurchaseHeader@1102602000 : Record 38;LineNo@1102602002 : Integer);
    VAR
      PurchaseLine@1102602004 : Record 39;
      GenJnlLine@1102602003 : Record 81;
      TransactionType@1102602005 : 'Actual,Budget,Commitment,Encumbrance,Statistical';
    BEGIN
      WITH PurchaseLine DO BEGIN
        SETRANGE("Document No.",PurchaseHeader."No.");
        SETRANGE("Document Type",PurchaseHeader."Document Type");
        SETRANGE(Status,Status::New);
        SETFILTER(Type,'<>%1',Type::" ");
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(FALSE,FALSE) THEN BEGIN
          MESSAGE(SNText18);
          EXIT;
        END;

        IF NOT NavigatorManagement.BudgetLicensed("Source Code") THEN
          ERROR(SNText05);

        REPEAT
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN
            WorkflowManagement.BudgetCheck("Internal Control No.",TRUE);
        UNTIL NEXT = 0;

        IF NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.BudgetCheckDisplay('','',"Source Code","Document No.",LineNo);
      END;
    END;

    PROCEDURE GenJournalBudgetCheck@1102602012(VAR TempGenJnlLine@1102602000 : Record 81;LineNo@1102602001 : Integer;DocumentNo@1102602003 : Code[20]);
    VAR
      GenJnlLine@1102602002 : Record 81;
    BEGIN
      WITH GenJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempGenJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempGenJnlLine."Journal Batch Name");
        SETRANGE(Status,Status::New);
        SETFILTER(Amount,'<>0');
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(FALSE,FALSE) THEN BEGIN
          MESSAGE(SNText12);
          EXIT;
        END;

        IF NOT NavigatorManagement.BudgetLicensed("Source Code") THEN
          ERROR(SNText05);

        REPEAT
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN
            WorkflowManagement.BudgetCheck("Internal Control No.",TRUE)
        UNTIL NEXT = 0;

        IF NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.BudgetCheckDisplay("Journal Template Name","Journal Batch Name","Source Code",DocumentNo,LineNo);
      END;
    END;

    PROCEDURE ItemJournalBudgetCheck@1102602018(VAR TempItemJnlLine@1102602000 : Record 83;LineNo@1102602001 : Integer;DocumentNo@1102602003 : Code[20]);
    VAR
      ItemJnlLine@1102602002 : Record 83;
      GenJnlLine@1102602004 : Record 81;
    BEGIN
      WITH ItemJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempItemJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempItemJnlLine."Journal Batch Name");
        SETRANGE(Status,Status::New);
        SETFILTER(Amount,'<>0');
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(FALSE,FALSE) THEN BEGIN
          MESSAGE(SNText12);
          EXIT;
        END;

        IF NOT NavigatorManagement.BudgetLicensed("Source Code") THEN
          ERROR(SNText05);

        REPEAT
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN
            WorkflowManagement.BudgetCheck("Internal Control No.",TRUE)
        UNTIL NEXT = 0;

        IF NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.BudgetCheckDisplay("Journal Template Name","Journal Batch Name","Source Code",DocumentNo,LineNo);
      END;
    END;

    PROCEDURE PayrollJournalBudgetCheck@1102602020(VAR TempPayrollJnlLine@1102602000 : Record 37032302;LineNo@1102602001 : Integer;DocumentNo@1102602003 : Code[20]);
    VAR
      PayrollJnlLine@1102602004 : Record 37032302;
      GenJnlLine@1102602002 : Record 81;
    BEGIN
      WITH PayrollJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempPayrollJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempPayrollJnlLine."Journal Batch Name");
        SETRANGE(Status,Status::New);
        SETFILTER(Amount,'<>0');
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(FALSE,FALSE) THEN BEGIN
          MESSAGE(SNText12);
          EXIT;
        END;

        IF NOT NavigatorManagement.BudgetLicensed("Source Code") THEN
          ERROR(SNText05);

        REPEAT
          IF NavigatorManagement.BudgetLicensed("Source Code") THEN
            WorkflowManagement.BudgetCheck("Internal Control No.",TRUE)
        UNTIL NEXT = 0;

        IF NavigatorManagement.BudgetLicensed("Source Code") THEN
          WorkflowManagement.BudgetCheckDisplay("Journal Template Name","Journal Batch Name","Source Code",DocumentNo,LineNo);
      END;
    END;

    PROCEDURE RequisitionCancelLine@1102602010(VAR RequisitionLine@1102602000 : Record 37001091;DocumentLevelCancel@1102634002 : Boolean);
    VAR
      RequisitionHeader@1102602001 : Record 37001090;
      RequisitionLine2@1102634001 : Record 37001091;
      TransactionType@1102602002 : 'Actual,Budget,Commitment,Encumbrance,Statistical';
      CancelLine@1102602004 : Boolean;
      Continue@1102633000 : Boolean;
      UpdateDocumentStatus@1102634000 : Boolean;
    BEGIN
      WITH RequisitionHeader DO BEGIN
        GET(RequisitionLine."Document No.");
        IF "Document Status" = "Document Status"::"Approval Pending" THEN BEGIN
          MESSAGE(SNText39,TABLECAPTION,"No.",FIELDCAPTION("Document Status"),"Document Status");
          EXIT;
        END;
      END;

      WITH RequisitionLine DO BEGIN
        CASE Status OF
          Status::Committed, Status::Approved :
            BEGIN
              ArchiveManagement.ArchiveRequDocumentNoConfirm(RequisitionHeader);
              ReverseCommitmentPost("Internal Control No.","Document No.",RequisitionHeader."Posting Date","Allocation No.");
              Status := Status::New;
              VALIDATE(Quantity, 0);
              Status := Status::Canceled;
              MODIFY;
              UpdateDocumentStatus := TRUE;
              DocumentHistoryWriteLine(DATABASE::"Purchase Requisition Line","Document No.",'',"Internal Control No.",9);
              DeleteLineDistributionBuffer("Internal Control No.");
            END;

          Status::"Approval Pending",Status::"Transfer Budget Pending" :
            BEGIN
              Continue := TRUE;
              IF GUIALLOWED AND (NOT DocumentLevelCancel) THEN
                Continue := CONFIRM(SNText23,FALSE);
              IF NOT Continue THEN
                MESSAGE(SNText24,"Document No.","Line No.")
              ELSE BEGIN
                ArchiveManagement.ArchiveRequDocumentNoConfirm(RequisitionHeader);
                Status := Status::New;
                VALIDATE(Quantity, 0);
                Status := Status::Canceled;
                MODIFY;
                UpdateDocumentStatus := TRUE;
                DocumentHistoryWriteLine(DATABASE::"Purchase Requisition Line","Document No.",'',"Internal Control No.",9);
                DeleteLineDistributionBuffer("Internal Control No.");
                IF NavigatorManagement.ApprovalsLicensed("Source Code") OR
                   NavigatorManagement.BudgetLicensed("Source Code") THEN BEGIN
                  WorkflowManagement.SetPreserveApprovalHistory(TRUE);
                  WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
                END;
              END;
            END;

          Status::New :
            MESSAGE(SNText15, "Line No.");

          Status::Disapproved :
            BEGIN
              MESSAGE(SNText15, "Line No.");
              DeleteLineDistributionBuffer("Internal Control No.");
            END;

          ELSE
            MESSAGE(SNText16, "Document No.","Line No.",Status);
        END;
      END;

      WITH RequisitionHeader DO BEGIN
        GET(RequisitionLine."Document No.");
        IF UpdateDocumentStatus AND ("Document Status" <> "Document Status"::New) THEN BEGIN
          RequisitionLine2.SETRANGE("Document No.","No.");
          RequisitionLine2.SETFILTER(Type,'<>%1',RequisitionLine2.Type::" ");
          RequisitionLine2.SETFILTER(Quantity,'<>0');
          RequisitionLine2.SETFILTER(Status,'<>%1',RequisitionLine2.Status::Canceled);
          IF NOT RequisitionLine2.FINDFIRST THEN BEGIN
            "Document Status" := "Document Status"::Canceled;
            MODIFY;
            WorkflowManagement.SetPreserveApprovalHistory(TRUE);
            WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
          END;
        END;
      END;
    END;

    PROCEDURE RequisitionCancelDocument@1102634005(VAR RequisitionHeader@1102602000 : Record 37001090);
    VAR
      RequisitionLine@1102602001 : Record 37001091;
      Continue@1102634000 : Boolean;
      CancelDocument@1102634001 : Boolean;
    BEGIN
      WITH RequisitionHeader DO BEGIN
        CASE "Document Status" OF
          "Document Status"::"Approval Pending" :
            BEGIN
              Continue := TRUE;
              IF GUIALLOWED THEN BEGIN
                Continue := CONFIRM(SNText36,FALSE);
              END;
              IF NOT Continue THEN BEGIN
                MESSAGE(SNText37,TABLECAPTION,"No.");
              END ELSE BEGIN
                CancelDocument := TRUE;
              END;
            END;

          "Document Status"::Approved, "Document Status"::Disapproved, "Document Status"::Committed, "Document Status"::Fulfilled  :
            BEGIN
              CancelDocument := TRUE;
            END;

          ELSE
            MESSAGE(SNText39,TABLECAPTION,"No.",FIELDCAPTION("Document Status"),"Document Status");
        END;

        IF CancelDocument THEN BEGIN
          ArchiveManagement.ArchiveRequDocumentNoConfirm(RequisitionHeader);
          "Document Status" := "Document Status"::Canceled;
          MODIFY;
          DocumentHistoryWriteLine(DATABASE::"Purchase Requisition Header","No.",'',"Internal Control No.",9);
          DeleteLineDistributionBuffer("Internal Control No.");

          IF NavigatorManagement.ApprovalsLicensed("Source Code") OR
             NavigatorManagement.BudgetLicensed("Source Code") OR
             NavigatorManagement.DocumentLevelApprovalsLicensed("Source Code") THEN BEGIN
            WorkflowManagement.SetPreserveApprovalHistory(TRUE);
            WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
          END;

          RequisitionLine.SETRANGE("Document No.","No.");
          RequisitionLine.SETFILTER(Type,'<>%1',RequisitionLine.Type::" ");
          RequisitionLine.SETFILTER("No.",'<>%1','');
          RequisitionLine.SETFILTER(Quantity,'<>0');
          RequisitionLine.SETFILTER(Status,'%1|%2|%3|%4',
            RequisitionLine.Status::"Approval Pending", RequisitionLine.Status::"Transfer Budget Pending",
            RequisitionLine.Status::Approved, RequisitionLine.Status::Committed);
          IF RequisitionLine.FINDSET(TRUE,FALSE) THEN BEGIN
            REPEAT
              RequisitionCancelLine(RequisitionLine,TRUE);
            UNTIL RequisitionLine.NEXT = 0;
          END;
        END;
      END;
    END;

    PROCEDURE PurchaseCancelLine@1102602008(VAR PurchaseLine@1102602000 : Record 39;DocumentLevelCancel@1102634000 : Boolean);
    VAR
      PurchaseHeader@1102602002 : Record 38;
      PurchaseLine2@1102634001 : Record 39;
      TempPurchLine@1102602007 : Record 39;
      RequisitionLine@1102602004 : Record 37001091;
      BlanketOrderLine@1102602001 : Record 39;
      QtyCanceled@1102602006 : Decimal;
      PostDate@1102602005 : Date;
      CancelLine@1102602003 : Boolean;
      NewStatusInvoice@1102602009 : Boolean;
      EncumberBlanketOrder@1102628000 : Boolean;
      Continue@1102633000 : Boolean;
    BEGIN
      WITH PurchaseHeader DO BEGIN
        GET(PurchaseLine."Document Type",PurchaseLine."Document No.");
        IF "Document Status" = "Document Status"::"Approval Pending" THEN BEGIN
          MESSAGE(SNText39,"Document Type","No.",FIELDCAPTION("Document Status"),"Document Status");
          EXIT;
        END;
      END;

      WITH PurchaseLine DO BEGIN
        IF (Type = Type::" ") OR ("No." = '') THEN
          EXIT;
        CancelLine := FALSE;
        NewStatusInvoice := FALSE;
        EncumberBlanketOrder := FALSE;

        CASE Status OF
          Status::New :
            MESSAGE(SNText09,"Document No.","Line No.");

          Status::Received,Status::Invoiced,Status::Canceled,Status::Disapproved :
            MESSAGE(SNText04,Status);

          Status::"Partial Received" :
            BEGIN
              CancelLine := TRUE;
              NewStatusInvoice := TRUE;
            END;

          Status::Encumbered :
            BEGIN
              CancelLine := TRUE;
              EncumberBlanketOrder := TRUE;
            END;

          Status::"Approval Pending",Status::"Transfer Budget Pending" :
            BEGIN
              Continue := TRUE;
              IF GUIALLOWED AND (NOT DocumentLevelCancel) THEN
                Continue := CONFIRM(SNText23,FALSE);
              IF NOT Continue THEN
                MESSAGE(SNText24,"Document No.","Line No.")
              ELSE BEGIN
                CancelLine := TRUE;
                IF ("Document Type" IN ["Document Type"::Order,"Document Type"::"Blanket Order"]) AND
                   (RequisitionLine.GET("Purchase Requisition No.","Purchase Requisition Line No.")) AND
                   (NOT BlanketOrderLine.GET("Document Type"::"Blanket Order","Blanket Order No.","Blanket Order Line No.")) THEN BEGIN
                  RequisitionLine."Previous Status" := RequisitionLine.Status;
                  RequisitionLine.Status := RequisitionLine.Status::Committed;
                  RequisitionLine.Decision := RequisitionLine.Decision::" ";
                  RequisitionLine."Target No." := '';
                  RequisitionLine."Fulfillment Doc. No." := '';
                  RequisitionLine."Fulfillment Doc. Line No." := 0;
                  RequisitionLine.MODIFY;
                  GenDistBufferRequisitionLine(RequisitionLine);

                  Status := Status::Canceled;
                  MODIFY;
                  MESSAGE(SNText07,"Document No.","Line No.");
                END;
              END;
            END;

          Status::Approved :
            BEGIN
              CancelLine := TRUE;
              IF ("Document Type" IN ["Document Type"::Order,"Document Type"::"Blanket Order"]) AND
                 (RequisitionLine.GET("Purchase Requisition No.","Purchase Requisition Line No.")) AND
                 (NOT BlanketOrderLine.GET("Document Type"::"Blanket Order","Blanket Order No.","Blanket Order Line No.")) THEN BEGIN
                RequisitionLine."Previous Status" := RequisitionLine.Status;
                RequisitionLine.Status := RequisitionLine.Status::Committed;
                RequisitionLine.Decision := RequisitionLine.Decision::" ";
                RequisitionLine."Target No." := '';
                RequisitionLine."Fulfillment Doc. No." := '';
                RequisitionLine."Fulfillment Doc. Line No." := 0;
                RequisitionLine.MODIFY;
                GenDistBufferRequisitionLine(RequisitionLine);

                Status := Status::Canceled;
                MODIFY;
                MESSAGE(SNText07,"Document No.","Line No.");
              END;
            END;
        END;

        IF CancelLine AND ("Document Type" = "Document Type"::"Blanket Order") THEN BEGIN
          TempPurchLine.SETRANGE("Blanket Order No.","Document No.");
          TempPurchLine.SETRANGE("Blanket Order Line No.","Line No.");
          IF TempPurchLine.FINDSET(FALSE,FALSE) THEN BEGIN
            REPEAT
              IF TempPurchLine.Quantity <> TempPurchLine."Quantity Invoiced" THEN
                CancelLine := FALSE
              ELSE IF NOT (TempPurchLine.Status IN [TempPurchLine.Status::Invoiced,
                                                    TempPurchLine.Status::Canceled,
                                                    TempPurchLine.Status::Disapproved]) THEN
                CancelLine := FALSE;
            UNTIL (TempPurchLine.NEXT = 0) OR (NOT CancelLine);
            IF NOT CancelLine THEN
              MESSAGE(SNText20);
          END;
        END;

        IF CancelLine THEN BEGIN
          PurchaseHeader.GET("Document Type","Document No.");
          ArchiveManagement.ArchivePurchDocumentNoConfirm(PurchaseHeader);

          PostDate := PurchaseHeader."Posting Date";
          IF PostDate = 0D THEN
            PostDate := PurchaseHeader."Posting Date";
          IF PostDate = 0D THEN
            PostDate := PurchaseHeader."Document Date";

          ReverseEncumbrancePost("Internal Control No.","Document No.",PostDate,FALSE,TRUE,"Outstanding Amount (LCY)","Allocation No.",
                                 GenJnlPostLine);

          IF "Document Type" = "Document Type"::Invoice THEN BEGIN
            "Quantity Received" := 0;
            "Qty. Received (Base)" := 0;
            "Qty. Rcd. Not Invoiced" := 0;
            "Qty. Rcd. Not Invoiced (Base)" := 0
          END;
          QtyCanceled := Quantity - "Quantity Received";
          Quantity := "Quantity Received";
          Status := Status::New;
          VALIDATE(Quantity);
          Status := Status::Canceled;
          IF NewStatusInvoice THEN BEGIN
            IF "Quantity Received" = "Quantity Invoiced" THEN
              Status := Status::Invoiced
            ELSE
                Status := Status::Received;
          END;

          MODIFY;
          DocumentHistoryWriteLine(DATABASE::"Purchase Line","Document No.",'',"Internal Control No.",9);
          DeleteLineDistributionBuffer("Internal Control No.");
          IF NavigatorManagement.ApprovalsLicensed("Source Code") OR
             NavigatorManagement.BudgetLicensed("Source Code") THEN BEGIN
            WorkflowManagement.SetPreserveApprovalHistory(TRUE);
            WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
          END;

          //ReEncumber Blanket Order Line
          IF BlanketOrderLine.GET("Document Type"::"Blanket Order","Blanket Order No.","Blanket Order Line No.") THEN BEGIN
            IF EncumberBlanketOrder THEN BEGIN
              IF CONFIRM(SNText21,FALSE,"Blanket Order No.","Blanket Order Line No.") THEN BEGIN
                PurchaseReEncumberLine(BlanketOrderLine,QtyCanceled);
                BlanketOrderLine.VALIDATE("Qty. Drawn Down",BlanketOrderLine."Qty. Drawn Down" - QtyCanceled);
                BlanketOrderLine.MODIFY;
              END;
            END ELSE BEGIN
              BlanketOrderLine.VALIDATE("Qty. Drawn Down",BlanketOrderLine."Qty. Drawn Down" - QtyCanceled);
              BlanketOrderLine.MODIFY;
            END;
          END;

          IF PurchaseHeader."Document Status" <> PurchaseHeader."Document Status"::New THEN BEGIN
            PurchaseLine2.SETRANGE("Document No.","No.");
            PurchaseLine2.SETFILTER(Type,'<>%1',PurchaseLine2.Type::" ");
            PurchaseLine2.SETFILTER(Quantity,'<>0');
            PurchaseLine2.SETFILTER(Status,'<>%1',PurchaseLine2.Status::Canceled);
            IF NOT PurchaseLine2.FINDFIRST THEN BEGIN
              PurchaseHeader."Document Status" := PurchaseHeader."Document Status"::New;
              PurchaseHeader.MODIFY;
              WorkflowManagement.SetPreserveApprovalHistory(TRUE);
              WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
            END;
          END;
        END;
      END;
    END;

    PROCEDURE PurchaseCancelDocument@1102634020(VAR PurchaseHeader@1102602000 : Record 38);
    VAR
      PurchaseLine@1102634001 : Record 39;
      Continue@1102634000 : Boolean;
      CancelDocument@1102634002 : Boolean;
    BEGIN
      WITH PurchaseHeader DO BEGIN
        CASE "Document Status" OF
          "Document Status"::"Approval Pending" :
            BEGIN
              Continue := TRUE;
              IF GUIALLOWED THEN
                Continue := CONFIRM(SNText23,FALSE);
              IF NOT Continue THEN BEGIN
                MESSAGE(SNText37,"Document Type","No.");
              END ELSE BEGIN
                CancelDocument := TRUE;
              END;
            END;

          "Document Status"::Approved,"Document Status"::Disapproved,"Document Status"::Encumbered,"Document Status"::"Partial Received"
      :
            BEGIN
              CancelDocument := TRUE;
            END;

          "Document Status"::New,"Document Status"::Received,"Document Status"::Invoiced,"Document Status"::Canceled :
            MESSAGE(SNText39,TABLECAPTION,"No.",FIELDCAPTION("Document Status"),"Document Status");
        END;

        IF CancelDocument THEN BEGIN
          ArchiveManagement.ArchivePurchDocumentNoConfirm(PurchaseHeader);
          IF "Document Status" <= "Document Status"::Approved THEN BEGIN
            "Document Status" := "Document Status"::New;
          END ELSE BEGIN
            "Document Status" := "Document Status"::Canceled;
          END;
          MODIFY;
          DocumentHistoryWriteLine(DATABASE::"Purchase Header","No.",'',"Internal Control No.",9);
          DeleteLineDistributionBuffer("Internal Control No.");

          SourceCodeSetup.GET;
          IF "Document Type" = "Document Type"::Order THEN BEGIN
            IF NavigatorManagement.ApprovalsLicensed(SourceCodeSetup."Purchase Orders") OR
               NavigatorManagement.BudgetLicensed(SourceCodeSetup."Purchase Orders") OR
               NavigatorManagement.DocumentLevelApprovalsLicensed(SourceCodeSetup."Purchase Orders") THEN BEGIN
              WorkflowManagement.SetPreserveApprovalHistory(TRUE);
              WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
            END;
          END ELSE BEGIN
            IF NavigatorManagement.ApprovalsLicensed(SourceCodeSetup.Purchases) OR
               NavigatorManagement.BudgetLicensed(SourceCodeSetup.Purchases) OR
               NavigatorManagement.DocumentLevelApprovalsLicensed(SourceCodeSetup.Purchases) THEN BEGIN
              WorkflowManagement.SetPreserveApprovalHistory(TRUE);
              WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
            END;
          END;

          PurchaseLine.SETRANGE("Document Type","Document Type");
          PurchaseLine.SETRANGE("Document No.","No.");
          PurchaseLine.SETFILTER(Type,'<>%1',PurchaseLine.Type::" ");
          PurchaseLine.SETFILTER("No.",'<>%1','');
          PurchaseLine.SETFILTER(Quantity,'<>0');
          PurchaseLine.SETFILTER(Status,'%1|%2|%3|%4|%5',
            PurchaseLine.Status::"Approval Pending", PurchaseLine.Status::"Transfer Budget Pending",
            PurchaseLine.Status::Approved, PurchaseLine.Status::Encumbered, PurchaseLine.Status::"Partial Received");
          IF PurchaseLine.FINDSET(TRUE,FALSE) THEN BEGIN
            REPEAT
              PurchaseCancelLine(PurchaseLine,TRUE);
            UNTIL PurchaseLine.NEXT = 0;
          END;


          PurchaseLine.SETRANGE(PurchaseLine.Status,PurchaseLine.Status::"Partial Received");
          IF PurchaseLine.FINDFIRST THEN BEGIN
            "Document Status" := "Document Status"::"Partial Received";
            MODIFY;
            EXIT;
          END;

          PurchaseLine.SETRANGE(Status,PurchaseLine.Status::Received);
          IF PurchaseLine.FINDFIRST THEN BEGIN
            "Document Status" := "Document Status"::Received;
            MODIFY;
            EXIT;
          END;

          PurchaseLine.SETRANGE(Status,PurchaseLine.Status::Invoiced);
          IF PurchaseLine.FINDFIRST THEN BEGIN
            "Document Status" := "Document Status"::Invoiced;
            MODIFY;
            EXIT;
          END;
        END;
      END;
    END;

    PROCEDURE GenJournalCancelLine@1102602009(VAR TempGenJnlLine@1102602001 : Record 81;LineNo@1102602000 : Integer;DocumentNo@1102602003 : Code[20]);
    VAR
      GenJnlLine@1102602002 : Record 81;
    BEGIN
      WITH GenJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempGenJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempGenJnlLine."Journal Batch Name");
        SETFILTER(Status,'<>%1',Status::New);
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText19);
          EXIT;
        END;

        REPEAT
          DeleteLineDistributionBuffer("Internal Control No.");
          IF NavigatorManagement.ApprovalsLicensed("Source Code") OR
             NavigatorManagement.BudgetLicensed("Source Code") THEN BEGIN
            WorkflowManagement.SetPreserveApprovalHistory(TRUE);
            WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
          END;
          Status := Status::New;
          "Document Post Status" := FALSE;
          "Internal Control No." := GenerateICN;
          MODIFY;
          GenDistBufferGenJnlLine(GenJnlLine);
        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE ItemJournalCancelLine@1102602021(VAR TempItemJnlLine@1102602001 : Record 83;LineNo@1102602000 : Integer;DocumentNo@1102602004 : Code[20]);
    VAR
      ItemJnlLine@1102602003 : Record 83;
      GenJnlLine@1102602002 : Record 81;
    BEGIN
      WITH ItemJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempItemJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempItemJnlLine."Journal Batch Name");
        SETFILTER(Status,'<>%1',Status::New);
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText19);
          EXIT;
        END;

        REPEAT
          DeleteLineDistributionBuffer("Internal Control No.");
          IF NavigatorManagement.ApprovalsLicensed("Source Code") OR
             NavigatorManagement.BudgetLicensed("Source Code") THEN BEGIN
            WorkflowManagement.SetPreserveApprovalHistory(TRUE);
            WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
          END;
          Status := Status::New;
          "Document Post Status" := FALSE;
          "Internal Control No." := GenerateICN;
          MODIFY;
          GenDistBufferItemJnlLine(ItemJnlLine);
        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE "//>---------------------------------------TBL Amos 20/01/15 cancelFAjournal----------------------------------------------"@1000000007();
    BEGIN
    END;

    PROCEDURE FAJournalCancelLine@1000000006(VAR TempFAJnlLine@1102602001 : Record 5621;LineNo@1102602000 : Integer;DocumentNo@1102602004 : Code[20]);
    VAR
      FAJnlLine@1102602003 : Record 5621;
      GenJnlLine@1102602002 : Record 81;
    BEGIN
      WITH FAJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempFAJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempFAJnlLine."Journal Batch Name");
        SETFILTER(Status,'<>%1',Status::New);
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText19);
          EXIT;
        END;

        REPEAT
          DeleteLineDistributionBuffer("Internal Control No.");
          IF NavigatorManagement.ApprovalsLicensed("Source Code") OR
             NavigatorManagement.BudgetLicensed("Source Code") THEN BEGIN
            WorkflowManagement.SetPreserveApprovalHistory(TRUE);
            WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
          END;
          Status := Status::New;
          "Document Post Status" := FALSE;
          "Internal Control No." := GenerateICN;
          MODIFY;
          GenDistBufferFAJnlLine(FAJnlLine);
        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE "//>---------------------------------TBL Amos 20/01/15 cancelFAjourna End----------------------------------------------------"@1000000008();
    BEGIN
    END;

    PROCEDURE PayrollJournalCancelLine@1102602044(VAR TempPayrollJnlLine@1102602001 : Record 37032302;LineNo@1102602000 : Integer;DocumentNo@1102602004 : Code[20]);
    VAR
      PayrollJnlLine@1102602003 : Record 37032302;
      GenJnlLine@1102602002 : Record 81;
    BEGIN
      WITH PayrollJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempPayrollJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempPayrollJnlLine."Journal Batch Name");
        SETFILTER(Status,'<>%1',Status::New);
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText19);
          EXIT;
        END;

        REPEAT
          DeleteLineDistributionBuffer("Internal Control No.");
          IF NavigatorManagement.ApprovalsLicensed("Source Code") OR
             NavigatorManagement.BudgetLicensed("Source Code") THEN BEGIN
            WorkflowManagement.SetPreserveApprovalHistory(TRUE);
            WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
          END;
          Status := Status::New;
          "Document Post Status" := FALSE;
          "Internal Control No." := GenerateICN;
          MODIFY;
          GenDistBufferPayrollJnlLine(PayrollJnlLine);
        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE SalesCancelLine@1102602087(VAR SalesLine@1102602000 : Record 37);
    VAR
      SalesHeader@1102602002 : Record 36;
      QtyCanceled@1102602004 : Decimal;
      CancelLine@1102602003 : Boolean;
      NewStatusInvoice@1102602001 : Boolean;
    BEGIN
      WITH SalesLine DO BEGIN

        IF (Type = Type::" ") OR ("No." = '') THEN
          EXIT;
        CancelLine := FALSE;
        NewStatusInvoice := FALSE;

        CASE Status OF
          Status::New :
            MESSAGE(SNText32,"Document No.","Line No.");

          Status::Shipped,Status::Invoiced,Status::Canceled,Status::Disapproved :
            MESSAGE(SNText33,Status);

          Status::"Partial Shipment" :
            BEGIN
              CancelLine := TRUE;
              NewStatusInvoice := TRUE;
            END;

          Status::"Approval Pending",Status::"Transfer Budget Pending" :
            IF NOT CONFIRM(SNText23,FALSE) THEN
              MESSAGE(SNText24,"Document No.","Line No.")
            ELSE
              CancelLine := TRUE;

          Status::Approved :
            CancelLine := TRUE;
        END;

        IF CancelLine THEN BEGIN
          SalesHeader.GET("Document Type","Document No.");
          ArchiveManagement.ArchiveSalesDocumentNoConfirm(SalesHeader);

          IF "Document Type" = "Document Type"::Invoice THEN BEGIN
            "Quantity Shipped" := 0;
            "Qty. Shipped (Base)" := 0;
            "Qty. Shipped Not Invoiced" := 0;
            "Qty. Shipped Not Invd. (Base)" := 0
          END;

          QtyCanceled := Quantity - "Quantity Shipped";
          Quantity := "Quantity Shipped";
          Status := Status::New;
          VALIDATE(Quantity);
          Status := Status::Canceled;
          IF NewStatusInvoice THEN BEGIN
            IF "Quantity Shipped" = "Quantity Invoiced" THEN
              Status := Status::Invoiced
            ELSE
              Status := Status::Shipped;
          END;

          MODIFY;
          DeleteLineDistributionBuffer("Internal Control No.");
          IF NavigatorManagement.ApprovalsLicensed("Source Code") OR
             NavigatorManagement.BudgetLicensed("Source Code") THEN BEGIN
            WorkflowManagement.SetPreserveApprovalHistory(TRUE);
            WorkflowManagement.DeleteCurrentApprovals("Internal Control No.");
          END;
        END;
      END;
    END;

    PROCEDURE RequisitionResetApprovals@1102602055(VAR RequisitionLine@1102602000 : Record 37001091);
    VAR
      RequisitionHeader@1102634000 : Record 37001090;
      ApprovalProcessingLine@1102602002 : Record 37001102;
    BEGIN
      WITH RequisitionHeader DO BEGIN
        GET(RequisitionLine."Document No.");
        IF "Document Status" = "Document Status"::"Approval Pending" THEN BEGIN
          MESSAGE(SNText38,TABLECAPTION,"No.",FIELDCAPTION("Document Status"),"Document Status");
          EXIT;
        END;
      END;

      WITH RequisitionLine DO BEGIN
        IF NOT (Status IN [Status::"Approval Pending",Status::"Transfer Budget Pending",Status::Disapproved]) THEN BEGIN
          MESSAGE(SNText30);
          EXIT;
        END;

        Status := Status::New;
        MODIFY;
        DocumentHistoryWriteLine(DATABASE::"Purchase Requisition Line","Document No.",'',"Internal Control No.",10);

        WorkflowManagement.ResetCurrentApprovals("Internal Control No.");
        WorkflowManagement.ClearWorkflowProcessingBuffer("Internal Control No.");
        DeleteLineDistributionBuffer("Internal Control No.");
        GenDistBufferRequisitionLine(RequisitionLine);
      END;
    END;

    PROCEDURE PurchaseResetApprovals@1102602048(VAR PurchaseLine@1102602000 : Record 39);
    VAR
      PurchaseHeader@1102634000 : Record 38;
      ApprovalProcessingLine@1102602002 : Record 37001102;
    BEGIN
      WITH PurchaseHeader DO BEGIN
        GET(PurchaseLine."Document Type",PurchaseLine."Document No.");
        IF "Document Status" = "Document Status"::"Approval Pending" THEN BEGIN
          MESSAGE(SNText38,"Document Type","No.",FIELDCAPTION("Document Status"),"Document Status");
          EXIT;
        END;
      END;

      WITH PurchaseLine DO BEGIN
        IF NOT (Status IN [Status::"Approval Pending",Status::"Transfer Budget Pending",
                           Status::Disapproved,Status::Approved]) THEN BEGIN
          MESSAGE(SNText30);
          EXIT;
        END;

        Status := Status::New;
        MODIFY;
        DocumentHistoryWriteLine(DATABASE::"Purchase Line","Document No.",'',"Internal Control No.",10);

        WorkflowManagement.ResetCurrentApprovals("Internal Control No.");
        WorkflowManagement.ClearWorkflowProcessingBuffer("Internal Control No.");
        DeleteLineDistributionBuffer("Internal Control No.");
        GenDistBufferPurchaseLine(PurchaseLine);
      END;
    END;

    PROCEDURE GenJournalResetApprovals@1102602064(VAR TempGenJnlLine@1102602003 : Record 81;LineNo@1102602001 : Integer;DocumentNo@1102602000 : Code[20]);
    VAR
      GenJnlLine@1102602004 : Record 81;
      ApprovalProcessingLine@1102602002 : Record 37001102;
    BEGIN
      WITH GenJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempGenJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempGenJnlLine."Journal Batch Name");
        SETFILTER(Status,'%1|%2|%3',Status::"Approval Pending",Status::"Transfer Budget Pending",Status::Disapproved);
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText31);
          EXIT;
        END;

        REPEAT
          Status := Status::New;
          MODIFY;

          WorkflowManagement.ResetCurrentApprovals("Internal Control No.");
          WorkflowManagement.ClearWorkflowProcessingBuffer("Internal Control No.");
          DeleteLineDistributionBuffer("Internal Control No.");
          GenDistBufferGenJnlLine(GenJnlLine);
        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE ItemJournalResetApprovals@1102602059(VAR TempItemJnlLine@1102602004 : Record 83;LineNo@1102602003 : Integer;DocumentNo@1102602001 : Code[20]);
    VAR
      ItemJnlLine@1102602000 : Record 83;
      ApprovalProcessingLine@1102602002 : Record 37001102;
    BEGIN
      WITH ItemJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempItemJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempItemJnlLine."Journal Batch Name");
        SETFILTER(Status,'%1|%2|%3',Status::"Approval Pending",Status::"Transfer Budget Pending",Status::Disapproved);
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText31);
          EXIT;
        END;

        REPEAT
          Status := Status::New;
          MODIFY;

          WorkflowManagement.ResetCurrentApprovals("Internal Control No.");
          WorkflowManagement.ClearWorkflowProcessingBuffer("Internal Control No.");
          DeleteLineDistributionBuffer("Internal Control No.");
          GenDistBufferItemJnlLine(ItemJnlLine);
        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE "//>----------------------------TBL Amos 20/01/15 reset fixed asset journal------------------------------------------------------"@1000000010();
    BEGIN
    END;

    PROCEDURE FAJournalResetApprovals@1000000009(VAR TempFAJnlLine@1102602004 : Record 5621;LineNo@1102602003 : Integer;DocumentNo@1102602001 : Code[20]);
    VAR
      FAJnlLine@1102602000 : Record 5621;
      ApprovalProcessingLine@1102602002 : Record 37001102;
    BEGIN
      WITH FAJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempFAJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempFAJnlLine."Journal Batch Name");
        SETFILTER(Status,'%1|%2|%3',Status::"Approval Pending",Status::"Transfer Budget Pending",Status::Disapproved);
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText31);
          EXIT;
        END;

        REPEAT
          Status := Status::New;
          MODIFY;

          WorkflowManagement.ResetCurrentApprovals("Internal Control No.");
          WorkflowManagement.ClearWorkflowProcessingBuffer("Internal Control No.");
          DeleteLineDistributionBuffer("Internal Control No.");
          GenDistBufferFAJnlLine(FAJnlLine);
        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE "//>----------------------------TBL Amos 20/01/15 reset fixed asset journal End--------------------------------------------------"@1000000011();
    BEGIN
    END;

    PROCEDURE PayrollJournalResetApprovals@1102602062(VAR TempPayrollJnlLine@1102602004 : Record 37032302;LineNo@1102602003 : Integer;DocumentNo@1102602001 : Code[20]);
    VAR
      PayrollJnlLine@1102602000 : Record 37032302;
      ApprovalProcessingLine@1102602002 : Record 37001102;
    BEGIN
      WITH PayrollJnlLine DO BEGIN
        SETRANGE("Journal Template Name",TempPayrollJnlLine."Journal Template Name");
        SETRANGE("Journal Batch Name",TempPayrollJnlLine."Journal Batch Name");
        SETFILTER(Status,'%1|%2|%3',Status::"Approval Pending",Status::"Transfer Budget Pending",Status::Disapproved);
        IF DocumentNo <> '' THEN
          SETRANGE("Document No.",DocumentNo);
        IF LineNo <> 0 THEN
          SETRANGE("Line No.",LineNo);

        IF NOT FINDSET(TRUE,FALSE) THEN BEGIN
          MESSAGE(SNText31);
          EXIT;
        END;

        REPEAT
          Status := Status::New;
          MODIFY;

          WorkflowManagement.ResetCurrentApprovals("Internal Control No.");
          WorkflowManagement.ClearWorkflowProcessingBuffer("Internal Control No.");
          DeleteLineDistributionBuffer("Internal Control No.");
          GenDistBufferPayrollJnlLine(PayrollJnlLine);
        UNTIL NEXT = 0;
      END;
    END;

    PROCEDURE SalesResetApprovals@1102602088(VAR SalesLine@1102602000 : Record 37);
    VAR
      ApprovalProcessingLine@1102602002 : Record 37001102;
    BEGIN
      WITH SalesLine DO BEGIN
        IF NOT (Status IN [Status::"Approval Pending",Status::"Transfer Budget Pending",Status::Disapproved]) THEN BEGIN
          MESSAGE(SNText30);
          EXIT;
        END;

        Status := Status::New;
        MODIFY;

        WorkflowManagement.ResetCurrentApprovals("Internal Control No.");
        WorkflowManagement.ClearWorkflowProcessingBuffer("Internal Control No.");
        DeleteLineDistributionBuffer("Internal Control No.");
        GenDistBufferSalesLine(SalesLine);
      END;
    END;

    PROCEDURE RequisitionResetDocumentStatus@1102634004(VAR RequsitionHeader@1102602000 : Record 37001090);
    VAR
      ApprovalProcessingLine@1102602002 : Record 37001102;
    BEGIN
      WITH RequsitionHeader DO BEGIN

        IF ("Document Status" IN ["Document Status"::New,"Document Status"::Canceled]) THEN BEGIN
          MESSAGE(SNText39,TABLECAPTION,"No.",FIELDCAPTION("Document Status"),"Document Status");
          EXIT;
        END;

        "Document Status" := "Document Status"::New;
        MODIFY;
        DocumentHistoryWriteLine(DATABASE::"Purchase Requisition Header","No.",'',"Internal Control No.",10);

        WorkflowManagement.ResetCurrentApprovals("Internal Control No.");
        WorkflowManagement.ClearWorkflowProcessingBuffer("Internal Control No.");
      END;
    END;

    PROCEDURE PurchaseResetDocumentStatus@1102634010(VAR PurchaseHeader@1102602000 : Record 38);
    VAR
      ApprovalProcessingLine@1102602002 : Record 37001102;
    BEGIN
      WITH PurchaseHeader DO BEGIN
        IF ("Document Status" IN ["Document Status"::New,"Document Status"::Invoiced,"Document Status"::Canceled]) THEN BEGIN
          MESSAGE(SNText39,TABLECAPTION,"No.",FIELDCAPTION("Document Status"),"Document Status");
          EXIT;
        END;

        "Document Status" := "Document Status"::New;
        MODIFY;
        DocumentHistoryWriteLine(DATABASE::"Purchase Header","No.",'',"Internal Control No.",10);

        WorkflowManagement.ResetCurrentApprovals("Internal Control No.");
        WorkflowManagement.ClearWorkflowProcessingBuffer("Internal Control No.");
      END;
    END;

    PROCEDURE RequisitionReview@50(VAR TempRequisitionLine@1102602000 : Record 37001091);
    VAR
      RequisitionLine@1102602002 : Record 37001091;
      UserSetup@1102602001 : Record 91;
      PurchaseHeader@1102602006 : Record 38;
      LineNo@1102602004 : Integer;
      LastVendorProcessed@1102602005 : Code[20];
      DocNo@1102602003 : Code[20];
      LastReqDocNoProcessed@1102602007 : Code[20];
    BEGIN
      PurchSetup.GET;
      WITH RequisitionLine DO BEGIN
        SETCURRENTKEY("Purchaser Code",Decision,"Target No.");
        COPYFILTERS(TempRequisitionLine);
        IF PurchSetup."Post Commitments" THEN
          SETRANGE(Status,Status::Committed)
        ELSE
          SETRANGE(Status,Status::Approved);
        SETFILTER("Target No.",'<>%1','');
        SETFILTER(Decision,'<>%1',Decision::" ");
        SETFILTER(Quantity,'<>0');

        UserSetup.GET(USERID);
        IF NOT UserSetup."Global Inbox" THEN
          SETRANGE("Purchaser Code", USERID);

        IF NOT FINDFIRST THEN BEGIN
          MESSAGE(SNText01);
          EXIT;
        END;

        Window.OPEN('#1#################################\\' +
                    'Processing Purchase Doc #2######################\' +
                    'New Target No.          #3######################\' +
                    'Detail Line No.         #4######################');

        //Create New Purchase Quote
        LineNo := 0;
        LastVendorProcessed := '';
        LastReqDocNoProcessed := '';
        DocNo := '';
        SETRANGE(Decision, Decision::Quote);
        IF FINDSET(TRUE,FALSE) THEN BEGIN
          Window.UPDATE(1, Decision);
          REPEAT
            CreateNewPurchaseDocument(RequisitionLine, PurchaseHeader."Document Type"::Quote, DocNo, LineNo,
                                      LastVendorProcessed, LastReqDocNoProcessed);
            DeleteLineDistributionBuffer("Internal Control No.");
            Decision := Decision::" ";
            "Target No." := '';
            MODIFY;
          UNTIL NEXT = 0;
        END;

        //Create New Purchase Order
        LineNo := 0;
        LastVendorProcessed := '';
        LastReqDocNoProcessed := '';
        DocNo := '';
        SETRANGE(Decision, Decision::Order);
        IF FINDSET(TRUE,FALSE) THEN BEGIN
          Window.UPDATE(1, Decision);
          REPEAT
            "Previous Status" := Status;
            Status := Status::Fulfilled;
            MODIFY;
            UpdateRequisitionDocApprStatus(RequisitionLine); //stoped here
            CreateNewPurchaseDocument(RequisitionLine, PurchaseHeader."Document Type"::Order, DocNo, LineNo, // check here
                                      LastVendorProcessed, LastReqDocNoProcessed);
            DeleteLineDistributionBuffer("Internal Control No.");
          UNTIL NEXT = 0;
        END;

        //Create New Blanket Order
        LineNo := 0;
        LastVendorProcessed := '';
        LastReqDocNoProcessed := '';
        DocNo := '';
        SETRANGE(Decision, Decision::"Blanket Order");
        IF FINDSET(TRUE,FALSE) THEN BEGIN
          Window.UPDATE(1, Decision);
          REPEAT
            "Previous Status" := Status;
            Status := Status::Fulfilled;
            MODIFY;
            UpdateRequisitionDocApprStatus(RequisitionLine);
            CreateNewPurchaseDocument(RequisitionLine,PurchaseHeader."Document Type"::"Blanket Order",DocNo,LineNo,
                                      LastVendorProcessed, LastReqDocNoProcessed);
            DeleteLineDistributionBuffer("Internal Control No.");
          UNTIL NEXT = 0;
        END;

        //Append to Purchase Order
        LastReqDocNoProcessed := '';
        SETRANGE(Decision, Decision::"Append To Order");
        IF FINDSET(TRUE,FALSE) THEN BEGIN
          Window.UPDATE(1, Decision);
          REPEAT
            "Previous Status" := Status;
            Status := Status::Fulfilled;
            MODIFY;
            UpdateRequisitionDocApprStatus(RequisitionLine);
            AppendToPurchaseDocument(RequisitionLine,PurchaseHeader."Document Type"::Order, LastReqDocNoProcessed);
            DeleteLineDistributionBuffer("Internal Control No.");
          UNTIL NEXT = 0;
        END;

        //Append to Blanket Order
        LastReqDocNoProcessed := '';
        SETRANGE(Decision, Decision::"Append to Blanket Order");
        IF FINDSET(TRUE,FALSE) THEN BEGIN
          Window.UPDATE(1, Decision);
          REPEAT
            "Previous Status" := Status;
            Status := Status::Fulfilled;
            MODIFY;
            UpdateRequisitionDocApprStatus(RequisitionLine);
            AppendToPurchaseDocument(RequisitionLine,PurchaseHeader."Document Type"::"Blanket Order", LastReqDocNoProcessed);
            DeleteLineDistributionBuffer("Internal Control No.");
          UNTIL NEXT = 0;
        END;

        // Fulfill from Inventory
        LineNo := 0;
        SETRANGE(Decision, Decision::Inventory);
        IF FINDSET(TRUE,FALSE) THEN BEGIN
          Window.UPDATE(1, Decision);
          REPEAT
            "Previous Status" := Status;
            Status := Status::Fulfilled;
            MODIFY;
            UpdateRequisitionDocApprStatus(RequisitionLine);
            FulfillFromInventory(RequisitionLine);
            DeleteLineDistributionBuffer("Internal Control No.");
          UNTIL NEXT = 0;
        END;

        Window.CLOSE;
      END;
    END;

    PROCEDURE CreateNewPurchaseDocument@54(VAR RequisitionLine@1102602000 : Record 37001091;DocumentType@1102602001 : 'Quote,Order,,,Blanket Order';VAR DocumentNo@1102602007 : Code[20];VAR LineNo@1102602004 : Integer;VAR LastVendorProcessed@1102602005 : Code[20];VAR LastReqDocNoProcessed@1102602013 : Code[20]);
    VAR
      PurchaseHeader@1102602006 : Record 38;
      PurchaseLine@1102602003 : Record 39;
      RequisitionHeader@1102602008 : Record 37001090;
      DeliverToAddress@1102602011 : Record 37001080;
      Vendor@1102602012 : Record 23;
    BEGIN
      WITH PurchaseHeader DO BEGIN
        IF LastVendorProcessed = RequisitionLine."Target No." THEN BEGIN
          LineNo := LineNo + 10000;
          GET(DocumentType,DocumentNo);

        END ELSE BEGIN
          IF Vendor.GET(RequisitionLine."Target No.") THEN
            IF Vendor."Proposed Vendor" THEN
              ERROR(SNText26,RequisitionLine."Target No.");

          PurchSetup.GET;
          INIT;
          "Document Type" := DocumentType;
          "Procurement No" := RequisitionLine."Procurement No";
          INSERT(TRUE);

          VALIDATE("No.");

          //TBL Amos 08/08/14------------
          IF PurchaseHeader."Document Type" = PurchaseHeader."Document Type"::Order THEN BEGIN
            PurchaseHeader."Order No" := "No.";
            PurchaseHeader."Procurement No" := RequisitionLine."Procurement No";
            PurchaseHeader.MODIFY;
          END;
          //-------------end---------------------------

          //TBL Amos 11/08/14--------------------------------------------------

          // To add requisition number to the purchase quote
          IF  "Document Type" = PurchaseHeader."Document Type"::Quote THEN BEGIN
            PurchaseHeader."Requisition No" := RequisitionLine."Document No.";
            PurchaseHeader."Procurement No" := RequisitionLine."Procurement No";
            PurchaseHeader.MODIFY;
          END;
          //---------end--------------------------------------------------------

          VALIDATE("Buy-from Vendor No.",RequisitionLine."Target No.");
          VALIDATE("Purchaser Code",RequisitionLine."Purchaser Code");
          "Requested For" := RequisitionLine."Requested For";

          RequisitionHeader.GET(RequisitionLine."Document No.");
          IF RequisitionHeader."Sell-to Customer No." <> '' THEN BEGIN
            VALIDATE("Sell-to Customer No.",RequisitionHeader."Sell-to Customer No.");
            VALIDATE("Ship-to Code",RequisitionHeader."Ship-to Code");
          END;
          IF RequisitionLine."Location Code" <> '' THEN
            VALIDATE("Location Code",RequisitionLine."Location Code");
          IF RequisitionLine."Deliver-to Address Code" <> '' THEN
            VALIDATE("Deliver-to Address Code",RequisitionLine."Deliver-to Address Code");
          "Prices Including VAT" := RequisitionHeader."Prices Including VAT";
          MODIFY;

          Window.UPDATE(2,STRSUBSTNO('%1 %2', "Document Type", "No."));
          Window.UPDATE(3,FORMAT(RequisitionLine."Target No."));
          LastVendorProcessed := RequisitionLine."Target No.";
          LineNo := 10000;
        END;

        PurchaseLine."Document Type" := "Document Type";
        PurchaseLine."Document No." := "No.";
        DocumentNo := "No.";
        xferCustomFields.RequisitionLineTOPurchaseLine(PurchaseLine,RequisitionLine,LineNo,FALSE);   // am here 2...
        IF LastReqDocNoProcessed <> RequisitionLine."Document No." THEN BEGIN
          RequisitionCommentCopy(RequisitionLine."Document No.",DocumentType,DocumentNo);
          COPYLINKS(RequisitionHeader);
          LastReqDocNoProcessed := RequisitionLine."Document No.";
        END;
      END;

      Window.UPDATE(4,PurchaseLine."Line No.");
      PurchaseLine.INSERT(TRUE);

      IF PurchaseLine.Status = PurchaseLine.Status::New THEN
        IF CheckWorkflowNewLines THEN BEGIN
          RequisitionLine.CALCFIELDS("No. Of Approvals");
          IF RequisitionLine."No. Of Approvals" > 0 THEN BEGIN
            PurchaseLine.Status := PurchaseLine.Status::Approved;
            PurchaseLine.MODIFY;
          END;
        END;

      RequisitionTextLinesCopy(PurchaseLine,RequisitionLine,LineNo);
      RequisitionLineCommentCopy(RequisitionLine."Document No.",DocumentType,DocumentNo,
                                 RequisitionLine."Line No.",PurchaseLine."Line No.");

      RequisitionLine."Fulfillment Doc. No." := PurchaseLine."Document No.";
      RequisitionLine."Fulfillment Doc. Line No." := PurchaseLine."Line No.";
      RequisitionLine.MODIFY;

      CASE DocumentType OF
        DocumentType::Quote :
          DocumentHistoryWriteLine(DATABASE::"Purchase Line",PurchaseLine."Document No.",RequisitionLine."Document No.",
                                   PurchaseLine."Internal Control No.",2);
        DocumentType::Order :
          DocumentHistoryWriteLine(DATABASE::"Purchase Line",PurchaseLine."Document No.",RequisitionLine."Document No.",
                                   PurchaseLine."Internal Control No.",3);
        DocumentType::"Blanket Order" :
          DocumentHistoryWriteLine(DATABASE::"Purchase Line",PurchaseLine."Document No.",RequisitionLine."Document No.",
                                   PurchaseLine."Internal Control No.",4);
      END;
    END;

    PROCEDURE AppendToPurchaseDocument@58(VAR RequisitionLine@1102602000 : Record 37001091;DocType@1102602006 : 'Quote,Order,Invoice,Credit Memo,Blanket Order,Return Order';VAR LastReqDocNoProcessed@1102602007 : Code[20]);
    VAR
      PurchaseHeader@1102602001 : Record 38;
      PurchaseLine@1102602002 : Record 39;
      LineNo@1102602003 : Integer;
    BEGIN
      IF NOT PurchaseHeader.GET(DocType,RequisitionLine."Target No.") THEN BEGIN
        ERROR(SNText03,RequisitionLine."Description 2");
        EXIT;
      END;

      WITH PurchaseLine DO BEGIN
        SETRANGE("Document Type",DocType);
        SETRANGE("Document No.",PurchaseHeader."No.");
        IF FINDLAST THEN
          LineNo := "Line No." + 10000
        ELSE
          LineNo := 10000;

        INIT;
        "Document Type" := PurchaseHeader."Document Type";
        "Document No." := PurchaseHeader."No.";
        xferCustomFields.RequisitionLineTOPurchaseLine(PurchaseLine,RequisitionLine,LineNo,TRUE);
        IF LastReqDocNoProcessed <> RequisitionLine."Document No." THEN BEGIN
          RequisitionCommentCopy(RequisitionLine."Document No.",PurchaseHeader."Document Type",PurchaseHeader."No.");
          LastReqDocNoProcessed := RequisitionLine."Document No.";
        END;
        INSERT(TRUE);

        IF PurchaseLine.Status = PurchaseLine.Status::New THEN
          IF CheckWorkflowNewLines THEN BEGIN
            RequisitionLine.CALCFIELDS("No. Of Approvals");
            IF RequisitionLine."No. Of Approvals" > 0 THEN BEGIN
              PurchaseLine.Status := PurchaseLine.Status::Approved;
              PurchaseLine.MODIFY;
            END;
          END;

        RequisitionTextLinesCopy(PurchaseLine,RequisitionLine,LineNo);
        RequisitionLineCommentCopy(RequisitionLine."Document No.","Document Type","Document No.",
                                   RequisitionLine."Line No.","Line No.");
      END;

      // Update purchase document info on the purchase requisition line
      RequisitionLine."Fulfillment Doc. No." := PurchaseLine."Document No.";
      RequisitionLine."Fulfillment Doc. Line No." := PurchaseLine."Line No.";
      RequisitionLine.MODIFY;

      CASE DocType OF
        DocType::Order :
          DocumentHistoryWriteLine(DATABASE::"Purchase Line",PurchaseLine."Document No.",RequisitionLine."Document No.",
                                   PurchaseLine."Internal Control No.",5);
        DocType::"Blanket Order" :
          DocumentHistoryWriteLine(DATABASE::"Purchase Line",PurchaseLine."Document No.",RequisitionLine."Document No.",
                                   PurchaseLine."Internal Control No.",6);
      END;
    END;

    PROCEDURE FulfillFromInventory@55(VAR RequisitionLine@1102602000 : Record 37001091);
    VAR
      ItemJnlBatch@1102602001 : Record 233;
      ItemJnlLine@1102602002 : Record 83;
      RequisitionHeader@1102602003 : Record 37001090;
    BEGIN
      IF RequisitionLine.Type <> RequisitionLine.Type::Item THEN
        EXIT;

      IF (RequisitionLine."No." = '') OR (RequisitionLine."Inventory Fund No." = '') THEN
        Window.CLOSE;
      RequisitionLine.TESTFIELD("No.");
      RequisitionLine.TESTFIELD("Inventory Fund No.");
      RequisitionHeader.GET(RequisitionLine."Document No.");

      PurchSetup.GET;
      IF (PurchSetup."Inventory Fulfill Template" = '') OR (PurchSetup."Inventory Fulfill Batch" = '') THEN
        Window.CLOSE;
      PurchSetup.TESTFIELD("Inventory Fulfill Template");
      PurchSetup.TESTFIELD("Inventory Fulfill Batch");

      ItemJnlBatch.GET(PurchSetup."Inventory Fulfill Template",PurchSetup."Inventory Fulfill Batch");
      IF ItemJnlBatch."No. Series" = '' THEN
        Window.CLOSE;
      ItemJnlBatch.TESTFIELD("No. Series");

      InvenSetup.GET;
      IF InvenSetup."Location Mandatory" THEN BEGIN
        IF (RequisitionLine."Location Code" = '') OR (RequisitionLine."Target No." = '') THEN
          Window.CLOSE;
        RequisitionLine.TESTFIELD("Location Code");
        RequisitionLine.TESTFIELD("Target No.");
      END;

      ReverseCommitmentPost(RequisitionLine."Internal Control No.",RequisitionLine."Document No.",
                            RequisitionHeader."Posting Date",RequisitionLine."Allocation No.");

      xferCustomFields.RequisitionLineTOItemJnlLine(ItemJnlLine,RequisitionLine);
      WITH ItemJnlLine DO
        IF PurchSetup."Automatic Inventory Posting" THEN BEGIN
          Status := Status::Approved;
          "Document Post Status" := TRUE;
          ItemJnlPostLine.RUN(ItemJnlLine);
        END ELSE BEGIN
          Status := Status::New;
          CheckAutomaticApproval("Source Code",Status,"Document Post Status");
          INSERT(TRUE);
        END;

      DocumentHistoryWriteLine(DATABASE::"Purchase Requisition Line",ItemJnlLine."Document No.",RequisitionLine."Document No.",
                               ItemJnlLine."Internal Control No.",7);
    END;

    PROCEDURE RequisitionTextLinesCopy@1102602056(PurchaseLine@1102602004 : Record 39;RequisitionLine@1102602000 : Record 37001091;VAR LineNo@1102602001 : Integer);
    VAR
      RequisitionLine2@1102602002 : Record 37001091;
    BEGIN
      RequisitionLine2.SETRANGE("Document No.",RequisitionLine."Document No.");
      RequisitionLine2.SETFILTER("Line No.",'>%1',RequisitionLine."Line No.");
      IF RequisitionLine2.FINDSET(FALSE,FALSE) THEN
        IF RequisitionLine2.Type = RequisitionLine2.Type::" " THEN
          REPEAT
            LineNo += 10000;
            PurchaseLine."Line No." := LineNo;
            PurchaseLine.Status := PurchaseLine.Status::New;
            PurchaseLine."Purchase Requisition No." := '';
            PurchaseLine.VALIDATE(Type,PurchaseLine.Type::" ");
            PurchaseLine.VALIDATE("No.",'');
            PurchaseLine.Description := RequisitionLine2.Description;
            PurchaseLine."Description 2" := RequisitionLine2."Description 2";
            PurchaseLine."Purchase Requisition No." := RequisitionLine2."Document No.";
            PurchaseLine."Purchase Requisition Line No." := RequisitionLine2."Line No.";
            PurchaseLine.INSERT;
          UNTIL (RequisitionLine2.NEXT = 0) OR (RequisitionLine2.Type <> RequisitionLine2.Type::" ");
    END;

    PROCEDURE RequisitionCommentCopy@1102602036(RequisitionNo@1102602000 : Code[20];PurchDocType@1102602001 : 'Quote,Order,Invoice,Credit Memo,Blanket Order,Return Order';PurchDocNo@1102602002 : Code[20]);
    VAR
      RequisitionCommentLine@1102602003 : Record 43;
      PurchaseCommentLine@1102602004 : Record 43;
      LineNo@1102602005 : Integer;
    BEGIN
      LineNo := 10000;
      PurchaseCommentLine.SETRANGE("Document Type",PurchDocType);
      PurchaseCommentLine.SETRANGE("No.",PurchDocNo);
      IF PurchaseCommentLine.FINDLAST THEN
        LineNo := PurchaseCommentLine."Line No." + 10000;

      RequisitionCommentLine.SETRANGE("Document Type",RequisitionCommentLine."Document Type"::Requisition);
      RequisitionCommentLine.SETRANGE("No.",RequisitionNo);
      IF RequisitionCommentLine.FINDSET(FALSE,FALSE) THEN
        REPEAT
          PurchaseCommentLine := RequisitionCommentLine;
          PurchaseCommentLine."Document Type" := PurchDocType;
          PurchaseCommentLine."No." := PurchDocNo;
          PurchaseCommentLine."Line No." := LineNo;
          PurchaseCommentLine.INSERT;
          LineNo += 10000;
        UNTIL RequisitionCommentLine.NEXT = 0;
    END;

    PROCEDURE RequisitionLineCommentCopy@1102602050(RequisitionNo@1102602000 : Code[20];PurchDocType@1102602001 : 'Quote,Order,Invoice,Credit Memo,Blanket Order,Return Order';PurchDocNo@1102602002 : Code[20];RequisitionLineNo@1102602006 : Integer;PurchLineNo@1102602007 : Integer);
    VAR
      RequisitionLineCommentLine@1102602003 : Record 37001094;
      PurchaseLineCommentLine@1102602004 : Record 37001094;
    BEGIN
      RequisitionLineCommentLine.SETRANGE("Document Type",RequisitionLineCommentLine."Document Type"::Requisition);
      RequisitionLineCommentLine.SETRANGE("Document No.",RequisitionNo);
      RequisitionLineCommentLine.SETRANGE("Document Line No.",RequisitionLineNo);
      IF RequisitionLineCommentLine.FINDSET(FALSE,FALSE) THEN
        REPEAT
          PurchaseLineCommentLine := RequisitionLineCommentLine;
          PurchaseLineCommentLine."Document Type" := PurchDocType;
          PurchaseLineCommentLine."Document No." := PurchDocNo;
          PurchaseLineCommentLine."Document Line No." := PurchLineNo;
          PurchaseLineCommentLine.INSERT;
        UNTIL RequisitionLineCommentLine.NEXT = 0;
    END;

    PROCEDURE UpdateRequisitionDocApprStatus@1102634006(RequisitionLine@1102634000 : Record 37001091);
    VAR
      RequisitionHeader@1102634001 : Record 37001090;
      RequisitionLine2@1102602000 : Record 37001091;
      TotalLineCount@1102634002 : Integer;
      FulfilledLineCount@1102634003 : Integer;
    BEGIN
      IF NOT RequisitionHeader.GET(RequisitionLine."Document No.") THEN
        EXIT;

      WITH RequisitionLine2 DO BEGIN
        SETRANGE("Document No.",RequisitionHeader."No.");
        SETFILTER(Type,'<>%1',Type::" ");
        SETFILTER(Quantity,'<>0');
        TotalLineCount := COUNT;

        SETRANGE(Status,Status::Fulfilled);
        FulfilledLineCount := COUNT;

        IF FulfilledLineCount = TotalLineCount THEN BEGIN
          RequisitionHeader."Document Status" := RequisitionHeader."Document Status"::Fulfilled;
          RequisitionHeader.MODIFY;
        END;
      END;
    END;

    PROCEDURE CheckAutomaticApproval@1102602046(SourceCode@1102602000 : Code[10];VAR Status@1102602001 : 'New,Approval Pending,Transfer Budget Pending,Approved,Disapproved';VAR DocPostStatus@1102602002 : Boolean);
    BEGIN
      IF (SourceCode = '') OR (Status <> Status::New) THEN
        EXIT;

      IF NavigatorManagement.BudgetLicensed(SourceCode) THEN
        EXIT;
      IF NavigatorManagement.ApprovalsLicensed(SourceCode) THEN
        EXIT;

      Status := Status::Approved;
      DocPostStatus := TRUE;
    END;

    PROCEDURE CheckAutomaticApproval2@1102602047(SourceCode@1102602000 : Code[10];VAR Status@1102602001 : 'New,Approval Pending,Transfer Budget Pending,Approved,Disapproved');
    BEGIN
      IF (SourceCode = '') OR (Status <> Status::New) THEN
        EXIT;

      IF NavigatorManagement.BudgetLicensed(SourceCode) THEN
        EXIT;
      IF NavigatorManagement.ApprovalsLicensed(SourceCode) THEN
        EXIT;

      Status := Status::Approved;
    END;

    PROCEDURE CheckWorkflowNewLines@1102602066() : Boolean;
    BEGIN
      PurchSetup.GET;
      EXIT(PurchSetup."Workflow Processing" = PurchSetup."Workflow Processing"::"New Lines Only");
    END;

    PROCEDURE DocumentHistoryWriteLine@1102602068(TableID@1102602000 : Integer;DocumentNo@1102602015 : Code[20];CreatedFromDocumentNo@1102602021 : Code[20];InternalControlNo@1102602006 : Code[50];Action@1102602007 : Integer);
    VAR
      DocumentHistory@1102602002 : Record 37001006;
      PurchaseHeader@1102634001 : Record 38;
      PurchaseLine@1102602003 : Record 39;
      RequisitionHeader@1102634000 : Record 37001090;
      RequisitionLine@1102602004 : Record 37001091;
      GenJnlLine@1102602001 : Record 81;
      EntryNo@1102602014 : Integer;
      LineNo@1102602005 : Integer;
    BEGIN
      IF NOT DocumentHistory.READPERMISSION THEN
        EXIT;
      IF (TableID = 0) OR (DocumentNo = '') OR (InternalControlNo = '') THEN
        EXIT;

      WITH DocumentHistory DO BEGIN
        DocumentHistoryGetEntryNo(DocumentNo,CreatedFromDocumentNo,Action,EntryNo,LineNo);

        INIT;
        "Entry No." := EntryNo;
        "Line No." :=  LineNo;
        "Document No." := DocumentNo;
        "Created From Doc. No." := CreatedFromDocumentNo;
        "Table ID" := TableID;
        "Internal Control No." := InternalControlNo;
        "Created By" := USERID;
        "Date Created" := TODAY;
        "Time Created" := TIME;
        Description := DocumentHistoryGetAction(Action);

        CASE TableID OF
          DATABASE::"Purchase Requisition Header":
            BEGIN
              RequisitionHeader.SETCURRENTKEY("Internal Control No.");
              RequisitionHeader.SETRANGE("Internal Control No.",InternalControlNo);
              IF NOT RequisitionHeader.FINDFIRST THEN
                EXIT;
              "Document Type" := "Document Type"::Requisition;
              "Document Line No." := 0;
              Status := RequisitionHeader."Document Status";
              INSERT;
            END;
          DATABASE::"Purchase Requisition Line":
            BEGIN
              RequisitionLine.SETCURRENTKEY("Internal Control No.");
              RequisitionLine.SETRANGE("Internal Control No.",InternalControlNo);
              IF NOT RequisitionLine.FINDFIRST THEN
                EXIT;
              "Document Type" := "Document Type"::Requisition;
              "Document Line No." := RequisitionLine."Line No.";
              Status := RequisitionLine.Status;
              INSERT;
            END;
          DATABASE::"Purchase Header":
            BEGIN
              PurchaseHeader.SETCURRENTKEY("Internal Control No.");
              PurchaseHeader.SETRANGE("Internal Control No.",InternalControlNo);
              IF NOT PurchaseHeader.FINDFIRST THEN
                EXIT;
              "Document Type" := PurchaseHeader."Document Type";
              "Document Line No." := 0;
              Status := PurchaseHeader."Document Status";
              INSERT;
            END;
          DATABASE::"Purchase Line":
            BEGIN
              PurchaseLine.SETCURRENTKEY("Internal Control No.");
              PurchaseLine.SETRANGE("Internal Control No.",InternalControlNo);
              IF NOT PurchaseLine.FINDFIRST THEN
                EXIT;
              "Document Type" := PurchaseLine."Document Type";
              "Document Line No." := PurchaseLine."Line No.";
              Status := PurchaseLine.Status;
              INSERT;
            END;
          DATABASE::"Purch. Rcpt. Header":
            BEGIN
              IF LineNo = 1 THEN
                EXIT;
              "Document Type" := "Document Type"::Receipt;
              INSERT;
            END;
          DATABASE::"Purch. Inv. Header":
            BEGIN
              IF LineNo = 1 THEN
                EXIT;
              "Document Type" := "Document Type"::"Posted Invoice";
              INSERT;
            END;
          DATABASE::"Purch. Cr. Memo Hdr.":
            BEGIN
              IF LineNo = 1 THEN
                EXIT;
              "Document Type" := "Document Type"::"Posted Credit Memo";
              INSERT;
            END;
          DATABASE::"Gen. Journal Line":
            BEGIN
              IF LineNo = 1 THEN
                EXIT;
              "Document Type" := "Document Type"::Payment;
              INSERT;
            END;

          ELSE
            EXIT;
        END;
      END;
    END;

    PROCEDURE DocumentHistoryGetAction@1102602069(Action@1102602016 : Integer) : Text[80];
    VAR
      Action01@1102602015 : TextConst 'ENU=New Document Line;FRA=Ligne de nouveau document;ESM="L¡nea de documento nuevo ";ENC=New Document Line';
      Action02@1102602014 : TextConst 'ENU=Purchase Quote generated from Requisition Line;FRA=Offre g‚n‚r‚e … partir d''une ligne de demande;ESM=Cotizaci¢n de compra generada a partir de la l¡nea de requisici¢n;ENC=Purchase Quote generated from Requisition Line';
      Action03@1102602013 : TextConst 'ENU=Purchase Order generated from Requisition Line;FRA=Commande g‚n‚r‚e … partir d''une ligne de demande;ESM=Orden de compra generada a partir de la l¡nea de requisici¢n;ENC=Purchase Order generated from Requisition Line';
      Action04@1102602012 : TextConst 'ENU=Purchase Blanket Order generated from Requisition Line;FRA=Commande ouverte g‚n‚r‚e … partir d''une ligne de demande;ESM=Se gener¢ orden de compra abierta a partir de la l¡nea de requisici¢n;ENC=Purchase Blanket Order generated from Requisition Line';
      Action05@1102602011 : TextConst 'ENU=Requisition Line appended to Purchase Order;FRA=Ligne de demande annex‚e … la commande;ESM=L¡nea de requisici¢n anexada a la orden de compra;ENC=Requisition Line appended to Purchase Order';
      Action06@1102602010 : TextConst 'ENU=Requisition Line appended to Purchase Blanket Order;FRA=Ligne de demande annex‚e … la commande ouverte;ESM=L¡nea de requisici¢n anexada a la orden de compra en blanco;ENC=Requisition Line appended to Purchase Blanket Order';
      Action07@1102602009 : TextConst 'ENU=Inventory Transaction generated from Requisition Line;FRA=Transaction d''inventaire g‚n‚r‚e depuis une ligne de r‚quisition;ESM="Transacci¢n de inventario generada de la l¡nea de requisici¢n ";ENC=Inventory Transaction generated from Requisition Line';
      Action08@1102602008 : TextConst 'ENU=Document Submitted;FRA=Document envoy‚;ESM="Documento emitido  ";ENC=Document Submitted';
      Action09@1102602007 : TextConst 'ENU=Document Line Cancelled;FRA=Ligne de document annul‚e;ESM="L¡nea del documento cancelada ";ENC=Document Line Cancelled';
      Action10@1102602006 : TextConst 'ENU=Reset Document Approval;FRA=R‚initialiser l''approbation du document;ESM=Reiniciar aprobaci¢n del documento;ENC=Reset Document Approval';
      Action11@1102602005 : TextConst 'ENU=Purchase Quote converted to Purchase Order;FRA=Offre convertie en commande;ESM=Cotizaci¢n de compra convertida en orden de compra;ENC=Purchase Quote converted to Purchase Order';
      Action12@1102602004 : TextConst 'ENU=Purchase Order created from Blanket Order;FRA=Commande cr‚‚e … partir d''une commande ouverte;ESM=Orden de compra creada a partir de la orden abierta;ENC=Purchase Order created from Blanket Order';
      Action13@1102602003 : TextConst 'ENU=Purchase Receipt Posted;FRA=R‚ception de la commande valid‚e;ESM=Recibo de compra contabilizado;ENC=Purchase Receipt Posted';
      Action14@1102602002 : TextConst 'ENU=Purchase Invoice Posted;FRA=Facture d''achat comptabilis‚e;ESM=Factura de compras contabilizada;ENC=Purchase Invoice Posted';
      Action15@1102602001 : TextConst 'ENU=Purchase Credit Memo Posted;FRA=M‚morandum de cr‚dit d''achat valid‚;ESM=Memo de cr‚dito de compras contabilizado;ENC=Purchase Credit Memo Posted';
      Action16@1102602000 : TextConst 'ENU=Payment Posted;FRA=Paiement comptabilis‚;ESM=Pago contabilizado;ENC=Payment Posted';
    BEGIN
      CASE Action OF
          1 : EXIT(Action01);
          2 : EXIT(Action02);
          3 : EXIT(Action03);
          4 : EXIT(Action04);
          5 : EXIT(Action05);
          6 : EXIT(Action06);
          7 : EXIT(Action07);
          8 : EXIT(Action08);
          9 : EXIT(Action09);
          10 : EXIT(Action10);
          11 : EXIT(Action11);
          12 : EXIT(Action12);
          13 : EXIT(Action13);
          14 : EXIT(Action14);
          15 : EXIT(Action15);
          16 : EXIT(Action16);
        END;
    END;

    PROCEDURE DocumentHistoryGetEntryNo@1102602071(DocumentNo@1102602015 : Code[20];CreatedFromDocumentNo@1102602021 : Code[20];Action@1102602007 : Integer;VAR EntryNo@1102602001 : Integer;VAR LineNo@1102602000 : Integer);
    VAR
      DocumentHistory@1102602002 : Record 37001006;
    BEGIN
      WITH DocumentHistory DO BEGIN
        SETCURRENTKEY("Document No.");
        IF Action IN [2..4,11..16] THEN
          SETRANGE("Document No.",CreatedFromDocumentNo)
        ELSE
          SETRANGE("Document No.",DocumentNo);

        // Set Entry No
        IF FINDLAST THEN
          EntryNo := "Entry No."
        ELSE BEGIN
          EntryNo := 1;
          RESET;
          IF FINDLAST THEN
            EntryNo += "Entry No.";
        END;

        // Set Line No
        RESET;
        LineNo := 1;
        SETRANGE("Entry No.",EntryNo);
        IF FINDLAST THEN
          LineNo += "Line No.";
      END;
    END;

    PROCEDURE PostCurrencyTransfer@1102628005(CurrencyConversion@1102628000 : Record 37001391);
    VAR
      GenJnlLine@1102628001 : Record 81;
      BankAccount@1102628002 : Record 270;
      BankAccount2@1102628003 : Record 270;
      BankAccountPostGroup@1102628004 : Record 277;
      CurrExchRate@1102628005 : Record 330;
      LCYAmount@1102628006 : Decimal;
      ACYToLCYConvFactor@1102633000 : Decimal;
    BEGIN
      WITH CurrencyConversion DO BEGIN
        TESTFIELD("Bank Account No.");
        TESTFIELD("To Bank Account No.");
        TESTFIELD("Posting Date");
        TESTFIELD("Document No.");
        TESTFIELD("Amount Exchanged");
        TESTFIELD("Amount Received");
        TESTFIELD(Posted,FALSE);

        GLSetup.GET;
        SourceCodeSetup.GET;
        SourceCodeSetup.TESTFIELD("Currency Conversion");
        BankAccount.GET("Bank Account No.");
        BankAccount2.GET("To Bank Account No.");

        CALCFIELDS("Currency Code","To Currency Code");
        IF "Currency Code" IN ['',GLSetup."LCY Code"] THEN
          LCYAmount := "Amount Exchanged"
        ELSE IF "To Currency Code" IN ['',GLSetup."LCY Code"] THEN
          LCYAmount := "Amount Received"
        ELSE
          LCYAmount :=
              ROUND(CurrExchRate.ExchangeAmtFCYToLCY(
                    "Posting Date","Currency Code","Amount Exchanged",
                    CurrExchRate.ExchangeRate("Posting Date","Currency Code")));

        ACYToLCYConvFactor := 0;
        IF GLSetup."Additional Reporting Currency" <> '' THEN BEGIN
          IF "Currency Code" = GLSetup."Additional Reporting Currency" THEN BEGIN
            ACYToLCYConvFactor := "Amount Exchanged" / LCYAmount;
            END
          ELSE IF "To Currency Code" = GLSetup."Additional Reporting Currency" THEN BEGIN
            ACYToLCYConvFactor := "Amount Received" / LCYAmount;
            END
          ELSE BEGIN
            ACYToLCYConvFactor := 0;
          END;
        END;

        GenJnlLine.INIT;
        GenJnlLine.Status := GenJnlLine.Status::Approved;
        GenJnlLine."Document Post Status" := TRUE;
        GenJnlLine."Source Code" := SourceCodeSetup."Currency Conversion";
        GenJnlLine."System-Created Entry" := TRUE;
        GenJnlLine.VALIDATE("Posting Date","Posting Date");
        GenJnlLine."Document No." := "Document No.";
        GenJnlLine."Internal Control No." := GenerateICN;
        GenJnlLine."Account Type" := GenJnlLine."Account Type"::"Bank Account";
        GenJnlLine.VALIDATE("Account No.","Bank Account No.");
        GenJnlLine.Description := COPYSTR(STRSUBSTNO(ConversionDescription,"Currency Code","To Currency Code"),
                                                     1,MAXSTRLEN(GenJnlLine.Description));
        GenJnlLine.VALIDATE(Amount,-"Amount Exchanged");
        IF NOT ("Currency Code" IN ['',GLSetup."LCY Code"]) THEN
          GenJnlLine."Amount (LCY)" := -LCYAmount;
        GenJnlLine.VALIDATE("Fund No.",BankAccount."G/L Cash Control Fund");
        GenJnlLine.VALIDATE("Ctl. Fund No.",BankAccount."G/L Cash Control Fund");
        BankAccountPostGroup.GET(BankAccount."Bank Acc. Posting Group");
        DimMgt.DIMBankPostGroupTOGenJnlLine(BankAccountPostGroup,GenJnlLine);
        GenJnlLine."Source Currency Code" := GenJnlLine."Currency Code";
        GenJnlLine."Source Currency Amount" := GenJnlLine.Amount;
        GenJnlLine."Original Currency Code" := "To Currency Code";
        GenJnlLine."Original Currency Amount" := ACYToLCYConvFactor;
        GenDistBufferGenJnlLine(GenJnlLine);
        GenJnlPostLine.RUN(GenJnlLine);

        GenJnlLine.INIT;
        GenJnlLine.Status := GenJnlLine.Status::Approved;
        GenJnlLine."Document Post Status" := TRUE;
        GenJnlLine."Source Code" := SourceCodeSetup."Currency Conversion";
        GenJnlLine."System-Created Entry" := TRUE;
        GenJnlLine.VALIDATE("Posting Date","Posting Date");
        GenJnlLine."Document No." := "Document No.";
        GenJnlLine."Internal Control No." := GenerateICN;
        GenJnlLine."Account Type" := GenJnlLine."Account Type"::"Bank Account";
        GenJnlLine.VALIDATE("Account No.","To Bank Account No.");
        GenJnlLine.Description := COPYSTR(STRSUBSTNO(ConversionDescription,"Currency Code","To Currency Code"),
                                                     1,MAXSTRLEN(GenJnlLine.Description));
        GenJnlLine.VALIDATE(Amount,"Amount Received");
        IF NOT (GenJnlLine."Currency Code" IN ['',GLSetup."LCY Code"]) THEN
          GenJnlLine."Amount (LCY)" := LCYAmount;
        GenJnlLine."Currency Factor" := CurrencyConversion."Conversion Rate";
        GenJnlLine.VALIDATE("Fund No.",BankAccount2."G/L Cash Control Fund");
        GenJnlLine.VALIDATE("Ctl. Fund No.",BankAccount."G/L Cash Control Fund");
        BankAccountPostGroup.GET(BankAccount2."Bank Acc. Posting Group");
        DimMgt.DIMBankPostGroupTOGenJnlLine(BankAccountPostGroup,GenJnlLine);
        GenJnlLine."Source Currency Code" := "To Currency Code";
        GenJnlLine."Source Currency Amount" := "Amount Received";
        GenJnlLine."Original Currency Code" := "Currency Code";
        GenJnlLine."Original Currency Amount" := ACYToLCYConvFactor;
        GenDistBufferGenJnlLine(GenJnlLine);
        GenJnlPostLine.RUN(GenJnlLine);

        FundManagement.CheckFundBalance(GenJnlLine."G/L Register No.");
        Posted := TRUE;
        MODIFY;
      END;
    END;

    PROCEDURE ProcessPRININTPAYTrx@1102634000(FromGenJnlLine@1102634000 : Record 81) : Boolean;
    VAR
      FromGenJnlLine2@1102634005 : TEMPORARY Record 81;
      GenJnlLine@1102634001 : TEMPORARY Record 81;
      Loan@1102634006 : Record 37086504;
      LoanPostingGroup@1102634007 : Record 37086515;
      PrincipalAmount@1102634002 : Decimal;
      InterestAmount@1102634003 : Decimal;
      "PRIN INT PAY"@1102634004 : TextConst 'ENU=PRIN INT PAY;FRA=PRIN INT PAY;ESM=PAGO INT CAP;ENC=PRIN INT PAY';
    BEGIN
      IF (FromGenJnlLine."Client No." <> '') AND (FromGenJnlLine."System Entry Type Code" = "PRIN INT PAY")
        AND (FromGenJnlLine."Client Account Type" = FromGenJnlLine."Client Account Type"::Loan)
        AND (FromGenJnlLine."Client Account No." <> '') THEN
      BEGIN
        GetLoanPrincipalAndInterest(FromGenJnlLine, PrincipalAmount, InterestAmount);
        Loan.GET(FromGenJnlLine."Client Account No.");
        LoanPostingGroup.GET(Loan."Loan Posting Group");

        FromGenJnlLine2 := FromGenJnlLine;
        FromGenJnlLine2.Status := FromGenJnlLine2.Status::New;
        FromGenJnlLine2."Document Post Status" := FALSE;
        FromGenJnlLine2.VALIDATE(Amount, -PrincipalAmount);
        FromGenJnlLine2.Status := FromGenJnlLine.Status;
        FromGenJnlLine2."Document Post Status" := FromGenJnlLine."Document Post Status";
        LDBManagement.LDBGenJnlLineTOGenJnlLine(GenJnlLine,FromGenJnlLine2);
        WITH GenJnlLine DO
          IF ("Account Type" IN ["Account Type"::Customer,"Account Type"::Vendor,"Account Type"::"Bank Account"]) AND
             ("Account No." <> '') AND
             ("Bal. Account Type" IN ["Bal. Account Type"::"G/L Account"]) AND
             ("Bal. Account No." <> '') AND
             ("Journal Template Name" <> '') AND ("Journal Batch Name" <> '') THEN BEGIN
            ExchAccGLJnlLine.RUN(GenJnlLine);
          END;
        LDBManagement.GenerateDistBuffer(GenJnlLine,TRUE,1,BatchValidationProcessing);

        CLEAR(GenJnlLine);
        FromGenJnlLine2 := FromGenJnlLine;
        FromGenJnlLine2."Account No." := LoanPostingGroup."Interest Receivable Account";
        FromGenJnlLine2.Status := FromGenJnlLine2.Status::New;
        FromGenJnlLine2."Document Post Status" := FALSE;
        FromGenJnlLine2.VALIDATE(Amount, -InterestAmount);
        FromGenJnlLine2.Status := FromGenJnlLine.Status;
        FromGenJnlLine2."Document Post Status" := FromGenJnlLine."Document Post Status";
        LDBManagement.LDBGenJnlLineTOGenJnlLine(GenJnlLine,FromGenJnlLine2);
        WITH GenJnlLine DO
          IF ("Account Type" IN ["Account Type"::Customer,"Account Type"::Vendor,"Account Type"::"Bank Account"]) AND
             ("Account No." <> '') AND
             ("Bal. Account Type" IN ["Bal. Account Type"::"G/L Account"]) AND
             ("Bal. Account No." <> '') AND
             ("Journal Template Name" <> '') AND ("Journal Batch Name" <> '') THEN BEGIN
            ExchAccGLJnlLine.RUN(GenJnlLine);
          END;
        LDBManagement.GenerateDistBuffer(GenJnlLine,TRUE,2,BatchValidationProcessing);

        EXIT(TRUE);
        END
      ELSE BEGIN
        EXIT(FALSE);
      END;
    END;

    PROCEDURE ProcessPRININTPAYTrxTemp@1102634001(VAR GenJnlLine@1102634001 : TEMPORARY Record 81;VAR TempLineDistBuffer@1102634000 : TEMPORARY Record 37001008) : Boolean;
    VAR
      "PRIN INT PAY"@1102634002 : TextConst 'ENU=PRIN INT PAY;FRA=PRIN INT PAY;ESM=PAGO INT CAP;ENC=PRIN INT PAY';
      GenJnlLine2@1102634003 : TEMPORARY Record 81;
      TempLineDistBuffer2@1102634006 : TEMPORARY Record 37001008;
      Loan@1102634009 : Record 37086504;
      LoanPostingGroup@1102634008 : Record 37086515;
      PrincipalAmount@1102634005 : Decimal;
      InterestAmount@1102634004 : Decimal;
      NextLineNo@1102634007 : Integer;
    BEGIN
      IF (GenJnlLine."Client No." <> '') AND (GenJnlLine."System Entry Type Code" = "PRIN INT PAY")
        AND (GenJnlLine."Client Account Type" = GenJnlLine."Client Account Type"::Loan)
        AND (GenJnlLine."Client Account No." <> '') THEN
      BEGIN
        NextLineNo := 10000;
        GetLoanPrincipalAndInterest(GenJnlLine, PrincipalAmount, InterestAmount);
        Loan.GET(GenJnlLine."Client Account No.");
        LoanPostingGroup.GET(Loan."Loan Posting Group");

        GenJnlLine2 := GenJnlLine;
        GenJnlLine2.Status := GenJnlLine2.Status::New;
        GenJnlLine2."Document Post Status" := FALSE;
        GenJnlLine2.VALIDATE(Amount, -PrincipalAmount);
        GenJnlLine2.Status := GenJnlLine.Status;
        GenJnlLine2."Document Post Status" := GenJnlLine."Document Post Status";
        IF (GenJnlLine2."Account Type" = GenJnlLine2."Account Type"::"G/L Account") AND
           (GenJnlLine2."Bal. Account Type" = GenJnlLine2."Bal. Account Type"::"G/L Account") THEN
          GenJnlLine2."Bal. Account No." := '';
        LDBManagement.GenerateDistBufferTemp(GenJnlLine2,TempLineDistBuffer2);
        GenJnlLine."Ctl. Fund No." := GenJnlLine2."Ctl. Fund No.";

        TempLineDistBuffer2.RESET;
        IF TempLineDistBuffer2.FINDSET(FALSE, FALSE) THEN
          REPEAT
            TempLineDistBuffer := TempLineDistBuffer2;
            TempLineDistBuffer."Line No." := NextLineNo;
            NextLineNo := NextLineNo + 10000;
            TempLineDistBuffer.INSERT(FALSE);
          UNTIL TempLineDistBuffer2.NEXT = 0;
        TempLineDistBuffer2.DELETEALL(FALSE);

        GenJnlLine2 := GenJnlLine;
        GenJnlLine2."Account No." := LoanPostingGroup."Interest Receivable Account";
        GenJnlLine2.Status := GenJnlLine2.Status::New;
        GenJnlLine2."Document Post Status" := FALSE;
        GenJnlLine2.VALIDATE(Amount, -InterestAmount);
        GenJnlLine2.Status := GenJnlLine.Status;
        GenJnlLine2."Document Post Status" := GenJnlLine."Document Post Status";
        IF (GenJnlLine2."Account Type" = GenJnlLine2."Account Type"::"G/L Account") AND
           (GenJnlLine2."Bal. Account Type" = GenJnlLine2."Bal. Account Type"::"G/L Account") THEN
          GenJnlLine2."Bal. Account No." := '';
        LDBManagement.GenerateDistBufferTemp(GenJnlLine2,TempLineDistBuffer2);

        TempLineDistBuffer2.RESET;
        IF TempLineDistBuffer2.FINDSET(FALSE, FALSE) THEN
          REPEAT
            TempLineDistBuffer := TempLineDistBuffer2;
            TempLineDistBuffer."Line No." := NextLineNo;
            NextLineNo := NextLineNo + 10000;
            TempLineDistBuffer.INSERT(FALSE);
          UNTIL TempLineDistBuffer2.NEXT = 0;

        EXIT(TRUE);
        END
      ELSE BEGIN
        EXIT(FALSE);
      END;
    END;

    PROCEDURE GetLoanPrincipalAndInterest@1102634002(GenJnlLine@1102634000 : Record 81;VAR PrincipalAmount@1102634002 : Decimal;VAR InterestAmount@1102634003 : Decimal);
    VAR
      DLJnlLine@1102634001 : Record 37086518;
    BEGIN
      DLJnlLine.VALIDATE(Type, DLJnlLine.Type::Loan);
      DLJnlLine.VALIDATE("Client No.", GenJnlLine."Client No.");
      DLJnlLine.VALIDATE("Client Account No.", GenJnlLine."Client Account No.");
      DLJnlLine.VALIDATE("Posting Date", GenJnlLine."Posting Date");
      DLJnlLine.VALIDATE("System Entry Type Code", GenJnlLine."System Entry Type Code");
      DLJnlLine.SetHidePRININTPAYChangeMsgs(TRUE);
      DLJnlLine.VALIDATE(Amount, -GenJnlLine.Amount);

      PrincipalAmount := DLJnlLine."Principal Amount";
      InterestAmount := DLJnlLine."Interest Amount";
    END;

    PROCEDURE ValidatePostingDate@1000000012(PostingDate@1000000000 : Date);
    VAR
      MonthPosting@1000000001 : Integer;
      CurrentMonth@1000000002 : Integer;
      Text50000@1000000004 : TextConst 'ENU=You can not post to the closed period. Please verify your  posting date';
    BEGIN
      {
      MonthPosting := DATE2DMY(PostingDate,2);
      CurrentMonth := DATE2DMY(TODAY,2);        // commented by amos chibwana to allow carol to post for earlier dates..
       IF MonthPosting <> CurrentMonth THEN     // the comments should be removed during deployment
        ERROR(Text50000);
      }
    END;

    BEGIN
    {
      Serenic Navigator - (c)Copyright Serenic Software, Inc. 1999-2013.
      By opening this object you acknowledge that this object includes confidential information
      and intellectual property of Serenic Software, Inc., and that this work is protected by US
      and international copyright laws and agreements.
      ------------------------------------------------------------------------------------------
    }
    END.
  }
}

No comments:

Post a Comment