Bug #25: Deleting a sale/receiving would not effect the stock/quantity.

This commit is contained in:
Malte Srocke
2015-01-24 19:44:19 +01:00
parent 606eb01a67
commit 7544aae394
3 changed files with 29 additions and 2 deletions

View File

@@ -47,5 +47,20 @@ class Item_quantities extends CI_Model
}
return $result;
}
/*
* changes to quantity of an item according to the given amount.
* if $quantity_change is negative, it will be subtracted,
* if it is positive, it will be added to the current quantity
*/
function change_quantity($item_id, $location_id, $quantity_change)
{
$quantity_old = $this->get_item_quantity($item_id, $location_id);
$quantity_new = $quantity_old->quantity + intval($quantity_change);
$location_detail = array('item_id'=>$item_id,
'location_id'=>$location_id,
'quantity'=>$quantity_new);
return $this->save($location_detail,$item_id,$location_id);
}
}
?>

View File

@@ -137,11 +137,17 @@ class Receiving extends CI_Model
'trans_items'=>$item['item_id'],
'trans_user'=>$employee_id,
'trans_comment'=>'Deleting sale ' . $receiving_id,
'trans_inventory'=>$item['quantity_purchased']
'trans_location'=>$item['item_location'],
'trans_inventory'=>$item['quantity_purchased']*-1
);
// update inventory
$this->Inventory->insert($inv_data);
// update quantities
$this->Item_quantities->change_quantity($item['item_id'],
$item['item_location'],
$item['quantity_purchased']*-1);
}
}
// delete all items

View File

@@ -184,11 +184,17 @@ class Sale extends CI_Model
'trans_items'=>$item['item_id'],
'trans_user'=>$employee_id,
'trans_comment'=>'Deleting sale ' . $sale_id,
'trans_inventory'=>$item['quantity_purchased']
'trans_location'=>$item['item_location'],
'trans_inventory'=>$item['quantity_purchased']*-1
);
// update inventory
$this->Inventory->insert($inv_data);
// update quantities
$this->Item_quantities->change_quantity($item['item_id'],
$item['item_location'],
$item['quantity_purchased']*-1);
}
}
// delete all items