text: function panelAddData(a, t){return stringData = t.toString(), stringData.length < 4 && (displayStatus?(stringData = panelData[a], displayStatus = !1):stringData += panelData[a]), stringData}function resetPanel(){displayStatus = !0, $("#display-panel").val("0")}function sendFormClient(){$("#add_client").valid() && $.ajax({type:"POST", url:window.location.href.match(/^.*\//) + "venta/addClient", data:$("#add_client").serialize()}).done(function(a){a.success?(console.log("Envio exitoso"), $("#modal-client").modal("hide"), clearFormClient(), showToast("success", "Registro exitosamente completado")):showToast("error", "Ocurrio un problema al realizar el registro")})}function clearFormClient(){$("#f_client_name").val(""), $("#f_client_document").val(""), $("#f_client_birthdate").val(""), $("#f_client_phone").val(""), $("#f_client_cellphone").val(""), $("#f_client_email").val(""), $("textarea#f_client_address").val("")}function clearBilling(){$("#f_billing_payment").val(""), $("#f_billing_change").val("0"), $("#send-billing").prop("disabled", !0)}function panelBillingAddData(a, t){return stringData = t.toString(), stringData += panelData[a], stringData}function changeBilling(a){var t = $("#f_billing_amount_total").val(); $("#f_billing_payment").val(a), a - t >= 0?($("#f_billing_change").val(a - t), $("#send-billing").prop("disabled", !1)):($("#f_billing_change").val("0"), $("#send-billing").prop("disabled", !0))}function checkImageForRow(){if (tablaVenta.row({selected:!0}).count() > 0){var a = tablaVenta.row({selected:!0}).data(); "-1" === a.filedata?$("#product-image").attr("src", window.location.href.match(/^.*\//) + "img/image_default.jpg"):$("#product-image").attr("src", window.location.href.match(/^.*\//) + "filedata/loadfile/" + a.filedata), $("#product-description").text(a.product_name)}}function showToast(a, t){toastr.options.positionClass = "toast-top-right", toastr.options.extendedTimeOut = 0, toastr.options.timeOut = 3e3, toastr.options.fadeOut = 250, toastr.options.fadeIn = 250, toastr[a](t)}var panelData = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."], displayStatus = !0, displayBillingStatus = !0; $(".select-custom").select2({dropdownParent:$("#modal-client")}); var tablaVenta = $("#venta").DataTable({paging:!1, searching:!1, orderClasses:!1, data:null, columns:[{data:"order_detail_id"}, {data:"quantity"}, {data:"product_name"}, {data:"price_unit"}, {data:"discount"}, {data:"price_total"}, {data:"filedata"}], columnDefs:[{targets:[0], visible:!1, searchable:!1}, {targets:[6], visible:!1, searchable:!1}], order:[[2, "asc"]], select:{style:"single"}}); $("#venta_info").css("display", "none"), tablaVenta.on("select", function(a, t, e, n){var o = tablaVenta.row(n).data(); "-1" === o.filedata?$("#product-image").attr("src", window.location.href.match(/^.*\//) + "img/image_default.jpg"):$("#product-image").attr("src", window.location.href.match(/^.*\//) + "filedata/loadfile/" + o.filedata), $("#product-description").text(o.product_name)}), tablaVenta.on("deselect", function(a, t, e, n){$("#product-image").attr("src", window.location.href.match(/^.*\//) + "img/image_default.jpg"), $("#product-description").text(" ")}); var search_client = $.typeahead({input:".search-client", minLength:1, order:"asc", hint:!0, group:!0, dropdownFilter:"Todo", dynamic:!0, emptyTemplate:function(a){if (a.length > 0)return'No se encontro "' + a + '"'}, template:'<div class="fila"><span class="titulo">DOC: </span><span class="valor">{{doc}}</span></div><div class="fila"><span class="titulo">NOMBRE: </span><span class="valor">{{name}}</span></div>', source:{Nombre:{display:"name", ajax:{type:"POST", url:window.location.href.match(/^.*\//) + "venta/searchClientByName", dataType:"json", data:{query:"{{query}}", type:2}}}, Documento:{display:"doc", ajax:{type:"POST", url:window.location.href.match(/^.*\//) + "venta/searchClientByDoc", dataType:"json", data:{query:"{{query}}", type:1}}}}, callback:{onClick:function(a, t, e, n){e["sale-order"] = $("#sale-order").val(), $.ajax({type:"POST", url:window.location.href.match(/^.*\//) + "venta/selectClient", data:e}).done(function(a){a?($("#doc-client").val(e.doc), $("#name-client").val(e.name), $("#client-info").css("display", "block")):showToast("error", "Ocurrio un problema al realizar el registro")})}}}), search_product = $.typeahead({input:".search-product", minLength:1, order:"asc", hint:!0, dynamic:!0, emptyTemplate:function(a){if (a.length > 0)return'No se encontro "' + a + '"'}, display:"product_name", source:{PRODUCTS:{ajax:{type:"POST", url:window.location.href.match(/^.*\//) + "venta/searchProduct", dataType:"json", data:{query:"{{query}}", saleOrder:$("#sale-order").val()}}}}, callback:{onClick:function(a, t, e, n){e["sale-order"] = $("#sale-order").val(), $.ajax({type:"POST", url:window.location.href.match(/^.*\//) + "venta/selectProduct", data:e}).done(function(a){if (a.success){$(".quantity-products").text(a.qProducts), $(".amount-total").text(a.aTotal); var t = tablaVenta.row.add(a).draw().node(); $(t).addClass("text-right"), showToast("success", "Producto adicionado correctamente")} else showToast("error", "Ocurrio un problema al realizar el registro")})}, onClickAfter:function(a, t, e, n){a.val(""), $("#product-image").attr("src", window.location.href.match(/^.*\//) + "img/image_default.jpg"), $("#product-description").text(" "), checkImageForRow()}, onMouseEnter:function(a, t, e, n){e.filedata?$("#product-image").attr("src", window.location.href.match(/^.*\//) + "filedata/loadfile/" + e.filedata):$("#product-image").attr("src", window.location.href.match(/^.*\//) + "img/image_default.jpg"), $("#product-description").text(e.product_name)}, onMouseLeave:function(a, t, e, n){$("#product-image").attr("src", window.location.href.match(/^.*\//) + "img/image_default.jpg"), $("#product-description").text(" "), checkImageForRow()}}}); $(".data-panel").click(function(){var a = panelAddData($(this).attr("data"), $("#display-panel").val()); $("#display-panel").val(a)}), $(".reset-panel").click(function(){resetPanel()}), $(".send-panel").click(function(){if (tablaVenta.row({selected:!0}).count() > 0){var a = tablaVenta.row({selected:!0}).data(); a["sale-order"] = $("#sale-order").val(), a["display-panel"] = $("#display-panel").val(), $.ajax({type:"POST", url:window.location.href.match(/^.*\//) + "venta/changeQuantityProduct", dataType:"json", data:a}).done(function(t){t.success?(a.quantity = t.quantity, a.price_total = t.price_total, tablaVenta.row({selected:!0}).data(a).node(), $(".quantity-products").text(t.qProducts), $(".amount-total").text(t.aTotal), resetPanel(), showToast("success", "Cambio de informacion correctamente efectuado"), t.stockStatus || showToast("warning", "No se cuenta con la cantidad necesaria del produto en stock")):showToast("error", "Ocurrio un problema al realizar el registro")})}}), $(".delete-panel").click(function(){if (tablaVenta.row({selected:!0}).count() > 0){var a = tablaVenta.row({selected:!0}).data(); a["sale-order"] = $("#sale-order").val(), $.ajax({type:"POST", url:window.location.href.match(/^.*\//) + "venta/removeProduct", dataType:"json", data:a}).done(function(a){a.success && (tablaVenta.row({selected:!0}).remove().draw(!1), $(".quantity-products").text(a.quantity_products), $(".amount-total").text(a.amount_total), $("#product-image").attr("src", window.location.href.match(/^.*\//) + "img/image_default.jpg"), $("#product-description").text(" "), showToast("success", "Cambio de informacion correctamente efectuado"))})}}), $("#btnOpenModalClient").click(function(){clearFormClient(), $("#modal-client").modal("show")}), $("#btnSendClient").click(function(){sendFormClient()}), $(".close-modal-client").click(function(){$("#modal-client").modal("hide"), clearFormClient()}), $("#add_client").validate({errorElement:"span", errorClass:"help-block help-block-error", focusInvalid:!1, ignore:"", messages:{}, rules:{client_name:{required:!0}, client_gender:{required:!0}, client_document:{required:!0}, client_cellphone:{required:!0}, client_email:{required:!0, email:!0}}, errorPlacement:function(a, t){t.is(":checkbox")?a.insertAfter(t.closest(".md-checkbox-list, .md-checkbox-inline, .checkbox-list, .checkbox-inline")):t.is(":radio")?a.insertAfter(t.closest(".md-radio-list, .md-radio-inline, .radio-list,.radio-inline")):a.insertAfter(t)}, highlight:function(a){$(a).closest(".form-group").addClass("has-error")}, unhighlight:function(a){$(a).closest(".form-group").removeClass("has-error")}, success:function(a){a.closest(".form-group").removeClass("has-error")}}), $("#btnOpenModalBilling").click(function(){clearBilling(), $("#modal-billing").modal("show")}), $(".billing-panel").click(function(){changeBilling(panelBillingAddData($(this).attr("data"), $("#f_billing_payment").val()))}), $(".billing-reset").click(function(){clearBilling()}), $(".close-billing").click(function(){$("#modal-billing").modal("hide"), clearBilling()}), $("#f_billing_payment").numeric({negative:!1}), $("#f_billing_payment").on("input propertychange", function(){changeBilling($(this).val())});