Description
With this method a Businessrelation can be added, modified or deleted.
Process the detaillines of a business-relation:
Address
Contact
VatNumber
Parameters
icAction | input | character | Action |
bcLstReturn | input-output | character | ocLstReturn |
bcLstPrimKey | input-output | character | ocLstPrimKey |
bcLstRowid | input-output | character | ocLstRowid |
blSaveAsDraft | input-output | logical | Save As Draft |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bbusinessrelation.p)
/* ================================================= */
/* Go through all VATNUMBERS of the BusinessRelation */
/* ================================================= */
for each tApiVatNumber where
tApiVatNumber.tc_ParentRowid = tApiBusinessRelation.tc_Rowid
by tApiVatNumber.tc_Rowid:
/* ==================================== */
/* Find the appropriate exsiting record */
/* ==================================== */
find tVatNumber where
tVatNumber.tc_ParentRowid = tBusinessRelation.tc_Rowid and
tVatNumber.VatNumberIdentity = tApiVatNumber.VatNumberIdentity and
tVatNumber.tcIdentityCountryCode = tApiVatNumber.tcIdentityCountryCode
no-error.
if not available tVatNumber
then find tVatNumber where
tVatNumber.tc_ParentRowid = tBusinessRelation.tc_Rowid and
tVatNumber.VatNumber_ID = tApiVatNumber.VatNumber_ID
no-error.
/* ================================= */
/* Check for Create / Update */
/* ================================= */
if available tVatNumber
then do:
assign tVatNumber.tc_Status = "":U.
buffer-compare tApiVatNumber except
VatNumber_ID
BusinessRelation_ID
tc_Rowid
tc_ParentRowid
tc_status
to tVatNumber save vlBufferCompareResult.
if vlBufferCompareResult = true
then next.
assign tVatNumber.tc_Status = "C":U.
end. /* if available tVatNumber */
else do:
<M-8 run AddDetailLine (input 'VatNumber':U (icTable),
input tBusinessRelation.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
end. /* NOT if available tVatNumber */
buffer-copy tApiVatNumber except
VatNumber_ID
BusinessRelation_ID
tc_Rowid
tc_ParentRowid
tc_Status
to tVatNumber.
end. /* for each tApiVatNumber where ... */
/* ========================================================= */
/* Remove the longer used VatNumbers of the BusinessRelation */
/* ========================================================= */
for each tVatNumber where
tVatNumber.tc_ParentRowid = tBusinessRelation.tc_Rowid :
/* Check if the record still exists */
find first tApiVatNumber where
tApiVatNumber.tc_ParentRowid = tApiBusinessRelation.tc_Rowid and
tApiVatNumber.VatNumber_ID = tVatNumber.VatNumber_ID
no-error.
if not available tApiVatNumber
then find first tApiVatNumber where
tApiVatNumber.tc_ParentRowid = tApiBusinessRelation.tc_Rowid and
tApiVatNumber.VatNumberIdentity = tVatNumber.VatNumberIdentity and
tApiVatNumber.tcIdentityCountryCode = tVatNumber.tcIdentityCountryCode
no-error.
if not available tApiVatNumber
then assign tVatNumber.tc_Status = "D":U.
end. /* for each tApiVatNumber where ... */
/* ================================================= */
/* Go through all ADDRESSES of the BusinessRelation */
/* ================================================= */
for each tApiAddress where
tApiAddress.tc_ParentRowid = tApiBusinessRelation.tc_Rowid
by tApiAddress.tc_Rowid:
/* ==================================== */
/* Find the appropriate exsiting record */
/* ==================================== */
find tAddress where
tAddress.tc_ParentRowid = tBusinessRelation.tc_Rowid and
tAddress.Address_ID = tApiAddress.Address_ID
no-error.
if not available tAddress
then find tAddress where
tAddress.tc_ParentRowid = tBusinessRelation.tc_Rowid and
tAddress.AddressLogicKeyString = tApiAddress.AddressLogicKeyString and
tAddress.tcAddressTypeCode = tApiAddress.tcAddressTypeCode
no-error.
if not available tAddress
then find tAddress where
tAddress.tc_ParentRowid = tBusinessRelation.tc_Rowid and
tAddress.AddressStreet1 = tApiAddress.AddressStreet1 and
tAddress.AddressStreet2 = tApiAddress.AddressStreet2 and
tAddress.AddressStreet3 = tApiAddress.AddressStreet3 and
tAddress.AddressZip = tApiAddress.AddressZip and
tAddress.AddressCity = tApiAddress.AddressCity and
tAddress.tcAddressTypeCode = tApiAddress.tcAddressTypeCode
no-error.
/* ================================= */
/* Check for Create / Update */
/* ================================= */
if available tAddress
then do:
assign tAddress.tc_Status = "":U.
buffer-compare tApiAddress except
Address_ID
BusinessRelation_ID
tc_Rowid
tc_ParentRowid
tc_status
to tAddress save vlBufferCompareResult.
if vlBufferCompareResult = true
then next.
assign tAddress.tc_Status = "C":U.
end. /* if available tAddress */
else do:
<M-1 run AddDetailLine (input 'Address':U (icTable),
input tBusinessRelation.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
end. /* not if available tAddress */
buffer-copy tApiAddress except
Address_ID
BusinessRelation_ID
tc_Rowid
tc_ParentRowid
tc_status
to tAddress.
/* ====================================== */
/* Go through all CONTACTS of the Address */
/* ====================================== */
for each tApiContact where
tApiContact.tc_ParentRowid = tApiAddress.tc_Rowid
by tApiContact.tc_Rowid:
/* ==================================== */
/* Find the appropriate exsiting record */
/* ==================================== */
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:
assign tContact.tc_Status = "":U.
buffer-compare tApiContact except
Contact_ID
Address_ID
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-9 run AddDetailLine (input 'Contact':U (icTable),
input tAddress.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
end. /* NOY if available tContact */
buffer-copy tApiContact except
Contact_ID
Address_ID
tc_Rowid
tc_ParentRowid
tc_Status
to tContact.
end. /* for each tApiContact where ... */
/* ============================================== */
/* Remove the longer used Contacts of the Address */
/* ============================================== */
for each tContact where
tContact.tc_ParentRowid = tAddress.tc_Rowid :
/* Check if the record still exists */
find first tApiContact where
tApiContact.tc_ParentRowid = tApiAddress.tc_Rowid AND
tApiContact.Contact_ID = tContact.Contact_ID
no-error.
if not available tApiContact
then find first tApiContact where
tApiContact.tc_ParentRowid = tApiAddress.tc_Rowid AND
tApiContact.ContactName = tContact.ContactName
no-error.
if not available tApiContact
then if tContact.tc_Status = "N":U
then delete tContact.
else assign tContact.tc_Status = "D":U.
end. /* for each tApiContact where ... */
end. /* for each tApiAddress where ... */
/* =============================================== */
/* Remove the longer used Addresses of the BusRel */
/* =============================================== */
for each tAddress where
tAddress.tc_ParentRowid = tBusinessRelation.tc_Rowid :
/* Check if the record still exists */
find first tApiAddress where
tApiAddress.tc_ParentRowid = tApiBusinessRelation.tc_Rowid and
tApiAddress.Address_ID = tAddress.Address_ID
no-error.
if not available tApiAddress
then find first tApiAddress where
tApiAddress.tc_ParentRowid = tApiBusinessRelation.tc_Rowid and
tApiAddress.AddressStreet1 = tAddress.AddressStreet1 and
tApiAddress.AddressStreet2 = tAddress.AddressStreet2 and
tApiAddress.AddressStreet3 = tAddress.AddressStreet3 and
tApiAddress.AddressZip = tAddress.AddressZip and
tApiAddress.AddressCity = tAddress.AddressCity and
tApiAddress.tcAddressTypeCode = tAddress.tcAddressTypeCode
no-error.
if not available tApiAddress
then assign tAddress.tc_Status = "D":U.
end. /* for each tApiAddress where ... */
/* ===================================================== */
/* Go through all SAF-DEFAULTS of the BusinessRelation */
/* ===================================================== */
for each tApiBusRelationSafDefault where
tApiBusRelationSafDefault.tc_ParentRowid = tApiBusinessRelation.tc_Rowid
by tApiBusRelationSafDefault.tc_Rowid:
/* ==================================== */
/* Find the appropriate exsiting record */
/* ==================================== */
find tBusRelationSafDefault where
tBusRelationSafDefault.tc_ParentRowid = tBusinessRelation.tc_Rowid and
tBusRelationSafDefault.tcSafConceptCode = tApiBusRelationSafDefault.tcSafConceptCode
no-error.
if not available tBusRelationSafDefault
then find tBusRelationSafDefault where
tBusRelationSafDefault.tc_ParentRowid = tBusinessRelation.tc_Rowid and
tBusRelationSafDefault.BusRelationSafDefault_ID = tApiBusRelationSafDefault.BusRelationSafDefault_ID
no-error.
/* ================================= */
/* Check for Create / Update */
/* ================================= */
if available tBusRelationSafDefault
then do:
assign tBusRelationSafDefault.tc_Status = "":U.
buffer-compare tApiBusRelationSafDefault except
BusRelationSafDefault_ID
BusinessRelation_ID
tc_Rowid
tc_ParentRowid
tc_status
to tBusRelationSafDefault save vlBufferCompareResult.
if vlBufferCompareResult = true
then next.
assign tBusRelationSafDefault.tc_Status = "C":U.
end. /* if available tBusRelationSafDefault */
else do:
<M-6 run AddDetailLine (input 'BusRelationSafDefault':U (icTable),
input tBusinessRelation.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
end. /* Not if available tBusRelationSafDefault */
buffer-copy tApiBusRelationSafDefault except
BusRelationSafDefault_ID
BusinessRelation_ID
tc_Rowid
tc_ParentRowid
tc_Status
to tBusRelationSafDefault.
end. /* for each tApiBusRelationSafDefault where ... */
/* ========================================================== */
/* Remove the longer used SafDefaults of the BusinessRelation */
/* ========================================================== */
for each tBusRelationSafDefault where
tBusRelationSafDefault.tc_ParentRowid = tBusinessRelation.tc_Rowid :
/* Check if the record still exists */
find first tApiBusRelationSafDefault where
tApiBusRelationSafDefault.tc_ParentRowid = tApiBusinessRelation.tc_Rowid AND
tApiBusRelationSafDefault.BusRelationSafDefault_ID = tBusRelationSafDefault.BusRelationSafDefault_ID
no-error.
if not available tApiBusRelationSafDefault
then find first tApiBusRelationSafDefault where
tApiBusRelationSafDefault.tc_ParentRowid = tApiBusinessRelation.tc_Rowid AND
tApiBusRelationSafDefault.tcSafConceptCode = tBusRelationSafDefault.tcSafConceptCode
no-error.
if not available tApiBusRelationSafDefault
then if tBusRelationSafDefault.tc_Status = "N":U
then delete tBusRelationSafDefault.
else assign tBusRelationSafDefault.tc_Status = "D":U.
end. /* for each tApiBusRelationSafDefault where ... */