project QadFinancials > class BCInvoice > method ReverseCInvoiceValidate


Parameters


biReversedCInvoiceIdinput-outputinteger
bcReverseInvoiceTypeinput-outputcharacter
biReversePostingYearinput-outputinteger
biReversePostingPeriodinput-outputinteger
btReversePostingDateinput-outputdate
bcReverseInvoiceJournalinput-outputcharacter
biReverseInvoiceVoucherinput-outputinteger
bcAdjustmentJournalinput-outputcharacter
biAdjustmentVoucherinput-outputinteger
bcReverseDescriptioninput-outputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.ReverseCInvoice


program code (program3/bcinvoice.p)

assign oiReturnStatus = -98
       viLocalReturn  = 0.

/* =================================================================================================== */
/* Normalizeibnput parameters                                                                          */
/* =================================================================================================== */
if biReversedCInvoiceId    = 0    then assign biReversedCInvoiceId    = ?.
if bcReverseInvoiceType    = "":U then assign bcReverseInvoiceType    = ?.
if biReversePostingYear    = 0    then assign biReversePostingYear    = ?.
if biReversePostingPeriod  = 0    then assign biReversePostingPeriod  = ?.
if bcReverseInvoiceJournal = "":U then assign bcReverseInvoiceJournal = ?.
if biReverseInvoiceVoucher = 0    then assign biReverseInvoiceVoucher = ?.
if bcAdjustmentJournal     = "":U then assign bcAdjustmentJournal     = ?.
if biAdjustmentVoucher     = 0    then assign biAdjustmentVoucher     = ?.
if bcReverseDescription    = "":U then assign bcReverseDescription    = ?.

/* =================================================================================================== */
/* Validate whether Supplier invoice can be reversed                                                   */
/* =================================================================================================== */
assign vcContext = "biReversedCInvoiceId=&1|bcReverseInvoiceType=&2|biReversePostingYear=&3|biReversePostingPeriod=&4|":U
                 + "bcReverseInvoiceJournal=&5|biReverseInvoiceVoucher=&6|bcAdjustmentJournal=&7|biAdjustmentVoucher=&8|":U
                 + "bcReverseDescription=&9":U
       vcContext = substitute(vcContext, biReversedCInvoiceId, bcReverseInvoiceType, biReversePostingYear, biReversePostingPeriod,
                                         bcReverseInvoiceJournal, biReverseInvoiceVoucher, bcAdjustmentJournal, biAdjustmentVoucher,
                                         bcReverseDescription)
       vcContext = replace(vcContext, "|":U, chr(2)).

/* Supplier invoice to be reversed has to be defined */
if biReversedCInvoiceId = ?
then do:
    assign vcMessage = #T-1'Input parameter with Supplier Invoice ID which should be reversed is empty.':255(69115)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-7890':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    assign oiReturnStatus = -1.
    return.
end.

if not available tCInvoice
then do:
    assign vcMessage = #T-4'The supplier invoice record is missing.':255(69114)T-4#.
    <M-3 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-7891':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    assign oiReturnStatus = -1.
    return.
end.
 
