project QadFinancials > class BAccountingInterface > method FillProDsIncomeStatement

Description

This method is used to generate the prodataset for Income Statement Report.


Parameters


icEntityListinputcharacterEntity List.
ohIncomeStatementoutputhandleHandle of Income Statement Report Prodataset.
itAccntFromDate1inputdateAccount From Date 1.
itAccntFromDate2inputdateAccount From Date 2.
itAccntToDate1inputdateAccount To Date1.
itAccntToDate2inputdateAccount To Date2.
iiBudgetLevelinputintegerBudget Level.
icReportStructISinputcharacterReport Strucure of Income Statement.
icLayerCodeinputcharacterLayer Code
icCOACrossRefCodeinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAccountingInterface.BulidProDataSet


program code (program3/baccountinginterface.p)

assign oiReturnStatus = -98.
/* Empty temp-tables which will be used later */
empty temp-table tIncomeStatement.
empty temp-table tSubIncomeStatement.
empty temp-table tReport.

/* Do validation on input parameter iiBudegetLevel */
if iiBudgetLevel < 1 or iiBudgetLevel > 8
then do:
    assign oiReturnStatus = -1.
    <M-1 run SetMessage
       (input  #T-1'The budget level must be an integer between 0 and 8 if you want to export the Income statement data file.':200(61682)T-1# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  '':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-6236':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BAccountingInterface>
    return.
end.

/* Start an instance of BGLReport in order to invoke its method */
if viBGLReportID  = 0 or viBGLReportID = ?
then do:
    <I-2 {bFcStartAndOpenInstance
         &CLASS                = "BGLReport"}>
end. /* if viBGLReportID  = 0 or viBGLReportID = ? */
else do:
    <I-3 {bFcStartInstance
         &CLASS                = "BGLReport"}>
end. /* if  not viBGLReportID  = 0 or viBGLReportID = ? */
     
/* to create a temp table, due to EDI limitation */
create tReport.
assign tReport.tiReportID = 1.

/* Initialize the integer variable for loop */
assign vii = 1.

/* Start querys */
<Q-8 run CompanyByIDAllInfo  (Start) in BCompany >
<Q-9 run CompanyPropertyByCompany  (Start) in BCompanyProperty >

repeat while vii <= num-entries(icEntityList):
    <Q-10 run CompanyByIDAllInfo (all) (Read) (NoCache)
       (input integer(entry(vii,icEntityList)), (CompanyId)
        output dataset tqCompanyByIDAllInfo) in BCompany >
    find first tqCompanyByIDAllInfo no-error.
    if not available tqCompanyByIDAllInfo
    then next.
    /* Construct the tFilter */
    /*find first tFilter where tFilter.tcBusinessFieldName = 'Division_CANDO':U no-error.
    if available tFilter
    then do:
         assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = '?':U.
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'Division_CANDO':U
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = '?':U. 
    end.*/
    /*find first tFilter where tFilter.tcBusinessFieldName = 'Layer_CANDO':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = icLayerCode.
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'Layer_CANDO':U
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = icLayerCode.
    end.*/
    /*find first tFilter where tFilter.tcBusinessFieldName = 'CostCenter_CANDO':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = '':U.
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'CostCenter_CANDO':U
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = '':U.
    end.*/
    /*find first tFilter where tFilter.tcBusinessFieldName = 'Measure1':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = 'Actuals':U.
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'Measure1':U
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue ='Actuals':U.
    end.
    find first tFilter where tFilter.tcBusinessFieldName = 'Measure1startDate':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = string(year(itAccntFromDate1)) + string(month(itAccntFromDate1),'99') + string(day(itAccntFromDate1),'99').
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'Measure1startDate':U
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = '='
            tFilter.tcParameterValue = string(year(itAccntFromDate1)) + string(month(itAccntFromDate1),'99') + string(day(itAccntFromDate1),'99').
    end.
    find first tFilter where tFilter.tcBusinessFieldName = 'Measure1TillDate':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = string(year(itAccntToDate1)) + string(month(itAccntToDate1),'99') + string(day(itAccntToDate1),'99').
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'Measure1TillDate':U
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = '='
            tFilter.tcParameterValue = string(year(itAccntToDate1)) + string(month(itAccntToDate1),'99') + string(day(itAccntToDate1),'99').
    end.*/
    /*find first tFilter where tFilter.tcBusinessFieldName = 'Measure3':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = 'Actuals':U.
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'Measure3':U
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = 'Actuals':U.
    end.
    find first tFilter where tFilter.tcBusinessFieldName = 'Measure3startDate':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = string(year(itAccntFromDate2)) + string(month(itAccntFromDate2),'99') + string(day(itAccntFromDate2),'99').
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'Measure3startDate':U
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = '='
            tFilter.tcParameterValue = string(year(itAccntFromDate2)) + string(month(itAccntFromDate2),'99') + string(day(itAccntFromDate2),'99').
    end.
    find first tFilter where tFilter.tcBusinessFieldName = 'Measure3TillDate':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = string(year(itAccntToDate2)) + string(month(itAccntToDate2),'99') + string(day(itAccntToDate2),'99').
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'Measure3TillDate':U
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = '='
            tFilter.tcParameterValue = string(year(itAccntToDate2)) + string(month(itAccntToDate2),'99') + string(day(itAccntToDate2),'99').
    end.*/

    find first tFilter where tFilter.tcBusinessFieldName = 'MeasureFromDate':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = string(year(itAccntFromDate1)) + string(month(itAccntFromDate1),'99') + string(day(itAccntFromDate1),'99').
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'MeasureFromDate':U
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = '='
            tFilter.tcParameterValue = string(year(itAccntFromDate1)) + string(month(itAccntFromDate1),'99') + string(day(itAccntFromDate1),'99').
    end.
    find first tFilter where tFilter.tcBusinessFieldName = 'MeasureToDate':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = string(year(itAccntToDate1)) + string(month(itAccntToDate1),'99') + string(day(itAccntToDate1),'99').
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'MeasureToDate':U
            tFilter.tcDataType = 't':U
            tFilter.tcOperator = '='
            tFilter.tcParameterValue = string(year(itAccntToDate1)) + string(month(itAccntToDate1),'99') + string(day(itAccntToDate1),'99').
    end.

    <Q-11 run CompanyPropertyByCompany (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input ?, (CompanyCode)
        input ?, (CurrencyCode)
        output dataset tqCompanyPropertyByCompany) in BCompanyProperty >
    find first tqCompanyPropertyByCompany no-error.
    if not available tqCompanyPropertyByCompany
    then next.
    find first tFilter where tFilter.tcBusinessFieldName = 'ReportingCurrency':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = tqCompanyPropertyByCompany.tcCurrencyCode. /* RMB */
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'ReportingCurrency':U
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = tqCompanyPropertyByCompany.tcCurrencyCode. /* RMB */
    end.

    find first tFilter where tFilter.tcBusinessFieldName = 'Company_CANDO':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = tqCompanyByIDAllInfo.tcCompanyCode.
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'Company_CANDO':U
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = tqCompanyByIDAllInfo.tcCompanyCode.
    end.
   
    find first tFilter where tFilter.tcBusinessFieldName = 'ReportStructure':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = icReportStructIS.
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'ReportStructure':U
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = icReportStructIS.
    end.
    find first tFilter where tFilter.tcBusinessFieldName = 'TopicLevel':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'i':U
            tFilter.tcOperator = ''
            /*tFilter.tcParameterValue = '8':U.*/
            tFilter.tcParameterValue = string(iiBudgetLevel).
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'TopicLevel':U
            tFilter.tcDataType = 'i':U
            tFilter.tcOperator = ''
            /*Filter.tcParameterValue = '8':U.*/
            tFilter.tcParameterValue = string(iiBudgetLevel).
    end.

    find first tFilter where tFilter.tcBusinessFieldName = 'COACrossRef':U no-error.
    if available tFilter
    then do:
        assign
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = icCOACrossRefCode.
    end.
    else do:
        create tFilter.
        assign
            tFilter.tcBusinessFieldName = 'COACrossRef':U
            tFilter.tcDataType = 'c':U
            tFilter.tcOperator = ''
            tFilter.tcParameterValue = icCOACrossRefCode.
    end.

    /* Call method IncomeStatementForCAI in BGLReport */
    create dataset vhResultSet in widget-pool "non-persistent".
    /*<M-20 run IncomeStatementForCAI
       (output vhResultSet (ohIncomeStatement), 
        input  tFilter (tFilter), 
        input  'EN' (icLanguageCode), 
        output viFcReturnSuper (oiReturnStatus)) in BGLReport>*/
    <M-30 run ChineseISForCAI
       (output vhResultSet (ohIncomeStatement), 
        input  tFilter (tFilter), 
        input  'EN':U (icLanguageCode), 
        output viFcReturnSuper (oiReturnStatus)) in BGLReport>
    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then do:
         <I-13 {bFcCloseAndStopInstance
              &CLASS           = "BGLReport"}>           
         return.
    end. /* if viFcReturnSuper < 0 */

    /*
    /* Use the dataset handle vhResultSet to get data */
    create query vhQuery in widget-pool "non-persistent".
    vhQuery:set-buffers(vhResultSet:get-buffer-handle(3)).
    vhQuery:query-prepare('for each ' + vhResultSet:get-buffer-handle(3):name).
    vhQuery:query-open().
    vhQuery:get-first().
    repeat while not vhQuery:query-off-end:
        /* Use temp-table SubIncomeState to store data */
        create tSubIncomeStatement.
        assign
            tSubIncomeStatement.tcFDSElementType     = vhResultSet:get-buffer-handle(3):buffer-field('tcFDSElementType'):buffer-value
            tSubIncomeStatement.tdMeasure1           = vhResultSet:get-buffer-handle(3):buffer-field('tdMeasure1'):buffer-value
            tSubIncomeStatement.tdMeasure2           = vhResultSet:get-buffer-handle(3):buffer-field('tdMeasure3'):buffer-value
            tSubIncomeStatement.tiBudgetFDSSeq       = vhResultSet:get-buffer-handle(3):buffer-field('tiBudgetFDSSeq'):buffer-value
            tSubIncomeStatement.tcTopic              = vhResultSet:get-buffer-handle(3):buffer-field('tcTopic' + string(iiBudgetLevel)):buffer-value
            tSubIncomeStatement.tcCompanyDescription = tqCompanyByIDAllInfo.tcCompanyDescription.
        /* Logic of getting tiLineNumber */
        assign vct_FieldName = 'tiTopic' + string(iiBudgetLevel) + 'WBSID'.
        <Q-14 run BudgetWBSByBudgetWBSID (all) (Read) (NoCache)
           (input vhResultSet:get-buffer-handle(3):buffer-field(vct_FieldName):buffer-value, (BudgetWBSID)
            output dataset tqBudgetWBSByBudgetWBSID) in BBudget >
        for first tqBudgetWBSByBudgetWBSID:
            assign tSubIncomeStatement.tiLineNumber = tqBudgetWBSByBudgetWBSID.tiBudgetWBSLineNumber.
        end.
        /* Logic of getting tcParentTopic */
        if iiBudgetLevel = 1
        then assign tSubIncomeStatement.tcParentTopic = ?.
        else assign tSubIncomeStatement.tcParentTopic = vhResultSet:get-buffer-handle(3):buffer-field('tcTopic' + string(iiBudgetLevel - 1)):buffer-value.
        vhQuery:get-next().
    end. /* repeat while not vhQuery:query-off-end: */
    vhQuery:query-close().
    assign vii = vii + 1.
    */

    /* Use the dataset handle vhResultSet to get data */
    create query vhQuery in widget-pool "non-persistent".
    vhQuery:set-buffers(vhResultSet:get-buffer-handle(1)).
    vhQuery:query-prepare('for each ' + vhResultSet:get-buffer-handle(1):name).
    vhQuery:query-open().
    vhQuery:get-first().
    repeat while not vhQuery:query-off-end:        
        create tIncomeStatement.
        assign
            tIncomeStatement.tcReportNo        = #T-29'Form AF-02':255(227670907)T-29#
            tIncomeStatement.tcReportEntity    = tqCompanyByIDAllInfo.tcCompanyDescription
            tIncomeStatement.tcReportDate      = string(itAccntToDate1)
            tIncomeStatement.tcCurrency        = #T-27'Yuan':255(591320860)T-27#
            tIncomeStatement.tcContent         = vhResultSet:get-buffer-handle(1):buffer-field('tcTopicProperty'):buffer-value
            tIncomeStatement.tcLines           = string(vhResultSet:get-buffer-handle(1):buffer-field('tiLineNumber'):buffer-value)
            tIncomeStatement.tdMonthlyMovement = round(vhResultSet:get-buffer-handle(1):buffer-field('tdPeriodActivity'):buffer-value, 2)
            tIncomeStatement.tdYearlyMovement  = round(vhResultSet:get-buffer-handle(1):buffer-field('tdYTDAmount'):buffer-value, 2)
            tIncomeStatement.tiReportID        = 1.
        vhQuery:get-next().
    end. /* repeat while not vhQuery:query-off-end: */
    vhQuery:query-close().
    assign vii = vii + 1.

end. /* repeat while vii <= num-entries(icEntityList): */
/* Stop querys */
<Q-23 run CompanyByIDAllInfo  (Stop) in BCompany >
<Q-24 run CompanyPropertyByCompany  (Stop) in BCompanyProperty >
/* Stop instance */
<I-17 {bFcCloseAndStopInstance
     &CLASS           = "BGLReport"}>

/*
/* Do more validation to iiBudgetLevel here */
find first tSubIncomeStatement where tSubIncomeStatement.tcFDSElementType = 'GL':U no-error.
if not available tSubIncomeStatement
then do:
    assign oiReturnStatus = -1.
    <M-21 run SetMessage
       (input  #T-20'The report structure for the income statement must include a GL level.':100(65680)T-20# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  '':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-7275':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BAccountingInterface>
    return.
end.
else do:
    assign viGLLevel = tSubIncomeStatement.tiBudgetFDSSeq.
end.
/* Validation: The BudgetLevel could not be larger than the GL level */
if iiBudgetLevel > viGLLevel
then do:
    assign oiReturnStatus = -1.
    <M-18 run SetMessage
       (input  #T-19'The budget level cannot be greater than the GL level.':100(59833)T-19# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  '':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-6310':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BAccountingInterface>
    return.
end. /* if iiBudgetLevel > viGLLevel */
/* Structure temp-table tIncomeStatement */
for each tSubIncomeStatement where tSubIncomeStatement.tiBudgetFDSSeq = iiBudgetLevel by tSubIncomeStatement.tcParentTopic:
     if tSubIncomeStatement.tcParentTopic <> ? and tSubIncomeStatement.tcParentTopic <> vct_ParentTopic
     then do:
         assign vct_ParentTopic = tSubIncomeStatement.tcParentTopic.
         create tIncomeStatement.
         assign
             tIncomeStatement.tcReportNo     = '??02?':U
             tIncomeStatement.tcReportEntity = tSubIncomeStatement.tcCompanyDescription
             tIncomeStatement.tcReportDate   = string(itAccntToDate2)
             tIncomeStatement.tcLines        = '':U
             tIncomeStatement.tcCurrency     = '?':U
             tIncomeStatement.tcContent      = tSubIncomeStatement.tcParentTopic + ':':U
             tIncomeStatement.tdMonthlyMovement = ?
             tIncomeStatement.tdYearlyMovement  = ?
             tIncomeStatement.tiReportID     = 1.
     end. /* if tSubIncomeStatement.tcParentTopic <> ? and tSubIncomeStatement.tcParentTopic <> vct_ParentTopic */
     if iiBudgetLevel <> viGLLevel or (iiBudgetLevel = viGLLevel and tSubIncomeStatement.tcFDSElementType = 'TopicTot':U)
     then do:
         create tIncomeStatement.
         assign
             tIncomeStatement.tcReportNo     = '??02?':U
             tIncomeStatement.tcReportEntity = tSubIncomeStatement.tcCompanyDescription
             tIncomeStatement.tcReportDate   = string(itAccntToDate2)
             tIncomeStatement.tcLines        = string(tSubIncomeStatement.tiLineNumber)
             tIncomeStatement.tcCurrency     = '?':U
             tIncomeStatement.tcContent      = tSubIncomeStatement.tcTopic
             tIncomeStatement.tdMonthlyMovement = tSubIncomeStatement.tdMeasure1
             tIncomeStatement.tdYearlyMovement = tSubIncomeStatement.tdMeasure2
             tIncomeStatement.tiReportID     = 1.
     end. /* if iiBudgetLevel <> viGLLevel or (iiBudgetLevel = viGLLevel and tSubIncomeStatement.tcFDSElementType = 'TopicTot':U) */
end. /* for each tSubIncomeStatement break by tSubIncomeStatement.tcTopic: */
*/

/* Use prodataset to encapsulate the temp-table */
create dataset ohIncomeStatement in widget-pool "non-persistent".
create buffer vhReport for table buffer tReport:handle in widget-pool "non-persistent".
create buffer vhIncomeStatement for table buffer tIncomeStatement:handle in widget-pool "non-persistent".
ohIncomeStatement:set-buffers(vhReport, vhIncomeStatement).
ohIncomeStatement:add-relation(vhReport, vhIncomeStatement, 'tiReportID,tiReportID', ?, true).
ohIncomeStatement:name = {&EXPORTREPORTCODE-Q_LR}.

if oiReturnStatus = -98
then assign oiReturnStatus = 0.