<script src="plugins/jquery/jquery.min.js"></script>
<script src="plugins/jquery-ui/jquery-ui.min.js"></script>
<script>
	$.widget.bridge('uibutton', $.ui.button);
</script>
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="plugins/chart.js/Chart.min.js"></script>
<script src="plugins/sparklines/sparkline.js"></script>
<script src="plugins/moment/moment.min.js"></script>
<script src="plugins/daterangepicker/daterangepicker.js"></script>
<script src="plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<script src="plugins/summernote/summernote-bs4.min.js"></script>
<script src="plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<script src="dist/js/adminlte.js"></script>
<script src="plugins/select2/js/select2.full.min.js"></script>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="plugins/jszip/jszip.min.js"></script>
<script src="plugins/pdfmake/pdfmake.min.js"></script>
<script src="plugins/pdfmake/vfs_fonts.js"></script>
<script src="plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
<script src="plugins/toastr/toastr.min.js"></script>
<script src="plugins/moment/moment-with-locales.js"></script>
<script src="plugins/blockui/jquery.blockui.min.js"></script>
<script src="plugins/datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script src="scripts/dataTables.buttons.min.js"></script>
<script src="scripts/jszip.min.js"></script>
<script src="scripts/pdfmake.min.js"></script>
<script src="scripts/vfs_fonts.js"></script>
<script src="scripts/buttons.html5.min.js"></script>
<script src="scripts/buttons.print.min.js"></script>
<script src="plugins/sweetalert2/sweetalert2.min.js"></script>
<script src="scripts/cookies.js"></script>
<script type="text/javascript" src="scripts/xlsx.js"></script>
<script type="text/javascript">
	$("#btnSideBar").trigger("click");
	$('.select2').select2({
		theme: 'bootstrap4',
		width: '100%'
	});

	$('.selectSmall').select2({
		theme: 'bootstrap4',
		width: '100%',
		dropdownCssClass: 'fontSelect'
	})

	$(document).on('select2:open', () => {
		document.querySelector('.select2-search__field').focus();
	});

	var dateToday = new Date(Date.now() + 3600 * 1000 * 72);
	var dateLastMonth = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);

	var day = addZero(parseInt(dateToday.getDate()));
	var month = addZero(dateToday.getMonth() + 1);
	var year = addZero(dateToday.getFullYear());

	var dayLastMonth = addZero(parseInt(dateLastMonth.getDate()));
	var monthLastMonth = addZero(dateLastMonth.getMonth() + 1);
	var yearLastMonth = addZero(dateLastMonth.getFullYear());

	var globalFechaInicial = `${yearLastMonth}-${monthLastMonth}-${dayLastMonth}`;
	var globalFechaFinal = `${year}-${month}-${day}`;

	$("#txtFechaIni").val(globalFechaInicial);
	$("#txtFechaFin").val(globalFechaFinal);

	$("#txtFechaIni").datetimepicker({
		format:'DD/MM/YYYY',
		date : globalFechaInicial,
		locale: 'es-MX'
	});

	$("#txtFechaFin").datetimepicker({
		format:'DD/MM/YYYY',
		date : globalFechaFinal,
		locale: 'es-MX'
	});

	$("#txtFechaIni").on("dp.change", function (e) {0
		$.blockUI({ message: '<h4> Cargando cotizaciones...</h4>', css: { backgroundColor: null, color: '#fff', border: null } });
		traerCotizaciones();
		$('#txtFechaFin').data("DateTimePicker").minDate(e.date);
	});

	$("#txtFechaFin").on("dp.change", function (e) {
		$.blockUI({ message: '<h4> Cargando cotizaciones...</h4>', css: { backgroundColor: null, color: '#fff', border: null } });
		traerCotizaciones();
		$('#txtFechaInicio').data("DateTimePicker").maxDate(e.date);
	});

	$("#txtFechaInicial").on("dp.change", function (e) {0
		$.blockUI({ message: '<h4> Cargando cotizaciones...</h4>', css: { backgroundColor: null, color: '#fff', border: null } });
		traerBitacora();
		$('#txtFechaFinal').data("DateTimePicker").minDate(e.date);
	});

	$("#txtFechaFinal").on("dp.change", function (e) {
		$.blockUI({ message: '<h4> Cargando cotizaciones...</h4>', css: { backgroundColor: null, color: '#fff', border: null } });
		traerBitacora();
		$('#txtFechaInicial').data("DateTimePicker").maxDate(e.date);
	});

	toastr.options = {
		"closeButton": true,
		"debug": false,
		"positionClass": "toast-top-left",
		"onclick": null,
		"showDuration": "1000",
		"hideDuration": "1000",
		"timeOut": "5000",
		"extendedTimeOut": "1000",
		"showEasing": "swing",
		"hideEasing": "linear",
		"showMethod": "fadeIn",
		"hideMethod": "fadeOut"
	}

	function valueNumber(i){
		return typeof i === 'string' ?
		i.replace(/[\$,]/g, '') * 1 :
		typeof i === 'number' ?
		i : 0;
	}

	function formatNumber (num) {
		if(num){
			return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
		}
	}

	function addZero(number){
		var valorReturn = number;
		if (number <= 9) {
			valorReturn = `0${number}`;
		}
		return valorReturn;
	}

	function onlyNumber(evt) {
		var theEvent = evt || window.event;

		if (theEvent.type === 'paste') {
			key = event.clipboardData.getData('text/plain');
		} else {
			var key = theEvent.keyCode || theEvent.which;
			key = String.fromCharCode(key);
		}
		var regex = /[0-9]/;
		if(!regex.test(key) ) {
			theEvent.returnValue = false;
			if(theEvent.preventDefault) theEvent.preventDefault();
		}
	}

	function negativeNumber(input){
		if(input.value < 0){
			input.value = 0;
			$(`#${input.id}`).focus();
			$(`#${input.id}`).select();
		}
	}

	function NotNegatives(input){
		input.value = Math.abs(input.value);
	}
</script>
