project QadFinancials > class BERSProcessor > method ERSProcessInit

Description

Initializes the ERS processor:
- Sets class variables for creating and printing audit reports.
- The mode of the ERS processor (receipt or legal document).
- Re-calculation of taxes.
- Batch number used for grouping the supplier invoices created.


Parameters


icGroupByinputcharacterThe mode to be used by the ERS processor: indicates how the pending vouchers hsould be grouped (see the preprocessor ERSPROCESSOR).
ilIsCreateCIAndAPMatchinginputlogicalShould the ERS processor create supplier invoices and AP matching records?
ilIsPrintAuditReportinputlogicalShould the ERS processor print an audit report.
ilIsRecalculateTaxesinputlogicalShould taxes be re-calculated?
t_sERSProcessorRefinputtemp-tableTemp-table used to hold the pending vouchers that the ERS Processor will process into supplier invoices.
ocBatchNumberoutputcharacterNew Batch number used for creation of Supplier Invoices and corresponding Postings
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BERSProcessor.ERSProcessBatch


program code (program5/bersprocessor.p)

/* =================================================================================================== */
/* Method      : ERSProcessInit                                                                        */
/* Desc        : Initiate processing of selected receipts                                              */
/* --------------------------------------------------------------------------------------------------- */
/* Params:   (I) GroupBy                     Group invoices by Receiver/Legal document (see prepr.)    */
/*           (I) IsCreateCIAndAPMatching     Create supplier invoice and receiver matching             */
/*           (I) IsPrintAuditReport          Print audit report                                        */
/*           (I) IsRecalculateTaxes          Recalculate taxes if needed (for APMatchingLn)            */
/*           (O) ERSProcessorRef             Selected list of receipt lines for ERS processor          */
/*           (O) BatchNumber                 Batch number used for creation of CInvocies and Postings  */
/* =================================================================================================== */

assign oiReturnStatus = -98
       viLocalReturn  = 0.

/* =================================================================================================== */
/* Remember input parameters                                                                           */
/* =================================================================================================== */
assign vcGroupBy                 = icGroupBy
       vlIsCreateCIAndAPMatching = ilIsCreateCIAndAPMatching
       vlIsPrintAuditReport      = ilIsPrintAuditReport
       vlIsRecalculateTaxes      = ilIsRecalculateTaxes.
       
empty temp-table tERSProcessorRef.
empty temp-table tERSProcessorLogRef.

temp-table tERSProcessorRef:handle:copy-temp-table(temp-table t_sERSProcessorRef:handle).

/* =================================================================================================== */
/* Default output values                                                                               */
/* =================================================================================================== */
assign viERSId       = ?
       ocBatchNumber = ?.

/* =================================================================================================== */
/* Validate selected receipts for processing                                                           */
/* =================================================================================================== */
<M-3 run ERSProcessInitValidateAll  (output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper <  0 then return.

/* =================================================================================================== */
/* Create new record in ERS log file                                                                   */
/* =================================================================================================== */
/* Start transaction */
<I-4 {bFcStartAndOpenInstance
     &ADD-TO-TRANSACTION = "false"
     &CLASS              = "Transaction"}>        

<M-5 run StartTransaction  (output viFcReturnSuper (oiReturnStatus)) in Transaction>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper <  0 then return.
    
/* ========================================================================================================================= */
/* Normally we would here close the communication to class Transaction but we wont do it for performance reasons as this way */ 
/* the transaction does not have to be re-open when other instances are added to the transactionthe instance to commit it.   */
/* ========================================================================================================================= */

             
/* Update block */        
ERS_INIT_UPDATE_BLOCK:
do:
    /* Create new ERS log record */
    <I-7 {bFcStartAndOpenInstance
         &ADD-TO-TRANSACTION = "true"
         &CLASS              = "BERS"}>        
                 
    <M-8 run AddERS
       (input  vlIsPrintAuditReport (ilIsPrintAuditReport), 
        input  vlIsCreateCIAndAPMatching (ilIsCreateCInvAndRM), 
        input  today (itStartDate), 
        input  time (iiStartTime), 
        input  ? (itEndDate), 
        input  ? (iiEndTime), 
        output viERSId (oiERSId), 
        output viFcReturnSuper (oiReturnStatus)) in BERS>
    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper <  0 then leave ERS_INIT_UPDATE_BLOCK.

    <M-9 run ValidateBCAndAdditionalUpdate  (output viFcReturnSuper (oiReturnStatus)) in BERS>
    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper <  0 then leave ERS_INIT_UPDATE_BLOCK.

    if vlIsCreateCIAndAPMatching
    then do:
        /* Get new batch number and create new record in batch number file */
        <I-17 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION = "true"
             &CLASS              = "BMfgBatchNumber"}>
             
        <M-18 run GetNextBatchNumber
           (input  vcDomainCode (icDomain), 
            input  {&BATCHNUMBER-MODULE-AP} (icModule), 
            output vcBatchNumber (oiBatch), 
            output viFcReturnSuper (oiReturnStatus)) in BMfgBatchNumber>
        if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
        if viFcReturnSuper <  0 then leave ERS_INIT_UPDATE_BLOCK.
    
        assign ocBatchNumber = vcBatchNumber.
    
        <M-19 run ValidateBCAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BMfgBatchNumber>
        if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
        if viFcReturnSuper <  0 then leave ERS_INIT_UPDATE_BLOCK.
    end.
