project QadFinancials > class BBill > method ValidateComponent

Description

Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.


Parameters


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bbill.p)

<ANCESTOR-CODE>

if vcActivityCode = "Create" or 
   vcActivityCode = "SetBillDate" or
   vcActivityCode = "Modify" or
   vcActivityCode = "Delete" 
then do:

    for each t_sBill where t_sBill.tc_Status = 'N':U or
                           t_sBill.tc_Status = 'C':U:
        /* Get DInvoice company id */
        find first tDInvoiceToBillForSave where 
            tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes and
            tDInvoiceToBillForSave.tiBill_ID = t_sBill.Bill_ID no-error.
        if available tDInvoiceToBillForSave then
            assign viDInvoiceCompanyId = tDInvoiceToBillForSave.tiCompany_ID.

        /* Ensure bill date is later than last confirm date */
        <Q-20 run GetConfirmedBillAfterBillDate (all) (Read) (NoCache)
           (input t_sBill.Company_ID, (CompanyId)
            input t_sBill.tcDebtorCode, (DebtorCode)
            input t_sBill.tcCurrencyCode, (CurrencyCode)
            input t_sBill.BillDate, (BillDate)
            input ?, (BillStatus)
            input viDInvoiceCompanyId, (DInvoiceCompanyId)
            input year(t_sBill.BillDate), (BillYear)
            output dataset tqGetConfirmedBillAfterBillDate) in BBill> 

        find first tqGetConfirmedBillAfterBillDate where 
                    tqGetConfirmedBillAfterBillDate.tiBillNumber <> t_sBill.BillNumber no-error.        
        if available tqGetConfirmedBillAfterBillDate then do:
            if tqGetConfirmedBillAfterBillDate.ttBillDate = t_sBill.BillDate then
            do:
                assign   viBillNumber = tqGetConfirmedBillAfterBillDate.tiBillNumber
                         vcCurCode = t_sBill.tcCurrencyCode
                         vcDebtorCode = t_sBill.tcDebtorCode
                         vtBillDate = t_sBill.BillDate.
                <M-18 run SetMessage
                   (input  trim(substitute(#T-21'There exists a bill (&1) for the same customer (&2) and currency (&3) with date (&4). You can only create bills with a later bill date.':255(956879274)T-21#, viBillNumber,vcDebtorCode,vcCurCode,string(vtBillDate))) (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  ? (icRowid), 
                    input  'qadfin-67355':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBill>
                assign oiReturnStatus = -1.
                return.
            end.
            else do:
                <M-58 run 
                   (input  trim(#T-51'The bill date must be later than the bill dates on other existing bills for the same currency, customer, and entity.':255(217243613)T-51#) (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  ? (icRowid), 
                    input  'qadfin-812238':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in >
                assign oiReturnStatus = -1.
                return.
            end.
        end.
        
        if t_sBill.BillDate = ? then do:
            <M-34 run SetMessage
               (input  trim(#T-78'The Bill Date field is mandatory.':255(869439267)T-78#) (icMessage), 
                input  '':U (icArguments), 
                input  't_sBill.BillDate':U (icFieldName), 
                input  string(t_sBill.BillDate) (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  ? (icRowid), 
                input  'qadfin-721972':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBill>
            assign oiReturnStatus = -1.
        end.

        if t_sBill.BillDueDate = ? then do:
            <M-8 run SetMessage
               (input  trim(#T-48'The Bill Due Date field is mandatory.':255(102390047)T-48#) (icMessage), 
                input  '':U (icArguments), 
                input  't_sBill.BillDueDate':U (icFieldName), 
                input  string(t_sBill.BillDueDate) (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  ? (icRowid), 
                input  'qadfin-275155':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBill>
            assign oiReturnStatus = -1.
            return.
        end.

        if t_sBill.BillDate > t_sBill.BillDueDate then do:
            <M-82 run SetMessage
               (input  trim(#T-80'The bill date should not be later than the bill due date.':255(901318760)T-80#) (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  string(t_sBill.BillDate) (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  ? (icRowid), 
                input  'qadfin-661347':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBill>
            assign oiReturnStatus = -1.
            return.
        end. 

        for each tDInvoiceToBillForSave where 
            tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes and
            tDInvoiceToBillForSave.tiBill_ID = t_sBill.Bill_ID no-lock:

            /* Bill date cannot be less than the invoice date. */
            if tDInvoiceToBillForSave.ttDInvoiceDate > t_sBill.BillDate then
            do:
                <M-64 run SetMessage
                   (input  trim(#T-79'The bill date cannot be earlier than any invoice date for that bill.':255(990032956)T-79#) (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  ? (icRowid), 
                    input  'qadfin-230645':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBill>                       
                assign oiReturnStatus = -1.  
                return.               
            end.

            /* Check if the selected invoice is already added to another bill. */
            <Q-26 run DInvoiceByIDForBill (all) (Read) (NoCache)
                (input ?, (CompanyId)
                 input tDInvoiceToBillForSave.tiDInvoice_ID, (DInvoice_ID)
                 input ?, (Bill_ID)
                 input {&MOVEMENTTYPE-INITIAL}, (MovementType)
                 output dataset tqDInvoiceByIDForBill) in BDInvoice>  

            find first tqDInvoiceByIDForBill no-lock no-error.
            if available tqDInvoiceByIDForBill      and 
               tqDInvoiceByIDForBill.tiBill_ID <> 0 and 
               tqDInvoiceByIDForBill.tiBill_ID <> ? and
               t_sBill.tc_Status = 'N':U then            
            do:
                if tqDInvoiceByIDForBill.tiBill_ID <> 0 and tqDInvoiceByIDForBill.tiBill_ID <> ? then            
                do:
                    <M-25 run SetMessage
                        (input  trim(#T-69'The selected invoice is already added to another bill.':255(908655238)T-69#) (icMessage), 
                         input  '':U (icArguments), 
                         input  '':U (icFieldName), 
                         input  '':U (icFieldValue), 
                         input  'E':U (icType), 
                         input  3 (iiSeverity), 
                         input  ? (icRowid), 
                         input  'qadfin-923490':U (icFcMsgNumber), 
                         input  ? (icFcExplanation), 
                         input  ? (icFcIdentification), 
                         input  ? (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BBill>
                    assign oiReturnStatus = -1.
                    return.
                end. /* if tqDInvoiceByIDForBill.tiBill_ID <> 0 and tqDInvoiceByIDForBill.tiBill_ID <> ? */
            end. /* if available tqDInvoiceByIDForBill */
        end. /* for each tDInvoiceToBillForSave where */
   
        <M-43 run IsHoliday
           (input  t_sBill.BillDueDate (itBillDate), 
            output vlBillDueDateIsHoliday (olIsHoliday), 
            output viFcReturnSuper (oiReturnStatus)) in BBill>
        if vlBillDueDateIsHoliday then
        do:
           <M-5 run SetMessage
              (input  trim(#T-46'The bill due date falls on a holiday.':255(758787094)T-46#) (icMessage), 
               input  '':U (icArguments), 
               input  't_sBill.BillDueDate':U (icFieldName), 
               input  string(t_sBill.BillDueDate) (icFieldValue), 
               input  'E':U (icType), 
               input  3 (iiSeverity), 
               input  ? (icRowid), 
               input  'qadfin-821801':U (icFcMsgNumber), 
               input  '':U (icFcExplanation), 
               input  '':U (icFcIdentification), 
               input  '':U (icFcContext), 
               output viFcReturnSuper (oiReturnStatus)) in BBill>
            assign oiReturnStatus = -1.
            return.
        end.
    end.
    
    for each t_sBill where t_sBill.tc_Status = 'C':U or
                           t_sBill.tc_Status = '':U:
    
        find first tDInvoiceToBillForSave where tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes no-error.      
        if not available tDInvoiceToBillForSave then
        do:
             <M-81 run SetMessage
                (input  trim(#T-92'A bill must contain one or more invoices.':255(352126198)T-92#) (icMessage), 
                 input  '':U (icArguments), 
                 input  't_sBill.BillDueDate':U (icFieldName), 
                 input  string(t_sBill.BillDueDate) (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  ? (icRowid), 
                 input  'qadfin-297946':U (icFcMsgNumber), 
                 input  '':U (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BBill>
            assign oiReturnStatus = -1.
            return.
        end.

        if t_sBill.Employee_ID = 0 then
        do:
            find first t_iBill where t_iBill.Bill_ID = t_sBill.Bill_ID no-error.
            if available t_iBill then
            do:
                if t_iBill.Employee_ID <> 0 then
                do:
                    <M-62 run SetMessage
                        (input  trim(#T-38'You cannot remove the current bill collector.':255(527674846)T-38#) (icMessage), 
                         input  ' ':U (icArguments), 
                         input  ' ':U (icFieldName), 
                         input  ' ':U (icFieldValue), 
                         input  'E':U (icType), 
                         input  3 (iiSeverity), 
                         input  ? (icRowid), 
                         input  'qadfin-185042':U (icFcMsgNumber), 
                         input  ' ':U (icFcExplanation), 
                         input  ' ':U (icFcIdentification), 
                         input  ' ':U (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BBill>
                    assign oiReturnStatus = -1.
                    return.
                end.
            end.
            else return.
        end.
    
        for each tDInvoiceToBillForSave where tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes:
            if tDInvoiceToBillForSave.tlBillScheduleIsUpdInvByBill then
            do:
                 if t_sBill.BillDueDate < tDInvoiceToBillForSave.ttDInvoiceDate then
                 do:
                    <M-31 run SetMessage
                       (input  trim(#T-89'The invoice due date is earlier than the invoice date.':255(318800801)T-89#) (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  ? (icRowid), 
                        input  'qadfin-63116':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BBill>
                    assign oiReturnStatus = -1.
                    return.
                end.
            end.
        end. /* for each tDInvoiceToBillForSave where tDInvoiceToBillForSave.tlDInvoiceIsSelected = yes */
    end. /* for each t_sBill where t_sBill.tc_Status = 'C':U */

    for each t_sBill where t_sBill.tc_Status = 'D':U:
        /* Get company code of invoice in bill */
        <Q-770 run GetDInvoiceByBillID (all) (Read) (NoCache)
           (input ?, (CompanyId)
            input t_sBill.Bill_ID, (Bill_Id)
            input ?, (IsOpen)
            output dataset tqGetDInvoiceByBillID) in BBill>
        find first tqGetDInvoiceByBillID no-lock.
        if available tqGetDInvoiceByBillID then
        do:
            <Q-3 run GetPreConfirmedBill (first) (Read) (NoCache)
               (input t_sBill.Company_ID, (CompanyId)
                input t_sBill.Currency_ID, (Currency_ID)
                input t_sBill.Debtor_ID, (Debtor_ID)
                input ?, (BillYear)
                input ?, (Bill_ID)
                input tqGetDInvoiceByBillID.tiCompany_ID, (DInvoiceCompany_ID)
                output dataset tqGetPreConfirmedBill) in BBill>

            if can-find (first tqGetPreConfirmedBill where tqGetPreConfirmedBill.tiBill_ID <> t_sBill.Bill_ID and
                         tqGetPreConfirmedBill.ttBillDate > t_sBill.BillDate no-lock) then
            do:
                <M-14 run SetMessage
                   (input  trim(#T-88'You can only delete the most recent created bill for the same customer, currency and entity.':255(960810497)T-88#) (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-734920':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBill>
                assign oiReturnStatus = -1.
                return.
            end.
        end. /* if available tqGetDInvoiceByBillID then */

        if t_sBill.BillStatus <> {&BILLSTATUS-INITIAL} then
        do:
            <M-77 run SetMessage
               (input  trim(#T-45'You can only delete bills with status 'Initial'.':255(113474124)T-45#) (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-868761':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBill>
            assign oiReturnStatus = -1.
            return.
        end.
    end. /* for each t_sBill where t_sBill.tc_Status = 'D':U */
end. /* if vcActivityCode = "Create" */