project QadFinancials > class BCInvoice > method InitialValues

Description

Add code here to initialize the calculated fields of a 'new' record (= a record that must be created in the application database) in a class temp-table.


Parameters


icTableNameinputcharacterName of the database table of which a record is created in the class temp-table.
oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bcinvoice.p)

<ANCESTOR-CODE>

case icTableName:

    when "CInvoice":U
    then do:
        assign vhFcComponent = ?.
        <M-8 run GetDefaultPeriodDate
           (input  ? (iiYearIn), 
            input  ? (iiPeriodIn), 
            input  today (itDateIn), 
            input  true (ilOpenForPurchase), 
            input  ? (ilOpenForSales), 
            input  ? (ilOpenForInventory), 
            output tCInvoice.CInvoicePostingYear (oiYear), 
            output tCInvoice.CInvoicePostingPeriod (oiPeriod), 
            output tCInvoice.CInvoicePostingDate (otPostingDate), 
            output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        assign tCInvoice.Company_ID                 = viCompanyId
               tCInvoice.CInvoiceDate               = tCInvoice.CInvoicePostingDate
               tCInvoice.CInvoiceTaxPointDate       = tCInvoice.CInvoicePostingDate
               tCInvoice.CInvoiceType               = {&INVOICETYPE-INVOICE}
               tCInvoice.CInvoiceAllocationStatus   = {&ALLOCSTATUS-NOALLOC}
               tCInvoice.CInvoiceIsOpen             = true
               tCInvoice.CInvoiceIsSelected         = false
               tCInvoice.tcLocalCurrencyCode        = vcCompanyLC
               tCInvoice.tcStatutoryCurrencyCode    = vcCompanyCC
               tCInvoice.CInvoiceIsLogisticMatching = false
               tCInvoice.CinvoiceRateScale          = 1
               tCInvoice.CInvoiceCirecClosingDate   = 12/31/9999
               tCInvoice.CInvoicePoDomain           = vcDomainCode
               tCInvoice.CInvoiceVatRateScale       = 1
               tCInvoice.CInvoiceCreationDate       = today
               tCInvoice.CInvoiceHoldAmountTC       = 0
               tCInvoice.CInvoiceIsTaxExcluded      = false.
        
        /* Own vat number, Transaction end country */
        <Q-7 run CompanyPropertyByBusinessRel (first) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
            output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty >
        find first tqCompanyPropertyByBusinessRel
                   no-error.
        if not available tqCompanyPropertyByBusinessRel
        then do:
            <Q-3 run CompanyPropertyByBusinessRel (first) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                input ?, (AddressType)
                output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty >
            find first tqCompanyPropertyByBusinessRel no-error.
        end.

        if available tqCompanyPropertyByBusinessRel
        then assign vlIsCompanyTaxInCityCI                 = tqCompanyPropertyByBusinessRel.tlAddressIsTaxInCity
                    tCInvoice.CInvoiceOwnVatNumber         = tqCompanyPropertyByBusinessRel.tcAddressTaxIDState
                    tCInvoice.tcOwnVatNumberCountryCode    = tqCompanyPropertyByBusinessRel.tcAddressCountryCode
                    tCInvoice.tcShipToBusinessRelationCode = tqCompanyPropertyByBusinessRel.tcBusinessRelationCode
                    tCInvoice.tcShipToAddressTypeCode      = tqCompanyPropertyByBusinessRel.tcAddressTypeCode
                    tCInvoice.tcShipToAddressStreet1       = tqCompanyPropertyByBusinessRel.tcAddressStreet1
                    tCInvoice.tcShipToAddressStreet2       = tqCompanyPropertyByBusinessRel.tcAddressStreet2
                    tCInvoice.tcShipToAddressStreet3       = tqCompanyPropertyByBusinessRel.tcAddressStreet3
                    tCInvoice.tcShipToAddressZip           = tqCompanyPropertyByBusinessRel.tcAddressZip
                    tCInvoice.tcShipToAddressCity          = tqCompanyPropertyByBusinessRel.tcAddressCity
                    tCInvoice.tcShipToAddressState         = tqCompanyPropertyByBusinessRel.tcStateCode
                    tCInvoice.tcShipToCountryCode          = tqCompanyPropertyByBusinessRel.tcAddressCountryCode
                    tCInvoice.tcShipToTaxZone              = tqCompanyPropertyByBusinessRel.tcTxzTaxZone
                    tCInvoice.tlShipToAddressIsTaxInCity   = tqCompanyPropertyByBusinessRel.tlAddressIsTaxInCity
                    tCInvoice.tlShipToCountryIsEUCountry   = tqCompanyPropertyByBusinessRel.tlAddressIsEUCountry
                    tCInvoice.tiShipToAddressId            = tqCompanyPropertyByBusinessRel.tiAddress_ID.
                    
        assign tCInvoice.tlDaybookOnInvoice = if vlPOCAllowUpdateDaybookOnInv = TRUE 
                                              then TRUE
                                              else FALSE.

        <M-10 run DefaultValuesOwnVatNumber
           (input  tqCompanyPropertyByBusinessRel.tlAddressIsEUCountry (ilShipToCountryIsEUCountry), 
            input  tqCompanyPropertyByBusinessRel.tcAddressTaxIDState (icShipToAddressTaxIdState), 
            input  tqCompanyPropertyByBusinessRel.tcAddressCountryCode (icShipToCountryCode), 
            output tCInvoice.CInvoiceOwnVatNumber (ocOwnVatNumber), 
            output tCInvoice.tcOwnVatNumberCountryCode (ocOwnVatCountryCode), 
            output tCInvoice.tcVatCurrencyCode (ocOwnVatCurrencyCode), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then return.


        assign tCInvoice.CInvoiceCreationDate = today.

        assign vhFcComponent = ?.
        <M-11 run GetNumber
           (input  viCompanyId (iiCompanyId), 
            input  9999 (iiNumbrYear), 
            input  {&SUPPLIERINVOICEREGNUMBER} (icNumbrType), 
            output tCInvoice.CInvoiceRegistrationNr (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.
                
        /* Default value for the tax excluded flag and CompExgRateUseAPInvoicetDate*/
        <Q-28 run CompanyPropertyForCInvoiceDef (all) (Read) (NoCache)
           (input tCInvoice.Company_ID, (CompanyId)
            output dataset tqCompanyPropertyForCInvoiceDef) in BCompanyProperty>
        find first tqCompanyPropertyForCInvoiceDef where
                   tqCompanyPropertyForCInvoiceDef.tiCompany_ID = tCInvoice.Company_ID
                   no-error.
        if available tqCompanyPropertyForCInvoiceDef
        then do:
            assign 
                tCInvoice.CInvoiceIsTaxExcluded = tqCompanyPropertyForCInvoiceDef.tlCompanyPropertyIsAPTaxExcluded
                vlCompanyPropertyIsAPUseInvDate = tqCompanyPropertyForCInvoiceDef.tlCompanyPropertyIsAPUseInvDate.
        end.
        else do:
            assign                 
                vlCompanyPropertyIsAPUseInvDate = false.
        end.
                        
        
        <M-12 run AddDetailLine
            (input  'CInvoicePO':U (icTable), 
             input  tCInvoice.tc_Rowid (icParentRowid), 
             output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then return.
     end.
    
    when "CInvoicePO":U
    then assign tCInvoicePO.CInvoicePOPoDomain = vcDomainCode.

    when "CInvoiceVat":U
    then do:
        assign tCInvoiceVat.tcVatInOut               = {&VATINOUT-INPUT}
               tCInvoiceVat.tcDomainCode             = vcDomainCode
               tCInvoiceVat.CInvoiceVatIsSuspDel     = false
               tCInvoiceVat.CInvoiceVatSequence      = 1
               tCInvoiceVat.CInvoiceVatUILinkedRowID = "0":U
               viHighCInvoiceVatUILinkedRowID        = -1.

        for each bCInvoiceVat where
                 bCInvoiceVat.tc_ParentRowid =  tCInvoice.tc_Rowid and
                 bCInvoiceVat.tc_Rowid       <> tCInvoiceVat.tc_Rowid :

            assign viCInvoiceVatUILinkedRowID = integer(bCInvoiceVat.CInvoiceVatUILinkedRowID) no-error.
            if error-status:error
            then do :
                assign oiReturnStatus = -3
                       vcMessage      = trim(#T-14'Internal error: unable to get the UI Linked Row ID.':255(999890340)T-14#).

                if error-status:num-messages > 0
                then assign vcMessage = vcMessage + chr(10) + 
                                        trim(substitute(#T-15'Detailed info: &1 (&2)':252(49824)T-15#,error-status:Get-Message(1),string(error-status:Get-Number(1)))).
                <M-13 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QadFin-9048':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                return.
            end. /* if error-status:error */
            if viHighCInvoiceVatUILinkedRowID < viCInvoiceVatUILinkedRowID
            then assign viHighCInvoiceVatUILinkedRowID = viCInvoiceVatUILinkedRowID.
        end.  /* end for each bCInvoiceVat */
        assign tCInvoiceVat.CInvoiceVatUILinkedRowID = string(viHighCInvoiceVatUILinkedRowID + 1).
   end. /* end CInvoiceVat */
   
   When "CInvoiceWHT":U 
   then assign tCInvoiceWHT.CInvoiceWHTIsOrigFromAPM = false.
   
end case.