var editor; // use a global for the submit and return data rendering in the examples (function($){ $(document).ready(function(e) { 'use strict'; //para formatear nuestros numeros function number_format(number, decimals, dec_point, thousands_sep) { // discuss at: http://phpjs.org/functions/number_format/ // original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // improved by: davook // improved by: Brett Zamir (http://brett-zamir.me) // improved by: Brett Zamir (http://brett-zamir.me) // improved by: Theriault // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // bugfixed by: Michael White (http://getsprink.com) // bugfixed by: Benjamin Lupton // bugfixed by: Allan Jensen (http://www.winternet.no) // bugfixed by: Howard Yeend // bugfixed by: Diogo Resende // bugfixed by: Rival // bugfixed by: Brett Zamir (http://brett-zamir.me) // revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // revised by: Luke Smith (http://lucassmith.name) // input by: Kheang Hok Chin (http://www.distantia.ca/) // input by: Jay Klehr // input by: Amir Habibi (http://www.residence-mixte.com/) // input by: Amirouche // example 1: number_format(1234.56); // returns 1: '1,235' // example 2: number_format(1234.56, 2, ',', ' '); // returns 2: '1 234,56' // example 3: number_format(1234.5678, 2, '.', ''); // returns 3: '1234.57' // example 4: number_format(67, 2, ',', '.'); // returns 4: '67,00' // example 5: number_format(1000); // returns 5: '1,000' // example 6: number_format(67.311, 2); // returns 6: '67.31' // example 7: number_format(1000.55, 1); // returns 7: '1,000.6' // example 8: number_format(67000, 5, ',', '.'); // returns 8: '67.000,00000' // example 9: number_format(0.9, 0); // returns 9: '1' // example 10: number_format('1.20', 2); // returns 10: '1.20' // example 11: number_format('1.20', 4); // returns 11: '1.2000' // example 12: number_format('1.2000', 3); // returns 12: '1.200' // example 13: number_format('1 000,50', 2, '.', ' '); // returns 13: '100 050.00' // example 14: number_format(1e-8, 8, '.', ''); // returns 14: '0.00000001' number = (number + '') .replace(/[^0-9+\-Ee.]/g, ''); var n = !isFinite(+number) ? 0 : +number, prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, dec = (typeof dec_point === 'undefined') ? '.' : dec_point, s = '', toFixedFix = function(n, prec) { var k = Math.pow(10, prec); return '' + (Math.round(n * k) / k) .toFixed(prec); }; // Fix for IE parseFloat(0.55).toFixed(0) = 0; s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)) .split('.'); if (s[0].length > 3) { s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); } if ((s[1] || '') .length < prec) { s[1] = s[1] || ''; s[1] += new Array(prec - s[1].length + 1) .join('0'); } return s.join(dec); }; //para completar con ceros a la izq. function rellenar(num){ numtmp='"'+num+'"'; largo=numtmp.length-5; numtmp=numtmp.split('"').join(''); if(largo==5)return numtmp; ceros=''; pendientes=5-largo; for(i=0;i', currentText: 'Hoy', monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'], dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sáb'], dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sá'], weekHeader: 'Sm', dateFormat: 'dd/mm/yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: '' }; $.datepicker.setDefaults($.datepicker.regional['es']); $('.numeromask').mask('000.000.000.000.000', {reverse: true}); $('.fc-datepicker').datepicker({ showOtherMonths: true, selectOtherMonths: true, dateFormat: 'yy-mm-dd' }); $('button.back').on('click', function(e){ e.preventDefault(); window.history.back(); }); $('select2').select2({ maximumInputLength: 20 // only allow terms up to 20 characters long }); $('#buscarAlumno').typeahead({ source: function (query, result) { $.ajax({ url: "../funciones/buscarAlumno.php", data: 'query=' + query, dataType: "json", type: "POST", success: function (data) { result($.map(data, function (item) { return item; console.log(item); })); } }); }, afterSelect: function (item) { var datos = item.toString().split("_"); var datosAlumo = datos[0]+' '+datos[1]+' ('+ datos[2] +')'; var tutor = datos[4]; $('#tutor_id').val(tutor); $('#buscarAlumno').val(datosAlumo); table.ajax.reload(); $('#estadoDeCuentaTable').show(); } }); var table = $('#dt01').DataTable( { //dom: "lBfrtip", dom: "<'row'<'col-sm-1 col-md-12 col-lg-8'B>"+ "<'col-sm-12 col-md-12 col-lg-3'f>>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-sm-6 col-md-6 col-lg-5'i>>", scrollY: "750px", scrollX: "true", scrollCollapse: true, autoWidth: false, lengthMenu: [ [10, 25, 50, -1], [10, 25, 50, "Todos"] ], language: { sProcessing: "Procesando...", sLengthMenu: "_MENU_", sZeroRecords: "No se encontraron resultados", sEmptyTable: "Ningún dato disponible en esta tabla", sInfo: "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros", sInfoEmpty: "Mostrando registros del 0 al 0 de un total de 0 registros", sInfoFiltered: "(filtrado de un total de _MAX_ registros)", sInfoPostFix: "", search: "", searchPlaceholder: "Buscar", sUrl: "", sInfoThousands: ",", sLoadingRecords: "Cargando...", decimal: ",", thousands: ".", oPaginate: { "sFirst": "<<", "sLast": ">>", "sNext": ">", "sPrevious": "<" }, oAria: { "sSortAscending": ": Activar para ordenar la columna de manera ascendente", "sSortDescending": ": Activar para ordenar la columna de manera descendente" }, select: { rows: { _: "Tienes %d registros seleccionados", 0: "Haz click en un registro para seleccionarlo", 1: "Solo 1 registro seleccionado" } } }, ajax: { url: "../../media/sys_controladores/table.administracion.cc_tutor_inicio.php", type: "POST", data: function ( d ) { var tutor_id = $("#tutor_id").val(); d.tutor_id = tutor_id; } }, serverSide: true, pageLength: -1, scrollY: 250, scrollCollapse: true, order: [[0, 'asc']], columns: [ { data: "adm_cuentas_corrientes_cursos.id",className: "text-center", "render": function ( data, type, row ) { if (row.adm_cuentas_corrientes_cursos.monto - row.adm_cuentas_corrientes_cursos.pago == '0') { return 'Pagado'; }else{ return ''; } } }, { data: "acad_rue.nombres", render: function ( data, type, row ) { return row.acad_rue.nombres+' '+row.acad_rue.apellidos; }, }, { data: "acad_rue.nombres", render: function ( data, type, row ) { return row.para_grados.nombre+' '+row.acad_turnos.nombre+' - Año: '+row.acad_periodos.nombre; }, }, { data: "para_aranceles.nombre", render: function ( data, type, row ) { return row.para_aranceles.nombre; }, }, { data: "adm_cuentas_corrientes_cursos.monto", className: "text-right", render: function ( data, type, row ) { return number_format(data,0,",","."); }, }, { data: "adm_cuentas_corrientes_cursos.monto", className: "text-right", render: function ( data, type, row ) { var saldo = row.adm_cuentas_corrientes_cursos.monto - row.adm_cuentas_corrientes_cursos.pago; return number_format(saldo,0,",","."); }, }, { data: "adm_cuentas_corrientes_cursos.monto", className: "text-right", render: function ( data, type, row ) { var saldo = row.adm_cuentas_corrientes_cursos.monto - row.adm_cuentas_corrientes_cursos.pago; if(saldo == 0){ row.adm_cuentas_corrientes_cursos.estado = 'Pagado'; return 'Pagado'; }else if(saldo > 0 && saldo < row.adm_cuentas_corrientes_cursos.monto){ row.adm_cuentas_corrientes_cursos.estado = 'Parcial'; return 'Parcial'; }else{ row.adm_cuentas_corrientes_cursos.estado = 'Pendiente'; return 'Pendiente'; } }, }, ], createdRow: function (node, data ) { var saldo = data.adm_cuentas_corrientes_cursos.monto - data.adm_cuentas_corrientes_cursos.pago; if (saldo == 0) { $(node).addClass( 'table-success' ); }else if(saldo > 0 && saldo < data.adm_cuentas_corrientes_cursos.monto){ $(node).addClass( 'table-warning' ); } }, keys: { columns: ':not(:first-child)', editor: editor }, select: { style: 'os', selector: 'td:first-child' }, buttons: [ { text: 'Pagar cuotas seleccionadas', className: 'btn btn-warning btn-lg', action: function ( e, dt, node, config ) { $( "#pagoCuotas" ).submit(); //location.reload(true); table.ajax.reload(); }, attr: { 'data-toggle': 'modal', 'data-target': '#formularioComprasModal' } }, { extend: 'print', text: 'Imprimir', customize: function(win){ $(win.document.body) .css( 'font-size', '9pt' ) .prepend( '' ); $(win.document.body).find( 'table' ) .addClass( 'compact' ) .css( 'font-size', 'inherit' ); var last = null; var current = null; var bod = []; var css = '@page { size: landscape; }', head = win.document.head || win.document.getElementsByTagName('head')[0], style = win.document.createElement('style'); style.type = 'text/css'; style.media = 'print'; if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(win.document.createTextNode(css)); } head.appendChild(style); } }, ], footerCallback: function ( row, data, type, start, end, display, source, val ) { var api = this.api(), data; // Remove the formatting to get integer data for summation var intVal = function ( i ) { return typeof i === 'string' ? i.replace(/([*+?^=!:${}()|\[\]\/\\])/g, '')*1 : typeof i === 'number' ? i : 0; }; var j; var total; var pageTotal; for (j = 4; j <= 5; j++) { // Total over all pages total = api .column( j ) .data() .reduce( function (a, b) { return intVal(a) + intVal(b); }, 0 ); // Total over this page pageTotal = api .column( j, { page: 'current'} ) .data() .reduce( function (a, b) { return intVal(a) + intVal(b); }, 0 ); // Update footer $( api.column( j ).footer() ).html( number_format(pageTotal,0,",",".") ); } }, } ); $('div.dataTables_length select').select2(); // Filter event handler $( table.table().container() ).on( 'keyup', 'tfoot input', function () { table .column( $(this).data('index') ) .search( this.value ) .draw(); } ); } ); }(jQuery));