Facebook
From Small Mousedeer, 1 Week ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 35
  1. Documentation()
  2.  
  3. OnRun()
  4.  
  5. CreateSalesInvoice(PSeminarRegHeader : Record "Seminar Registration Header")
  6. SalesSetup.GET;
  7. SalesSetup.TESTFIELD("G/L Account No.");
  8. PSeminarRegHeader.TESTFIELD(Status, PSeminarRegHeader.Status::Finished);
  9. PSeminarRegHeader.TESTFIELD("Posting Date");
  10.  
  11. LSeminarRegLine.RESET;
  12. LSeminarRegLine.SETRANGE("Seminar Registration No.", PSeminarRegHeader."No.");
  13. LSeminarRegLine.SETRANGE("To Invoice", TRUE);
  14. LSeminarRegLine.SETRANGE("Invoice No.", '');
  15. IF LSeminarRegLine.FINDSET THEN BEGIN
  16.   LLineCreated := TRUE;
  17.   REPEAT
  18.     CLEAR(LSalesHeader);
  19.     LSalesHeader.RESET;
  20.     LSalesHeader.SETRANGE("Document Type", LSalesHeader."Document Type"::Invoice);
  21.     LSalesHeader.SETRANGE("Sell-to Customer No.", LSeminarRegLine."Bill-to Customer No.");
  22.     LSalesHeader.SETRANGE("External Document No.", PSeminarRegHeader."No.");
  23.       IF NOT LSalesHeader.FINDFIRST THEN BEGIN
  24.         LSalesHeader.INIT;
  25.         LSalesHeader."Document Type" := LSalesHeader."Document Type"::Invoice;
  26.         LSalesHeader.VALIDATE("Posting Date", PSeminarRegHeader."Posting Date");
  27.         LSalesHeader.VALIDATE("Document Date", PSeminarRegHeader."Posting Date");
  28.         LSalesHeader.VALIDATE("Sales Date", PSeminarRegHeader."Posting Date");
  29.         LSalesHeader.VALIDATE("Sell-to Customer No.", LSeminarRegLine."Bill-to Customer No.");
  30.         LSalesHeader."External Document No." := PSeminarRegHeader."No.";
  31.         LSalesHeader.INSERT(TRUE);
  32.       END;
  33.     CLEAR(LSalesLine);
  34.     LSalesLine.SETRANGE("Document Type", LSalesLine."Document Type"::Invoice);
  35.     LSalesLine.SETRANGE("Document No.", LSalesHeader."No.");
  36.     IF LSalesLine.FINDLAST THEN
  37.       LineNo:=LSalesLine."Line No.";
  38.  
  39.     LineNo := LineNo + 10000;
  40.     CLEAR(LSalesLine);
  41.  
  42.     LSalesLine."Document Type" := LSalesLine."Document Type"::Invoice;
  43.     LSalesLine."Document No." := LSalesHeader."No.";
  44.     LSalesLine."Line No." := LineNo;
  45.     LSalesLine.VALIDATE("Sell-to Customer No.",LSalesHeader."Sell-to Customer No.");
  46.     LSalesLine.Type := LSalesLine.Type::"G/L Account";
  47.     LSalesLine.VALIDATE("No.", SalesSetup."G/L Account No.");
  48.     LSalesLine.VALIDATE(Quantity,1);
  49.     LSalesLine.VALIDATE("Unit Price", LSeminarRegLine.Amount);
  50.     LSeminarRegLine.CALCFIELDS("Participant Name");
  51.     LSalesLine.Description := STRSUBSTNO('ABC',PSeminarRegHeader."No.", LSeminarRegLine."Participant Name");
  52.     LSalesLine.INSERT;
  53.     LSeminarRegLine."Invoice No." := LSalesHeader."No.";
  54.     LSeminarRegLine.MODIFY;
  55.     UNTIL LSeminarRegLine.NEXT = 0;
  56.   END;
  57.    IF LLineCreated THEN
  58.      MESSAGE(success)
  59.    ELSE
  60.      MESSAGE(failure);
  61.