Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.7 kB
2
Indexable
Never
local procedure FindSalesCustomerByRefNo(ReferenceNo: Code[30]; SalesOrCredit: Option Sales,Credit; var DocumentNo: Code[20]; var DocumentType: Option Quote,"Order",Invoice,"Credit Memo","Blanket Order","Return Order"; var DocumentDate: Date): Code[20]
    var
        SalesHeader: Record "Sales Header";
        SalesInvHeader: Record "Sales Invoice Header";
        SalesCrMemoHeader: Record "Sales Cr.Memo Header";
    begin
        //62086
        //194-387 New parameter

        //
        CASE SalesOrCredit OF
            SalesOrCredit::Sales:
                BEGIN
                    SalesHeader.RESET;
                    SalesHeader.SETRANGE("Document Type", SalesHeader."Document Type"::Order);
                    SalesHeader.SETFILTER("WI Order No.", '<>%1', '');
                    SalesHeader.SETRANGE(SalesHeader."EE Reference No.", ReferenceNo);
                    IF SalesHeader.FINDFIRST THEN BEGIN
                        DocumentType := DocumentType::Order;
                        DocumentNo := SalesHeader."No.";
                        //194-387
                        DocumentDate := SalesHeader."Posting Date";
                        //
                        EXIT(SalesHeader."Bill-to Customer No.");
                    END;

                    SalesInvHeader.RESET;
                    SalesInvHeader.SETFILTER("WI Order No.", '<>%1', '');
                    SalesInvHeader.SETRANGE("EE Reference No.", ReferenceNo);
                    IF SalesInvHeader.FINDFIRST THEN BEGIN
                        DocumentType := DocumentType::Invoice;
                        DocumentNo := SalesInvHeader."No.";
                        //194-387
                        DocumentDate := SalesInvHeader."Posting Date";
                        //
                        EXIT(SalesInvHeader."Bill-to Customer No.");
                    END;
                END;

            SalesOrCredit::Credit:
                BEGIN
                    SalesCrMemoHeader.RESET;
                    SalesCrMemoHeader.SETFILTER("WI Order No.", '<>%1', '');
                    SalesCrMemoHeader.SETRANGE("EE Reference No.", ReferenceNo);
                    IF SalesCrMemoHeader.FINDFIRST THEN BEGIN
                        DocumentType := DocumentType::"Credit Memo";
                        DocumentNo := SalesCrMemoHeader."No.";
                        //194-387
                        DocumentDate := SalesCrMemoHeader."Posting Date";
                        //
                        EXIT(SalesCrMemoHeader."Bill-to Customer No.");
                    END;
                END;
        END;
    end;
Leave a Comment