I am doing a api
to change the status
of an item within an inventory, for certain processes the change can be applied.
else if(isset($_POST['id']) && isset($_POST['x']))
{
$connection = new MySqlServerConnection();
$query1 = 'SELECT quantity-2, reorder_Level FROM inventory_list WHERE id= ?';
$result1 = $connection->executeQuery($query1,array($_POST['id']));
echo $result1[0][0];
echo $result1[0][1];
if (intval($result1[0][0]) == intval($result1[0][1]))
{
$query = 'UPDATE inventory_list SET status = 2 WHERE id = ?';
$result = $connection->executeNonQueryWithReturn($query,array($_POST['id']));
}
else
{
$query = 'UPDATE Supplies SET status = 1 WHERE id = ?';
$result = $connection->executeNonQueryWithReturn($query,array($_POST['id']));
}
if ($result == 1)
{
echo json_encode(array(
'status' => '0',
'errorMessage' => 'articulo cambio status'
));
}
else
{
echo json_encode(array(
'status' => '2',
'errorMessage' => 'articulo no cambio status'
));
}
}
else if(isset($_POST['id']))
{
$connection = new MySqlServerConnection();
$query1 = 'SELECT quantity, reorder_Level FROM inventory_list WHERE id = ?';
$result1 = $connection->executeQuery($query1,array($_POST['id']));
if (intval($result1[0][0]) <= intval($result1[0][1]))
{
$query = 'UPDATE inventory_list SET status = 3 WHERE id = ?';
$result = $connection >executeNonQuery($query,array($_POST['id']));
}
else
{
$query = 'UPDATE inventory_list SET status = 0 WHERE id = ?';
$result = $connection->executeNonQuery($query,array($_POST['id']));
}
if ($result == 0)
{
echo json_encode(array(
'status' => '0',
'errorMessage' => 'articulo cambio status'
));
}
else
{
echo json_encode(array(
'status' => '2',
'errorMessage' => 'articulo no cambio status'
));
}
}
This is based on quantity
and reorder_level(cantidad minima)
, in the first query I'm trying to change it to status 2
if my current quantity is about to end with% difference% co_, so the rest is that amount from the beginning.
Example: If my 2
is reorder_level
and my current quantity is 2
, subtracting 4
from the beginning this would be equal to my minimum amount in stock so there is a difference of 2
for this to end, and change the% co_from% to 2.
Otherwise, change to 2
status
.
In the next status
if my quantity is equal to or less than my 1
then it changes to else if
, because it is below the minimum, otherwise it changes to reorder_level
0 = the article is inactive.
1 = the article is active.
2 = the article is about to end.
3 = the article is below its minimum.
In code does not give any error, executes but does not fulfill the function, does not change status 3
, the intermediate processes may be that add more units to status 0
or be removed. That's when you run the status
.