project QadFinancials > class BCInvoice > method ReverseCInvoiceValidateStatus

Description

This method validates, whether supplier invoice can be reversed or not


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.DefaultValuesReverse
method BCInvoice.ReverseCInvoiceValidate


program code (program3/bcinvoice.p)

assign oiReturnStatus = -98.

/* =================================================================================================== */
/* Validate input parameters                                                                           */
/* =================================================================================================== */
if not available tCInvoice
then do:
    assign vcMessage = #T-1'The supplier invoice to be validated cannot be found.':255(69095)T-1#.
    <M-2 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-7869':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* Supplier invoice cannot be in the initial status                                                    */
/* =================================================================================================== */
if tCInvoice.CInvoiceIsInitialStatus = true
then do:
    assign vcMessage = #T-3' You cannot reverse an initial supplier invoice (&1/&2/&3).':255(69097)T-3#
           vcMessage = subst(vcMessage, tCInvoice.CInvoicePostingYear, tCInvoice.tcJournalCode, tCInvoice.CInvoiceVoucher).

    <M-4 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-7870':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* Supplier invoice cannot be included in the payment selection even in initial status                 */
/* =================================================================================================== */
if tCInvoice.CInvoiceIsSelected = true
then do:
    assign vcMessage = #T-8'You cannot reverse supplier invoice (&1/&2/&3) because this invoice is included in a payment selection in the initial status.':255(69104)T-8#
           vcMessage = subst(vcMessage, tCInvoice.CInvoicePostingYear, tCInvoice.tcJournalCode, tCInvoice.CInvoiceVoucher).

    <M-7 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-7878':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

    assign oiReturnStatus = -1.
    return.
end.


/* =================================================================================================== */
/* Supplier invoice cannot be included in the payment or paid                                         */
/* =================================================================================================== */
if can-find(first tCInvoiceMovement where
                  tCInvoiceMovement.tc_ParentRowid = tCInvoice.tc_Rowid and
                  tCInvoiceMovement.CInvoiceMovementType = {&MOVEMENTTYPE-MOVEMENT})
then do:
        
      
    <Q-10 run CInvoiceMovementByType (all) (Read) (NoCache)
       (input tCInvoice.Company_ID, (CompanyId)
        input tCInvoice.CInvoice_ID, (CInvoiceId)
        input {&MOVEMENTTYPE-MOVEMENT}, (CInvoiceMovementType)
        output dataset tqCInvoiceMovementByType) in BCInvoice >       
       
    assign viPostingLineDebitTC = 0
           viPostingLineCreditTC = 0.
              
    for each tqCInvoiceMovementByType :
            
        assign viPostingLineDebitTC  = viPostingLineDebitTC + tqCInvoiceMovementByType.tdPostingLineDebitTC      
               viPostingLineCreditTC = viPostingLineCreditTC + tqCInvoiceMovementByType.tdPostingLineCreditTC.
       
    end.            
       
               
    if (viPostingLineDebitTC - viPostingLineCreditTC) <> 0               
    then do:                  
       assign vcMessage = #T-6'You cannot reverse supplier invoice (&1/&2/&3) if the invoice is included in payments or if the invoice has been paid.':255(69732)T-6#
              vcMessage = subst(vcMessage, tCInvoice.CInvoicePostingYear, tCInvoice.tcJournalCode, tCInvoice.CInvoiceVoucher).

       <M-5 run SetMessage
          (input  vcMessage (icMessage), 
           input  '':U (icArguments), 
           input  '':U (icFieldName), 
           input  '':U (icFieldValue), 
           input  'E':U (icType), 
           input  3 (iiSeverity), 
           input  tCInvoice.tc_Rowid (icRowid), 
           input  'QadFin-7871':U (icFcMsgNumber), 
           input  '':U (icFcExplanation), 
           input  '':U (icFcIdentification), 
           input  '':U (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

       assign oiReturnStatus = -1.
       return.
        
    end.  
end.

/* The invoices which do not have cinvoiceposting record, can not be reversed */
/* normally they are opening balance invoice, prepayment or adjustment */
find first tCInvoicePosting where
           tCInvoicePosting.tc_ParentRowid = tCInvoice.tc_Rowid no-error.
           
if not available tCInvoicePosting
then do :
    assign oiReturnStatus = -1
           vcMessage = trim(#T-12'Invoices created as prepayment, open item adjustment or supplier opening balance cannot be reversed with this program.':255(413929476)T-12#).
    <M-11 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-9658':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    return.    
end.

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.