KOKINIO - MANAGER
Edit File: comisiones.js
$(function(){ $("#cliente-select").select2({ placeholder:"Selecciona el Cliente", allowClear: true, ajax: { url: main_path+'/cliente/clientes', dataType: 'json', data: function (params) { var query = { search: params.term, } return query }, processResults: function (data) { const dataResult = data.map(res => { return { id: res.id, text: `${res.registro} ${res.nombre} ${res.ape_p} ${res.ape_m}` } }) return { results: dataResult }; } }, }); //Comisiones.getComisiones(); }) var Comisiones = { getComisiones:function(e){ var cliente = $("#cliente-select").val(); var token = $("#token").val(); var month = $("#month").val(); var year = $("#year").val(); $.post(main_path+"/comisiones/getComisiones",{'_token':token, 'cliente':cliente, 'month':month, 'year':year},function(html){ $("#table-comisiones").html(html); var txtyear, txtmonth; if(year == ""){ txtyear = (new Date()).getFullYear(); }else{ txtyear = $("#year :selected").text(); $('tbody').find('button').each(function (index, element) { console.log(element); $(element).attr('data-year',year); }); } if(month == ""){ txtmonth = (new Date()).getMonth() + 1; }else{ txtmonth = $("#month :selected").text(); $('tbody').find('button').each(function (index, element) { console.log(element); $(element).attr('data-month',month); }); //$('#printComisiones').attr('data-month',month); } $('#refresh_comisiones').attr('data-year', year); $('#refresh_comisiones').attr('data-month', month); $('#date-comisiones').text(txtmonth+" "+txtyear) }); }, payComision:function(e){ console.log(e); var month = $(e).data('month'); var year = $(e).data('year'); var cliente_id = $(e).data('id'); var venta = $(e).data('venta'); var comision = $(e).data('comision'); var pay = $(e).data('pay'); var data = { 'month' : month, 'year' : year, 'cliente_id' : cliente_id, 'venta' : venta, 'comision' : comision, 'pay' : pay, } $.get(main_path+'/comisiones/payComisiones',data,function(resp){ swal({ title: "", text: resp.message, icon: resp.status }); var total_p = $('#total-pagado').text(); total_p = parseFloat(total_p.replace(",","")); if(pay == 1){ $($(e).parent()).parent().css('backgroundColor',"#c7f5c7"); $(e).parent().html('<button id="payComisiones" data-pay="0" data-venta="'+data.venta+'" data-comision="'+data.comision+'" data-month="'+data.month+'" data-year="'+data.year+'" data-id="'+data.id+'" class="btn btn-danger" data-toggle="tooltip" title="Eliminar Pago" onclick="Comisiones.payComision(this)"><span class="glyphicon glyphicon-minus"></span></button>'); $(e).remove(); var num = (total_p) + (data.comision); num = Math.round(num * 100) / 100; num = num.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); $('#total-pagado').text(num); }else{ $($(e).parent()).parent().css('backgroundColor',"white"); $(e).parent().html('<button id="payComisiones" data-pay="1" data-venta="'+data.venta+'" data-comision="'+data.comision+'" data-month="'+data.month+'" data-year="'+data.year+'" data-id="'+data.id+'" class="btn btn-success" data-toggle="tooltip" title="Eliminar Pago" onclick="Comisiones.payComision(this)"><span class="glyphicon glyphicon-plus"></span></button>'); $(e).remove() var num = (total_p) - (data.comision); num = Math.round(num * 100) / 100; num = num.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); $('#total-pagado').text(num); } }); }, getMonths: (e) => { $.get(main_path+'/comisiones/getMonths', {year: $(e).val()}, (resp) => { $('#month').html('').html(resp); }); }, refreshComisiones: e => { const year = $(e).data('year'); const month = $(e).data('month'); const clientId = $('#cliente-select').val() // $('#loading').append(`<img id="gif_loading" style="width:25px" src='${main_path}/img/Loading_2.gif' />`); $('#gif_loading').css('display', 'block'); console.log('loading'); $.get(main_path+'/comisiones/insertComisiones', {year, month, clientId}, (resp) => { if (resp) { console.log('stop loading'); $('#gif_loading').css('display', 'none'); } }); }, deletePagoComision: e => { const id = $(e).data('id'); const pos = $(e).data('pos'); if(id !== '0') { $.get(main_path+'/comisionesPago/deleteComisionPagada', {id}, (resp) => { console.log(resp); if (resp.status) { swal('', serv.message, 'success'); $('#cliente-select'+ (pos + 1)).val('vacio').trigger('change'); $('#cantidad_comision_' + pos).val(''); $('#deletePago_' + pos).attr('data-id', '0'); // $('#gif_loading').css('display', 'none'); } else { swal('', serv.message, 'warning'); } }); } } }