diff --git a/httpdocs/assets/js/safekat/pages/facturas/facturasList.js b/httpdocs/assets/js/safekat/pages/facturas/facturasList.js new file mode 100644 index 00000000..d0c66bf1 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/facturas/facturasList.js @@ -0,0 +1,199 @@ +$(() => { + + $(document).on('click', '.btn-edit', function (e) { + window.location.href = '/facturas/edit/' + $(this).attr('data-id'); + }); + + const lastColNr = $('#tableOfFacturas').find("tr:first th").length - 1; + + let datatableColumns = []; + if ($('#cliente_id').val() == -1) { + datatableColumns = [ + { 'data': 'id' }, + { 'data': 'numero' }, + { 'data': 'fecha_factura_at', searchable: false }, + { 'data': 'cliente' }, + { 'data': 'base', render: (d) => `${d}` }, + { 'data': 'total', render: (d) => `${d}` }, + { 'data': 'pendiente', render: (d) => `${d}` }, + { 'data': 'creditoAsegurado' }, + { 'data': 'estado' }, + { 'data': 'estado_pago' }, + { 'data': 'forma_pago' }, + { 'data': 'vencimiento' }, + { 'data': 'dias_vencimiento' }, + { 'data': 'action' } + ]; + } else { + datatableColumns = [ + { 'data': 'id' }, + { 'data': 'numero' }, + { 'data': 'fecha_factura_at', searchable: false }, + { 'data': 'base', render: (d) => `${d}` }, + { 'data': 'total', render: (d) => `${d}` }, + { 'data': 'pendiente', render: (d) => `${d}` }, + { 'data': 'action' } + ]; + } + + $('#tableOfFacturas').DataTable({ + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + orderCellsTop: true, + lengthMenu: [5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500], + pageLength: 250, + "dom": 'lBrtip', + buttons: [ + { + text: 'Exportar Excel Contaplus', + action: function (e, dt, button, config) { + var searchValue = theTable.search(); // Captura el valor del campo de búsqueda + var ajaxParams = theTable.ajax.params(); // Captura otros parámetros de la tabla + + console.log(searchValue); + + /* + $.ajax({ + url: '/ruta/exportarExcel', // URL del servidor para manejar la exportación + type: 'POST', + data: { + search: searchValue, + extraParams: ajaxParams + }, + xhrFields: { + responseType: 'blob' // Para manejar la descarga del archivo + }, + success: function(blob, status, xhr) { + // Crear un enlace temporal para descargar el archivo + var link = document.createElement('a'); + var url = window.URL.createObjectURL(blob); + link.href = url; + link.download = 'datos_personalizados.xlsx'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(url); + } + }); + */ + } + }, + { + text: 'Exportar Lineas a Excel', + action: function (e, dt, button, config) { + var searchValue = theTable.search(); // Captura el valor del campo de búsqueda + var ajaxParams = theTable.ajax.params(); // Captura otros parámetros de la tabla + + console.log(searchValue); + + } + }, + { + text: 'Exportar Girosgit ', + action: function (e, dt, button, config) { + var searchValue = theTable.search(); // Captura el valor del campo de búsqueda + var ajaxParams = theTable.ajax.params(); // Captura otros parámetros de la tabla + + console.log(searchValue); + + } + } + ], + order: [[0, 'asc']], + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + ajax: { + url: '/facturas/datatable', + type: 'GET', + data: function (d) { + d.cliente_id = $('#cliente_id').val(); + d.fecha_factura = getDate(); + } + }, + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr] + }, + ], + columns: datatableColumns, + }); + + $(document).on("keyup", ".factura-filter", (event) => { + //console.log(this.datatablePlanningRot.column($(event.currentTarget).attr("name"))) + let columnName = $(event.currentTarget).attr("name"); + let columnIndex = $('#tableOfFacturas').DataTable().columns().eq(0).filter(function (index) { + return $('#tableOfFacturas').DataTable().column(index).dataSrc() === columnName; + })[0]; + $('#tableOfFacturas').DataTable().column(columnIndex).search($(event.currentTarget).val()).draw() + }) + + $(document).on("change", ".factura-filter-select", (event) => { + let columnName = $(event.currentTarget).attr("name"); + let columnIndex = $('#tableOfFacturas').DataTable().columns().eq(0).filter(function (index) { + return $('#tableOfFacturas').DataTable().column(index).dataSrc() === columnName; + })[0]; + $('#tableOfFacturas').DataTable().column(columnIndex).search($(event.currentTarget).val()).draw(); + }); + + + + let bsRangePickerRange = $('#' + 'fechaFactura'); + bsRangePickerRange.daterangepicker({ + ranges: { + [window.datepickerLang.hoy]: [moment(), moment()], + [window.datepickerLang.ayer]: [moment().subtract(1, 'days'), moment().subtract(1, 'days')], + [window.datepickerLang.ultimos7]: [moment().subtract(6, 'days'), moment()], + [window.datepickerLang.ultimos30]: [moment().subtract(29, 'days'), moment()], + [window.datepickerLang.esteMes]: [moment().startOf('month'), moment().endOf('month')], + [window.datepickerLang.ultimoMes]: [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')] + }, + opens: 'right', + language: window.datepickerLocale, + "locale": { + "customRangeLabel": window.datepickerLang.rangoPersonalizado, + "format": "YYYY-MM-DD", + "separator": " ", + "applyLabel": window.datepickerLang.aplicar, + "cancelLabel": window.datepickerLang.limpiar, + + }, + "alwaysShowCalendars": true, + autoUpdateInput: false, + + }); + + + function getDate() { + + let picker = bsRangePickerRange.data('daterangepicker'); + + if (!picker || !picker.startDate || !picker.endDate || $('#fechaFactura').val() == '') { + return ''; + } + + let startDate = picker.startDate.format('YYYY-MM-DD'); + let endDate = picker.endDate.format('YYYY-MM-DD'); + + return startDate + "|" + endDate; + + } + + bsRangePickerRange.on('apply.daterangepicker', function (ev, picker) { + + $(this).val(picker.startDate.format('DD/MM/YYYY') + ' ' + picker.endDate.format('DD/MM/YYYY')); + let table = $('#tableOfFacturas').DataTable(); + table.column(2).draw(); + }); + + bsRangePickerRange.on('cancel.daterangepicker', function (ev, picker) { + $(this).val(''); + $('#tableOfFacturas').DataTable().column(2).search('').draw(); + }); + +}) \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/pedidos/pedidos.js b/httpdocs/assets/js/safekat/pages/pedidos/pedidos.js new file mode 100644 index 00000000..555634b9 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/pedidos/pedidos.js @@ -0,0 +1,145 @@ +import Ajax from "../../components/ajax.js" + +class Pedidos { + + constructor() { + + this.total_ejemplares = 0; + this.total_facturado = 0; + + this.tableFacturas = $('#tableOfFacturas').DataTable(); + this.tablePedidos = $('#tableOfLineasPedido').DataTable(); + this.btnAddFactura = $('#add-factura'); + } + + init() { + + if (this.btnAddFactura) { + this.tableFacturas.on('draw', function () { + this.total_facturado = 0; + for (let i = 0; i < this.tableFacturas.rows().count(); i++) { + this.total_facturado += parseFloat(this.tableFacturas.row(i).data().ejemplares); + } + this.checkAddFactura(); + }.bind(this)); + + this.tablePedidos.on('draw', function () { + this.total_ejemplares = 0; + for (let i = 0; i < this.tablePedidos.rows().count(); i++) { + this.total_ejemplares += parseInt(this.tablePedidos.row(i).data().unidades); + } + this.checkAddFactura(); + }.bind(this)); + + this.btnAddFactura.on('click', this.addFacturaAction.bind(this)); + } + } + + addFacturaAction() { + + Swal.fire({ + title: 'Seleccione serie de facturación', + html: `