refs #443 invoice create and edit add stack

This commit is contained in:
cuneytsenturk
2018-08-16 10:32:07 +03:00
parent 17eda360d5
commit 30298635fd
5 changed files with 201 additions and 337 deletions

View File

@ -8,6 +8,7 @@ use App\Events\InvoiceUpdated;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\Income\Invoice as Request; use App\Http\Requests\Income\Invoice as Request;
use App\Http\Requests\Income\InvoicePayment as PaymentRequest; use App\Http\Requests\Income\InvoicePayment as PaymentRequest;
use Illuminate\Http\Request as ItemRequest;
use App\Models\Banking\Account; use App\Models\Banking\Account;
use App\Models\Income\Customer; use App\Models\Income\Customer;
use App\Models\Income\Invoice; use App\Models\Income\Invoice;
@ -524,7 +525,7 @@ class Invoices extends Controller
$tables = ['items', 'histories', 'payments', 'totals']; $tables = ['items', 'histories', 'payments', 'totals'];
foreach ($tables as $table) { foreach ($tables as $table) {
$excel->sheet('invoice_' . $table, function($sheet) use ($invoices, $table) { $excel->sheet('invoice_' . $table, function ($sheet) use ($invoices, $table) {
$hidden_fields = ['id', 'company_id', 'created_at', 'updated_at', 'deleted_at', 'title']; $hidden_fields = ['id', 'company_id', 'created_at', 'updated_at', 'deleted_at', 'title'];
$i = 1; $i = 1;
@ -856,6 +857,31 @@ class Invoices extends Controller
return redirect()->back(); return redirect()->back();
} }
public function addItem(ItemRequest $request)
{
if ($request['item_row']) {
$item_row = $request['item_row'];
$taxes = Tax::enabled()->orderBy('rate')->get()->pluck('title', 'id');
$html = view('incomes.invoices.item', compact('item_row', 'taxes'))->render();
return response()->json([
'success' => true,
'error' => false,
'message' => 'null',
'html' => $html,
]);
}
return response()->json([
'success' => false,
'error' => true,
'message' => trans('issue'),
'html' => 'null',
]);
}
protected function prepareInvoice(Invoice $invoice) protected function prepareInvoice(Invoice $invoice)
{ {
$paid = 0; $paid = 0;

View File

@ -8,17 +8,19 @@
{!! Form::open(['url' => 'incomes/invoices', 'files' => true, 'role' => 'form']) !!} {!! Form::open(['url' => 'incomes/invoices', 'files' => true, 'role' => 'form']) !!}
<div class="box-body"> <div class="box-body">
@stack('customer_id_input_start')
<div class="form-group col-md-6 required {{ $errors->has('customer_id') ? 'has-error' : ''}}"> <div class="form-group col-md-6 required {{ $errors->has('customer_id') ? 'has-error' : ''}}">
{!! Form::label('customer_id', trans_choice('general.customers', 1), ['class' => 'control-label']) !!} {!! Form::label('customer_id', trans_choice('general.customers', 1), ['class' => 'control-label']) !!}
<div class="input-group"> <div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div> <div class="input-group-addon"><i class="fa fa-user"></i></div>
{!! Form::select('customer_id', $customers, null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.customers', 1)])])) !!} {!! Form::select('customer_id', $customers, null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.customers', 1)])])) !!}
<div class="input-group-btn"> <div class="input-group-btn">
<button type="button" onclick="createCustomer();" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button> <button type="button" id="button-customer" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button>
</div> </div>
</div> </div>
{!! $errors->first('customer_id', '<p class="help-block">:message</p>') !!} {!! $errors->first('customer_id', '<p class="help-block">:message</p>') !!}
</div> </div>
@stack('customer_id_input_end')
{{ Form::selectGroup('currency_code', trans_choice('general.currencies', 1), 'exchange', $currencies, setting('general.default_currency')) }} {{ Form::selectGroup('currency_code', trans_choice('general.currencies', 1), 'exchange', $currencies, setting('general.default_currency')) }}
@ -36,46 +38,43 @@
<table class="table table-bordered" id="items"> <table class="table table-bordered" id="items">
<thead> <thead>
<tr style="background-color: #f9f9f9;"> <tr style="background-color: #f9f9f9;">
@stack('actions_th_start')
<th width="5%" class="text-center">{{ trans('general.actions') }}</th> <th width="5%" class="text-center">{{ trans('general.actions') }}</th>
@stack('actions_th_end')
@stack('name_th_start')
<th width="40%" class="text-left">{{ trans('general.name') }}</th> <th width="40%" class="text-left">{{ trans('general.name') }}</th>
@stack('name_th_end')
@stack('quantity_th_start')
<th width="5%" class="text-center">{{ trans('invoices.quantity') }}</th> <th width="5%" class="text-center">{{ trans('invoices.quantity') }}</th>
@stack('quantity_th_end')
@stack('price_th_start')
<th width="10%" class="text-right">{{ trans('invoices.price') }}</th> <th width="10%" class="text-right">{{ trans('invoices.price') }}</th>
@stack('price_th_end')
@stack('taxes_th_start')
<th width="15%" class="text-right">{{ trans_choice('general.taxes', 1) }}</th> <th width="15%" class="text-right">{{ trans_choice('general.taxes', 1) }}</th>
@stack('taxes_th_end')
@stack('total_th_start')
<th width="10%" class="text-right">{{ trans('invoices.total') }}</th> <th width="10%" class="text-right">{{ trans('invoices.total') }}</th>
@stack('total_th_end')
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $item_row = 0; ?> <?php $item_row = 0; ?>
<tr id="item-row-{{ $item_row }}"> @include('incomes.invoices.item')
<td class="text-center" style="vertical-align: middle;">
<button type="button" onclick="$(this).tooltip('destroy'); $('#item-row-{{ $item_row }}').remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
</td>
<td>
<input class="form-control typeahead" required="required" placeholder="{{ trans('general.form.enter', ['field' => trans_choice('invoices.item_name', 1)]) }}" name="item[{{ $item_row }}][name]" type="text" id="item-name-{{ $item_row }}" autocomplete="off">
<input name="item[{{ $item_row }}][item_id]" type="hidden" id="item-id-{{ $item_row }}">
</td>
<td>
<input class="form-control text-center" required="required" name="item[{{ $item_row }}][quantity]" type="text" id="item-quantity-{{ $item_row }}">
</td>
<td>
<input class="form-control text-right" required="required" name="item[{{ $item_row }}][price]" type="text" id="item-price-{{ $item_row }}">
</td>
<td>
{!! Form::select('item[' . $item_row . '][tax_id]', $taxes, setting('general.default_tax'), ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)])]) !!}
</td>
<td class="text-right" style="vertical-align: middle;">
<span id="item-total-{{ $item_row }}">0</span>
</td>
</tr>
<?php $item_row++; ?> <?php $item_row++; ?>
@stack('add_item_td_start')
<tr id="addItem"> <tr id="addItem">
<td class="text-center"><button type="button" onclick="addItem();" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-xs btn-primary" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i></button></td> <td class="text-center"><button type="button" id="button-add-item" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-xs btn-primary" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i></button></td>
<td class="text-right" colspan="5"></td> <td class="text-right" colspan="5"></td>
</tr> </tr>
@stack('add_item_td_end')
@stack('sub_total_td_start')
<tr> <tr>
<td class="text-right" colspan="5"><strong>{{ trans('invoices.sub_total') }}</strong></td> <td class="text-right" colspan="5"><strong>{{ trans('invoices.sub_total') }}</strong></td>
<td class="text-right"><span id="sub-total">0</span></td> <td class="text-right"><span id="sub-total">0</span></td>
</tr> </tr>
@stack('sub_total_td_end')
@stack('add_discount_td_start')
<tr> <tr>
<td class="text-right" style="vertical-align: middle;" colspan="5"> <td class="text-right" style="vertical-align: middle;" colspan="5">
<a href="javascript:void(0)" id="discount-text" rel="popover">{{ trans('invoices.add_discount') }}</a> <a href="javascript:void(0)" id="discount-text" rel="popover">{{ trans('invoices.add_discount') }}</a>
@ -85,14 +84,19 @@
{!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right']) !!} {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right']) !!}
</td> </td>
</tr> </tr>
@stack('add_discount_td_end')
@stack('tax_total_td_start')
<tr> <tr>
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td> <td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
<td class="text-right"><span id="tax-total">0</span></td> <td class="text-right"><span id="tax-total">0</span></td>
</tr> </tr>
@stack('tax_total_td_end')
@stack('grand_total_td_start')
<tr> <tr>
<td class="text-right" colspan="5"><strong>{{ trans('invoices.total') }}</strong></td> <td class="text-right" colspan="5"><strong>{{ trans('invoices.total') }}</strong></td>
<td class="text-right"><span id="grand-total">0</span></td> <td class="text-right"><span id="grand-total">0</span></td>
</tr> </tr>
@stack('grand_total_td_end')
</tbody> </tbody>
</table> </table>
</div> </div>
@ -100,17 +104,19 @@
{{ Form::textareaGroup('notes', trans_choice('general.notes', 2)) }} {{ Form::textareaGroup('notes', trans_choice('general.notes', 2)) }}
@stack('category_id_input_start')
<div class="form-group col-md-6 required {{ $errors->has('category_id') ? 'has-error' : ''}}"> <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']) !!} {!! Form::label('category_id', trans_choice('general.categories', 1), ['class' => 'control-label']) !!}
<div class="input-group"> <div class="input-group">
<div class="input-group-addon"><i class="fa fa-folder-open-o"></i></div> <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)])])) !!} {!! 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"> <div class="input-group-btn">
<button type="button" onclick="createCategory();" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button> <button type="button" id="button-category" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button>
</div> </div>
</div> </div>
{!! $errors->first('category_id', '<p class="help-block">:message</p>') !!} {!! $errors->first('category_id', '<p class="help-block">:message</p>') !!}
</div> </div>
@stack('category_id_input_end')
{{ Form::recurring('create') }} {{ Form::recurring('create') }}
@ -154,47 +160,31 @@
<script type="text/javascript"> <script type="text/javascript">
var item_row = '{{ $item_row }}'; var item_row = '{{ $item_row }}';
function addItem() { $(document).on('click', '#button-add-item', function (e) {
html = '<tr id="item-row-' + item_row + '">'; $.ajax({
html += ' <td class="text-center" style="vertical-align: middle;">'; url: '{{ url("incomes/invoices/addItem") }}',
html += ' <button type="button" onclick="$(this).tooltip(\'destroy\'); $(\'#item-row-' + item_row + '\').remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>'; type: 'GET',
html += ' </td>'; dataType: 'JSON',
html += ' <td>'; data: {item_row: item_row},
html += ' <input class="form-control typeahead" required="required" placeholder="{{ trans('general.form.enter', ['field' => trans_choice('invoices.item_name', 1)]) }}" name="item[' + item_row + '][name]" type="text" id="item-name-' + item_row + '" autocomplete="off">'; success: function(json) {
html += ' <input name="item[' + item_row + '][item_id]" type="hidden" id="item-id-' + item_row + '">'; if (json['success']) {
html += ' </td>'; $('#items tbody #addItem').before(json['html']);
html += ' <td>'; //$('[rel=tooltip]').tooltip();
html += ' <input class="form-control text-center" required="required" name="item[' + item_row + '][quantity]" type="text" id="item-quantity-' + item_row + '">';
html += ' </td>';
html += ' <td>';
html += ' <input class="form-control text-right" required="required" name="item[' + item_row + '][price]" type="text" id="item-price-' + item_row + '">';
html += ' </td>';
html += ' <td>';
html += ' <select class="form-control tax-select2" name="item[' + item_row + '][tax_id]" id="item-tax-' + item_row + '">';
html += ' <option selected="selected" value="">{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}</option>';
@foreach($taxes as $tax_key => $tax_value)
html += ' <option value="{{ $tax_key }}">{{ $tax_value }}</option>';
@endforeach
html += ' </select>';
html += ' </td>';
html += ' <td class="text-right" style="vertical-align: middle;">';
html += ' <span id="item-total-' + item_row + '">0</span>';
html += ' </td>';
$('#items tbody #addItem').before(html); $('[data-toggle="tooltip"]').tooltip('hide');
//$('[rel=tooltip]').tooltip();
$('[data-toggle="tooltip"]').tooltip('hide'); $('#item-row-' + item_row + ' .tax-select2').select2({
placeholder: {
id: '-1', // the value of the option
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
}
});
$('#item-row-' + item_row + ' .tax-select2').select2({ item_row++;
placeholder: { }
id: '-1', // the value of the option
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
} }
}); });
});
item_row++;
}
$(document).ready(function(){ $(document).ready(function(){
//Date picker //Date picker
@ -382,200 +372,31 @@
}); });
} }
function createCustomer() { $(document).on('click', '#button-customer', function (e) {
$('#modal-create-customer').remove(); $('#modal-create-customer').remove();
modal = '<div class="modal fade" id="modal-create-customer" style="display: none;">';
modal += ' <div class="modal-dialog modal-lg">';
modal += ' <div class="modal-content">';
modal += ' <div class="modal-header">';
modal += ' <h4 class="modal-title">{{ trans('general.title.new', ['type' => trans_choice('general.customers', 1)]) }}</h4>';
modal += ' </div>';
modal += ' <div class="modal-body">';
modal += ' {!! Form::open(['id' => 'form-create-customer', 'role' => 'form']) !!}';
modal += ' <div class="row">';
modal += ' <div class="form-group col-md-6 required">';
modal += ' <label for="name" class="control-label">{{ trans('general.name') }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>';
modal += ' <input class="form-control" placeholder="{{ trans('general.name') }}" required="required" name="name" type="text" id="name">';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-6">';
modal += ' <label for="email" class="control-label">{{ trans('general.email') }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-envelope"></i></div>';
modal += ' <input class="form-control" placeholder="{{ trans('general.email') }}" required="required" name="email" type="text" id="email">';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-6">';
modal += ' <label for="tax_number" class="control-label">{{ trans('general.tax_number') }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
modal += ' <input class="form-control" placeholder="{{ trans('general.tax_number') }}" name="tax_number" type="text" id="tax_number">';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-6 required">';
modal += ' <label for="email" class="control-label">{{ trans_choice('general.currencies', 1) }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-exchange"></i></div>';
modal += ' <select class="form-control" required="required" id="currency_code" name="currency_code">';
modal += ' <option value="">{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}</option>';
@foreach($currencies as $currency_code => $currency_name)
modal += ' <option value="{{ $currency_code }}" {{ (setting('general.default_currency') == $currency_code) ? 'selected' : '' }}>{{ $currency_name }}</option>';
@endforeach
modal += ' </select>';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-12">';
modal += ' <label for="address" class="control-label">{{ trans('general.address') }}</label>';
modal += ' <textarea class="form-control" placeholder="{{ trans('general.address') }}" rows="3" name="address" cols="50" id="address"></textarea>';
modal += ' </div>';
modal += ' {!! Form::hidden('enabled', '1', []) !!}';
modal += ' </div>';
modal += ' {!! Form::close() !!}';
modal += ' </div>';
modal += ' <div class="modal-footer">';
modal += ' <div class="pull-left">';
modal += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' =>'button-create-customer', 'class' => 'btn btn-success']) !!}';
modal += ' <button type="button" class="btn btn-default" data-dismiss="modal"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</button>';
modal += ' </div>';
modal += ' </div>';
modal += ' </div>';
modal += ' </div>';
modal += '</div>';
$('body').append(modal);
$("#modal-create-customer #currency_code").select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}"
});
$('#modal-create-customer').modal('show');
}
$(document).on('click', '#button-create-customer', function (e) {
$('#modal-create-customer .modal-header').before('<span id="span-loading" style="position: absolute; height: 100%; width: 100%; z-index: 99; background: #6da252; opacity: 0.4;"><i class="fa fa-spinner fa-spin" style="font-size: 16em !important;margin-left: 35%;margin-top: 8%;"></i></span>');
$.ajax({ $.ajax({
url: '{{ url("incomes/customers/customer") }}', url: '{{ url("modals/customers/create") }}',
type: 'POST', type: 'GET',
dataType: 'JSON', dataType: 'JSON',
data: $("#form-create-customer").serialize(), success: function(json) {
beforeSend: function () { if (json['success']) {
$(".form-group").removeClass("has-error"); $('body').append(json['html']);
$(".help-block").remove();
},
success: function(data) {
$('#span-loading').remove();
$('#modal-create-customer').modal('hide');
$("#customer_id").append('<option value="' + data.id + '" selected="selected">' + data.name + '</option>');
$('#customer_id').trigger('change');
$("#customer_id").select2('refresh');
},
error: function(error, textStatus, errorThrown) {
$('#span-loading').remove();
if (error.responseJSON.name) {
$("input[name='name']").parent().parent().addClass('has-error');
$("input[name='name']").parent().after('<p class="help-block">' + error.responseJSON.name + '</p>');
}
if (error.responseJSON.email) {
$("input[name='email']").parent().parent().addClass('has-error');
$("input[name='email']").parent().after('<p class="help-block">' + error.responseJSON.email + '</p>');
}
if (error.responseJSON.currency_code) {
$("select[name='currency_code']").parent().parent().addClass('has-error');
$("select[name='currency_code']").parent().after('<p class="help-block">' + error.responseJSON.currency_code + '</p>');
} }
} }
}); });
}); });
function createCategory() { $(document).on('click', '#button-category', function (e) {
$('#modal-create-category').remove(); $('#modal-create-category').remove();
modal = '<div class="modal fade" id="modal-create-category" style="display: none;">';
modal += ' <div class="modal-dialog modal-lg">';
modal += ' <div class="modal-content">';
modal += ' <div class="modal-header">';
modal += ' <h4 class="modal-title">{{ trans('general.title.new', ['type' => trans_choice('general.categories', 1)]) }}</h4>';
modal += ' </div>';
modal += ' <div class="modal-body">';
modal += ' {!! Form::open(['id' => 'form-create-category', 'role' => 'form']) !!}';
modal += ' <div class="row">';
modal += ' <div class="form-group col-md-6 required">';
modal += ' <label for="name" class="control-label">{{ trans('general.name') }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>';
modal += ' <input class="form-control" placeholder="{{ trans('general.name') }}" required="required" name="name" type="text" id="name">';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-6 required">';
modal += ' <label for="color" class="control-label">{{ trans('general.color') }}</label>';
modal += ' <div id="category-color-picker" class="input-group colorpicker-component">';
modal += ' <div class="input-group-addon"><i></i></div>';
modal += ' <input class="form-control" value="#00a65a" placeholder="{{ trans('general.color') }}" required="required" name="color" type="text" id="color">';
modal += ' </div>';
modal += ' </div>';
modal += ' {!! Form::hidden('type', 'income', []) !!}';
modal += ' {!! Form::hidden('enabled', '1', []) !!}';
modal += ' </div>';
modal += ' {!! Form::close() !!}';
modal += ' </div>';
modal += ' <div class="modal-footer">';
modal += ' <div class="pull-left">';
modal += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' =>'button-create-category', 'class' => 'btn btn-success']) !!}';
modal += ' <button type="button" class="btn btn-default" data-dismiss="modal"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</button>';
modal += ' </div>';
modal += ' </div>';
modal += ' </div>';
modal += ' </div>';
modal += '</div>';
$('body').append(modal);
$('#category-color-picker').colorpicker();
$('#modal-create-category').modal('show');
}
$(document).on('click', '#button-create-category', function (e) {
$('#modal-create-category .modal-header').before('<span id="span-loading" style="position: absolute; height: 100%; width: 100%; z-index: 99; background: #6da252; opacity: 0.4;"><i class="fa fa-spinner fa-spin" style="font-size: 10em !important;margin-left: 35%;margin-top: 8%;"></i></span>');
$.ajax({ $.ajax({
url: '{{ url("settings/categories/category") }}', url: '{{ url("modals/categories/create") }}',
type: 'POST', type: 'GET',
dataType: 'JSON', dataType: 'JSON',
data: $("#form-create-category").serialize(), success: function(json) {
beforeSend: function () { if (json['success']) {
$(".form-group").removeClass("has-error"); $('body').append(json['html']);
$(".help-block").remove();
},
success: function(data) {
$('#span-loading').remove();
$('#modal-create-category').modal('hide');
$("#category_id").append('<option value="' + data.id + '" selected="selected">' + data.name + '</option>');
$("#category_id").select2('refresh');
},
error: function(error, textStatus, errorThrown) {
$('#span-loading').remove();
if (error.responseJSON.name) {
$("input[name='name']").parent().parent().addClass('has-error');
$("input[name='name']").parent().after('<p class="help-block">' + error.responseJSON.name + '</p>');
}
if (error.responseJSON.color) {
$("input[name='color']").parent().parent().addClass('has-error');
$("input[name='color']").parent().after('<p class="help-block">' + error.responseJSON.color + '</p>');
} }
} }
}); });

View File

@ -19,78 +19,56 @@
{{ Form::textGroup('invoice_number', trans('invoices.invoice_number'), 'file-text-o') }} {{ Form::textGroup('invoice_number', trans('invoices.invoice_number'), 'file-text-o') }}
{{ Form::textGroup('order_number', trans('invoices.order_number'), 'shopping-cart',[]) }} {{ Form::textGroup('order_number', trans('invoices.order_number'), 'shopping-cart',[]) }}
<div class="form-group col-md-12"> <div class="form-group col-md-12">
{!! Form::label('items', trans_choice('general.items', 2), ['class' => 'control-label']) !!} {!! Form::label('items', trans_choice('general.items', 2), ['class' => 'control-label']) !!}
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-bordered" id="items"> <table class="table table-bordered" id="items">
<thead> <thead>
<tr style="background-color: #f9f9f9;"> <tr style="background-color: #f9f9f9;">
@stack('actions_th_start')
<th width="5%" class="text-center">{{ trans('general.actions') }}</th> <th width="5%" class="text-center">{{ trans('general.actions') }}</th>
@stack('actions_th_end')
@stack('name_th_start')
<th width="40%" class="text-left">{{ trans('general.name') }}</th> <th width="40%" class="text-left">{{ trans('general.name') }}</th>
@stack('name_th_end')
@stack('quantity_th_start')
<th width="5%" class="text-center">{{ trans('invoices.quantity') }}</th> <th width="5%" class="text-center">{{ trans('invoices.quantity') }}</th>
@stack('quantity_th_end')
@stack('price_th_start')
<th width="10%" class="text-right">{{ trans('invoices.price') }}</th> <th width="10%" class="text-right">{{ trans('invoices.price') }}</th>
@stack('price_th_end')
@stack('taxes_th_start')
<th width="15%" class="text-right">{{ trans_choice('general.taxes', 1) }}</th> <th width="15%" class="text-right">{{ trans_choice('general.taxes', 1) }}</th>
@stack('taxes_th_end')
@stack('total_th_start')
<th width="10%" class="text-right">{{ trans('invoices.total') }}</th> <th width="10%" class="text-right">{{ trans('invoices.total') }}</th>
@stack('total_th_end')
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $item_row = 0; ?> <?php $item_row = 0; ?>
@foreach($invoice->items as $item) @foreach($invoice->items as $item)
<tr id="item-row-{{ $item_row }}"> @include('incomes.invoices.item')
<td class="text-center" style="vertical-align: middle;">
<button type="button" onclick="$(this).tooltip('destroy'); $('#item-row-{{ $item_row }}').remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
</td>
<td>
<input value="{{ $item->name }}" class="form-control typeahead" required="required" placeholder="{{ trans('general.form.enter', ['field' => trans_choice('invoices.item_name', 1)]) }}" name="item[{{ $item_row }}][name]" type="text" id="item-name-{{ $item_row }}">
<input value="{{ $item->item_id }}" name="item[{{ $item_row }}][item_id]" type="hidden" id="item-id-{{ $item_row }}">
</td>
<td>
<input value="{{ $item->quantity }}" class="form-control text-center" required="required" name="item[{{ $item_row }}][quantity]" type="text" id="item-quantity-{{ $item_row }}">
</td>
<td>
<input value="{{ $item->price }}" class="form-control text-right" required="required" name="item[{{ $item_row }}][price]" type="text" id="item-price-{{ $item_row }}">
</td>
<td>
{!! Form::select('item[' . $item_row . '][tax_id]', $taxes, $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'placeholder' => trans('general.form.enter', ['field' => trans_choice('general.taxes', 1)])]) !!}
</td>
<td class="text-right" style="vertical-align: middle;">
<span id="item-total-{{ $item_row }}">@money($item->total, $invoice->currency_code, true)</span>
</td>
</tr>
<?php $item_row++; ?> <?php $item_row++; ?>
@endforeach @endforeach
@if (empty($invoice->items)) @if (empty($invoice->items))
<tr id="item-row-{{ $item_row }}"> @include('incomes.invoices.item')
<td class="text-center" style="vertical-align: middle;">
<button type="button" onclick="$(this).tooltip('destroy'); $('#item-row-{{ $item_row }}').remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
</td>
<td>
<input class="form-control typeahead" required="required" placeholder="{{ trans('general.form.enter', ['field' => trans_choice('invoices.item_name', 1)]) }}" name="item[{{ $item_row }}][name]" type="text" id="item-name-{{ $item_row }}" autocomplete="off">
<input name="item[{{ $item_row }}][item_id]" type="hidden" id="item-id-{{ $item_row }}">
</td>
<td>
<input class="form-control text-center" required="required" name="item[{{ $item_row }}][quantity]" type="text" id="item-quantity-{{ $item_row }}">
</td>
<td>
<input class="form-control text-right" required="required" name="item[{{ $item_row }}][price]" type="text" id="item-price-{{ $item_row }}">
</td>
<td>
{!! Form::select('item[' . $item_row . '][tax_id]', $taxes, null, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control select2', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)])]) !!}
</td>
<td class="text-right" style="vertical-align: middle;">
<span id="item-total-{{ $item_row }}">0</span>
</td>
</tr>
@endif @endif
<?php $item_row++; ?> <?php $item_row++; ?>
@stack('add_item_td_start')
<tr id="addItem"> <tr id="addItem">
<td class="text-center"><button type="button" onclick="addItem();" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-xs btn-primary" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i></button></td> <td class="text-center"><button type="button" id="button-add-item" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-xs btn-primary" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i></button></td>
<td class="text-right" colspan="5"></td> <td class="text-right" colspan="5"></td>
</tr> </tr>
@stack('add_item_td_end')
@stack('sub_total_td_start')
<tr> <tr>
<td class="text-right" colspan="5"><strong>{{ trans('invoices.sub_total') }}</strong></td> <td class="text-right" colspan="5"><strong>{{ trans('invoices.sub_total') }}</strong></td>
<td class="text-right"><span id="sub-total">0</span></td> <td class="text-right"><span id="sub-total">0</span></td>
</tr> </tr>
@stack('sub_total_td_end')
@stack('add_discount_td_start')
<tr> <tr>
<td class="text-right" style="vertical-align: middle;" colspan="5"> <td class="text-right" style="vertical-align: middle;" colspan="5">
<a href="javascript:void(0)" id="discount-text" rel="popover">{{ trans('invoices.add_discount') }}</a> <a href="javascript:void(0)" id="discount-text" rel="popover">{{ trans('invoices.add_discount') }}</a>
@ -100,14 +78,19 @@
{!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right']) !!} {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right']) !!}
</td> </td>
</tr> </tr>
@stack('add_discount_td_end')
@stack('tax_total_td_start')
<tr> <tr>
<td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td> <td class="text-right" colspan="5"><strong>{{ trans_choice('general.taxes', 1) }}</strong></td>
<td class="text-right"><span id="tax-total">0</span></td> <td class="text-right"><span id="tax-total">0</span></td>
</tr> </tr>
@stack('tax_total_td_end')
@stack('grand_total_td_start')
<tr> <tr>
<td class="text-right" colspan="5"><strong>{{ trans('invoices.total') }}</strong></td> <td class="text-right" colspan="5"><strong>{{ trans('invoices.total') }}</strong></td>
<td class="text-right"><span id="grand-total">0</span></td> <td class="text-right"><span id="grand-total">0</span></td>
</tr> </tr>
@stack('grand_total_td_end')
</tbody> </tbody>
</table> </table>
</div> </div>
@ -158,47 +141,31 @@
<script type="text/javascript"> <script type="text/javascript">
var item_row = '{{ $item_row }}'; var item_row = '{{ $item_row }}';
function addItem() { $(document).on('click', '#button-add-item', function (e) {
html = '<tr id="item-row-' + item_row + '">'; $.ajax({
html += ' <td class="text-center" style="vertical-align: middle;">'; url: '{{ url("incomes/invoices/addItem") }}',
html += ' <button type="button" onclick="$(this).tooltip(\'destroy\'); $(\'#item-row-' + item_row + '\').remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>'; type: 'GET',
html += ' </td>'; dataType: 'JSON',
html += ' <td>'; data: {item_row: item_row},
html += ' <input class="form-control typeahead" required="required" placeholder="{{ trans('general.form.enter', ['field' => trans_choice('invoices.item_name', 1)]) }}" name="item[' + item_row + '][name]" type="text" id="item-name-' + item_row + '" autocomplete="off">'; success: function(json) {
html += ' <input name="item[' + item_row + '][item_id]" type="hidden" id="item-id-' + item_row + '">'; if (json['success']) {
html += ' </td>'; $('#items tbody #addItem').before(json['html']);
html += ' <td>'; //$('[rel=tooltip]').tooltip();
html += ' <input class="form-control text-center" required="required" name="item[' + item_row + '][quantity]" type="text" id="item-quantity-' + item_row + '">';
html += ' </td>';
html += ' <td>';
html += ' <input class="form-control text-right" required="required" name="item[' + item_row + '][price]" type="text" id="item-price-' + item_row + '">';
html += ' </td>';
html += ' <td>';
html += ' <select class="form-control tax-select2" name="item[' + item_row + '][tax_id]" id="item-tax-' + item_row + '">';
html += ' <option selected="selected" value="">{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}</option>';
@foreach($taxes as $tax_key => $tax_value)
html += ' <option value="{{ $tax_key }}">{{ $tax_value }}</option>';
@endforeach
html += ' </select>';
html += ' </td>';
html += ' <td class="text-right" style="vertical-align: middle;">';
html += ' <span id="item-total-' + item_row + '">0</span>';
html += ' </td>';
$('#items tbody #addItem').before(html); $('[data-toggle="tooltip"]').tooltip('hide');
//$('[rel=tooltip]').tooltip();
$('[data-toggle="tooltip"]').tooltip('hide'); $('#item-row-' + item_row + ' .tax-select2').select2({
placeholder: {
id: '-1', // the value of the option
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
}
});
$('#item-row-' + item_row + ' .tax-select2').select2({ item_row++;
placeholder: { }
id: '-1', // the value of the option
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
} }
}); });
});
item_row++;
}
$(document).ready(function(){ $(document).ready(function(){
totalItem(); totalItem();
@ -249,24 +216,24 @@
}); });
@if($invoice->attachment) @if($invoice->attachment)
attachment_html = '<span class="attachment">'; attachment_html = '<span class="attachment">';
attachment_html += ' <a href="{{ url('uploads/' . $invoice->attachment->id . '/download') }}">'; attachment_html += ' <a href="{{ url('uploads/' . $invoice->attachment->id . '/download') }}">';
attachment_html += ' <span id="download-attachment" class="text-primary">'; attachment_html += ' <span id="download-attachment" class="text-primary">';
attachment_html += ' <i class="fa fa-file-{{ $invoice->attachment->aggregate_type }}-o"></i> {{ $invoice->attachment->basename }}'; attachment_html += ' <i class="fa fa-file-{{ $invoice->attachment->aggregate_type }}-o"></i> {{ $invoice->attachment->basename }}';
attachment_html += ' </span>'; attachment_html += ' </span>';
attachment_html += ' </a>'; attachment_html += ' </a>';
attachment_html += ' {!! Form::open(['id' => 'attachment-' . $invoice->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline']) !!}'; attachment_html += ' {!! Form::open(['id' => 'attachment-' . $invoice->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline']) !!}';
attachment_html += ' <a id="remove-attachment" href="javascript:void();">'; attachment_html += ' <a id="remove-attachment" href="javascript:void();">';
attachment_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>'; attachment_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
attachment_html += ' </a>'; attachment_html += ' </a>';
attachment_html += ' {!! Form::close() !!}'; attachment_html += ' {!! Form::close() !!}';
attachment_html += '</span>'; attachment_html += '</span>';
$('.fancy-file .fake-file').append(attachment_html); $('.fancy-file .fake-file').append(attachment_html);
$(document).on('click', '#remove-attachment', function (e) { $(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') !!}"); 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') !!}");
}); });
@endif @endif
var autocomplete_path = "{{ url('common/items/autocomplete') }}"; var autocomplete_path = "{{ url('common/items/autocomplete') }}";

