project QadFinancials > class BMfgAddress > method MaintainDataDebtorShipto
Parameters
tDebtorShiptosToUpdate | input | temp-table | |
iiBusinessRelationInstanceID | input | integer | |
icShiptoActivityCode | input | character | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/bmfgaddress.p)
assign oiReturnStatus = -98.
<M-32 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
/* clear tAddress */
empty temp-table tAddress.
empty temp-table tContactsToUpdate.
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Return.
/* store the instance id of the Business Relation */
assign viBBusinessRelation7ID = iiBusinessRelationInstanceID.
/* If an business relation doesn't exist start and open it - otherwise just open the existing isntance */
if viBBusinessRelation7ID = 0 or
viBBusinessRelation7ID = ?
then do:
<I-19 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BBusinessRelation"}>
end.
else do:
<I-20 {bFcOpenInstance
&CLASS = "BBusinessRelation"}>
if viFcReturnsuper <> 0
then do:
assign viBBusinessRelation7ID = 0.
<I-43 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BBusinessRelation"}>
end.
end.
/* loop through all the debtor shipto records */
shipto:
for each tDebtorShiptosToUpdate
where (tDebtorShiptosToUpdate.tc_status = "N":U
or tDebtorShiptosToUpdate.tc_status = "D":U
or tDebtorShiptosToUpdate.tc_status = "C":U) and
tDebtorShiptosToUpdate.DebtorEndUser_ID = 0:
/* clear the tAddres temp table */
empty temp-table tAddress.
/* If we are changing a shipto we only want to process the change if the adddress id has changed */
if tDebtorShiptosToUpdate.tc_status = "C":U
then do:
<Q-31 run DebtorShipToByIDCode (all) (Read) (NoCache)
(input tDebtorShiptosToUpdate.debtorshipto_id, (DebtorShiptoId)
input '', (DebtorShiptoCode)
input viCompanyID, (CompanyId)
output dataset tqDebtorShipToByIDCode) in BDebtorShipTo >
for first tqDebtorShipToByIDCode:
/* IF we are in excel integration then we want to update the address */
if tDebtorShiptosToUpdate.address_id = tqDebtorShipToByIDCode.tiAddress_ID
and icShiptoActivityCode <> "ExcelIntegration":U
then
next shipto.
end.
end.
/* get the address information from the business relation instance.*/
<M-24 run GetAddressWithID (input tDebtorShiptosToUpdate.address_id (iiAddressID),
input-output tAddress (tApiAddress),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
<M-46 run GetContactByAddress
(input tDebtorShiptosToUpdate.address_id (iiAddressID),
input-output tContactsToUpdate (tApiContact),
output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
if tDebtorShiptosToUpdate.DebtorShipToIsDebtor
then do:
for first tAddress
where tAddress.Address_ID = tDebtorShiptosToUpdate.Address_ID:
<Q-49 run DebtorByCode (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input tDebtorShiptosToUpdate.DebtorShipToCode, (DebtorCode)
output dataset tqDebtorByCode) in BDebtor >
for first tqDebtorByCode
where tqDebtorByCode.tcDebtorCode = tDebtorShiptosToUpdate.DebtorShipToCode:
end.
if available tqDebtorByCode
then do:
<Q-39 run DebtorByIDAllInfo (all) (Read) (NoCache)
(input ?, (CompanyId)
input tqDebtorByCode.tiDebtor_ID, (DebtorID)
output dataset tqDebtorByIDAllInfo) in BDebtor >
for first tqDebtorByIDAllInfo
where tqDebtorByIDAllInfo.tiDebtor_ID = tqDebtorByCode.tiDebtor_ID:
end.
if available tqDebtorByIDAllInfo
then do:
assign tAddress.AddressIsTaxable = tqDebtorByIDAllInfo.tlDebtorIsTaxable
tAddress.AddressIsTaxIncluded = tqDebtorByIDAllInfo.tlDebtorIsTaxIncluded
tAddress.AddressIsTaxInCity = tqDebtorByIDAllInfo.tlDebtorIsTaxInCity
tAddress.AddressTaxIDFederal = tqDebtorByIDAllInfo.tcDebtorTaxIDFederal
tAddress.AddressTaxIDState = tqDebtorByIDAllInfo.tcDebtorTaxIDState
tAddress.AddressTaxIDMisc1 = tqDebtorByIDAllInfo.tcDebtorTaxIDMisc1
tAddress.AddressTaxIDMisc2 = tqDebtorByIDAllInfo.tcDebtorTaxIDMisc2
tAddress.AddressTaxIDMisc3 = tqDebtorByIDAllInfo.tcDebtorTaxIDMisc3
tAddress.TxzTaxZone = tqDebtorByIDAllInfo.tcTxzTaxZone
tAddress.TxclTaxCls = tqDebtorByIDAllInfo.tcTxclTaxCls
tAddress.TxuTaxUsage = tqDebtorByIDAllInfo.tcTxuTaxUsage.
end. /*IF AVAILABLE tqDebtorByIDAllInfo*/
end. /*IF AVAILABLE tqDebtorByCode*/
end. /*FOR FIRST tAddress*/
end. /*IF tDebtorShiptosToUpdate.DebtorShipToIsDebtor*/
/* find the tAddress record we just created */
for first tAddress
where tAddress.address_id = tDebtorShiptosToUpdate.address_id:
end.
/* We should always be able to find an address but in case we don't then raise an error */
if not available tAddress
then do:
assign
vcMessageText =#T-25'The address details are not defined in the system.':35(31629)T-25#
oiReturnStatus = -1.
<M-26 run SetMessage (input vcMessageText (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4860':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
leave.
end.
/* Overrite the AdddresName in this case so that the Debtor end user name will be used for the ad_name value */
assign tAddress.AddressName = tDebtorShiptosToUpdate.DebtorShiptoName.
/* Store the Debtor shipto code into a variable, it will be populated in ad_addr */
assign vcRelationCode = tDebtorShiptosToUpdate.DebtorShiptoCode.
/* If the current shipto is a debtor then we only want to update the ad_mstr record - so set the status = C*/
if tDebtorShiptosToUpdate.DebtorShipToIsDebtor
then
assign
vcRelationType = "customer":U
tAddress.tc_status = "C":U. /*t_sDebtorsToUpdate.tc_status*/
else
assign
vcRelationType = "ship-to":U
tAddress.tc_status = tDebtorShiptosToUpdate.tc_status.
/* Addresses are system wide date, so we need to use the SystemWideToMfg pattern.
* However, we are processing Creditors, which use the SharedSetToMfg pattern.
* We need to copy the address information (system wide data) to all domains where the
* creditor is added. To achieve this we determine all the companies that uses the creditor
* shared set, get the domains and for each domain we run MaintainData and follow
* the SystemWideToMFG pattern.
*/
if tDebtorShiptosToUpdate.tc_status = "D":U
then
assign vcRelatedCustomer = "":U.
else
assign vcRelatedCustomer = tDebtorShiptosToUpdate.tcDebtorCode.
<Q-2 run CompanyBySharedSet (all) (Read) (NoCache)
(input '', (CompanyId)
input tDebtorShiptosToUpdate.SharedSet_ID, (SharedSetId)
output dataset tqCompanyBySharedSet) in BCompany >
/*
* Process the Financial Data into each of the domains returned by the above query.
*/
DomainLoop:
for each tqCompanyBySharedSet where
tqCompanyBySharedSet.tlDomainPropertyIsSetupCompl = true
break by tqCompanyBySharedSet.tcDomainCode:
if not first-of(tqCompanyBySharedSet.tcDomainCode) then
next DomainLoop.
/* find the tAddress record we just created */
for first tAddress
where tAddress.address_id = tDebtorShiptosToUpdate.address_id:
end.
/* save the domain code which is currently being processed */
assign vcDomain = tqCompanyBySharedSet.tcDomainCode.
/* Check if we need to replicate to one domain or to all */
<I-36 {bFcOpenInstance
&CLASS = "Session"}>
<M-37 run GetCharacterValue
(input 'ProcessSharedSetToMFGDomainCode':U (icName),
output vcProcessSharedSetToMFGDomain (ocValue),
output viSessionReturnStatus (oiReturnStatus)) in Session>
<I-38 {bFcCloseInstance
&CLASS = "Session"}>
if viSessionReturnStatus <> 0
then assign oiReturnStatus = viSessionReturnStatus.
if viSessionReturnStatus < 0
then do :
leave shipto.
end. /* if viFcReturnSuper < 0 */
if vcProcessSharedSetToMFGDomain <> '':U and
vcProcessSharedSetToMFGDomain <> ? and
vcProcessSharedSetToMFGDomain <> tqCompanyBySharedSet.tcDomainCode
then next DomainLoop.
if tAddress.tc_status = "D":U
then do:
/* check if address already exists */
<Q-44 run AddressListDetailByDomainCode (all) (Read) (NoCache)
(input tDebtorShiptosToUpdate.DebtorShipToCode, (AddressCode)
input vcDomain, (domain)
output dataset tqAddressListDetailByDomainCode) in BMfgAddressListDetail >
for first tqAddressListDetailByDomainCode
where tqAddressListDetailByDomainCode.tcls_addr = tDebtorShiptosToUpdate.DebtorShipToCode
and tqAddressListDetailByDomainCode.tcls_domain = vcDomain
and tqAddressListDetailByDomainCode.tcls_type <> "ship-to":U:
next domainloop.
end.
end. /* end new debtor */
/* Check if this address already exists */
if tAddress.tc_Status = "N":U
then do:
<Q-45 assign vlFcQueryRecordsAvailable = AdMstrByDomainByCode (NoCache)
(input tqCompanyBySharedSet.tcDomainCode, (Domain)
input tDebtorShiptosToUpdate.DebtorShipToCode, (Code)) in BMfgAddress >
if vlFcQueryRecordsAvailable <> false or
(can-find(first tad_mstr where
tad_mstr.ad_domain = tqCompanyBySharedSet.tcDomainCode and
tad_mstr.ad_addr = tDebtorShiptosToUpdate.DebtorShipToCode))
then assign tAddress.tc_Status = "C":U.
end.
/* update the MFG/PRO record */
<M-33 run ProcessMaintainData (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave shipto.
end. /* end of companybysharedset */
end. /* end of for each tDebtorShiptosToUpdate */
/* If we started the business relation instance then we need to stop it - otherwise just close it */
if iiBusinessRelationInstanceID = 0
then do:
<I-22 {bFcCloseAndStopInstance
&CLASS = "BBusinessRelation"}>
end.
else do:
<I-23 {bFcCloseInstance
&CLASS = "BBusinessRelation"}>
end.
if oiReturnStatus > 0 or oiReturnStatus = -98
then do:
<M-35 run ProcessMaintainDataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Return.
end.
/* ======================== */
/* Set ReturnStatus = OK */
/* ======================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.