var itemsTable = 'itemsTable'; var items = new Array(); var displayArray = new Array(); var validation = new Object(); var shipping_addresses = new Array(); var searchedProducts = new Array(); var ajax_url = "index.php?module=EcmStockDocOuts&action=javahelper&to_pdf=1"; //add mz // oo vat stuff var account_vat_payer = false; var oo_active = false; // draw table function DrawHeaders() { var html = ''; html += '
'; html += ''; html += ''; html += ''; // draw columns headers $.each(columns, function (index, column) { //if(column.label=='Ceny')hide=' style="display: none"'; //else var hide = ''; html += ''; }); html += '
' + column.label + '
'; html += '

'; // totals table html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += '
'; html += ' '; html += ' '; html += '
'; html += ''; html += '
'; html += '
 
'; // sort? why not! /* * html += 'Sortowanie: '; html += ''; vats_summary += vats[x].value_name + ':' + toFixed(vats[x].netto, 2) + ':' + toFixed(vats[x].value, 2) + ':' + toFixed(vats[x].brutto, 2) + ':' + ','; } } html += 'Ilość razem'; html += ''; DrawSummary(html); $('#total_vat').val(FormatNumber(sum_vats)); $('#total_quantity').val(FormatNumber(total_quantity)); $("#t_netto").val(FormatNumber(all_subtotal)); $("#t_brutto").val(FormatNumber(all_total)); $("#vats_summary").val(vats_summary); } function manageOO() { var count = items.length; //parse OO object if (typeof (OO) != 'object') OO = JSON.parse(OO); for (var index = 0; index != count; index++) { if (oo_active == true) { if ($('#product_is_oo_' + index).val() != '1') continue; //save orginal vat items[index].real_vat_id = items[index].ecmvat_id; items[index].real_vat_name = items[index].ecmvat_name; items[index].real_vat_value = items[index].ecmvat_value; items[index].ecmvat_id = OO.id; items[index].ecmvat_name = OO.name; items[index].ecmvat_value = OO.value; $('#ecmvat_id_' + index).val(OO.id); $('#ecmvat_name_' + index).val(OO.name); $('#ecmvat_value_' + index).val(OO.value); } else { if ($('#product_is_oo_' + index).val() != '1') continue; items[index].ecmvat_id = items[index].real_vat_id; items[index].ecmvat_name = items[index].real_vat_name; items[index].ecmvat_value = items[index].real_vat_value; $('#ecmvat_id_' + index).val(items[index].real_vat_id); $('#ecmvat_name_' + index).val(items[index].real_vat_name); $('#ecmvat_value_' + index).val(items[index].real_vat_value); } calculateRow(index); } calculateTotal(); } function DrawSummary(vats) { $("#result_table").html(''); html = ''; html += ' '; html += 'Suma netto'; html += ''; html += ''; html += vats; html += ' '; html += 'Suma brutto'; html += ''; html += ''; $("#result_table").html(html); } function DrawDetailSummary() { $("#result_table").html(''); html = ''; html += ' '; html += 'Razem ilość'; html += ''; html += ''; html += ''; html += 'Suma dokumentu'; html += ''; html += ''; html += ''; html += 'Suma operacji: wyjście'; html += ''; html += ''; $("#result_table").html(html); } function generateNumber() { var params = { job: 'generateNumber', stock_id: $("#stock_id").val(), date: $("#register_date").val(), }; $.ajax({ type: "POST", url: ajax_url, dataType: "json", success: function (data) { if (data == '-1') { // try loading again generateNumber(); } else { $("#document_no").val(data.document_no); $("#number").val(data.number); $(".loading_panel").css("display", "none"); } }, data: params }); } function getCategoriesList() { var params = { job: 'getCategoriesList' }; $.ajax({ type: "POST", url: ajax_url, dataType: "json", success: function (data) { var html = ''; $.each(data, function (index, value) { html += ''; $("#productSearchCategory").html(html); }); }, data: params }); } function refreshStock(index) { var params = { job: 'getStockState', id: $("#product_id_" + index).val(), stockId: $("#stock_id").val(), }; $.ajax({ type: "POST", url: ajax_url, dataType: "json", async: false, success: function (data) { $("#stock_state_" + index).val(FormatNumber(data, $("#product_precision_" + index).val())); }, data: params }); } function refreshAllStocks(ids) { return new Promise((resolve) => { var params = { job: "getStockStates", ids: ids.join("|"), stockId: $("#stock_id").val(), }; $.ajax({ type: "POST", url: ajax_url, dataType: "json", async: false, success: function (data) { resolve(data); }, data: params }); }); } function setRowDate(index) { var qty = UnformatNumber($("#quantity_" + index).val()); items[index].quantity = qty; } async function checkProducts() { $(".loading_panel").css("display", "block"); //var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row var count = items.length; var ids = []; for (var index = 0; index != count; index++) { var id = $("#product_id_" + index).val(); if (id !== "") { ids.push(id); } } var states = []; if (ids.length > 0) { states = await refreshAllStocks(ids); } var error = false; // hope :) for (var index = 0; index != count; index++) { if ($("#product_id_" + index).val() != '') { var prodId = $("#product_id_" + index).val(); var state = states.find(x => x.id === prodId); if (state) { $("#stock_state_" + index).val(FormatNumber(state.state, $("#product_precision_" + index).val())); } else { $("#stock_state_" + index).val(FormatNumber(0, $("#product_precision_" + index).val())); } //refreshStock(index); var qty = UnformatNumber($("#quantity_" + index).val()); var cat_id = $("#product_category_id_" + index).val(); var part_qty = $("#product_consignment_qty_" + index).val(); // refresh items array items[index].quantity = qty; if ($('#product_is_consignment_' + index).val() != '1') { part_qty = qty; } var stock = UnformatNumber($("#stock_state_" + index).val()); if (qty > 0 && qty <= part_qty && qty <= stock) { $("#quantity_" + index).css("color", "black"); } else { error = true; $("#quantity_" + index).css("color", "red"); } } } $(".loading_panel").css("display", "none"); if (error) { return false; } else { return true; } } function getComponents(index) { $(".loading_panel").css("display", "block"); var product_id = items[index].product_id; var qty = items[index].quantity; //var price = items[index].price; var params = { job: 'getComponents', product_id: product_id, }; $.ajax({ type: "POST", url: ajax_url, dataType: "json", async: false, success: function (data) { if (data.length > 0) { items.splice(index, 1); $.each(data, function (index, value) { var p = new Object(); p.product_id = value.id; p.name = value.name; p.product_code = value.code; p.unit_name = value.unit_name; p.unit_id = value.unit_id; p.quantity = qty * parseInt(value.quantity); p.product_category_id = value.product_category_id; if (p.product_category_id == 'd7f876b0-1a3d-43a1-7c9b-511ba40df3d1') return; items.push(p); }); } ; }, data: params }); FillTable(items); $(".loading_panel").css("display", "none"); } function getPricesInfo(index) { $("#price_start_div_" + index).show('slow'); $("#price_start_div_" + index).html( ''); var params = { job: 'getPricesInfo', product_id: $("#product_id_" + index).val(), pricebook_id: $("#pricebook_id :selected").val(), account_id: $("#parent_id").val(), }; $ .ajax({ type: "POST", url: ajax_url, dataType: "json", async: false, success: function (data) { html = ''; }, data: params }); $("#price_start_div_" + index).html(html); } function calculateRow(index) { if (index == -1) return; // liczone według najlepszych zasad księgowości var price_netto = UnformatNumber($('#price_netto_' + index).val()); var vat_value = $('#ecmvat_value_' + index).val(); var quantity = UnformatNumber($('#quantity_' + index).val()); var precision = UnformatNumber($('#product_precision_' + index).val()); var total_netto = price_netto * quantity; // put data $('#price_netto_' + index).val(FormatNumber(price_netto)); $('#total_netto_' + index).val(FormatNumber(total_netto)); $('#total_vat_' + index).val(FormatNumber((total_netto * vat_value) / 100)); $('#price_brutto_' + index).val(FormatNumber(((price_netto * vat_value) / 100) + price_netto)); $('#total_brutto_' + index).val(FormatNumber(((total_netto * vat_value) / 100) + total_netto)); // put data to items array items[index].price_netto = toFixed(price_netto, 2); items[index].price_brutto = toFixed(((price_netto * vat_value) / 100) + price_netto, 2); items[index].total_netto = toFixed(total_netto, 2); items[index].total_brutto = toFixed(((total_netto * vat_value) / 100) + total_netto, 2); items[index].total_vat = toFixed(((total_netto * vat_value) / 100), 2); items[index].quantity = toFixed(quantity, precision), precision; items[index].ecmvat_id = $('#ecmvat_id_' + index).val(); items[index].ecmvat_name = $('#ecmvat_name_' + index).val(); items[index].ecmvat_value = vat_value; // change name or language? items[index].name = htmlEscape($('#name_' + index).val()); items[index].part_no = htmlEscape($('#part_no_' + index).val()); items[index].un_code = htmlEscape($('#un_code_' + index).val()); calculateTotal(); //update cartons var pieces_per_carton = UnformatNumber($('#product_pieces_per_carton_' + index).val()); var cartons = 0; if (pieces_per_carton > 0) { cartons = Math.ceil(quantity / pieces_per_carton); } $('#product_cartons_' + index).val(FormatNumber(cartons, 2)); items[index].product_pieces_per_carton = toFixed(pieces_per_carton, 2); items[index].product_cartons = toFixed(cartons, 2); } function updatePartNo(index) { items[index].part_no = $('#part_no_' + index).val(); } function updateUnCode(index) { console.log('UN', index); items[index].un_code = $('#un_code_' + index).val(); } function getSearchInfo2(product_id, product_code) { $("#search_info_div2_" + product_id).show().draggable(); var html = ''; html += '' + product_code + '

