# How to get total transaction amount of supplier for current fiscal year

By | June 30, 2021

In Sage X3, only posted transactions will be considered for accounting effects. Here in this blog we had a requirment from a client that , there should be a field on the header of purchase invoice screen, in which total transaction amount of the Supplier should be displayed for current fiscal year according to the PAN No of the Supplier.

For e.g., if a supplier 1 has XYZ PAN No. and supplier 2 also has XYZ PAN No., then same total transaction amount will be displayed in the Purchase invoice screen for supplier 1 as well as supplier 2.

To fullfil user’s requirment follow below steps:

Step 1: Add “Total invoice Amt for current fiscal yr “(ZINVAMT) field into (PINVOICE)table and (header) screen

New Stuff: Validation on Purchase Invoice screen

[Table]
[Screen]

Step 2: Add below code into SPEPIH script

###### ####################################################################################

Local DECIMAL A
Local DECIMAL B
Local DECIMAL C

Local Char REQUEST1(255)(8)
REQUEST1(0) = ” SELECT SUM(AMTATI_0) FROM “+nomap+”.PINVOICE P “
REQUEST1(1) = ” LEFT OUTER JOIN “+nomap+”.BPSUPPLIER BPS ON BPS.BPSNUM_0=P.BPR_0 “
REQUEST1(2) = ” LEFT OUTER JOIN “+nomap+”.BPSUPPLIER BPS1 ON BPS1.BPSNUM_0='”+NUM\$([M:PIH0]BPR)+”‘”
REQUEST1(3) = ” WHERE BPS.XX1P4PANNO_0=BPS1.XX1P4PANNO_0 AND P.STA_0= ‘3’ AND P.ACCDAT_0 BETWEEN DateFromParts((CASE WHEN MONTH(‘”+[M:PIH0]ACCDAT+”‘) IN(1,2,3) THEN (YEAR(‘”+[M:PIH0]ACCDAT+”‘)-1) ELSE YEAR(‘”+[M:PIH0]ACCDAT+”‘) END),04,01) and ‘”+[M:PIH0]ACCDAT+”‘ “
REQUEST1(4) = ” GROUP BY BPS1.XX1P4PANNO_0″
FOR (DECIMAL DTEXTE_0) FROM “5” Sql REQUEST1 As [YCHD]
A =[YCHD]DTEXTE_0
NEXT

C=A-B
[M:PIH0]ZINVAMT=C
AFFZO[M:PIH0]ZINVAMT

######################################################################

Step 3: Compile SPEPIH script

[Output]

Now after validation of script, when user will create new purchase invoice, the total transaction amount of the posted invoices created against the supplier for the current fiscal year according to PAN No gets calculated and displayed in the ZINVAMT field as shown in above screenshot.