This topic is locked
[SOLVED]

 IF AND IF Query

8/18/2019 1:05:26 PM
PHPRunner General questions
K
Kay author

I need help or hint for a double query.
I have two tables (products: id, product_id, quantity, product_name) AND (transactions:id, product_id, quantity, item_counter, general_status).
The Table transaction is important here with two columns: general_status (new, ready_to_pick) and item_counter(nicht_abgezogen(not_deducted), abgezogen(deducted)).
That is what i have in the Add page - After record added:

IF($data["general_status"] = "ready_to_pick"){

IF($data["item_counter"] = "abgezogen"){

{

CustomQuery("update tblproducts set quantity = quantity -".$values["quantity"]." where product_id=".$values["product_id"]);

}

}

}
return true;


It subtracts everytime however what for values are setted.
I want to proof the two values and only when the values are general_status = "ready_to_pick" AND item_counter = "abgezogen"

are together has this values, the quantity are deducted over the product_id.
That was a very important step to solute the inventory system.

When the "Coordinator" set this new "order" to ready_to_pick - the picker_worker can do his job and set it later to a picked status AND

the Coordinator has a view over this order <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=26656&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />
PLEASE help me to solve this. THANK YOU!
Kay from Germany

W
wpl 8/18/2019

Kay,
you ar not comparing your values, you are assigning values in your IF-statements. For information about comparison in PHP see
Comparison operators in PHP
Plus, 2 of your curly brackets are superfluous. Your code should read:



IF($data["general_status"] === "ready_to_pick")

{

IF($data["item_counter"] === "abgezogen")

{

CustomQuery("update tblproducts set quantity = quantity -".$values["quantity"]." where product_id=".$values["product_id"]);

}

}


Regards

K
Kay author 8/18/2019

Hello and thank you for your answer.
I have write the code in but it dont deducted any item - no madder how value i set (this or that, that or this and both for the wanted deduction.
Any idea?

W
wpl 8/18/2019

Kay,
I should have asked from where your're fetching the $data elements.
Regards

Sergey Kornilov admin 8/18/2019

Here is the simplified version of this code.

if($data["general_status"] == "ready_to_pick" && if($data["item_counter"] == "abgezogen") {

CustomQuery("update tblproducts set quantity = quantity -".$values["quantity"]." where product_id=".$values["product_id"]);

}


If this doesn't work you can need to troubleshoot your code i.e. print values of $data["general_status"] and $data["item_counter"] on the page.

K
Kay author 8/19/2019

Okay Guys,i have found a bit in this forum and i tried until it worked out.

Thank you first for your help - i will give back now my solution for the community, too.

I'm not a professional, but I think it might be helpful for other newcomers as well, which I find out.

And also Yeah - i forgot the item_counter - why so complicated?
Table 1: id (int, primary key, auto increment), product_id (int), stock (int).

Table 2: id (int, primary key, auto increment), product_id (int), quantity (int), general_status (varchar,50).
For the general_status i used in Designer the Editas Lookup wizard and choice "List of values" (maybe the reason that $values works and $data not, see below)

and save the values "neu" and "ready_to_pick".
If you ADD a new ordered item (here as a test in the table "tblproducts") with a value neu (means new in german) - the item just got saved.
for this i used this code - okay or not - it works ^^ - insert this into the AddPage - After record added:

IF($values["general_status"] == "ready_to_pick")

{

CustomQuery("update tblproducts set stock = stock -".$values["quantity"]." where product_id=".$values["product_id"]);

}



For the normal situation - we add a new value as new, right?
And now the magic moment, put the same code into the EDIT page - After record added.

That result is, when a worker set via EDIT the value from "neu" to "ready_to_pick" the item were deducted from the "Item"-Table "tblproducts".
Hope you can work with this as a little tutorial.

Wish you have a nice afternoon, guys !