mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 04:01:10 -04:00
refactor items tax add and update
This commit is contained in:
@ -55,6 +55,7 @@ class ItemsController extends Controller
|
||||
|
||||
if ($request->has('taxes')) {
|
||||
foreach ($request->taxes as $tax) {
|
||||
$tax['company_id'] = $request->header('company');
|
||||
$item->taxes()->create($tax);
|
||||
}
|
||||
}
|
||||
@ -75,12 +76,16 @@ class ItemsController extends Controller
|
||||
$item->price = $request->price;
|
||||
$item->save();
|
||||
|
||||
$oldTaxes = $item->taxes->toArray();
|
||||
|
||||
foreach ($oldTaxes as $oldTax) {
|
||||
Tax::destroy($oldTax['id']);
|
||||
}
|
||||
|
||||
if ($request->has('taxes')) {
|
||||
foreach ($request->taxes as $tax) {
|
||||
$item->taxes()->updateOrCreate(
|
||||
['tax_type_id' => $tax['tax_type_id']],
|
||||
['amount' => $tax['amount'], 'percent' => $tax['percent'], 'name' => $tax['name']]
|
||||
);
|
||||
$tax['company_id'] = $request->header('company');
|
||||
$item->taxes()->create($tax);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user