project QadFinancials > class BCInvoice > method CreateCInvoiceMovementsIDS


Parameters


tMovementinput-outputtemp-table
tCInvoiceStageUpdatesinputtemp-table
tInvoicesToUpdateoutputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.CreateCInvoiceMovements


program code (program7/bcinvoice.p)

for each tMovement:
    /* replace unknown values */
    if tMovement.tiCInvoiceId = ? then assign tMovement.tiCInvoiceId = 0.
    if tMovement.tdAmountDebitTC = ? then assign tMovement.tdAmountDebitTC = 0.
    if tMovement.tdAmountCreditTC = ? then assign tMovement.tdAmountCreditTC = 0.
    if tMovement.tcGLAccountDivisionCode = ? then assign tMovement.tcGLAccountDivisionCode = "":U.
    /* invoice is mandatory */
    if tMovement.tiCInvoiceId = 0
    then do:
      assign oiReturnStatus = -1.
      <M-1 run SetMessage
         (input  trim(#T-5'You must enter the invoice identification.':255(1204)T-5#) (icMessage), 
          input  '':U (icArguments), 
          input  '':U (icFieldName), 
          input  '':U (icFieldValue), 
          input  'E':U (icType), 
          input  3 (iiSeverity), 
          input  '':U (icRowid), 
          input  'QadFin-5890':U (icFcMsgNumber), 
          input  '' (icFcExplanation), 
          input  '' (icFcIdentification), 
          input  '' (icFcContext), 
          output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
      Leave.
    end.
    /* debit or credit must be filled */
    if tMovement.tdAmountDebitTC  = 0 and
       tMovement.tdAmountCreditTC = 0
    then do:
      assign oiReturnStatus = -1.
      <M-2 run SetMessage
         (input  trim(#T-6'You must enter either the debit or the credit amount.':255(1205)T-6#) (icMessage), 
          input  '':U (icArguments), 
          input  '':U (icFieldName), 
          input  '':U (icFieldValue), 
          input  'E':U (icType), 
          input  3 (iiSeverity), 
          input  '':U (icRowid), 
          input  'QadFin-5891':U (icFcMsgNumber), 
          input  '' (icFcExplanation), 
          input  '' (icFcIdentification), 
          input  '' (icFcContext), 
          output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
      Leave.
    end.
    /* Check if the CInvoice is in another company; if so then   */
    /* start another method that will do the specific processing */
    <Q-7 run CInvoiceByCyIDYearJrnlVchr (all) (Read) (Cache)
       (input ?, (CompanyId)
        input tMovement.tiCInvoiceId, (CInvoiceId)
        input ?, (PeriodYear)
        input ?, (JournalId)
        input ?, (JournalCode)
        input ?, (Voucher)
        output dataset tqCInvoiceByCyIDYearJrnlVchr) in BCInvoice>
    find first tqCInvoiceByCyIDYearJrnlVchr where 
               tqCInvoiceByCyIDYearJrnlVchr.tiCInvoice_ID  = tMovement.tiCInvoiceId and
               tqCInvoiceByCyIDYearJrnlVchr.tiCompany_ID  <> viCompanyId
               no-lock no-error.
    if available tqCInvoiceByCyIDYearJrnlVchr
    then do:
        find first tCInvoiceStageUpdates where
                   tCInvoiceStageUpdates.tiCInvoice_ID = tMovement.tiCInvoiceId
                   no-error.
        <M-4 run CreateCInvoiceMovementsCrossCy
           (input  tMovement.tcPostingRowId (icPostingRowId), 
            input  tMovement.tdAmountCreditTC (idMovementAmountCreditTC), 
            input  tMovement.tdAmountDebitTC (idMovementAmountDebitTC), 
            input  tMovement.tdAmountCreditLC (idMovementAmountCreditLC), 
            input  tMovement.tdAmountDebitLC (idMovementAmountDebitLC), 
            input  tMovement.tdAmountCreditCC (idMovementAmountCreditCC), 
            input  tMovement.tdAmountDebitCC (idMovementAmountDebitCC), 
            input  tMovement.tiCInvoiceId (iiMovementCInvoiceID), 
            input  tMovement.tcGLAccountDivisionCode (icMovemenGLAccountDivisionCode), 
            input  if available tCInvoiceStageUpdates then tCInvoiceStageUpdates.CDocumentInvoiceXref_ID else ? (iiCDocInvoiceXrefID), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 
        then leave. 
        next. /* posting lines are created in this submethod so continue with the next tMovement */
    end. /* if available tqCInvoiceByCyIDYearJrnlVchr */

    /* put all invoices in a variabled, so you can do a dataload only once */
    find first tCInvoice where 
               tCInvoice.CInvoice_ID = tMovement.tiCInvoiceId
               no-error.
    if not available tCInvoice
    then do:
        if not can-find(first tInvoicesToUpdate where tInvoicesToUpdate.tiCInvoiceID =  tMovement.tiCInvoiceId)
        then do:
            create tInvoicesToUpdate.           
            assign tInvoicesToUpdate.tiCInvoiceID = tMovement.tiCInvoiceId.
        end.
    
    /*assign bcListCInvoiceIds = if bcListCInvoiceIds = "":U
                                    then string(tMovement.tiCInvoiceId)
                                    else if lookup(string(tMovement.tiCInvoiceId), bcListCInvoiceIds,chr(4)) = 0
                                         then bcListCInvoiceIds + chr(4) + string (tMovement.tiCInvoiceId)
                                         else bcListCInvoiceIds.*/
    end.
end.