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