calculated field fuctions works only on the first run

prettem

Member

Your current DaDaBIK version​

You are using DaDaBIK version 11.4-Elba enterprise, installed on 09.03.2022 (installation code: 1780462288396de6b1), the latest version of DaDaBIK is 11.4-Elba released on 28.02.2022

You are running the latest release of DaDaBIK

In case you want to upgrade to a more powerful edition (from Pro to Enterprise/Platinum, from Enteprise to Platinum) please contact us.

System info​

PHP Version: 7.3.27

mysql version: 5.7.33-0ubuntu0.16.04.1

Web server: Apache

Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36 OPR/84.0.4316.31


Hello,
please support me with this question, I wrote the below function, it calculates the invoice number. It works fine wenn I create a new entry in the
table rechnung, I can store it to the table and the value of the invoice number is available.
But when I go to edit form and store again, the $abo_nr (1000X) is cutting off. The field value is correctly shown, but its not stored in the database

edit form shows RE22-04-26-1000X why is the value 1000X deleted from my table
database stores only RE22-04-26-

Thank you very much and best regards
Manuel


function dadabik_rechnungsnummer ($params){
global $conn;
$where_value = $params['Abo_id'];
$sql = "SELECT abo_nummer FROM Abos WHERE ID = :where_value";
$res_prepare = prepare_db($conn, $sql);
$res_bind = bind_param_db($res_prepare, ':where_value', $where_value);
$res = execute_prepared_db($res_prepare,0);
$row = fetch_row_db($res_prepare);
$abo_nr = $row['abo_nummer'];
if ($params['ReDatum'] !== ' ' && !is_null ($params['ReDatum']) ){
$jahr = substr($params['ReDatum'], 2);
if ( $params['Type'] === 'Rechnung' )
<------>{ $rechnungsnummer = sprintf("RE%s-%s",$jahr,$abo_nr);}
else
<------>{$rechnungsnummer = sprintf("MA%s-%s",$jahr,$abo_nr);}
return $rechnungsnummer;}
else {return NULL;}
}

1650971349725.png

1650970727594.png
 

stefank

New member
Dear Manuel,

I am not quite sure about your problem. But maybe you can do some kind of debugging of the result of your sql query. I am using an intermediate return for debugging step by step at calculation fields.

Best regards,
Stefan.
 
Last edited:

prettem

Member
Hello Stefan,
thanks for your reply. I tried to remove the IF statements, but no change. When I edit the record, the $abo_nr is shown anyway, but not stored in the database. the sql query itself is ok, I can test it in phpmyadmin with response ok. How can I go with this step by step debugging you talked about?

best regards
Manuel
 

prettem

Member
solved
after several tries, I found a rights issue. I dont know why exactly, but the form need a edit right for the search field (where_value)

1651106491960.png
 

stefank

New member
Hello Stefan,
thanks for your reply. I tried to remove the IF statements, but no change. When I edit the record, the $abo_nr is shown anyway, but not stored in the database. the sql query itself is ok, I can test it in phpmyadmin with response ok. How can I go with this step by step debugging you talked about?

best regards
Manuel
Dear Manual,
you found the solution, but however I want to answer your question - for debugging I am adding let's say a text field to the database and use the calculate field function then for this text field. For debuging I use then not the final return value I use the return command in between to get an overview about eg. the sql string, the internal calculations, ....
Best regards
Stefan
 
Top