project QadFinancials > class BDebtor > method ValidateComponent
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.
Parameters
oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/bdebtor.p)
<M-19 run PreValidateComponent (output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
for each t_sDebtor where
t_sDebtor.tc_Status <> "D":U:
if vcActivityCode = "ExcelIntegration":U
then do :
if t_sDebtor.tc_Status = "C":U
then do :
for each t_iDebtor where
t_iDebtor.tc_rowid = t_sDebtor.tc_rowid :
assign t_sDebtor.DebtorLastPayment = t_iDebtor.DebtorLastPayment
t_sDebtor.DebtorLastSale = t_iDebtor.DebtorLastSale
t_sDebtor.DebtorHighCredit = t_iDebtor.DebtorHighCredit
t_sDebtor.DebtorHighCreditDate = t_iDebtor.DebtorHighCreditDate
t_sDebtor.DebtorSalesOrderBalance = t_iDebtor.DebtorSalesOrderBalance
t_sDebtor.DebtorLastFinChargeDate = t_iDebtor.DebtorLastFinChargeDate
t_sDebtor.DebtorTotalDaysLate = t_iDebtor.DebtorTotalDaysLate
t_sDebtor.DebtorTotalNbrOfInvoices = t_iDebtor.DebtorTotalNbrOfInvoices .
end. /* for t_idebtor */
end. /* t_sDebtor.tc_Status = "C":U */
if t_sDebtor.tc_Status = "N":U
then do :
assign t_sDebtor.DebtorLastPayment = ?
t_sDebtor.DebtorLastSale = ?
t_sDebtor.DebtorHighCredit = 0
t_sDebtor.DebtorHighCreditDate = ?
t_sDebtor.DebtorSalesOrderBalance = 0
t_sDebtor.DebtorLastFinChargeDate = ?
t_sDebtor.DebtorTotalDaysLate = 0
t_sDebtor.DebtorTotalNbrOfInvoices = 0 .
end. /* t_sDebtor.tc_Status = "N":U */
end. /* if vcActivityCOde = "ExcelIntegration " */
/* calculate type of normal payment condition*/
if (t_sDebtor.tcNormalPaymentConditionType = '' or t_sDebtor.tcNormalPaymentConditionType = ?) and
t_sDebtor.tcNormalPaymentConditionCode <> "" and
t_sDebtor.tcNormalPaymentConditionCode <> ?
then do:
<Q-16 run PaymentConditionByProperties (all) (Read) (Cache)
(input ?, (PaymentCondition_ID)
input t_sDebtor.tcNormalPaymentConditionCode, (PaymentConditionCode)
input ?, (PaymentConditionIsActive)
input ?, (PaymentConditionPaymentType)
input ?, (PaymentConditionPdDiscType)
input ?, (PaymentConditionPercentage)
output dataset tqPaymentConditionByProperties) in BPaymentCondition>
find first tqPaymentConditionByProperties no-error.
if available tqPaymentConditionByProperties
then assign t_sDebtor.tcNormalPaymentConditionType = tqPaymentConditionByProperties.tcPaymentConditionPaymentTyp.
end. /* t_sDebtor.tcNormalPaymentConditionCode */
if t_sDebtor.tcBusinessRelationName1 = ""
then do:
<Q-81 run BusinessRelationByIdCode (all) (Read) (NoCache)
(input t_sDebtor.BusinessRelation_ID, (BusinessRelationId)
input t_sDebtor.tcBusinessRelationCode, (BusinessRelationCode)
output dataset tqBusinessRelationByIdCode) in BBusinessRelation>
find first tqBusinessRelationByIdCode no-error.
if available tqBusinessRelationByIdCode
then assign t_sDebtor.tcBusinessRelationName1 = tqBusinessRelationByIdCode.tcBusinessRelationName1.
end. /* if t_sDebtor.tcBusinessRelationName1 = "" */
if t_sDebtor.tc_status = "C":U
then do:
/*
* It is not possible to change the Debtor 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 debtor_ID for foreign key
* relationships but it will cause major data integrity problems
* within MFG/PRO if this data is allowed to change.
*/
find t_iDebtor where
t_iDebtor.tc_Rowid = t_sDebtor.tc_Rowid
no-error.
if not available t_iDebtor
then next.
if t_iDebtor.DebtorCode <> t_sDebtor.DebtorCode
then do:
assign
vcMessageText = #T-36'Cannot change key field value.':50(17933)T-36#
oiReturnStatus = -1.
<M-37 run SetMessage (input vcMessageText (icMessage),
input t_sDebtor.DebtorCode (icArguments),
input 'DebtorCode':U (icFieldName),
input t_sDebtor.DebtorCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDebtor.tc_rowid (icRowid),
input 'QadFin-4931':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
return.
end.
/* Due to limitions in Mfg/Pro is not possible to update the business relation once a debtor has been created */
if t_iDebtor.tcBusinessRelationCode <> t_sDebtor.tcBusinessRelationCode
then do:
assign
vcMessageText = #T-39'The business relation cannot be modified.':45(31956)t-39#
oiReturnStatus = -1.
<M-38 run SetMessage (input vcMessageText (icMessage),
input '' (icArguments),
input 'BusinessRelation':U (icFieldName),
input t_sDebtor.tcBusinessrelationCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDebtor.tc_rowid (icRowid),
input 'QadFin-5109':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
return.
end.
if t_iDebtor.tcCurrencyCode <> t_sDebtor.tcCurrencyCode and
vcActivityCode ="DebtorCreditInfo":U
then assign t_sDebtor.tcCurrencyCode = t_iDebtor.tcCurrencyCode.
end. /* end record has changed */
end. /* for each t_sDebtor */
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
/* Convert Saf Code + Saf Concept Code to Saf ID */
for each t_sDebtorSafDefault where
t_sDebtorSafDefault.tcSafCode <> "":U:
<Q-12 run SafPrim (all) (Read) (Cache)
(input ?, (SafID)
input t_sDebtorSafDefault.tcSafCode, (SafCode)
input ?, (SafConceptCode)
output dataset tqSafPrim) in BSaf>
find first tqSafPrim where
tqSafPrim.tcSafCode = t_sDebtorSafDefault.tcSafCode and
tqSafPrim.tcSafConceptCode = t_sDebtorSafDefault.tcSafConceptCode
no-error.
if not available tqSafPrim
then find first tqSafPrim where
tqSafPrim.tcSafCode = t_sDebtorSafDefault.tcSafCode
no-error.
assign t_sDebtorSafDefault.Saf_ID = if available tqSafPrim
then tqSafPrim.tiSaf_ID
else -1.
end. /* for each t_sDebtorSafDefault where */
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
<M-55 run StopExternalInstances
(output viFcReturnSuper (oiReturnStatus)) in BDebtor>
<ANCESTOR-CODE>
if oiReturnStatus < 0
then return.
<M-10 run PostValidateComponent (output viFcReturnSuper (oiReturnStatus)) in BDebtor>
assign oiReturnStatus = if (oiReturnStatus > 0 and
viFcReturnSuper = 0) or
oiReturnStatus < 0
then oiReturnStatus
else viFcReturnSuper.
/* 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. */
<I-40 {bFcOpenInstance
&CLASS = "Session"}>
<M-41 run GetLogicalValue
(input 'ReplicationEnabled':U (icName),
output vlReplicationEnabled (olValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<I-42 {bFcCloseInstance
&CLASS = "Session"}>
if vlReplicationEnabled <> false
then do:
for each t_sDebtor where
t_sDebtor.tc_status = "N":U
break by t_sDebtor.SharedSet_ID :
if first-of (t_sDebtor.SharedSet_ID)
then do :
<Q-17 run DomainBySharedSetDomain (all) (Read) (NoCache)
(input t_sDebtor.SharedSet_ID, (SharedSetId)
input ?, (DomainID)
input ?, (DomainCode)
output dataset tqDomainBySharedSetDomain) in BDomain>
end.
/* Process the Financial Data into each of the domains returned by the above query */
DomainLoop:
for each tqDomainBySharedSetDomain:
<Q-22 run AdMstrByDomainByCode (all) (Read) (NoCache)
(input tqDomainBySharedSetDomain.tcDomainCode, (Domain)
input t_sDebtor.DebtorCode, (Code)
output dataset tqAdMstrByDomainByCode) in BMfgAddress>
find first tqAdMstrByDomainByCode no-lock no-error.
if available tqAdMstrByDomainByCode
then do:
assign vcMessageText = #T-26'Code $1 is already in use in domain $3 - address type $2':100(63675)T-26#
oiReturnStatus = (if oiReturnStatus < 0 then oiReturnStatus else 1).
<M-23 run SetMessage
(input vcMessageText (icMessage),
input t_sDebtor.DebtorCode + chr(2) + tqAdMstrByDomainByCode.tcad_type + chr(2) + tqAdmstrByDomainByCode.tcad_domain (icArguments),
input 't_sDebtor.DebtorCode':U (icFieldName),
input t_sDebtor.DebtorCode (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QADFIN-4540':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if tqAdMstrByDomainByCode.tcad_bus_relation <> t_sDebtor.tcBusinessRelationCode
then do:
assign vcMessage = #T-43'Business Relation Codes must be the same':100(61711)T-43#
oiReturnStatus = -1.
<M-45 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-6366':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
return.
end.
end. /* available tqAdMstrByDomainByCode */
end. /* for each tqDomainBySharedSetDomain */
end. /* for each t_sDebtor where */
end. /* if vlReplicationEnabled */
/* Not allow a customer be deleted if the customer is in use as a shipto for another customer. */
for each t_sDebtor where
t_sDebtor.tc_Status = "D":U:
<Q-52 run DebtorShipToForDebtorByIsDebtor (all) (Read) (NoCache)
(input ?, (DebtorID)
input true, (DebtorShiptoIsDebtor)
input t_sDebtor.DebtorCode, (DebtorShiptoCode)
input viCompanyId, (CompanyId)
output dataset tqDebtorShipToForDebtorIsDebtor) in BDebtorShipTo>
find first tqDebtorShipToForDebtorIsDebtor no-lock no-error.
if available tqDebtorShipToForDebtorIsDebtor
then do:
assign vcMessage = #T-54'The customer cannot be deleted because it is in use as a Ship-To for another customer.':90(64343)t-54#
oiReturnStatus = -1.
<M-53 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6786':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
return.
end. /* if available tqDebtorShipToForDebtorIsDebtor */
end. /* t_sDebtor.tc_Status = "D":U */
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.