project QadFinancials > class BDInvoice > method DefaultValuesDAJournal


Parameters


icDInvoiceRowIdinputcharacterRow ID of customer invoice
bcDAJournalCodeinput-outputcharacter
iiDInvoicePostingYearinputinteger
iiOldDinvoicePostingYearinputinteger
icOldDAJournalCodeinputcharacter
iiOldDAVoucherinputinteger
oiDAVoucheroutputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.DefaultValuesLinkedInvoice
method BDInvoice.DefaultValuesPostingDate
method BDInvoice.DefaultValuesPostingYear


program code (program3/bdinvoice.p)

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

if iiOldDInvoicePostingYear <> 0    and
   iiOldDInvoicePostingYear <> ?    and
   icOldDAJournalCode       <> "":U and
   icOldDAJournalCode       <> ?    and
   iiOldDAVoucher           <> 0    and
   iiOldDAVoucher           <> ?
then do:
    assign vhFcComponent = ?.
    <M-1 run ReleaseNumber
       (input  viCompanyId (iiCompanyId), 
        input  iiOldDInvoicePostingYear (iiNumbrYear), 
        input  icOldDAJournalCode (icNumbrType), 
        input  iiOldDAVoucher (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 bcDAJournalCode = ?
then assign bcDAJournalCode = "":U.

if bcDAJournalCode = "":U
then do:
    assign tDInvoice.tcDAJournalCode = bcDAJournalCode
           tDInvoice.tiDAVoucher     = 0.
    return.
end.

if bcDAJournalCode <> icOldDAJournalCode
then do:

    <Q-5 run JournalBeginsForJEDefault (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input bcDAJournalCode, (JournalCode)
        input {&JOURNALCONTROL-FINANCIAL}, (JournalControl)
        input {&JOURNALTYPE-DEBTORADJUSTMENT}, (JournalTypeCode)
        output dataset tqJournalBeginsForJEDefault) in BJournal >

    find first tqJournalBeginsForJEDefault no-error.
    
    if not available tqJournalBeginsForJEDefault
    then do:
        assign oiReturnStatus = -4.
        return.
    end.
    else do:
        find first tqJournalBeginsForJEDefault
             where tqJournalBeginsForJEDefault.tcJournalCode = bcDAJournalCode no-error.
        if not available tqJournalBeginsForJEDefault
           then do:
               find tqJournalBeginsForJEDefault
                    where tqJournalBeginsForJEDefault.tcJournalCode BEGINS bcDAJournalCode no-error.
                /* if there's only one record */
               if available tqJournalBeginsForJEDefault 
               then do:
                    assign bcDAJournalCode = tqJournalBeginsForJEDefault.tcJournalCode.
               end.
               /* Ambiguous records will not be found and available will be false */
               else do:
                    assign bcDAJournalCode = vcOriginalDAJournalCode
                           oiReturnStatus  = -4.
                    return.                  
               end. 
         end.
    end.
end.

if iiDInvoicePostingYear <> 0 and
   iiDInvoicePostingYear <> ?
then do:
    assign vhFcComponent = ?.

    <M-3 run GetNumber
       (input  viCompanyId (iiCompanyId), 
        input  iiDInvoicePostingYear (iiNumbrYear), 
        input  bcDAJournalCode (icNumbrType), 
        output oiDAVoucher (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.

    assign tDInvoice.tiLinkedPeriodYear      = iiDInvoicePostingYear
           tDInvoice.tcLinkedJournalCode     = bcDAJournalCode
           tDInvoice.tiLinkedDInvoiceVoucher = oiDAVoucher
           tDInvoice.tcDAJournalCode         = bcDAJournalCode
           tDInvoice.tiDAVoucher             = oiDAVoucher.
end.