Skip to content

Commit

Permalink
Invoice and bill create/update empty tax issue solved.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Nov 7, 2018
1 parent 404c5ca commit f372e36
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 36 deletions.
18 changes: 10 additions & 8 deletions app/Jobs/Expense/CreateBill.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ public function handle()
$sub_total += $bill_item->total;

// Set taxes
foreach ($bill_item->item_taxes as $item_tax) {
if (isset($taxes) && array_key_exists($item_tax['tax_id'], $taxes)) {
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
} else {
$taxes[$item_tax['tax_id']] = [
'name' => $item_tax['name'],
'amount' => $item_tax['amount']
];
if ($bill_item->item_taxes) {
foreach ($bill_item->item_taxes as $item_tax) {
if (isset($taxes) && array_key_exists($item_tax['tax_id'], $taxes)) {
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
} else {
$taxes[$item_tax['tax_id']] = [
'name' => $item_tax['name'],
'amount' => $item_tax['amount']
];
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion app/Jobs/Expense/CreateBillItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,12 @@ public function handle()
'total' => $item_amount,
]);

$bill_item->item_taxes = false;
$bill_item->inclusives = false;
$bill_item->compounds = false;

// set item_taxes for
if (!empty($this->data['tax_id'])) {
// set item_taxes for
$bill_item->item_taxes = $item_taxes;
$bill_item->inclusives = $inclusives;
$bill_item->compounds = $compounds;
Expand Down
18 changes: 10 additions & 8 deletions app/Jobs/Expense/UpdateBill.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ public function handle()
$sub_total += $bill_item->total;

// Set taxes
foreach ($bill_item->item_taxes as $item_tax) {
if (isset($taxes) && array_key_exists($item_tax['tax_id'], $taxes)) {
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
} else {
$taxes[$item_tax['tax_id']] = [
'name' => $item_tax['name'],
'amount' => $item_tax['amount']
];
if ($bill_item->item_taxes) {
foreach ($bill_item->item_taxes as $item_tax) {
if (isset($taxes) && array_key_exists($item_tax['tax_id'], $taxes)) {
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
} else {
$taxes[$item_tax['tax_id']] = [
'name' => $item_tax['name'],
'amount' => $item_tax['amount']
];
}
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions app/Jobs/Income/CreateInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ public function handle()
$sub_total += $invoice_item->total;

// Set taxes
foreach ($invoice_item->item_taxes as $item_tax) {
if (isset($taxes) && array_key_exists($item_tax['tax_id'], $taxes)) {
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
} else {
$taxes[$item_tax['tax_id']] = [
'name' => $item_tax['name'],
'amount' => $item_tax['amount']
];
if ($invoice_item->item_taxes) {
foreach ($invoice_item->item_taxes as $item_tax) {
if (isset($taxes) && array_key_exists($item_tax['tax_id'], $taxes)) {
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
} else {
$taxes[$item_tax['tax_id']] = [
'name' => $item_tax['name'],
'amount' => $item_tax['amount']
];
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion app/Jobs/Income/CreateInvoiceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,12 @@ public function handle()
'total' => $item_amount,
]);

$invoice_item->item_taxes = false;
$invoice_item->inclusives = false;
$invoice_item->compounds = false;

// set item_taxes for
if (!empty($this->data['tax_id'])) {
// set item_taxes for
$invoice_item->item_taxes = $item_taxes;
$invoice_item->inclusives = $inclusives;
$invoice_item->compounds = $compounds;
Expand Down
18 changes: 10 additions & 8 deletions app/Jobs/Income/UpdateInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ public function handle()
$sub_total += $invoice_item->total;

// Set taxes
foreach ($invoice_item->item_taxes as $item_tax) {
if (isset($taxes) && array_key_exists($item_tax['tax_id'], $taxes)) {
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
} else {
$taxes[$item_tax['tax_id']] = [
'name' => $item_tax['name'],
'amount' => $item_tax['amount']
];
if ($invoice_item->item_taxes) {
foreach ($invoice_item->item_taxes as $item_tax) {
if (isset($taxes) && array_key_exists($item_tax['tax_id'], $taxes)) {
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
} else {
$taxes[$item_tax['tax_id']] = [
'name' => $item_tax['name'],
'amount' => $item_tax['amount']
];
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/expenses/bills/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@stack('taxes_td_start')
<td {{ $errors->has('item.' . $item_row . '.tax_id') ? 'class="has-error"' : '' }}>
@stack('tax_id_input_start')
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, empty($item) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, (empty($item) || empty($item->tax_id)) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
{!! $errors->first('item.' . $item_row . '.tax_id', '<p class="help-block">:message</p>') !!}
@stack('tax_id_input_end')
</td>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/incomes/invoices/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@stack('taxes_td_start')
<td {{ $errors->has('item.' . $item_row . '.tax_id') ? 'class="has-error"' : '' }}>
@stack('tax_id_input_start')
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, empty($item) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, (empty($item) || empty($item->tax_id)) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
{!! $errors->first('item.' . $item_row . '.tax_id', '<p class="help-block">:message</p>') !!}
@stack('tax_id_input_end')
</td>
Expand Down

0 comments on commit f372e36

Please sign in to comment.