local procedure CopyAndCheckItemCharge(SalesHeader: Record "Sales Header")
var
TempSalesLine: Record "Sales Line" temporary;
SalesLine: Record "Sales Line";
InvoiceEverything: Boolean;
AssignError: Boolean;
QtyNeeded: Decimal;
IsHandled: Boolean;
begin
//new-s
IsHandled := false;
OnBeforeCopyAndCheckItemCharge(SalesHeader, TempSalesLine, SalesLine, InvoiceEverything, AssignError, QtyNeeded, IsHandled, TempItemChargeAssgntSales, ItemChargeAssgntSales, TempSalesLineGlobal);
If IsHandled then
exit;
//new-e
TempItemChargeAssgntSales.Reset();
TempItemChargeAssgntSales.DeleteAll();
// Check for max qty posting
with TempSalesLine do begin
ResetTempLines(TempSalesLine);
SetRange(Type, Type::"Charge (Item)");
if IsEmpty() then
exit;
CopyItemChargeForSalesLine(TempItemChargeAssgntSales, TempSalesLine);
SetFilter("Qty. to Invoice", '<>0');
if FindSet() then
repeat
SkipTestJobNo := false;
OnCopyAndCheckItemChargeOnBeforeLoop(TempSalesLine, SalesHeader, SkipTestJobNo);
if not SkipTestJobNo then begin
TestField("Job No.", '', ErrorInfo.Create());
TestField("Job Contract Entry No.", 0, ErrorInfo.Create());
end;
if ("Qty. to Ship" + "Return Qty. to Receive" <> 0) and
((SalesHeader.Ship or SalesHeader.Receive) or
(Abs("Qty. to Invoice") >
Abs("Qty. Shipped Not Invoiced" + "Qty. to Ship") +
Abs("Ret. Qty. Rcd. Not Invd.(Base)" + "Return Qty. to Receive")))
then
TestField("Line Amount", ErrorInfo.Create());
if not SalesHeader.Ship then
"Qty. to Ship" := 0;
if not SalesHeader.Receive then
"Return Qty. to Receive" := 0;
if Abs("Qty. to Invoice") >
Abs("Quantity Shipped" + "Qty. to Ship" + "Return Qty. Received" + "Return Qty. to Receive" - "Quantity Invoiced")
then
"Qty. to Invoice" :=
"Quantity Shipped" + "Qty. to Ship" + "Return Qty. Received" + "Return Qty. to Receive" - "Quantity Invoiced";
CalcFields("Qty. to Assign", "Qty. Assigned");
if Abs("Qty. to Assign" + "Qty. Assigned") > Abs("Qty. to Invoice" + "Quantity Invoiced") then begin
AdjustQtyToAssignForSalesLine(TempSalesLine);
CalcFields("Qty. to Assign", "Qty. Assigned");
if Abs("Qty. to Assign" + "Qty. Assigned") > Abs("Qty. to Invoice" + "Quantity Invoiced") then
Error(CannotAssignMoreErr,
"Qty. to Invoice" + "Quantity Invoiced" - "Qty. Assigned",
FieldCaption("Document Type"), "Document Type",
FieldCaption("Document No."), "Document No.",
FieldCaption("Line No."), "Line No.");
CopyItemChargeForSalesLine(TempItemChargeAssgntSales, TempSalesLine);
end;
if Quantity = "Qty. to Invoice" + "Quantity Invoiced" then begin
if "Qty. to Assign" <> 0 then
if Quantity = "Quantity Invoiced" then begin
TempItemChargeAssgntSales.SetRange("Document Line No.", "Line No.");
TempItemChargeAssgntSales.SetRange("Applies-to Doc. Type", "Document Type");
if TempItemChargeAssgntSales.FindSet() then
repeat
SalesLine.Get(
TempItemChargeAssgntSales."Applies-to Doc. Type",
TempItemChargeAssgntSales."Applies-to Doc. No.",
TempItemChargeAssgntSales."Applies-to Doc. Line No.");
if SalesLine.Quantity = SalesLine."Quantity Invoiced" then
Error(CannotAssignInvoicedErr, SalesLine.TableCaption,
SalesLine.FieldCaption("Document Type"), SalesLine."Document Type",
SalesLine.FieldCaption("Document No."), SalesLine."Document No.",
SalesLine.FieldCaption("Line No."), SalesLine."Line No.");
until TempItemChargeAssgntSales.Next() = 0;
end;
if Quantity <> "Qty. to Assign" + "Qty. Assigned" then
AssignError := true;
end;
if ("Qty. to Assign" + "Qty. Assigned") < ("Qty. to Invoice" + "Quantity Invoiced") then
Error(MustAssignItemChargeErr, "No.");
// check if all ILEs exist
QtyNeeded := "Qty. to Assign";
TempItemChargeAssgntSales.SetRange("Document Line No.", "Line No.");
if TempItemChargeAssgntSales.FindSet() then
repeat
if (TempItemChargeAssgntSales."Applies-to Doc. Type" <> "Document Type") or
(TempItemChargeAssgntSales."Applies-to Doc. No." <> "Document No.")
then
QtyNeeded := QtyNeeded - TempItemChargeAssgntSales."Qty. to Assign"
else begin
SalesLine.Get(
TempItemChargeAssgntSales."Applies-to Doc. Type",
TempItemChargeAssgntSales."Applies-to Doc. No.",
TempItemChargeAssgntSales."Applies-to Doc. Line No.");
if ItemLedgerEntryExist(SalesLine, SalesHeader.Ship or SalesHeader.Receive) then
QtyNeeded := QtyNeeded - TempItemChargeAssgntSales."Qty. to Assign";
end;
until TempItemChargeAssgntSales.Next() = 0;
if QtyNeeded <> 0 then
Error(CannotInvoiceItemChargeErr, "No.");
until Next() = 0;
// Check saleslines
if AssignError then
if SalesHeader."Document Type" in
[SalesHeader."Document Type"::Invoice, SalesHeader."Document Type"::"Credit Memo"]
then
InvoiceEverything := true
else begin
Reset;
SetFilter(Type, '%1|%2', Type::Item, Type::"Charge (Item)");
if FindSet() then
repeat
if SalesHeader.Ship or SalesHeader.Receive then
InvoiceEverything :=
Quantity = "Qty. to Invoice" + "Quantity Invoiced"
else
InvoiceEverything :=
(Quantity = "Qty. to Invoice" + "Quantity Invoiced") and
("Qty. to Invoice" =
"Qty. Shipped Not Invoiced" + "Ret. Qty. Rcd. Not Invd.(Base)");
until (Next() = 0) or (not InvoiceEverything);
end;
if InvoiceEverything and AssignError then
Error(MustAssignErr);
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeCopyAndCheckItemCharge(var SalesHeader: Record "Sales Header"; var TempSalesLine: Record "Sales Line" temporary; var SalesLine: Record "Sales Line"; var InvoiceEverything: Boolean; var AssignError: Boolean; var QtyNeeded: Decimal; var IsHandled: Boolean; var TempItemChargeAssgntSales: Record "Item Charge Assignment (Sales)" temporary; var ItemChargeAssgntSales: Record "Item Charge Assignment (Sales)"; var TempSalesLineGlobal: Record "Sales Line" temporary);
begin
end;
Hello,
we need the possibility to extend the Function "CopyAndCheckItemCharge" on "Sales-Post" Codeunit (80) as follows:
and