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
Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Please check if $data contains "sign_count" at all.
If I remember right, readonly fields are not being passed to *_before_* hooks.
Code: Select all
function TABLENAME_before_insert(&$data, $memberInfo, &$args)
{
echo '<pre>';
var_dump($data);
echo '</pre>';
exit;
return TRUE;
}
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
jsetzer wrote: ↑2020-09-07 06:19Please check if $data contains "sign_count" at all.
If I remember right, readonly fields are not being passed to *_before_* hooks.Code: Select all
function TABLENAME_before_insert(&$data, $memberInfo, &$args) { echo '<pre>'; var_dump($data); echo '</pre>'; exit; return TRUE; }
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.
This is the SQL auto calculated from the field "sign_count" from the table "qtn"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;
}
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
- Attachments
-
- 22.png (209.05 KiB) Viewed 2891 times
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
Hi,
try
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']);
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Prevent update for the record based on filed value. and prevent adding child records for a specified table.
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 ) ?
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.
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.
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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.