project QadFinancials > class BCInvoice > method ValidateComponentPostMatching

Description

This method is a submethod of ValidateComponentPost.

This method does some validations on the creditor invoice logistic matching flag.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.ValidateComponentPost


program code (program5/bcinvoice.p)

/* Receiver matching option cannot be turned of if a matching posting already exists. */
if t_sCInvoice.tc_Status                   = "C":U                                  and
   t_sCInvoice.CInvoiceIsLogisticMatching <> t_iCInvoice.CInvoiceIsLogisticMatching and
   t_sCInvoice.CInvoiceIsLogisticMatching  = false                                  and
   t_iCInvoice.CInvoiceIsLogisticMatching  = true                                   and
   can-find(t_sCInvoicePosting where
            t_sCInvoicePosting.tc_ParentRowid      = t_sCInvoice.tc_Rowid             and
            t_sCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION} and
            t_sCInvoicePosting.tc_Status          <> "D":U and
            t_sCInvoicePosting.tc_Status          <> "N":U)
then do:
    assign vcMessage      = trim(#T-4'You cannot modify the Receiver Matching option when a matching posting already exists.':150(1249)t-4#) + chr(10) +
                            trim(subst(#T-5'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-5#, string(t_sCInvoice.CInvoicePostingYear), string(t_sCInvoice.CInvoicePostingPeriod), t_sCInvoice.tcJournalCode, string(t_sCInvoice.CInvoiceVoucher)))
           oiReturnStatus = -1.

    <M-1 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  'tCInvoice.CInvoiceIsLogisticMatching':U (icFieldName), 
        input  t_sCInvoice.CInvoiceIsLogisticMatching (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sCInvoice.tc_Rowid (icRowid), 
        input  'QADFIN-4437':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.

/* Do not save the invoice when Matching status is INITIAL */
if vlBAPMatchingInvoice  = false and
   t_sCInvoice.tc_Status <> "N":U
then do:
   if t_sCInvoice.CInvoiceIsLogisticMatching = true and
      t_iCInvoice.CInvoiceIsLogisticMatching = true and
      t_sCInvoice.tcReasonAllocationStatus = {&ALLOCSTATUS-ALLOC} and
      t_iCInvoice.tcReasonAllocationStatus = {&ALLOCSTATUS-NOALLOC}
   then do:
      <Q-11 run APMatchingByCInvoice (all) (Read) (NoCache)
         (input viCompanyId, (CompanyId)
          input t_sCInvoice.CInvoice_ID, (CInvoiceId)
          input ?, (CInvoiceYear)
          input ?, (CInvoiceJournalCode)
          input ?, (CInvoiceVoucher)
          output dataset tqAPMatchingByCInvoice) in BAPMatching>
          
      find first tqAPMatchingByCInvoice where 
                 tqAPMatchingByCInvoice.tiCInvoice_ID = t_sCInvoice.CInvoice_ID no-error.
      if available tqAPMatchingByCInvoice and
      tqAPMatchingByCInvoice.tcAPMatchingStatus = {&APMATCHINGSTATUS-INITIAL}
      then do:
         assign vcMessage = trim(#T-80'You cannot save the Invoice. Matching has a status of INITIAL.':255(645527215)T-80#).
         
         <M-56 run SetMessage
            (input  vcMessage (icMessage), 
             input  '':U (icArguments), 
             input  'tqAPMatchingByCInvoice.tcAPMatchingStatus':U (icFieldName), 
             input  tqAPMatchingByCInvoice.tcAPMatchingStatus (icFieldValue), 
             input  'E':U (icType), 
             input  3 (iiSeverity), 
             input  tqAPMatchingByCInvoice.tc_rowid (icRowid), 
             input  'qadfin-240691':U (icFcMsgNumber), 
             input  '':U (icFcExplanation), 
             input  '':U (icFcIdentification), 
             input  '':U (icFcContext), 
             output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
         oiReturnStatus = -1.
      end.
   end.
   else if t_sCInvoice.CInvoiceIsLogisticMatching = false and
           t_iCInvoice.CInvoiceIsLogisticMatching = true
        then do:
           <Q-87 run APMatchingByCInvoice (all) (Read) (NoCache)
              (input viCompanyId, (CompanyId)
               input t_sCInvoice.CInvoice_ID, (CInvoiceId)
               input ?, (CInvoiceYear)
               input ?, (CInvoiceJournalCode)
               input ?, (CInvoiceVoucher)
               output dataset tqAPMatchingByCInvoice) in BAPMatching>
               
           find first tqAPMatchingByCInvoice where
                      tqAPMatchingByCInvoice.tiCInvoice_ID = t_sCInvoice.CInvoice_ID no-error.
           if available tqAPMatchingByCInvoice and
           tqAPMatchingByCInvoice.tcAPMatchingStatus = {&APMATCHINGSTATUS-INITIAL}
           then do:
              assign vcMessage = trim(#T-94'You cannot change the Invoice Status Code, Receiver Matching has a status of INITIAL. Please delete the Receiver Matching to use the Invoice Status Code':255(82023987)T-94#).
              
              <M-73 run SetMessage
                 (input  vcMessage (icMessage), 
                  input  '':U (icArguments), 
                  input  'tqAPMatchingByCInvoice.tcAPMatchingStatus':U (icFieldName), 
                  input  tqAPMatchingByCInvoice.tcAPMatchingStatus (icFieldValue), 
                  input  'E':U (icType), 
                  input  3 (iiSeverity), 
                  input  tqAPMatchingByCInvoice.tc_rowid (icRowid), 
                  input  'qadfin-625001':U (icFcMsgNumber), 
                  input  '':U (icFcExplanation), 
                  input  '':U (icFcIdentification), 
                  input  '':U (icFcContext), 
                  output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
              oiReturnStatus = -1.
           end. /* if available tqAPMatchingByCInvoice and */
        end. /* else if t_sCInvoice.CInvoiceIsLogisticMatching = false and */
end. /* if vlBAPMatchingInvoice  = false and */

/* when vcactivitycode <> "" (so when invoice activity, not matching activity)                          */
/* check if no invoice status code is used of logistic matching and allocation status of allocation     */
/* only done for initial allocation status of no allocation                                             */
/* (otherwise when modifying a supplier invoice that is matched by receiver matching gives also error)  */
if  vcActivityCode <> "":U and
  ((t_sCInvoice.tc_Status                   = "N":U and
    t_sCInvoice.CInvoiceIsLogisticMatching  = true  and
    t_sCInvoice.tcReasonAllocationStatus   <> {&ALLOCSTATUS-NOALLOC} and
   (t_sCInvoice.LinkedCInvoice_ID           = 0 or
    t_sCInvoice.LinkedCInvoice_ID           = ?)) or
   (t_sCInvoice.tc_Status                   = "C":U and
    t_sCInvoice.tcReasonCode               <> t_iCInvoice.tcReasonCode and
    t_sCInvoice.CInvoiceIsLogisticMatching  = true  and
    t_sCInvoice.tcReasonAllocationStatus   <> {&ALLOCSTATUS-NOALLOC} and
  ((t_iCInvoice.tcReasonAllocationStatus    = {&ALLOCSTATUS-NOALLOC} and
    t_iCInvoice.CInvoiceIsLogisticMatching  = true) or
   (t_iCInvoice.tcReasonAllocationStatus    = {&ALLOCSTATUS-NOALLOC} and
    t_iCInvoice.CInvoiceIsLogisticMatching  = false) or
   (t_iCInvoice.tcReasonAllocationStatus   <> {&ALLOCSTATUS-NOALLOC} and
    t_iCInvoice.CInvoiceIsLogisticMatching  = false) ) and
   (t_sCInvoice.LinkedCInvoice_ID           = 0 or
    t_sCInvoice.LinkedCInvoice_ID           = ?)) )
then do:
    assign vcMessage      = trim(#T-6'You selected an invalid invoice status code. This invoice status code has been defined as an After Matching status code.':255(69400)t-6#) + chr(10) +
                            trim(subst(#T-7'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-7#, string(t_sCInvoice.CInvoicePostingYear), string(t_sCInvoice.CInvoicePostingPeriod), t_sCInvoice.tcJournalCode, string(t_sCInvoice.CInvoiceVoucher)))
           oiReturnStatus = -1.

    <M-2 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  'tCInvoice.CInvoiceIsLogisticMatching':U (icFieldName), 
        input  t_sCInvoice.CInvoiceIsLogisticMatching (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sCInvoice.tc_Rowid (icRowid), 
        input  'QADFIN-4438':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
end.