project QadFinancials > class BCInvoice > method LoadCIAndMFPosting

Description

Load the CI and MF Posting


Parameters


iiCInvoiceIdinputintegerCreditor invoice ID
oiBJournalEntryIdoutputintegerInstance of Journal Entry
oiCIPostingIdoutputintegerPosting ID of CI Posting
oiMFPostingIdoutputintegerPosting ID of the MF Posting
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bcinvoice.p)

/* ======================= */
/* Default return-status   */
/* ======================= */
assign oiReturnStatus = -98. 

/* ====================== */
/* replace unknown values */
/* ====================== */
if iiCInvoiceId = ? then assign iiCInvoiceId = 0.

/* ======================== */
/* validate input parameter */
/* ======================== */
if iiCInvoiceId = 0
then do:
    assign oiReturnStatus = -1.
    <M-25 run SetMessage
       (input  trim(#T-29'You must enter the supplier invoice identification.':150(1121)T-29#) (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8299':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    return.
end.

find first tCInvoice where
           tCInvoice.CInvoice_ID = iiCInvoiceId
           no-error.
if not available tCInvoice
then do:
    assign oiReturnStatus = -1.

     <M-26 run SetMessage
        (input  #T-90'Supplier Invoice (ID $1) not found.':150(950600368)T-90# (icMessage), 
         input  string(iiCInvoiceId) (icArguments), 
         input  ' ':U (icFieldName), 
         input  ' ':U (icFieldValue), 
         input  'E':U (icType), 
         input  3 (iiSeverity), 
         input  ' ':U (icRowid), 
         input  'QadFin-8300':U (icFcMsgNumber), 
         input  ' ':U (icFcExplanation), 
         input  ' ':U (icFcIdentification), 
         input  ' ':U (icFcContext), 
         output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    return.
end.
    
/* ======================================= */
/* No posting records for initial invoices */
/* ======================================= */
if tCInvoice.CInvoiceIsInitialStatus = false
then do:    
    /* ============================== */
    /* search the right CI Posting ID */
    /* ============================== */
    assign viCIPostingId = 0.
    find first tCInvoicePosting where
               tCInvoicePosting.CInvoice_ID         = iiCInvoiceId and
               tCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-INITIAL}
               no-error.
    if available tCinvoicePosting
    then assign viCIPostingId = tCInvoicePosting.Posting_ID.
    else do:
        find first tCInvoiceMovement where
                   tCInvoiceMovement.CInvoice_ID          = iiCInvoiceId and
                   tCInvoiceMovement.CInvoiceMovementType = {&MOVEMENTTYPE-INITIAL}
                   no-error.
        if available tCInvoiceMovement
        then do:
            <Q-24 run PostingByPostingLineId (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input tCInvoiceMovement.PostingLine_ID, (PostingLineId)
           output dataset tqPostingByPostingLineId) in BPosting >
            find first tqPostingByPostingLineId no-error.
            assign viCIPostingId = if available tqPostingByPostingLineId
                                   then tqPostingByPostingLineId.tiPosting_ID
                                   else 0.
        end.
    end.
    
    if viCIPostingId = 0
    then do:
        assign oiReturnStatus = -1.
        <M-18 run SetMessage
           (input  trim(#T-28'No SI posting record found for supplier invoice $1 $2 $3.':150(70245)T-28#) (icMessage), 
            input  string(tCInvoice.CInvoicePostingYear) + chr(2) + tCInvoice.tcJournalCode + chr(2) + string(tCInvoice.CInvoiceVoucher) (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'D':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-8298':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        return.
    end.
    
    /* ============================== */
    /* search the right MF Posting ID */
    /* ============================== */
    assign viMFPostingId = 0.
    
    find first tCInvoicePosting where
               tCInvoicePosting.CInvoice_ID         = iiCInvoiceId and
               tCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION}
               no-error.
    if available tCinvoicePosting
    then assign viMFPostingId = tCInvoicePosting.Posting_ID.
    
    /* ============================================ */
    /* start and/or open the journal entry instance */
    /* ============================================ */
    if viBJournalEntryCIId = 0 or
       viBJournalEntryCIId = ?
    then do:
        <I-19 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BJournalEntry"}>
        assign vlBJEIsStartedFromCI = true.
    end.
    else do:
        <I-20 {bFcOpenInstance
            &CLASS           = "BJournalEntry"}>
    end.
    
    /* =============== */
    /* load the record */
    /* =============== */
    assign vcListPostingIds = if viMFPostingId <> 0
                              then string(viCIPostingId) + chr(4) + string(viMFPostingId)
                              else string(viCIPostingId).

    <M-21 run DataLoad
       (input  '':U (icRowids), 
        input  vcListPostingIds (icPkeys), 
        input  '':U (icObjectIds), 
        input  '' (icFreeform), 
        input  false (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
    then assign oiReturnStatus = viFcReturnSuper.

    /* ================================ */
    /* close the journal entry instance */
    /* ================================ */
    <I-22 {bFcCloseInstance
            &CLASS           = "BJournalEntry"}>
    if viFcReturnSuper < 0 
    then do:
    
        /* ======================= */
        /* Stop external instances */
        /* ======================= */
        <M-23 run StopExternalInstances
           (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        return.
    end.
end.
else assign viBJournalEntryCIID = 0
            viCIPostingId       = 0
            viMFPostingId       = 0.

   
assign oiBJournalEntryId = viBJournalEntryCIID
       oiCIPostingId     = viCIPostingId
       oiMFPostingId     = viMFPostingId.

/* ====================== */
/* Default return-status  */
/* ====================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.