...
Vendor.GET(PurchHeader."Pay-to Vendor No.");
VendorPostingGroup.GET(Vendor."Vendor Posting Group");
END;
IF FINDSET THEN
REPEAT
// Delete the following lines.
IF (Type = Type::"G/L Account") AND NOT "Prepayment Line" THEN
RoundingLineInserted := ("No." = VendorPostingGroup."Invoice Rounding Account") OR RoundingLineInserted;
IF "VAT Calculation Type" IN
["VAT Calculation Type"::"Reverse Charge VAT","VAT Calculation Type"::"Sales Tax"]
THEN
"VAT %" := 0;
IF NOT VATAmountLine.GET(
"VAT Identifier","VAT Calculation Type","Tax Group Code","Use Tax","Line Amount" >= 0)
THEN BEGIN
VATAmountLine.INIT;
VATAmountLine."VAT Identifier" := "VAT Identifier";
VATAmountLine."VAT Calculation Type" := "VAT Calculation Type";
VATAmountLine."Tax Group Code" := "Tax Group Code";
VATAmountLine."Use Tax" := "Use Tax";
VATAmountLine."VAT %" := "VAT %";
VATAmountLine.Modified := TRUE;
VATAmountLine.Positive := "Line Amount" >= 0;
VATAmountLine.INSERT;
END;
CASE QtyType OF
QtyType::General:
BEGIN
VATAmountLine.Quantity := VATAmountLine.Quantity + "Quantity (Base)";
VATAmountLine."Line Amount" := VATAmountLine."Line Amount" + "Line Amount";
IF "Allow Invoice Disc." THEN
VATAmountLine."Inv. Disc. Base Amount" :=
VATAmountLine."Inv. Disc. Base Amount" + "Line Amount";
VATAmountLine."Invoice Discount Amount" :=
VATAmountLine."Invoice Discount Amount" + "Inv. Discount Amount";
VATAmountLine."VAT Difference" := VATAmountLine."VAT Difference" + "VAT Difference";
IF "Prepayment Line" THEN
VATAmountLine."Includes Prepayment" := TRUE;
VATAmountLine."VAT Base (Lowered)" := VATAmountLine."VAT Base (Lowered)" + "VAT Base Amount";
VATAmountLine.MODIFY;
END;
QtyType::Invoicing:
BEGIN
CASE TRUE OF
("Document Type" IN ["Document Type"::Order,"Document Type"::Invoice]) AND
(NOT PurchHeader.Receive) AND PurchHeader.Invoice AND (NOT "Prepayment Line"):
BEGIN
IF "Receipt No." = '' THEN BEGIN
QtyToHandle := GetAbsMin("Qty. to Invoice","Qty. Rcd. Not Invoiced");
VATAmountLine.Quantity :=
VATAmountLine.Quantity + GetAbsMin("Qty. to Invoice (Base)","Qty. Rcd. Not Invoiced (Base)");
END ELSE BEGIN
QtyToHandle := "Qty. to Invoice";
VATAmountLine.Quantity := VATAmountLine.Quantity + "Qty. to Invoice (Base)";
END;
END;
("Document Type" IN ["Document Type"::"Return Order","Document Type"::"Credit Memo"]) AND
(NOT PurchHeader.Ship) AND PurchHeader.Invoice:
BEGIN
QtyToHandle := GetAbsMin("Qty. to Invoice","Return Qty. Shipped Not Invd.");
VATAmountLine.Quantity :=
VATAmountLine.Quantity + GetAbsMin("Qty. to Invoice (Base)","Ret. Qty. Shpd Not Invd.(Base)");
END;
ELSE
BEGIN
QtyToHandle := "Qty. to Invoice";
VATAmountLine.Quantity := VATAmountLine.Quantity + "Qty. to Invoice (Base)";
END;
END;
VATAmountLine."Line Amount" :=
VATAmountLine."Line Amount" +
(ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
Currency."Amount Rounding Precision"));
IF "Allow Invoice Disc." THEN
VATAmountLine."Inv. Disc. Base Amount" :=
VATAmountLine."Inv. Disc. Base Amount" +
(ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
Currency."Amount Rounding Precision"));
IF (PurchHeader."Invoice Discount Calculation" <> PurchHeader."Invoice Discount Calculation"::Amount) THEN
VATAmountLine."Invoice Discount Amount" :=
VATAmountLine."Invoice Discount Amount" +
ROUND("Inv. Discount Amount" * QtyToHandle / Quantity,Currency."Amount Rounding Precision")
ELSE
VATAmountLine."Invoice Discount Amount" :=
VATAmountLine."Invoice Discount Amount" + "Inv. Disc. Amount to Invoice";
VATAmountLine."VAT Difference" := VATAmountLine."VAT Difference" + "VAT Difference";
IF "Prepayment Line" THEN
VATAmountLine."Includes Prepayment" := TRUE;
VATAmountLine."VAT Base (Lowered)" := VATAmountLine."VAT Base (Lowered)" + "VAT Base Amount";
VATAmountLine.MODIFY;
END;
QtyType::Shipping:
BEGIN
IF "Document Type" IN
["Document Type"::"Return Order","Document Type"::"Credit Memo"]
THEN BEGIN
QtyToHandle := "Return Qty. to Ship";
VATAmountLine.Quantity := VATAmountLine.Quantity + "Return Qty. to Ship (Base)";
END ELSE BEGIN
QtyToHandle := "Qty. to Receive";
VATAmountLine.Quantity := VATAmountLine.Quantity + "Qty. to Receive (Base)";
END;
VATAmountLine."Line Amount" :=
VATAmountLine."Line Amount" +
(ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
Currency."Amount Rounding Precision"));
IF "Allow Invoice Disc." THEN
VATAmountLine."Inv. Disc. Base Amount" :=
VATAmountLine."Inv. Disc. Base Amount" +
(ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
Currency."Amount Rounding Precision"));
VATAmountLine."Invoice Discount Amount" :=
VATAmountLine."Invoice Discount Amount" +
ROUND("Inv. Discount Amount" * QtyToHandle / Quantity,Currency."Amount Rounding Precision");
VATAmountLine."VAT Difference" := VATAmountLine."VAT Difference" + "VAT Difference";
IF "Prepayment Line" THEN
VATAmountLine."Includes Prepayment" := TRUE;
VATAmountLine.MODIFY;
END;
END;
TotalVATAmount := TotalVATAmount + "Amount Including VAT" - Amount;
// End of the deleted lines.
UNTIL NEXT = 0;
SETRANGE(Type);
SETRANGE(Quantity);
...
...
Vendor.GET(PurchHeader."Pay-to Vendor No.");
VendorPostingGroup.GET(Vendor."Vendor Posting Group");
END;
IF FINDSET THEN
REPEAT
// Add the following lines.
IF NOT ZeroAmountLine(QtyType) THEN BEGIN
IF (Type = Type::"G/L Account") AND NOT "Prepayment Line" THEN
RoundingLineInserted := ("No." = VendorPostingGroup."Invoice Rounding Account") OR RoundingLineInserted;
IF "VAT Calculation Type" IN
["VAT Calculation Type"::"Reverse Charge VAT","VAT Calculation Type"::"Sales Tax"]
THEN
"VAT %" := 0;
IF NOT VATAmountLine.GET(
"VAT Identifier","VAT Calculation Type","Tax Group Code","Use Tax","Line Amount" >= 0)
THEN BEGIN
VATAmountLine.INIT;
VATAmountLine."VAT Identifier" := "VAT Identifier";
VATAmountLine."VAT Calculation Type" := "VAT Calculation Type";
VATAmountLine."Tax Group Code" := "Tax Group Code";
VATAmountLine."Use Tax" := "Use Tax";
VATAmountLine."VAT %" := "VAT %";
VATAmountLine.Modified := TRUE;
VATAmountLine.Positive := "Line Amount" >= 0;
VATAmountLine.INSERT;
END;
CASE QtyType OF
QtyType::General:
BEGIN
VATAmountLine.Quantity := VATAmountLine.Quantity + "Quantity (Base)";
VATAmountLine."Line Amount" := VATAmountLine."Line Amount" + "Line Amount";
IF "Allow Invoice Disc." THEN
VATAmountLine."Inv. Disc. Base Amount" :=
VATAmountLine."Inv. Disc. Base Amount" + "Line Amount";
VATAmountLine."Invoice Discount Amount" :=
VATAmountLine."Invoice Discount Amount" + "Inv. Discount Amount";
VATAmountLine."VAT Difference" := VATAmountLine."VAT Difference" + "VAT Difference";
IF "Prepayment Line" THEN
VATAmountLine."Includes Prepayment" := TRUE;
VATAmountLine."VAT Base (Lowered)" := VATAmountLine."VAT Base (Lowered)" + "VAT Base Amount";
VATAmountLine.MODIFY;
END;
QtyType::Invoicing:
BEGIN
CASE TRUE OF
("Document Type" IN ["Document Type"::Order,"Document Type"::Invoice]) AND
(NOT PurchHeader.Receive) AND PurchHeader.Invoice AND (NOT "Prepayment Line"):
BEGIN
IF "Receipt No." = '' THEN BEGIN
QtyToHandle := GetAbsMin("Qty. to Invoice","Qty. Rcd. Not Invoiced");
VATAmountLine.Quantity :=
VATAmountLine.Quantity + GetAbsMin("Qty. to Invoice (Base)","Qty. Rcd. Not Invoiced (Base)");
END ELSE BEGIN
QtyToHandle := "Qty. to Invoice";
VATAmountLine.Quantity := VATAmountLine.Quantity + "Qty. to Invoice (Base)";
END;
END;
("Document Type" IN ["Document Type"::"Return Order","Document Type"::"Credit Memo"]) AND
(NOT PurchHeader.Ship) AND PurchHeader.Invoice:
BEGIN
QtyToHandle := GetAbsMin("Qty. to Invoice","Return Qty. Shipped Not Invd.");
VATAmountLine.Quantity :=
VATAmountLine.Quantity + GetAbsMin("Qty. to Invoice (Base)","Ret. Qty. Shpd Not Invd.(Base)");
END;
ELSE
BEGIN
QtyToHandle := "Qty. to Invoice";
VATAmountLine.Quantity := VATAmountLine.Quantity + "Qty. to Invoice (Base)";
END;
END;
VATAmountLine."Line Amount" :=
VATAmountLine."Line Amount" +
(ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
Currency."Amount Rounding Precision"));
IF "Allow Invoice Disc." THEN
VATAmountLine."Inv. Disc. Base Amount" :=
VATAmountLine."Inv. Disc. Base Amount" +
(ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
Currency."Amount Rounding Precision"));
IF (PurchHeader."Invoice Discount Calculation" <> PurchHeader."Invoice Discount Calculation"::Amount) THEN
VATAmountLine."Invoice Discount Amount" :=
VATAmountLine."Invoice Discount Amount" +
ROUND("Inv. Discount Amount" * QtyToHandle / Quantity,Currency."Amount Rounding Precision")
ELSE
VATAmountLine."Invoice Discount Amount" :=
VATAmountLine."Invoice Discount Amount" + "Inv. Disc. Amount to Invoice";
VATAmountLine."VAT Difference" := VATAmountLine."VAT Difference" + "VAT Difference";
IF "Prepayment Line" THEN
VATAmountLine."Includes Prepayment" := TRUE;
VATAmountLine."VAT Base (Lowered)" := VATAmountLine."VAT Base (Lowered)" + "VAT Base Amount";
VATAmountLine.MODIFY;
END;
QtyType::Shipping:
BEGIN
IF "Document Type" IN
["Document Type"::"Return Order","Document Type"::"Credit Memo"]
THEN BEGIN
QtyToHandle := "Return Qty. to Ship";
VATAmountLine.Quantity := VATAmountLine.Quantity + "Return Qty. to Ship (Base)";
END ELSE BEGIN
QtyToHandle := "Qty. to Receive";
VATAmountLine.Quantity := VATAmountLine.Quantity + "Qty. to Receive (Base)";
END;
VATAmountLine."Line Amount" :=
VATAmountLine."Line Amount" +
(ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
Currency."Amount Rounding Precision"));
IF "Allow Invoice Disc." THEN
VATAmountLine."Inv. Disc. Base Amount" :=
VATAmountLine."Inv. Disc. Base Amount" +
(ROUND(QtyToHandle * "Direct Unit Cost" - ("Line Discount Amount" * QtyToHandle / Quantity),
Currency."Amount Rounding Precision"));
VATAmountLine."Invoice Discount Amount" :=
VATAmountLine."Invoice Discount Amount" +
ROUND("Inv. Discount Amount" * QtyToHandle / Quantity,Currency."Amount Rounding Precision");
VATAmountLine."VAT Difference" := VATAmountLine."VAT Difference" + "VAT Difference";
IF "Prepayment Line" THEN
VATAmountLine."Includes Prepayment" := TRUE;
VATAmountLine.MODIFY;
END;
END;
TotalVATAmount := TotalVATAmount + "Amount Including VAT" - Amount;
END;
// End of the added lines.
UNTIL NEXT = 0;
SETRANGE(Type);
SETRANGE(Quantity);
...