close #620 Fixed: Invoice/Bill edit not change customer/vendor information

This commit is contained in:
cuneytsenturk 2018-11-12 12:04:01 +03:00
parent 393fb6ede7
commit 0a5d945452
6 changed files with 895 additions and 961 deletions

View File

@ -170,65 +170,19 @@
@push('scripts')
<script type="text/javascript">
var focus = false;
var item_row = '{{ $item_row }}';
$(document).on('click', '#button-add-item', function (e) {
var currency_code = $('#currency_code').val();
$.ajax({
url: '{{ url("expenses/bills/addItem") }}',
type: 'GET',
dataType: 'JSON',
data: {item_row: item_row, currency_code : currency_code},
success: function(json) {
if (json['success']) {
$('#items tbody #addItem').before(json['html']);
//$('[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)]) }}"
},
escapeMarkup: function (markup) {
return markup;
},
language: {
noResults: function () {
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
}
}
});
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++;
}
}
});
});
var currency_code = $('#currency_code').val();
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
$(document).ready(function(){
itemTableResize();
@if (old('item'))
$('#vendor_id').trigger('change');
@endif
$(".input-price").maskMoney({
itemTableResize();
$('.input-price').maskMoney({
thousands : '{{ $currency->thousands_separator }}',
decimal : '{{ $currency->decimal_mark }}',
precision : {{ $currency->precision }},
@ -260,7 +214,7 @@
language: '{{ language()->getShortCode() }}'
});
$(".tax-select2").select2({
$('.tax-select2').select2({
placeholder: {
id: '-1', // the value of the option
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
@ -275,15 +229,15 @@
}
});
$("#vendor_id").select2({
$('#vendor_id').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.vendors', 1)]) }}"
});
$("#currency_code").select2({
$('#currency_code').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}"
});
$("#category_id").select2({
$('#category_id').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
});
@ -293,188 +247,262 @@
placeholder : '{{ trans('general.form.no_file_selected') }}'
});
$(document).on('click', '#tax-add-new', function(e){
tax_name = $('.select2-search__field').val();
$('#modal-create-tax').remove();
$.ajax({
url: '{{ url("modals/taxes/create") }}',
type: 'GET',
dataType: 'JSON',
data: {name: tax_name},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
$(document).on('click', '.form-control.typeahead', function() {
input_id = $(this).attr('id').split('-');
item_id = parseInt(input_id[input_id.length-1]);
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
url: autocomplete_path,
type: 'GET',
dataType: 'JSON',
data: 'query=' + query + '&type=bill&currency_code=' + $('#currency_code').val(),
success: function(data) {
return process(data);
}
});
},
afterSelect: function (data) {
$('#item-id-' + item_id).val(data.item_id);
$('#item-quantity-' + item_id).val('1');
$('#item-price-' + item_id).val(data.purchase_price);
$('#item-tax-' + item_id).val(data.tax_id);
// This event Select2 Stylesheet
$('#item-price-' + item_id).trigger('focusout');
$('#item-tax-' + item_id).trigger('change');
$('#item-total-' + item_id).html(data.total);
totalItem();
}
});
});
$('a[rel=popover]').popover({
html: true,
placement: 'bottom',
title: '{{ trans('bills.discount') }}',
content: function () {
html = '<div class="discount box-body">';
html += ' <div class="col-md-6">';
html += ' <div class="input-group" id="input-discount">';
html += ' {!! Form::number('pre-discount', null, ['id' => 'pre-discount', 'class' => 'form-control text-right']) !!}';
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
html += ' </div>';
html += ' </div>';
html += ' <div class="col-md-6">';
html += ' <div class="discount-description">';
html += ' {{ trans('bills.discount_desc') }}';
html += ' </div>';
html += ' </div>';
html += '</div>';
html += '<div class="discount box-footer">';
html += ' <div class="col-md-12">';
html += ' <div class="form-group no-margin">';
html += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' => 'save-discount','class' => 'btn btn-success']) !!}';
html += ' <a href="javascript:void(0)" id="cancel-discount" class="btn btn-default"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</a>';
html += ' </div>';
html += ' </div>';
html += '</div>';
return html;
}
});
$(document).on('keyup', '#pre-discount', function(e){
e.preventDefault();
$('#discount').val($(this).val());
totalItem();
});
$(document).on('click', '#save-discount', function(){
$('a[rel=popover]').trigger('click');
});
$(document).on('click', '#cancel-discount', function(){
$('#discount').val('');
totalItem();
$('a[rel=popover]').trigger('click');
});
$(document).on('change', '#currency_code, #items tbody select', function(){
totalItem();
});
var focus = false;
$(document).on('focusin', '#items .input-price', function(){
focus = true;
});
$(document).on('blur', '#items .input-price', function(){
if (focus) {
totalItem();
focus = false;
}
});
$(document).on('keyup', '#items tbody .form-control', function(){
if (!$(this).hasClass('input-price')) {
totalItem();
}
});
$(document).on('change', '#vendor_id', function (e) {
$.ajax({
url: '{{ url("expenses/vendors/currency") }}',
type: 'GET',
dataType: 'JSON',
data: 'vendor_id=' + $(this).val(),
success: function(data) {
$('#vendor_name').val(data.name);
$('#vendor_email').val(data.email);
$('#vendor_tax_number').val(data.tax_number);
$('#vendor_phone').val(data.phone);
$('#vendor_address').val(data.address);
$('#currency_code').val(data.currency_code);
$('#currency_rate').val(data.currency_rate);
$('.input-price').each(function(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
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');
}
});
});
@if(old('item'))
totalItem();
@endif
});
$(document).on('click', '#button-add-item', function (e) {
$.ajax({
url: '{{ url("expenses/bills/addItem") }}',
type: 'GET',
dataType: 'JSON',
data: {item_row: item_row, currency_code : currency_code},
success: function(json) {
if (json['success']) {
$('#items tbody #addItem').before(json['html']);
//$('[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)]) }}"
},
escapeMarkup: function (markup) {
return markup;
},
language: {
noResults: function () {
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
}
}
});
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++;
}
}
});
});
$(document).on('click', '#tax-add-new', function(e){
tax_name = $('.select2-search__field').val();
$('#modal-create-tax').remove();
$.ajax({
url: '{{ url("modals/taxes/create") }}',
type: 'GET',
dataType: 'JSON',
data: {name: tax_name},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
$(document).on('click', '.form-control.typeahead', function() {
input_id = $(this).attr('id').split('-');
item_id = parseInt(input_id[input_id.length-1]);
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
url: autocomplete_path,
type: 'GET',
dataType: 'JSON',
data: 'query=' + query + '&type=bill&currency_code=' + $('#currency_code').val(),
success: function(data) {
return process(data);
}
});
},
afterSelect: function (data) {
$('#item-id-' + item_id).val(data.item_id);
$('#item-quantity-' + item_id).val('1');
$('#item-price-' + item_id).val(data.purchase_price);
$('#item-tax-' + item_id).val(data.tax_id);
// This event Select2 Stylesheet
$('#item-price-' + item_id).trigger('focusout');
$('#item-tax-' + item_id).trigger('change');
$('#item-total-' + item_id).html(data.total);
totalItem();
}
});
});
$('a[rel=popover]').popover({
html: true,
placement: 'bottom',
title: '{{ trans('bills.discount') }}',
content: function () {
html = '<div class="discount box-body">';
html += ' <div class="col-md-6">';
html += ' <div class="input-group" id="input-discount">';
html += ' {!! Form::number('pre-discount', null, ['id' => 'pre-discount', 'class' => 'form-control text-right']) !!}';
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
html += ' </div>';
html += ' </div>';
html += ' <div class="col-md-6">';
html += ' <div class="discount-description">';
html += ' {{ trans('bills.discount_desc') }}';
html += ' </div>';
html += ' </div>';
html += '</div>';
html += '<div class="discount box-footer">';
html += ' <div class="col-md-12">';
html += ' <div class="form-group no-margin">';
html += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' => 'save-discount','class' => 'btn btn-success']) !!}';
html += ' <a href="javascript:void(0)" id="cancel-discount" class="btn btn-default"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</a>';
html += ' </div>';
html += ' </div>';
html += '</div>';
return html;
}
});
$(document).on('keyup', '#pre-discount', function(e){
e.preventDefault();
$('#discount').val($(this).val());
totalItem();
});
$(document).on('click', '#save-discount', function(){
$('a[rel=popover]').trigger('click');
});
$(document).on('click', '#cancel-discount', function(){
$('#discount').val('');
totalItem();
$('a[rel=popover]').trigger('click');
});
$(document).on('change', '#currency_code, #items tbody select', function(){
totalItem();
});
$(document).on('focusin', '#items .input-price', function(){
focus = true;
});
$(document).on('blur', '#items .input-price', function(){
if (focus) {
totalItem();
focus = false;
}
});
$(document).on('keyup', '#items tbody .form-control', function(){
if (!$(this).hasClass('input-price')) {
totalItem();
}
});
$(document).on('change', '#vendor_id', function (e) {
$.ajax({
url: '{{ url("expenses/vendors/currency") }}',
type: 'GET',
dataType: 'JSON',
data: 'vendor_id=' + $(this).val(),
success: function(data) {
$('#vendor_name').val(data.name);
$('#vendor_email').val(data.email);
$('#vendor_tax_number').val(data.tax_number);
$('#vendor_phone').val(data.phone);
$('#vendor_address').val(data.address);
$('#currency_code').val(data.currency_code);
$('#currency_rate').val(data.currency_rate);
$('.input-price').each(function(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
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');
}
});
});
$(document).on('click', '#button-vendor', function (e) {
$('#modal-create-vendor').remove();
$.ajax({
url: '{{ url("modals/vendors/create") }}',
type: 'GET',
dataType: 'JSON',
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
$(document).on('click', '#button-category', function (e) {
$('#modal-create-category').remove();
$.ajax({
url: '{{ url("modals/categories/create") }}',
type: 'GET',
dataType: 'JSON',
data: {type: 'expense'},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
function totalItem() {
$.ajax({
url: '{{ url("common/items/totalItem") }}',
@ -520,36 +548,5 @@
}
});
}
$(document).on('click', '#button-vendor', function (e) {
$('#modal-create-vendor').remove();
$.ajax({
url: '{{ url("modals/vendors/create") }}',
type: 'GET',
dataType: 'JSON',
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
$(document).on('click', '#button-category', function (e) {
$('#modal-create-category').remove();
$.ajax({
url: '{{ url("modals/categories/create") }}',
type: 'GET',
dataType: 'JSON',
data: {type: 'expense'},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
</script>
@endpush

View File

@ -151,11 +151,12 @@
@push('scripts')
<script type="text/javascript">
var focus = false;
var item_row = '{{ $item_row }}';
var currency_code = $('#currency_code').val();
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
$(document).on('click', '#button-add-item', function (e) {
var currency_code = $('#currency_code').val();
$.ajax({
url: '{{ url("expenses/bills/addItem") }}',
type: 'GET',
@ -185,7 +186,7 @@
var currency = json['data']['currency'];
$("#item-price-" + item_row).maskMoney({
$('#item-price-' + item_row).maskMoney({
thousands : currency.thousands_separator,
decimal : currency.decimal_mark,
precision : currency.precision,
@ -194,7 +195,7 @@
suffix : (currency.symbol_first) ? '' : currency.symbol
});
$("#item-price-" + item_row).trigger('focusout');
$('#item-price-' + item_row).trigger('focusout');
item_row++;
}
@ -221,13 +222,11 @@
});
$(document).ready(function(){
$('#vendor_id').trigger('change');
itemTableResize();
@if (old('item'))
$('#vendor_id').trigger('change');
@endif
$(".input-price").maskMoney({
$('.input-price').maskMoney({
thousands : '{{ $currency->thousands_separator }}',
decimal : '{{ $currency->decimal_mark }}',
precision : {{ $currency->precision }},
@ -261,7 +260,7 @@
language: '{{ language()->getShortCode() }}'
});
$(".tax-select2").select2({
$('.tax-select2').select2({
placeholder: {
id: '-1', // the value of the option
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
@ -276,15 +275,15 @@
}
});
$("#vendor_id").select2({
$('#vendor_id').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.vendors', 1)]) }}"
});
$("#currency_code").select2({
$('#currency_code').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}"
});
$("#category_id").select2({
$('#category_id').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
});
@ -313,175 +312,174 @@
attachment_html += '</span>';
$('.fancy-file .fake-file').append(attachment_html);
$(document).on('click', '#remove-attachment', function (e) {
confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '<strong>' . $bill->attachment->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
$(document).on('click', '.form-control.typeahead', function() {
input_id = $(this).attr('id').split('-');
item_id = parseInt(input_id[input_id.length-1]);
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
url: autocomplete_path,
type: 'GET',
dataType: 'JSON',
data: 'query=' + query + '&type=bill&currency_code=' + $('#currency_code').val(),
success: function(data) {
return process(data);
}
});
},
afterSelect: function (data) {
$('#item-id-' + item_id).val(data.item_id);
$('#item-quantity-' + item_id).val('1');
$('#item-price-' + item_id).val(data.purchase_price);
$('#item-tax-' + item_id).val(data.tax_id);
// This event Select2 Stylesheet
$('#item-price-' + item_id).trigger('focusout');
$('#item-tax-' + item_id).trigger('change');
$('#item-total-' + item_id).html(data.total);
totalItem();
}
});
});
$('a[rel=popover]').popover({
html: true,
placement: 'bottom',
title: '{{ trans('bills.discount') }}',
content: function () {
html = '<div class="discount box-body">';
html += ' <div class="col-md-6">';
html += ' <div class="input-group" id="input-discount">';
html += ' {!! Form::number('pre-discount', null, ['id' => 'pre-discount', 'class' => 'form-control text-right']) !!}';
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
html += ' </div>';
html += ' </div>';
html += ' <div class="col-md-6">';
html += ' <div class="discount-description">';
html += ' {{ trans('bills.discount_desc') }}';
html += ' </div>';
html += ' </div>';
html += '</div>';
html += '<div class="discount box-footer">';
html += ' <div class="col-md-12">';
html += ' <div class="form-group no-margin">';
html += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' => 'save-discount','class' => 'btn btn-success']) !!}';
html += ' <a href="javascript:void(0)" id="cancel-discount" class="btn btn-default"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</a>';
html += ' </div>';
html += ' </div>';
html += '</div>';
return html;
}
});
$(document).on('keyup', '#pre-discount', function(e){
e.preventDefault();
$('#discount').val($(this).val());
totalItem();
});
$(document).on('click', '#save-discount', function(){
$('a[rel=popover]').trigger('click');
});
$(document).on('click', '#cancel-discount', function(){
$('#discount').val('');
totalItem();
$('a[rel=popover]').trigger('click');
});
$(document).on('change', '#currency_code, #items tbody select', function(){
totalItem();
});
var focus = false;
$(document).on('focusin', '#items .input-price', function(){
focus = true;
});
$(document).on('blur', '#items .input-price', function(){
if (focus) {
totalItem();
focus = false;
}
});
$(document).on('keyup', '#items tbody .form-control', function(){
if (!$(this).hasClass('input-price')) {
totalItem();
}
});
$(document).on('change', '#vendor_id', function (e) {
$.ajax({
url: '{{ url("expenses/vendors/currency") }}',
type: 'GET',
dataType: 'JSON',
data: 'vendor_id=' + $(this).val(),
success: function(data) {
$('#vendor_name').val(data.name);
$('#vendor_email').val(data.email);
$('#vendor_tax_number').val(data.tax_number);
$('#vendor_phone').val(data.phone);
$('#vendor_address').val(data.address);
$('#currency_code').val(data.currency_code);
$('#currency_rate').val(data.currency_rate);
$('.input-price').each(function(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
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');
}
});
});
@if(old('item'))
totalItem();
totalItem();
@endif
});
@if($bill->attachment)
$(document).on('click', '#remove-attachment', function (e) {
confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '<strong>' . $bill->attachment->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
$(document).on('click', '.form-control.typeahead', function() {
input_id = $(this).attr('id').split('-');
item_id = parseInt(input_id[input_id.length-1]);
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
url: autocomplete_path,
type: 'GET',
dataType: 'JSON',
data: 'query=' + query + '&type=bill&currency_code=' + $('#currency_code').val(),
success: function(data) {
return process(data);
}
});
},
afterSelect: function (data) {
$('#item-id-' + item_id).val(data.item_id);
$('#item-quantity-' + item_id).val('1');
$('#item-price-' + item_id).val(data.purchase_price);
$('#item-tax-' + item_id).val(data.tax_id);
// This event Select2 Stylesheet
$('#item-price-' + item_id).trigger('focusout');
$('#item-tax-' + item_id).trigger('change');
$('#item-total-' + item_id).html(data.total);
totalItem();
}
});
});
$('a[rel=popover]').popover({
html: true,
placement: 'bottom',
title: '{{ trans('bills.discount') }}',
content: function () {
html = '<div class="discount box-body">';
html += ' <div class="col-md-6">';
html += ' <div class="input-group" id="input-discount">';
html += ' {!! Form::number('pre-discount', null, ['id' => 'pre-discount', 'class' => 'form-control text-right']) !!}';
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
html += ' </div>';
html += ' </div>';
html += ' <div class="col-md-6">';
html += ' <div class="discount-description">';
html += ' {{ trans('bills.discount_desc') }}';
html += ' </div>';
html += ' </div>';
html += '</div>';
html += '<div class="discount box-footer">';
html += ' <div class="col-md-12">';
html += ' <div class="form-group no-margin">';
html += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' => 'save-discount','class' => 'btn btn-success']) !!}';
html += ' <a href="javascript:void(0)" id="cancel-discount" class="btn btn-default"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</a>';
html += ' </div>';
html += ' </div>';
html += '</div>';
return html;
}
});
$(document).on('keyup', '#pre-discount', function(e){
e.preventDefault();
$('#discount').val($(this).val());
totalItem();
});
$(document).on('click', '#save-discount', function(){
$('a[rel=popover]').trigger('click');
});
$(document).on('click', '#cancel-discount', function(){
$('#discount').val('');
totalItem();
$('a[rel=popover]').trigger('click');
});
$(document).on('change', '#currency_code, #items tbody select', function(){
totalItem();
});
$(document).on('focusin', '#items .input-price', function(){
focus = true;
});
$(document).on('blur', '#items .input-price', function(){
if (focus) {
totalItem();
focus = false;
}
});
$(document).on('keyup', '#items tbody .form-control', function(){
if (!$(this).hasClass('input-price')) {
totalItem();
}
});
$(document).on('change', '#vendor_id', function (e) {
$.ajax({
url: '{{ url("expenses/vendors/currency") }}',
type: 'GET',
dataType: 'JSON',
data: 'vendor_id=' + $(this).val(),
success: function(data) {
$('#vendor_name').val(data.name);
$('#vendor_email').val(data.email);
$('#vendor_tax_number').val(data.tax_number);
$('#vendor_phone').val(data.phone);
$('#vendor_address').val(data.address);
$('#currency_code').val(data.currency_code);
$('#currency_rate').val(data.currency_rate);
$('.input-price').each(function(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
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');
}
});
});
function totalItem() {
$.ajax({
url: '{{ url("common/items/totalItem") }}',

View File

@ -446,39 +446,11 @@
@push('scripts')
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click', '#button-email', function (e) {
$('#email-modal').remove();
var html = '<div class="modal fade" id="email-modal" tabindex="-1" role="dialog" aria-labelledby="emailModalLabel">';
html += ' <div class="modal-dialog" role="document">';
html += ' <div class="modal-content">';
html += ' <div class="modal-header">';
html += ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
html += ' <h4 class="modal-title" id="emailModalLabel">Overflowing text</h4>';
html += ' </div>';
html += ' <div class="modal-body">';
html += ' {{ trans('general.na') }}';
html += ' </div>';
html += ' <div class="modal-footer">';
html += ' <button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('general.cancel') }}</button>';
html += ' <button type="button" class="btn btn-success">Save changes</button>';
html += ' </div>';
html += ' </div>';
html += ' </div>';
html += '</div>';
$('body').append(html);
$('#email-modal').modal('show');
});
@if($bill->attachment)
$(document).on('click', '#remove-attachment', function (e) {
confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '<strong>' . $bill->attachment->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
@if($bill->attachment)
$(document).on('click', '#remove-attachment', function (e) {
confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '<strong>' . $bill->attachment->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
$(document).on('click', '#button-payment', function (e) {
$('#modal-add-payment').remove();

View File

@ -170,11 +170,12 @@
@push('scripts')
<script type="text/javascript">
var focus = false;
var item_row = '{{ $item_row }}';
var currency_code = $('#currency_code').val();
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
$(document).on('click', '#button-add-item', function (e) {
var currency_code = $('#currency_code').val();
$.ajax({
url: '{{ url("incomes/invoices/addItem") }}',
type: 'GET',
@ -204,7 +205,7 @@
var currency = json['data']['currency'];
$("#item-price-" + item_row).maskMoney({
$('#item-price-' + item_row).maskMoney({
thousands : currency.thousands_separator,
decimal : currency.decimal_mark,
precision : currency.precision,
@ -213,7 +214,7 @@
suffix : (currency.symbol_first) ? '' : currency.symbol
});
$("#item-price-" + item_row).trigger('focusout');
$('#item-price-' + item_row).trigger('focusout');
item_row++;
}
@ -228,7 +229,7 @@
$('#customer_id').trigger('change');
@endif
$(".input-price").maskMoney({
$('.input-price').maskMoney({
thousands : '{{ $currency->thousands_separator }}',
decimal : '{{ $currency->decimal_mark }}',
precision : {{ $currency->precision }},
@ -260,7 +261,7 @@
language: '{{ language()->getShortCode() }}'
});
$(".tax-select2").select2({
$('.tax-select2').select2({
placeholder: {
id: '-1', // the value of the option
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
@ -275,15 +276,15 @@
}
});
$("#customer_id").select2({
$('#customer_id').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.customers', 1)]) }}"
});
$("#currency_code").select2({
$('#currency_code').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}"
});
$("#category_id").select2({
$('#category_id').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
});
@ -293,188 +294,215 @@
placeholder : '{{ trans('general.form.no_file_selected') }}'
});
$(document).on('click', '#tax-add-new', function(e){
tax_name = $('.select2-search__field').val();
$('#modal-create-tax').remove();
$.ajax({
url: '{{ url("modals/taxes/create") }}',
type: 'GET',
dataType: 'JSON',
data: {name: tax_name},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
$(document).on('click', '.form-control.typeahead', function() {
input_id = $(this).attr('id').split('-');
item_id = parseInt(input_id[input_id.length-1]);
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
url: autocomplete_path,
type: 'GET',
dataType: 'JSON',
data: 'query=' + query + '&type=invoice&currency_code=' + $('#currency_code').val(),
success: function(data) {
return process(data);
}
});
},
afterSelect: function (data) {
$('#item-id-' + item_id).val(data.item_id);
$('#item-quantity-' + item_id).val('1');
$('#item-price-' + item_id).val(data.sale_price);
$('#item-tax-' + item_id).val(data.tax_id);
// This event Select2 Stylesheet
$('#item-price-' + item_id).trigger('focusout');
$('#item-tax-' + item_id).trigger('change');
$('#item-total-' + item_id).html(data.total);
totalItem();
}
});
});
$('a[rel=popover]').popover({
html: true,
placement: 'bottom',
title: '{{ trans('invoices.discount') }}',
content: function () {
html = '<div class="discount box-body">';
html += ' <div class="col-md-6">';
html += ' <div class="input-group" id="input-discount">';
html += ' {!! Form::number('pre-discount', null, ['id' => 'pre-discount', 'class' => 'form-control text-right']) !!}';
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
html += ' </div>';
html += ' </div>';
html += ' <div class="col-md-6">';
html += ' <div class="discount-description">';
html += ' {{ trans('invoices.discount_desc') }}';
html += ' </div>';
html += ' </div>';
html += '</div>';
html += '<div class="discount box-footer">';
html += ' <div class="col-md-12">';
html += ' <div class="form-group no-margin">';
html += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' => 'save-discount','class' => 'btn btn-success']) !!}';
html += ' <a href="javascript:void(0)" id="cancel-discount" class="btn btn-default"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</a>';
html += ' </div>';
html += ' </div>';
html += '</div>';
return html;
}
});
$(document).on('keyup', '#pre-discount', function(e){
e.preventDefault();
$('#discount').val($(this).val());
totalItem();
});
$(document).on('click', '#save-discount', function(){
$('a[rel=popover]').trigger('click');
});
$(document).on('click', '#cancel-discount', function(){
$('#discount').val('');
totalItem();
$('a[rel=popover]').trigger('click');
});
$(document).on('change', '#currency_code, #items tbody select', function(){
totalItem();
});
var focus = false;
$(document).on('focusin', '#items .input-price', function(){
focus = true;
});
$(document).on('blur', '#items .input-price', function(){
if (focus) {
totalItem();
focus = false;
}
});
$(document).on('keyup', '#items tbody .form-control', function(){
if (!$(this).hasClass('input-price')) {
totalItem();
}
});
$(document).on('change', '#customer_id', function (e) {
$.ajax({
url: '{{ url("incomes/customers/currency") }}',
type: 'GET',
dataType: 'JSON',
data: 'customer_id=' + $(this).val(),
success: function(data) {
$('#customer_name').val(data.name);
$('#customer_email').val(data.email);
$('#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(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
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');
}
});
});
@if(old('item'))
totalItem();
@endif
});
$(document).on('click', '#tax-add-new', function(e){
tax_name = $('.select2-search__field').val();
$('#modal-create-tax').remove();
$.ajax({
url: '{{ url("modals/taxes/create") }}',
type: 'GET',
dataType: 'JSON',
data: {name: tax_name},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
$(document).on('click', '.form-control.typeahead', function() {
input_id = $(this).attr('id').split('-');
item_id = parseInt(input_id[input_id.length-1]);
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
url: autocomplete_path,
type: 'GET',
dataType: 'JSON',
data: 'query=' + query + '&type=invoice&currency_code=' + $('#currency_code').val(),
success: function(data) {
return process(data);
}
});
},
afterSelect: function (data) {
$('#item-id-' + item_id).val(data.item_id);
$('#item-quantity-' + item_id).val('1');
$('#item-price-' + item_id).val(data.sale_price);
$('#item-tax-' + item_id).val(data.tax_id);
// This event Select2 Stylesheet
$('#item-price-' + item_id).trigger('focusout');
$('#item-tax-' + item_id).trigger('change');
$('#item-total-' + item_id).html(data.total);
totalItem();
}
});
});
$('a[rel=popover]').popover({
html: true,
placement: 'bottom',
title: '{{ trans('invoices.discount') }}',
content: function () {
html = '<div class="discount box-body">';
html += ' <div class="col-md-6">';
html += ' <div class="input-group" id="input-discount">';
html += ' {!! Form::number('pre-discount', null, ['id' => 'pre-discount', 'class' => 'form-control text-right']) !!}';
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
html += ' </div>';
html += ' </div>';
html += ' <div class="col-md-6">';
html += ' <div class="discount-description">';
html += ' {{ trans('invoices.discount_desc') }}';
html += ' </div>';
html += ' </div>';
html += '</div>';
html += '<div class="discount box-footer">';
html += ' <div class="col-md-12">';
html += ' <div class="form-group no-margin">';
html += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' => 'save-discount','class' => 'btn btn-success']) !!}';
html += ' <a href="javascript:void(0)" id="cancel-discount" class="btn btn-default"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</a>';
html += ' </div>';
html += ' </div>';
html += '</div>';
return html;
}
});
$(document).on('keyup', '#pre-discount', function(e){
e.preventDefault();
$('#discount').val($(this).val());
totalItem();
});
$(document).on('click', '#save-discount', function(){
$('a[rel=popover]').trigger('click');
});
$(document).on('click', '#cancel-discount', function(){
$('#discount').val('');
totalItem();
$('a[rel=popover]').trigger('click');
});
$(document).on('change', '#currency_code, #items tbody select', function(){
totalItem();
});
$(document).on('focusin', '#items .input-price', function(){
focus = true;
});
$(document).on('blur', '#items .input-price', function(){
if (focus) {
totalItem();
focus = false;
}
});
$(document).on('keyup', '#items tbody .form-control', function(){
if (!$(this).hasClass('input-price')) {
totalItem();
}
});
$(document).on('change', '#customer_id', function (e) {
$.ajax({
url: '{{ url("incomes/customers/currency") }}',
type: 'GET',
dataType: 'JSON',
data: 'customer_id=' + $(this).val(),
success: function(data) {
$('#customer_name').val(data.name);
$('#customer_email').val(data.email);
$('#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(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
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');
}
});
});
$(document).on('click', '#button-customer', function (e) {
$('#modal-create-customer').remove();
$.ajax({
url: '{{ url("modals/customers/create") }}',
type: 'GET',
dataType: 'JSON',
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
$(document).on('click', '#button-category', function (e) {
$('#modal-create-category').remove();
$.ajax({
url: '{{ url("modals/categories/create") }}',
type: 'GET',
dataType: 'JSON',
data: {type: 'income'},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
function totalItem() {
$.ajax({
url: '{{ url("common/items/totalItem") }}',
@ -520,36 +548,5 @@
}
});
}
$(document).on('click', '#button-customer', function (e) {
$('#modal-create-customer').remove();
$.ajax({
url: '{{ url("modals/customers/create") }}',
type: 'GET',
dataType: 'JSON',
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
$(document).on('click', '#button-category', function (e) {
$('#modal-create-category').remove();
$.ajax({
url: '{{ url("modals/categories/create") }}',
type: 'GET',
dataType: 'JSON',
data: {type: 'income'},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
</script>
@endpush

View File

@ -151,83 +151,16 @@
@push('scripts')
<script type="text/javascript">
var focus = false;
var item_row = '{{ $item_row }}';
$(document).on('click', '#button-add-item', function (e) {
var currency_code = $('#currency_code').val();
$.ajax({
url: '{{ url("incomes/invoices/addItem") }}',
type: 'GET',
dataType: 'JSON',
data: {item_row: item_row, currency_code : currency_code},
success: function(json) {
if (json['success']) {
$('#items tbody #addItem').before(json['html']);
//$('[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)]) }}"
},
escapeMarkup: function (markup) {
return markup;
},
language: {
noResults: function () {
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
}
}
});
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++;
}
}
});
});
$(document).on('click', '#tax-add-new', function(e){
tax_name = $('.select2-search__field').val();
$('#modal-create-tax').remove();
$.ajax({
url: '{{ url("modals/taxes/create") }}',
type: 'GET',
dataType: 'JSON',
data: {name: tax_name},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
$(document).ready(function(){
$('#customer_id').trigger('change');
itemTableResize();
@if (old('item'))
$('#customer_id').trigger('change');
@endif
$(".input-price").maskMoney({
$('.input-price').maskMoney({
thousands : '{{ $currency->thousands_separator }}',
decimal : '{{ $currency->decimal_mark }}',
precision : {{ $currency->precision }},
@ -261,7 +194,7 @@
language: '{{ language()->getShortCode() }}'
});
$(".tax-select2").select2({
$('.tax-select2').select2({
placeholder: {
id: '-1', // the value of the option
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
@ -276,15 +209,15 @@
}
});
$("#customer_id").select2({
$('#customer_id').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.customers', 1)]) }}"
});
$("#currency_code").select2({
$('#currency_code').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}"
});
$("#category_id").select2({
$('#category_id').select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
});
@ -313,176 +246,241 @@
attachment_html += '</span>';
$('.fancy-file .fake-file').append(attachment_html);
$(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') !!}");
});
@endif
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
$(document).on('click', '.form-control.typeahead', function() {
input_id = $(this).attr('id').split('-');
item_id = parseInt(input_id[input_id.length-1]);
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
url: autocomplete_path,
type: 'GET',
dataType: 'JSON',
data: 'query=' + query + '&type=invoice&currency_code=' + $('#currency_code').val(),
success: function(data) {
return process(data);
}
});
},
afterSelect: function (data) {
$('#item-id-' + item_id).val(data.item_id);
$('#item-quantity-' + item_id).val('1');
$('#item-price-' + item_id).val(data.sale_price);
$('#item-tax-' + item_id).val(data.tax_id);
// This event Select2 Stylesheet
$('#item-price-' + item_id).trigger('focusout');
$('#item-tax-' + item_id).trigger('change');
$('#item-total-' + item_id).html(data.total);
totalItem();
}
});
});
$('a[rel=popover]').popover({
html: true,
placement: 'bottom',
title: '{{ trans('invoices.discount') }}',
content: function () {
html = '<div class="discount box-body">';
html += ' <div class="col-md-6">';
html += ' <div class="input-group" id="input-discount">';
html += ' {!! Form::number('pre-discount', null, ['id' => 'pre-discount', 'class' => 'form-control text-right']) !!}';
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
html += ' </div>';
html += ' </div>';
html += ' <div class="col-md-6">';
html += ' <div class="discount-description">';
html += ' {{ trans('invoices.discount_desc') }}';
html += ' </div>';
html += ' </div>';
html += '</div>';
html += '<div class="discount box-footer">';
html += ' <div class="col-md-12">';
html += ' <div class="form-group no-margin">';
html += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' => 'save-discount','class' => 'btn btn-success']) !!}';
html += ' <a href="javascript:void(0)" id="cancel-discount" class="btn btn-default"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</a>';
html += ' </div>';
html += ' </div>';
html += '</div>';
return html;
}
});
$(document).on('keyup', '#pre-discount', function(e){
e.preventDefault();
$('#discount').val($(this).val());
totalItem();
});
$(document).on('click', '#save-discount', function(){
$('a[rel=popover]').trigger('click');
});
$(document).on('click', '#cancel-discount', function(){
$('#discount').val('');
totalItem();
$('a[rel=popover]').trigger('click');
});
$(document).on('change', '#currency_code, #items tbody select', function(){
totalItem();
});
var focus = false;
$(document).on('focusin', '#items .input-price', function(){
focus = true;
});
$(document).on('blur', '#items .input-price', function(){
if (focus) {
totalItem();
focus = false;
}
});
$(document).on('keyup', '#items tbody .form-control', function(){
if (!$(this).hasClass('input-price')) {
totalItem();
}
});
$(document).on('change', '#customer_id', function (e) {
$.ajax({
url: '{{ url("incomes/customers/currency") }}',
type: 'GET',
dataType: 'JSON',
data: 'customer_id=' + $(this).val(),
success: function(data) {
$('#customer_name').val(data.name);
$('#customer_email').val(data.email);
$('#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(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
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');
}
});
});
@if(old('item'))
totalItem();
totalItem();
@endif
});
@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') !!}");
});
@endif
$(document).on('click', '.form-control.typeahead', function() {
input_id = $(this).attr('id').split('-');
item_id = parseInt(input_id[input_id.length-1]);
$(this).typeahead({
minLength: 3,
displayText:function (data) {
return data.name + ' (' + data.sku + ')';
},
source: function (query, process) {
$.ajax({
url: autocomplete_path,
type: 'GET',
dataType: 'JSON',
data: 'query=' + query + '&type=invoice&currency_code=' + $('#currency_code').val(),
success: function(data) {
return process(data);
}
});
},
afterSelect: function (data) {
$('#item-id-' + item_id).val(data.item_id);
$('#item-quantity-' + item_id).val('1');
$('#item-price-' + item_id).val(data.sale_price);
$('#item-tax-' + item_id).val(data.tax_id);
// This event Select2 Stylesheet
$('#item-price-' + item_id).trigger('focusout');
$('#item-tax-' + item_id).trigger('change');
$('#item-total-' + item_id).html(data.total);
totalItem();
}
});
});
$('a[rel=popover]').popover({
html: true,
placement: 'bottom',
title: '{{ trans('invoices.discount') }}',
content: function () {
html = '<div class="discount box-body">';
html += ' <div class="col-md-6">';
html += ' <div class="input-group" id="input-discount">';
html += ' {!! Form::number('pre-discount', null, ['id' => 'pre-discount', 'class' => 'form-control text-right']) !!}';
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
html += ' </div>';
html += ' </div>';
html += ' <div class="col-md-6">';
html += ' <div class="discount-description">';
html += ' {{ trans('invoices.discount_desc') }}';
html += ' </div>';
html += ' </div>';
html += '</div>';
html += '<div class="discount box-footer">';
html += ' <div class="col-md-12">';
html += ' <div class="form-group no-margin">';
html += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' => 'save-discount','class' => 'btn btn-success']) !!}';
html += ' <a href="javascript:void(0)" id="cancel-discount" class="btn btn-default"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</a>';
html += ' </div>';
html += ' </div>';
html += '</div>';
return html;
}
});
$(document).on('click', '#button-add-item', function (e) {
var currency_code = $('#currency_code').val();
$.ajax({
url: '{{ url("incomes/invoices/addItem") }}',
type: 'GET',
dataType: 'JSON',
data: {item_row: item_row, currency_code : currency_code},
success: function(json) {
if (json['success']) {
$('#items tbody #addItem').before(json['html']);
//$('[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)]) }}"
},
escapeMarkup: function (markup) {
return markup;
},
language: {
noResults: function () {
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
}
}
});
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++;
}
}
});
});
$(document).on('click', '#tax-add-new', function(e){
tax_name = $('.select2-search__field').val();
$('#modal-create-tax').remove();
$.ajax({
url: '{{ url("modals/taxes/create") }}',
type: 'GET',
dataType: 'JSON',
data: {name: tax_name},
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
$(document).on('keyup', '#pre-discount', function(e){
e.preventDefault();
$('#discount').val($(this).val());
totalItem();
});
$(document).on('click', '#save-discount', function(){
$('a[rel=popover]').trigger('click');
});
$(document).on('click', '#cancel-discount', function(){
$('#discount').val('');
totalItem();
$('a[rel=popover]').trigger('click');
});
$(document).on('change', '#currency_code, #items tbody select', function(){
totalItem();
});
$(document).on('focusin', '#items .input-price', function(){
focus = true;
});
$(document).on('blur', '#items .input-price', function(){
if (focus) {
totalItem();
focus = false;
}
});
$(document).on('keyup', '#items tbody .form-control', function(){
if (!$(this).hasClass('input-price')) {
totalItem();
}
});
$(document).on('change', '#customer_id', function (e) {
$.ajax({
url: '{{ url("incomes/customers/currency") }}',
type: 'GET',
dataType: 'JSON',
data: 'customer_id=' + $(this).val(),
success: function(data) {
$('#customer_name').val(data.name);
$('#customer_email').val(data.email);
$('#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(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
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');
}
});
});
function totalItem() {
$.ajax({
url: '{{ url("common/items/totalItem") }}',

View File

@ -474,39 +474,11 @@
@push('scripts')
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click', '#button-email', function (e) {
$('#email-modal').remove();
var html = '<div class="modal fade" id="email-modal" tabindex="-1" role="dialog" aria-labelledby="emailModalLabel">';
html += ' <div class="modal-dialog" role="document">';
html += ' <div class="modal-content">';
html += ' <div class="modal-header">';
html += ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
html += ' <h4 class="modal-title" id="emailModalLabel">Overflowing text</h4>';
html += ' </div>';
html += ' <div class="modal-body">';
html += ' {{ trans('general.na') }}';
html += ' </div>';
html += ' <div class="modal-footer">';
html += ' <button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('general.cancel') }}</button>';
html += ' <button type="button" class="btn btn-success">Save changes</button>';
html += ' </div>';
html += ' </div>';
html += ' </div>';
html += '</div>';
$('body').append(html);
$('#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') !!}");
});
@endif
@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') !!}");
});
@endif
$(document).on('click', '#button-payment', function (e) {
$('#modal-add-payment').remove();