project QadFinancials > class BCInvoice > method ValidateComponentPostCAJournal

Description

This method is a submethod of ValidateComponentPost.

This method validates the CA Journal Code : this can only be filled for credit notes and where linked to invoice is filled


Parameters


blStart1input-outputlogicalIs query tqJournalForJEDefault already started or not ?
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.ValidateComponentPost


program code (program5/bcinvoice.p)

/* shx In the supplier invoice reversal function we need to provide the possibility to reverse
  a credit note to an invoice so the asjustments for invoices should be allowed */
/* No adjustment for invoices */

/*
if (t_sCInvoice.tc_Status        = "N":U                         or
    t_sCInvoice.tc_Status        = "C":U                         and
   (t_sCInvoice.CInvoiceType    <> t_iCInvoice.CInvoiceType      or
    t_sCInvoice.tcCAJournalCode <> t_iCInvoice.tcCAJournalCode)) and
    t_sCInvoice.CInvoiceType     = {&INVOICETYPE-INVOICE}        and
    t_sCInvoice.tcCAJournalCode <> "":U                          and
    t_sCInvoice.tcCAJournalCode <> ?
then do:
    <M-1 run SetMessage
       (input  trim(#T-1'You cannot use an adjustment daybook with invoice type $1.':255(69401)t-1#) (icMessage), 
        input  {&INVOICETYPE-INVOICE-TR} (icArguments), 
        input  'tCInvoice.tcCAJournalCode':U (icFieldName), 
        input  t_sCInvoice.tcCAJournalCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sCInvoice.tc_Rowid (icRowid), 
        input  'QadFin-7043':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

    assign oiReturnStatus = -1.
end.
*/
/* Adjustment mandatory for credit notes, invoice corrections and credit note corrections if a linked invoice is specified */
if (t_sCInvoice.tc_Status          = "N":U                                or
    t_sCInvoice.tc_Status          = "C":U                                and
   (t_sCInvoice.CInvoiceType      <> t_iCInvoice.CInvoiceType             or
    t_sCInvoice.tcCAJournalCode   <> t_iCInvoice.tcCAJournalCode          or
    t_sCInvoice.LinkedCInvoice_ID <> t_iCInvoice.LinkedCInvoice_ID))      and
   (t_sCInvoice.CInvoiceType       = {&INVOICETYPE-CREDITNOTE}            or
    t_sCInvoice.CInvoiceType       = {&INVOICETYPE-INVOICECORRECTION}     or
    t_sCInvoice.CInvoiceType       = {&INVOICETYPE-CREDITNOTECORRECTION}) and
    t_sCInvoice.LinkedCInvoice_ID <> 0                                    and
    t_sCInvoice.LinkedCInvoice_ID <> ?                                    and
   (t_sCInvoice.tcCAJournalCode    = "":U                                 or
    t_sCInvoice.tcCAJournalCode    = ?)
then do:
    <M-2 run SetMessage
       (input  trim(#T-2'You must use an adjustment daybook for invoice type $1, $2, or $3.':255(69402)t-2#) (icMessage), 
        input  {&INVOICETYPE-CREDITNOTE-TR} + chr(2) + {&INVOICETYPE-INVOICECORRECTION-TR} + chr(2) + {&INVOICETYPE-CREDITNOTECORRECTION-TR} (icArguments), 
        input  'tCInvoice.tcCAJournalCode':U (icFieldName), 
        input  t_sCInvoice.tcCAJournalCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sCInvoice.tc_Rowid (icRowid), 
        input  'QadFin-7044':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

    assign oiReturnStatus = -1.
end.
/* shx CA Journal must be active not only for Creditnote invoice correction creditonote correction 
   buf also for other invoice types */
/* CA Journal must be active, of type Creditor Adjustment and of Financial control */
if (t_sCInvoice.tc_Status          = "N":U                                or
    t_sCInvoice.tc_Status          = "C":U                                and
   (t_sCInvoice.CInvoiceType      <> t_iCInvoice.CInvoiceType             or
    t_sCInvoice.tcCAJournalCode   <> t_iCInvoice.tcCAJournalCode          or
    t_sCInvoice.LinkedCInvoice_ID <> t_iCInvoice.LinkedCInvoice_ID))      and
/* (t_sCInvoice.CInvoiceType       = {&INVOICETYPE-CREDITNOTE}            or
    t_sCInvoice.CInvoiceType       = {&INVOICETYPE-INVOICECORRECTION}     or
    t_sCInvoice.CInvoiceType       = {&INVOICETYPE-CREDITNOTECORRECTION}) and */
    t_sCInvoice.LinkedCInvoice_ID <> 0                                    and
    t_sCInvoice.LinkedCInvoice_ID <> ?                                    and
    t_sCInvoice.tcCAJournalCode   <> "":U                                 and
    t_sCInvoice.tcCAJournalCode   <> ?
then do:
    if not blStart1
    then do:
        <Q-8 run JournalByJournalIDCodeType  (Start) in BJournal >
        assign blStart1 = true.
    end.

    <Q-7 run JournalByJournalIDCodeType (all) (Read) (NoCache)
       (input t_sCInvoice.Company_ID, (CompanyId)
        input ?, (JournalID)
        input t_sCInvoice.tcCAJournalCode, (JournalCode)
        input {&JOURNALTYPE-CREDITORADJUSTMENT}, (JournalTypeCode)
        output dataset tqJournalByJournalIDCodeType) in BJournal >

    find first tqJournalByJournalIDCodeType where
               tqJournalByJournalIDCodeType.tcJournalCode     = t_sCInvoice.tcCAJournalCode and
               tqJournalByJournalIDCodeType.tcJournalTypeCode = {&JOURNALTYPE-CREDITORADJUSTMENT}
               no-error.

    if available tqJournalByJournalIDCodeType
    then do:
        <M-5 run ValIsActive
           (input  t_sCInvoice.tcCAJournalCode (icTargetField), 
            input  'tCInvoice.tcCAJournalCode':U (icTargetFieldName), 
            input  t_sCInvoice.tc_Rowid (icRowid), 
            input  tqJournalByJournalIDCodeType.tlJournalIsActive (ilIsActive), 
            input  trim(#T-3'Adjustment daybook code':40(65427)T-3#) (icParentObjectLabel), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.
    end.
    else do:
        <M-6 run SetMessage
           (input  trim(#T-4'The adjustment daybook code you specified is invalid.':255(65428)t-4#) (icMessage), 
            input  '':U (icArguments), 
            input  'tCInvoice.tcCAJournalCode':U (icFieldName), 
            input  t_sCInvoice.tcCAJournalCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sCInvoice.tc_Rowid (icRowid), 
            input  'QadFin-7045':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

        assign oiReturnStatus = -1.
    end.
end.