Description
Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.
For both new and existing records:
Verify that both DebtorEndUserIsShipto and DebtorEndUserIsDebtor flags are not being set together.
If the DebtorEndUserIsDebtor flag is set then the DebtorEndUserCode value must be the same as the DebtorCode value.
If the DebtorEndUserIsShipto flag is set to true then ensure the DebtorEndUserCode is a validate shipto code.
Ensure the current DebtorEndUser Address is not already setup as an EndUser for a same Debtor.
For new records:
Verfiy the DebtorEndUser code is not blank. If it is then call GetAutoNumber.
Verify that the DebtorIsActive flag on the owning Debtor is set to true.
Verify that the DataCompleteFlag (cm_datacomplete) is set to true for the primary domain for the current company.
Validate the Owning Debtor - it should be a validate Debtor.
If DebtorEndUser.DebtorEndUserIsDebtor and DebtorEndUser.DebtorEndUserIsShipTo are not set to true then ensure that the code does not exist already in any of the domains that share the same Debtor sharedset as the current company.
For existing records:
Verify the DebtorEndUserCode, DebtorCode,DebtorEndUserIsShipto, DebtorEndUserIsDebtor values are not being modified.
Parameters
| oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/bdebtorenduser.p)
/* No call to stop external interfaces as the API relies on the business relation component still running */
/* Verify that the Debtor code is not being used as a code in MFG/PRO
* at this moment the ad_mstr record of the current debtor itself should not be created yet.
*/
VALIDATE_BLOCK:
do on error undo, leave:
/* first populate the address_id and retrieve shared end users - if required */
<M-58 run ValidateComponentUpdateAllSharedEndusers (output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
endusers:
for each t_sDebtorEndUser
where t_sDebtorEndUser.tc_status = "N":U
or t_sDebtorEndUser.tc_status = "C":U:
if(t_sDebtorEndUser.DebtorEndUserCode <> ? and
t_sDebtorEndUser.DebtorEndUserCode <> "":U)
then assign t_sDebtorEndUser.DebtorEndUserCode = trim(t_sDebtorEndUser.DebtorEndUserCode).
/*Check if there is no duplicate address record which are already in Database while creating new end user from excel*/
if t_sDebtorEndUser.tlAddressIsShared <> true
then do:
if can-find (bDebtorEndUser where
bDebtorEndUser.tcAddressStreet1 = t_SDebtorEndUser.tcAddressStreet1 and
bDebtorEndUser.tcAddressStreet2 = t_SDebtorEndUser.tcAddressStreet2 and
bDebtorEndUser.tcAddressStreet3 = t_SDebtorEndUser.tcAddressStreet3 and
bDebtorEndUser.tcAddressCity = t_SDebtorEndUser.tcAddressCity and
bDebtorEndUser.tcAddressZip = t_SDebtorEndUser.tcAddressZip and
bDebtorEndUser.tcAddressTypeCode = t_SDebtorEndUser.tcAddressTypeCode and
bDebtorEndUser.tiAddressBusinessRelation_ID = t_SDebtorEndUser.tiAddressBusinessRelation_ID and
bDebtorEndUser.DebtorEndUser_ID <> t_SDebtorEndUser.DebtorEndUser_ID)
then
assign vlAddressFound = true.
if not (vlAddressFound)
then do:
<Q-86 run AddressPrim (all) (Read) (NoCache)
(input t_sDebtorEndUser.tcAddressCity, (AddressCity)
input t_sDebtorEndUser.tcAddressStreet1, (AddressStreet1)
input t_sDebtorEndUser.tcAddressStreet2, (AddressStreet2)
input t_sDebtorEndUser.tcAddressZip, (AddressZip)
input t_sDebtorEndUser.tcAddressTypeCode, (AddressTypeCode)
input ?, (AddressID)
input ?, (BusinessRelationID)
input t_sDebtorEndUser.tcBusinessRelationCode, (BusinessRelationCode)
input ?, (AddressTypeID)
input t_sDebtorEndUser.tcAddressStreet3, (AddressStreet3)
output dataset tqAddressPrim) in BBusinessRelation>
find first tqAddressPrim where
tqAddressPrim.tcAddressCity = t_sDebtorEndUser.tcAddressCity and
tqAddressPrim.tcAddressStreet1 = t_sDebtorEndUser.tcAddressStreet1 and
tqAddressPrim.tcAddressStreet2 = t_sDebtorEndUser.tcAddressStreet2 and
tqAddressPrim.tcAddressStreet3 = t_sDebtorEndUser.tcAddressStreet3 and
tqAddressPrim.tcAddressZip = t_sDebtorEndUser.tcAddressZip and
tqAddressPrim.tcAddressTypeCode = t_sDebtorEndUser.tcAddressTypeCode and
tqAddressPrim.tcBusinessRelationCode = t_sDebtorEndUser.tcbusinessrelationcode no-error.
if available tqAddressPrim
then do:
<Q-82 run DebtorEndUserByAddress (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input tqAddressPrim.tiAddress_ID, (AddressID)
input ?, (DebtorEndUserIDDifferentFro)
output dataset tqDebtorEndUserByAddress) in BDebtorEndUser>
find first tqDebtorEndUserByAddress where
tqDebtorEndUserByAddress.tcDebtorEndUserCode <> t_sDebtorEndUser.DebtorEndUserCode no-error.
if available tqDebtorEndUserByAddress
then
assign vlAddressFound = true.
end.
end.
end.
if vlAddressFound
then do:
assign vcMessageText = #T-68'The address below already exists - To assign an end user to an existing address use the 'Link to end user address', $1, $2, $3, $4, $5, $6':255(269168777)T-68#.
assign oiReturnStatus = -1.
<M-335 run SetMessage
(input vcMessageText (icMessage),
input t_sDebtorEndUser.tcAddressStreet1 + chr(2) + t_sDebtorEndUser.tcAddressStreet2 + chr(2) + t_sDebtorEndUser.tcAddressStreet3 + chr(2) + t_sDebtorEndUser.tcAddressCity + chr(2) + t_sDebtorEndUser.tcAddressZip + chr(2) + t_sDebtorEndUser.tcBusinessRelation (icArguments),
input 'AddressStreet1' (icFieldName),
input t_sDebtorEndUser.tcAddressStreet1 (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input ' ' (icRowid),
input 'qadfin-123024':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
leave VALIDATE_BLOCK.
end.
/*
* We only want to check if the end user code is an ad_mstr record already if the user has not ticked the customer or shipto tick boxes
* This is because if these boxes are ticked then ad_mstr records will already exists with the enduser code.
*/
if t_sDebtorEndUser.tc_status = "N":U
then do:
/* Check for an automatic number for debtor */
if t_sDebtorEndUser.DebtorEndUserCode = '':U or
t_sDebtorEndUser.DebtorEndUserCode = ?
then do:
assign vhFcComponent = ?.
<M-75 run GetAutoNumber
(input t_sDebtorEndUser.tc_Rowid (icRowId),
output t_sDebtorEndUser.DebtorEndUserCode (ocDebtorEndUserCode),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave endusers.
end. /* if t_sDebtorEndUser.DebtorEndUserCode = '':U */
<Q-73 run DebtorByBusinessRelation (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input t_sDebtorEndUser.tcDebtorCode, (DebtorCode)
input t_sDebtorEndUser.Debtor_ID, (DebtorId)
input t_sDebtorEndUser.tiDebtorBusinessRelation_ID, (BusinessRelationID)
output dataset tqDebtorByBusinessRelation) in BDebtor >
for first tqDebtorByBusinessRelation:
/* The end user shouldn't be created when the custeomer's data is incomplete,
User can go to Customer Data Maintenance to complete the setup */
<Q-76 run CustomerByDomainAddress (all) (Read) (NoCache)
(input vcDomainCode, (DomainCode)
input t_sDebtorEndUser.tcDebtorCode, (Address)
output dataset tqCustomerByDomainAddress) in BMfgCustomer >
find first tqCustomerByDomainAddress no-error.
if not available tqCustomerByDomainAddress or
tqCustomerByDomainAddress.tlcm_datacomplete = no
then do:
assign oiReturnStatus = -1.
<M-77 run SetMessage
(input #T-61'The customer setup is incomplete. Go to Customer Data Maintenance to complete the setup':255(71084)T-61# (icMessage),
input t_sDebtorEndUser.tcDebtorCode (icArguments),
input 't_sDebtorEndUser.tcDebtorCode':U (icFieldName),
input t_sDebtorEndUser.tcDebtorCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8600':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
leave endusers.
end. /* if not available tqCustomerByDomainAddress or tqCustomerByDomainAddress.tlcm_datacomplete = no */
end. /* for first tqDebtorByBusinessRelation: */
if not available tqDebtorByBusinessRelation
then do:
assign
vcMessageText = trim(#T-54'The specified customer: $1 is invalid.':255(63858)t-54#)
oiReturnStatus = -1.
<M-55 run SetMessage
(input vcMessageText (icMessage),
input t_sDebtorEndUser.tcDebtorCode (icArguments),
input 't_sDebtorEndUser.tcDebtorCode':U (icFieldName),
input t_sDebtorEndUser.tcDebtorCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-6602':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
leave endusers.
end. /* if not available tqDebtorByBusinessRelation */
if not(t_sDebtorEndUser.DebtorEndUserIsDebtor) and
not(t_sDebtorEndUser.DebtorEndUserIsShipTo)
then do:
/* if this enduseris not linked to a customer or ship-to then the address type has to be ship-to*/
if t_sDebtorEndUser.tcAddressTypeCode <> {&ADDRESSTYPECODESYSTEM-ENDUSER}
then do:
assign
vcMessageText = #T-95'Address type must be $1 when creating a new address for an End user':255(112308247)T-95#
oiReturnStatus = -1.
<M-24 run SetMessage
(input vcMessageText (icMessage),
input #T-2'End User':255(65024)T-2# (icArguments),
input 'tcAddressTypeCode' (icFieldName),
input t_sDebtorEndUser.tcAddressTypeCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDebtorEndUser.tc_rowid (icRowid),
input 'qadfin-500882':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
leave endusers.
end. /* end of addresstypecode validation */
/* Check if replication is enabled */
<I-41 {bFcOpenInstance
&CLASS = "Session"}>
<M-43 run GetLogicalValue
(input 'ReplicationEnabled':U (icName),
output vlReplicationEnabled (olValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<I-45 {bFcCloseInstance
&CLASS = "Session"}>
/* Only check for existing ad_mstr records if replication is not enabled */
if vlReplicationEnabled <> false
then do:
<Q-46 run CompanyBySharedSet (all) (Read) (NoCache)
(input '', (CompanyId)
input t_sDebtorEndUser.SharedSet_ID, (SharedSetId)
output dataset tqCompanyBySharedSet) in BCompany >
/* start query */
DomainLoop:
for each tqCompanyBySharedSet
break by tqCompanyBySharedSet.tcDomainCode:
if not first-of(tqCompanyBySharedSet.tcDomainCode)
then next DomainLoop.
<Q-28 assign vlFcQueryRecordsAvailable = AdMstrByDomainByCode (NoCache)
(input tqCompanyBySharedSet.tcDomainCode, (Domain)
input t_sDebtorEndUser.DebtorEndUserCode, (Code)) in BMfgAddress >
if vlFcQueryRecordsAvailable
then do:
assign
vcMessageText = trim(#T-26'Code $1 is already in use in the address master (ad_mstr).':100(45744)t-26#)
oiReturnStatus = -1.
<M-29 run SetMessage
(input vcMessageText (icMessage),
input t_sDebtorEndUser.DebtorEndUserCode (icArguments),
input 't_sDebtorEndUser.DebtorEndUserCode':U (icFieldName),
input t_sDebtorEndUser.DebtorEndUserCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDebtorEndUser.tc_rowid (icRowid),
input 'QadFin-5059':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
leave DomainLoop.
end. /* if vlFcQueryRecordsAvailable then do: */
end. /* for each tqCompanyBySharedSet */
end. /* replication enabled */
end. /* end of not customer or shipto */
end. /*end new record only */
/*
* It is not possible to change the Debtor Shipto Code value on the account
* as this is a key value that is used in MFG/PRO, the financials
* can handle these changes as they used the DebtorShipto_ID for foreign key
* relationships but it will cause major data integrity problems
* within MFG/PRO if this data is allowed to change.
*/
for first t_iDebtorEndUser
where t_iDebtorEndUser.tc_Rowid = t_sDebtorEndUser.tc_Rowid:
if t_iDebtorEndUser.DebtorEndUserCode <> t_sDebtorEndUser.DebtorEndUserCode
then do:
assign
vcMessageText = trim(#T-33'Cannot change key field value.':50(17933)T-33#)
oiReturnStatus = -1.
<M-32 run SetMessage
(input vcMessageText (icMessage),
input '' (icArguments),
input 'DebtorEndUserCode':U (icFieldName),
input t_sDebtorEndUser.DebtorEndUserCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDebtorEndUser.tc_rowid (icRowid),
input 'QadFin-5060':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
end. /* if t_iDebtorEndUser.DebtorEndUserCode <> t_sDebtorEndUser.DebtorEndUserCode */
if t_iDebtorEndUser.tcDebtorCode <> ? and
t_iDebtorEndUser.tcDebtorCode <> '':U and
t_iDebtorEndUser.tcDebtorCode <> t_sDebtorEndUser.tcDebtorCode
then do:
assign
vcMessageText = trim(#T-40'$1 Field cannot be modified':50(45756)T-40#)
oiReturnStatus = -1.
<M-39 run SetMessage
(input vcMessageText (icMessage),
input 'Customer Code':U (icArguments),
input 't_sDebtorEndUser.tcDebtorCode':U (icFieldName),
input t_sDebtorEndUser.tcDebtorCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDebtorEndUser.tc_rowid (icRowid),
input 'QadFin-5065':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
end. /* if t_iDebtorEndUser.tcDebtorCode <> ? and */
if t_iDebtorEndUser.DebtorEndUserIsShipTo <> t_sDebtorEndUser.DebtorEndUserIsShipTo
then do:
assign
vcMessageText = trim(#T-35'$1 Field cannot be modified':50(45756)T-35#)
oiReturnStatus = -1.
<M-34 run SetMessage
(input vcMessageText (icMessage),
input 'Use Ship-To':U (icArguments),
input 'DebtorEndUserIsShipTo':U (icFieldName),
input t_sDebtorEndUser.DebtorEndUserIsShipto (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDebtorEndUser.tc_rowid (icRowid),
input 'QadFin-5061':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
end. /* if t_iDebtorEndUser.DebtorEndUserIsShipTo <> t_sDebtorEndUser.DebtorEndUserIsShipTo */
if t_iDebtorEndUser.DebtorEndUserIsDebtor <> t_sDebtorEndUser.DebtorEndUserIsDebtor
then do:
assign
vcMessageText = trim(#T-38'$1 Field cannot be modified':50(45756)T-38#)
oiReturnStatus = -1.
<M-36 run SetMessage
(input vcMessageText (icMessage),
input 'Customer':U (icArguments),
input 'DebtorEndUserIsDebtor':U (icFieldName),
input t_sDebtorEndUser.DebtorEndUserIsDebtor (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDebtorEndUser.tc_rowid (icRowid),
input 'QadFin-5062':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
end. /* if t_iDebtorEndUser.DebtorEndUserIsDebtor <> t_sDebtorEndUser.DebtorEndUserIsDebtor */
if oiReturnStatus = -1 then
leave endusers.
end. /* end of find old record */
end. /* for each t_sDebtorEndUser */
if oiReturnStatus < 0 and oiReturnStatus <> -98
then return.
<ANCESTOR-CODE>
enduserdelete:
for each t_sDebtorEndUser
where t_sDebtorEndUser.tc_status = "N":U
or t_sDebtorEndUser.tc_status = "C":U:
if t_sDebtorEndUser.tc_status = "N":U
then do:
/* Both the Is Debtor and Is Shipto flag can not be selected together */
if t_sDebtorEndUser.DebtorEndUserIsDebtor and
t_sDebtorEndUser.DebtorEndUserIsShipTo
then do:
assign
vcMessageText = trim(#T-1'You cannot select both the Use Customer and Use Ship-To fields.':65(31140)t-1#)
oiReturnStatus = -1.
<M-2 run SetMessage
(input vcMessageText (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4718':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
leave enduserdelete.
end. /* check for two flags checked together */
/* If Use Debtor is selected the make sure the end user and debtor code match */
else if t_sDebtorEndUser.DebtorEndUserIsDebtor and
t_sDebtorEndUser.DebtorEndUserCode <> t_sDebtorEndUser.tcDebtorCode
then do:
assign
vcMessageText = trim(#T-5'If Use Customer field is selected, the end user code must be the same as the customer code.':93(31142)t-5#)
oiReturnStatus = -1.
<M-3 run SetMessage
(input vcMessageText (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4719':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
leave enduserdelete.
end. /* end of t_sDebtorEndUser.DebtorEndUserIsDebtor */
/* If the Use Shipto is selected - make sure it points to a valid shipto */
else if t_sDebtorEndUser.DebtorEndUserIsShipTo
then do:
<Q-21 assign vlFcQueryRecordsAvailable = DebtorShipToPrim (NoCache)
(input '', (DebtorShiptoID)
input t_sDebtorEndUser.DebtorEndUserCode, (DebtorShiptoCode)
input viCompanyId, (CompanyId)) in BDebtorShipTo>
if vlFcQueryRecordsAvailable <> true
then do:
assign
vcMessageText = trim(#T-9'$1 is not a valid customer ship-to.':35(32065)T-9#)
oiReturnStatus = -1.
<M-7 run SetMessage
(input vcMessageText (icMessage),
input t_sDebtorEndUser.DebtorEndUserCode (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-4723':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
leave enduserdelete.
end. /* no record availabl e*/
end. /* end of t_sDebtorEndUser.DebtorEndUserIsShipTo */
end. /*end new records only */
end. /* end of for each t_sDebtorEndUser */
end. /* of VALIDATE BLOCK */
/* Close instances of the component when and error was found and system does not *
* continue with the next execution of the AdditionalUpdates */
if oiReturnStatus < 0
then do:
<M-63 run StopExternalInstances (output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
end.