begin
SalesNReceivableSetup.Get();
SalesHeaderRec.Reset();
SalesHeaderRec.SetRange(/External Document No./, SalesStaging.InvoiceNo);
if not SalesHeaderRec.FindFirst() then begin
SalesHeader.Init();
SalesHeader./No./ := NoSeriesMngt.GetNextNo(SalesNReceivableSetup./Invoice Nos./, WORKDATE, TRUE);
SalesHeader.Validate(/No./);
CustomerRec.Reset();
CustomerRec.SetRange(ClientID, SalesStaging./Client ID/);
CustomerRec.SetRange(/Application Type/, SalesStaging./Application Type/);
if CustomerRec.FindFirst() then begin
SalesHeader./Sell-to Customer No./ := CustomerRec./No./;
// SalesHeader./Sell-to Customer Name/:=CustomerRec.Name;
SalesHeader.Validate(/Sell-to Customer No./);
end;
//--
if SalesStaging.PaymentTerms <> '' then begin
SalesHeader./Payment Terms Code/ := SalesStaging.PaymentTerms;
SalesHeader.Validate(/Payment Terms Code/);
end;
SalesHeader./Document Type/ := SalesHeader./Document Type/::Invoice;
SalesHeader.Validate(/Document Type/);
// SalesHeader./Sell-to Customer Name/ := SalesStaging.ClientName;
// SalesHeader.Validate(/Sell-to Customer No./);
SalesHeader./Sell-to Address/ := SalesStaging.Address;
SalesHeader.Validate(/Sell-to Address/);
SalesHeader./Posting Date/ := SalesStaging.Createddate;
SalesHeader.Validate(/Posting Date/);
SalesHeader./Sell-to Address 2/ := CopyStr(SalesStaging.Address2, 1, 50);
SalesHeader.Validate(/Sell-to Address 2/);
SalesHeader./Payment Terms Code/ := SalesStaging.PaymentTerms;
SalesHeader.Validate(/Payment Terms Code/);
SalesHeader.Validate(/External Document No./);
if SalesNReceivableSetup./Ho Location/ <> '' then begin
SalesHeader./Location Code/ := SalesNReceivableSetup./Ho Location/;
SalesHeader.Validate(/Location Code/);
end;
SalesHeader.Insert(true);
if SalesNReceivableSetup./Ho Location/ <> '' then begin
SalesHeader./Location Code/ := SalesNReceivableSetup./Ho Location/;
SalesHeader.Validate(/Location Code/);
end;
SalesHeader.Modify();
SalesLine.Init();
SalesLine./Document Type/ := SalesLine./Document Type/::Invoice;
SalesLine.Validate(/Document Type/);
SalesLine./Document No./ := SalesHeader./No./;
SalesLine./Line No./ := 10000;
SalesLine.Validate(/Line No./);
SalesLine.Type := SalesLine.Type::/G/L Account/;
SalesLine.Validate(Type);
SalesLine./No./ := CustomerRec./Sales Account/;
SalesLine.Validate(/No./);
SalesLine./Location Code/ := SalesHeader./Location Code/;
SalesLine.Validate(/Location Code/);
SalesLine.Quantity := SalesStaging.Completes;
SalesLine.Validate(Quantity);
SalesLine./Shortcut Dimension 2 Code/ := SalesStaging.Marketid;
SalesLine.Validate(/Shortcut Dimension 2 Code/);
SalesLine./Unit Price/ := SalesStaging.Cpi;
SalesLine.Validate(/Unit Price/);
SalesLine./GST Group Code/ := SalesStaging./GST Group Code/;
SalesLine.Validate(/GST Group Code/);
SalesLine.Validate(/HSN/SAC Code/);
SalesLine.Insert(true);
end;