4 Nisan 2014 Cuma

AX 2012 - Generate RDP (Report Data Provider)

Data Provider class:


------------Class Declaration-------------------
[SRSReportParameterAttribute(classStr(myCustInvoicePrintContract))]
class myCustInvoicePrintDP extends SRSReportDataProviderbase
{
    CustInvoicePrintTMP      InvoicePrint;
    CustInvoicePrintTransTMP InvoicePrintTrans;
    CustInvoicePrintTaxTMP   InvoicePrintTax;
    CustInvoicePrintFootTMP  InvoicePrintFoot;

    RecId                       RecId;
}

-----------------Table methods for SSRS---------------------------
[SRSReportDataSetAttribute(tableStr(CustInvoicePrintTMP))]
public CustInvoicePrintTMP getCustInvoicePrint()
{
    select * from InvoicePrint;
    return InvoicePrint;
}

[SRSReportDataSetAttribute(tableStr(CustInvoicePrintTransTMP))]
public CustInvoicePrintTransTMP getCustInvoicePrintTrans()
{
    select * from InvoicePrintTrans;
    return InvoicePrintTrans;
}

------------------GetParameter method--------------------------------
private void getReportParameters()
{
    myCustInvoicePrintContract Contract = this.parmDataContract();

    if (Contract)
    {
        RecId   = Contract.parmRecordId();
    }
}


------------------- processReport method where data filled--------
[SysEntryPointAttribute(false)]
public void processReport()
{
    CustInvoiceJour         InvoiceJour;
    CustInvoiceTrans        InvoiceTrans;
    TaxTrans                taxTrans;
    TaxOnItem               taxOnItem;
    TaxGroupData            taxGroupData;
    AmountMST               Tax;
    this.getReportParameters();

    InvoiceJour = CustInvoiceJour::findRecId(RecId);
    InvoicePrint.InvoiceDate    = InvoiceJour.InvoiceDate;
    InvoicePrint.InvoiceName    = InvoiceJour.invoiceName();
    InvoicePrint.TaxOfficeName_TR   = CustTable::find(InvoiceJour.InvoiceAccount).TaxOfficeName_TR;
    ...
    InvoicePrint.insert();
    while select InvoiceTrans where
        InvoiceTrans.SalesId == InvoiceJour.SalesId && InvoiceTrans.InvoiceId == InvoiceJour.InvoiceId &&
        InvoiceTrans.InvoiceDate == InvoiceJour.InvoiceDate && InvoiceTrans.numberSequenceGroup == InvoiceJour.numberSequenceGroup
    {
        select taxOnItem
                where taxOnItem.TaxItemGroup == InvoiceTrans.TaxItemGroup
            join taxGroupData
                where taxGroupData.TaxCode == taxOnItem.TaxCode &&
                      taxGroupData.TaxGroup == InvoiceTrans.TaxGroup;
        InvoicePrintTrans.TaxValue          = TaxData::find(TaxOnItem.TaxCode, InvoiceTrans.InvoiceDate, 0).TaxValue;
        InvoicePrintTrans.Qty               = InvoiceTrans.Qty;
        ...
        InvoicePrintTrans.insert();
        Tax = Tax::calcTaxAmount(InvoiceTrans.TaxGroup,taxOnItem.TaxItemGroup,InvoiceTrans.InvoiceDate,
                InvoiceTrans.CurrencyCode,InvoiceTrans.LineAmount,TaxModuleType::Sales);
        ...
            InvoicePrintTax.insert();
        }
    }
    ...
}


Controller class:

--------------Class Declaration------------------
class myCustInvoicePrintController extends SrsReportRunController
{
    #define.ReportName('CustInvoicePrint.Report')
    myCustInvoicePrintContract    contract;
    CustInvoiceJour           custInvoiceJour;
}

Get parameter
protected void prePromptModifyContract()
{
    if (this.parmArgs()             &&
        this.parmArgs().record()    &&
        this.parmArgs().dataset() == tableNum(CustInvoiceJour))
    {
        custInvoiceJour = this.parmArgs().record();
    }

    if (!Contract)
    {
        Contract = this.parmReportContract().parmRdpContract();
    }

    contract.parmRecordId(custInvoiceJour.RecId);

    super();
}

public static myCustInvoicePrintController construct(Args _args)
{
    myCustInvoicePrintController controller = new myCustInvoicePrintController();
    controller.parmArgs(_args);
    return controller;
}

public static void main(Args _args)
{
    SysLastValue    SysLastValue;
    myCustInvoicePrintController controller = new myCustInvoicePrintController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);

    if(CSReportPrint::find(SysUserInfo::find().RecId,CSReportType::Invoice1).PrinterName)
    {
        controller.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Printer);
        controller.parmReportContract().parmPrintSettings().printerName(CSReportPrint::find(SysUserInfo::find().RecId,CSReportType::Invoice1).PrinterName);
    }
    controller.parmShowDialog(false); //don't show dialog at screen
    controller.startOperation();
}



Contract class:
---------------class declaration---------------------------

[DataContractAttribute]
class myCustInvoicePrintContract
{
    RecId recordId;
}
Get parameter
[DataMemberAttribute('RecordId')]
public recId parmRecordId(recId _recordId = recordId)
{
   recordId = _recordId;
   return recordId;
}