Dear all..
I try to make an inventory control, with FIFO(first in first out) base, but I have a problem with the next record.
this is the code i make :
[PHP]$db = new clsDBMassimo;
$product_id = $Stock->product_id->GetValue();
$AmOrdered = $Stock->stock_out_un it->GetValue();
//check if the stock is enough
$sql = "SELECT SUM(stock_in_un it) as Total FROM stock_level WHERE product_id = $product_id";
$db->query($sql);
$result = $db->next_record( );
if($result) ($Total = $db->f("Total"));
//if stock not enough, then cancel insert and give error message, but i still have an error
if($Total < $AmOrdered){
$Stock->Errors->addError("Stoc k Not Enough");=>in this part also have problem.event
$db->close(); though I already add an error, but stock out still inserted on table.any suggestion?
}else{ //if the stock is enough then select from table stock_level
$sql = "SELECT * FROM stock_level WHERE product_id = $product_id ORDER BY in_date";
$db->query($sql);
$result= $db->next_record( );
$IDnya = $db->f("stock_level _id");
$AmOnHand = $db->f("stock_in_un it");
while($db->next_record()) {
//loop as long as amount ordered > 0
while ($AmOrdered > 0){
if($AmOrdered < $AmOnHand){
$Res = $AmOnHand - $AmOrdered;
$update = "UPDATE stock_level SET stock_in_unit = $Res where stock_level_id = $IDnya";
$db->query($update) ;
$AmOrdered = 0;
}else{
$AmOrdered = $AmOrdered - $AmOnHand;
$update = "UPDATE stock_level SET stock_in_unit = 0 where stock_level_id = $IDnya";
$db->query($update) ;
//here should be move to the next record to get the next stock, but can not move to next record
}
}
}
$db->close();
} [/PHP]
Please give any suggestions, for the error I got or for the code structure. any helps are appreciated.
Thanks a lot
I try to make an inventory control, with FIFO(first in first out) base, but I have a problem with the next record.
this is the code i make :
[PHP]$db = new clsDBMassimo;
$product_id = $Stock->product_id->GetValue();
$AmOrdered = $Stock->stock_out_un it->GetValue();
//check if the stock is enough
$sql = "SELECT SUM(stock_in_un it) as Total FROM stock_level WHERE product_id = $product_id";
$db->query($sql);
$result = $db->next_record( );
if($result) ($Total = $db->f("Total"));
//if stock not enough, then cancel insert and give error message, but i still have an error
if($Total < $AmOrdered){
$Stock->Errors->addError("Stoc k Not Enough");=>in this part also have problem.event
$db->close(); though I already add an error, but stock out still inserted on table.any suggestion?
}else{ //if the stock is enough then select from table stock_level
$sql = "SELECT * FROM stock_level WHERE product_id = $product_id ORDER BY in_date";
$db->query($sql);
$result= $db->next_record( );
$IDnya = $db->f("stock_level _id");
$AmOnHand = $db->f("stock_in_un it");
while($db->next_record()) {
//loop as long as amount ordered > 0
while ($AmOrdered > 0){
if($AmOrdered < $AmOnHand){
$Res = $AmOnHand - $AmOrdered;
$update = "UPDATE stock_level SET stock_in_unit = $Res where stock_level_id = $IDnya";
$db->query($update) ;
$AmOrdered = 0;
}else{
$AmOrdered = $AmOrdered - $AmOnHand;
$update = "UPDATE stock_level SET stock_in_unit = 0 where stock_level_id = $IDnya";
$db->query($update) ;
//here should be move to the next record to get the next stock, but can not move to next record
}
}
}
$db->close();
} [/PHP]
Please give any suggestions, for the error I got or for the code structure. any helps are appreciated.
Thanks a lot
Comment