project QadFinancials > class BOpenItemAdjustment > method OIAdjNewOpenItem

Description

OIAdjNewOpenItem; Create a single record in TOIAdj based onthe values of the input parameters


Parameters


icInvoiceOrigininputcharacterInvoiceOrigin
icCredDebEmplCodeinputcharacterCredDebEmplCode
itInvoiceDateinputdateInvoiceDate
itInvoiceNormalDueDateinputdateInvoiceNormalDueDate
itInvoiceDiscountDueDateinputdateInvoiceDiscountDueDate
icInvoiceCurrencyCodeinputcharacterInvocieCurrencyCode
idAdjustmentAmountTCinputdecimalAdjustmentAmountTC
idAdjustmentAmountLCinputdecimalAdjustmentAmountLC
idAdjustmentExchangeRateinputdecimalAdjustmentExcahngeRate
idAdjustmentExchangeRateScaleinputdecimal
icNewBalanceCrDtinputcharacterNewBalanceCrDt
icInvoiceDescriptioninputcharacterInvoice Description
icInvoiceDivisionCodeinputcharacterSub-Account Code
icInvoiceProjectCodeinputcharacterInvoice Project Code
icInvoiceCostCentreCodeinputcharacterInvoice Cost Centre Code
icInvoiceTypeinputcharacterInvoice Type
icReasonCodeinputcharacterReason Code
tOIAdjoutputtemp-tabletemp-table with a single record in it; this is the new open item
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bopenitemadjustment.p)

