project QadFinancials > class BDInvoice > method ValidateComponentAllCheckAmountDateDebt

Description

This method is a submethod of ValidateComponentAll.

Validates if you can find an invoice or credit note with the same amount, same invoice date, same debtor , if so, then give error


Parameters


icDInvoiceTypeinputcharacterInvoice Type
idDInvoiceOriginalTCinputdecimalInvoice Amount in TC
itDInvoiceDateinputdateInvoice Date
iiDebtorIdinputintegerDebtor ID
icDebtorCodeinputcharacterCustomer Code
iiCurrencyIdinputintegercurrency id
icCurrencyCodeinputcharacterCurrrency Code
icRowIdinputcharacterRow ID
iiDInvoiceIdinputintegerDInvoice ID
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.DefaultValuesValidate
method BDInvoice.ValidateComponentAll


program code (program5/bdinvoice.p)

/* replace unknown values */
    if icDInvoiceType = ? then assign icDInvoiceType = "":U.
    if idDInvoiceOriginalTC = ? then assign idDInvoiceOriginalTC = 0.
    if iiDebtorId = ? then assign iiDebtorId = 0.
    if icDebtorCode = ? then assign icDebtorCode = "":U.
    if iiCurrencyId = ? then assign iiCurrencyId = 0.
    if icCurrencyCode = ? then assign icCurrencyCode = "":U.
    if icRowId = ? then assign icRowId = "":U.
    if iiDInvoiceId = ? then assign iiDInvoiceId = 0.
    
    /* if an invoice with the same amount, same invoice date, same debtor already exists, nothing happens */
    /* if a credit note with the same amount, same invoice date, same creditor already exists, give warning */
    assign vlError = false.
    if icDInvoiceType =  {&INVOICETYPE-CREDITNOTE} or icDInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
    then do:
        if icRowId = "":U
        then do:
            find first bDInvoice where
                       bDInvoice.DInvoiceOriginalCreditTC = idDInvoiceOriginalTC and
                       bDInvoice.DInvoiceDate             = itDInvoiceDate and
                      (bDInvoice.Debtor_ID                = iiDebtorId or
                       bDInvoice.tcDebtorCode             = icDebtorCode) and
                      (bDInvoice.DInvoiceCurrency_ID      = iiCurrencyId or
                       bDInvoice.tcCurrencyCode           = icCurrencyCode) and
                       bDInvoice.DInvoiceType             = icDInvoiceType and
                       bDInvoice.DInvoice_ID             <> iiDInvoiceId and
                       bDInvoice.tc_status               <> "D":U
                       no-lock no-error.
        end.
        else do:
            find first bDInvoice where
                       bDInvoice.DInvoiceOriginalCreditTC = idDInvoiceOriginalTC and
                       bDInvoice.DInvoiceDate             = itDInvoiceDate and
                      (bDInvoice.Debtor_ID                = iiDebtorId or
                       bDInvoice.tcDebtorCode             = icDebtorCode) and
                      (bDInvoice.DInvoiceCurrency_ID      = iiCurrencyId or
                       bDInvoice.tcCurrencyCode           = icCurrencyCode) and
                       bDInvoice.DInvoiceType             = icDInvoiceType and
                       bDInvoice.DInvoice_ID             <> iiDInvoiceId and
                       bDInvoice.tc_status               <> "D":U and
                       bDInvoice.tc_Rowid                <> icRowId 
                       no-lock no-error.
        end.
        if available bDInvoice
        then assign vlError = true.
        else do:
            <Q-3 assign vlFcQueryRecordsAvailable = DInvoiceByOriginalDateDebtType (NoCache)
               (input viCompanyId, (CompanyId)
                input itDInvoiceDate, (DInvoiceDate)
                input icDInvoiceType, (DInvoiceType)
                input iiDebtorId, (DebtorId)
                input iiCurrencyId, (CurrencyId)
                input idDInvoiceOriginalTC, (DInvoiceOriginalCreditTC)
                input ?, (DInvoiceOriginalDebitTC)
                input iiDInvoiceId, (DInvoiceId)
                input icRowId, (SkipRowId)
                input if iidebtorId = 0 then icdebtorCode else '':U, (DebtorCode)
                input if iicurrencyId = 0 then iccurrencyCode else '':U, (CurrencyCode)) in BDInvoice >
            if vlFcQueryRecordsAvailable <> false
            then assign vlError = true.
        end.
    end.

    if vlError 
    then do:
        assign vcMessage      = trim(#T-5'The invoice amount already exists on another credit note with the same invoice date and the same customer.':150(1759)T-5#).
        if oiReturnStatus = 0
        then assign oiReturnStatus = +1 /* WARNING */.
        <M-4 run SetMessage (input  vcMessage (icMessage), 
                     input  '':U (icArguments), 
                     input  'tDInvoice.DInvoiceOriginalCreditTC':U (icFieldName), 
                     input  idDInvoiceOriginalTC (icFieldValue), 
                     input  'W':U (icType), 
                     input  3 (iiSeverity), 
                     input  '':U (icRowid), 
                     input  'QADFIN-4466':U (icFcMsgNumber), 
                     input  '' (icFcExplanation), 
                     input  '' (icFcIdentification), 
                     input  '' (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    end.