project QadFinancials > class BDInvoice > method DefaultValuesVoucher

Description

Default the voucher


Parameters


icNewJournalCodeinputcharacterNew Journal Code
icOldJournalCodeinputcharacterOld Journal Code : journal code for which i must release the number
iiNewPeriodYearinputintegerYear of the accounting period for which a new number must be found
iiOldPeriodYearinputintegerYear of accounting period for which the number must be released
iiOldDInvoiceVoucherinputintegerVoucher number that must be released
oiNewDInvoiceVoucheroutputintegerNew Voucher
icRowIdinputcharacterRowId of Debtor Invoice
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bdinvoice.p)

if (icNewJournalCode = "":U or icNewJournalCode = ? or
    iiNewPeriodYear  = 0    or iiNewPeriodYear  = ?) and
    iiOldDInvoiceVoucher = 0
then return.

if icNewJournalCode      = icOldJournalCode and
   iiNewPeriodYear       = iiOldPeriodYear and
   iiOldDInvoiceVoucher <> 0
then do:
    assign oiNewDInvoiceVoucher = iiOldDInvoiceVoucher.
    return.
end. /* if icNewJournalCode = icOldJournalCode */

find first tDInvoice where
           tDInvoice.tc_Rowid = icRowId
           no-error.
if not available tDInvoice
then do:
    <M-5 run SetMessage
       (input  #T-6'The specified customer invoice is not defined in the system.':255(69263)t-6# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'D':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8012':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 */

/* ================================================================= */
/* Reserve a number for this sheet.                                  */
/* This number will be released again by housekeeping if the         */
/* transaction was not committed by then.                            */
/* ================================================================= */

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

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

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


if vlCCNIsConsecutNr      = TRUE and
   vlJournalIsOperational = FALSE
then do:
    assign oiNewDInvoiceVoucher = viCCNTempDInvNbr
           viCCNTempDInvNbr     = viCCNTempDInvNbr + 1.
end. /* if vlCCNIsConsecutNr = TRUE */
else do:
    assign vhFcComponent = ?.
    <M-3 run GetNumber
       (input  viCompanyId (iiCompanyId), 
        input  iiNewPeriodYear (iiNumbrYear), 
        input  icNewJournalCode (icNumbrType), 
        output oiNewDInvoiceVoucher (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 oiReturnStatus < 0
    then return.
end. /* NOT if vlCCNIsConsecutNr = TRUE */
assign tDInvoice.DInvoicePostingYear = iiNewPeriodYear
       tDInvoice.tcJournalCode       = icNewJournalCode
       tDInvoice.DInvoiceVoucher     = oiNewDInvoiceVoucher.

/* ================================================================= */
/* Release previously reserved number.                               */
/* ================================================================= */
if iiOldDInvoiceVoucher <> 0
then do:

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

    find first tqJournalBeginsForJEDefault where
               tqJournalBeginsForJEDefault.tcJournalCode     = icOldJournalCode     and
               tqJournalBeginsForJEDefault.tcJournalControl  = {&JOURNALCONTROL-LOGISTIC}
    no-lock no-error.
    
    if available tqJournalBeginsForJEDefault then
        assign vlJournalIsOperational = TRUE.
    else 
        assign vlJournalIsOperational = FALSE.

    assign vhFcComponent = ?.
    if vlCCNIsConsecutNr = FALSE or
       vlJournalIsOperational = TRUE
    then do:
        <M-4 run ReleaseNumber
           (input  viCompanyId (iiCompanyId), 
            input  iiOldPeriodYear (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 oiReturnStatus < 0
        then return.
    end. /* if vlCCNIsConsecutNr = FALSE */
end.     /* if iiOldDInvoiceVoucher <> 0 */