diff --git a/modules/EcmSales/javascript/EcmSales3.js b/modules/EcmSales/javascript/EcmSales3.js index cef35462..45daffb1 100755 --- a/modules/EcmSales/javascript/EcmSales3.js +++ b/modules/EcmSales/javascript/EcmSales3.js @@ -1,216 +1,217 @@ //START: $(document).ready( - function() { - //set sizes - $("#parent_name").attr("size", "70"); - $("#parent_name_copy").attr("size", "70"); - $("#parent_shipping_address_name").attr("size", "70"); - $("#payment_date_days").css("width", "40"); - //$("#payment_method").css("width", "100"); - //change parent select button - $("#btn_clr_parent_name").children().attr("src","themes/default/images/id-ff-add.png" ); - $("#btn_clr_parent_name").attr("title","Dodaj" ); - $("#btn_clr_parent_name").click(createAccount); - // confirm exit - window.onbeforeunload = confirmExit; - // prevent submit by enter press - lockEnter(); - // parent info - $("#delivery_date").on('inputchange',function() { - calculateDate($("#delivery_date").val()); - }); - var previousVal; - var pollInterval = setInterval(function() { - var val = $('#parent_id').val(); - if (val !== previousVal) { - if ($('#parent_id').val() == '') return; - $(".loading_panel").css("display", "block"); - setTimeout(function() { - getParentInfo($("#parent_id").val(), 'Accounts'); - }, 1000); - } - previousVal = val; - }, 500); - //newProduct - var previousVal2; - var prodInterval = setInterval(function() { - var val = $('#newProductId').val(); - if (val !== previousVal2) { - if ($('#newProductId').val() == '') return; - $(".loading_panel").css("display", "block"); - setTimeout(function() { - AddProduct(items.length-1, val); - }, 500); - } - previousVal2 = val; - }, 500); - // categories + function () { + //set sizes + $("#parent_name").attr("size", "70"); + $("#parent_name_copy").attr("size", "70"); + $("#parent_shipping_address_name").attr("size", "70"); + $("#payment_date_days").css("width", "40"); + //$("#payment_method").css("width", "100"); + //change parent select button + $("#btn_clr_parent_name").children().attr("src", "themes/default/images/id-ff-add.png"); + $("#btn_clr_parent_name").attr("title", "Dodaj"); + $("#btn_clr_parent_name").click(createAccount); + // confirm exit + window.onbeforeunload = confirmExit; + // prevent submit by enter press + lockEnter(); - $('#pdf_type').change(function () { - manageOO(); - var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - - // thead row - for (var index = 0; index != count; index++){ - calculateRow(index); + $("#delivery_date").on('inputchange', function () { + calculateDate($("#delivery_date").val()); + }); + var previousVal; + var pollInterval = setInterval(function () { + var val = $('#parent_id').val(); + if (val !== previousVal) { + if ($('#parent_id').val() == '') return; + $(".loading_panel").css("display", "block"); + setTimeout(function () { + getParentInfo($("#parent_id").val(), 'Accounts'); + }, 1000); + } + previousVal = val; + }, 500); + //newProduct + var previousVal2; + var prodInterval = setInterval(function () { + var val = $('#newProductId').val(); + if (val !== previousVal2) { + if ($('#newProductId').val() == '') return; + $(".loading_panel").css("display", "block"); + setTimeout(function () { + AddProduct(items.length - 1, val); + }, 500); + } + previousVal2 = val; + }, 500); + // categories - } - calculateTotal(); - }); + $('#pdf_type').change(function () { + manageOO(); + var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - + // thead row + for (var index = 0; index != count; index++) { + calculateRow(index); - getCategoriesList(); - // its vat free change - $("#no_tax").change(function() { - // calculate totals - var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - - // thead row - for (var index = 0; index != count; index++) - calculateRow(index); - }); - // language channge - $("#ecmlanguage").change(function() { - changeLanguage(); - }); - removeFromValidate('EditView', 'shipping_iln'); - DrawHeaders(); - // stock selector - $("#stock").change(function() { - $("#stock_id").val(($("#stock :selected").val())); - - }); - if($("#type :selected").val()=='sales_order'){ - removeFromValidate('EditView', 'invoice_date'); - } - $("#type").change(function() { - if($("#type :selected").val()=='sales_order'){ - removeFromValidate('EditView', 'invoice_date'); - } else { - addToValidate('EditView', 'invoice_date', 'id', 'true', ''); - } - - }); - if (($("#new_number").val() == true) - && ($("#duplicate").val() != true) && ($("#ecmquote_id").val() =='')) { - EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmSales'); - //sale from subpanel?? - var ecp = $("#ecommerce_products").val(); - if (ecp && ecp.length > 0) { - loadECommerceProducts(ecp); - } else if ($("#parent_id").val()!='') { - $(".loading_panel").css("display", "block"); - setTimeout(function() { - getParentInfo($("#parent_id").val(), $( - "#parent_type :selected").val()); - }, 1000); - } - $(".loading_panel").css("display", "none"); - } else if (($("#new_number").val() == true) - && ($("#duplicate").val() == true)) { - EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmSales'); - getParentInfo($("#parent_id").val(), - $("#parent_type :selected").val()); - getItems(); - $(".loading_panel").css("display", "none"); - } else if (($("#new_number").val() == true) - && ($("#ecmquote_id").val() != '')) { - - EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmSales'); - getParentInfo($("#parent_id").val(), - 'Accounts'); - getItemsFromSale(); - $(".loading_panel").css("display", "none"); - } else { - getParentInfo($("#parent_id").val(), - $("#parent_type :selected").val()); - getItems(); - $(".loading_panel").css("display", "none"); - } - // handle setItems - setITEMS = function() { - var formname = 'EditView'; - if (check_form_(formname) == true) { - SetTab('ITEMS'); - } - }; - //payment date functions - $('#payment_date_days').css('height', '18'); - $('#payment_date_days').val('0'); - $('#payment_date_days').change(function() { - calculatePaymentDate(); - }); - // parent info - var previousVal4; - var pollInterval4 = setInterval(function() { - var val = $('#payment_date').val(); - if (val !== previousVal4) { - setTimeout(function() { - calculateDateDiff(); - }, 1000); - } - previousVal4 = val; - }, 1000); - // wyszukiwanie start - $('#searchProductsInput').keyup(function(e) { - if (e.keyCode == 13) { - // stronicowanie od 1 strony przy zmianie szukanego produktu - $('#searchStart').val(0); - searchProducts(); - } - }); - AddSearchRecord(); - $(".loading_panel").css("display", "none"); - }); + } + calculateTotal(); + }); + + getCategoriesList(); + // its vat free change + $("#no_tax").change(function () { + // calculate totals + var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - + // thead row + for (var index = 0; index != count; index++) + calculateRow(index); + }); + // language channge + $("#ecmlanguage").change(function () { + changeLanguage(); + }); + removeFromValidate('EditView', 'shipping_iln'); + DrawHeaders(); + // stock selector + $("#stock").change(function () { + $("#stock_id").val(($("#stock :selected").val())); + + }); + if ($("#type :selected").val() == 'sales_order') { + removeFromValidate('EditView', 'invoice_date'); + } + $("#type").change(function () { + if ($("#type :selected").val() == 'sales_order') { + removeFromValidate('EditView', 'invoice_date'); + } else { + addToValidate('EditView', 'invoice_date', 'id', 'true', ''); + } + + }); + if (($("#new_number").val() == true) + && ($("#duplicate").val() != true) && ($("#ecmquote_id").val() == '')) { + EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmSales'); + //sale from subpanel?? + var ecp = $("#ecommerce_products").val(); + if (ecp && ecp.length > 0) { + loadECommerceProducts(ecp); + } else if ($("#parent_id").val() != '') { + $(".loading_panel").css("display", "block"); + setTimeout(function () { + getParentInfo($("#parent_id").val(), $( + "#parent_type :selected").val()); + }, 1000); + } + $(".loading_panel").css("display", "none"); + } else if (($("#new_number").val() == true) + && ($("#duplicate").val() == true)) { + EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmSales'); + getParentInfo($("#parent_id").val(), + $("#parent_type :selected").val()); + getItems(); + $(".loading_panel").css("display", "none"); + } else if (($("#new_number").val() == true) + && ($("#ecmquote_id").val() != '')) { + + EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmSales'); + getParentInfo($("#parent_id").val(), + 'Accounts'); + getItemsFromSale(); + $(".loading_panel").css("display", "none"); + } else { + getParentInfo($("#parent_id").val(), + $("#parent_type :selected").val()); + getItems(); + $(".loading_panel").css("display", "none"); + } + // handle setItems + setITEMS = function () { + var formname = 'EditView'; + if (check_form_(formname) == true) { + SetTab('ITEMS'); + } + }; + //payment date functions + $('#payment_date_days').css('height', '18'); + $('#payment_date_days').val('0'); + $('#payment_date_days').change(function () { + calculatePaymentDate(); + }); + // parent info + var previousVal4; + var pollInterval4 = setInterval(function () { + var val = $('#payment_date').val(); + if (val !== previousVal4) { + setTimeout(function () { + calculateDateDiff(); + }, 1000); + } + previousVal4 = val; + }, 1000); + // wyszukiwanie start + $('#searchProductsInput').keyup(function (e) { + if (e.keyCode == 13) { + // stronicowanie od 1 strony przy zmianie szukanego produktu + $('#searchStart').val(0); + searchProducts(); + } + }); + AddSearchRecord(); + calculateDate($("#delivery_date").val()); + $(".loading_panel").css("display", "none"); + }); // handle save var check_form_ = check_form; -check_form = function(formname,event) { - // zapobiega zapisywaniu dokumentu firefox bug, w przypadku nacisniecia enter w polu z autocomplete - if(event.clientY==0 && event.clientX==0){ - return false; - } - window.onbeforeunload = null; - if (items.length == 0 || items[0].product_id=='') { - alert("Brak produktów"); - return false; - } - // usuwa rekord pomocniczy - clearEmpty(); - $(".loading_panel").css("display", "block"); - // calculate totals - var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row - for (var index = 0; index != count; index++) { - calculateRow(index); - if (validation.recipient_code == true) - console.log('Sprawdzić kody trzeba'); - } - $("#total_netto").val($("#t_netto").val()); - $("#total_brutto").val($("#t_brutto").val()); - $("#discount").val($("#disc").val()); - $("#position_list").val(JSON.stringifyNoSecurity(items)); +check_form = function (formname, event) { + // zapobiega zapisywaniu dokumentu firefox bug, w przypadku nacisniecia enter w polu z autocomplete + if (event.clientY == 0 && event.clientX == 0) { + return false; + } + window.onbeforeunload = null; + if (items.length == 0 || items[0].product_id == '') { + alert("Brak produktów"); + return false; + } + // usuwa rekord pomocniczy + clearEmpty(); + $(".loading_panel").css("display", "block"); + // calculate totals + var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row + for (var index = 0; index != count; index++) { + calculateRow(index); + if (validation.recipient_code == true) + console.log('Sprawdzić kody trzeba'); + } + $("#total_netto").val($("#t_netto").val()); + $("#total_brutto").val($("#t_brutto").val()); + $("#discount").val($("#disc").val()); + $("#position_list").val(JSON.stringifyNoSecurity(items)); - - if (check_form_(formname) === true) { - return true; - } else { - window.onbeforeunload = confirmExit; - $(".loading_panel").css("display", "none"); - return false; - } + if (check_form_(formname) === true) { + return true; + } else { + window.onbeforeunload = confirmExit; + $(".loading_panel").css("display", "none"); + return false; + } }; + function confirmExit() { - return ""; + return ""; } function lockEnter() { - // prevent default + // prevent default - $(window).keydown(function(event) { + $(window).keydown(function (event) { - if (event.keyCode == 13 && $(":focus").prop('tagName')!='input') { + if (event.keyCode == 13 && $(":focus").prop('tagName') != 'input') { - event.preventDefault(); - return false; - } - }); + event.preventDefault(); + return false; + } + }); } function loadECommerceProducts(ecp) { diff --git a/modules/EcmSales/javascript/helper.php b/modules/EcmSales/javascript/helper.php index 97ef5b8f..3d66fcf2 100755 --- a/modules/EcmSales/javascript/helper.php +++ b/modules/EcmSales/javascript/helper.php @@ -24,6 +24,13 @@ function calculateDate($date){ $date = new Datetime($date); $date->modify('-1 day'); $tmp['date']=$date->format("d.m.Y"); + $tmp['date_day']=date('N', strtotime($tmp['date'])); + if($tmp['date_day']==7){ + $date->modify('-2 day'); + } else if($tmp['date_day']==6){ + $date->modify('-1 day'); + } + $tmp['date']=$date->format("d.m.Y"); echo json_encode($tmp); return ''; }