close #647 Fixed: Problem after editing payed invoice item quantity
This commit is contained in:
parent
b722dee962
commit
40907d8b16
@ -3,6 +3,7 @@
|
||||
namespace App\Jobs\Expense;
|
||||
|
||||
use App\Events\BillUpdated;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Expense\Bill;
|
||||
use App\Models\Expense\BillTotal;
|
||||
use App\Traits\Currencies;
|
||||
@ -52,6 +53,22 @@ class UpdateBill
|
||||
$discount = $this->request['discount'];
|
||||
|
||||
if ($this->request['item']) {
|
||||
$items = $this->bill->items;
|
||||
|
||||
if ($items) {
|
||||
foreach ($items as $item) {
|
||||
if (empty($item->item_id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item_object = Item::find($item->item_id);
|
||||
|
||||
// Decrease stock
|
||||
$item_object->quantity -= (double) $item->quantity;
|
||||
$item_object->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->deleteRelationships($this->bill, 'items');
|
||||
|
||||
foreach ($this->request['item'] as $item) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Jobs\Income;
|
||||
|
||||
use App\Events\InvoiceUpdated;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\InvoiceTotal;
|
||||
use App\Traits\Currencies;
|
||||
@ -53,6 +54,22 @@ class UpdateInvoice
|
||||
$discount = $this->request['discount'];
|
||||
|
||||
if ($this->request['item']) {
|
||||
$items = $this->invoice->items;
|
||||
|
||||
if ($items) {
|
||||
foreach ($items as $item) {
|
||||
if (empty($item->item_id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item_object = Item::find($item->item_id);
|
||||
|
||||
// Increase stock
|
||||
$item_object->quantity += (double) $item->quantity;
|
||||
$item_object->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->deleteRelationships($this->invoice, 'items');
|
||||
|
||||
foreach ($this->request['item'] as $item) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user