View File

@ -0,0 +1,49 @@
<tr id="item-row-{{ $item_row }}">
@stack('actions_td_start')
<td class="text-center" style="vertical-align: middle;">
@stack('actions_button_start')
<button type="button" onclick="$(this).tooltip('destroy'); $('#item-row-{{ $item_row }}').remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
@stack('actions_button_end')
</td>
@stack('actions_td_end')
@stack('name_td_start')
<td>
@stack('name_input_start')
<input value="{{ empty($item) ? '' : $item->name }}" class="form-control typeahead" required="required" placeholder="{{ trans('general.form.enter', ['field' => trans_choice('invoices.item_name', 1)]) }}" name="item[{{ $item_row }}][name]" type="text" id="item-name-{{ $item_row }}" autocomplete="off">
<input value="{{ empty($item) ? '' : $item->item_id }}" name="item[{{ $item_row }}][item_id]" type="hidden" id="item-id-{{ $item_row }}">
@stack('name_input_end')
</td>
@stack('name_td_end')
@stack('quantity_td_start')
<td>
@stack('quantity_input_start')
<input value="{{ empty($item) ? '' : $item->quantity }}" class="form-control text-center" required="required" name="item[{{ $item_row }}][quantity]" type="text" id="item-quantity-{{ $item_row }}">
@stack('quantity_input_end')
</td>
@stack('quantity_td_end')
@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 }}">
@stack('price_input_end')
</td>
@stack('price_td_end')
@stack('taxes_td_start')
<td>
@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)])]) !!}
@stack('tax_id_input_end')
</td>
@stack('taxes_td_end')
@stack('total_td_start')
<td class="text-right" style="vertical-align: middle;">
@stack('total_input_start')
@if (empty($item))
<span id="item-total-{{ $item_row }}">0</span>
@else
<span id="item-total-{{ $item_row }}">@money($item->total, $invoice->currency_code, true)</span>
@endif
@stack('total_input_end')
</td>
@stack('total_td_end')
</tr>