'; html += ''; var params = { job: 'getStockArray', product_id: product_id, }; $.ajax({ type: "POST", url: ajax_url, dataType: "json", async: false, success: function (data) { $.each(data, function (key, value) { html += ''; }); }, data: params }); html += '
MagazynIlość
' + key + '' + FormatNumber(value) + '
'; $("#search_info_div2_" + product_id).html(html); } function getSearchInfo(product_id, product_code) { $("#search_info_div_" + product_id).show().draggable(); var html = ''; html += '' + product_code + '

'; // get prices info html += ''; var params = { job: 'getPricesInfo', product_id: product_id, pricebook_id: $("#pricebook_id :selected").val(), account_id: $("#parent_id").val(), }; $.ajax({ type: "POST", url: ajax_url, dataType: "json", async: false, success: function (data) { $.each(data, function (key, value) { if (value.name == 'pricebook') html += $("#pricebook_id :selected").html() + ': ' + FormatNumber(value.price) + '
'; if (value.name == $("#ecmprice_name").val()) html += '' + value.name + ': ' + FormatNumber(value.price) + '
'; else if (value.module == 'EcmStockDocIns') { html += ''; } //html += value.name + ': ' + FormatNumber(value.price) // + '
'; }); }, data: params }); html += '
NazwaIlośćCenaData dok
' + value.name + '' + value.quantity + ' ' + FormatNumber(value.price) + '' + value.register_date + '
'; $("#search_info_div_" + product_id).html(html); } function getSearchInfo3(product_id, product_code) { $("#search_info_div3_" + product_id).show().draggable(); var html = ''; html += '' + product_code + '

