project QadFinancials > class BCInvoice > method DefaultValuesJournal


Parameters


icCInvoiceRowIdinputcharacterRow ID of the supplier invoice
bcJournalCodeinput-outputcharacter
iiCInvoicePostingYearinputinteger
icCInvoiceTypeinputcharacter
iiOldCInvoicePostingYearinputinteger
icOldJournalCodeinputcharacter
iiOldCInvoiceVoucherinputinteger
ilCInvoiceIsInitialStatusinputlogical
oiCInvoiceVoucheroutputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.DefaultValuesDaybookSetCodeSite
method BCInvoice.DefaultValuesPostingDate
method BCInvoice.DefaultValuesPostingYear
method BCInvoice.DefaultValuesReverseDaybook
method BCInvoice.DefaultValuesReverseDaybookSet


program code (program3/bcinvoice.p)

/* ===================================================================== */
/* This method will                                                      */
/* - release the previous number to the numbering system  (if needed)    */
/* - check if the new daybook (journal) is valid in case it changed      */
/* - get a new number from the numbering system (if needed)              */
/* ===================================================================== */

assign vcOriginalJournalCode = bcJournalCode.

find first tCInvoice where
           tCInvoice.tc_Rowid = icCInvoiceRowId
           no-error.
if not available tCInvoice
then do:
    <M-8 run SetMessage
       (input  #T-9'The specified supplier invoice is not defined in the system or is invalid.':255(69257)t-9# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'D':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8550':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    assign oiReturnStatus = -3.
    return.
end.

if bcJournalCode = ?
then assign bcJournalCode = "":U.

/* Validate the daybook */
if bcJournalCode = "":U
then do:
    assign tCInvoice.tcJournalCode   = bcJournalCode
           tCInvoice.CInvoiceVoucher = 0.
    return.
end.

if bcJournalCode <> icOldJournalCode
then do:
    assign vcJournalTypeCode = if icCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
                               then {&JOURNALTYPE-CREDITORCREDITNOTECORRECT}
                               else
                               if icCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                               then {&JOURNALTYPE-CREDITORCREDITNOTE}
                               else
                               if icCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                               then {&JOURNALTYPE-CREDITORINVOICECORRECT}
                               else {&JOURNALTYPE-CREDITORINVOICE}.

   <Q-7 run JournalBeginsForJEDefault (all) (Read) (NoCache)
      (input viCompanyId, (CompanyId)
       input bcJournalCode, (JournalCode)
       input {&JOURNALCONTROL-FINANCIAL}, (JournalControl)
       input vcJournalTypeCode, (JournalTypeCode)
       output dataset tqJournalBeginsForJEDefault) in BJournal >
   
       find first tqJournalBeginsForJEDefault
            where tqJournalBeginsForJEDefault.tcJournalCode = bcJournalCode no-error.
       if not available tqJournalBeginsForJEDefault
          then do:
              find tqJournalBeginsForJEDefault
                   where tqJournalBeginsForJEDefault.tcJournalCode BEGINS bcJournalCode no-error.
               /* if there's only one record - ambiguous records will not be found and available will be false */
              if available tqJournalBeginsForJEDefault 
              then assign bcJournalCode = tqJournalBeginsForJEDefault.tcJournalCode.
              else do:
                  assign  bcJournalCode = vcOriginalJournalCode
                  oiReturnStatus = -4.
                  return.                  
              end. 
        end.
end.

/* Invoices with status 'Initial' can never have a voucher assigned */
if ilCInvoiceIsInitialStatus = true
then do:
     assign oiCInvoiceVoucher = 0.
     return.
end.

/* ============================================== */
/* Check if consecutive numbering is enabled.     */
/* If so, use a temporary number.                 */
/* Otherwise use standard numbering functionality */
/* ============================================== */
if vlCIDomainIsConsecutNr = true                and
   (icCInvoiceType <> {&INVOICETYPE-PREPAYMENT} and
    icCInvoiceType <> {&INVOICETYPE-ADJUSTMENT})
then assign viTempCInvoiceVoucher = viTempCInvoiceVoucher + 1
            oiCInvoiceVoucher     = viTempCInvoiceVoucher.
else do:
    /* Release the previous number */
    if iiOldCInvoicePostingYear <> 0    and iiOldCInvoicePostingYear <> ?    and
       icOldJournalCode         <> "":U and icOldJournalCode         <> ?    and
       iiOldCInvoiceVoucher     <> 0    and iiOldCInvoiceVoucher     <> ?   
    then do:
        assign vhFcComponent = ?.
        <M-1 run ReleaseNumber
           (input  viCompanyId (iiCompanyId), 
            input  iiOldCInvoicePostingYear (iiNumbrYear), 
            input  icOldJournalCode (icNumbrType), 
            input  iiOldCInvoiceVoucher (iiNumbr), 
            input  viFcCurrentInstanceId (iiInstanceId), 
            input  vcFcComponentName (icClassName), 
            output viFcReturnSuper (oiReturnStatus)) in BNumber>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)        
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then return.
    end.
    
    if iiCInvoicePostingYear <> 0 and iiCInvoicePostingYear <> ?   
    then do:
        assign vhFcComponent = ?.
    
        <M-3 run GetNumber
           (input  viCompanyId (iiCompanyId), 
            input  iiCInvoicePostingYear (iiNumbrYear), 
            input  bcJournalCode (icNumbrType), 
            output oiCInvoiceVoucher (oiNumber), 
            input  viFcCurrentInstanceId (iiInstanceId), 
            input  vcFcComponentName (icClassName), 
            output viFcReturnSuper (oiReturnStatus)) in BNumber>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then return.
    end.
end. /* else do: */

assign tCInvoice.CInvoicePostingYear = iiCInvoicePostingYear
       tCInvoice.tcJournalCode       = bcJournalCode
       tCInvoice.CInvoiceVoucher     = oiCInvoiceVoucher.