project QadFinancials > class BDInvoice > method DefaultValuesJournal


Parameters


icDInvoiceRowIdinputcharacterRow ID of customer invoice
bcJournalCodeinput-outputcharacter
iiDInvoicePostingYearinputinteger
icDInvoiceTypeinputcharacter
iiOldDInvoicePostingYearinputinteger
icOldJournalCodeinputcharacter
iiOldDInvoiceVoucherinputinteger
oiDInvoiceVoucheroutputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.DefaultValuesPostingDate
method BDInvoice.DefaultValuesPostingYear


program code (program3/bdinvoice.p)

if iiDInvoicePostingYear = iiOldDInvoicePostingYear and
   bcJournalCode         = icOldJournalCode            
then do:
    assign oiDInvoiceVoucher = iiOldDInvoiceVoucher.
    return.                                         
end. /* if iiDInvoicePostingYear = iiOldDInvoicePostingYear */

assign vcOriginalJournalCode = bcJournalCode.

find first tDInvoice where
           tDInvoice.tc_Rowid = icDInvoiceRowId
           no-error.
if not available tDInvoice
then do:
    <M-4 run SetMessage
       (input  #T-5'The specified customer invoice is not defined in the system.':255(69263)t-5# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'D':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8011':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    assign oiReturnStatus = -3.
    return.
end. /* if not available tDInvoice */

/* Determine the type of daybook to be used. */
<Q-8 run JournalBeginsForJEDefault (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input bcJournalCode, (JournalCode)
    input {&JOURNALCONTROL-LOGISTIC}, (JournalControl)
    input vcJournalTypeCode, (JournalTypeCode)
    output dataset tqJournalBeginsForJEDefault) in BJournal >

find first tqJournalBeginsForJEDefault where
           tqJournalBeginsForJEDefault.tcJournalCode     = bcJournalCode     and
           tqJournalBeginsForJEDefault.tcJournalTypeCode = vcJournalTypeCode and 
           tqJournalBeginsForJEDefault.tcJournalControl  = {&JOURNALCONTROL-LOGISTIC}
no-lock no-error.

if available tqJournalBeginsForJEDefault then
    assign vlJournalIsOperational = TRUE.
else 
    assign vlJournalIsOperational = FALSE.

if iiOldDInvoicePostingYear <> 0    and
   iiOldDInvoicePostingYear <> ?    and
   icOldJournalCode         <> "":U and
   icOldJournalCode         <> ?    and
   iiOldDInvoiceVoucher     <> 0    and
   iiOldDInvoiceVoucher     <> ?
then do:
    assign vhFcComponent = ?.
    if vlCCNIsConsecutNr      = FALSE  or
       vlJournalIsOperational = TRUE
    then do:
        <M-1 run ReleaseNumber
           (input  viCompanyId (iiCompanyId), 
            input  iiOldDInvoicePostingYear (iiNumbrYear), 
            input  icOldJournalCode (icNumbrType), 
            input  iiOldDInvoiceVoucher (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 viFcReturnSuper < 0
        then return.
    end. /* if vlCCNIsConsecutNr = FALSE */
end.     /* if iiOldDInvoicePostingYear <> 0 */

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

if bcJournalCode = "":U
then do:
    assign tDInvoice.tcJournalCode   = bcJournalCode
           tDInvoice.DInvoiceVoucher = 0.
    return.
end. /* if bcJournalCode = "":U */

if bcJournalCode <> icOldJournalCode
then do:
    assign vcJournalTypeCode = if icDInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
                               then {&JOURNALTYPE-DEBTORCREDITNOTECORRECT}
                               else
                               if icDInvoiceType = {&INVOICETYPE-CREDITNOTE}
                               then {&JOURNALTYPE-DEBTORCREDITNOTE}
                               else
                               if icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                               then {&JOURNALTYPE-DEBTORINVOICECORRECT}
                               else if icDInvoiceType = {&INVOICETYPE-FINANCECHARGE}
                                    then {&JOURNALTYPE-DEBTORFINANCECHARGE}
                               else if icDInvoiceType = {&INVOICETYPE-DEDUCTION}
                                    then {&JOURNALTYPE-DEDUCTION}
                                    else {&JOURNALTYPE-DEBTORINVOICE}.


    <Q-35 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 no-error.
    
    if not available tqJournalBeginsForJEDefault
    then do:
        assign bcJournalCode  = vcOriginalJournalCode
               oiReturnStatus = -4.
        return.
    end.
    else do:
        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 */
           if available tqJournalBeginsForJEDefault 
           then assign bcJournalCode = tqJournalBeginsForJEDefault.tcJournalCode.
           /* Ambiguous records will not be found and available will be false */
           else do:
               assign bcJournalCode  = vcOriginalJournalCode
                      oiReturnStatus = -4.
               return.                  
           end. /* NOT if available tqJournalBeginsForJEDefault      */
        end.    /* NOT if not available tqJournalBeginsForJEDefault  */
    end.        /* NOT if not available tqJournalBeginsForJEDefault  */
end.            /* if bcJournalCode <> icOldJournalCode              */


if iiDInvoicePostingYear <> 0 and iiDInvoicePostingYear <> ?
then do:
    assign vhFcComponent = ?.
    /* Get the voucher number. */
    if vlCCNIsConsecutNr      = TRUE and 
       vlJournalIsOperational = FALSE
    then do:
        assign oiDInvoiceVoucher = viCCNTempDInvNbr
               viCCNTempDInvNbr  = viCCNTempDInvNbr + 1.
    end. /* if vlCCNIsConsecutNr */
    else do:
        <M-2 run GetNumber
           (input  viCompanyId (iiCompanyId), 
            input  iiDInvoicePostingYear (iiNumbrYear), 
            input  bcJournalCode (icNumbrType), 
            output oiDInvoiceVoucher (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. /* NOT if vlCCNIsConsecutNr */
end.     /* if iiDInvoicePostingYear <> 0 and iiDInvoicePostingYear <> ? */
assign tDInvoice.DInvoicePostingYear = iiDInvoicePostingYear
       tDInvoice.tcJournalCode       = bcJournalCode
       tDInvoice.DInvoiceVoucher     = oiDInvoiceVoucher.