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
icTableName | input | character | Name of the database table of which a record is created in the class temp-table. |
oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/bdinvoice.p)
<ANCESTOR-CODE>
case icTableName:
when "DInvoice":U
then do:
/* Get All periods that cover itDateIn using Start/End date */
<Q-73 run PeriodByStartEndDate (all) (Read) (Cache)
(input viCompanyId, (CompanyId)
input today, (Date)
output dataset tqPeriodByStartEndDate) in BPeriod>
/* Check if the "Normal" Period is OK */
find first tqPeriodByStartEndDate where
tqPeriodByStartEndDate.tiCompany_ID = viCompanyId and
tqPeriodByStartEndDate.tcPeriodTypeCode = {&PERIODTYPECODE-NORMAL} and
tqPeriodByStartEndDate.tlPeriodIsPostingGLAllowed = true and
tqPeriodByStartEndDate.tlPeriodIsPostingSalesAllow = true and
tqPeriodByStartEndDate.ttPeriodStartDate <= today and
tqPeriodByStartEndDate.ttPeriodEndDate >= today
no-error.
if available tqPeriodByStartEndDate
then assign tDInvoice.DInvoicePostingYear = tqPeriodByStartEndDate.tiPeriodYear
tDInvoice.DInvoicePostingPeriod = tqPeriodByStartEndDate.tiPeriodPeriod
tDInvoice.DInvoicePostingDate = today.
else do:
assign vhFcComponent = ?.
<M-6 run GetDefaultPeriodDate (input ? (iiYearIn),
input ? (iiPeriodIn),
input today (itDateIn),
input ? (ilOpenForPurchase),
input true (ilOpenForSales),
input ? (ilOpenForInventory),
output tDInvoice.DInvoicePostingYear (oiYear),
output tDInvoice.DInvoicePostingPeriod (oiPeriod),
output tDInvoice.DInvoicePostingDate (otPostingDate),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
end.
assign tDInvoice.Company_ID = viCompanyId
tDInvoice.DInvoiceDate = tDInvoice.DInvoicePostingDate
tDInvoice.DInvoiceTaxPointDate = tDInvoice.DInvoicePostingDate
tDInvoice.DInvoiceIsTaxExcluded = false
tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE}
tDInvoice.DInvoiceIsOpen = true
tDInvoice.DInvoiceIsSelected = false
tDInvoice.DInvoiceIsPaymentAllowed = false
tDInvoice.tcLocalCurrencyCode = vcCompanyLC
tDInvoice.DInvoiceRateScale = 1
tDInvoice.DInvoiceVatExchangeRate = 1
tDInvoice.DInvoiceVatRateScale = 1.
/* default own vat number, transaction end country */
<Q-5 run CompanyPropertyByBusinessRel (first) (Read) (Cache)
(input viCompanyId, (CompanyId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty>
find first tqCompanyPropertyByBusinessRel no-error.
if not available tqCompanyPropertyByBusinessRel
then do:
<Q-4 run CompanyPropertyByBusinessRel (first) (Read) (Cache)
(input viCompanyId, (CompanyId)
input ?, (AddressType)
output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty>
find first tqCompanyPropertyByBusinessRel no-error.
end.
if available tqCompanyPropertyByBusinessRel
then assign vcCompanyAVRCode = tqCompanyPropertyByBusinessRel.tcBusinessRelationAVRCode
vlIsCompanyTaxInCity = tqCompanyPropertyByBusinessRel.tlAddressIsTaxInCity
tDInvoice.DInvoiceOwnVatNumber = tqCompanyPropertyByBusinessRel.tcAddressTaxIDState
tDInvoice.tcOwnVatNumberCountryCode = tqCompanyPropertyByBusinessRel.tcAddressCountryCode
vlTransactionStartIsEUCountry = tqCompanyPropertyByBusinessRel.tlAddressIsEUCountry
vcCompanyTxzTaxZone = tqCompanyPropertyByBusinessRel.tcTxzTaxZone
tDInvoice.tcShipFromBusinessRelationCode = tqCompanyPropertyByBusinessRel.tcBusinessRelationCode
tDInvoice.tcShipFromAddressTypeCode = tqCompanyPropertyByBusinessRel.tcAddressTypeCode
tDInvoice.tcShipFromAddressStreet1 = tqCompanyPropertyByBusinessRel.tcAddressStreet1
tDInvoice.tcShipFromAddressStreet2 = tqCompanyPropertyByBusinessRel.tcAddressStreet2
tDInvoice.tcShipFromAddressStreet3 = tqCompanyPropertyByBusinessRel.tcAddressStreet3
tDInvoice.tcShipFromAddressZip = tqCompanyPropertyByBusinessRel.tcAddressZip
tDInvoice.tcShipFromAddressCity = tqCompanyPropertyByBusinessRel.tcAddressCity
tDInvoice.tcShipFromAddressState = tqCompanyPropertyByBusinessRel.tcStateCode
tDInvoice.tcShipFromCountryCode = tqCompanyPropertyByBusinessRel.tcAddressCountryCode
tDInvoice.tcShipFromTaxIdState = tqCompanyPropertyByBusinessRel.tcAddressTaxIDState
tDInvoice.tlShipFromCountryIsEUCountry = tqCompanyPropertyByBusinessRel.tlAddressIsEUCountry
tDInvoice.tcShipFromTaxZone = tqCompanyPropertyByBusinessRel.tcTxzTaxZone
tDInvoice.tiShipFromAddressId = tqCompanyPropertyByBusinessRel.tiAddress_ID
tDInvoice.tcVatCurrencyCode = tqCompanyPropertyByBusinessRel.tcCurrencyCode
vlCompanyPropertyIsARUseTaxDate = tqCompanyPropertyByBusinessRel.tlCompanyPropertyIsARUseTaxDate.
<Q-7 run MfgTaxControlByDomain (all) (Read) (Cache)
(input vcDomainCode, (DomainCode)
output dataset tqMfgTaxControlByDomain) in BMfgTaxControl>
find first tqMfgTaxControlByDomain where
tqMfgTaxControlByDomain.tctxc_domain = vcDomainCode
no-lock no-error.
if available tqMfgTaxControlByDomain
then assign tDInvoice.DInvoiceIsTaxExcluded = tqMfgTaxControlByDomain.tltxc_ar_taxexcl.
end. /* when "DInvoice":U */
when "DInvoiceVat":U
then do:
assign tDInvoiceVat.tcVatInOut = {&VATINOUT-OUTPUT}
tDInvoiceVat.tcDomainCode = vcDomainCode
tDInvoiceVat.DInvoiceVatIsSuspDel = false
tDInvoiceVat.DInvoiceVatSequence = 1
tDInvoiceVat.DInvoiceVatUILinkedRowID = "0":U
viHighDInvoiceVatUILinkedRowID = -1.
for each bDInvoiceVat where
bDInvoiceVat.tc_ParentRowid = tDInvoice.tc_Rowid and
bDInvoiceVat.tc_Rowid <> tDInvoiceVat.tc_Rowid :
assign viDInvoiceVatUILinkedRowID = integer(bDInvoiceVat.DInvoiceVatUILinkedRowID) no-error.
if error-status:error
then do :
assign oiReturnStatus = -3
vcMessage = trim(#T-8'Internal error: unable to get the UI Linked Row ID.':255(999890340)T-8#).
if error-status:num-messages > 0
then assign vcMessage = vcMessage + chr(10) +
trim(substitute(#T-9'Detailed info: &1 (&2)':252(49824)T-9#,error-status:Get-Message(1),string(error-status:Get-Number(1)))).
<M-10 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-9049':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end. /* if error-status:error */
if viHighDInvoiceVatUILinkedRowID < viDInvoiceVatUILinkedRowID
then assign viHighDInvoiceVatUILinkedRowID = viDInvoiceVatUILinkedRowID.
end. /* end for each bDInvoiceVat */
assign tDInvoiceVat.DInvoiceVatUILinkedRowID = string(viHighDInvoiceVatUILinkedRowID + 1).
end. /* end DInvoiceVat */
end case.