VAR
// Delete the following lines.
VATEntry3@1100000 : Record 254;
GLEntry@1100002 : Record 17;
GLAccount@1100003 : Record 15;
TempVATEntry@1100004 : TEMPORARY Record 254;
BEGIN
VATEntry3.SETCURRENTKEY(Type,"Country/Region Code","VAT Registration No.");
VATEntry3.SETRANGE("Country/Region Code",CountryCode);
IF IsCustomer THEN BEGIN
VATEntry3.SETRANGE(Type,VATEntry3.Type::Sale);
VATEntry3.SETRANGE("VAT Registration No.",Customer."VAT Registration No.");
VATEntry3.SETFILTER("Bill-to/Pay-to No.",'<>%1',Customer."No.");
END ELSE BEGIN
VATEntry3.SETRANGE(Type,VATEntry3.Type::Purchase);
VATEntry3.SETRANGE("VAT Registration No.",Vendor."VAT Registration No.");
VATEntry3.SETFILTER("Bill-to/Pay-to No.",'<>%1',Vendor."No.");
END;
VATEntry3.SETRANGE("Document Date",FromDate,ToDate);
IF VATEntry3.FINDFIRST THEN
REPEAT
IF IsCustomer THEN
Amt := Amt - VATEntry3.Base - VATEntry3.Amount
ELSE
Amt := Amt + VATEntry3.Base + VATEntry3.Amount;
UpdateQuarterAmount(AmountType::Sales,ABS(VATEntry3.Base) + ABS(VATEntry3.Amount),VATEntry3."Document Date");
TempVATEntry.SETRANGE("Transaction No.",VATEntry3."Transaction No.");
IF NOT TempVATEntry.FINDFIRST THEN BEGIN
GLEntry.SETRANGE("Transaction No.",VATEntry3."Transaction No.");
IF GLEntry.FINDSET THEN
REPEAT
UpdateNotIn347Amount(GLEntry);
UNTIL GLEntry.NEXT = 0;
TempVATEntry := VATEntry3;
TempVATEntry.INSERT;
END;
UNTIL VATEntry3.NEXT = 0;
// End of the deleted lines.
EXIT(Amt);
VAR
// Add the following lines.
VATEntry3@1100002 : Record 254;
GLEntry@1100003 : Record 17;
Customer2@110000022 : Record 18;
CustLedgEntry@1100007 : Record 21;
SalesInvHeader@1100008 : Record 112;
SalesCrMemoHeader@1100011 : Record 114;
Vendor2@1100013 : Record 23;
VendorLedgerEntry@1100014 : Record 25;
PurchInvHeader@1100015 : Record 122;
OrderAdress@1100017 : Record 224;
PurchCrMemoHeader@1100018 : Record 124;
VendorAmount@1100020 : Decimal;
CustomerAmount@1100021 : Decimal;
BEGIN
IF IsCustomer THEN BEGIN
Customer2.SETCURRENTKEY("VAT Registration No.");
Customer2.SETFILTER("No.",'<>%1',Customer."No.");
Customer2.SETRANGE("VAT Registration No.",Customer."VAT Registration No.");
IF Customer2.FINDFIRST THEN
REPEAT
CustomerAmount := 0;
CustLedgEntry.SETCURRENTKEY("Customer No.","Document Type");
CustLedgEntry.SETRANGE("Customer No.", Customer2."No.");
CustLedgEntry.SETRANGE("Document Date",FromDate,ToDate);
CustLedgEntry.SETRANGE("Document Type",CustLedgEntry."Document Type"::Invoice,CustLedgEntry."Document Type"::"Credit Memo");
IF CustLedgEntry.FINDFIRST THEN
REPEAT
FilterVATEntry(VATEntry3,CustLedgEntry."Document Date",CustLedgEntry."Document Type",
CustLedgEntry."Document No.",IsCustomer);
IF NOT VATEntry3.FINDFIRST THEN BEGIN
CASE CustLedgEntry."Document Type" OF
CustLedgEntry."Document Type"::Invoice:
CheckCustDocTypeInvoice(SalesInvHeader,CustLedgEntry,Customer2);
CustLedgEntry."Document Type"::"Credit Memo" :
CheckCustDocTypeCrMemo(SalesCrMemoHeader,CustLedgEntry,Customer2);
END;
END ELSE
CheckVatEntryNotIn347(VATEntry3,GLEntry);
IF (VATEntry3."VAT Registration No." <> '') OR NoTaxVATFound OR FromJournal THEN BEGIN
CustLedgEntry.CALCFIELDS(CustLedgEntry."Amount (LCY)");
Amt := Amt + CustLedgEntry."Amount (LCY)";
CustomerAmount := CustomerAmount + CustLedgEntry."Amount (LCY)";
UpdateQuarterAmount(AmountType::SameVATNo,CustLedgEntry."Amount (LCY)",CustLedgEntry."Posting Date");
END;
UNTIL CustLedgEntry.NEXT = 0;
IF CustomerMaxAmount < CustomerAmount THEN BEGIN
CustomerMaxAmount := CustomerAmount;
Name347 := Customer2.Name;
END;
UNTIL Customer2.NEXT = 0;
Name347 := PADSTR(FormatTextName(Name347),40,' ');
END ELSE BEGIN
Vendor2.SETCURRENTKEY("VAT Registration No.");
Vendor2.SETFILTER("No.",'<>%1',Vendor."No.");
Vendor2.SETRANGE("VAT Registration No.",Vendor."VAT Registration No.");
IF Vendor2.FINDFIRST THEN
REPEAT
VendorAmount := 0;
VendorLedgerEntry.SETCURRENTKEY("Vendor No.","Document Type");
VendorLedgerEntry.SETRANGE("Vendor No.", Vendor2."No.");
VendorLedgerEntry.SETRANGE("Document Date",FromDate,ToDate);
VendorLedgerEntry.SETRANGE("Document Type",VendorLedgerEntry."Document Type"::Invoice,
VendorLedgerEntry."Document Type"::"Credit Memo");
IF VendorLedgerEntry.FINDFIRST THEN
REPEAT
FilterVATEntry(VATEntry3,VendorLedgerEntry."Document Date",VendorLedgerEntry."Document Type",
VendorLedgerEntry."Document No.",IsCustomer);
IF NOT VATEntry3.FINDFIRST THEN BEGIN
CASE VendorLedgerEntry."Document Type" OF
VendorLedgerEntry."Document Type"::Invoice:
CheckVendDocTypeInvoice(PurchInvHeader,VendorLedgerEntry,Vendor2);
VendorLedgerEntry."Document Type"::"Credit Memo":
CheckVendDocTypeCrMemo(PurchCrMemoHeader,VendorLedgerEntry,Vendor2);
END;
END ELSE
CheckVatEntryNotIn347(VATEntry3,GLEntry);
IF (VATEntry3."VAT Registration No." <> '') OR NoTaxVATFound OR FromJournal THEN BEGIN
VendorLedgerEntry.CALCFIELDS(VendorLedgerEntry."Amount (LCY)");
Amt := Amt - VendorLedgerEntry."Amount (LCY)";
VendorAmount := VendorAmount - VendorLedgerEntry."Amount (LCY)";
UpdateQuarterAmount(AmountType::SameVATNo,-VendorLedgerEntry."Amount (LCY)",VendorLedgerEntry."Posting Date");
END;
UNTIL VendorLedgerEntry.NEXT = 0;
IF VendorMaxAmount < VendorAmount THEN BEGIN
VendorMaxAmount := VendorAmount;
Name347 := Vendor2.Name;
END;
UNTIL Vendor2.NEXT = 0;
Name347 := PADSTR(FormatTextName(Name347),40,' ');
END;
// End of the added lines.
EXIT(Amt);