| tApiBusinessRelation | input-output | temp-table | This temp table contains the necessary business relation information - required to update the address information contact in tApiAddress. |
| tApiAddress | input-output | temp-table | Contains the address(s) that you wish to create/update for the business relations specified in 'tApiBusinessRelation'. tApiAddress.tc_parentrowid must have the tc_rowid of its parent business relation. (tapibusinessrelation.tc_rowid) |
| tApiContact | input-output | temp-table | This temp table contains any contact information assoicated with the address that you wish to update/create in the database. tApiContact.tc_parentrowid must have the tc_rowid of its parent address. (tapiaddress.tc_rowid) |
| oiReturnStatus | output | integer | Return status of the method. |
QadFinancials
<I-67 {bFcStartAndOpenInstance
&CLASS = "PGTM"}>
MAIN_BLOCK:
do on error undo, leave MAIN_BLOCK:
assign oiReturnStatus = -98
viLocalReturnStatus = 0.
/* Build a list of all id's of the BusinessRelation and Addresses to load from the database */
assign vcBusinessRelationList = "":U
vcAddressList = "":U
viCurrentAddressID = 0.
for each tApiBusinessRelation:
/* Normalize key values */
if tApiBusinessRelation.BusinessRelation_ID = 0 then assign tApiBusinessRelation.BusinessRelation_ID = ?.
if tApiBusinessRelation.BusinessRelationCode = "":U then assign tApiBusinessRelation.BusinessRelationCode = ?.
/* Get both business relation ID and Code if needed */
if tApiBusinessRelation.BusinessRelation_ID = ? or
tApiBusinessRelation.BusinessRelationCode = ?
then do:
/* At least ID or Code have to be supplied */
if tApiBusinessRelation.BusinessRelation_ID = ? and
tApiBusinessRelation.BusinessRelationCode = ?
then do:
assign vcMessageText = #T-6'Business relation is not defined in the input data file tApiBusinessRelation.':255(761366534)T-6#.
<M-39 run SetMessage
(input vcMessageText (icMessage),
input tApiBusinessRelation.BusinessRelationCode (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-66028':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
assign viLocalReturnStatus = -3.
leave MAIN_BLOCK.
end.
<Q-21 run BusinessRelationPrim (all) (Read) (Cache)
(input tApiBusinessRelation.BusinessRelation_ID, (BusinessRelationId)
input tApiBusinessRelation.BusinessRelationCode, (BusinessRelationCode)
output dataset tqBusinessRelationPrim) in BBusinessRelation >
find first tqBusinessRelationPrim where
(tqBusinessRelationPrim.tiBusinessRelation_ID = tApiBusinessRelation.BusinessRelation_ID or tApiBusinessRelation.BusinessRelation_ID = ?) and
(tqBusinessRelationPrim.tcBusinessRelationCode = tApiBusinessRelation.BusinessRelationCode or tApiBusinessRelation.BusinessRelationCode = ?)
no-error.
if not available tqBusinessRelationPrim
then do:
assign vcMessageText = #T-69'$1 is not a valid Business Relation Code':50(999890460)T-69#.
<M-40 run SetMessage
(input vcMessageText (icMessage),
input tApiBusinessRelation.BusinessRelationCode (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-430650':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
assign viLocalReturnStatus = -3.
leave MAIN_BLOCK.
end.
assign tApiBusinessRelation.BusinessRelationCode = tqBusinessRelationPrim.tcBusinessRelationCode
tApiBusinessRelation.BusinessRelation_ID = tqBusinessRelationPrim.tiBusinessRelation_ID.
end. /* if tApiBusinessRelation.BusinessRelation_ID = ? or */
/* Make list of all business relation to load */
assign vcBusinessRelationList = if vcBusinessRelationList = "":U
then string(tApiBusinessRelation.BusinessRelation_ID)
else vcBusinessRelationList + chr(4) + string(tApiBusinessRelation.BusinessRelation_ID).
/* ========================================================================================== */
/* Make also list of all addresses to load - this is done because of performance improvements */
/* ========================================================================================== */
for each tApiAddress where
tApiAddress.tc_ParentRowid = tApiBusinessRelation.tc_Rowid:
assign viCurrentAddressID = 0.
if tApiAddress.Address_ID = 0 then assign tApiAddress.Address_ID = ?.
/* if we cannot match the address by key fields then if the Address_ID
is set assume we are updating the existing address */
if tApiAddress.Address_ID <> ? and tApiAddress.tc_Status <> "D"
then assign
viCurrentAddressID = tApiAddress.Address_ID
tApiAddress.Address_ID = ?.
/* validate - we always need the addresstype */
if (tApiAddress.tcAddressTypeCode = ? or tApiAddress.tcAddressTypeCode = '') and
tApiAddress.tc_Status <> "D"
then do :
assign vcMessageText = trim (#T-62'Invalid address type found: $1.':250(3308)T-62#).
<M-51 run SetMessage
(input vcMessageText (icMessage),
input tApiAddress.tcAddressTypeCode (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-114080':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
assign viLocalReturnStatus = -3.
leave MAIN_BLOCK.
end.
/* Try to find existing address in the database and save it in tApiAddress.Address_ID */
/* - use the address type in case of HO Reminder and remmittance */
/* - use AddressLogicKeyString when available */
/* - use address fields */
if tApiAddress.Address_ID = ? and
(tApiAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE} or
tApiAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-REMINDER} or
tApiAddress.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-REMITTANCE})
then do :
/* For HO, Reminder and Remittance there can be only one */
<Q-7 run AddressForIntegration (all) (Read) (NoCache)
(input tApiBusinessRelation.BusinessRelation_ID, (BusinessRelation_ID)
input ?, (Address_ID)
input '':U, (AddressLogicKeyString)
input tApiAddress.tcAddressTypeCode, (AddressTypeCode)
input '':U, (AddressStreet1)
input '':U, (AddressStreet2)
input '':U, (AddressStreet3)
input '':U, (AddressZip)
input '':U, (AddressCity)
output dataset tqAddressForIntegration) in BBusinessRelation>
find tqAddressForIntegration where
tqAddressForIntegration.tiBusinessRelation_ID = tApiBusinessRelation.BusinessRelation_ID and
tqAddressForIntegration.tcAddressTypeCode = tApiAddress.tcAddressTypeCode
no-error.
if available tqAddressForIntegration
then assign tApiAddress.Address_ID = tqAddressForIntegration.tiAddress_ID.
end.
if tApiAddress.Address_ID = ? and
tApiAddress.AddressLogicKeyString <> ? and
tApiAddress.AddressLogicKeyString <> "":U
then do:
/* Use AddressLogicKeyString */
<Q-93 run AddressForIntegration (all) (Read) (NoCache)
(input tApiBusinessRelation.BusinessRelation_ID, (BusinessRelation_ID)
input tApiAddress.Address_ID, (Address_ID)
input tApiAddress.AddressLogicKeyString, (AddressLogicKeyString)
input tApiAddress.tcAddressTypeCode, (AddressTypeCode)
input '':U, (AddressStreet1)
input '':U, (AddressStreet2)
input '':U, (AddressStreet3)
input '':U, (AddressZip)
input '':U, (AddressCity)
output dataset tqAddressForIntegration) in BBusinessRelation>
find tqAddressForIntegration where
tqAddressForIntegration.tiBusinessRelation_ID = tApiBusinessRelation.BusinessRelation_ID and
tqAddressForIntegration.tcAddressLogicKeyString = tApiAddress.AddressLogicKeyString and
tqAddressForIntegration.tcAddressTypeCode = tApiAddress.tcAddressTypeCode
no-error.
if available tqAddressForIntegration
then assign tApiAddress.Address_ID = tqAddressForIntegration.tiAddress_ID.
end. /* if tApiAddress.Address_ID = ? and tApiAddress.AddressLogicKeyString <> ? and */
if tApiAddress.Address_ID = ?
then do:
/* validate - all of the key fields should be specified - it can not be ? */
if tApiAddress.AddressStreet1 = ? or
tApiAddress.AddressStreet2 = ? or
tApiAddress.AddressStreet3 = ? or
tApiAddress.AddressZip = ? or
tApiAddress.AddressCity = ?
then do :
assign vcMessageText = #T-53'You have to specify the full key of the address you want to select.':255(837023272)T-53#.
<M-5 run SetMessage
(input vcMessageText (icMessage),
input ? (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-204462':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
assign viLocalReturnStatus = -3.
leave MAIN_BLOCK.
end.
/* FINS-3210 */
/* We need to keep the blank value in the where clause */
assign vcInputAddressStreet1 = if tApiAddress.AddressStreet1 = '' then '-999999' else tApiAddress.AddressStreet1
vcInputAddressStreet2 = if tApiAddress.AddressStreet2 = '' then '-999999' else tApiAddress.AddressStreet2
vcInputAddressStreet3 = if tApiAddress.AddressStreet3 = '' then '-999999' else tApiAddress.AddressStreet3
vcInputAddressZip = if tApiAddress.AddressZip = '' then '-999999' else tApiAddress.AddressZip
vcInputAddressCity = if tApiAddress.AddressCity = '' then '-999999' else tApiAddress.AddressCity.
<Q-85 run AddressForIntegration (all) (Read) (NoCache)
(input tApiBusinessRelation.BusinessRelation_ID, (BusinessRelation_ID)
input ?, (Address_ID)
input '':U, (AddressLogicKeyString)
input tApiAddress.tcAddressTypeCode, (AddressTypeCode)
input vcInputAddressStreet1, (AddressStreet1)
input vcInputAddressStreet2, (AddressStreet2)
input vcInputAddressStreet3, (AddressStreet3)
input vcInputAddressZip, (AddressZip)
input vcInputAddressCity, (AddressCity)
output dataset tqAddressForIntegration) in BBusinessRelation>
find tqAddressForIntegration where
tqAddressForIntegration.tiBusinessRelation_ID = tApiBusinessRelation.BusinessRelation_ID and
tqAddressForIntegration.tcAddressStreet1 = tApiAddress.AddressStreet1 and
tqAddressForIntegration.tcAddressStreet2 = tApiAddress.AddressStreet2 and
tqAddressForIntegration.tcAddressStreet3 = tApiAddress.AddressStreet3 and
tqAddressForIntegration.tcAddressZip = tApiAddress.AddressZip and
tqAddressForIntegration.tcAddressCity = tApiAddress.AddressCity and
tqAddressForIntegration.tcAddressTypeCode = tApiAddress.tcAddressTypeCode
no-error.
if available tqAddressForIntegration
then assign tApiAddress.Address_ID = tqAddressForIntegration.tiAddress_ID.
end. /* if tApiAddress.Address_ID = ? and tApiAddress.AddressCity <> ? */
/* cannot find the address so assume we are updating the current address */
if tApiAddress.Address_ID = ? and viCurrentAddressID <> 0
then do:
assign tApiAddress.Address_ID = viCurrentAddressID.
end.
/* Make list of all addresses to load */
if tApiAddress.Address_ID <> ? and
tApiAddress.Address_ID <> 0
then assign vcAddressList = if vcAddressList = "":U
then string(tApiAddress.Address_ID)
else vcAddressList + ',' + string(tApiAddress.Address_ID).
end. /* for each tApiAddress where */
end. /* for each tApiBusinessRelation: */
/* if no business relations are to be updated then return */
if vcBusinessRelationList = "":U
then do:
assign vcMessageText = #T-28'No Business Relation data available':255(999890621)T-28#.
<M-27 run SetMessage
(input vcMessageText (icMessage),
input tApiBusinessRelation.BusinessRelationCode (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-9148':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
assign viLocalReturnStatus = -1.
leave MAIN_BLOCK.
end.
/* ================================================================================= *
* Load the business relation record *
* Because of the performance, we will load only those address records which will be *
* changed or deleted *
* ================================================================================= */
if vcAddressList = ? or
vcAddressList = "":U
then /* We are creating just new addresses -> no address to be loaded */
assign vcDataLoadAddressExtraFilter = "Address.Address_ID = -99999999".
else do:
assign vcDataLoadAddressExtraFilter = "(":U.
do viCounter = 1 to num-entries(vcAddressList):
if viCounter > 1 then assign vcDataLoadAddressExtraFilter = vcDataLoadAddressExtraFilter + " OR ":U.
assign vcDataLoadAddressExtraFilter = vcDataLoadAddressExtraFilter + "Address.Address_ID = " + entry(viCounter, vcAddressList).
end.
assign vcDataLoadAddressExtraFilter = vcDataLoadAddressExtraFilter + ")":U.
end.
<M-17 run DataLoad
(input '' (icRowids),
input vcBusinessRelationList (icPkeys),
input '' (icObjectIds),
input '' (icFreeform),
input false (ilKeepPrevious),
output viFcreturnsuper (oiReturnStatus)) in BBusinessRelation>
assign vcDataLoadAddressExtraFilter = "":U.
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
/* ================================================================================= *
* Update instance data *
* ================================================================================= */
for each tApiBusinessRelation:
/* Get business relation data */
find first tBusinessRelation where
tBusinessRelation.BusinessRelationCode = tApiBusinessRelation.BusinessRelationCode
no-error.
if not available tBusinessRelation
then do:
assign vcMessageText = #T-30'No Business Relation data available':255(999890621)T-30#.
<M-29 run SetMessage
(input vcMessageText (icMessage),
input tApiBusinessRelation.BusinessRelationCode (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-9149':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
assign viLocalReturnStatus = -1.
leave MAIN_BLOCK.
end.
/* Go through the addresses passed in */
for each tApiAddress where
tApiAddress.tc_ParentRowid = tApiBusinessRelation.tc_Rowid:
assign vcTaxZoneCode = "":U.
if tApiAddress.tcCountyCode = ?
then assign tApiAddress.tcCountyCode = "":U.
if tApiAddress.TxzTaxZone = "":U or
tApiAddress.TxzTaxZone = ?
then do:
<M-88 run GetTaxZoneByParam
(input tApiAddress.tcCountryCode (icCountryCode),
input tApiAddress.tcStateCode (icStateCode),
input tApiAddress.tcCountyCode (icCountyCode),
input tApiAddress.AddressCity (icAddressCity),
input tApiAddress.AddressZip (icAddressZip),
output vcTaxZoneCode (ocTaxZoneCode),
output viFcReturnSuper (oiReturnStatus)) in PGTM>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave MAIN_BLOCK.
assign tApiAddress.TxzTaxZone = vcTaxZoneCode.
end. /* if tApiAddress.TxzTaxZone = "":U or */
/* Check to see if the address exists already - try first with address id or else with unique keys */
find tAddress where
tAddress.tc_ParentRowid = tBusinessRelation.tc_Rowid and
tAddress.Address_ID = tApiAddress.Address_ID
no-error.
/* if we have a tAddress record it means that we are doing an update */
if available tAddress
then do:
/* if we are deleting this record then delete it otherwise update the record */
if tApiAddress.tc_Status = "D":U
then assign tAddress.tc_status = "D":U.
else do:
/* Check if anything has changed. */
buffer-compare tApiAddress except
AddressLogicKeyString
Address_ID
BusinessRelation_ID
LastModifiedDate
LastModifiedTime
LastModifiedUser
tc_Rowid
tc_ParentRowid
tc_Status
to tAddress save vlBufferCompareResult.
if vlBufferCompareResult = true
then next.
assign tAddress.tc_Status = "C":U.
end.
end. /* if available tAddress */
else do:
/* no address record exists so we need to create one */
<M-18 run AddDetailLine
(input 'Address':U (icTable),
input tBusinessRelation.tc_rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
end. /* not if available tAddress */
if tAddress.tc_status <> "D":U
then buffer-copy tApiAddress except
AddressLogicKeyString
Address_ID
BusinessRelation_ID
LastModifiedDate
LastModifiedTime
LastModifiedUser
tc_Rowid
tc_ParentRowid
tc_status
to tAddress.
/* Store the address id in the api table */
assign tApiAddress.Address_Id = tAddress.Address_ID
tApiAddress.BusinessRelation_ID = tAddress.BusinessRelation_ID.
if tAddress.tc_status <> "D":U
then do:
/* process the contact information */
for each tApiContact where
tApiContact.tc_ParentRowid = tApiAddress.tc_Rowid:
find tContact where
tContact.tc_ParentRowid = tAddress.tc_Rowid and
tContact.ContactName = tApiContact.ContactName
no-error.
if not available tContact
then find tContact where
tContact.tc_ParentRowid = tAddress.tc_Rowid and
tContact.Contact_ID = tApiContact.Contact_ID
no-error.
/* ================================= */
/* Check for Create / Update */
/* ================================= */
if available tContact
then do:
buffer-compare tApiContact except
Contact_ID
Address_ID
LastModifiedDate
LastModifiedTime
LastModifiedUser
tc_Rowid
tc_ParentRowid
tc_status
to tContact save vlBufferCompareResult.
if vlBufferCompareResult = true
then next.
assign tContact.tc_Status = "C":U.
end. /* if available tContact */
else do:
<M-19 run AddDetailLine
(input 'Contact':U (icTable),
input tAddress.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
end. /* NOY if available tContact */
buffer-copy tApiContact except
Contact_ID
Address_ID
LastModifiedDate
LastModifiedTime
LastModifiedUser
tc_Rowid
tc_ParentRowid
tc_Status
to tContact.
assign tApiContact.Contact_ID = tContact.Contact_ID.
end. /* for each tApiContact where ... */
end. /* End tAddress.tc_stutus = "D" */
end. /* end for each tApiAddress */
end. /* end for each businessrelation */
/* Validate the business relation componenet */
<M-15 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
/* save the componenet */
<M-16 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
end. /* of MAIN_BLOCK */
<I-46 {tFcCloseAndStopInstance
&CLASS = "PGTM"}>
/* ======================================================================== *
* Error handling *
* ======================================================================== */
assign oiReturnStatus = viLocalReturnStatus.