0
I got the following Array()
:
Array
(
[0] => stdClass Object
(
[inventory_id] => 1
[product_id] => 1
[order_id] => 0
[product_quantity] => 15 <--------
[notify_quantity] => 1
[total_price] => 690
[others_price] => 33.9
[media_price] => 48.26
[supplier_id] => 1
[product_type] => order
[product_stock_date] => 2019-01-31 11:59:06
[initial_stock] => 1
[type] => E
)
[1] => stdClass Object
(
[inventory_id] => 4
[product_id] => 1
[order_id] => 0
[product_quantity] => 10 <--------
[notify_quantity] => 1
[total_price] => 200
[others_price] => 20
[media_price] => 22
[supplier_id] => 2
[product_type] => purchase
[product_stock_date] => 2019-02-22 15:22:50
[initial_stock] => 0
[type] => E
)
)`
Note that I have product_quantity = 15 e 10
.
I have the $product['qty'] = 20
. This is the amount I am requesting at the time of purchase. Ie I have in stock because adding all are 25 in total items.
So, at the time of assembling the loop, I need to deduct then 15 items from the first and 5 items from the second... in this case, there will be only 5 items left in the second array()
. The problem is: how to do this?
What I tried to:
foreach($suppliers_products as $s_products){
$qty = $s_products->product_quantity;
echo "Qtd total ".$s_products->inventory_id." > ".$qty."<br><br<br>";
if($qty >= $product['qty']){
echo "achou total <br>";
} else {
$s = $product['qty'] - $qty;
echo $s." < faltou > <br>";
echo "<br><br><br>faltou ainda <br>";
}
}
Whereas $suppliers_products is the array()
above.
To deduct in stock, I’m using as a reference PEPS - First that goes in, first out.