'; // get prices info html += ''; var params = { job: 'getPricesInfo', product_id: product_id, pricebook_id: $("#pricebook_id :selected").val(), account_id: $("#parent_id").val(), }; $.ajax({ type: "POST", url: ajax_url, dataType: "json", async: false, success: function (data) { $.each(data, function (key, value) { if (value.name == 'pricebook') html += $("#pricebook_id :selected").html() + ': ' + FormatNumber(value.price) + '
'; if (value.name == $("#ecmprice_name").val()) html += '' + value.name + ': ' + FormatNumber(value.price) + '
'; else if (value.module == 'EcmPrices') { html += ''; } if (value.module == 'EcmInvoiceOuts') { html += ''; } //html += value.name + ': ' + FormatNumber(value.price) // + '
'; }); }, data: params }); html += '
NazwaCena
' + value.name + ': ' + FormatNumber(value.price) + '
' + value.name + ': ' + FormatNumber(value.price) + '
'; $("#search_info_div3_" + product_id).html(html); } /* $.event.special.inputchange = { setup: function () { var self = this, val; $.data(this, 'timer', window.setInterval(function () { val = self.value; if ($.data(self, 'cache') != val) { $.data(self, 'cache', val); $(self).trigger('inputchange'); } }, 20)); }, teardown: function () { window.clearInterval($.data(this, 'timer')); }, add: function () { $.data(this, 'cache', this.value); } }; */ function createProduct() { var newProdId = document.getElementById("newProductId"); newProduct = window.open('index.php?module=EcmProducts&action=EditView&IamPopup=1', 'newProduct', 'toolbar=no,menubar=no,scrollbars=yes,scrollbars=1'); newProduct.newProdId = newProdId; newProduct.focus(); } function createAccount() { var parent_name = document.getElementById("parent_name"); var parent_id = document.getElementById("parent_id"); newAccount = window.open('index.php?module=Accounts&action=EditView&IamPopup=1', 'newAccount', 'toolbar=no,menubar=no,scrollbars=yes,scrollbars=1'); newAccount.parent_name = parent_name; newAccount.parent_id = parent_id; newAccount.focus(); } // sortable rows in main table //$("#" + itemsTable + " tbody").sortable();