Page 1 of 1
Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Posted: 2020-09-07 05:46
by afayez
Dears,
Good day,
I need to prevent update for the record, if a specified filed value is more than zero.
Also i need to prevent adding a child record for a specified child table (not all the child tables) if the specified filed value in the parent table is more than zero.
I tried the below code in the "qtn.php" in the hooks folder, where is "qtn" is my table name. but it works only with an editable field, and it didn't work with the auto calculated field.
function qtn_before_update(&$data, $memberInfo, &$args) {
if( $data['onex'] > 0 ) return FALSE;
return TRUE;
}
"onex" is an editable field, the previous code works well.
but when i put $data['sign_count'] which is a calculated field, it doesn't work.
the auto calculated field contains:
SELECT
COUNT(`digital_signatures`.`id_sign`)
FROM
`qtn` LEFT JOIN
`digital_signatures` ON `qtn`.`id_qtn` = `digital_signatures`.`id_qtn`
WHERE
`qtn`.`id_qtn` = '%ID%'
Please support
Thanks
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Posted: 2020-09-07 06:19
by jsetzer
Please check if
$data contains "sign_count" at all.
Code: Select all
function TABLENAME_before_insert(&$data, $memberInfo, &$args)
{
echo '<pre>';
var_dump($data);
echo '</pre>';
exit;
return TRUE;
}
If I remember right,
readonly fields are
not being passed to *_before_* hooks.
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Posted: 2020-09-07 08:38
by afayez
jsetzer wrote: ↑2020-09-07 06:19
Please check if
$data contains "sign_count" at all.
Code: Select all
function TABLENAME_before_insert(&$data, $memberInfo, &$args)
{
echo '<pre>';
var_dump($data);
echo '</pre>';
exit;
return TRUE;
}
If I remember right,
readonly fields are
not being passed to *_before_* hooks.
Yes Dear jsetzer, The read only field did not appears a below:
array(19) {
["date"]=>
string(8) "2020-9-6"
["subject"]=>
string(0) ""
["customer"]=>
string(1) "1"
["attn"]=>
string(0) ""
["location"]=>
string(0) ""
["status"]=>
string(10) "PO waiting"
["sales_man"]=>
string(0) ""
["sales_tel"]=>
string(0) ""
["sales_email"]=>
string(0) ""
["payment"]=>
string(15) "100% in advance"
["execution"]=>
string(46) "During 1-2 week from receiving the site ready."
["offer_validity"]=>
string(7) "15 Days"
["terms"]=>
string(81) "15 NOT including VAT - All prices in Saudi Riyal - NOT including civil works"
["stamp"]=>
string(1) "2"
["myheader"]=>
string(1) "2"
["myfooter"]=>
string(1) "2"
["onex"]=>
string(1) "0"
["selectedID"]=>
string(1) "1"
["documents"]=>
string(0) ""
}
can i make a SQL inquiry inside the PHP code? like below:
If yes, please help me for the right formula.
function tablename_before_update(&$data, $memberInfo, &$args){
$get_my_value = sqlValue("?????????????????????'");
if($get_my_value > 0 ) return FALSE;
return TRUE;
}
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Posted: 2020-09-07 08:52
by afayez
afayez wrote: ↑2020-09-07 08:38
can i make a SQL inquiry inside the PHP code? like below:
If yes, please help me for the right formula.
function tablename_before_update(&$data, $memberInfo, &$args){
$get_my_value = sqlValue("?????????????????????'");
if($get_my_value > 0 ) return FALSE;
return TRUE;
}
This is the SQL auto calculated from the field "sign_count" from the table "qtn"
SELECT
COUNT(`digital_signatures`.`id_sign`)
FROM
`qtn` LEFT JOIN
`digital_signatures` ON `qtn`.`id_qtn` = `digital_signatures`.`id_qtn`
WHERE
`qtn`.`id_qtn` = '%ID%'
download/file.php?mode=view&id=1847
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Posted: 2020-09-07 16:11
by pbottcher
Hi,
try
Code: Select all
$get_my_value = sqlValue("SELECT COUNT(`digital_signatures`.`id_sign`) FROM `qtn` LEFT JOIN `digital_signatures` ON `qtn`.`id_qtn` =
digital_signatures`.`id_qtn` WHERE `qtn`.`id_qtn` = ".$data['selectedID']);
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Posted: 2020-09-08 08:41
by afayez
Thanks a lot dear pböttcher

Your code helped me, it worked with little modification that i took the SQL value of the read only field
"sign_count" instead of recalculating the value.
$get_my_value = sqlValue("SELECT `sign_count` from `qtn` where `id_qtn`='{$data['selectedID']}'");
if( $get_my_value > 0 ) return FALSE;
Can i prevent adding any new child record for the table
"qtn_items" based on the same previous rule
if( $get_my_value > 0 ) ?
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Posted: 2020-09-08 19:52
by pbottcher
Hi,
gald it worked out. Yes you can use the same also in the child record handling. Just put it into the correct hooks -> before_insert function.