View File

@ -53,6 +53,7 @@ Route::group(['middleware' => 'language'], function () {
Route::get('invoices/{invoice}/print', 'Incomes\Invoices@printInvoice'); Route::get('invoices/{invoice}/print', 'Incomes\Invoices@printInvoice');
Route::get('invoices/{invoice}/pdf', 'Incomes\Invoices@pdfInvoice'); Route::get('invoices/{invoice}/pdf', 'Incomes\Invoices@pdfInvoice');
Route::get('invoices/{invoice}/duplicate', 'Incomes\Invoices@duplicate'); Route::get('invoices/{invoice}/duplicate', 'Incomes\Invoices@duplicate');
Route::get('invoices/addItem', 'Incomes\Invoices@addItem')->name('invoice.add.item');
Route::post('invoices/payment', 'Incomes\Invoices@payment')->middleware(['dateformat', 'money'])->name('invoice.payment'); Route::post('invoices/payment', 'Incomes\Invoices@payment')->middleware(['dateformat', 'money'])->name('invoice.payment');
Route::delete('invoices/payment/{payment}', 'Incomes\Invoices@paymentDestroy'); Route::delete('invoices/payment/{payment}', 'Incomes\Invoices@paymentDestroy');
Route::post('invoices/import', 'Incomes\Invoices@import')->name('invoices.import'); Route::post('invoices/import', 'Incomes\Invoices@import')->name('invoices.import');