end. /* of ERS_INIT_UPDATE_BLOCK */

/* Complete transaction */
<I-10 {bFcOpenInstance
     &CLASS           = "Transaction"}>

if viLocalReturn >= 0
then do:
    <M-11 run CommitTransaction
       (input  true (ilStop), 
        input  ? (ihParentInstance), 
        output vcDummy (ocInstances), 
        output viFcReturnSuper (oiReturnStatus)) in Transaction>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
end.
else do:
    <M-12 run AbortTransaction
       (input  ? (ihParentInstance), 
        output vcDummy (ocInstances), 
        output viFcReturnSuper (oiReturnStatus)) in Transaction>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
end.

<I-13 {bFcCloseAndStopInstance
     &CLASS           = "Transaction"}>

/* =================================================================================================== */
/* Daybook for APMatching                                                                              */
/* Current implementation: - get first correct daybook where code contains "ERS"                       */
/*                         - get first active daybook                                                  */
/* Ideal implemenation   - create new field AP Matching Daybbok in ERS control                         */
/* =================================================================================================== */
<Q-14 run JournalByJournalLayer (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input ?, (JournalCode)
    input {&JOURNALTYPE-CIREC}, (CandoJournalTypeCode)
    input ?, (LayerCode)
    input {&LAYERTYPECODE-OFFICIAL}, (CandoLayerTypeCode)
    input ?, (JournalID)
    input true, (JournalIsActive)
    output dataset tqJournalByJournalAndLayer) in BJournal >

find first tqJournalByJournalAndLayer where
           tqJournalByJournalAndLayer.tcJournalTypeCode = {&JOURNALTYPE-CIREC}      and
           tqJournalByJournalAndLayer.tcLayerTypeCode   = {&LAYERTYPECODE-OFFICIAL} and
           tqJournalByJournalAndLayer.tlJournalIsActive = true                      and
           index(tqJournalByJournalAndLayer.tcJournalCode, "ERS":U) > 0
           no-error.
if not available tqJournalByJournalAndLayer
then find first tqJournalByJournalAndLayer where
                tqJournalByJournalAndLayer.tcJournalTypeCode = {&JOURNALTYPE-CIREC}      and
                tqJournalByJournalAndLayer.tcLayerTypeCode   = {&LAYERTYPECODE-OFFICIAL} and
                tqJournalByJournalAndLayer.tlJournalIsActive = true
                no-error.

if available tqJournalByJournalAndLayer
then assign vcAPMatchingJournalCode = tqJournalByJournalAndLayer.tcJournalCode.
else do:
    assign vcAPMatchingJournalCode = ?
           vcMessage               = #T-16'There is missing definition of Daybook to be used for creation of Receiver Matching. System first takes Receiver matching daybook which contains ERS keyword in the code. In second stage it takes first active Receiver matching daybook.':255(999890041)T-16#.
    <M-15 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8745':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
assign oiReturnStatus = viLocalReturn.