Options

Problem with loop

foersterfoerster Member Posts: 11
Hi,

I am having a problem with loops. Hope someone can help.

I am writing a dataport to import General Journal Line entries. Every entry is divided into several journal lines. All lines of an entry are identified by the document no. As for some entries I have a VAT difference, I would like the OnPostDataItem trigger to go through every document and to sum up the amounts of all lines referring to a G/L account and to compare the sum with the amount in the line referring to the customer account. If I have a VAT difference the highest of the G/L amounts should be adjusted. Therefore I tried the following:
FIND('-');
Comparer:='x';
REPEAT
  LineNo:="Line No.";
  IF "Document No."<>Comparer THEN BEGIN
    Comparer:="Document No.";
    Max:=0;
    Summe:=0;
    WHILE "Document No."=Comparer DO BEGIN
       IF "Account Type"="Account Type"::Customer THEN BEGIN
          InvoiceAmount:=Amount;
       END ELSE BEGIN
          Summe:=Summe+Amount;
          IF ABS(Amount)>Max THEN BEGIN
             Max:=ABS(Amount);
             MaxLine:="Line No.";
          END;
       END;
       NEXT;
    END;
    IF InvoiceAmount+Summe<>0 THEN BEGIN
       GET('ALLGEMEIN','STANDARD',MaxZeile);
       Amount:=Amount-Summe-InvoiceAmount;
       VALIDATE(Amount);
       "VAT Amount":="VAT Amount"-Summe-InvoiceAmount;
       VALIDATE("VAT Amount");
       MODIFY;
    END;
    GET('ALLGEMEIN','STANDARD',LineNo);
  END;
UNTIL NEXT=0;

I am glad for every hint. Thanx already!

Jens

Comments

  • Options
    fbfb Member Posts: 246
    FIND('-');
    Comparer := "Document No.";
    Max := 0;
    MaxLine := 0;
    Summe := 0;
    InvoiceAmount := 0;
    REPEAT 
      IF "Document No." <> Comparer THEN BEGIN 
        IF InvoiceAmount + Summe <> 0 THEN BEGIN 
          LineNo := "Line No.";
          GET("Journal Template Name","Journal Batch Name",MaxLine); 
          Amount := Amount - Summe - InvoiceAmount; 
          VALIDATE(Amount); 
          "VAT Amount":="VAT Amount" - Summe - InvoiceAmount; 
          VALIDATE("VAT Amount"); 
          MODIFY; 
          GET("Journal Template Name","Journal Batch Name",LineNo); 
        END;
        Comparer := "Document No."; 
        Max := 0; 
        MaxLine := 0;
        Summe := 0; 
        InvoiceAmount := 0;
      END;
      IF "Account Type" = "Account Type"::Customer THEN
        InvoiceAmount := Amount; 
      ELSE BEGIN 
        Summe := Summe + Amount; 
        IF ABS(Amount) > Max THEN BEGIN 
          Max := ABS(Amount); 
          MaxLine := "Line No."; 
        END; 
      END;
    UNTIL NEXT = 0;
    IF InvoiceAmount + Summe <> 0 THEN BEGIN 
      GET("Journal Template Name","Journal Batch Name",MaxLine); 
      Amount := Amount - Summe - InvoiceAmount; 
      VALIDATE(Amount); 
      "VAT Amount" := "VAT Amount" - Summe - InvoiceAmount; 
      VALIDATE("VAT Amount"); 
      MODIFY; 
    END;
    
  • Options
    foersterfoerster Member Posts: 11
    Hi fb,

    works perfect! Many, many thanks. You saved my day!!!

    I kept on thinking about that problem all day. ](*,)

    Jens
Sign In or Register to comment.