How to get purchase invoice amount total at the time of invoicing in MSD axapta PO

To  get purchase invoice amount total at the time of invoicing in axapta Purchase order you can try below  code in a method and just need to call that method on any event to get show total amount which will be invoice amount.

 vendPackingSlipJour _vendPackingSlipJour_1;  
 real TotalInvoiceAmt;  
 purchParmTable parmtable;  
 purchParmUpdate parmupdate;  
 PurchId _PurchId;  
 PurchTotals purchtotal;  
 ;  
 While Select parmtable where parmtable.ParmId == PurchParmTable.ParmId  
 && parmtable.Ordering == DocumentStatus::Invoice  
 {  
 Select parmupdate where parmupdate.ParmId == parmtable.ParmId;  
 _PurchId = parmtable.PurchId;  
 if(parmupdate)  
 {  
 purchtotal = PurchTotals::newPurchParmTable(parmtable, PurchUpdate::All, AccountOrder::Auto,  
 parmtable.ParmId, _PurchId, PurchParmTable.Ordering);  
 purchtotal.calc();  
 TotalInvoiceAmt+= purchtotal.purchTotalAmount();  
 }  
 }  
You can get total after select single packing slip or multiple packing slip.