/* ========================================================================== */
    /* Validations and converting unknown values into displayable values          */
    /* ========================================================================== */
    assign vcMsgOIAdj = "":U.
    if icCredDebEmplCode = ? then assign icCredDebEmplCode = "":U.
    if icInvoiceCurrencyCode = ? then assign icInvoiceCurrencyCode = "":U.
    if idAdjustmentAmountTC = ? then assign idAdjustmentAmountTC = 0.
    if idAdjustmentAmountLC = ? then assign idAdjustmentAmountLC = 0.
    if idAdjustmentExchangeRate = ? then assign idAdjustmentExchangeRate = 0.
    if icInvoiceCurrencyCode = ? then assign icInvoiceCurrencyCode = "":U.
    if icNewBalanceCrDt = ? then assign icNewBalanceCrDt = "":U.
    if icReasonCode = ? then assign icReasonCode = "":U.
    
    if icInvoiceType = ? then assign icInvoiceType = "":U.
    if icInvoiceType <> {&INVOICETYPE-ADJUSTMENT} and 
       icInvoiceType <> {&INVOICETYPE-PREPAYMENT} 
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(substitute(#T-6'The invoice type of the new open item must be in this list: '&1.':255(2884)t-6#,{&INVOICETYPE-ADJUSTMENT-TR} + ", ":U + {&INVOICETYPE-PREPAYMENT-TR})).
    if icInvoiceOrigin = ? then assign icInvoiceOrigin = "":U.
    if icInvoiceOrigin <> {&INVOICEORIGIN-CREDITOR} and 
       icInvoiceOrigin <> {&INVOICEORIGIN-DEBTOR} 
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(substitute(#T-7'The origin of the new open item must be in this list: &1.':255(2885)t-7#,{&INVOICEORIGIN-CREDITOR-TR} + ", ":U + {&INVOICEORIGIN-DEBTOR-TR} )).
    else do :
        case icInvoiceOrigin :
        when {&INVOICEORIGIN-CREDITOR}
        then do :
            <Q-82 run CreditorByCode (all) (Read) (NoCache)
               (input viMainPostingCompanyID, (CompanyId)
                input icCredDebEmplCode, (CreditorCode)
                output dataset tqCreditorByCode) in BCreditor >
            find first tqCreditorByCode where 
                       tqCreditorByCode.tcCreditorCode = icCredDebEmplCode
                       no-lock NO-error.
            if not available tqCreditorByCode
            then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(substitute(#T-8'Invalid supplier: &1.':255(2886)T-8#,icCredDebEmplCode)).
            else assign vcBusinessRealtionCode      = tqCreditorByCode.tcBusinessRelationCode
                        vlBusinessRelationIsCompens = tqCreditorByCode.tlBusinessRelationIsCompens.
        end.
        when {&INVOICEORIGIN-DEBTOR}
        then do :
           <Q-24 run DebtorByCode (all) (Read) (NoCache)
              (input viMainPostingCompanyID, (CompanyId)
               input icCredDebEmplCode, (DebtorCode)
               output dataset tqDebtorByCode) in BDebtor >
            find first tqDebtorByCode where 
                       tqDebtorByCode.tcDebtorCode = icCredDebEmplCode
                       no-lock NO-error.
            if not available tqDebtorByCode
            then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(substitute(#T-9'The specifed customer: &1 is invalid.':255(2887)t-9#,icCredDebEmplCode)).
            else assign vcBusinessRealtionCode      = tqDebtorByCode.tcBusinessRelationCode
                        vlBusinessRelationIsCompens = tqDebtorByCode.tlBusinessRelationIsCompens.
        end.
        end case.
    end. /* not if icInvoiceOrigin <> {&INVOICEORIGIN-CREDITOR} and */
    if idAdjustmentAmountTC = 0 
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(#T-11'You must enter the adjustment amount in the transaction currency.':255(2889)t-11#).
    if idAdjustmentAmountLC = 0 
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(#T-12'You must enter the adjustment amount in the base currency.':255(2890)t-12#).
    if idAdjustmentExchangeRate = ? or 
       idAdjustmentExchangeRate = 0
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(#T-13'You must enter the adjustment exchange rate.':255(2891)T-13#).
    else do :
        if icInvoiceCurrencyCode = vcCompanyLC and 
           idAdjustmentExchangeRate <> 1
        then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(substitute(#T-14'The adjustment exchange rate must be 1 because the transaction currency and base currency are the same (&1).':255(2892)t-14#,vcCompanyLC)).
    end. /* if idAdjustmentExchangeRate <> ? and  <> 0 */
    if itInvoiceDate = ?
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) +  trim(#T-15'You must enter the invoice date.':255(2893)T-15#).
    if itInvoiceNormalDueDate = ?
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) +  trim(#T-16'You must enter the due date.':255(2894)T-16#).
    if icNewBalanceCrDt <> {&CREDITDEBITABBREVIATION-CREDIT} and 
       icNewBalanceCrDt <> {&CREDITDEBITABBREVIATION-DEBIT}
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(substitute(#T-17'There must be a debit/credit indication in this list: &1.':255(2895)T-17#,{&CREDITDEBITABBREVIATION-CREDIT-TR} + ", ":U + {&CREDITDEBITABBREVIATION-DEBIT-TR} )).
    if icInvoiceCurrencyCode = "":U
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(#T-18'You must enter the invoice currency.':255(2896)T-18#).
    else do :
        <Q-4 assign vlFcQueryRecordsAvailable = CurrencyPrim (NoCache)
          (input icInvoiceCurrencyCode, (CurrencyCode)
           input ?, (Currency_ID)) in BCurrency >
        if vlFcQueryRecordsAvailable <> true
        then vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(substitute(#T-19'The specified currency (&1) is invalid.':255(2897)t-19#,icInvoiceCurrencyCode)).
    end. /* if icInvoiceCurrencyCode = "":U */
    
    if icReasonCode = ? or icReasonCode = "":U 
    then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(#T-52'Invoice Status Code cannot be blank':255(481264365)T-52#).
    
    if icReasonCode <> "":U
    then do:
        <Q-91 run ReasonByIdCode (all) (Read) (NoCache)
           (input ?, (ReasonId)
            input icReasonCode, (ReasonCode)
            output dataset tqReasonByIdCode) in BReason >
       find first tqReasonByIdCode where 
                  tqReasonByIdCode.tcReasonCode = icReasonCode 
       no-error.
       if available tqReasonByIdCode 
       then do:
           if tqReasonByIdCode.tlReasonIsInitialStatus = no                      and
              tqReasonByIdCode.tcReasonAllocationStatus = {&ALLOCSTATUS-NOALLOC} and
              tqReasonByIdCode.tlReasonIsLogisticMatching = no
          then .
          else do:
              assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(#T-41'You must enter the Invoice Status Code with Allocation Status = No Allocation, Initial Status = No and Receiver Matching = No.':255(105994601)T-41#).
          end. /* else do: */
       end. /* if available tqReasonByIdCode */
       else do:
           assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + trim(#T-64'The invoice status code specified is not defined in the system.':150(1242)T-64#).
       end.
    end. /* if icReasonCode <> "":U */
    
    if vcMsgOIAdj <> "":U
    then do :
        assign oiReturnStatus = -1
               vcMsgOIAdj     = trim(#T-20'Invalid or incomplete data received for the creation of a new open item. See further on for more details.':255(2898)T-20#) + vcMsgOIAdj.
        <M-5 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-769':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
    end. /* if vcMsgOIAdj <> "":U */
    
    <Q-70 run CompanyPropertyByIDAllInfo (all) (Read) (NoCache)
       (input viMainPostingCompanyID, (CompanyId)
        output dataset tqCompanyPropertyByIDAllInfo) in BCompanyProperty >
    find first tqCompanyPropertyByIDAllInfo where
               tqCompanyPropertyByIDAllInfo.tiCompany_ID = viMainPostingCompanyID
               no-lock no-error.

    <Q-33 run BusinessRelationByCode (all) (Read) (NoCache)
       (input vcBusinessRealtionCode, (BusinessRelationCode)
        input viDomainID, (DomainID)
        output dataset tqBusinessRelationByCode) in BBusinessRelation>
    find first tqBusinessRelationByCode where 
        tqBusinessRelationByCode.tcBusinessRelationCode = vcBusinessRealtionCode 
    no-lock no-error.
    if available tqBusinessRelationByCode and 
        tqBusinessRelationByCode.tiCorporateGroup_ID <> 0 and 
        tqBusinessRelationByCode.tiCorporateGroup_ID <> ?
    then do:
        <Q-81 run CorporateGroupPrim (all) (Read) (NoCache)
           (input tqBusinessRelationByCode.tiCorporateGroup_ID, (CorporateGroup_ID)
            input ?, (CorporateGroupCode)
            output dataset tqCorporateGroupPrim) in BCorporateGroup>
        find first tqCorporateGroupPrim no-lock no-error.
    end.

    /* ======================================= */
    /* Create the new output temp-table record */
    /* ======================================= */
    empty temp-table tOIAdj.
    create tOIAdj.
    assign tOIAdj.tiCompanyID                   = viMainPostingCompanyID
           tOIAdj.tiInvoiceID                   = ?
           tOIAdj.tcBusinessRelationCode        = vcBusinessRealtionCode
           tOIAdj.tcCredDebEmplCode             = icCredDebEmplCode
           tOIAdj.tcInvoiceCurrencyCode         = icInvoiceCurrencyCode
           tOIAdj.tcInvoiceType                 = icInvoiceType
           tOIAdj.tcInvoiceNumberReference      = trim(string(viMainPostingYear)) + "/":U + trim(vcMainPostingJournalCode) + "/":U + string(viMainPostingVoucher,"999999999":U)
           tOIAdj.tcInvoiceOrigin               = icInvoiceOrigin
           tOIAdj.ttInvoiceNormalDueDate        = itInvoiceNormalDueDate
           tOIAdj.ttInvoiceDiscountDueDate      = itInvoiceDiscountDueDate
           tOIAdj.ttInvoiceDate                 = itInvoiceDate
           tOIAdj.tdInvoiceExchangeRate         = idAdjustmentExchangeRate
           tOIAdj.tdInvoiceExchangeRateScale    = idAdjustmentExchangeRateScale
           tOIAdj.tcInvoiceBalanceCrDt          = icNewBalanceCrDt
           tOIAdj.tdInvoiceBalanceTC            = 0
           tOIAdj.tlIsNewOpenItem               = true
           tOIAdj.tdAdjustmentAmountLC          = idAdjustmentAmountLC
           tOIAdj.tdAdjustmentAmountTC          = idAdjustmentAmountTC
           tOIAdj.tcAdjustmentCrDt              = icNewBalanceCrDt
           tOIAdj.tdAdjustmentExchangeRate      = idAdjustmentExchangeRate
           tOIAdj.tdAdjustmentExchangeRateScale = idAdjustmentExchangeRateScale
           tOIAdj.tcNewBalanceCrDt              = icNewBalanceCrDt
           tOIAdj.tdNewBalanceTC                = idAdjustmentAmountTC
           tOIAdj.tcInvoiceDescription          = icInvoiceDescription
           tOIAdj.tcInvoiceDivisonCode          = icInvoiceDivisionCode
           tOIAdj.tcInvoiceProjectCode          = icInvoiceProjectCode
           tOIAdj.tcInvoiceCostCentreCode       = icInvoiceCostCentreCode
           tOIAdj.tcReasonCode                  = icReasonCode
           tOIAdj.tdInvoiceBalanceLC            = 0
           tOIAdj.tcCompanyCode                 = vcCompanyCode
           tOIAdj.tcCInvoiceReference           = (if icInvoiceOrigin = {&INVOICEORIGIN-CREDITOR} then tOIAdj.tcInvoiceNumberReference else "":U)
           tOIAdj.tiInvMovementPostingLineID    = 0
           tOIAdj.tlBusinessRelationIsCompens   = vlBusinessRelationIsCompens
           tOIAdj.tlCompIsCompens               = if available tqCompanyPropertyByIDAllInfo then tqCompanyPropertyByIDAllInfo.tlCompanyPropertyIsCompens else false
           tOIAdj.tcCompOINetRest               = if available tqCompanyPropertyByIDAllInfo then tqCompanyPropertyByIDAllInfo.tcCompanyPropertyOINetRestr else "":U
           tOIAdj.tcCorporateGroupCode          = if available tqCorporateGroupPrim then tqCorporateGroupPrim.tcCorporateGroupCode else "":U.

    if icInvoiceOrigin = {&INVOICEORIGIN-CREDITOR}
    then do :
        <Q-21 run CreditorForProfiles (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input tOIAdj.tcCredDebEmplCode, (CreditorCode)
            input ?, (CreditorID)
            output dataset tqCreditorForProfiles) in BCreditor >
        find first tqCreditorForProfiles where 
                   tqCreditorForProfiles.tcCreditorCode = tOIAdj.tcCredDebEmplCode
                   no-lock no-error.
        assign tOIAdj.tcInvoiceControlGLCode = if available tqCreditorForProfiles = false 
                                               then "":U
                                               else if tOIAdj.tcInvoiceType = {&INVOICETYPE-PREPAYMENT}
                                                    then tqCreditorForProfiles.tcPrePaymentControlGLCode
                                                    else if tOIAdj.tcInvoiceType = {&INVOICETYPE-ADJUSTMENT}
                                                         then tqCreditorForProfiles.tcCreditNoteControlGLCode
                                                         else tqCreditorForProfiles.tcInvoiceControlGLCode. 
    end. /* if icInvoiceOrigin = {&INVOICEORIGIN-CREDITOR} */ 
    else do :
        <Q-23 run DebtorForProfiles (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input tOIAdj.tcCredDebEmplCode, (DebtorCode)
            input ?, (DebtorID)
            output dataset tqDebtorForProfiles) in BDebtor >
        find first tqDebtorForProfiles where 
                   tqDebtorForProfiles.tcDebtorCode = tOIAdj.tcCredDebEmplCode
                   no-lock no-error.
        assign tOIAdj.tcInvoiceControlGLCode = if available tqDebtorForProfiles = false 
                                               then "":U
                                               else if tOIAdj.tcInvoiceType = {&INVOICETYPE-PREPAYMENT}
                                                    then tqDebtorForProfiles.tcPrepaymentControlGLCode
                                                    else if tOIAdj.tcInvoiceType = {&INVOICETYPE-ADJUSTMENT}
                                                         then tqDebtorForProfiles.tcCreditNoteControlGLCode
                                                         else tqDebtorForProfiles.tcInvoiceControlGLCode.
    end. /* not if icInvoiceOrigin = {&INVOICEORIGIN-CREDITOR} */