project QadFinancials > class BOpenItemAdjustment > method OIAdjCommitValidateOne

Description

OIAdjCommit; Save the whole adjustment: validations


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BOpenItemAdjustment.OIAdjCommit


program code (program8/bopenitemadjustment.p)

/* ====================================== */
/* Exception handling - processing block  */
/* ====================================== */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.
VALIDATIONONEBLOCK : DO :
    
    /* ============================================== */
    /* Get the Layer and Control based on the Journal */
    /* ============================================== */
    if viMainPostingCompanyID   <> 0    and 
       viMainPostingCompanyID   <> ?    and 
       vcMainPostingJournalCode <> "":U and 
       vcMainPostingJournalCode <> ?
    then do :
        <Q-219 run JournalByJournalLayer (all) (Read) (NoCache)
           (input viMainPostingCompanyID, (CompanyId)
            input vcMainPostingJournalCode, (JournalCode)
            input ?, (CandoJournalTypeCode)
            input ?, (LayerCode)
            input ?, (CandoLayerTypeCode)
            input ?, (JournalID)
            input ?, (JournalIsActive)
            output dataset tqJournalByJournalAndLayer) in BJournal >
        find first tqJournalByJournalAndLayer no-lock no-error.
        if not available tqJournalByJournalAndLayer 
        then do :
            assign vcMsgOIAdj          = trim(substitute(#T-223'Cannot find the daybook based on its code &1.':255(69636)t-223#,vcMainPostingJournalCode)) + chr(10) + 
                                         trim(substitute(#T-224'Company ID: &1':255(69637)t-224#,string(viMainPostingCompanyID)))
                   viLocalReturnStatus = -1.
            <M-220 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-8209':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Leave VALIDATIONONEBLOCK.
        end. /* if not available tqJournalByJournalAndLayer */
        if tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-CREDITORADJUSTMENT} and
           tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-DEBTORADJUSTMENT} 
        then do:
            assign vcMsgOIAdj          = trim(substitute(#T-225'The daybook type of the selected daybook must be &1 or &2.':255(2911)t-225#, {&JOURNALTYPE-CREDITORADJUSTMENT-TR}, {&JOURNALTYPE-DEBTORADJUSTMENT-TR}))
                   viLocalReturnStatus = -1.
            <M-221 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-8210':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Leave VALIDATIONONEBLOCK.
        end. /* if tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-CREDITORADJUSTMENT} and */
        if tqJournalByJournalAndLayer.tcJournalControl <> {&JOURNALCONTROL-FINANCIAL}
        then do:
            assign vcMsgOIAdj          = trim(substitute(#T-226'Daybook &1 has invalid daybook control &2.':255(69638)t-226#, vcMainPostingJournalCode, tqJournalByJournalAndLayer.tcJournalControl)) + chr(10) +
                                         trim(substitute(#T-227'You can only specify daybooks with control &1.':255(69634)t-227#,{&JOURNALCONTROL-FINANCIAL-TR}))
                   viLocalReturnStatus = -1.
            <M-222 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-8211':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Leave VALIDATIONONEBLOCK.
        end. /* if tqJournalByJournalAndLayer.tcJournalControl <> {&JOURNALCONTROL-FINANCIAL} */
    end. /* if viMainPostingCompanyID   <> 0    and */
    
    /* ======================================================================================= */
    /* Round all amounts in the input table; this shoudl normaly be done by the caller but as  */
    /* the C#-client or the .Net-remoting have problems with it for the moment; we do it here. */
    /* Clear tcCreatedDiscountPostingLines as this holds the PostingLine_IDs                   */
    /* The UI always sets the discount as positive amounts (also for corrections): same here   */
    /* ======================================================================================= */
    for each tOIAdj :               
        assign tOIAdj.tdAdjustmentAmountLC          = <M-165 RoundAmount
                                                         (input  tOIAdj.tdAdjustmentAmountLC (idUnroundedAmount), 
                                                          input  viCompanyLCid (iiCurrencyID), 
                                                          input  ? (icCurrencyCode)) in BOpenItemAdjustment> 
               tOIAdj.tdAdjustmentAmountTC          = <M-166 RoundAmount
                                                         (input  tOIAdj.tdAdjustmentAmountTC (idUnroundedAmount), 
                                                          input  ? (iiCurrencyID), 
                                                          input  tOIAdj.tcInvoiceCurrencyCode (icCurrencyCode)) in BOpenItemAdjustment>
               tOIAdj.tdInvoiceBalanceTC            = <M-168 RoundAmount
                                                         (input  tOIAdj.tdInvoiceBalanceTC (idUnroundedAmount), 
                                                          input  ? (iiCurrencyID), 
                                                          input  tOIAdj.tcInvoiceCurrencyCode (icCurrencyCode)) in BOpenItemAdjustment>
               tOIAdj.tdNewBalanceTC                = <M-169 RoundAmount
                                                         (input  tOIAdj.tdNewBalanceTC (idUnroundedAmount), 
                                                          input  ? (iiCurrencyID), 
                                                          input  tOIAdj.tcInvoiceCurrencyCode (icCurrencyCode)) in BOpenItemAdjustment>
               tOIAdj.tdAdjustmentDiscountAmountLC  = <M-208 RoundAmount
                                                         (input  tOIAdj.tdAdjustmentDiscountAmountLC (idUnroundedAmount), 
                                                          input  viCompanyLCId (iiCurrencyID), 
                                                          input  ? (icCurrencyCode)) in BOpenItemAdjustment>
               tOIAdj.tdAdjustmentDiscountAmountTC  = <M-209 RoundAmount
                                                         (input  tOIAdj.tdAdjustmentDiscountAmountTC (idUnroundedAmount), 
                                                          input  ? (iiCurrencyID), 
                                                          input  tOIAdj.tcInvoiceCurrencyCode (icCurrencyCode)) in BOpenItemAdjustment>
               tOIAdj.tcCreatedDiscountPostingLines = "":U.
    end. /* for each tOIAdj : */
    
    /* ============================================================ */
    /* ValidationChecks; we can only have a single NewOpenItem line */
    /* ============================================================ */
    find first tOIAdj where
               tOIAdj.tlIsNewOpenItem = true
               no-lock no-error.
    if available tOIAdj
    then do:
        /* Invoice Origin must match Journal Type */
        if tOIAdj.tcInvoiceOrigin        = {&INVOICEORIGIN-CREDITOR}         and
           vcMainPostingJournalTypeCode <> {&JOURNALTYPE-CREDITORADJUSTMENT} or
           tOIAdj.tcInvoiceOrigin        = {&INVOICEORIGIN-DEBTOR}           and
           vcMainPostingJournalTypeCode <> {&JOURNALTYPE-DEBTORADJUSTMENT} 
        then do:
            assign vcMsgOIAdj          = trim(subst(#T-190'Daybook type (&1) does not match the invoice origin of the new open item (&2).':255(2917)T-190#, vcMainPostingJournalTypeCode, tOIAdj.tcInvoiceOrigin))
                   viLocalReturnStatus = -1.
            <M-175 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-8136':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Leave VALIDATIONONEBLOCK.
        end.
        find first btOIAdj where
                   btOIAdj.tlIsNewOpenItem  = true and 
                   rowid(btOIAdj)          <> rowid(tOIAdj)
                   no-lock no-error.
        if available btOIAdj
        then do :
            assign viLocalReturnStatus = -1
                   vcMsgOIAdj          = trim(#T-207'You can only specify one new open item for open item adjustments.':255(2918)t-207#).
            <M-172 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-8133':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Leave VALIDATIONONEBLOCK.
        end. /* if available btOIAdj */
    end. /* if available tOIAdj */
    
    /* =============================================================================== */
    /* ValidationChecks on the Non-new OpenItem lines;                                 */
    /*   - InvoiceID should be filled for all lines (except the new one)               */
    /*   - The adjustment-rate should be correct regarding the original exchange-rate  */
    /* =============================================================================== */
    for each tOIAdj where 
             tOIAdj.tlIsNewOpenItem = false no-lock:
        if tOIAdj.tiInvoiceID = 0 or 
           tOIAdj.tiInvoiceID = ?
        then do :
            assign viLocalReturnStatus = -1
                   vcMsgOIAdj          = trim(#T-185'The invoice ID is not defined.':255(2919)T-185#) + " ":U + trim(#T-186'Details':255(2920)T-186#) + ";":U + chr(10) + 
                                         trim(substitute(#T-187'Invoice origin: &1.':255(2921)T-187#,tOIAdj.tcInvoiceOrigin)) + chr(10) + 
                                         trim(substitute(#T-188'Invoice type: &1.':255(2922)T-188#,tOIAdj.tcInvoiceType)) + chr(10) + 
                                         trim(substitute(#T-191'Invoice number: &1.':255(2923)T-191#,tOIAdj.tcInvoiceNumberReference)). 
            <M-173 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-8134':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Leave VALIDATIONONEBLOCK.
        end. /* if tOIAdj.tiInvoiceID = 0 or */
        if tOIAdj.tdAdjustmentExchangeRate <> tOIAdj.tdInvoiceExchangeRate
        then do :
            assign viLocalReturnStatus = -1
                   vcMsgOIAdj          = trim(substitute(#T-192'The exchange rate of the invoice (&1) must match the exchange rate of the adjustment (&2).':255(2925)t-192#,tOIAdj.tdInvoiceExchangeRate,tOIAdj.tdAdjustmentExchangeRate)) + " ":U + trim(#T-193'Details':255(2920)T-193#) + ";":U + chr(10) + 
                                         trim(substitute(#T-194'Invoice origin: &1.':255(2921)T-194#,tOIAdj.tcInvoiceOrigin)) + chr(10) + 
                                         trim(substitute(#T-195'Invoice type: &1.':255(2922)T-195#,tOIAdj.tcInvoiceType)) + chr(10) + 
                                         trim(substitute(#T-196'Invoice number: &1.':255(2923)T-196#,tOIAdj.tcInvoiceNumberReference)). 
            <M-178 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-8139':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Leave VALIDATIONONEBLOCK.
        end. /*  if tOIAdj.tcInvoiceBalanceCrDt <> tOIAdj.tcNewBalanceCrDt */                           
    end. /* for each tOIAdj where */
    
    /* ====================================================== */
    /* Stop in case error occured in the previous code-blocks */
    /* ====================================================== */
    if viLocalReturnStatus < 0
    then Leave VALIDATIONONEBLOCK.
    
END. /* VALIDATIONONEBLOCK */

/* =================== */
/* Exception handling  */
/* =================== */
assign oiReturnStatus = viLocalReturnStatus.