Tuesday, 22 March 2016

How to get sales/purchase tax/GST/VAT info for report?

 https://mycsharpdeveloper.wordpress.com/2015/07/03/how-to-get-salespurchase-taxgstvat-info-for-report/
If we customize Sales Invoice and Free Tax Invoice report for AX2012, we may need to get sales tax information. But how to get it. They are quite several ways to get it, and it depends only type of document you print also.
For posted Sales Invoice report
1
2
select taxTrans where taxTrans.InventTransId == _custInvoiceTrans.InventTransId;
    salesInvoiceTmp.TaxValue = taxTrans.TaxValue;
For posted Free Text Invoice report
1
2
3
4
select taxTrans
    where taxTrans.Source == TaxModuleType::FreeTxtInvoice
        && taxTrans.SourceTableId == tableNum(CustInvoiceTrans)
        && taxTrans.SourceRecId == _custInvoiceTrans.RecId;
For both Sales Invoice and Free Text Invoice report, it can be get like this also if you enable Tax Specification and you are inside SalesInvoiceDP or FreeTextInvoiceDP
1
this.getTaxValue(_taxSpec, _custInvoiceJour);
For none posted Sales Invoice / Free Text Invoice, for eg: Purchase Order confirmation or Sales Order confirmation, you can get data from TaxJournalTrans table.
1
2
3
4
5
6
7
8
TaxJournalTrans taxJournalTrans;

select sum(TaxAmount), TaxValue from taxJournalTrans
    group by TaxValue
    where taxJournalTrans.TransTableId == VendPurchOrderJour.TableId
    && TaxJournalTrans.TransRecId == VendPurchOrderJour.RecId;
//taxJournalTrans.TaxValue; //GST rate
//taxJournalTrans.TaxAmount; //GST amount
For Proforma report, you need to calculate tax using AX SalesTotals or PurchTotals class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
static void CalcTaxJob(Args _args)
{
    TmpTaxWorkTrans             tmpTax;
    SalesTable                  salesTable;
    SalesTotals                 salesTotals; //Use PurchTotals for Purchase Order
    ;

    salesTable  = SalesTable::find('YourSalesId');
    salesTotals = SalesTotals::construct(salesTable);

    // Calculate Tax
    salesTotals.calc();

    // Load tmpTaxWorkTrans
    tmpTax.setTmpData(salesTotals.tax().tmpTaxWorkTrans());

    // Showing taxes with tax value/rate
    while select tmpTax
    {
        info( strFmt('%1 : %2 : %3' , tmpTax.TaxCode, tmpTax.showTaxValue(), tmpTax.TaxAmount));
    }
}
If you need go to until every line level, you can use
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
static void CalcTaxJob(Args _args)
{
    TaxOnItem       TaxOnItem;
    TaxGroupData    TaxGroupData;
    real            TaxAmount;
    TaxValue        TaxValue;
    SalesLine       SalesLine
    ;
    
    select firstOnly from salesLine where salesLine.SalesId == 'YourSalesId';
    if(salesLine.TaxItemGroup && salesLine.TaxGroup && salesLine.LineAmount != 0)
    {
        while select TaxOnItem
            where TaxOnItem.TaxItemGroup == salesline.TaxItemGroup
        {
            if(TaxOnItem)
            {
                while select TaxGroupData
                    where TaxGroupData.TaxGroup == Salesline.TaxGroup
                        && TaxGroupData.TaxCode  == TaxOnItem.TaxCode
                {
                    if(TaxGroupData)
                    {
                        TaxValue  =  TaxData::find(TaxOnItem.TaxCode, Systemdateget(), 0).TaxValue;
                        TaxAmount = (Salesline.LineAmount * TaxValue) / 100;
                    }
                }
            }
        }
    }
}
Final note is although most of the examples here are for sales side, they are all applicable to purchase side.


1 comment:

  1. According to Stanford Medical, It is in fact the ONLY reason this country's women live 10 years longer and weigh on average 19 kilos less than us.

    (And actually, it is not related to genetics or some secret exercise and EVERYTHING about "how" they eat.)

    BTW, I said "HOW", not "WHAT"...

    Tap this link to find out if this little questionnaire can help you release your real weight loss potential

    ReplyDelete