project QadFinancials > class BOpenItemAdjustment > method GetBusinessRelationForCredDeb

Description

GetBusinessRelationForCredDeb: method that returns the bus-rel for a creditor or debtor


Parameters


iiCompanyIDinputintegerID of the company; if unknown value or zero is passed then the current company will be used
icInvoiceOrigininputcharacterInidcates if it concerns a debtor or creditor. Use preprocessors for this paramater:
{&INVOICEORIGIN-CREDITOR} {&INVOICEORIGIN-DEBTOR}
icCreditorCodeDebtorCodeinputcharacterCode of the debtor or creditor
ocBusinessRelationCodeoutputcharacterBusinessRelationCode: BusinessRelation of the debtor or creditor
ocDefaultReasonCodeoutputcharacterDefault reson-code for the debtor or creditor
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program5/bopenitemadjustment.p)

/* ================== */
    /* Exception handling */
    /* ================== */
    assign oiReturnStatus      = -98
           viLocalReturnStatus = 0.
    
    /* ==================== */
    /* Parameter validation */
    /* ==================== */
    if iiCompanyID = ? or
       iiCompanyID = 0
    then assign iiCompanyID = viCompanyId.
    if icInvoiceOrigin <> {&INVOICEORIGIN-CREDITOR} and 
       icInvoiceOrigin <> {&INVOICEORIGIN-DEBTOR}
    then do :
        assign vcMsgOIAdj     = trim(substitute(#T-1'Internal error. The parameter value provided for method &1 is invalid.':255(69469)T-1#,"GetBusinessRelationForCredDeb":U)) + chr(10) + 
                                trim(substitute(#T-2'Valid values for parameter &1 are &2 and &3':255(733716348)T-2#,"InvoiceOrigin":U, {&INVOICEORIGIN-CREDITOR}, {&INVOICEORIGIN-DEBTOR}))
               oiReturnStatus = -3.
        <M-3 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-8107':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        Return.
    end. /* if icInvoiceOrigin <> {&INVOICEORIGIN-CREDITOR} and */
    if icCreditorCodeDebtorCode = "":U or 
       icCreditorCodeDebtorCode = ?
    then do :
        assign vcMsgOIAdj     = trim(substitute(#T-5'Internal error: mandatory parameter (&1) is missing':255(69471)T-5#,"CreditorCodeDebtorCode":U))
               oiReturnStatus = -3.
        <M-4 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-8108':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        Return.
    end. /* if icCreditorCodeDebtorCode = "":U or */
    
    /* =========================== */
    /* Query the business-relation */
    /* =========================== */
    if icInvoiceOrigin = {&INVOICEORIGIN-CREDITOR}
    then do :
        <Q-12 run CreditorForReasonBusRel (all) (Read) (NoCache)
           (input iiCompanyID, (CompanyId)
            input icCreditorCodeDebtorCode, (CreditorCode)
            input ?, (CreditorID)
            output dataset tqCreditorForReasonBusRel) in BCreditor >
        Find first tqCreditorForReasonBusRel no-lock no-error.
        if not available tqCreditorForReasonBusRel
        then do :
            assign vcMsgOIAdj     = trim(substitute(#T-8'The system cannot find the business relation of supplier &1.':255(69472)T-8#,icCreditorCodeDebtorCode))
                   oiReturnStatus = -3.
            <M-7 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-8109':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Return.
        end. /* if not available tqCreditorForReasonBusRel */
        assign ocBusinessRelationCode = tqCreditorForReasonBusRel.tcBusinessRelationCode
               ocDefaultReasonCode    = tqCreditorForReasonBusRel.tcReasonCode.
    end. /* if icInvoiceOrigin = {&INVOICEORIGIN-CREDITOR} */
    else do :
        <Q-13 run DebtorForReasonBusRel (all) (Read) (NoCache)
           (input iiCompanyID, (CompanyId)
            input icCreditorCodeDebtorCode, (DebtorCode)
            input ?, (DebtorID)
            output dataset tqDebtorForReasonBusRel) in BDebtor >
        Find first tqDebtorForReasonBusRel no-lock no-error.
        if not available tqDebtorForReasonBusRel
        then do :
            assign vcMsgOIAdj     = trim(substitute(#T-10'The system cannot find the business relation of customer &1.':255(69473)T-10#,icCreditorCodeDebtorCode))
                   oiReturnStatus = -3.
            <M-9 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-8110':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Return.
        end. /* if not available tqDebtorForReasonBusRel */
        assign ocBusinessRelationCode = tqDebtorForReasonBusRel.tcBusinessRelationCode
               ocDefaultReasonCode    = tqDebtorForReasonBusRel.tcReasonCode.
    end. /* Not if icInvoiceOrigin = {&INVOICEORIGIN-CREDITOR} */
    
    /*If Reason Code is not "No Allocation" then it should not be default*/
    if ocDefaultReasonCode <> "":U and
       ocDefaultReasonCode <> ? 
    then do:
   
        <Q-32 run ReasonByIdCode (all) (Read) (NoCache)
           (input ?, (ReasonId)
            input ocDefaultReasonCode, (ReasonCode)
            output dataset tqReasonByIdCode) in BReason >    

        find first tqReasonByIdCode where tqReasonByIdCode.tcReasonCode =  ocDefaultReasonCode no-error.
        if available tqReasonByIdCode then do:
            if tqReasonByIdCode.tcReasonAllocationStatus <> {&ALLOCSTATUS-NOALLOC}
                then ocDefaultReasonCode = '':U.
        end. /* if available tqReasonByIdCode then do*/  
    end.  /* if ocDefaultReasonCode <> "":U*/ 
       
    /* ================== */
    /* Exception handling */
    /* ================== */
    assign oiReturnStatus      = viLocalReturnStatus.