project QadFinancials > class BCInvoice > method ApiCreateCreditorInvoices

Description

method that allows external parties to create Creditor-Opening-Balances (= CI of type Adjustment)


Parameters


tOpenBalanceCIinput-outputtemp-tabletemp-table used for the creation of Creditor-Opening-Balances
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCreditorOpenBalance.ApiCreateCreditorOpenBalanceV01


program code (program9/bcinvoice.p)

<M-15 run CreateCInvoices
   (input-output tOpenBalanceCI (tOpenBalanceCI), 
    input  ? (iiBJournalEntryId), 
    input  ? (iiPostingId), 
    input  ? (icPONbrInv), 
    output vcParam (ocNewRecordInfo), 
    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

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

/* extra validation for the prepayment open balance creation */
/* this can not be done in CreateCInvoicesValidate because the validation should only be done to Supplier Open Balance Create */
for each tOpenBalanceCI where 
         tOpenBalanceCI.tcInvoiceType = {&INVOICETYPE-PREPAYMENT} :
    /* Get The JournalType */
    <Q-24 run JournalByJournalLayerType (all) (Read) (NoCache)
       (input ?, (JournalId)
        input tOpenBalanceCI.tcJournalCode, (JournalCode)
        input viCompanyId, (CompanyId)
        input ?, (LayerTypeCode)
        output dataset tqJournalByJournalLayerType) in BJournal >
    find first tqJournalByJournalLayerType where
               tqJournalByJournalLayerType.tcJournalCode = tOpenBalanceCI.tcJournalCode 
               no-error.
    /* no need to validate the availablility because it has been done in CreateCInvoiceValidate method */
    if available tqJournalByJournalLayerType and 
       tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-CREDITORADJUSTMENT}
    then do:
        assign oiReturnStatus = -1.
        <M-23 run SetMessage
           (input  trim(#T-22'For opening balances of type Prepayment a daybook of type Supplier Adjustment should be used.':150(733763888)T-22#) (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-9743':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    end. /* if available */
end. /* end of For each */

if oiReturnStatus < 0
then return.

/* No check if mandatory on role needed when coming from ApiCreateCreditorInvoices. */
/* Keep track by setting a variable in session.                                     */
<I-16 {bFcOpenInstance
     &CLASS           = "Session"}>
<M-17 run SetLogicalValue
   (input  'CInvoiceRoleIsMandatory':U (icName), 
    input  false (ilValue), 
    output viFcReturnSuper (oiReturnStatus)) in Session>


/* Set actvity */
if can-find(first tCInvoice where
                  tCInvoice.tc_Status = "N":U)
then assign vcActivityCode = "Create":U.
else
if can-find (first tCInvoice where
                   tCInvoice.tc_Status = "C":U)
then assign vcActivityCode = "Modify":U.

/* Validate */
<M-12 run ValidateBC  (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

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

if oiReturnStatus < 0
then return.

/* Additional Updates */
<M-13 run AdditionalUpdates  (output  viFcReturnSuper (oiReturnStatus)) in BCInvoice>

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

if oiReturnStatus < 0
then return.

<I-20 {bFcOpenInstance
     &CLASS           = "Session"}>

<M-19 run SetLogicalValue
   (input  'CInvoiceRoleIsMandatory':U (icName), 
    input  true (ilValue), 
    output viFcReturnSuper (oiReturnStatus)) in Session>



/* Save */
<M-14 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

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

if oiReturnStatus < 0
then return.

<M-48 run GetOpeningBalanceVoucher
    (input-output tOpenBalanceCI (tOpenBalanceCI), 
     output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
     
if viFcReturnSuper < 0 or
   oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.