This topic is locked

field update value update error (inventory)

5/26/2021 2:54:47 PM
PHPRunner General questions
F
facos79 author

Good morning,
I have recently downloaded the demo version of phprunner and I am seriously considering the purchase. I've always worked with Appgini but phprunner has a lot more interesting options.
Before purchasing the license I would like to evaluate the functioning especially as regards the part relating to the calculations in the fields.

I'm going crazy. I have generated a small database and am running into a computation problem

Below you can see the two tables and the 'disponibilita' field which needs to be updated after a loading / unloading movement (similar to an inventory).

img alt

I wrote this code but I can't figure out what's wrong and why the 'availability' field in table 1 is not updated:

global $conn;

$stockdata = $pageObject->getMasterRecord();
$stockdata =["disponibilita"];

IF($values["carico_scarico"] == "Carico")
{
$newstock = $stockdata["disponibilita"] + $values["quantita"];
}
ELSE
{
$newstock = $stockdata["disponibilita"] - $values["quantita"];

}
$stockUpdate = "UPDATE materieprime SET 'disponibilita' = ".$newstock." where 'id' = ".$values["materiaprimaid"]."";
db_exec($stockUpdate,$conn);

when, after adding the values to the table, the following error appears:

img alt

can someone help me understand where am I wrong?
Thank you very much
(sorry for the english but i am using an automatic translator)

Sergey Kornilov admin 5/26/2021

You need to remove single quotes around field names like 'disponibilita' and 'id'.

Also want to add that using Database API is an easier option and you will avoid making syntax errors like this:
https://xlinesoft.com/phprunner/docs/db_update.htm

F
facos79 author 5/28/2021

Hello, thanks for the help.
I don't know php very well but I would like to understand the dynamics of the code that must be used with phprunner.
I tried to remove the quotes. Now the indicated error no longer appears but the 'disponibilita' calculation is incorrect.
Each time a movement is carried out (Carico / Scarico) in the 'disponibilita' field only the last value is copied.
Example: if 'Carico' a 'quantity' of 4pcs in the 'disponibilita' cell 4 is indicated.
If I later add another 3pcs in the 'disponibilita' cell, 3 is indicated instead of 7.
Where am I wrong?

global $conn;

$stockdata = $pageObject->getMasterRecord();
$stockdata =["disponibilita"];

IF($values["carico_scarico"] == "Carico")
{
$newstock = $stockdata["disponibilita"] + $values["quantita"];
}
ELSE
{
$newstock = $stockdata["disponibilita"] - $values["quantita"];

}
$stockUpdate = "UPDATE materieprime SET disponibilita = ".$newstock." where id = ".$values["materiaprimaid"]."";
db_exec($stockUpdate,$conn);
Sergey Kornilov admin 5/28/2021

There is a lot that you doing wrong here.

  1. $stockdata = $pageObject->getMasterRecord();

You assign the value but you never use it anywhere.

  1. $stockdata =["disponibilita"];

This is not a correct code and I have no idea what it does.

getMasterRecord() function returns an array of fields that belongs to the master record. See examples in the manual

F
facos79 author 5/31/2021

Thanks for the reply. Unfortunately by dint of trying and trying again I was unable to arrive at the solution. The trial version of the software has reached 200 builds and is now no longer usable even if I still have 15 days of the 30 trial.
Thanks anyway. I am only sorry that I was not able to do the calculations in the cells as I wanted to and then buy the license.

Sergey Kornilov admin 5/31/2021

I recommend you contact support directly and we'll find the way to proceed.