/* Supplier invoice can be reversed if it's in certains status only */
<M-5 run ReverseCInvoiceValidateStatus  (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper < 0 or
   viFcReturnSuper > 0 and viLocalReturn = 0 
then assign viLocalReturn = viFcReturnSuper.

/* =================================================================================================== */
/* Validate whether all parameters for creation of Revese Supplier invoice are entered                 */
/* =================================================================================================== */
/* Check whether invoice type for reverse invoice is entered */
if bcReverseInvoiceType = ?
then do:
    assign vcMessage = #T-7'The Invoice Type for reversal invoices has not been defined.':255(69119)T-7#.
    <M-6 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-7892':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    assign viLocalReturn = -1.
end.

/* Check whether invoice type is valid one applicable for reversed (original) invoice */
else do:
    <M-8 run DefaultValuesReverseInvoiceTypes
       (input  tCInvoice.CInvoiceType (icOriginalInvoiceType), 
        output vcReverseInvoiceTypes (ocReverseInvoiceTypes), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    if viFcReturnSuper < 0 or
       viFcReturnSuper > 0 and viLocalReturn = 0 
    then assign viLocalReturn = viFcReturnSuper.

    if viFcReturnSuper >= 0
    then do:
        if lookup(bcReverseInvoiceType, vcReverseInvoiceTypes, chr(2)) = 0
        then do:
            assign vcMessage = #T-10'You cannot use an invoice of type (&1) to reverse supplier invoices of type &2.':255(69121)T-10#
                   vcMessage = substitute(vcMessage, bcReverseInvoiceType, tCInvoice.CInvoiceType).
            <M-9 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-7894':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  vcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
            assign viLocalReturn = -1.
        end.
    end.
end.

/* Posting date and period has to be entered */
if biReversePostingYear   = ? or
   biReversePostingPeriod = ? or
   btReversePostingDate   = ?
then do:
    assign vcMessage = #T-12'You must specify the posting date (&1), year (&2), and GL period (&3) to reverse a supplier invoice.':255(69122)T-12#
           vcMessage = substitute(vcMessage, btReversePostingDate, biReversePostingYear, biReversePostingPeriod).
    <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-7895':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    assign viLocalReturn = -1.
end.

/* Invoice daybook for reversal supplier invoice */
if bcReverseInvoiceJournal = ?
then do:
    assign vcMessage = #T-14'You must specify a reverse daybook.':255(69287)T-14#.
    <M-13 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-7896':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    assign viLocalReturn = -1.
end.
else do:
    if  vlPOCAllowUpdateDaybookOnInv     = false and
        tCInvoice.CInvoiceDayBookSetCode <> "":U and 
        tCInvoice.CInvoiceDayBookSetCode <> ?    and
        bcReverseInvoiceJournal <> "":U          and
        bcReverseInvoiceJournal <> ?             
    then do:  
        <Q-18 run DaybookSetByCodeBySite (all) (Read) (NoCache)
           (input tCInvoice.CInvoiceDayBookSetCode, (DaybookSetCode)
            input ?, (Site)
            input vcDomainCode, (DomainCode)
            output dataset tqDaybookSetByCodeBySite) in BMfgDaybookSet >
        find first tqDaybookSetByCodeBySite 
             where tqDaybookSetByCodeBySite.tcdybs_code = tCInvoice.CInvoiceDayBookSetCode no-error.
        if available tqDaybookSetByCodeBySite 
        then do:
            if bcReverseInvoiceType = {&INVOICETYPE-INVOICE} and
               bcReverseInvoiceJournal <> tqDaybookSetByCodeBySite.tcdybs_invoices_dybk
            then vlJournalNotInDaybookSet = true.    
            else if bcReverseInvoiceType = {&INVOICETYPE-CREDITNOTE} and
                 bcReverseInvoiceJournal <> tqDaybookSetByCodeBySite.tcdybs_credit_dybk
            then vlJournalNotInDaybookSet = true.
            else if bcReverseInvoiceType = {&INVOICETYPE-INVOICECORRECTION} and
                 bcReverseInvoiceJournal <> tqDaybookSetByCodeBySite.tcdybs_neg_criv_dybk
            then vlJournalNotInDaybookSet = true.
            else if bcReverseInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} and
                 bcReverseInvoiceJournal <> tqDaybookSetByCodeBySite.tcdybs_neg_crcn_dybk
            then vlJournalNotInDaybookSet = true.            
        end.          
    end. /* if  vlPOCAllowUpdateDaybookOnIn  = false and */
    
    if vlJournalNotInDaybookSet
    then do:
        <M-19 run SetMessage
           (input  trim(#T-20'The reverse daybook is not valid for the daybook set':255(733745365)T-20#) (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-9633':U:U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    
        assign viLocalReturn = -1.
    end.
end.

/* Adjustment daybook for reversal supplier invoice */
if bcAdjustmentJournal = ?
then do:
    assign vcMessage = #T-16'Adjustment daybook is mandatory.':255(69131)T-16#.
    <M-15 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-7897':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    assign viLocalReturn = -1.
end.

/* Description */
if bcReverseDescription = ?
then assign bcReverseDescription = tCInvoice.CInvoiceDescription.

/* ======================================================================= */
/* Error handling                                                          */
/* ======================================================================= */
if viLocalReturn  <> 0  then assign oiReturnStatus = viLocalReturn.
if oiReturnStatus = -98 then assign oiReturnStatus = 0.