I am trying to prevent more than three records being written to a particular table i.e. TimeSheetMissed. I figured out using the AppGini documentation that the best place was to modify the hooks/TimeSheetMissed.php file _before_insert hook.
The behaviour is that it ignores my code, drops straight through and creates a record. I guess I might have an error in my code but despite many iterations iterations I cannot figure it out. Could someone help please?
The table (TimeSheetMissed) contains the following fields (non calculated fields are not shown):-
TSMSID (int 11, PK)
TSHDRID (int 11). This field relates it to a TimeSheet Header record
Reason (varchar 40)
ApptDate (Date)
StartTime (Time)
EndTime (Time)
DateInformed (Date)
TimeInformed (Time)
Code: Select all
function TimeSheetMissed_before_insert(&$data, $memberInfo, &$args) {
$tshdrid = $data['TSHDRID'];
$numrecords = sqlValue("SELECT COUNT('TSHDRID') FROM 'TimeSheetMissed' WHERE 'TSHDRID' = $tshdrid");
/* $numrecords = sqlValue("SELECT COUNT('TSHDRID') FROM 'TimeSheetMissed' WHERE 'TSHDRID' = '{$data['TSHDRID']}'"); */
if($numrecords > 3){
$args['error_message'] = 'Error: Only three missed appointments per timesheet are allowed';
return FALSE;
}
return TRUE;
}