project QadFinancials > class BCInvoice > method PostSaveValidate

Description

Implement new validations to really ensure, there are really created only those recors which are really needed.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program1/bcinvoice.p)

/* ====================================================================================== *
 * Method       : PostSaveValidate                                                        *
 * Description  : Implement new validations to ensure, there are really created those     *
 *                records which are expected.                                             *
 * -------------------------------------------------------------------------------------- *
 * Parameters   :                                                                         *
 * ====================================================================================== */
assign oiReturnStatus = -98
       viLocalReturn  = 0.

MAIN_BLOCK:
do on error undo, return:
    

    /* For complete validation, we need to know details from posting component */
    



    for each tCInvoice where
             tCInvoice.tc_Status <> "D":U:

        /* Find original record */
        if tCInvoice.tc_Status <> "N":U
        then do:
            find t_iCInvoice where
                 t_iCInvoice.tc_Rowid = tCInvoice.tc_Rowid
                 no-error.
            if not available t_iCInvoice
            then do:
                assign vcMessage     = #T-76'Could not find initial values for supplier invoice &1/&2/&3.':255(156783171)T-76#
                       vcMessage     = substitute(vcMessage, tCInvoice.CInvoicePostingYear, tCInvoice.tcJournalCode, tCInvoice.CInvoiceVoucher)
                       viLocalReturn = -1.
                <M-16 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'S':U (icType), 
                    input  2 (iiSeverity), 
                    input  tCInvoice.tc_Rowid (icRowid), 
                    input  'QadFin-286440':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                next.
            end.
        end.

        /* Invoice created in non initial status can have only one movement of type "Initial" */
        if not tCInvoice.CInvoiceIsInitialStatus                                 and
           not can-find(tCInvoiceMovement where
                        tCInvoiceMovement.tc_ParentRowid       = tCInvoice.tc_Rowid      and
                        tCInvoiceMovement.CInvoiceMovementType = {&MOVEMENTTYPE-INITIAL} and
                        tCInvoiceMovement.tc_Status           <> "D":U)
        then do:
            assign vcMessage     = #T-53'There is missing Initial movement record for Supplier invoice &1/&2/&3.':255(285260843)T-53#
                   vcMessage     = substitute(vcMessage, tCInvoice.CInvoicePostingYear, tCInvoice.tcJournalCode, tCInvoice.CInvoiceVoucher)
                   viLocalReturn = -1.
            <M-86 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'S':U (icType), 
                input  2 (iiSeverity), 
                input  tCInvoice.tc_Rowid (icRowid), 
                input  'QadFin-265977':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        end.

        /* ===================================================================================== *
         * CInvoice movement validations                                                         *
         * ===================================================================================== */
        for each tCInvoiceMovement where
                 tCInvoiceMovement.tc_ParentRowid = tCInvoice.tc_Rowid and
                 tCInvoiceMovement.tc_Status     <> "D":U:

            /* Every movement have to have posting link to it */
            if tCInvoiceMovement.PostingLine_ID = 0 or
               tCInvoiceMovement.PostingLine_ID = ?
            then do:
                assign vcMessage     = #T-17'There is missing Posting Line linked to Movement.':255(230703880)T-17#
                       vcMessage     = substitute(vcMessage, tCInvoice.CInvoicePostingYear, tCInvoice.tcJournalCode, tCInvoice.CInvoiceVoucher)
                       viLocalReturn = -1.
                <M-87 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'S':U (icType), 
                    input  2 (iiSeverity), 
                    input  tCInvoice.tc_Rowid (icRowid), 
                    input  'QadFin-885892':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
            end.

        end. /* for each tCInvoiceMovement where */
    end. /* for each tCInvoice: */

    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper <  0 then leave MAIN_BLOCK.

end. /* MAIN_BLOCK */

assign oiReturnStatus = viLocalReturn.