MN
Asked
Hi Support,
Please we have errors in the stock quantity of different product. Every minute of each day the stock quantity keep changing. I believe this is a bug.
Please see attached images for details
What could be the course and how can it be resolved please.
Thank you
Please we have errors in the stock quantity of different product. Every minute of each day the stock quantity keep changing. I believe this is a bug.
Please see attached images for details
What could be the course and how can it be resolved please.
Thank you
- MSAnswered**[Michael Nwuzor](/u/mnwuzor)** Hello,
We are still checking the issue and suggestions by [@Enyinnaya Gift](/u/giftedhands4real)
Thank you - MSAnsweredHello [@Enyinnaya Gift](/u/giftedhands4real) and [@Michael Nwuzor](/u/mnwuzor),
I have update the demo with fixed. Can you guys help me check now.
Thank you - EGAnswered**[Mian Saleem](/u/saleem)** This is ok, but it will call `resetSaleActions()` function each time a sale status update button is clicked and I don't see a need for that. Having it as a condition that `resetSaleActions()` function is only called when there is a change in the current sale status is better.
- EGAnswered**[Mian Saleem](/u/saleem)** Well done, I have checked the fix on the demo for both issues, and it is working fine now. But still, consider my suggestion on only calling the `resetSaleActions()` function when there is a change in the current sale status.
- MSAnswered**[Enyinnaya Gift](/u/giftedhands4real)** Yes, you are right. I have reset the `updateStatus` as you suggested.
Methods looks like this now
```php
public function updateStatus($id, $status, $note)
{
$this->db->trans_start();
$sale = $this->getInvoiceByID($id);
$items = $this->getAllInvoiceItems($id);
$cost = [];
if ($status == 'completed' && $sale->sale_status != 'completed') {
foreach ($items as $item) {
$items_array[] = (array) $item;
}
$cost = $this->site->costing($items_array);
}
if ($status != 'completed' && $sale->sale_status == 'completed') {
$this->resetSaleActions($id);
}
if ($this->db->update('sales', ['sale_status' => $status, 'note' => $note], ['id' => $id])) {
if ($status == 'completed' && $sale->sale_status != 'completed') {
$this->db->delete('costing', ['sale_id' => $id]);
foreach ($items as $item) {
$item = (array) $item;
if ($this->site->getProductByID($item['product_id'])) {
$item_costs = $this->site->item_costing($item);
foreach ($item_costs as $item_cost) {
if (isset($item_cost['date']) || isset($item_cost['pi_overselling'])) {
$item_cost['sale_item_id'] = $item['id'];
$item_cost['sale_id'] = $id;
$item_cost['date'] = date('Y-m-d', strtotime($sale->date));
if (!isset($item_cost['pi_overselling'])) {
$this->db->insert('costing', $item_cost);
}
} else {
foreach ($item_cost as $ic) {
$ic['sale_item_id'] = $item['id'];
$ic['sale_id'] = $id;
$ic['date'] = date('Y-m-d', strtotime($sale->date));
if (!isset($ic['pi_overselling'])) {
$this->db->insert('costing', $ic);
}
}
}
}
}
}
if (!empty($cost)) {
$this->site->syncPurchaseItems($cost);
}
$this->site->syncQuantity($id);
}
}
$this->db->trans_complete();
if ($this->db->trans_status() === false) {
log_message('error', 'An errors has been occurred while adding the sale (UpdataStatus:Sales_model.php)');
} else {
return true;
}
return false;
}
```
Thank you for help - EGAnswered**[Mian Saleem](/u/saleem)** Great! Well done.
Please, let me know when you push the update, I told some customers that contacted me on this issue to hold on for the update. - MSAnsweredHello,
I have released the update with fixes.
Thank you - Login to Reply