var ajaxsearch_url = 'index.php?module=EcmProducts&action=javahelper&to_pdf=1'; var dialog; var form; var currentPart=0; var group_ks_search = ''; function htmlEscape(str) { return String(str) .replace(/&/g, '&') .replace(/"/g, '"') .replace(/'/g, ''') .replace(//g, '>'); } function showdialog() { $('#searchResultDiv').html(''); $(".loading_panel").css("display", "block"); var url = 'index.php?module=EcmProducts&action=QuickCreate2'; $('#searchResultDiv'). append(''); var iframe = $('#frameid'); iframe.attr('src', url); iframe.load(function () { $(".loading_panel").css("display", "none"); callback(this, iframe); }); } function callback(frame, frame2) { $('#frameid').contents().bind({ submit: function () { $(".loading_panel").css("display", "block"); frame2.load(function () { AddProduct(searchEmpty(), $('#frameid').contents().find("#return_product_id").val()); $('#searchResultDiv').html(''); $(".loading_panel").css("display", "none"); }); } }); } function replaceAll(str, find, replace) { return str.replace(new RegExp(find, 'g'), replace); } function replaceCharters(text){ var res = replaceAll(text,'"', """); var res = replaceAll(res,"'", "'"); return res; } function FillTable(data, allReadOnly) { html = ''; // loop throw data rows var pozycja = 1; var color; $.each( data, function (row_index, row) { html += ''; if (row.product_corrected == "false") { color = '#D4D9DB'; } else { color = '#ffffff'; } // and insert columns $.each( columns, function (col_index, column) { // row must have code and name if (!row.product_code || row.product_code == '' || !row.name || row.name == '') return; // return in each = // continue in php for // loop // special types if (column.name == 'number') { html += '
'; } else if (column.name == 'options') { if (allReadOnly) html += ''; else { html += ''; // move up html += ''; html += ' '; // move down html += ''; html += '
'; // delete row html += ''; html += ''; } } // other types else { if (column.hide == 'yes') hide = ' style="display: none;background-color:' + color + ';"'; else hide = 'style="background-color:' + color + ';"'; html += ''; $ .each( column.content, function ( cell_index, cell) { var cellname = column.name + cell.name; if (cellname == 'product_link') { html += '' + row.product_code + '
'; } else if (cellname == 'price_purchase') { html += ''; if(row.product_category_id=='bf900339-6c7b-f278-2737-542023796730' || row.product_ks_group=='3'){ html += ' '; html += ' '; } }else if (cellname == 'price_start_div' && !allReadOnly) { html += '
'; html += ''; }else if (cellname == 'unit_div' && !allReadOnly) { html += '
'; html += ''; }else if (cellname == 'ecmvat_div' && !allReadOnly) { html += '
'; html += ''; } else if (cellname == 'quantity') { if (cell.label && cell.label != '') html += '

' + cell.label + '

'; html += '

'; } }else if (cellname == 'stock_state') { if (cell.label && cell.label != '') html += '

' + cell.label + '

'; html += '

'; } } else { if (cell.label && cell.label != '') html += '

' + cell.label + '

'; html += ' tbody').html(html); if (!allReadOnly || allReadOnly == 'y') { if (module_function == 'EcmSales' || module_function == 'EcmInvoiceOuts' || module_function == 'EcmReceipts' || module_function == 'EcmPurchaseOrders' || module_function == 'EcmQuotes' || module_function == 'EcmStockDocIns' || module_function == 'EcmStockDocOuts') { // calculate totals var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - // thead // row for (var index = 0; index != count; index++) calculateRow(index); } if (module_function == 'EcmStockDocOuts' || module_function == 'EcmStockDocInsideOuts') { checkProducts(); } $('#itemsTable_T').enableCellNavigation(); } else DrawDetailSummary(); } function changeName(index) { console.log(index); items[index].name = $('#name_' + index).val(); } function SearchSingleProduct(index) { /* * var searchKey = $('#name_'+index).val(); if (searchKey.length < 6 && * searchKey != '%') { $('#search_auto_id_'+index).hide(); } else { * * * setTimeout(function() { if (searchKey == $('#name_'+index).val()) { var * params = { job : 'searchProductsAutocomplite', searchKey : searchKey, * searchStock : $("#productSearchStock :selected").val(), searchStockId : * $("#stock_id").val(), index: index, }; * * $.ajax({ type : "POST", url : ajaxsearch_url, dataType : "json", async : * false, success : function(data) { if (data != '-1'){ * $('#search_auto_id_'+index).html(''); var content=''; $.each(data, * function( index, value ) { * * content+='
  • '+value.name+'
  • '; }); * $('#search_auto_id_'+index).append(content); * $('#search_auto_id_'+index).show(); } }, data : params }); } }, 1000); } */ // prevent html escape $["ui"]["autocomplete"].prototype["_renderItem"] = function (ul, item) { return $("
  • ").data("item.autocomplete", item).append( $("").html(item.label)).appendTo(ul); }; // prevent html escape end if ($("#product_id_" + index).val() == '') { $("#name_" + index) .autocomplete( { source: function (request, response) { $ .ajax({ type: "POST", url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1", dataType: "json", async: false, data: { job: "searchProductsAutocomplite", term: request.term, searchStock: $( "#productSearchStock :selected") .val(), searchStockId: $("#stock_id") .val(), index: index }, success: function (data) { response(data); } }); }, minLength: 6, select: function (event, ui) { var url = ui.item.id; if (url != '') { AddProduct(index, ui.item.id); } }, html: false, open: function (event, ui) { $(".ui-autocomplete").css("z-index", 1000); } }); } } function set_item(item, index) { // change input value $('#name_' + index).text(item); // hide proposition list $('#search_auto_id_' + index).hide(); } function AddSearchRecord() { var p = new Object(); p.product_id = ''; p.name = 'Wpisz tu nazwę lub indeks produktu aby wyszukać'; p.product_code = ' '; p.product_id = ''; p.ecmvat_id = ''; p.ecmvat_value = ''; p.ecmvat_name = ''; p.product_ean = ''; p.discount = ''; p.product_ean2 = ''; p.unit_name = ''; p.unit_id = ''; p.price_start = ''; p.recipient_code = ''; items.push(p); FillTable(items, false); } function deleteRow(index) { items.splice(index, 1); FillTable(items); } function moveUpRow(index) { if (index == 0) return; // Can't go upper.. :( var new_index = index - 1; var old_index = index; if (new_index >= items.length) { var k = new_index - items.length; while ((k--) + 1) { items.push(undefined); } } items.splice(new_index, 0, items.splice(old_index, 1)[0]); FillTable(items); } function moveDownRow(index) { if (index == items.length - 1) return; // Can't go lower.. :( var new_index = index + 1; var old_index = index; if (new_index >= items.length) { var k = new_index - items.length; while ((k--) + 1) { items.push(undefined); } } items.splice(new_index, 0, items.splice(old_index, 1)[0]); FillTable(items); } function searchProducts() { var searchKey = $('#searchProductsInput').val(); if (searchKey.length < 2 && searchKey != '%') { return; } var stockid = module_function == 'EcmStockDocMoves' ? $("#stock_out_id") .val() : $("#stock_id").val(); $("#searchResultDiv").html( ''); setTimeout(function () { if (searchKey == $('#searchProductsInput').val()) { var params = { job: 'searchProducts', searchKey: searchKey, searchCategory: $("#productSearchCategory :selected").val(), searchStock: $("#productSearchStock :selected").val(), searchStockId: stockid, searchSort: $("#searchSort").val(), searchStart: $("#searchStart").val(), searchCount: $("#searchCount").val(), groupKs: group_ks_search, }; $.ajax({ type: "POST", url: ajaxsearch_url, dataType: "json", success: function (data) { if (data != '-1') if (data.length == 0) $('#searchResultDiv').html( 'MOD.LBL_SEARCH_NO_RESULT'); else createSearchResult(data); }, data: params }); } }, 1000); } function searchAllProducts() { var searchKey = '%'; var stockid = module_function == 'EcmStockDocMoves' ? $("#stock_out_id") .val() : $("#stock_id").val(); $("#searchResultDiv").html( ''); setTimeout(function () { var params = { job: 'searchProducts', searchKey: searchKey, searchCategory: $("#productSearchCategory :selected").val(), searchStock: $("#productSearchStock :selected").val(), searchStockId: stockid, searchSort: $("#searchSort").val(), }; $.ajax({ type: "POST", url: ajaxsearch_url, dataType: "json", success: function (data) { if (data != '-1') if (data.length == 0) $('#searchResultDiv').html('MOD.LBL_SEARCH_NO_RESULT'); else createSearchResult(data); }, data: params }); }, 1000); } function createPaginationTable(data) { // akcja if (parseInt($("#searchStart").val()) - 50 >= 0) { var img = 'start.gif'; var disabled = ''; var onclick = "$('#searchStart').val(0);searchProducts();"; } else { var img = 'start_off.gif'; var disabled = 'disabled="disabled"'; var onclick = ''; } // guzik var firstbutton = ''; if (parseInt($("#searchStart").val()) - 50 >= 0) { var img = 'previous.gif'; var disabled = ''; var onclick = "$('#searchStart').val(parseInt($('#searchStart').val())-50);searchProducts();"; } else { var img = 'previous_off.gif'; var disabled = 'disabled="disabled"'; var onclick = ''; } var prev = ''; if (parseInt($("#searchStart").val()) + 50 < data.count) { var img = 'next.gif'; var disabled = ''; var onclick = "$('#searchStart').val(parseInt($('#searchStart').val())+50);searchProducts();"; } else { var img = 'next_off.gif'; var disabled = 'disabled="disabled"'; var onclick = ''; } var next = ''; if (parseInt($("#searchStart").val()) + 50 < data.count) { var img = 'end.gif'; var disabled = ''; var last = Math.floor(parseInt(data.count) / 50) * 50; if (last == data.count) last = last - 50; var onclick = "$('#searchStart').val(" + last + ");searchProducts();"; } else { var img = 'end_off.gif'; var disabled = 'disabled="disabled"'; var onclick = ''; } var lastbutton = ''; var action = "$('#searchStart').val($('#gotoPage option:selected').val());searchProducts();"; var select = ''; var close = ''; var html = ''; var page = 'Strona ' + current_page + ' z ' + total_pages; html += '
    Znaleziono ' + data.count + ' produktów' + firstbutton + ' ' + prev + ' ' + select + ' ' + next + ' ' + lastbutton + ' ' + page + ' ' + close + '
    '; return html; } function SelectDeselectChb() { if ($(".tf").is(':checked')) { $(".tf").attr('checked', false); } else { $(".tf").prop('checked', 'checked'); } } function toggleSort(code1, code2) { if ($("#searchSort").val() == code1) { $("#searchSort").val(code2); } else { $("#searchSort").val(code1); } } function getSortImages() { var img = new Object(); if ($("#searchSort").val() == 1) { img.indeximg = 'themes/Sugar5/images/arrow_up.gif'; img.nameimg = 'themes/Sugar5/images/arrow.gif'; } if ($("#searchSort").val() == 2) { img.indeximg = 'themes/Sugar5/images/arrow_down.gif'; img.nameimg = 'themes/Sugar5/images/arrow.gif'; } if ($("#searchSort").val() == 3) { img.nameimg = 'themes/Sugar5/images/arrow_up.gif'; img.indeximg = 'themes/Sugar5/images/arrow.gif'; } if ($("#searchSort").val() == 4) { img.nameimg = 'themes/Sugar5/images/arrow_down.gif'; img.indeximg = 'themes/Sugar5/images/arrow.gif'; } return img; } function createSearchResult(data, single, index) { // stronicowanie :)) var single = single ? single : true; var index = index ? index : false; if (data.count > 0) { var pagination = createPaginationTable(data); var img = getSortImages(); // strzałki do sortowania var html = pagination + ''; html += ''; if (number_show == true) html += ''; // jeśli wyszukujesz z tabelki blokuje zaznaczanie wielu if (single != false) { disabled = ''; } else { disabled = 'disabled="disabled"'; } html += ''; html += ''; html += ''; if ($("#productSearchStock :selected").val() != '1') html += ''; if (unit_show == true) html += ''; if (extraproductinfo_show == true) html += ''; html += ''; // numeracja wyszukiwanych rekordow var number = parseInt($('#searchStart').val()) + 1; // czy to podmiana rekodu czy kolejny if (index == false) { action = ' return addProducts();'; } else { action = ' return replaceProduct(' + index + ');'; } var counter; delete data.count; $.each( data, function (index, value) { if (counter % 2 == 0) { html += ''; } else { html += ''; } if (number_show == true) html += ''; html += ''; html += ''; html += ''; if ($("#productSearchStock :selected").val() != '1') html += ''; if (unit_show == true) html += ''; if (extraproductinfo_show == true) { html += ''; } html += ''; searchedProducts.push(value.id); counter++; number++; }); // add button html += '
    L.p.Indeks Nazwa StanJ.M. 
    ' + number + '' + value.code + '' + value.name + '' + value.stock_state + '' + value.unit_name + ''; html += ''; html += ''; html += '

    '; if (module_function != 'EcmStockDocOuts') { html += 'Cena:  '; } html += 'Ilość: '; if (index == false && single != false) { html += '

    '; } else if (index == false && single == false) { html += '

    '; } else { html += '

    '; } $('#searchResultDiv').html(html); if (single == false) CheckBoxSingleSelectGuard(); } else { html = 'Nie znaleziono produktów o szukanej nazwie!
    '; // add product // html += ''; $('#searchResultDiv').html(html); } } function CheckBoxSingleSelectGuard() { $('input[type="checkbox"]').on('change', function () { $('input[type="checkbox"]').not(this).prop('checked', false); }); } function unsetAllCheckboxes() { $("#searchResultDiv input[type=checkbox]").each(function () { $(this).prop("checked", false); }); } // search Empty record function searchEmpty() { for (var index in items) { if ($('#product_id_' + index).val() == '') { return index; } } } // usuwa rekord do wyszukiwania function clearEmpty() { for (var index in items) { if ($('#product_id_' + index).val() == '') { items.splice(index, 1); } } FillTable(items); } function getSearchInfo(product_id, product_code) { $("#search_info_div_" + product_id).show('slow'); var html = '' + product_code + '

    '; html += ''; var show_purchase_prices = false; if (show_purchase_prices) { html += ''; } html += '
    '; // get prices info var params = { job: 'getPricesInfo', product_id: product_id, pricebook_id: $("#pricebook_id :selected").val(), account_id: $("#parent_id").val(), }; $ .ajax({ type: "POST", url: ajaxsearch_url, dataType: "json", async: false, success: function (data) { html += 'Ceny'; $.each(data, function (key, value) { if (value.name == 'pricebook') html += ''; if (value.name == $("#ecmprice_name").val()) html += ''; else html += ''; }); html += '
    NazwaCena
    ' + $("#pricebook_id :selected").html() + '' + FormatNumber(value.price) + '
    ' + value.name + '' + FormatNumber(value.price) + '
    ' + value.name + '' + FormatNumber(value.price) + '
    '; }, data: params }); html += '
    '; var params = { job: 'getStockArray', product_id: product_id, }; $ .ajax({ type: "POST", url: ajaxsearch_url, dataType: "json", async: false, success: function (data) { html += 'Stany'; $.each(data, function (key, value) { html += ''; }); html += '
    MagazynIlość
    ' + key + '' + FormatNumber(value) + '
    '; }, data: params }); // struktura zapasu start html += '
    '; var params = { job: 'getStockProductDetails', record: product_id, stock_id: $("#stock_id").val(), }; $ .ajax({ type: "POST", url: ajaxsearch_url, dataType: "json", async: false, success: function (data) { html += 'Struktura zapasu'; $ .each( data, function (key, value) { html += ''; }); html += '
    DokumentIlośćCena
    ' + value.parent_name + '' + FormatNumber(value.quantity) + '' + FormatNumber(value.price) + '
    '; }, data: params }); // struktura zapasu end html += '
    '; var params = { job: 'getPurchaseArray', product_id: product_id, }; $.ajax({ type: "POST", url: ajaxsearch_url, dataType: "json", async: false, success: function (data) { console.log(data); }, data: params }); html += '
    '; $("#search_info_div_" + product_id).html(html); } function getFirstpartNumber(){ var params = { job: 'savePartNumber', }; $.ajax({ type: "POST", url: ajaxsearch_url, dataType: "json", async: false, success: function (data) { if (data != '-1'){ partCounter= data.value1; } }, data: params }); console.log(partCounter); } function getPartNumber(index){ var params = { job: 'savePartNumber', }; $.ajax({ type: "POST", url: ajaxsearch_url, dataType: "json", async: false, success: function (data) { if (data != '-1'){ currentPart=data; } }, data: params }); $('#consignments_div_'+index).find('#consignment_part_no').val(currentPart); $('#product_consignment_part_' + index).val(currentPart); items[index].product_consignment_part = currentPart; }