diff --git a/app/Http/Controllers/Common/Items.php b/app/Http/Controllers/Common/Items.php
index 414eaa275..6cfc73ebd 100644
--- a/app/Http/Controllers/Common/Items.php
+++ b/app/Http/Controllers/Common/Items.php
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Common;
use App\Http\Controllers\Controller;
use App\Http\Requests\Common\Item as Request;
+use App\Http\Requests\Common\TotalItem as TRequest;
use App\Models\Common\Item;
use App\Models\Setting\Category;
use App\Models\Setting\Currency;
@@ -300,11 +301,11 @@ class Items extends Controller
return response()->json($items);
}
- public function totalItem()
+ public function totalItem(TRequest $request)
{
- $input_items = request('item');
- $currency_code = request('currency_code');
- $discount = request('discount');
+ $input_items = $request->input('item');
+ $currency_code = $request->input('currency_code');
+ $discount = $request->input('discount');
if (empty($currency_code)) {
$currency_code = setting('general.default_currency');
diff --git a/app/Http/Requests/Common/TotalItem.php b/app/Http/Requests/Common/TotalItem.php
new file mode 100644
index 000000000..9e6f8167c
--- /dev/null
+++ b/app/Http/Requests/Common/TotalItem.php
@@ -0,0 +1,42 @@
+ 'required',
+ 'item.*.price' => 'required|amount',
+ 'item.*.currency' => 'required|string|currency',
+ ];
+ }
+
+ public function messages()
+ {
+ return [
+ 'item.*.quantity.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('invoices.quantity'))]),
+ 'item.*.price.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('invoices.price'))]),
+ 'item.*.currency.required' => trans('validation.custom.invalid_currency'),
+ 'item.*.currency.string' => trans('validation.custom.invalid_currency'),
+ ];
+ }
+}
diff --git a/app/Http/Requests/Expense/Bill.php b/app/Http/Requests/Expense/Bill.php
index 3b41c242f..b1c746d10 100644
--- a/app/Http/Requests/Expense/Bill.php
+++ b/app/Http/Requests/Expense/Bill.php
@@ -40,6 +40,10 @@ class Bill extends Request
'billed_at' => 'required|date',
'due_at' => 'required|date',
'amount' => 'required',
+ 'item.*.name' => 'required|string',
+ 'item.*.quantity' => 'required',
+ 'item.*.price' => 'required|amount',
+ 'item.*.currency' => 'required|string|currency',
'currency_code' => 'required|string|currency',
'currency_rate' => 'required',
'vendor_id' => 'required|integer',
@@ -60,4 +64,15 @@ class Bill extends Request
$this->request->set('due_at', $due_at);
}
}
+
+ public function messages()
+ {
+ return [
+ 'item.*.name.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('general.name'))]),
+ 'item.*.quantity.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('bills.quantity'))]),
+ 'item.*.price.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('bills.price'))]),
+ 'item.*.currency.required' => trans('validation.custom.invalid_currency'),
+ 'item.*.currency.string' => trans('validation.custom.invalid_currency'),
+ ];
+ }
}
diff --git a/app/Http/Requests/Income/Invoice.php b/app/Http/Requests/Income/Invoice.php
index f26ba911f..75c005d1d 100644
--- a/app/Http/Requests/Income/Invoice.php
+++ b/app/Http/Requests/Income/Invoice.php
@@ -40,6 +40,10 @@ class Invoice extends Request
'invoiced_at' => 'required|date',
'due_at' => 'required|date',
'amount' => 'required',
+ 'item.*.name' => 'required|string',
+ 'item.*.quantity' => 'required',
+ 'item.*.price' => 'required|amount',
+ 'item.*.currency' => 'required|string|currency',
'currency_code' => 'required|string|currency',
'currency_rate' => 'required',
'customer_id' => 'required|integer',
@@ -60,4 +64,15 @@ class Invoice extends Request
$this->request->set('due_at', $due_at);
}
}
+
+ public function messages()
+ {
+ return [
+ 'item.*.name.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('general.name'))]),
+ 'item.*.quantity.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('invoices.quantity'))]),
+ 'item.*.price.required' => trans('validation.required', ['attribute' => mb_strtolower(trans('invoices.price'))]),
+ 'item.*.currency.required' => trans('validation.custom.invalid_currency'),
+ 'item.*.currency.string' => trans('validation.custom.invalid_currency'),
+ ];
+ }
}
diff --git a/resources/views/expenses/bills/create.blade.php b/resources/views/expenses/bills/create.blade.php
index 30c3f5e18..688d80c41 100644
--- a/resources/views/expenses/bills/create.blade.php
+++ b/resources/views/expenses/bills/create.blade.php
@@ -59,9 +59,17 @@
-
- @include('expenses.bills.item')
-
+ @php $item_row = 0; @endphp
+ @if(old('item'))
+ @foreach(old('item') as $old_item)
+ @php $item = (object) $old_item; @endphp
+ @include('expenses.bills.item')
+ @php $item_row++; @endphp
+ @endforeach
+ @else
+ @include('expenses.bills.item')
+ @endif
+ @php $item_row++; @endphp
@stack('add_item_td_start')
|
@@ -122,14 +130,14 @@
{{ Form::fileGroup('attachment', trans('general.attachment'),[]) }}
- {{ Form::hidden('vendor_name', '', ['id' => 'vendor_name']) }}
- {{ Form::hidden('vendor_email', '', ['id' => 'vendor_email']) }}
- {{ Form::hidden('vendor_tax_number', '', ['id' => 'vendor_tax_number']) }}
- {{ Form::hidden('vendor_phone', '', ['id' => 'vendor_phone']) }}
- {{ Form::hidden('vendor_address', '', ['id' => 'vendor_address']) }}
- {{ Form::hidden('currency_rate', '', ['id' => 'currency_rate']) }}
- {{ Form::hidden('bill_status_code', 'draft', ['id' => 'bill_status_code']) }}
- {{ Form::hidden('amount', '0', ['id' => 'amount']) }}
+ {{ Form::hidden('vendor_name', old('vendor_name'), ['id' => 'vendor_name']) }}
+ {{ Form::hidden('vendor_email', old('vendor_email'), ['id' => 'vendor_email']) }}
+ {{ Form::hidden('vendor_tax_number', old('vendor_tax_number'), ['id' => 'vendor_tax_number']) }}
+ {{ Form::hidden('vendor_phone', old('vendor_phone'), ['id' => 'vendor_phone']) }}
+ {{ Form::hidden('vendor_address', old('vendor_address'), ['id' => 'vendor_address']) }}
+ {{ Form::hidden('currency_rate', old('currency_rate'), ['id' => 'currency_rate']) }}
+ {{ Form::hidden('bill_status_code', old('bill_status_code', 'draft'), ['id' => 'bill_status_code']) }}
+ {{ Form::hidden('amount', old('amount', '0'), ['id' => 'amount']) }}
@@ -162,7 +170,7 @@
$(document).on('click', '#button-add-item', function (e) {
var currency_code = $('#currency_code').val();
-
+
$.ajax({
url: '{{ url("expenses/bills/addItem") }}',
type: 'GET',
@@ -415,6 +423,10 @@
}
});
});
+
+ @if(old('item'))
+ totalItem();
+ @endif
});
function totalItem() {
diff --git a/resources/views/expenses/bills/edit.blade.php b/resources/views/expenses/bills/edit.blade.php
index 1e3572605..ef21f9d8d 100644
--- a/resources/views/expenses/bills/edit.blade.php
+++ b/resources/views/expenses/bills/edit.blade.php
@@ -47,15 +47,23 @@
-
- @foreach($bill->items as $item)
- @include('expenses.bills.item')
-
- @endforeach
- @if (empty($bill->items))
- @include('expenses.bills.item')
- @endif
-
+ @php $item_row = 0; @endphp
+ @if(old('item'))
+ @foreach(old('item') as $old_item)
+ @php $item = (object) $old_item; @endphp
+ @include('expenses.bills.item')
+ @php $item_row++; @endphp
+ @endforeach
+ @else
+ @foreach($bill->items as $item)
+ @include('expenses.bills.item')
+ @php $item_row++; @endphp
+ @endforeach
+ @if (empty($bill->items))
+ @include('expenses.bills.item')
+ @endif
+ @endif
+ @php $item_row++; @endphp
@stack('add_item_td_start')
|
@@ -104,14 +112,14 @@
{{ Form::fileGroup('attachment', trans('general.attachment'),[]) }}
- {{ Form::hidden('vendor_name', null, ['id' => 'vendor_name']) }}
- {{ Form::hidden('vendor_email', null, ['id' => 'vendor_email']) }}
- {{ Form::hidden('vendor_tax_number', null, ['id' => 'vendor_tax_number']) }}
- {{ Form::hidden('vendor_phone', null, ['id' => 'vendor_phone']) }}
- {{ Form::hidden('vendor_address', null, ['id' => 'vendor_address']) }}
- {{ Form::hidden('currency_rate', null, ['id' => 'currency_rate']) }}
- {{ Form::hidden('bill_status_code', null, ['id' => 'bill_status_code']) }}
- {{ Form::hidden('amount', null, ['id' => 'amount']) }}
+ {{ Form::hidden('vendor_name', old('customer_name', null), ['id' => 'vendor_name']) }}
+ {{ Form::hidden('vendor_email', old('vendor_email', null), ['id' => 'vendor_email']) }}
+ {{ Form::hidden('vendor_tax_number', old('vendor_tax_number', null), ['id' => 'vendor_tax_number']) }}
+ {{ Form::hidden('vendor_phone', old('vendor_phone', null), ['id' => 'vendor_phone']) }}
+ {{ Form::hidden('vendor_address', old('vendor_address', null), ['id' => 'vendor_address']) }}
+ {{ Form::hidden('currency_rate', old('currency_rate', null), ['id' => 'currency_rate']) }}
+ {{ Form::hidden('bill_status_code', old('bill_status_code', null), ['id' => 'bill_status_code']) }}
+ {{ Form::hidden('amount', old('amount', null), ['id' => 'amount']) }}
@@ -423,6 +431,10 @@
}
});
});
+
+ @if(old('item'))
+ totalItem();
+ @endif
});
function totalItem() {
diff --git a/resources/views/expenses/bills/item.blade.php b/resources/views/expenses/bills/item.blade.php
index fe5d8ec2f..0d015fd48 100644
--- a/resources/views/expenses/bills/item.blade.php
+++ b/resources/views/expenses/bills/item.blade.php
@@ -7,39 +7,43 @@
@stack('actions_td_end')
@stack('name_td_start')
-
+ | has('item.' . $item_row . '.name') ? 'class="has-error"' : '' !!}">
@stack('name_input_start')
-
+
+ {!! $errors->first('item.' . $item_row . '.name', ' :message ') !!}
@stack('name_input_end')
|
@stack('name_td_end')
@stack('quantity_td_start')
-
+ | has('item.' . $item_row . '.quantity') ? 'class="has-error"' : '' }}">
@stack('quantity_input_start')
+ {!! $errors->first('item.' . $item_row . '.quantity', ' :message ') !!}
@stack('quantity_input_end')
|
@stack('quantity_td_end')
@stack('price_td_start')
-
+ | has('item.' . $item_row . 'price') ? 'class="has-error"' : '' }}">
@stack('price_input_start')
+ {!! $errors->first('item.' . $item_row . 'price', ' :message ') !!}
@stack('price_input_end')
|
@stack('price_td_end')
@stack('taxes_td_start')
-
+ | 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', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)])]) !!}
+ {!! $errors->first('item.' . $item_row . '.tax_id', ' :message ') !!}
@stack('tax_id_input_end')
|
@stack('taxes_td_end')
@stack('total_td_start')
@stack('total_input_start')
- @if (empty($item))
+ @if (empty($item) || !isset($item->total))
0
@else
@money($item->total, $bill->currency_code, true)
diff --git a/resources/views/incomes/invoices/create.blade.php b/resources/views/incomes/invoices/create.blade.php
index 1bd67d045..6065fa413 100644
--- a/resources/views/incomes/invoices/create.blade.php
+++ b/resources/views/incomes/invoices/create.blade.php
@@ -59,9 +59,17 @@
|
-
- @include('incomes.invoices.item')
-
+ @php $item_row = 0; @endphp
+ @if(old('item'))
+ @foreach(old('item') as $old_item)
+ @php $item = (object) $old_item; @endphp
+ @include('incomes.invoices.item')
+ @php $item_row++; @endphp
+ @endforeach
+ @else
+ @include('incomes.invoices.item')
+ @endif
+ @php $item_row++; @endphp
@stack('add_item_td_start')
|
@@ -122,14 +130,14 @@
{{ Form::fileGroup('attachment', trans('general.attachment')) }}
- {{ Form::hidden('customer_name', '', ['id' => 'customer_name']) }}
- {{ Form::hidden('customer_email', '', ['id' => 'customer_email']) }}
- {{ Form::hidden('customer_tax_number', '', ['id' => 'customer_tax_number']) }}
- {{ Form::hidden('customer_phone', '', ['id' => 'customer_phone']) }}
- {{ Form::hidden('customer_address', '', ['id' => 'customer_address']) }}
- {{ Form::hidden('currency_rate', '', ['id' => 'currency_rate']) }}
- {{ Form::hidden('invoice_status_code', 'draft', ['id' => 'invoice_status_code']) }}
- {{ Form::hidden('amount', '0', ['id' => 'amount']) }}
+ {{ Form::hidden('customer_name', old('customer_name'), ['id' => 'customer_name']) }}
+ {{ Form::hidden('customer_email', old('customer_email'), ['id' => 'customer_email']) }}
+ {{ Form::hidden('customer_tax_number', old('customer_tax_number'), ['id' => 'customer_tax_number']) }}
+ {{ Form::hidden('customer_phone', old('customer_phone'), ['id' => 'customer_phone']) }}
+ {{ Form::hidden('customer_address', old('customer_address'), ['id' => 'customer_address']) }}
+ {{ Form::hidden('currency_rate', old('currency_rate'), ['id' => 'currency_rate']) }}
+ {{ Form::hidden('invoice_status_code', old('invoice_status_code', 'draft'), ['id' => 'invoice_status_code']) }}
+ {{ Form::hidden('amount', old('amount', '0'), ['id' => 'amount']) }}
@@ -415,6 +423,10 @@
}
});
});
+
+ @if(old('item'))
+ totalItem();
+ @endif
});
function totalItem() {
diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php
index 03d21c05e..93095b172 100644
--- a/resources/views/incomes/invoices/edit.blade.php
+++ b/resources/views/incomes/invoices/edit.blade.php
@@ -47,15 +47,23 @@
-
- @foreach($invoice->items as $item)
- @include('incomes.invoices.item')
-
- @endforeach
- @if (empty($invoice->items))
- @include('incomes.invoices.item')
- @endif
-
+ @php $item_row = 0; @endphp
+ @if(old('item'))
+ @foreach(old('item') as $old_item)
+ @php $item = (object) $old_item; @endphp
+ @include('incomes.invoices.item')
+ @php $item_row++; @endphp
+ @endforeach
+ @else
+ @foreach($invoice->items as $item)
+ @include('incomes.invoices.item')
+ @php $item_row++; @endphp
+ @endforeach
+ @if (empty($invoice->items))
+ @include('incomes.invoices.item')
+ @endif
+ @endif
+ @php $item_row++; @endphp
@stack('add_item_td_start')
|
@@ -104,14 +112,14 @@
{{ Form::fileGroup('attachment', trans('general.attachment')) }}
- {{ Form::hidden('customer_name', null, ['id' => 'customer_name']) }}
- {{ Form::hidden('customer_email', null, ['id' => 'customer_email']) }}
- {{ Form::hidden('customer_tax_number', null, ['id' => 'customer_tax_number']) }}
- {{ Form::hidden('customer_phone', null, ['id' => 'customer_phone']) }}
- {{ Form::hidden('customer_address', null, ['id' => 'customer_address']) }}
- {{ Form::hidden('currency_rate', null, ['id' => 'currency_rate']) }}
- {{ Form::hidden('invoice_status_code', null, ['id' => 'invoice_status_code']) }}
- {{ Form::hidden('amount', null, ['id' => 'amount']) }}
+ {{ Form::hidden('customer_name', old('customer_name', null), ['id' => 'customer_name']) }}
+ {{ Form::hidden('customer_email', old('customer_email', null), ['id' => 'customer_email']) }}
+ {{ Form::hidden('customer_tax_number', old('customer_tax_number', null), ['id' => 'customer_tax_number']) }}
+ {{ Form::hidden('customer_phone', old('customer_phone', null), ['id' => 'customer_phone']) }}
+ {{ Form::hidden('customer_address', old('customer_address', null), ['id' => 'customer_address']) }}
+ {{ Form::hidden('currency_rate', old('currency_rate', null), ['id' => 'currency_rate']) }}
+ {{ Form::hidden('invoice_status_code', old('invoice_status_code', null), ['id' => 'invoice_status_code']) }}
+ {{ Form::hidden('amount', old('amount', null), ['id' => 'amount']) }}
@@ -423,6 +431,10 @@
}
});
});
+
+ @if(old('item'))
+ totalItem();
+ @endif
});
function totalItem() {
diff --git a/resources/views/incomes/invoices/item.blade.php b/resources/views/incomes/invoices/item.blade.php
index c178be22e..882277924 100644
--- a/resources/views/incomes/invoices/item.blade.php
+++ b/resources/views/incomes/invoices/item.blade.php
@@ -7,39 +7,43 @@
@stack('actions_td_end')
@stack('name_td_start')
-
+ | has('item.' . $item_row . '.name') ? 'class="has-error"' : '' !!}">
@stack('name_input_start')
+ {!! $errors->first('item.' . $item_row . '.name', ' :message ') !!}
@stack('name_input_end')
|
@stack('name_td_end')
@stack('quantity_td_start')
-
+ | has('item.' . $item_row . '.quantity') ? 'class="has-error"' : '' }}">
@stack('quantity_input_start')
+ {!! $errors->first('item.' . $item_row . '.quantity', ' :message ') !!}
@stack('quantity_input_end')
|
@stack('quantity_td_end')
@stack('price_td_start')
-
+ | has('item.' . $item_row . 'price') ? 'class="has-error"' : '' }}">
@stack('price_input_start')
+ {!! $errors->first('item.' . $item_row . 'price', ' :message ') !!}
@stack('price_input_end')
|
@stack('price_td_end')
@stack('taxes_td_start')
-
+ | 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', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)])]) !!}
+ {!! $errors->first('item.' . $item_row . '.tax_id', ' :message ') !!}
@stack('tax_id_input_end')
|
@stack('taxes_td_end')
@stack('total_td_start')
@stack('total_input_start')
- @if (empty($item))
+ @if (empty($item) || !isset($item->total))
0
@else
@money($item->total, $invoice->currency_code, true)
|