close #620 Fixed: Invoice/Bill edit not change customer/vendor information
This commit is contained in:
		| @@ -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¤cy_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>  ' . 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>  {{ 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¤cy_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>  ' . 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>  {{ 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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user