refs #451 Invoice create added item price mask
This commit is contained in:
parent
33673def5b
commit
17b582796d
@ -365,9 +365,16 @@ class Customers extends Controller
|
||||
// Get currency object
|
||||
$currency = Currency::where('code', $currency_code)->first();
|
||||
|
||||
$customer->currency_name = $currency->name;
|
||||
$customer->currency_code = $currency_code;
|
||||
$customer->currency_rate = $currency->rate;
|
||||
|
||||
$customer->thousands_separator = $currency->thousands_separator;
|
||||
$customer->decimal_mark = $currency->decimal_mark;
|
||||
$customer->precision = (int) $currency->precision;
|
||||
$customer->symbol_first = $currency->symbol_first;
|
||||
$customer->symbol = $currency->symbol;
|
||||
|
||||
return response()->json($customer);
|
||||
}
|
||||
|
||||
|
@ -69,16 +69,35 @@ class Invoices extends Controller
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
foreach ($invoice->payments as $item) {
|
||||
$amount = $item->amount;
|
||||
// Get Invoice Payments
|
||||
if ($invoice->payments->count()) {
|
||||
$_currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
|
||||
if ($invoice->currency_code != $item->currency_code) {
|
||||
$item->default_currency_code = $invoice->currency_code;
|
||||
foreach ($invoice->payments as $item) {
|
||||
$default_amount = $item->amount;
|
||||
|
||||
$amount = $item->getDynamicConvertedAmount();
|
||||
if ($invoice->currency_code != $item->currency_code) {
|
||||
$default_amount_model = new InvoicePayment();
|
||||
|
||||
$default_amount_model->default_currency_code = $invoice->currency_code;
|
||||
$default_amount_model->amount = $default_amount;
|
||||
$default_amount_model->currency_code = $item->currency_code;
|
||||
$default_amount_model->currency_rate = $_currencies[$item->currency_code];
|
||||
|
||||
$default_amount = (double) $default_amount_model->getDivideConvertedAmount();
|
||||
}
|
||||
|
||||
$convert_amount = new InvoicePayment();
|
||||
|
||||
$convert_amount->default_currency_code = $item->currency_code;
|
||||
$convert_amount->amount = $default_amount;
|
||||
$convert_amount->currency_code = $invoice->currency_code;
|
||||
$convert_amount->currency_rate = $_currencies[$invoice->currency_code];
|
||||
|
||||
$amount = (double) $convert_amount->getDynamicConvertedAmount();
|
||||
|
||||
$paid += $amount;
|
||||
}
|
||||
|
||||
$paid += $amount;
|
||||
}
|
||||
|
||||
$invoice->paid = $paid;
|
||||
@ -109,6 +128,8 @@ class Invoices extends Controller
|
||||
|
||||
$currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code');
|
||||
|
||||
$currency = Currency::where('code', '=', setting('general.default_currency'))->first();
|
||||
|
||||
$items = Item::enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('rate')->get()->pluck('title', 'id');
|
||||
@ -117,7 +138,7 @@ class Invoices extends Controller
|
||||
|
||||
$number = $this->getNextInvoiceNumber();
|
||||
|
||||
return view('incomes.invoices.create', compact('customers', 'currencies', 'items', 'taxes', 'categories', 'number'));
|
||||
return view('incomes.invoices.create', compact('customers', 'currencies', 'currency', 'items', 'taxes', 'categories', 'number'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -864,11 +885,19 @@ class Invoices extends Controller
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('rate')->get()->pluck('title', 'id');
|
||||
|
||||
$currency = Currency::where('code', '=', $request['currency_code'])->first();
|
||||
|
||||
// it should be integer for amount mask
|
||||
$currency->precision = (int) $currency->precision;
|
||||
|
||||
$html = view('incomes.invoices.item', compact('item_row', 'taxes'))->render();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'currency' => $currency
|
||||
],
|
||||
'message' => 'null',
|
||||
'html' => $html,
|
||||
]);
|
||||
@ -877,6 +906,7 @@ class Invoices extends Controller
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'data' => 'null',
|
||||
'message' => trans('issue'),
|
||||
'html' => 'null',
|
||||
]);
|
||||
|
246
app/Http/Controllers/Modals/InvoicePayments.php
Normal file
246
app/Http/Controllers/Modals/InvoicePayments.php
Normal file
@ -0,0 +1,246 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Modals;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Income\InvoicePayment as Request;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Income\InvoicePayment;
|
||||
use App\Models\Income\InvoiceHistory;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Utilities\Modules;
|
||||
use App\Traits\Uploads;
|
||||
|
||||
class InvoicePayments extends Controller
|
||||
{
|
||||
use Uploads;
|
||||
|
||||
/**
|
||||
* Instantiate a new controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Add CRUD permission check
|
||||
$this->middleware('permission:create-incomes-invoices')->only(['create', 'store', 'duplicate', 'import']);
|
||||
$this->middleware('permission:read-incomes-invoices')->only(['index', 'show', 'edit', 'export']);
|
||||
$this->middleware('permission:update-incomes-invoices')->only(['update', 'enable', 'disable']);
|
||||
$this->middleware('permission:delete-incomes-invoices')->only('destroy');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(Invoice $invoice)
|
||||
{
|
||||
$accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code')->toArray();
|
||||
|
||||
$currency = Currency::where('code', setting('general.default_currency'))->first();
|
||||
|
||||
$account_currency_code = Account::where('id', setting('general.default_account'))->pluck('currency_code')->first();
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
$invoice->paid = $this->getPaid($invoice);
|
||||
|
||||
// Get Invoice Totals
|
||||
foreach ($invoice->totals as $invoice_total) {
|
||||
$invoice->{$invoice_total->code} = $invoice_total->amount;
|
||||
}
|
||||
|
||||
$invoice->grand_total = $invoice->total;
|
||||
|
||||
if (!empty($paid)) {
|
||||
$invoice->grand_total = $invoice->total - $paid;
|
||||
}
|
||||
|
||||
$html = view('modals.invoices.payment', compact('invoice', 'accounts', 'account_currency_code', 'currencies', 'currency', 'payment_methods'))->render();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'message' => 'null',
|
||||
'html' => $html,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Invoice $invoice, Request $request)
|
||||
{
|
||||
// Get currency object
|
||||
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
$currency = Currency::where('code', $request['currency_code'])->first();
|
||||
|
||||
$request['currency_code'] = $currency->code;
|
||||
$request['currency_rate'] = $currency->rate;
|
||||
|
||||
$total_amount = $invoice->amount;
|
||||
|
||||
$default_amount = (double) $request['amount'];
|
||||
|
||||
if ($invoice->currency_code != $request['currency_code']) {
|
||||
$default_amount_model = new InvoicePayment();
|
||||
|
||||
$default_amount_model->default_currency_code = $invoice->currency_code;
|
||||
$default_amount_model->amount = $default_amount;
|
||||
$default_amount_model->currency_code = $request['currency_code'];
|
||||
$default_amount_model->currency_rate = $currencies[$request['currency_code']];
|
||||
|
||||
$default_amount = (double) $default_amount_model->getDivideConvertedAmount();
|
||||
}
|
||||
|
||||
$convert_amount = new InvoicePayment();
|
||||
|
||||
$convert_amount->default_currency_code = $request['currency_code'];
|
||||
$convert_amount->amount = $default_amount;
|
||||
$convert_amount->currency_code = $invoice->currency_code;
|
||||
$convert_amount->currency_rate = $currencies[$invoice->currency_code];
|
||||
|
||||
$amount = (double) $convert_amount->getDynamicConvertedAmount();
|
||||
|
||||
if ($invoice->payments()->count()) {
|
||||
$total_amount -= $this->getPaid($invoice);
|
||||
}
|
||||
|
||||
// For amount cover integer
|
||||
$multiplier = 1;
|
||||
|
||||
for ($i = 0; $i < $currency->precision; $i++) {
|
||||
$multiplier *= 10;
|
||||
}
|
||||
|
||||
$amount_check = $amount * $multiplier;
|
||||
$total_amount_check = $total_amount * $multiplier;
|
||||
|
||||
if ($amount_check > $total_amount_check) {
|
||||
$error_amount = $total_amount;
|
||||
|
||||
if ($invoice->currency_code != $request['currency_code']) {
|
||||
$error_amount_model = new InvoicePayment();
|
||||
|
||||
$error_amount_model->default_currency_code = $request['currency_code'];
|
||||
$error_amount_model->amount = $error_amount;
|
||||
$error_amount_model->currency_code = $invoice->currency_code;
|
||||
$error_amount_model->currency_rate = $currencies[$invoice->currency_code];
|
||||
|
||||
$error_amount = (double) $error_amount_model->getDivideConvertedAmount();
|
||||
}
|
||||
|
||||
$convert_amount = new InvoicePayment();
|
||||
|
||||
$convert_amount->default_currency_code = $invoice->currency_code;
|
||||
$convert_amount->amount = $error_amount;
|
||||
$convert_amount->currency_code = $request['currency_code'];
|
||||
$convert_amount->currency_rate = $currencies[$request['currency_code']];
|
||||
|
||||
$error_amount = (double) $convert_amount->getDynamicConvertedAmount();
|
||||
|
||||
$message = trans('messages.error.over_payment', ['amount' => money($error_amount, $request['currency_code'], true)]);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'data' => [
|
||||
'amount' => $error_amount
|
||||
],
|
||||
'message' => $message,
|
||||
'html' => 'null',
|
||||
]);
|
||||
} elseif ($amount == $total_amount) {
|
||||
$invoice->invoice_status_code = 'paid';
|
||||
} else {
|
||||
$invoice->invoice_status_code = 'partial';
|
||||
}
|
||||
|
||||
$invoice->save();
|
||||
|
||||
$invoice_payment_request = [
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $request['invoice_id'],
|
||||
'account_id' => $request['account_id'],
|
||||
'paid_at' => $request['paid_at'],
|
||||
'amount' => $request['amount'],
|
||||
'currency_code' => $request['currency_code'],
|
||||
'currency_rate' => $request['currency_rate'],
|
||||
'description' => $request['description'],
|
||||
'payment_method' => $request['payment_method'],
|
||||
'reference' => $request['reference']
|
||||
];
|
||||
|
||||
$invoice_payment = InvoicePayment::create($invoice_payment_request);
|
||||
|
||||
// Upload attachment
|
||||
if ($request->file('attachment')) {
|
||||
$media = $this->getMedia($request->file('attachment'), 'invoices');
|
||||
|
||||
$invoice_payment->attachMedia($media, 'attachment');
|
||||
}
|
||||
|
||||
$request['status_code'] = $invoice->invoice_status_code;
|
||||
$request['notify'] = 0;
|
||||
|
||||
$desc_amount = money((float) $request['amount'], (string) $request['currency_code'], true)->format();
|
||||
|
||||
$request['description'] = $desc_amount . ' ' . trans_choice('general.payments', 1);
|
||||
|
||||
InvoiceHistory::create($request->input());
|
||||
|
||||
$message = trans('messages.success.added', ['type' => trans_choice('general.payments', 1)]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'data' => $invoice_payment,
|
||||
'message' => $message,
|
||||
'html' => 'null',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getPaid($invoice)
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
// Get Invoice Payments
|
||||
if ($invoice->payments->count()) {
|
||||
$_currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
|
||||
foreach ($invoice->payments as $item) {
|
||||
$default_amount = $item->amount;
|
||||
|
||||
if ($invoice->currency_code != $item->currency_code) {
|
||||
$default_amount_model = new InvoicePayment();
|
||||
|
||||
$default_amount_model->default_currency_code = $invoice->currency_code;
|
||||
$default_amount_model->amount = $default_amount;
|
||||
$default_amount_model->currency_code = $item->currency_code;
|
||||
$default_amount_model->currency_rate = $_currencies[$item->currency_code];
|
||||
|
||||
$default_amount = (double) $default_amount_model->getDivideConvertedAmount();
|
||||
}
|
||||
|
||||
$convert_amount = new InvoicePayment();
|
||||
|
||||
$convert_amount->default_currency_code = $item->currency_code;
|
||||
$convert_amount->amount = $default_amount;
|
||||
$convert_amount->currency_code = $invoice->currency_code;
|
||||
$convert_amount->currency_rate = $_currencies[$invoice->currency_code];
|
||||
|
||||
$amount = (double) $convert_amount->getDynamicConvertedAmount();
|
||||
|
||||
$paid += $amount;
|
||||
}
|
||||
}
|
||||
|
||||
return $paid;
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ class Money
|
||||
}
|
||||
}
|
||||
|
||||
/* check item price use money
|
||||
if (isset($sale_price)) {
|
||||
$sale_price = money($sale_price, $currency_code)->getAmount();
|
||||
|
||||
@ -56,6 +57,7 @@ class Money
|
||||
|
||||
$request->request->set('purchase_price', $purchase_price);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@ -101,4 +101,9 @@ class InvoicePayment extends Model
|
||||
|
||||
return $this->getMedia('attachment')->last();
|
||||
}
|
||||
|
||||
public function getDivideConvertedAmount($format = false)
|
||||
{
|
||||
return $this->divide($this->amount, $this->currency_code, $this->currency_rate, $format);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ return [
|
||||
'disabled' => ':type disabled!',
|
||||
],
|
||||
'error' => [
|
||||
'over_payment' => 'Error: Payment not added! Amount passes the total.',
|
||||
'over_payment' => 'Error: Payment not added! Amount passes the total. You don\'t should max add amount: :amount',
|
||||
'not_user_company' => 'Error: You are not allowed to manage this company!',
|
||||
'customer' => 'Error: User not created! :name already uses this email address.',
|
||||
'no_file' => 'Error: No file selected!',
|
||||
|
@ -3,133 +3,133 @@
|
||||
@section('title', trans('general.title.new', ['type' => trans_choice('general.items', 1)]))
|
||||
|
||||
@section('content')
|
||||
<!-- Default box -->
|
||||
<div class="box box-success">
|
||||
{!! Form::open(['route' => 'items.store', 'files' => true, 'role' => 'form']) !!}
|
||||
<!-- Default box -->
|
||||
<div class="box box-success">
|
||||
{!! Form::open(['route' => 'items.store', 'files' => true, 'role' => 'form']) !!}
|
||||
|
||||
<div class="box-body">
|
||||
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
|
||||
<div class="box-body">
|
||||
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
|
||||
|
||||
{{ Form::textGroup('sku', trans('items.sku'), 'key') }}
|
||||
{{ Form::textGroup('sku', trans('items.sku'), 'key') }}
|
||||
|
||||
{{ Form::textareaGroup('description', trans('general.description')) }}
|
||||
{{ Form::textareaGroup('description', trans('general.description')) }}
|
||||
|
||||
{{ Form::textGroup('sale_price', trans('items.sales_price'), 'money') }}
|
||||
{{ Form::textGroup('sale_price', trans('items.sales_price'), 'money') }}
|
||||
|
||||
{{ Form::textGroup('purchase_price', trans('items.purchase_price'), 'money') }}
|
||||
{{ Form::textGroup('purchase_price', trans('items.purchase_price'), 'money') }}
|
||||
|
||||
{{ Form::textGroup('quantity', trans_choice('items.quantities', 1), 'cubes', ['required' => 'required'], '1') }}
|
||||
{{ Form::textGroup('quantity', trans_choice('items.quantities', 1), 'cubes', ['required' => 'required'], '1') }}
|
||||
|
||||
{{ Form::selectGroup('tax_id', trans_choice('general.taxes', 1), 'percent', $taxes, setting('general.default_tax'), []) }}
|
||||
{{ Form::selectGroup('tax_id', trans_choice('general.taxes', 1), 'percent', $taxes, setting('general.default_tax'), []) }}
|
||||
|
||||
@stack('category_id_input_start')
|
||||
<div class="form-group col-md-6 required {{ $errors->has('category_id') ? 'has-error' : ''}}">
|
||||
{!! Form::label('category_id', trans_choice('general.categories', 1), ['class' => 'control-label']) !!}
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><i class="fa fa-folder-open-o"></i></div>
|
||||
{!! Form::select('category_id', $categories, null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)])])) !!}
|
||||
<div class="input-group-btn">
|
||||
<button type="button" id="button-category" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
@stack('category_id_input_start')
|
||||
<div class="form-group col-md-6 required {{ $errors->has('category_id') ? 'has-error' : ''}}">
|
||||
{!! Form::label('category_id', trans_choice('general.categories', 1), ['class' => 'control-label']) !!}
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><i class="fa fa-folder-open-o"></i></div>
|
||||
{!! Form::select('category_id', $categories, null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)])])) !!}
|
||||
<div class="input-group-btn">
|
||||
<button type="button" id="button-category" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
{!! $errors->first('category_id', '<p class="help-block">:message</p>') !!}
|
||||
</div>
|
||||
@stack('category_id_input_end')
|
||||
|
||||
{{ Form::fileGroup('picture', trans_choice('general.pictures', 1)) }}
|
||||
|
||||
{{ Form::radioGroup('enabled', trans('general.enabled')) }}
|
||||
{!! $errors->first('category_id', '<p class="help-block">:message</p>') !!}
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
@stack('category_id_input_end')
|
||||
|
||||
<div class="box-footer">
|
||||
{{ Form::saveButtons('common/items') }}
|
||||
</div>
|
||||
<!-- /.box-footer -->
|
||||
{{ Form::fileGroup('picture', trans_choice('general.pictures', 1)) }}
|
||||
|
||||
{!! Form::close() !!}
|
||||
{{ Form::radioGroup('enabled', trans('general.enabled')) }}
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
|
||||
<div class="box-footer">
|
||||
{{ Form::saveButtons('common/items') }}
|
||||
</div>
|
||||
<!-- /.box-footer -->
|
||||
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('js')
|
||||
<script src="{{ asset('public/js/bootstrap-fancyfile.js') }}"></script>
|
||||
<script src="{{ asset('vendor/almasaeed2010/adminlte/plugins/colorpicker/bootstrap-colorpicker.js') }}"></script>
|
||||
<script src="{{ asset('public/js/bootstrap-fancyfile.js') }}"></script>
|
||||
<script src="{{ asset('vendor/almasaeed2010/adminlte/plugins/colorpicker/bootstrap-colorpicker.js') }}"></script>
|
||||
@endpush
|
||||
|
||||
@push('css')
|
||||
<link rel="stylesheet" href="{{ asset('public/css/bootstrap-fancyfile.css') }}">
|
||||
<link rel="stylesheet" href="{{ asset('vendor/almasaeed2010/adminlte/plugins/colorpicker/bootstrap-colorpicker.css') }}">
|
||||
<link rel="stylesheet" href="{{ asset('public/css/bootstrap-fancyfile.css') }}">
|
||||
<link rel="stylesheet" href="{{ asset('vendor/almasaeed2010/adminlte/plugins/colorpicker/bootstrap-colorpicker.css') }}">
|
||||
@endpush
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
var text_yes = '{{ trans('general.yes') }}';
|
||||
var text_no = '{{ trans('general.no') }}';
|
||||
<script type="text/javascript">
|
||||
var text_yes = '{{ trans('general.yes') }}';
|
||||
var text_no = '{{ trans('general.no') }}';
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#sale_price").maskMoney({
|
||||
thousands : '{{ $currency->thousands_separator }}',
|
||||
decimal : '{{ $currency->decimal_mark }}',
|
||||
precision : {{ $currency->precision }},
|
||||
allowZero : true,
|
||||
@if($currency->symbol_first)
|
||||
prefix : '{{ $currency->symbol }}'
|
||||
@else
|
||||
suffix : '{{ $currency->symbol }}'
|
||||
@endif
|
||||
});
|
||||
|
||||
$("#purchase_price").maskMoney({
|
||||
thousands : '{{ $currency->thousands_separator }}',
|
||||
decimal : '{{ $currency->decimal_mark }}',
|
||||
precision : {{ $currency->precision }},
|
||||
allowZero : true,
|
||||
@if($currency->symbol_first)
|
||||
prefix : '{{ $currency->symbol }}'
|
||||
@else
|
||||
suffix : '{{ $currency->symbol }}'
|
||||
@endif
|
||||
});
|
||||
|
||||
$("#sale_price").focusout();
|
||||
$("#purchase_price").focusout();
|
||||
|
||||
$('#enabled_1').trigger('click');
|
||||
|
||||
$('#name').focus();
|
||||
|
||||
$("#tax_id").select2({
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
}
|
||||
});
|
||||
|
||||
$("#category_id").select2({
|
||||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
|
||||
});
|
||||
|
||||
$('#picture').fancyfile({
|
||||
text : '{{ trans('general.form.select.file') }}',
|
||||
style : 'btn-default',
|
||||
placeholder : '{{ trans('general.form.no_file_selected') }}'
|
||||
});
|
||||
$(document).ready(function(){
|
||||
/*$("#sale_price").maskMoney({
|
||||
thousands : '{{ $currency->thousands_separator }}',
|
||||
decimal : '{{ $currency->decimal_mark }}',
|
||||
precision : {{ $currency->precision }},
|
||||
allowZero : true,
|
||||
@if($currency->symbol_first)
|
||||
prefix : '{{ $currency->symbol }}'
|
||||
@else
|
||||
suffix : '{{ $currency->symbol }}'
|
||||
@endif
|
||||
});
|
||||
|
||||
$(document).on('click', '#button-category', function (e) {
|
||||
$('#modal-create-category').remove();
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("modals/categories/create") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: {type: 'item'},
|
||||
success: function(json) {
|
||||
if (json['success']) {
|
||||
$('body').append(json['html']);
|
||||
}
|
||||
}
|
||||
});
|
||||
$("#purchase_price").maskMoney({
|
||||
thousands : '{{ $currency->thousands_separator }}',
|
||||
decimal : '{{ $currency->decimal_mark }}',
|
||||
precision : {{ $currency->precision }},
|
||||
allowZero : true,
|
||||
@if($currency->symbol_first)
|
||||
prefix : '{{ $currency->symbol }}'
|
||||
@else
|
||||
suffix : '{{ $currency->symbol }}'
|
||||
@endif
|
||||
});
|
||||
</script>
|
||||
|
||||
$("#sale_price").focusout();
|
||||
$("#purchase_price").focusout();*/
|
||||
|
||||
$('#enabled_1').trigger('click');
|
||||
|
||||
$('#name').focus();
|
||||
|
||||
$("#tax_id").select2({
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
}
|
||||
});
|
||||
|
||||
$("#category_id").select2({
|
||||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
|
||||
});
|
||||
|
||||
$('#picture').fancyfile({
|
||||
text : '{{ trans('general.form.select.file') }}',
|
||||
style : 'btn-default',
|
||||
placeholder : '{{ trans('general.form.no_file_selected') }}'
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '#button-category', function (e) {
|
||||
$('#modal-create-category').remove();
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("modals/categories/create") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: {type: 'item'},
|
||||
success: function(json) {
|
||||
if (json['success']) {
|
||||
$('body').append(json['html']);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -59,7 +59,7 @@
|
||||
var text_no = '{{ trans('general.no') }}';
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#sale_price").maskMoney({
|
||||
/*$("#sale_price").maskMoney({
|
||||
thousands : '{{ $currency->thousands_separator }}',
|
||||
decimal : '{{ $currency->decimal_mark }}',
|
||||
precision : {{ $currency->precision }},
|
||||
@ -84,7 +84,7 @@
|
||||
});
|
||||
|
||||
$("#sale_price").focusout();
|
||||
$("#purchase_price").focusout();
|
||||
$("#purchase_price").focusout();*/
|
||||
|
||||
$("#tax_id").select2({
|
||||
placeholder: {
|
||||
|
@ -165,7 +165,7 @@
|
||||
url: '{{ url("incomes/invoices/addItem") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: {item_row: item_row},
|
||||
data: {item_row: item_row, currency_code : $('#currency_code').val()},
|
||||
success: function(json) {
|
||||
if (json['success']) {
|
||||
$('#items tbody #addItem').before(json['html']);
|
||||
@ -180,6 +180,19 @@
|
||||
}
|
||||
});
|
||||
|
||||
var currency = json['data']['currency'];
|
||||
|
||||
$("#item-price-" + item_row).maskMoney({
|
||||
thousands : currency.thousands_separator,
|
||||
decimal : currency.decimal_mark,
|
||||
precision : currency.precision,
|
||||
allowZero : true,
|
||||
prefix : (currency.symbol_first) ? currency.symbol : '',
|
||||
suffix : (currency.symbol_first) ? '' : currency.symbol
|
||||
});
|
||||
|
||||
$("#item-price-" + item_row).trigger('focusout');
|
||||
|
||||
item_row++;
|
||||
}
|
||||
}
|
||||
@ -187,6 +200,20 @@
|
||||
});
|
||||
|
||||
$(document).ready(function(){
|
||||
$(".input-price").maskMoney({
|
||||
thousands : '{{ $currency->thousands_separator }}',
|
||||
decimal : '{{ $currency->decimal_mark }}',
|
||||
precision : {{ $currency->precision }},
|
||||
allowZero : true,
|
||||
@if($currency->symbol_first)
|
||||
prefix : '{{ $currency->symbol }}'
|
||||
@else
|
||||
suffix : '{{ $currency->symbol }}'
|
||||
@endif
|
||||
});
|
||||
|
||||
$('.input-price').trigger('focusout');
|
||||
|
||||
//Date picker
|
||||
$('#invoiced_at').datepicker({
|
||||
format: 'yyyy-mm-dd',
|
||||
@ -338,9 +365,27 @@
|
||||
$('#customer_tax_number').val(data.tax_number);
|
||||
$('#customer_phone').val(data.phone);
|
||||
$('#customer_address').val(data.address);
|
||||
|
||||
$('#currency_code').val(data.currency_code);
|
||||
$('#currency_rate').val(data.currency_rate);
|
||||
|
||||
$('.input-price').each(function(){
|
||||
amount = $(this).maskMoney('unmasked')[0];
|
||||
|
||||
$(this).maskMoney({
|
||||
thousands : data.thousands_separator,
|
||||
decimal : data.decimal_mark,
|
||||
precision : data.precision,
|
||||
allowZero : true,
|
||||
prefix : (data.symbol_first) ? data.symbol : '',
|
||||
suffix : (data.symbol_first) ? '' : data.symbol
|
||||
});
|
||||
|
||||
$(this).val(amount);
|
||||
|
||||
$(this).trigger('focusout');
|
||||
});
|
||||
|
||||
// This event Select2 Stylesheet
|
||||
$('#currency_code').trigger('change');
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
@stack('price_td_start')
|
||||
<td>
|
||||
@stack('price_input_start')
|
||||
<input value="{{ empty($item) ? '' : $item->price }}" class="form-control text-right" required="required" name="item[{{ $item_row }}][price]" type="text" id="item-price-{{ $item_row }}">
|
||||
<input value="{{ empty($item) ? '' : $item->price }}" class="form-control text-right input-price" required="required" name="item[{{ $item_row }}][price]" type="text" id="item-price-{{ $item_row }}">
|
||||
@stack('price_input_end')
|
||||
</td>
|
||||
@stack('price_td_end')
|
||||
|
@ -175,7 +175,7 @@
|
||||
@permission('update-incomes-invoices')
|
||||
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/pay') }}">{{ trans('invoices.mark_paid') }}</a></li>
|
||||
@endpermission
|
||||
@if(empty($invoice->payments()->count()) || (!empty($invoice->payments()->count()) && $invoice->payments()->paid() != $invoice->amount))
|
||||
@if(empty($invoice->payments()->count()) || (!empty($invoice->payments()->count()) && $invoice->paid != $invoice->amount))
|
||||
<li><a href="#" id="button-payment">{{ trans('invoices.add_payment') }}</a></li>
|
||||
@endif
|
||||
<li class="divider"></li>
|
||||
@ -329,110 +329,6 @@
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$(document).on('click', '#button-payment', function (e) {
|
||||
$('#payment-modal').remove();
|
||||
|
||||
var html = '';
|
||||
|
||||
html += '<div class="modal fade" id="payment-modal" tabindex="-1" role="dialog" aria-labelledby="paymentModalLabel">';
|
||||
html += ' <div class="modal-dialog" role="document">';
|
||||
html += ' <div class="modal-content box box-success">';
|
||||
html += ' <div class="modal-header">';
|
||||
html += ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>';
|
||||
html += ' <h4 class="modal-title" id="paymentModalLabel">{{ trans('invoices.add_payment') }}</h4>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="modal-body box-body">';
|
||||
html += ' <div class="modal-message"></div>';
|
||||
html += ' <div class="form-group col-md-6 required">';
|
||||
html += ' {!! Form::label('paid_at', trans('general.date'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-calendar"></i></div>';
|
||||
html += ' {!! Form::text('paid_at', \Carbon\Carbon::now()->toDateString(), ['id' => 'paid_at', 'class' => 'form-control', 'required' => 'required', 'data-inputmask' => '\'alias\': \'yyyy-mm-dd\'', 'data-mask' => '', 'autocomplete' => 'off']) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="form-group col-md-6 required">';
|
||||
html += ' {!! Form::label('amount', trans('general.amount'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-money"></i></div>';
|
||||
html += ' {!! Form::text('amount', $invoice->grand_total, ['class' => 'form-control', 'required' => 'required', 'placeholder' => trans('general.form.enter', ['field' => trans('general.amount')])]) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="form-group col-md-6 required">';
|
||||
html += ' {!! Form::label('account_id', trans_choice('general.accounts', 1), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-university"></i></div>';
|
||||
html += ' {!! Form::select('account_id', $accounts, setting('general.default_account'), ['class' => 'form-control', 'required' => 'required', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.accounts', 1)])]) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="form-group col-md-6 required">';
|
||||
html += ' {!! Form::label('currency_code', trans_choice('general.currencies', 1), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-exchange"></i></div>';
|
||||
html += ' {!! Form::text('currency', $currencies[$account_currency_code], ['id' => 'currency', 'class' => 'form-control', 'required' => 'required', 'disabled' => 'disabled']) !!}';
|
||||
html += ' {!! Form::hidden('currency_code', $account_currency_code, ['id' => 'currency_code', 'class' => 'form-control', 'required' => 'required']) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="form-group col-md-12">';
|
||||
html += ' {!! Form::label('description', trans('general.description'), ['class' => 'control-label']) !!}';
|
||||
html += ' {!! Form::textarea('description', null, ['class' => 'form-control', 'rows' => '3', 'placeholder' => trans('general.form.enter', ['field' => trans('general.description')])]) !!}';
|
||||
html += ' </div>';
|
||||
html += ' <div class="form-group col-md-6 required">';
|
||||
html += ' {!! Form::label('payment_method', trans_choice('general.payment_methods', 1), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-folder-open-o"></i></div>';
|
||||
html += ' {!! Form::select('payment_method', $payment_methods, setting('general.default_payment_method'), ['class' => 'form-control', 'required' => 'required', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.payment_methods', 1)])]) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="form-group col-md-6">';
|
||||
html += ' {!! Form::label('reference', trans('general.reference'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-file-text-o"></i></div>';
|
||||
html += ' {!! Form::text('reference', null, ['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => trans('general.reference')])]) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' {!! Form::hidden('invoice_id', $invoice->id, ['id' => 'invoice_id', 'class' => 'form-control', 'required' => 'required']) !!}';
|
||||
html += ' </div>';
|
||||
html += ' <div class="modal-footer" style="text-align: left;">';
|
||||
html += ' <button type="button" onclick="addPayment();" class="btn btn-success">{{ trans('general.save') }}</button>';
|
||||
html += ' <button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('general.cancel') }}</button>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
|
||||
$('body').append(html);
|
||||
|
||||
$('#paid_at').datepicker({
|
||||
format: 'yyyy-mm-dd',
|
||||
weekStart: 1,
|
||||
autoclose: true,
|
||||
language: '{{ language()->getShortCode() }}'
|
||||
});
|
||||
|
||||
$("#account_id").select2({
|
||||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.accounts', 1)]) }}"
|
||||
});
|
||||
|
||||
$("#payment_method").select2({
|
||||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.payment_methods', 1)]) }}"
|
||||
});
|
||||
|
||||
$('#payment-modal').modal('show');
|
||||
});
|
||||
|
||||
$(document).on('change', '#account_id', function (e) {
|
||||
$.ajax({
|
||||
url: '{{ url("banking/accounts/currency") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: 'account_id=' + $(this).val(),
|
||||
success: function(data) {
|
||||
$('#currency').val(data.currency_name);
|
||||
$('#currency_code').val(data.currency_code);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '#button-email', function (e) {
|
||||
$('#email-modal').remove();
|
||||
|
||||
@ -458,6 +354,7 @@
|
||||
|
||||
$('#email-modal').modal('show');
|
||||
});
|
||||
|
||||
@if($invoice->attachment)
|
||||
$(document).on('click', '#remove-attachment', function (e) {
|
||||
confirmDelete("#attachment-{!! $invoice->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '<strong>' . $invoice->attachment->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
|
||||
@ -465,68 +362,19 @@
|
||||
@endif
|
||||
});
|
||||
|
||||
function addPayment() {
|
||||
$('.help-block').remove();
|
||||
$(document).on('click', '#button-payment', function (e) {
|
||||
$('#modal-add-payment').remove();
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("incomes/invoices/payment") }}',
|
||||
type: 'POST',
|
||||
url: '{{ url("modals/invoices/" . $invoice->id . "/payment/create") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: $('#payment-modal input[type=\'text\'], #payment-modal input[type=\'hidden\'], #payment-modal textarea, #payment-modal select'),
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
beforeSend: function() {
|
||||
$('#payment-modal .modal-content').append('<div id="loading" class="text-center"><i class="fa fa-spinner fa-spin fa-5x checkout-spin"></i></div>');
|
||||
},
|
||||
complete: function() {
|
||||
$('#loading').remove();
|
||||
},
|
||||
success: function(json) {
|
||||
if (json['error']) {
|
||||
$('#payment-modal .modal-message').append('<div class="alert alert-danger">' + json['message'] + '</div>');
|
||||
$('div.alert-danger').delay(3000).fadeOut(350);
|
||||
}
|
||||
|
||||
if (json['success']) {
|
||||
$('#payment-modal .modal-message').before('<div class="alert alert-success">' + json['message'] + '</div>');
|
||||
$('div.alert-success').delay(3000).fadeOut(350);
|
||||
|
||||
setTimeout(function(){
|
||||
$("#payment-modal").modal('hide');
|
||||
|
||||
location.reload();
|
||||
}, 3000);
|
||||
}
|
||||
},
|
||||
error: function(data){
|
||||
var errors = data.responseJSON;
|
||||
|
||||
if (typeof errors !== 'undefined') {
|
||||
if (errors.paid_at) {
|
||||
$('#payment-modal #paid_at').parent().after('<p class="help-block">' + errors.paid_at + '</p>');
|
||||
}
|
||||
|
||||
if (errors.amount) {
|
||||
$('#payment-modal #amount').parent().after('<p class="help-block">' + errors.amount + '</p>');
|
||||
}
|
||||
|
||||
if (errors.account_id) {
|
||||
$('#payment-modal #account_id').parent().after('<p class="help-block">' + errors.account_id + '</p>');
|
||||
}
|
||||
|
||||
if (errors.currency_code) {
|
||||
$('#payment-modal #currency_code').parent().after('<p class="help-block">' + errors.currency_code + '</p>');
|
||||
}
|
||||
|
||||
if (errors.category_id) {
|
||||
$('#payment-modal #category_id').parent().after('<p class="help-block">' + errors.category_id + '</p>');
|
||||
}
|
||||
|
||||
if (errors.payment_method) {
|
||||
$('#payment-modal #payment_method').parent().after('<p class="help-block">' + errors.payment_method + '</p>');
|
||||
}
|
||||
$('body').append(json['html']);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
176
resources/views/modals/invoices/payment.blade.php
Normal file
176
resources/views/modals/invoices/payment.blade.php
Normal file
@ -0,0 +1,176 @@
|
||||
<div class="modal fade" id="modal-add-payment" style="display: none;">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">{{ trans('general.title.new', ['type' => trans_choice('general.categories', 1)]) }}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="modal-message"></div>
|
||||
{!! Form::open(['id' => 'form-add-payment', 'role' => 'form']) !!}
|
||||
<div class="row">
|
||||
{{ Form::textGroup('paid_at', trans('general.date'), 'calendar',['id' => 'paid_at', 'class' => 'form-control', 'required' => 'required', 'data-inputmask' => '\'alias\': \'yyyy-mm-dd\'', 'data-mask' => '', 'autocomplete' => 'off'], Date::now()->toDateString()) }}
|
||||
|
||||
{{ Form::textGroup('amount', trans('general.amount'), 'money', ['required' => 'required', 'autofocus' => 'autofocus'], $invoice->grand_total) }}
|
||||
|
||||
{{ Form::selectGroup('account_id', trans_choice('general.accounts', 1), 'university', $accounts, setting('general.default_account')) }}
|
||||
|
||||
@stack('currency_code_input_start')
|
||||
<div class="form-group col-md-6 required">
|
||||
{!! Form::label('currency_code', trans_choice('general.currencies', 1), ['class' => 'control-label']) !!}
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><i class="fa fa-exchange"></i></div>
|
||||
{!! Form::text('currency', $currencies[$account_currency_code], ['id' => 'currency', 'class' => 'form-control', 'required' => 'required', 'disabled' => 'disabled']) !!}
|
||||
{!! Form::hidden('currency_code', $account_currency_code, ['id' => 'currency_code', 'class' => 'form-control', 'required' => 'required']) !!}
|
||||
</div>
|
||||
</div>
|
||||
@stack('currency_code_input_end')
|
||||
|
||||
{{ Form::textareaGroup('description', trans('general.description')) }}
|
||||
|
||||
{{ Form::selectGroup('payment_method', trans_choice('general.payment_methods', 1), 'credit-card', $payment_methods, setting('general.default_payment_method')) }}
|
||||
|
||||
{{ Form::textGroup('reference', trans('general.reference'), 'file-text-o',[]) }}
|
||||
|
||||
{!! Form::hidden('invoice_id', $invoice->id, ['id' => 'invoice_id', 'class' => 'form-control', 'required' => 'required']) !!}
|
||||
</div>
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="pull-left">
|
||||
{!! Form::button('<span class="fa fa-save"></span> ' . trans('general.save'), ['type' => 'button', 'id' =>'button-add-payment', 'class' => 'btn btn-success']) !!}
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><span class="fa fa-times-circle"></span> {{ trans('general.cancel') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('#modal-add-payment #amount').focus();
|
||||
|
||||
$(document).ready(function(){
|
||||
$('#modal-add-payment').modal('show');
|
||||
|
||||
$("#modal-add-payment #amount").maskMoney({
|
||||
thousands : '{{ $currency->thousands_separator }}',
|
||||
decimal : '{{ $currency->decimal_mark }}',
|
||||
precision : {{ $currency->precision }},
|
||||
allowZero : true,
|
||||
@if($currency->symbol_first)
|
||||
prefix : '{{ $currency->symbol }}'
|
||||
@else
|
||||
suffix : '{{ $currency->symbol }}'
|
||||
@endif
|
||||
});
|
||||
|
||||
$('#modal-add-payment #amount').trigger('focusout');
|
||||
|
||||
$('#modal-add-payment #paid_at').datepicker({
|
||||
format: 'yyyy-mm-dd',
|
||||
weekStart: 1,
|
||||
autoclose: true,
|
||||
language: '{{ language()->getShortCode() }}'
|
||||
});
|
||||
|
||||
$("#modal-add-payment #account_id").select2({
|
||||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.accounts', 1)]) }}"
|
||||
});
|
||||
|
||||
$("#modal-add-payment #payment_method").select2({
|
||||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.payment_methods', 1)]) }}"
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('change', '#modal-add-payment #account_id', function (e) {
|
||||
$.ajax({
|
||||
url: '{{ url("banking/accounts/currency") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: 'account_id=' + $(this).val(),
|
||||
success: function(data) {
|
||||
$('#modal-add-payment #currency').val(data.currency_name);
|
||||
$('#modal-add-payment #currency_code').val(data.currency_code);
|
||||
|
||||
amount = $('#modal-add-payment #amount').maskMoney('unmasked')[0];
|
||||
|
||||
$("#modal-add-payment #amount").maskMoney({
|
||||
thousands : data.thousands_separator,
|
||||
decimal : data.decimal_mark,
|
||||
precision : data.precision,
|
||||
allowZero : true,
|
||||
prefix : (data.symbol_first) ? data.symbol : '',
|
||||
suffix : (data.symbol_first) ? '' : data.symbol
|
||||
});
|
||||
|
||||
$('#modal-add-payment #amount').val(amount);
|
||||
|
||||
$('#modal-add-payment #amount').focus();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '#button-add-payment', function (e) {
|
||||
$('.help-block').remove();
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("modals/invoices/" . $invoice->id . "/payment") }}',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: $("#form-add-payment").serialize(),
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
beforeSend: function() {
|
||||
$('#modal-add-payment .modal-content').append('<div id="loading" class="text-center"><i class="fa fa-spinner fa-spin fa-5x checkout-spin"></i></div>');
|
||||
},
|
||||
complete: function() {
|
||||
$('#loading').remove();
|
||||
},
|
||||
success: function(json) {
|
||||
if (json['error']) {
|
||||
$('#modal-add-payment .modal-message').append('<div class="alert alert-danger">' + json['message'] + '</div>');
|
||||
$('div.alert-danger').delay(3000).fadeOut(350);
|
||||
}
|
||||
|
||||
if (json['success']) {
|
||||
$('#modal-add-payment .modal-message').before('<div class="alert alert-success">' + json['message'] + '</div>');
|
||||
$('div.alert-success').delay(3000).fadeOut(350);
|
||||
|
||||
setTimeout(function(){
|
||||
$("#modal-add-payment").modal('hide');
|
||||
|
||||
location.reload();
|
||||
}, 3000);
|
||||
}
|
||||
},
|
||||
error: function(data){
|
||||
var errors = data.responseJSON;
|
||||
|
||||
if (typeof errors !== 'undefined') {
|
||||
if (errors.paid_at) {
|
||||
$('#modal-add-payment #paid_at').parent().after('<p class="help-block">' + errors.paid_at + '</p>');
|
||||
}
|
||||
|
||||
if (errors.amount) {
|
||||
$('#modal-add-payment #amount').parent().after('<p class="help-block">' + errors.amount + '</p>');
|
||||
}
|
||||
|
||||
if (errors.account_id) {
|
||||
$('#modal-add-payment #account_id').parent().after('<p class="help-block">' + errors.account_id + '</p>');
|
||||
}
|
||||
|
||||
if (errors.currency_code) {
|
||||
$('#modal-add-payment #currency_code').parent().after('<p class="help-block">' + errors.currency_code + '</p>');
|
||||
}
|
||||
|
||||
if (errors.category_id) {
|
||||
$('#modal-add-payment #category_id').parent().after('<p class="help-block">' + errors.category_id + '</p>');
|
||||
}
|
||||
|
||||
if (errors.payment_method) {
|
||||
$('#modal-add-payment #payment_method').parent().after('<p class="help-block">' + errors.payment_method + '</p>');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
@ -53,7 +53,7 @@ Route::group(['middleware' => 'language'], function () {
|
||||
Route::get('invoices/{invoice}/print', 'Incomes\Invoices@printInvoice');
|
||||
Route::get('invoices/{invoice}/pdf', 'Incomes\Invoices@pdfInvoice');
|
||||
Route::get('invoices/{invoice}/duplicate', 'Incomes\Invoices@duplicate');
|
||||
Route::get('invoices/addItem', 'Incomes\Invoices@addItem')->name('invoice.add.item');
|
||||
Route::get('invoices/addItem', 'Incomes\Invoices@addItem')->middleware(['money'])->name('invoice.add.item');
|
||||
Route::post('invoices/payment', 'Incomes\Invoices@payment')->middleware(['dateformat', 'money'])->name('invoice.payment');
|
||||
Route::delete('invoices/payment/{payment}', 'Incomes\Invoices@paymentDestroy');
|
||||
Route::post('invoices/import', 'Incomes\Invoices@import')->name('invoices.import');
|
||||
@ -167,6 +167,7 @@ Route::group(['middleware' => 'language'], function () {
|
||||
Route::resource('categories', 'Modals\Categories');
|
||||
Route::resource('customers', 'Modals\Customers');
|
||||
Route::resource('vendors', 'Modals\Vendors');
|
||||
Route::resource('invoices/{invoice}/payment', 'Modals\InvoicePayments', ['middleware' => ['dateformat', 'money']]);
|
||||
});
|
||||
|
||||
/* @deprecated */
|
||||
|
Loading…
x
Reference in New Issue
Block a user