project QadFinancials > class BLayer > 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/blayer.p)
<ANCESTOR-CODE>
if oiReturnStatus < 0
then return.
for each t_sLayer where
t_sLayer.tc_Status <> "":U:
/*Error: only one official layer allowed and it should be active*/
if t_sLayer.LayerTypeCode = {&LAYERTYPECODE-OFFICIAL}
then do:
if t_sLayer.LayerIsActive <> true and
t_sLayer.tc_Status <> "":U and
t_sLayer.tc_Status <> "D":U
then do :
assign vcMessage = trim(#T-22'The official layer cannot be deactivated.':255(69500)t-22#)
oiReturnStatus = -1.
<M-21 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tLayer.LayerIsActive':U (icFieldName),
input t_sLayer.LayerIsActive (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sLayer.tc_Rowid (icRowid),
input 'QadFin-8124':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BLayer>
end. /* if t_sLayer.LayerIsActive <> true */
if t_sLayer.tc_Status = "N":U
then do :
assign vcLayerTypeOfficial = {&LAYERTYPECODE-OFFICIAL}.
<Q-1 assign vlFcQueryRecordsAvailable = LayerByCodeTypeCode (NoCache)
(input vcLayerTypeOfficial, (LayerTypeCode)
input ?, (LayerCode)) in BLayer >
/*in fact vlFcQueryRecordsAvailable should always be true, for ? means that there is more that one Official layer*/
if vlFcQueryRecordsAvailable = true or
vlFcQueryRecordsAvailable = ?
then do:
assign vcMessage = trim(substitute(#T-13'Cannot create a new &1 layer.':200(2776)t-13#, trim({&LAYERTYPECODE-OFFICIAL-TR}))) + chr(10) +
trim(#T-14'Only one layer of this type is allowed.':200(2777)t-14#) + chr(10) +
program-name(1)
oiReturnStatus = -1.
<M-2 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tLayer.LayerTypeCode':U (icFieldName),
input t_sLayer.LayerTypeCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sLayer.tc_Rowid (icRowid),
input 'QADFIN-17':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BLayer>
end. /* if vlFcQueryRecordsAvailable */
end. /* if t_sLayer.tc_Status = "N":U */
end. /* if t_sLayer.LayerTypeCode = {&LAYERTYPECODE-OFFICIAL} */
/*initially loaded data*/
if t_sLayer.tc_Status = "C":U or
t_sLayer.tc_Status = "D":U
then do:
find first tFcRowidConvert where
tFcRowidConvert.tcFcOldRowid = t_sLayer.tc_Rowid no-error.
if available tFcRowidConvert
then find first t_iLayer where
t_iLayer.tc_Rowid = tFcRowidConvert.tcFcNewRowid no-error.
else find first t_iLayer where
t_iLayer.tc_Rowid = t_sLayer.tc_Rowid no-error.
if not available t_iLayer
then do:
assign vcMessage = "t_iLayer not available.":U + chr(10) + program-name(1)
oiReturnStatus = -1.
<M-3 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-18':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BLayer>
return.
end.
/*Error: cannot change LayerTypeCode if already exists in Journal, Posting, PostingHist*/
if available t_iLayer and
t_sLayer.tc_Status = "C":U and
t_sLayer.LayerTypeCode <> t_iLayer.LayerTypeCode
then do:
assign vcMessage = "":U.
/*check layer existence in Journal*/
<Q-6 assign vlFcQueryRecordsAvailable = JournalByLayerIDJournalID (NoCache)
(input t_sLayer.Layer_ID, (LayerId)
input viCompanyId, (CompanyId)
input ?, (JournalID)) in BJournal >
if vlFcQueryRecordsAvailable = true or
vlFcQueryRecordsAvailable = ?
then assign vcMessage = vcMessage + " ":U + right-trim (#T-15'Daybook':40(4294)T-15#).
/*check layer existence in Posting*/
<Q-8 assign vlFcQueryRecordsAvailable = PostingByLayerID (NoCache)
(input t_sLayer.Layer_ID, (LayerId)
input viCompanyId, (CompanyId)) in BPosting >
if vlFcQueryRecordsAvailable = true or
vlFcQueryRecordsAvailable = ?
then assign vcMessage = vcMessage + " ":U + right-trim (#T-16'Posting':20(63258)T-16#).
/*check layer existence in PostingHist*/
<Q-20 assign vlFcQueryRecordsAvailable = PostingHistByIds (NoCache)
(input viCompanyId, (CompanyId)
input ?, (PostingHistId)
input ?, (CostCentreId)
input ?, (DivisionId)
input ?, (GLId)
input ?, (ProjectId)
input ?, (JournalId)
input t_sLayer.Layer_ID, (LayerId)
input ?, (CurrencyId)
input ?, (IntercoBusinessRelationId)
input ?, (PostingSafCombinedId)) in BPostingHist >
if vlFcQueryRecordsAvailable = true or
vlFcQueryRecordsAvailable = ?
then assign vcMessage = vcMessage + " ":U + right-trim (#T-17'Posting History':20(63259)T-17#).
assign vcMessage = right-trim (vcMessage, ",":U)
vcMessage = trim(substitute (#T-18'Cannot change the layer type of layer &1 from &2 to &3.':200(2781)t-18#, trim(t_sLayer.LayerCode), trim(t_iLayer.LayerTypeCode), trim(t_sLayer.LayerTypeCode))) + chr(10) +
trim(#T-19'The layer is already used in:':200(2782)t-19#) + chr(10) +
trim(vcMessage) + chr(10) +
program-name(1)
oiReturnStatus = -1.
<M-7 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tLayer.LayerTypeCode':U (icFieldName),
input t_sLayer.LayerTypeCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sLayer.tc_Rowid (icRowid),
input 'QADFIN-20':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BLayer>
end.
/* Validation for switching off Additional GL Numbering: if there is any posting that used additional GL number within the layer,
* Additional GL Numbering cannot be switched off for this layer.
*/
if t_iLayer.LayerIsAddGLNbr and not t_sLayer.LayerIsAddGLNbr
then do:
<Q-73 run PostingCheckAddGLNbrByLayerID (all) (Read) (NoCache)
(input ?, (CompanyId)
input t_sLayer.Layer_ID, (LayerID)
output dataset tqPostingCheckAddGLNbrByLayerID) in BPosting >
for first tqPostingCheckAddGLNbrByLayerID:
end.
if available tqPostingCheckAddGLNbrByLayerID
then do:
assign vcMessage = trim(#T-90''You cannot switch off Additional GL Numbering once postings under this layer have already used it.':100(826134963)T-90#)
oiReturnStatus = -1.
<M-75 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input 'Layer.LayerIsAddGLNbr':U (icFieldName),
input t_sLayer.LayerIsAddGLNbr (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'qadfin-252291':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BLayer>
return.
end. /* if available tqPostingCheckAddGLNbrByLayerID */
end. /* if t_iLayer.LayerIsAddGLNbr... */
end.
end.