project QadFinancials > class BCompany > 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/bcompany.p)
/* StopExternalInstances */
<M-34 run StopExternalInstances (output viFcReturnSuper (oiReturnStatus)) in BCompany>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
<ANCESTOR-CODE>
/* Validate that the domain is not setup complete */
for each t_sCompany where
t_sCompany.tc_Status = "C":U:
find first t_iCompany where
t_iCompany.tc_Rowid = t_sCompany.tc_Rowid
no-lock no-error.
if not available t_iCompany
then next.
/* Only allow deactivate of company if no pending SO's or unposted transactions */
if(t_iCompany.CompanyIsActive <> t_sCompany.CompanyIsActive and
t_sCompany.CompanyIsActive = false)
then do:
/* Check for existing sales orders */
<Q-22 assign vlFcQueryRecordsAvailable = SalesOrderByDomainCompany (NoCache)
(input t_sCompany.tcDomainCode, (DomainCode)
input t_sCompany.CompanyCode, (CompanyCode)) in BMfgSalesOrder >
if(vlFcQueryRecordsAvailable <> false)
then do:
assign oiReturnStatus = -1
vcMessage = trim(#T-23'You cannot deactivate a company which has pending sales orders.':255(63713)T-23#).
<M-24 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input 'tCompany.CompanyIsActive':U (icFieldName),
input t_sCompany.CompanyIsActive (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-6553':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
end. /* if(vlFcQueryRecordsAvailable) */
/* Check for unposted transactions */
<Q-25 assign vlFcQueryRecordsAvailable = TransactionByDateType (NoCache)
(input t_sCompany.tcDomainCode, (Domain)
input t_sCompany.CompanyCode, (Entity)
input ?, (Type)
input ?, (StartDate)
input ?, (EndDate)) in BMfgUnpostedTransDetail >
if(vlFcQueryRecordsAvailable <> false)
then do:
assign oiReturnStatus = -1
vcMessage = #T-26'You cannot deactivate a company which has pending un-posted transactions.':255(63714)T-26#.
<M-27 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input 'tCompany.CompanyIsActive':U (icFieldName),
input t_sCompany.CompanyIsActive (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'QadFin-6554':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
end. /* if(vlFcQueryRecordsAvailable) */
end. /* if(t_iCompany.CompanyIsActive <> t_sCompanyIsActive... */
if t_iCompany.Domain_ID <> t_sCompany.Domain_ID
then do:
<Q-11 run DomainPropertyByDomain (all) (Read) (NoCache)
(input t_iCompany.Domain_ID, (DomainID)
output dataset tqDomainPropertyByDomain) in BDomainProperty >
find first tqDomainPropertyByDomain no-lock no-error.
if available tqDomainPropertyByDomain and
tqDomainPropertyByDomain.tlDomainPropertyIsSetupCompl = true
then do:
assign oiReturnStatus = -1
vcMessage = trim(#T-13'You cannot change the domain of an entity when the domain setup is complete.':200(32060)T-13#).
<M-12 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 't_sCompany.tcDomainCode':U (icFieldName),
input t_sCompany.tcDomainCode (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input t_sCompany.tc_rowid (icRowid),
input 'QadFin-5166':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
end.
/* Check if double employeecodes exist when you change the domain of a company. */
<Q-30 run EmployeeByEmployee (all) (Read) (NoCache)
(input t_sCompany.Company_ID, (CompanyId)
input 0, (Employee_ID)
input '':U, (EmployeeCode)
output dataset tqEmployeeByEmployee) in BEmployee >
for each tqEmployeeByEmployee where
tqEmployeeByEmployee.tiCompany_ID = t_sCompany.Company_ID
no-lock:
<Q-29 assign vlFcQueryRecordsAvailable = EmployeeForDomain (NoCache)
(input 0, (CompanyId)
input tqEmployeeByEmployee.tcEmployeeCode, (EmployeeCode)
input tqEmployeeByEmployee.tc_Rowid, (SkipRowid)
input t_sCompany.Domain_ID, (DomainId)) in BEmployee >
if vlFcQueryRecordsAvailable <> false
then do:
assign vcMessage = trim(substitute(#T-31'The employee code &1 already exists in this domain.':100(63804)T-31#, trim(tqEmployeeByEmployee.tcEmployeeCode) ))
oiReturnStatus = -1.
<M-32 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tCompany.tcDomainCode':U (icFieldName),
input t_sCompany.tcDomainCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sCompany.tc_Rowid (icRowid),
input 'QadFin-6585':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
end.
end. /* for each tqEmployeePrim ... */
end.
end.
/* Validate that the domain is active */
for each t_sCompany where
t_sCompany.tc_status = "N":U or
t_sCompany.tc_status = "C":U:
<Q-14 run DomainsByCode (all) (Read) (NoCache)
(input t_sCompany.Domain_ID, (DomainID)
input '':U, (DomainCode)
output dataset tqDomainsByCode) in BDomain >
for each tqDomainsByCode:
if tqDomainsByCode.tlDomainIsActive <> true
then do:
<M-15 run SetMessage
(input #T-16'The selected Domain is not active':100(31731)T-16# (icMessage),
input '':U (icArguments),
input 'tCompany.Domain_ID':U (icFieldName),
input t_sCompany.CompanyDomain (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sCompany.tc_Rowid (icRowid),
input 'QadFin-5167':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
assign oiReturnStatus = -1.
end.
end.
/* validate the company code, ensure that it does not contain characters that are invalid for */
/* use in Windows directory names */
if index(t_sCompany.CompanyCode, '~\':U) <> 0 or
index(t_sCompany.CompanyCode, '/':U) <> 0 or
index(t_sCompany.CompanyCode, ':':U) <> 0 or
index(t_sCompany.CompanyCode, '*':U) <> 0 or
index(t_sCompany.CompanyCode, '?':U) <> 0 or
index(t_sCompany.CompanyCode, '"':U) <> 0 or
index(t_sCompany.CompanyCode, '<':U) <> 0 or
index(t_sCompany.CompanyCode, '>':U) <> 0 or
index(t_sCompany.CompanyCode, '|':U) <> 0
then do:
assign oiReturnStatus = -1
vcMessage = trim(#T-20'The Entity Code can not contain any of the following characters:':100(61050)T-20#)
vcMessage = vcMessage + '~\ / : * ? " < > |':U.
<M-21 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tCompany.CompanyCode':U (icFieldName),
input t_sCompany.CompanyCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sCompany.tc_rowid (icRowid),
input 'QadFin-6242':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
end. /* end of if index <> 0 */
end.
/* Warnings */
if oiReturnStatus >= 0
then do:
for each t_sCompany:
find first t_iCompany where t_iCompany.tc_Rowid = t_sCompany.tc_Rowid no-lock no-error.
/* Check if the company is being linked to the system domain */
if t_sCompany.tc_Status = "N":U
or (available t_iCompany and t_iCompany.Domain_ID <> t_sCompany.Domain_ID)
then do:
<Q-6 assign vlFcQueryRecordsAvailable = DomainsByDomainType (NoCache)
(input t_sCompany.Domain_ID, (DomainID)
input {&DOMAINSDOMAINTYPE-SYSTEM}, (DomainType)) in BDomain >
if vlFcQueryRecordsAvailable
then do:
assign vcMessage = trim(substitute(#T-4'The entity &1 will be linked or is already linked to the system domain.':200(64347)T-4#, t_sCompany.CompanyCode))
oiReturnStatus = 1.
<M-5 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 't_sCompany.tcDomainCode':U (icFieldName),
input t_sCompany.tcDomainCode (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input t_sCompany.tc_Rowid (icRowid),
input 'QadFin-4944':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input 't_sCompany.tc_Status=' + t_sCompany.tc_Status (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
end.
end.
/* Check if the domain setup has been confirmed */
if available (t_iCompany) and (t_iCompany.Domain_ID <> t_sCompany.Domain_ID)
then do:
<Q-7 run DomainPropertyByDomain (all) (Read) (NoCache)
(input t_sCompany.Domain_ID, (DomainID)
output dataset tqDomainPropertyByDomain) in BDomainProperty >
for first tqDomainPropertyByDomain:
if tqDomainPropertyByDomain.tlDomainPropertyIsSetupCompl = true
then do:
assign vcMessage = trim(substitute(#T-8'The setup of domain &1 is complete. This domain cannot be changed after you save this record. Is the domain setup correct?':200(42755)T-8#, t_sCompany.tcDomainCode))
oiReturnStatus = 1.
<M-10 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 't_sCompany.tcDomainCode':U (icFieldName),
input t_sCompany.tcDomainCode (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input t_sCompany.tc_Rowid (icRowid),
input 'QadFin-4964':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
end. /* if tqDomainPropertyByDomain.tlDomainPropertyIsSetupCompl = true */
end. /* for first tqDomainPropertyByDomain */
end. /* if available */
if t_sCompany.tc_Status = "N":U
then do:
assign oiReturnStatus = 1
vcMessage = #T-17'Is all information correct? The entity $1 cannot be deleted after saving.':200(49207)T-17#.
<M-18 run SetMessage
(input vcMessage (icMessage),
input t_sCompany.CompanyCode (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input t_sCompany.tc_Rowid (icRowid),
input 'QadFin-5397':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
end.
end. /* for each t_sCompany */
end. /* if oiReturnStatus >= 0 */