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/bbusinessrelation.p)
<ANCESTOR-CODE>
if vlSysPropertyIsBusRelDomRes = ? and
(icTableName = "BusinessRelation":U or
icTableName = "Address":U)
then do:
<Q-73 run SystemPropertyByAll (all) (Read) (NoCache) (output dataset tqSystemPropertyByAll) in BSystemProperty >
find first tqSystemPropertyByAll
no-error.
if available tqSystemPropertyByAll and
tqSystemPropertyByAll.tlSysPropertyIsBusRelDomRes = true
then assign vlSysPropertyIsBusRelDomRes = true.
else assign vlSysPropertyIsBusRelDomRes = false.
end.
case icTableName:
when "BusinessRelation":U
then do:
/* ==================================== */
/* Get the language of the current user */
/* ==================================== */
<Q-1 run UsrByIdLoginIsActNameLng (first) (Read) (Cache)
(input viUsrId, (UsrId)
input ?, (UsrLogin)
input ?, (UsrIsActive)
input ?, (UsrName)
input ?, (LngId)
output dataset tqUsrByIdLoginIsActNameLng) in BUser >
find first tqUsrByIdLoginIsActNameLng where
tqUsrByIdLoginIsActNameLng.tiUsr_ID = viUsrId
no-error.
assign tBusinessRelation.Lng_ID = if available tqUsrByIdLoginIsActNameLng
then tqUsrByIdLoginIsActNameLng.tiDefaultLng_ID
else 0
tBusinessRelation.tcLngCode = if available tqUsrByIdLoginIsActNameLng
then tqUsrByIdLoginIsActNameLng.tcLngCode
else "us":U
tBusinessRelation.BusinessRelationIsActive = true
tBusinessRelation.BusinessRelationIsInterco = false
tBusinessRelation.BusinessRelationIsInComp = false
tBusinessRelation.BusinessRelationIsCompens = false
tBusinessRelation.BusinessRelationIsDomRestr = vlSysPropertyIsBusRelDomRes.
end.
when "VatNumber":U
then assign tVatNumber.VatNumberIsActive = true.
when "Address":U
then do:
/* ======================================================= */
/* Get the country from the company of the current session */
/* ======================================================= */
<Q-2 run CompanyPropertyByBusinessRel (first) (Read) (Cache)
(input viCompanyId, (CompanyId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty >
find first tqCompanyPropertyByBusinessRel where
tqCompanyPropertyByBusinessRel.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
no-error.
assign tAddress.AddressIsSendToPostal = false
tAddress.AddressIsTaxInCity = true
tAddress.Country_ID = if available tqCompanyPropertyByBusinessRel
then tqCompanyPropertyByBusinessRel.tiCountry_ID
else 0
tAddress.tcCountryCode = if available tqCompanyPropertyByBusinessRel
then tqCompanyPropertyByBusinessRel.tcAddressCountryCode
else "":U.
tAddress.tcCountryDescription = if available tqCompanyPropertyByBusinessRel
then tqCompanyPropertyByBusinessRel.tcCountryDescription
else "":U.
/*Assign default AddressFormat retrieved from Country*/
<Q-72 run CountryByCode (all) (Read) (NoCache)
(input tAddress.tcCountryCode, (CountryCode)
output dataset tqCountryByCode) in BCountry>
find first tqCountryByCode where
tqCountryByCode.tcCountryCode = tAddress.tcCountryCode
no-error.
if available tqCountryByCode
then assign tAddress.AddressFormat = tqCountryByCode.tiCountryFormat.
if vlSysPropertyIsBusRelDomRes
then do:
<Q-5 run MfgTaxControlByDomain (all) (Read) (Cache)
(input vcDomainCode, (DomainCode)
output dataset tqMfgTaxControlByDomain) in BMfgTaxControl >
find first tqMfgTaxControlByDomain where
tqMfgTaxControlByDomain.tctxc_domain = vcDomainCode
no-error.
if available tqMfgTaxControlByDomain
then assign tAddress.AddressIsTaxable = tqMfgTaxControlByDomain.tltxc_ar_taxexcl.
end.
/* The name and search name of the address records default to the name and search name of the business relation. */
/* get the related business relation record. */
/* use the rowid/parentrowid, since the BusinessRelation_ID of the address record is not filled yet */
find first tBusinessRelation where
tBusinessRelation.tc_Rowid = tAddress.tc_ParentRowid
no-error.
if available tBusinessRelation
then assign tAddress.AddressName = tBusinessRelation.BusinessRelationName1
tAddress.AddressSearchName = tBusinessRelation.BusinessRelationSearchName.
/* =========================================================================== */
/* If this is the first Address for the BusRel then set the type to HeadOffice */
/* =========================================================================== */
if not can-find (first bAddress where
bAddress.tc_ParentRowid = tAddress.tc_ParentRowid and
bAddress.tc_Rowid <> tAddress.tc_Rowid and
bAddress.tc_Status <> "D":U)
then assign tAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}.
end.
When "Contact":U
then do:
assign tContact.ContactGender = "MALE":U.
find first tAddress where
tAddress.tc_Rowid = tContact.tc_ParentRowid
no-error.
if available tAddress
then assign tContact.tcLngCode = tAddress.tcLngCode
tContact.Lng_ID = tAddress.Lng_ID.
end.
end case.