Parameters
ihMfgTable | input | handle | |
ihFinancialAddressTable | input | handle | |
ihFinancialContactTable | input | handle | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/bmfgaddress.p)
assign
oiReturnStatus = -98
viContactCount = 0.
/* create a query to go through the MFG/PRO records */
create query vhMfgQuery in widget-pool "non-persistent".
vhMfgQuery:set-buffers(ihMfgTable).
vhMfgQuery:query-prepare("for each ":U + ihMfgTable:name + " where tc_status <> 'D'").
vhMfgQuery:query-open.
/* Find mapping record */
for first tMfgBufferFieldMapping
where tMfgBufferFieldMapping.tcMfgTableName = "ad_mstr":U
and tMfgBufferFieldMapping.tcFinancialTableName = "Address":U
and tMfgBufferFieldMapping.tcFieldMapping <> ""
and tMfgBufferFieldMapping.tcFieldMapping <> ?:
/* iterate through all the source records */
repeat:
vhMfgQuery:get-next().
if vhMfgQuery:query-off-end
then leave.
/* create a new record in the financial table */
ihFinancialAddressTable:buffer-create().
/* if this is a change record then get existing values so we can overrite them */
if ihMfgTable:buffer-field("tc_status":U):buffer-value = "C":U
then do:
<Q-4 run AddressById (all) (Read) (NoCache)
(input ihMfgTable:buffer-field('ad_address_id':U):buffer-value, (AddressID)
output dataset tqAddressById) in BBusinessRelation >
for first tqAddressById:
assign vhAddressHandle = dataset tqAddressById:get-buffer-handle(1).
<M-3 run BufferCopy
(input vhAddressHandle (ihFrom),
input ihFinancialAddressTable (ihTo),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
end.
end.
<M-1 run MappedBufferCopy
(input ihMfgTable (ihSourceBuffer),
input ihFinancialAddressTable (ihTargetBuffer),
input tMfgBufferFieldMapping.tcFieldMapping (icBufferFieldMapping),
input '' (icExcludeFields),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
/* Check for errors */
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper.
leave.
end.
/* map address type */
if ihMfgTable:buffer-field("ad_type":U):buffer-value = "shipto":U or
ihMfgTable:buffer-field("ad_type":U):buffer-value = "ship-to":U
then
assign ihFinancialAddressTable:buffer-field('tcAddressTypeCode':U):buffer-value = {&ADDRESSTYPECODESYSTEM-DELIVERY}.
else if ihMfgTable:buffer-field("ad_type":U):buffer-value = "customer":U or
ihMfgTable:buffer-field("ad_type":U):buffer-value = "supplier":U
then
assign ihFinancialAddressTable:buffer-field('tcAddressTypeCode':U):buffer-value = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}.
else
assign ihFinancialAddressTable:buffer-field('tcAddressTypeCode':U):buffer-value = ihMfgTable:buffer-field("ad_type":U):buffer-value.
/* Map tax is Included */
if ihMfgTable:buffer-field('ad_tax_in':U):buffer-value = yes
then
assign ihFinancialAddressTable:buffer-field('AddressIsTaxIncluded':U):buffer-value = true no-error.
else
assign ihFinancialAddressTable:buffer-field('AddressIsTaxIncluded':U):buffer-value = false no-error.
/*Map the language*/ /* Set the new address to active */
/* Store the MFG/PRO oid on the Financial table to use as a cross reference later on*/
assign
ihFinancialAddressTable:buffer-field("tc_rowid":U):buffer-value = ihMfgTable:buffer-field("tc_rowid":U):buffer-value
ihFinancialAddressTable:buffer-field("tcLngCode":U):buffer-value = ihMfgTable:buffer-field("ad_lang":U):buffer-value
ihFinancialAddressTable:buffer-field("tiCountryFormat":U):buffer-value = ihMfgTable:buffer-field("ad_format":U):buffer-value
ihFinancialAddressTable:buffer-field("AddressTelephone":U):buffer-value = ihMfgTable:buffer-field("ad_phone":U):buffer-value
no-error.
if ihMfgTable:buffer-field("tc_status":U):buffer-value = "C":U
then do:
<Q-8 run ContactByAddress (all) (Read) (NoCache)
(input ihMfgTable:buffer-field('ad_address_id':U):buffer-value, (AddressId)
output dataset tqContactByAddress) in BBusinessRelation >
end.
/* check to see if we have primary contact information */
if ihMfgTable:buffer-field('ad_attn':U):buffer-value <> "":U
then do:
ihFinancialContactTable:buffer-create() no-error.
assign vlFoundPrimaryContact = false.
/* Check to see if we have an existing primary and secondary contact so we can override the */
for first tqContactByAddress
where tqContactByAddress.tlContactIsPrimary:
assign
vlFoundPrimaryContact = true.
vhContactHandle = dataset tqContactByAddress:get-buffer-handle(1).
<M-9 run BufferCopy
(input vhContactHandle (ihFrom),
input ihFinancialContactTable (ihTo),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
end.
assign
viContactCount = viContactCount + 1
ihFinancialContactTable:buffer-field('tc_Rowid':U):buffer-value = viContactCount
ihFinancialContactTable:buffer-field('ContactName':U):buffer-value = ihMfgTable:buffer-field('ad_attn':U):buffer-value
ihFinancialContactTable:buffer-field('ContactTelephone':U):buffer-value = ihMfgTable:buffer-field('ad_phone':U):buffer-value
ihFinancialContactTable:buffer-field('ContactFax':U):buffer-value = ihMfgTable:buffer-field('ad_fax':U):buffer-value
ihFinancialContactTable:buffer-field('ContactEmail':U):buffer-value = ihMfgTable:buffer-field('ad_email':U):buffer-value
ihFinancialContactTable:buffer-field('ContactIsPrimary':U):buffer-value = true
ihFinancialContactTable:buffer-field('tcLngCode':U):buffer-value = ihFinancialAddressTable:buffer-field("tcLngCode":U):buffer-value
ihFinancialContactTable:buffer-field('tc_ParentRowid':U):buffer-value = ihFinancialAddressTable:buffer-field("tc_rowid":U):buffer-value no-error.
if not(vlFoundPrimaryContact)
then
assign ihFinancialContactTable:buffer-field('ContactGender':U):buffer-value = "Male":U no-error.
end.
/* IF we are mapping a new record then check to see if we have secondary contact information */
if ihMfgTable:buffer-field('ad_attn2':U):buffer-value <> "":U
then do:
ihFinancialContactTable:buffer-create() no-error.
assign vlFoundSecondaryContact = false.
/* if this is a change record then get existing values so we can overrite them */
for first tqContactByAddress
where tqContactByAddress.tlContactIsSecondary:
assign
vlFoundSecondaryContact = true.
vhContactHandle = dataset tqContactByAddress:get-buffer-handle(1).
<M-11 run BufferCopy
(input vhContactHandle (ihFrom),
input ihFinancialContactTable (ihTo),
output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
end.
assign
viContactCount = viContactCount + 1
ihFinancialContactTable:buffer-field('tc_Rowid':U):buffer-value = viContactCount
ihFinancialContactTable:buffer-field('ContactName':U):buffer-value = ihMfgTable:buffer-field('ad_attn2':U):buffer-value
ihFinancialContactTable:buffer-field('ContactTelephone':U):buffer-value = ihMfgTable:buffer-field('ad_phone2':U):buffer-value
ihFinancialContactTable:buffer-field('ContactFax':U):buffer-value = ihMfgTable:buffer-field('ad_fax2':U):buffer-value
ihFinancialContactTable:buffer-field('ContactEmail':U):buffer-value = ihMfgTable:buffer-field('ad_email2':U):buffer-value
ihFinancialContactTable:buffer-field('ContactIsSecondary':U):buffer-value = true
ihFinancialContactTable:buffer-field('tcLngCode':U):buffer-value = ihFinancialAddressTable:buffer-field("tcLngCode":U):buffer-value
ihFinancialContactTable:buffer-field('tc_ParentRowid':U):buffer-value = ihFinancialAddressTable:buffer-field("tc_rowid":U):buffer-value no-error.
if not(vlFoundSecondaryContact)
then
assign ihFinancialContactTable:buffer-field('ContactGender':U):buffer-value = "Male":U no-error.
end.
if ihFinancialAddressTable:available then ihFinancialAddressTable:buffer-release().
if ihFinancialContactTable:available then ihFinancialContactTable:buffer-release().
end. /* end of repeat */
/* clean up query */
vhMfgQuery:query-close().
delete object vhMfgQuery.
if oiReturnStatus < 0 and
oiReturnStatus <> -98
then return.
end. /* end of for first tMfgBufferFieldMapping */
assign
oiReturnStatus = 0.