project QadFinancials > class BCInvoice > method PostSave

Description

Actions to take after writing current instance to the database, and before final commit of the transaction.
Use the field tc_status to test the status of the updated records:
'' = unchanged
'N' = new
'C' = changed
'D' = deleted


Parameters


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bcinvoice.p)

/* ======================================================================= */
/* Note that the CommitNumber for WHT is done in component BWithHoldingTax */
/* ======================================================================= */
    
<ANCESTOR-CODE>
    
/* ========================== */
/* Commit the voucher-numbers */
/* ========================== */
for each tCInvoice where
         tCInvoice.tc_Status = "N":U:

    if tCInvoice.CInvoiceVoucher <> 0 and
       tCInvoice.CInvoiceVoucher <> ?
    then do:
        assign vhFcComponent = ?.
        <M-2 run CommitNumber
           (input  viCompanyId (iiCompanyID), 
            input  tCInvoice.CInvoicePostingYear (iiNumbrYear), 
            input  tCInvoice.tcJournalCode (icNumbrType), 
            input  tCInvoice.CInvoiceVoucher (iiNumbr), 
            input  viFcCurrentInstanceId (iiInstanceId), 
            input  vcFcComponentName (icClassName), 
            output viFcReturnSuper (oiReturnStatus)) in BNumber>

        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then return.

    end. /* if tCInvoice.CInvoiceVoucher <> 0 and */

    if tCInvoice.tiCAVoucher <> 0 and
       tCInvoice.tiCAVoucher <> ?
    then do:
        assign vhFcComponent = ?.
        <M-13 run CommitNumber
           (input  viCompanyId (iiCompanyID), 
            input  tCInvoice.CInvoicePostingYear (iiNumbrYear), 
            input  tCInvoice.tcCAJournalCode (icNumbrType), 
            input  tCInvoice.tiCAVoucher (iiNumbr), 
            input  viFcCurrentInstanceId (iiInstanceId), 
            input  vcFcComponentName (icClassName), 
            output viFcReturnSuper (oiReturnStatus)) in BNumber>
        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then return.
    end. /* if tCInvoice.tiCAVoucher <> 0 and */

    if tCInvoice.CInvoiceRegistrationNr <> 0 and
       tCInvoice.CInvoiceRegistrationNr <> ?
    then do:
        assign vhFcComponent = ?.
        <M-14 run CommitNumber
           (input  viCompanyId (iiCompanyID), 
            input  9999 (iiNumbrYear), 
            input  {&SUPPLIERINVOICEREGNUMBER} (icNumbrType), 
            input  tCInvoice.CInvoiceRegistrationNr (iiNumbr), 
            input  viFcCurrentInstanceId (iiInstanceId), 
            input  vcFcComponentName (icClassName), 
            output viFcReturnSuper (oiReturnStatus)) in BNumber>
        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then return.
    end. /* if tCInvoice.CInvoiceRegistrationNr <> 0 and */

end. /* for each tCInvoice where */

/* I19 requirement for Brazil =============================================================================================== *
 * When the invoice is created for the Legal document, and this invoice is beeing or Finished or Cancelled, then we have to   *
 * update also Legal document to indicate, it is or posted or un-posted                                                       *
 * ========================================================================================================================== */
if can-find(first tCInvoice where
                  tCInvoice.tlCInvoiceIsForLegalDoc = true)
then do:
    <M-55 run PostSaveLegalDocument  (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    if viFcReturnSuper < 0 or oiReturnStatus  = 0 then assign oiReturnStatus = viFcReturnSuper.
    if oiReturnStatus < 0 then return.
end.

/* ============================= */
/* Actions for sending out mails */
/* ============================= */
/* ********* SHOULD BE DONE IN WORKOBJECT, but till then it will be done here ******* */
if vcRoleNameList <> '':U
then do:
    /* Get From Mail Address */
    <Q-8 run UserByNameID (all) (Read) (NoCache)
          (input viUsrId, (UsrId)
           input '':U, (UsrName)
           input ?, (UsrLogin)
           output dataset tqUserByNameID) in BUser >
    find first tqUserByNameID where
               tqUserByNameID.tiUsr_ID = viUsrId
               no-lock no-error.
    if not available tqUserByNameID
    then do:
        assign vcMessage = trim(#T-10'The current user could not be found.':200(1225)T-10#) + chr(10) +
                           trim(substitute(#T-11'User ID: &1.':100(1226)T-11#, trim(string(viUsrId)) ))
               oiReturnStatus = -1.
        <M-9 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  viUsrId (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-2236':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        return.
    end. /* if not available tqUserByNameID */
end. /* if vcRoleNameList <> '':U */

do viCnt = num-entries(vcRoleNameList, chr(4)) to 1 by -1:

    /* Send mail */
    /* Get To Mail Address */
    <Q-5 run UsrRoleByRole (all) (Read) (NoCache)
          (input 0, (RoleID)
           input entry(viCnt, vcRoleNameList, chr(4)), (RoleName)
           output dataset tqUsrRoleByRole) in BRole >
    find first tqUsrRoleByRole where
               tqUsrRoleByRole.tcRoleName = entry(viCnt, vcRoleNameList, chr(4))
               no-lock no-error.
    if not available tqUsrRoleByRole
    then do:
        assign oiReturnStatus = -1.
        <M-6 run SetMessage
           (input  trim(subst(#T-12'No user role is defined for role &1.':200(1227)t-12#, trim(entry(viCnt, vcRoleNameList, chr(4))))) (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-2235':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        return.
    end. /* if not available tqUsrRoleByRole */

    assign vhFcComponent = ?.
    <M-7 run Send (input  tqUserByNameID.tcUsrMailAddress (icFrom), 
               input  tqUsrRoleByRole.tcUsrMailAddress (icTo), 
               input  entry(viCnt, vcInstructionList, chr(4)) (icSubject), 
               input  '':U (icBody), 
               output viFcReturnSuper (oiReturnStatus)) in Mail>

end. /* do viCnt = num-entries(vcRoleNameList, chr(4)) to 1 by -1: */

/* ====================================================================================================================== */
/* IMPORTANT NOTE:                                                                                                        */
/* The normal process is that updates towards other classes are done through the normal approach with Starting&Opening    */
/* the external instance and then call a method in there. But as that decreases the performance to much for frequently    */
/* used actions like the creation of the QCInvoiceMovement-records, we will here do the creation of these                 */
/* records here via dynamic buffers.                                                                                      */
/* The temp-tables records of tQCInvoiceMovementToCreate are still created in AdditionalUpdatesAllQCInvoiceMovement       */
/* ====================================================================================================================== */
<M-60 run PostSaveDynamicCreations
   (output viCnt (oiNbrOfCreatedQCInvoiceMovement), 
    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.