report 60009 "Purchase Invoice Test"
{
DefaultLayout = RDLC;
RDLCLayout = './ReportLayouts/PurchInvTest.rdl';
Caption = 'Purchase Invoice - Test';
dataset
{
dataitem("Purchase Header"; "Purchase Header")
{
DataItemTableView = SORTING("No.") WHERE("document Type" = FILTER(Invoice));
RequestFilterFields = "No.", "Buy-from Vendor No.", "No. Printed";
RequestFilterHeading = 'Purchase Invoice';
column(Pay_to_Vendor_No_; "Pay-to Vendor No.")
{
}
column(Pay_to_Name; "Pay-to Name")
{
}
column(Pay_to_Address; "Pay-to Address")
{
}
column(Pay_to_Address_2; "Pay-to Address 2")
{
}
column(Pay_to_City; "Pay-to City")
{
}
column(Pay_to_Post_Code; "Pay-to Post Code")
{
}
column(VAT_Registration_No_; "VAT Registration No.")
{
}
column(PaymentTermsName; PaymentTermsName)
{
}
column(No_; "No.")
{
}
column(Document_Date; "Document Date")
{
}
column(Personname; Personname)
{
}
column(Vendor_Shipment_No_; "Vendor Shipment No.")
{
}
column(Vendor_Invoice_No_; "Vendor Invoice No.")
{
}
column(currencytxt; currencytxt)
{
}
column(CompInfo_TRN; CompInfo."VAT Registration No.")
{
}
column(CompInfo_picture; CompInfo.Picture)
{
}
column(GrandTotalInText; GrandTotalInText)
{
}
column(paymentname; paymentname)
{
}
column(g_txtCommentsArr1; g_txtCommentsArr[1])
{
}
column(g_txtCommentsArr2; g_txtCommentsArr[2])
{
}
column(username; username)
{
}
column(Location_Code; "Location Code")
{
}
column(LocName; LocName)
{
}
column(currencyfactor; currencyfactor)
{
}
column(totalfx; totalfx)
{
}
column(TotalDisc; TotalDisc)
{
}
column(totalvatbaseamt; totalvatbaseamt)
{
}
column(totallcyamt; totallcyamt)
{
}
column(totalvatfive; totalvatfive)
{
}
column(totallcywithvat; totallcywithvat)
{
}
column(ReverseVat; ReverseVat)
{
}
column(TotAmt; TotAmt)
{
}
dataitem("Purchase Line"; "Purchase Line")
{
DataItemLink = "Document No." = FIELD("No.");
DataItemLinkReference = "Purchase Header";
column(Line_No_; "Line No.")
{
}
column(Type; Type)
{
}
column(Item_No_; "No.")
{
}
column(Description; Description)
{
}
column(Unit_of_Measure_Code; "Unit of Measure Code")
{
}
column(Quantity; Quantity)
{
}
column(Direct_Unit_Cost; "Direct Unit Cost")
{
}
column(Line_Amount; "Line Amount")
{
}
column(VAT_Base_Amount; "VAT Base Amount")
{
}
column(DiscAmt; DiscAmt)
{
}
column(lcyamt; lcyamt)
{
}
column(vatamt; vatamt)
{
}
column(lcyamtwithvat; lcyamtwithvat)
{
}
trigger OnAfterGetRecord()
begin
Clear(DiscAmt);
DiscAmt := "Inv. Discount Amount" + "Line Discount Amount";
Clear(lcyamt);
Clear(vatamt);
Clear(lcyamtwithvat);
lcyamt := "VAT Base Amount" * currencyfactor;
vatamt := lcyamt * ("VAT %" / 100);
lcyamtwithvat := lcyamt + vatamt;
end;
}
trigger OnAfterGetRecord()
begin
Clear(PaymentTermsName);
PaymentTermRec.Reset();
PaymentTermRec.SetRange(Code, "Purchase Header"."Payment Terms Code");
if PaymentTermRec.FindFirst() then
PaymentTermsName := PaymentTermRec.Description;
Clear(Personname);
SalespersonRec.Reset();
SalespersonRec.SetRange(Code, "Purchase Header"."Purchaser Code");
if SalespersonRec.FindFirst() then
Personname := SalespersonRec.Name;
Clear(currencyfactor);
Clear(currencytxt);
if ("Currency Code" <> 'AED') and ("Currency Code" <> '') then begin
currencyfactor := 1 / "Purchase Header"."Currency Factor";
currencyfactor := Round(currencyfactor, 0.001, '=');
currencytxt := "Purchase Header"."Currency Code";
end else begin
currencyfactor := 1;
currencytxt := "Purchase Header"."Currency Code";
end;
Clear(LocName);
if locrec.Get("Purchase Header"."Location Code") then
LocName := locrec.Name;
Clear(paymentname);
paymentMethodrec.Reset();
paymentMethodrec.SetRange(Code, "Purchase Header"."Payment Method Code");
if paymentMethodrec.FindFirst() then;
paymentname := paymentMethodrec.Description;
Clear(totalfx);
Clear(TotalDisc);
Clear(totalvatbaseamt);
Clear(totalvatfive);
Clear(totallcyamt);
Clear(totallcywithvat);
Clear(TotAmt);
PurchLine.Reset;
PurchLine.SetRange("Document Type", PurchLine."Document Type"::Invoice);
PurchLine.SetRange("Document No.", "Purchase Header"."No.");
if PurchLine.FindSet then
repeat
totalfx := totalfx + PurchLine."Line Amount";
TotalDisc := TotalDisc + (PurchLine."Inv. Discount Amount" + PurchLine."Line Discount Amount");
totalvatbaseamt := totalvatbaseamt + PurchLine."VAT Base Amount";
totallcyamt := totallcyamt + (PurchLine."VAT Base Amount" * currencyfactor);
//totalvatfive := totalvatfive + totallcyamt * (PurchLine."VAT %" / 100);
totalvatfive := totalvatfive + ((PurchLine."VAT Base Amount" * currencyfactor) * (PurchLine."VAT %" / 100));
until PurchLine.Next = 0;
//totalvatfive := totallcyamt * 0.05;
TotAmt := totallcyamt + totalvatfive;
Clear(ReverseVat);
/*if (PurchLine."VAT Bus. Posting Group" = 'IMPORT') or (PurchLine."VAT Bus. Posting Group" = 'INTERCO') then begin
totallcywithvat := totallcyamt;
ReverseVat := Round(totalvatfive, 0.01, '=');
end
else begin
ReverseVat := 0.00;
totallcywithvat := totallcyamt + totalvatfive;
end;*/
//
PurchLine1.Reset;
PurchLine1.SetRange("Document Type", PurchLine."Document Type"::Invoice);
PurchLine1.SetRange("Document No.", "Purchase Header"."No.");
if PurchLine1.FindSet then
repeat
if VATPostingSetup.Get(PurchLine1."VAT Bus. Posting Group", PurchLine1."VAT Prod. Posting Group") then begin
If VATPostingSetup."VAT Calculation Type" = VATPostingSetup."VAT Calculation Type"::"Reverse Charge VAT" then begin
ReverseVat := ReverseVat + (PurchLine1."VAT Base Amount" * currencyfactor) * (VATPostingSetup."VAT %" / 100);
totalvatfive := totalvatfive + (PurchLine1."VAT Base Amount" * currencyfactor) * (VATPostingSetup."VAT %" / 100);
end;
end;
until PurchLine1.Next = 0;
//
ReverseVat := -Round(ReverseVat, 0.01, '=');
//
if ReverseVat = 0 then
totallcywithvat := totalvatfive + totallcyamt
else
totallcywithvat := totallcyamt + totalvatfive + ReverseVat;
//
Clear(g_txtCommentsArr);
PurchCommentLine.Reset();
PurchCommentLine.SetRange("No.", "Purchase Header"."No.");
PurchCommentLine.SetRange("Document Type", PurchCommentLine."Document Type"::Invoice);
PurchCommentLine.SetRange("Document Line No.", 0);
if PurchCommentLine.FindFirst() then begin
i := 0;
repeat
i += 1;
g_txtCommentsArr[i] := PurchCommentLine.Comment;
until (PurchCommentLine.Next = 0) or (i = 2);
end;
userid.Reset();
Clear(username);
if userid.Get(SystemCreatedBy) then
username := userid."User Name";
checkReportData.InitTextVariable();
PurchLine.setrange("Document No.", "Purchase Header"."No.");
if PurchLine.Findset then
totallcywithvat := totallcywithvat;
checkReportData.FormatNoText(GrandTotalInTextArr, Round(totallcywithvat, 0.01), 'AED');
GrandTotalInText := GrandTotalInTextArr[1];
end;
}
}
trigger OnInitReport()
begin
CompInfo.get();
CompInfo.CalcFields(Picture);
end;
var
vatamt: Decimal;
CompInfo: Record "Company Information";
totalAmtSum: Decimal;
checkReportData: Report 1401;
GrandTotalInTextArr: Array[2] of Text[180];
GrandTotalInText: Text[80];
TotAmt: Decimal;
PurchLine: Record "Purchase Line";
PurchLine1: Record "Purchase Line";
PurchCommentLine: Record "Purch. Comment Line";
g_txtCommentsArr: array[2] of text[80];
i: Integer;
userid: Record User;
username: Text;
DimensionID: Record "Dimension Set Entry";
DiscAmt: Decimal;
TotalDisc: Decimal;
LocName: Text;
lcyamt: Decimal;
lcyamtwithvat: Decimal;
totalfx: Decimal;
totalvatbaseamt: Decimal;
totallcyamt: Decimal;
totalvatfive: Decimal;
totallcywithvat: Decimal;
currencyfactor: Decimal;
currencytxt: Text;
locrec: Record Location;
paymentname: Text;
paymentMethodrec: Record "Payment Method";
ReverseVat: Decimal;
Personname: Text;
SalespersonRec: Record "Salesperson/Purchaser";
CurrExchRate: Record "Currency Exchange Rate";
CurrExAmt: Decimal;
CurrExName: Code[20];
VenRec: Record Vendor;
PaymentTermsName: Text[120];
PaymentTermRec: Record "Payment Terms";
VATPostingSetup: REcord "VAT Posting Setup";
}