1119 lines
60 KiB
JavaScript
1119 lines
60 KiB
JavaScript
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, '<')
|
|
.replace(/>/g, '>');
|
|
}
|
|
function showdialog() {
|
|
|
|
$('#searchResultDiv').html('');
|
|
$(".loading_panel").css("display", "block");
|
|
var url = 'index.php?module=EcmProducts&action=QuickCreate2';
|
|
$('#searchResultDiv').
|
|
append('<iframe id="frameid" frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:1400px;width:100%;top:0px;left:0px;right:0px;bottom:0px" height="100%" width="100%"></iframe>');
|
|
|
|
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 += '<tr>';
|
|
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 += '<td style="background-color:'
|
|
+ color
|
|
+ ';"><input class="inputs" style="text-align: center;background-color:'
|
|
+ color
|
|
+ ';" type="text" id="number_'
|
|
+ row_index
|
|
+ '" name="number_'
|
|
+ row_index
|
|
+ '" readonly value="';
|
|
if (row.product_corrected == "true") {
|
|
html += 'było';
|
|
allReadOnly = 'y';
|
|
} else if (row.product_corrected == "false") {
|
|
html += pozycja;
|
|
pozycja++;
|
|
readonly = 'readonly';
|
|
allReadOnly = null;
|
|
} else {
|
|
html += +row_index + 1;
|
|
}
|
|
html += '"/></td>';
|
|
} else if (column.name == 'name') {
|
|
html += '<td style="background-color:'
|
|
+ color
|
|
+ ';"><div class="ui-widget"><input style="background-color:'
|
|
+ color
|
|
+ ';" class="inputs" type="text" oninput="SearchSingleProduct('
|
|
+ row_index
|
|
+ ');" onclick="$(this).select();" id="name_'
|
|
+ row_index
|
|
+ '" onChange="changeName(' + row_index + ')" name="name_'
|
|
+ row_index + '"';
|
|
if (allReadOnly)
|
|
html += ' readonly';
|
|
html += ' value="'
|
|
+ replaceCharters(row.name)
|
|
+ '"/></div><div class="ui-widget" style="margin-top:2em; font-family:Arial"></div><div style="color:red;" id="row_alert_'+row_index+'"></div></td>';
|
|
} else if (column.name == 'options') {
|
|
if (allReadOnly)
|
|
html += '<td style="background-color:'
|
|
+ color
|
|
+ ';"></tr>';
|
|
else {
|
|
html += '<td style="background-color:'
|
|
+ color + ';">';
|
|
// move up
|
|
html += '<a onClick="moveUpRow('
|
|
+ row_index
|
|
+ ')" target="_blank"><img style="cursor:pointer;" src="modules/EcmSales/images/moverowup.gif"/></a>';
|
|
html += ' ';
|
|
// move down
|
|
html += '<a onClick="moveDownRow('
|
|
+ row_index
|
|
+ ')" target="_blank"><img style="cursor:pointer;" src="modules/EcmSales/images/moverowdown.gif"/></a>';
|
|
html += '<br>';
|
|
// delete row
|
|
html += '<a onClick="deleteRow('
|
|
+ row_index
|
|
+ ')" target="_blank"><img style="cursor:pointer;" src="modules/EcmSales/images/deleterow.gif"/></a>';
|
|
html += '</td>';
|
|
}
|
|
}
|
|
// other types
|
|
else {
|
|
if (column.hide == 'yes')
|
|
hide = ' style="display: none;background-color:'
|
|
+ color + ';"';
|
|
else
|
|
hide = 'style="background-color:'
|
|
+ color + ';"';
|
|
html += '<td ' + hide + ' >';
|
|
$
|
|
.each(
|
|
column.content,
|
|
function (
|
|
cell_index,
|
|
cell) {
|
|
var cellname = column.name
|
|
+ cell.name;
|
|
|
|
if (cellname == 'product_link') {
|
|
html += '<a id="product_link_' + row_index + '" href="index.php?module=EcmProducts&action=DetailView&record='
|
|
+ row.product_id
|
|
+ '" target="_blank">'
|
|
+ row.product_code
|
|
+ '</a><br>';
|
|
} else if (cellname == 'price_purchase') {
|
|
html += '<input class="inputs" type="text"'
|
|
+ ' name="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '" id="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '" onClick="$(this).select();" onChange="$(this).val(FormatNumber($(this).val(),2))" value="'+FormatNumber(row.price_purchase,2)+'" style="text-align: right;background-color:#ffffff;" readonly="readonly">';
|
|
if(row.product_category_id=='bf900339-6c7b-f278-2737-542023796730' || row.product_ks_group=='3'){
|
|
html += ' <img style="cursor: pointer" id="price_purchase_edit_'+row_index+'" onclick="modPrice('+"'"+row_index+"'"+')" src="themes/Sugar5/images/edit_inline.gif" align="right">';
|
|
html += ' <input type="button" value="Zapisz" id="price_purchase_save_'+row_index+'" style="display:none;" onclick="savePrice('+"'"+row_index+"'"+')">';
|
|
}
|
|
|
|
}else if (cellname == 'price_start_div'
|
|
&& !allReadOnly) {
|
|
html += '<br><img style="cursor: pointer;" src="modules/EcmSales/images/search.gif" onClick="if ($(\'#price_start_div_'
|
|
+ row_index
|
|
+ '\').css(\'display\')==\'none\') getPricesInfo('
|
|
+ row_index
|
|
+ '); else $(\'#price_start_div_'
|
|
+ row_index
|
|
+ '\').hide(\'slow\')"/>';
|
|
html += '<div id="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '" style="display:none;float:right;text-align:right;border: 1px #cccccc solid;padding:3px;"></div>';
|
|
}else if (cellname == 'unit_div'
|
|
&& !allReadOnly) {
|
|
html += '<br><img style="cursor: pointer;" src="modules/EcmSales/images/edit_position.gif" onClick="if ($(\'#unit_div_'
|
|
+ row_index
|
|
+ '\').css(\'display\')==\'none\') getUnitInfo('
|
|
+ row_index
|
|
+ '); else $(\'#unit_div_'
|
|
+ row_index
|
|
+ '\').hide(\'slow\')"/>';
|
|
html += '<div id="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '" style="display:none;float:right;text-align:right;border: 1px #cccccc solid;padding:3px;"></div>';
|
|
}else if (cellname == 'ecmvat_div'
|
|
&& !allReadOnly) {
|
|
html += '<br><img style="cursor: pointer;" src="modules/EcmSales/images/edit_position.gif" onClick="if ($(\'#ecmvat_div_'
|
|
+ row_index
|
|
+ '\').css(\'display\')==\'none\') getVatInfo('
|
|
+ row_index
|
|
+ '); else $(\'#ecmvat_div_'
|
|
+ row_index
|
|
+ '\').hide(\'slow\')"/>';
|
|
html += '<div id="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '" style="display:none;float:right;text-align:right;border: 1px #cccccc solid;padding:3px;"></div>';
|
|
} else if (cellname == 'quantity') {
|
|
|
|
if (cell.label
|
|
&& cell.label != '')
|
|
html += '<p>'
|
|
+ cell.label
|
|
+ '</p>';
|
|
html += '<input class="inputs" type="'
|
|
+ cell.type
|
|
+ '" name="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '" id="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '"';
|
|
if (cell.readonly
|
|
|| allReadOnly)
|
|
html += ' readonly ';
|
|
var check=$('#refresh_positions').val();
|
|
if(check!==undefined){
|
|
if(check=='1'){
|
|
if(row.product_ks_group!='3'){
|
|
html += ' readonly ';
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if (column.align)
|
|
html += ' style="text-align: '
|
|
+ column.align
|
|
+ ';background-color:'
|
|
+ color
|
|
+ ';"';
|
|
if (cell.onChange
|
|
|| cell.isNumber)
|
|
html += ' onChange="$(this).val(FormatNumber2($(this).val(),'
|
|
+ row.unit_precision
|
|
+ '));'
|
|
+ cell.onChange
|
|
+ '" onClick="$(this).select();"';
|
|
else if (cell.onChange
|
|
|| !cell.isNumber)
|
|
html += ' onChange="'
|
|
+ cell.onChange
|
|
+ '" ';
|
|
if (row[cellname]
|
|
&& cell.isNumber)
|
|
html += ' value="'
|
|
+ FormatNumber2(row[cellname], row.unit_precision)
|
|
+ '" ';
|
|
else if (row[cellname])
|
|
html += ' value="'
|
|
+ FormatNumber2(row[cellname], row.unit_precision)
|
|
+ '" ';
|
|
else {
|
|
if (cell.isNumber)
|
|
html += ' value="0,00" ';
|
|
else
|
|
html += ' value="" ';
|
|
}
|
|
html += '>';
|
|
if (row['quantity_used'] != '' && row['quantity_used'] != null) {
|
|
html += '<br><p style="text-align:right;"><b>(' + row['quantity_used'] + ')</b></p>';
|
|
}
|
|
}else if (cellname == 'stock_state') {
|
|
|
|
if (cell.label
|
|
&& cell.label != '')
|
|
html += '<p>'
|
|
+ cell.label
|
|
+ '</p>';
|
|
html += '<input class="inputs" type="'
|
|
+ cell.type
|
|
+ '" name="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '" id="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '"';
|
|
if (cell.readonly
|
|
|| allReadOnly)
|
|
html += ' readonly ';
|
|
if (column.align)
|
|
html += ' style="text-align: '
|
|
+ column.align
|
|
+ ';background-color:'
|
|
+ color
|
|
+ ';"';
|
|
if (cell.onChange
|
|
|| cell.isNumber)
|
|
html += ' onChange="$(this).val(FormatNumber($(this).val(),'
|
|
+ row.unit_precision
|
|
+ '));'
|
|
+ cell.onChange
|
|
+ '" onClick="$(this).select();"';
|
|
else if (cell.onChange
|
|
|| !cell.isNumber)
|
|
html += ' onChange="'
|
|
+ cell.onChange
|
|
+ '" ';
|
|
if (row[cellname]
|
|
&& cell.isNumber)
|
|
html += ' value="'
|
|
+ FormatNumber(row[cellname], row.unit_precision)
|
|
+ '" ';
|
|
else if (row[cellname])
|
|
html += ' value="'
|
|
+ FormatNumber(row[cellname], row.unit_precision)
|
|
+ '" ';
|
|
else {
|
|
if (cell.isNumber)
|
|
html += ' value="0,00" ';
|
|
else
|
|
html += ' value="" ';
|
|
}
|
|
html += '>';
|
|
if (row['quantity_used'] != '' && row['quantity_used'] != null) {
|
|
html += '<br><p style="text-align:right;"><b>(' + row['quantity_used'] + ')</b></p>';
|
|
}
|
|
} else {
|
|
|
|
if (cell.label
|
|
&& cell.label != '')
|
|
html += '<p>'
|
|
+ cell.label
|
|
+ '</p>';
|
|
html += '<input class="inputs" type="'
|
|
+ cell.type
|
|
+ '" name="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '" id="'
|
|
+ cellname
|
|
+ '_'
|
|
+ row_index
|
|
+ '"';
|
|
if (cell.readonly
|
|
|| allReadOnly)
|
|
html += ' readonly ';
|
|
if (column.align)
|
|
html += ' style="text-align: '
|
|
+ column.align
|
|
+ ';background-color:'
|
|
+ color
|
|
+ ';"';
|
|
if (cell.onChange
|
|
|| cell.isNumber)
|
|
html += ' onChange="$(this).val(FormatNumber($(this).val()));'
|
|
+ cell.onChange
|
|
+ '" onClick="$(this).select();"';
|
|
else if (cell.onChange
|
|
|| !cell.isNumber)
|
|
html += ' onChange="'
|
|
+ cell.onChange
|
|
+ '" ';
|
|
if (row[cellname]
|
|
&& cell.isNumber)
|
|
html += ' value="'
|
|
+ FormatNumber(row[cellname])
|
|
+ '" ';
|
|
else if (row[cellname])
|
|
html += ' value="'
|
|
+ row[cellname]
|
|
+ '" ';
|
|
else {
|
|
if (cell.isNumber)
|
|
html += ' value="0,00" ';
|
|
else
|
|
html += ' value="" ';
|
|
}
|
|
html += '>';
|
|
}
|
|
});
|
|
html += '</td>';
|
|
}
|
|
|
|
});
|
|
html += '</tr>';
|
|
|
|
});
|
|
$('#' + itemsTable + '_T > 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+='<li value="'+value.id+'">'+value.name+'</li>'; });
|
|
* $('#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 $("<li></li>").data("item.autocomplete", item).append(
|
|
$("<a></a>").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(
|
|
'<img src="modules/EcmSales/images/loading.gif"/>');
|
|
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(
|
|
'<img src="modules/EcmSales/images/loading.gif"/>');
|
|
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 = '<button id="listViewStartButton" class="button"'
|
|
+ disabled + ' onclick="' + onclick
|
|
+ '" title="Początek" name="listViewStartButton" type="button">';
|
|
firstbutton += '<img border="0" align="absmiddle" alt="Początek" src="themes/Sugar5/images/'
|
|
+ img + '">';
|
|
firstbutton += '</button>';
|
|
|
|
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 = '<button id="listViewStartButton" class="button" ' + disabled
|
|
+ ' title="Poprzedni" onclick="' + onclick
|
|
+ '" name="listViewStartButton" type="button">';
|
|
prev += '<img border="0" align="absmiddle" alt="Poprzedni" src="themes/Sugar5/images/'
|
|
+ img + '">';
|
|
prev += '</button>';
|
|
|
|
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 = '<button '
|
|
+ disabled
|
|
+ ' onclick="'
|
|
+ onclick
|
|
+ '" class="button" title="Nastęny" name="listViewNextButton" id="listViewNextButton" type="button">';
|
|
next += '<img border="0" align="absmiddle" alt="Nastęny" src="themes/Sugar5/images/'
|
|
+ img + '">';
|
|
next += '</button>';
|
|
|
|
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 = '<button id="listViewStartButton" class="button"'
|
|
+ disabled + ' onclick="' + onclick
|
|
+ '" title="Początek" name="listViewStartButton" type="button">';
|
|
lastbutton += '<img border="0" align="absmiddle" alt="Ostatni" src="themes/Sugar5/images/'
|
|
+ img + '">';
|
|
lastbutton += '</button>';
|
|
|
|
var action = "$('#searchStart').val($('#gotoPage option:selected').val());searchProducts();";
|
|
var select = '<select id="gotoPage" name="gotoPage" onChange="' + action
|
|
+ '">';
|
|
var current_page = parseInt($('#searchStart').val()) / 50 + 1;
|
|
var total_pages = Math.ceil(parseInt(data.count) / 50);
|
|
var strona = 1;
|
|
for (var i = 1; i <= data.count; i = i + 50) {
|
|
var val = i - 1;
|
|
if (current_page == strona) {
|
|
var selected = 'selected="selected"';
|
|
} else {
|
|
var selected = '';
|
|
}
|
|
select += '<option value="' + val + '" ' + selected + '>' + strona
|
|
+ '</option>';
|
|
strona = strona + 1;
|
|
}
|
|
select += '</select>';
|
|
|
|
var close = '<button id="listViewStartButton" onclick="$(\'#searchResultDiv\').html(\'\');" title="Zamknij" name="listViewStartButton" type="button">';
|
|
close += '<img border="0" align="absmiddle" alt="Zamknij" src="themes/Sugar5/images/close.gif">';
|
|
close += '</button>';
|
|
|
|
var html = '<table style="width: 100%;"><tr><td style="width: 50%;">Znaleziono '
|
|
+ data.count + ' produktów</td>';
|
|
var page = 'Strona ' + current_page + ' z ' + total_pages;
|
|
html += '<td style="vertical-align: right;width: 50%;text-align: right;">'
|
|
+ firstbutton + ' ' + prev + ' ' + select + ' ' + next + ' '
|
|
+ lastbutton + ' ' + page + ' ' + close + '</td></tr></table>';
|
|
|
|
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
|
|
+ '<table style="text-align: center;" cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">';
|
|
html += '<theader><tr>';
|
|
if (number_show == true)
|
|
html += '<th style="width: 15pt; text-align: right;">L.p.</th>';
|
|
// jeśli wyszukujesz z tabelki blokuje zaznaczanie wielu
|
|
if (single != false) {
|
|
disabled = '';
|
|
} else {
|
|
disabled = 'disabled="disabled"';
|
|
}
|
|
html += '<th style="width: 10pt; margin: auto auto;text-align: center;"><input id="checkAll" type="checkbox" onClick="SelectDeselectChb();" '
|
|
+ disabled + '/></th>';
|
|
|
|
html += '<th style="width: 100pt; text-align: left;"><a class="listViewThLinkS1" onClick="toggleSort(1,2);searchProducts();">Indeks <img id="indeximg" src="'
|
|
+ img.indeximg + '"></a></th>';
|
|
html += '<th style="width: 300pt; text-align: left;"><a class="listViewThLinkS1" onClick="toggleSort(3,4);searchProducts();">Nazwa <img id="indeximg" src="'
|
|
+ img.nameimg + '"></a></th>';
|
|
if ($("#productSearchStock :selected").val() != '1')
|
|
html += '<th style="width: 30pt; text-align: right;">Stan</th>';
|
|
if (unit_show == true)
|
|
html += '<th style="width: 30pt; text-align: right;">J.M.</th>';
|
|
if (extraproductinfo_show == true)
|
|
html += '<th style="width: 15pt; margin: auto auto;"> </th>';
|
|
html += '</tr></thead>';
|
|
// 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 += '<tr style="height: 15pt;" class="oddListRowS1">';
|
|
} else {
|
|
html += '<tr style="height: 15pt;" class="evenListRowS1">';
|
|
}
|
|
if (number_show == true)
|
|
html += '<td style="text-align: right;">'
|
|
+ number + '</td>';
|
|
html += '<td style=""><input id="prod_'
|
|
+ value.id
|
|
+ '" type="checkbox"/ class="tf" name="checkbox_group[]"></td>';
|
|
html += '<td style="text-align: left;" onClick="$(\'#prod_'
|
|
+ value.id
|
|
+ '\').prop(\'checked\', true);">'
|
|
+ value.code + '</td>';
|
|
html += '<td style="text-align: left;" onClick="unsetAllCheckboxes(); $(\'#prod_'
|
|
+ value.id
|
|
+ '\').prop(\'checked\', true);'
|
|
+ action + '">' + value.name + '</td>';
|
|
if ($("#productSearchStock :selected").val() != '1')
|
|
html += '<td style="text-align: right;">'
|
|
+ value.stock_state + '</td>';
|
|
if (unit_show == true)
|
|
html += '<td style="text-align: right;">'
|
|
+ value.unit_name + '</td>';
|
|
if (extraproductinfo_show == true) {
|
|
html += '<td style="">';
|
|
html += '<img style="cursor: pointer;" src="modules/EcmSales/images/search.gif" onClick="if ($(\'#search_info_div_'
|
|
+ value.id
|
|
+ '\').css(\'display\')==\'none\') getSearchInfo(\''
|
|
+ value.id
|
|
+ '\',\''
|
|
+ value.code
|
|
+ '\'); else $(\'#search_info_div_'
|
|
+ value.id + '\').hide(\'slow\')"/>';
|
|
html += '<div id="'
|
|
+ 'search_info_div_'
|
|
+ value.id
|
|
+ '" style="display:none;float:right;text-align:right;border: 1px #cccccc solid;padding:3px;"></div>';
|
|
html += '</td>';
|
|
}
|
|
html += '</tr>';
|
|
searchedProducts.push(value.id);
|
|
counter++;
|
|
number++;
|
|
});
|
|
// add button
|
|
html += '</table><br>';
|
|
if (module_function != 'EcmStockDocOuts') {
|
|
html += 'Cena: <input type="text" id="searchInputPrice" onchange="$(this).val(FormatNumber($(this).val()));" onclick="$(this).select();" value=""/> ';
|
|
}
|
|
html += 'Ilość: <input type="text" id="searchInputQty" onchange="$(this).val(FormatNumber($(this).val(),0));" onclick="$(this).select();" value=""/>';
|
|
if (index == false && single != false) {
|
|
html += '<br><br><input type="button" value="Dodaj wiele" onClick="return addProducts();"/>';
|
|
} else if (index == false && single == false) {
|
|
html += '<br><br><input type="button" value="Dodaj jeden" onClick="return addProducts();"/>';
|
|
} else {
|
|
html += '<br><br><input type="button" value="Zamień" onClick="return replaceProduct('
|
|
+ index + ');"/>';
|
|
}
|
|
$('#searchResultDiv').html(html);
|
|
if (single == false)
|
|
CheckBoxSingleSelectGuard();
|
|
} else {
|
|
html = 'Nie znaleziono produktów o szukanej nazwie!<br>';
|
|
// add product
|
|
// html += '<input type="button" onclick="showdialog();" value="Dodaj produkt"/>';
|
|
$('#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 = '<a href="index.php?module=EcmProducts&action=DetailView&record='
|
|
+ product_id + '" target="_blank">' + product_code + '</a><br><br>';
|
|
html += '<table><tr><td><table><tr><td>';
|
|
// 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<table><tr><td style="text-align: left;">Nazwa</td><td>Cena</td></tr>';
|
|
$.each(data, function (key, value) {
|
|
if (value.name == 'pricebook')
|
|
html += '<tr><td style="text-align: left;">'
|
|
+ $("#pricebook_id :selected").html()
|
|
+ '</td><td style="text-align:right;">'
|
|
+ FormatNumber(value.price) + '</td></tr>';
|
|
if (value.name == $("#ecmprice_name").val())
|
|
html += '<tr><td style="text-align: left;">'
|
|
+ value.name
|
|
+ '</td><td style="text-align:right;">'
|
|
+ FormatNumber(value.price) + '</td></tr>';
|
|
else
|
|
html += '<tr><td style="text-align: left;">'
|
|
+ value.name
|
|
+ '</td><td style="text-align:right;">'
|
|
+ FormatNumber(value.price) + '</td></tr>';
|
|
});
|
|
html += '</table>';
|
|
},
|
|
data: params
|
|
});
|
|
html += '</td></tr></table></td><td><table><tr><td>';
|
|
var params = {
|
|
job: 'getStockArray',
|
|
product_id: product_id,
|
|
};
|
|
$
|
|
.ajax({
|
|
type: "POST",
|
|
url: ajaxsearch_url,
|
|
dataType: "json",
|
|
async: false,
|
|
success: function (data) {
|
|
html += 'Stany<table><tr><td style="text-align: left;">Magazyn</td><td>Ilość</td></tr>';
|
|
$.each(data, function (key, value) {
|
|
html += '<tr><td style="text-align: left;">' + key
|
|
+ '</td><td style="text-align: right;">'
|
|
+ FormatNumber(value) + '</td></tr>';
|
|
});
|
|
html += '</table>';
|
|
},
|
|
data: params
|
|
});
|
|
// struktura zapasu start
|
|
html += '</td></tr></table></td><td><table><tr><td>';
|
|
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<table><tr><td style="text-align: left;">Dokument</td><td style="text-align: right;">Ilość</td><td style="text-align: right;">Cena</td></tr>';
|
|
$
|
|
.each(
|
|
data,
|
|
function (key, value) {
|
|
html += '<tr><td style="text-align: left;"><a href="index.php?module='
|
|
+ value.parent_type
|
|
+ '&action=DetailView&record='
|
|
+ value.parent_id
|
|
+ '">'
|
|
+ value.parent_name
|
|
+ '</a></td><td style="text-align:right;">'
|
|
+ FormatNumber(value.quantity)
|
|
+ '</td><td style="text-align:right;">'
|
|
+ FormatNumber(value.price)
|
|
+ '</td></tr>';
|
|
});
|
|
html += '</table>';
|
|
},
|
|
data: params
|
|
});
|
|
// struktura zapasu end
|
|
html += '</td></tr></table></td>';
|
|
var show_purchase_prices = false;
|
|
|
|
if (show_purchase_prices) {
|
|
html += '<td><table><tr><td>';
|
|
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 += '</td></tr></table></td>';
|
|
}
|
|
|
|
html += '</tr></table>';
|
|
|
|
$("#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;
|
|
|
|
}
|