project QadFinancials > class BCInvoice > method AdditionalUpdatesAllAssignments

Description

This submethod of AdditionalUpdatesAll holds all program-code for some assigments and the run of the validations in BJE


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.AdditionalUpdatesAll


program code (program8/bcinvoice.p)

    
    
        
    assign oiReturnStatus = -98.
    
    /* General note: BJournalEntry is already started and opened by the caller-method */
    if can-find(first tCInvoiceMovement where
                      tCInvoiceMovement.tc_Status <> "":U) and
       (viBJournalEntryCIID = 0                            or
        viBJournalEntryCIID = ?                            or
        not valid-handle(vhBJournalEntryCIInst))
    then do:
        assign vcMessage      = trim(#T-36'Internal error: unexpected situation-no communication to the postings available':255(17891)T-36#) + chr(10) +
                                trim(substitute(#T-37'Instance ID = &1.':255(17892)T-37#,string(viBJournalEntryCIID)))                         + chr(10) +
                                trim(substitute(#T-38'Valid handle = &1.':255(17893)T-38#,string(valid-handle(vhBJournalEntryCIInst) = TRUE))) + chr(10) +
                                trim(substitute(#T-39'Handle value = &1.':255(17894)T-39#,string(vhBJournalEntryCIInst)))
               oiReturnStatus = -3.
    
        <M-35 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-4482':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    
        return.
    end. /* if can-find(first tCInvoiceMovement */
    
    for each tCInvoice where
             tCInvoice.tc_status <> "D":U,
        each tCInvoiceMovement where 
             tCInvoiceMovement.tc_ParentRowid = tCInvoice.tc_Rowid and 
            (tCInvoiceMovement.tc_Status = "N":U or
             tCInvoiceMovement.tc_Status = "C":U) 
        no-lock:
        if not can-find(first tPostingPostingLineInfoCIJE where
                              tPostingPostingLineInfoCIJE.tiPostingLine_ID = tCInvoiceMovement.PostingLine_ID)
        then do:
            create tPostingPostingLineInfoCIJE.
            assign tPostingPostingLineInfoCIJE.tiPostingLine_ID = tCInvoiceMovement.PostingLine_ID.
        end. /* if not can-find(first tPostingPostingLineInfoCIJE  */
    end.     /* or each tCInvoice where                            */
    
    if can-find(first tPostingPostingLineInfoCIJE)
    then do:
        <M-47 run GetPostingInfoByPostingLineIDTT
           (input-output tPostingPostingLineInfoCIJE (tPostingPostingLineInfo), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then return.
    end. /* if can-find(first tPostingPostingLineInfoCIJE) */
    
    /* Go through all non-deleted CI's */
    for each tCInvoice where
             tCInvoice.tc_status <> "D":U:
        /* Fill in the CC and LC amounts on the Stage-records */
        for each tCInvoiceStage where
                 tCInvoiceStage.tc_ParentRowid = tCInvoice.tc_Rowid and
                (tCInvoiceStage.tc_Status      = "N":U              or
                 tCInvoiceStage.tc_Status      = "C":U):
            /* LC amounts */
            if tCInvoice.tcCurrencyCode = vcCompanyLC
            then assign tCInvoiceStage.CInvoiceStageAmountLC = tCInvoiceStage.CInvoiceStageAmountTC.
            else assign tCInvoiceStage.CInvoiceStageAmountLC =
                     <M-40 RoundAmount
                        (input  tCInvoiceStage.CInvoiceStageAmountTC * tCInvoice.CInvoiceExchangeRate * tCInvoice.CInvoiceRateScale (idUnroundedAmount), 
                         input  viCompanyLCId (iiCurrencyID), 
                         input  vcCompanyLC (icCurrencyCode)) in business>.
    
            /* CC amounts */
            if  vcCompanyCC = tCInvoice.tcCurrencyCode
            then assign tCInvoiceStage.CInvoiceStageAmountCC = tCInvoiceStage.CInvoiceStageAmountTC.
            else if vlDomainIsStatutory = false
            then assign tCInvoiceStage.CInvoiceStageAmountCC = tCInvoiceStage.CInvoiceStageAmountLC.
            else do:
                
                <M-86 run GetExRateByEntityInvoiceFlag
                   (input  tCInvoice.CInvoiceDate (itCInvoiceDate), 
                    input  tCInvoice.CInvoicePostingDate (itCInvoicePostingDate), 
                    input  tCInvoice.CInvoiceCurrency_ID (iiFromCurrencyId), 
                    input  ? (icFromCurrencyCode), 
                    input  viCompanyCCId (iiToCurrencyId), 
                    input  ? (icToCurrencyCode), 
                    input  ? (iiExchangeRateTypeId), 
                    input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                    output vdExchangeRate (odCInvoiceExchangeRate), 
                    output vdExchangeRateScale (odCInvoiceRateScale), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                    
                if viFcReturnSuper <> 0
                then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0 then return.
    
                assign tCInvoiceStage.CInvoiceStageAmountCC =
                    <M-41 RoundAmount
                       (input  tCInvoiceStage.CInvoiceStageAmountTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount), 
                        input  viCompanyCCId (iiCurrencyID), 
                        input  vcCompanyCC (icCurrencyCode)) in business>.
            end. /* else do:                      */
        end.     /* for each tCInvoiceStage where */
    
        if tCInvoice.tdCInvoiceOriginalTC = 0
        then do:
            /* CI Posting */
            find first tCInvoicePosting where
                       tCInvoicePosting.tc_ParentRowid      = tCInvoice.tc_Rowid            and
                       tCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-INITIAL} and
                       tCInvoicePosting.tc_Status           = "N":U
                       no-error.
    
            if available tCinvoicePosting
            then do:
                <M-43 run SetPostingIsZeroValueAllowed
                   (input  ? (icPostingRowId), 
                    input  tCInvoicePosting.Posting_ID (iiPostingId), 
                    input  true (ilPostingIsZeroValueAllowed), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    
                if viFcReturnSuper < 0 or
                   oiReturnStatus  = 0
                then assign oiReturnStatus = viFcReturnSuper.
    
                if viFcReturnSuper < 0
                then leave.
            end. /* if available tCinvoicePosting */
    
            /* MF Posting */
            find first tCInvoicePosting where
                       tCInvoicePosting.tc_ParentRowid      = tCInvoice.tc_Rowid               and
                       tCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION} and
                       tCInvoicePosting.tc_Status           = "N":U
                       no-error.
    
            if available tCinvoicePosting
            then do:
                <M-44 run SetPostingIsZeroValueAllowed
                   (input  ? (icPostingRowId), 
                    input  tCInvoicePosting.Posting_ID (iiPostingId), 
                    input  true (ilPostingIsZeroValueAllowed), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    
                if viFcReturnSuper < 0 or
                   oiReturnStatus  = 0
                then assign oiReturnStatus = viFcReturnSuper.
    
                if viFcReturnSuper < 0
                then leave.
            end. /* if available tCinvoicePosting         */
        end.     /* if tCInvoice.tdCInvoiceOriginalTC = 0 */
    
        /* Assign some fields in the CInvoiceMovements */
        for each tCInvoiceMovement where
                 tCInvoiceMovement.tc_ParentRowid = tCInvoice.tc_Rowid and
                (tCInvoiceMovement.tc_Status      = "N":U              or
                 tCInvoiceMovement.tc_Status      = "C":U):
            /* Check in the JE-instance */
            find first tPostingPostingLineInfoCIJE where
                       tPostingPostingLineInfoCIJE.tiPostingLine_ID = tCInvoiceMovement.PostingLine_ID
                       no-error.
            if not available tPostingPostingLineInfoCIJE
            then do:
                assign vcMessage      = trim(#T-49'Internal error: unexpected situation - no postingline information available':255(999890248)T-49#) + chr(10) +
                                        trim(substitute(#T-50'Posting Line ID = &1.':255(999890249)T-50#,string(tCInvoiceMovement.PostingLine_ID)))
                       oiReturnStatus = -3.
            
                <M-48 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-8980':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                next.
            end. /* if not available tPostingPostingLineInfoCIJE */
            assign tCInvoiceMovement.Company_ID                 = tCInvoice.Company_ID
                   tCInvoiceMovement.Period_ID                  = tPostingPostingLineInfoCIJE.tiPeriod_ID
                   tCInvoiceMovement.Creditor_ID                = tCInvoice.Creditor_ID
                   tCInvoiceMovement.CInvoiceMovementYearPeriod = tPostingPostingLineInfoCIJE.tiPostingYearPeriod
                   tCInvoiceMovement.CInvoiceMovementPostDate   = tPostingPostingLineInfoCIJE.ttPostingDate.
        end. /* for each tCInvoiceMovement where */
    
        /* State the closing Date if the CI */
        if tCInvoice.CInvoiceIsOpen
        then assign tCInvoice.CInvoiceClosingDate = 12/31/9999.
        else do:
            assign vtLastDateOfInvoiceMovement  = ?.
    
            find t_iCInvoice where
                 t_iCInvoice.tc_Rowid = tCInvoice.tc_Rowid
                 no-error.
    
            if not available t_iCInvoice or
               t_iCInvoice.CInvoiceIsOpen
            then do:
                for each tCInvoiceMovement where
                         tCInvoiceMovement.tc_ParentRowid = tCInvoice.tc_Rowid:
                    /* Check in the db; if found then next */
                    if not vlStartPostingByPostingLineId
                    then do:
                        <Q-45 run PostingByPostingLineId  (Start) in BPosting >
                        assign vlStartPostingByPostingLineId = true.
                    end. /* if not vlStartPostingByPostingLineId */
    
                    <Q-11 run PostingByPostingLineId (all) (Read) (NoCache)
                       (input tCInvoice.Company_ID, (CompanyId)
                        input tCInvoiceMovement.PostingLine_ID, (PostingLineId)
                        output dataset tqPostingByPostingLineId) in BPosting >
    
                    find tqPostingByPostingLineId where
                         tqPostingByPostingLineId.tiCompany_ID     = tCInvoice.Company_ID and
                         tqPostingByPostingLineId.tiPostingLine_ID = tCInvoiceMovement.PostingLine_ID
                         no-error.
    
                    if available tqPostingByPostingLineId
                    then do:
                        if tqPostingByPostingLineId.ttPostingDate > vtLastDateOfInvoiceMovement or
                           vtLastDateOfInvoiceMovement            = ?
                        then assign vtLastDateOfInvoiceMovement = tqPostingByPostingLineId.ttPostingDate.
    
                        assign tCInvoiceMovement.Company_ID                 = tCInvoice.Company_ID
                               tCInvoiceMovement.Period_ID                  = tqPostingByPostingLineId.tiPeriod_ID
                               tCInvoiceMovement.Creditor_ID                = tCInvoice.Creditor_ID
                               tCInvoiceMovement.CInvoiceMovementYearPeriod = tqPostingByPostingLineId.tiPeriodYearPeriod
                               tCInvoiceMovement.CInvoiceMovementPostDate   = tqPostingByPostingLineId.ttPostingDate.
    
                        next.
                    end. /* if available tqPostingByPostingLineId */
    
                    /* Check in the instance */
                    find first tPostingPostingLineInfoCIJE where
                               tPostingPostingLineInfoCIJE.tiPostingLine_ID = tCInvoiceMovement.PostingLine_ID
                               no-error.
                    if available tPostingPostingLineInfoCIJE
                    then do:
                        if tPostingPostingLineInfoCIJE.ttPostingDate <> ? and
                          (tPostingPostingLineInfoCIJE.ttPostingDate  > vtLastDateOfInvoiceMovement or
                           vtLastDateOfInvoiceMovement = ?)
                        then assign vtLastDateOfInvoiceMovement = tPostingPostingLineInfoCIJE.ttPostingDate.
                    end. /* if available tPostingPostingLineInfoCIJE */
                end.     /* for each tCInvoiceMovement where         */
    
                assign tCInvoice.CInvoiceClosingDate = if vtLastDateOfInvoiceMovement = ?
                                                       then today
                                                       else vtLastDateOfInvoiceMovement.
            end. /* if not available t_iCInvoice    */
        end.     /* NOT if tCInvoice.CInvoiceIsOpen */
        
        /* Update of the postinglines if the invoice is linked to another invoice with a different CC rate */
        if tCInvoice.LinkedCInvoice_ID <> 0 
        then do:
        
            /* Check if the bjournalentry instance is open or not. If not open, then open an instance. */
            if not valid-handle(vhBJournalEntryCIInst)
            then do:
                <I-73 {bFcOpenInstance
                     &CLASS           = "BJournalEntry"}>
                assign vlBJournalEntryOpenInThisMethod = TRUE.
            end. /* if not valid-handle(vhBJournalEntryCIInst) */
        
        
            /* Get the linked invoice */
            <Q-66 run CInvoiceByInvoiceNumber (all) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                input tCInvoice.tiLinkedPeriodYear, (CInvoicePostingYear)
                input tCInvoice.tiLinkedCInvoiceVoucher, (CInvoiceVoucher)
                input tCInvoice.tcLinkedJournalCode, (JournalCode)
                output dataset tqCInvoiceByInvoiceNumber) in BCInvoice >
         
            find first tqCInvoiceByInvoiceNumber where
                       tqCInvoiceByInvoiceNumber.tiCInvoicePostingYear = tCInvoice.tiLinkedPeriodYear      and
                       tqCInvoiceByInvoiceNumber.tiCInvoiceVoucher     = tCInvoice.tiLinkedCInvoiceVoucher and 
                       tqCInvoiceByInvoiceNumber.tcJournalCode         = tCInvoice.tcLinkedJournalCode     and
                       tqCInvoiceByInvoiceNumber.tiCompany_ID          = viCompanyId       
            no-lock no-error.
            if available tqCInvoiceByInvoiceNumber and
                         tqCInvoiceByInvoiceNumber.ttCInvoicePostingDate <> tCInvoice.CInvoicePostingDate
            then do: 
                <M-76 run UpdatePostinglineCCAmts
                   (input-output tPostingPostingLineInfoCIJE (tPostingPostingLineInfo), 
                    input  tqCInvoiceByInvoiceNumber.tdCInvoiceCCRate (idRateCC), 
                    input  tqCInvoiceByInvoiceNumber.tdCInvoiceCCScale (idRateScaleCC), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>        
                if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0 then Leave.
    
            end. /* if available tqCInvoiceByInvoiceNumber */
        end.     /* if tCInvoice.LinkedCInvoice_ID <> 0    */
    end.         /* for each tCInvoice where               */
    
    if vlStartPostingByPostingLineId
    then do:
        <Q-46 run PostingByPostingLineId  (Stop) in BPosting >
    end. /* if vlStartPostingByPostingLineId */
    
    /* Check if the instance to BournalEntry needs to be closed. */
    if vlBJournalEntryOpenInThisMethod = TRUE
    then .  /* ========================================================================================================= */
            /* Normally we would here close the communication to BJournalEntry but we will not do it for performance     */
            /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
            /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
            /* appserver that is executed after each call to the appserver                                               */
            /* ========================================================================================================= */
    
                    
    /* Set default return-status */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.