init
This commit is contained in:
104
modules/EcmReturns/javascript/EcmReturns.js
Normal file
104
modules/EcmReturns/javascript/EcmReturns.js
Normal file
@@ -0,0 +1,104 @@
|
||||
//START:
|
||||
$(document).ready(
|
||||
function() {
|
||||
// confirm exit
|
||||
window.onbeforeunload = confirmExit;
|
||||
// prevent submit by enter press
|
||||
lockEnter();
|
||||
// parent info
|
||||
$("#parent_name").change(
|
||||
function() {
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function() {
|
||||
getParentInfo($("#parent_id").val(), $(
|
||||
"#parent_type :selected").val());
|
||||
}, 1000);
|
||||
});
|
||||
// categories
|
||||
getCategoriesList();
|
||||
// type change
|
||||
$("#type").change(function() {
|
||||
// calculate totals
|
||||
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 -
|
||||
// thead row
|
||||
for (var index = 0; index != count; index++)
|
||||
calculateRow(index);
|
||||
});
|
||||
// searchProductInput change
|
||||
$('#searchProductsInput').keyup(function() {
|
||||
searchProducts();
|
||||
});
|
||||
DrawHeaders();
|
||||
|
||||
$("#register_date").prop("disabled", true);
|
||||
$("#assigned_user_name").prop("disabled", true);
|
||||
$("#register_date_trigger").hide();
|
||||
$("#btn_assigned_user_name").hide();
|
||||
$("#btn_clr_assigned_user_name").hide();
|
||||
|
||||
if (($("#new_number").val() == true)
|
||||
&& ($("#duplicate").val() != true)) {
|
||||
generateNumber();
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#duplicate").val() == true)) {
|
||||
generateNumber();
|
||||
getParentInfo($("#parent_id").val(),
|
||||
$("#parent_type :selected").val());
|
||||
getItems();
|
||||
} else {
|
||||
getParentInfo($("#parent_id").val(),
|
||||
$("#parent_type :selected").val());
|
||||
getItems();
|
||||
}
|
||||
// handle setItems
|
||||
setITEMS = function() {
|
||||
var formname = 'EditView';
|
||||
if (check_form_(formname) == true) {
|
||||
SetTab('ITEMS');
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
// handle save
|
||||
var check_form_ = check_form;
|
||||
check_form = function(formname) {
|
||||
window.onbeforeunload = null;
|
||||
if (items.length == 0) {
|
||||
alert("Brak produktów");
|
||||
return false;
|
||||
}
|
||||
$(".loading_panel").css("display", "block");
|
||||
$("#register_date").prop("disabled", false);
|
||||
$("#assigned_user_name").prop("disabled", false);
|
||||
// calculate totals
|
||||
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||||
for (var index = 0; index != count; index++)
|
||||
calculateRow(index);
|
||||
|
||||
$("#position_list").val(JSON.stringifyNoSecurity(items));
|
||||
|
||||
var check = checkProducts();
|
||||
|
||||
if (check_form_(formname) == false || check == false) {
|
||||
$("#register_date").prop("disabled", true);
|
||||
$("#assigned_user_name").prop("disabled", true);
|
||||
window.onbeforeunload = confirmExit;
|
||||
$(".loading_panel").css("display", "none");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
function confirmExit() {
|
||||
return "";
|
||||
}
|
||||
|
||||
function lockEnter() {
|
||||
// prevent default
|
||||
$(window).keydown(function(event) {
|
||||
if (event.keyCode == 13 && $(":focus").prop('tagName')!='TEXTAREA') {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
7
modules/EcmReturns/javascript/EcmReturnsDetail.js
Normal file
7
modules/EcmReturns/javascript/EcmReturnsDetail.js
Normal file
@@ -0,0 +1,7 @@
|
||||
//START:
|
||||
$(document).ready(
|
||||
function() {
|
||||
DrawHeaders();
|
||||
getItems(false);
|
||||
});
|
||||
|
||||
829
modules/EcmReturns/javascript/bimit_table.js
Normal file
829
modules/EcmReturns/javascript/bimit_table.js
Normal file
@@ -0,0 +1,829 @@
|
||||
var ajax_url = "index.php?module=EcmReturns&action=javahelper&to_pdf=1";
|
||||
var itemsTable = 'itemsTable';
|
||||
var items = new Array();
|
||||
var displayArray = new Array();
|
||||
var searchedProducts = new Array();
|
||||
|
||||
function FillTable(data, allReadOnly) {
|
||||
html = '';
|
||||
// loop throw data rows
|
||||
$
|
||||
.each(
|
||||
data,
|
||||
function(row_index, row) {
|
||||
html += '<tr>';
|
||||
// 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><input class="inputs" style="text-align: center;" type="text" id="number_'
|
||||
+ row_index
|
||||
+ '" name="number_'
|
||||
+ row_index
|
||||
+ '" readonly value="'
|
||||
+ (row_index + 1)
|
||||
+ '"/></td>';
|
||||
} else if (column.name == 'name') {
|
||||
html += '<td><textarea style="width: 100%; height: 100%;" id="name_'
|
||||
+ row_index
|
||||
+ '" name="name_'
|
||||
+ row_index + '"';
|
||||
if (allReadOnly)
|
||||
html += ' readonly';
|
||||
html += '>' + row.name
|
||||
+ '</textarea></td>';
|
||||
} else if (column.name == 'options') {
|
||||
if (allReadOnly)
|
||||
html += '<td></tr>';
|
||||
else {
|
||||
html += '<td>';
|
||||
// move up
|
||||
html += '<a onClick="moveUpRow('
|
||||
+ row_index
|
||||
+ ')" target="_blank"><img style="cursor:pointer;" src="modules/EcmReturns/images/moverowup.gif"/></a>';
|
||||
html += ' ';
|
||||
// move down
|
||||
html += '<a onClick="moveDownRow('
|
||||
+ row_index
|
||||
+ ')" target="_blank"><img style="cursor:pointer;" src="modules/EcmReturns/images/moverowdown.gif"/></a>';
|
||||
html += '<br>';
|
||||
// delete row
|
||||
html += '<a onClick="deleteRow('
|
||||
+ row_index
|
||||
+ ')" target="_blank"><img style="cursor:pointer;" src="modules/EcmReturns/images/deleterow.gif"/></a>';
|
||||
html += '</td>';
|
||||
}
|
||||
}
|
||||
// other types
|
||||
else {
|
||||
html += '<td>';
|
||||
$
|
||||
.each(
|
||||
column.content,
|
||||
function(
|
||||
cell_index,
|
||||
cell) {
|
||||
var cellname = column.name
|
||||
+ cell.name;
|
||||
if (cellname == 'product_link') {
|
||||
html += '<a href="index.php?module=EcmProducts&action=DetailView&record='
|
||||
+ row.product_id
|
||||
+ '" target="_blank">'
|
||||
+ row.product_code
|
||||
+ '</a>';
|
||||
} else if (cellname == 'price_start_div'
|
||||
&& !allReadOnly) {
|
||||
html += '<br><img style="cursor: pointer;" src="modules/EcmReturns/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 (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
|
||||
+ ';"';
|
||||
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) {
|
||||
// calculate totals
|
||||
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||||
for (var index = 0; index != count; index++)
|
||||
calculateRow(index);
|
||||
} else {
|
||||
if ($("#type").val() == '0') {
|
||||
$("input[name^=price_start]").css("color", "red");
|
||||
$("input[name^=total_netto]").css("color", "red");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calculateRow(index) {
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
// liczone według najlepszych zasad księgowości
|
||||
var price_start = UnformatNumber($('#price_start_' + index).val());
|
||||
|
||||
var quantity = UnformatNumber($('#quantity_' + index).val());
|
||||
var price_netto = 0;
|
||||
|
||||
price_netto = price_start;
|
||||
|
||||
var total_netto = price_netto * quantity;
|
||||
|
||||
// put data
|
||||
$('#price_netto_' + index).val(FormatNumber(price_netto));
|
||||
$('#total_netto_' + index).val(FormatNumber(total_netto));
|
||||
|
||||
// put data to items array
|
||||
items[index].price_start = toFixed(price_start, 2);
|
||||
items[index].price_netto = toFixed(price_netto, 2);
|
||||
items[index].total_netto = toFixed(total_netto, 2);
|
||||
items[index].quantity = toFixed(quantity, 2);
|
||||
|
||||
// put other data
|
||||
items[index].recipient_code = $('#recipient_code_' + index).val();
|
||||
items[index].remarks = $('#remarks_' + index).val();
|
||||
// change name or language?
|
||||
items[index].name = $('#name_' + index).val();
|
||||
items[index].unit_name = $('#unit_name_' + index).val();
|
||||
|
||||
if ($("#type").val() == '0') {
|
||||
$("#price_start_" + index).prop("disabled", true);
|
||||
$("#price_start_" + index).css("color", "red");
|
||||
$("#total_netto_" + index).css("color", "red");
|
||||
} else {
|
||||
$("#price_start_" + index).prop("disabled", false);
|
||||
$("#price_start_" + index).css("color", "black");
|
||||
$("#total_netto_" + index).css("color", "black");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 FormatNumber(number, precision) {
|
||||
var precision = precision || 2;
|
||||
// make string..
|
||||
number = number + '';
|
||||
number = number.replace(',', '.');
|
||||
// round
|
||||
number = toFixed(number, precision);
|
||||
// add 1000 sep
|
||||
var tmp = number.split(".");
|
||||
var c = '';
|
||||
for (var i = tmp[0].length; i != -1; i--) {
|
||||
c += tmp[0].charAt(i);
|
||||
if ((tmp[0].length - i) == 0 || i == 0)
|
||||
continue;
|
||||
if ((tmp[0].length - i) % 3 == 0)
|
||||
c += '.';
|
||||
}
|
||||
// reverse c
|
||||
c = c.split("").reverse().join("");
|
||||
|
||||
return c + ',' + tmp[1];
|
||||
}
|
||||
|
||||
function UnformatNumber(number) {
|
||||
// make string..
|
||||
number = number + '';
|
||||
// remove 1000 sep
|
||||
number = number.replace('.', '');
|
||||
// change ',' to '.'
|
||||
number = number.replace(',', '.');
|
||||
|
||||
return parseFloat(number);
|
||||
}
|
||||
|
||||
// round with precision
|
||||
function toFixed(value, precision) {
|
||||
var precision = precision || 0, neg = value < 0, power = Math.pow(10,
|
||||
precision), value = Math.round(value * power), integral = String((neg ? Math.ceil
|
||||
: Math.floor)(value / power)), fraction = String((neg ? -value
|
||||
: value)
|
||||
% power), padding = new Array(Math.max(precision - fraction.length,
|
||||
0) + 1).join('0');
|
||||
|
||||
return precision ? integral + '.' + padding + fraction : integral;
|
||||
}
|
||||
|
||||
// draw table
|
||||
function DrawHeaders() {
|
||||
var html = '<link rel="stylesheet" type="text/css" href="modules/EcmReturns/MyTable.css" />';
|
||||
html += '<div style="width:100%;border: 1px solid rgb(48,192,255);background-color:white;height: 250px;overflow:auto;" id="'
|
||||
+ itemsTable + 'DIV">';
|
||||
html += '<table class="positions" style="width:100%;" id="' + itemsTable
|
||||
+ '_T">';
|
||||
html += '<thead id="head">';
|
||||
html += '<tr id="tr">';
|
||||
// draw columns headers
|
||||
$.each(columns, function(index, column) {
|
||||
html += '<td width="' + column.width + '%">' + column.label + '</td>';
|
||||
});
|
||||
html += '</tr></thead><tbody></tbody></table>';
|
||||
html += '</div><br>';
|
||||
// totals table
|
||||
html += '<table width="100%"" cellpadding="0" cellspacing="0" border="0">';
|
||||
html += '<tr>';
|
||||
html += '<td width="55%" class="dataLabel" valign="top">';
|
||||
html += ' ';
|
||||
html += '</td> <!--color:#b3b9cf;-->';
|
||||
html += '<td width="40%" class="dataField" style="text-align: left;">';
|
||||
html += '<br>';
|
||||
html += '<table id="result_table" cellpadding="0" cellspacing="0" style="width:100%; height:100%; border: 1px solid rgb(48,192,255);">';
|
||||
html += '</table>';
|
||||
html += '</td>';
|
||||
html += '<td width="5%" class="dataField" style="text-align: left;"> </td>';
|
||||
html += '</tr>';
|
||||
html += '</table>';
|
||||
// sort? why not!
|
||||
/*
|
||||
* html += 'Sortowanie: '; html += '<select id="sort_field"
|
||||
* onChange="sortTable();"'; html += '<option value=""></option>'; html += '<option
|
||||
* value="name">Nazwa</option>'; html += '<option value="code">Kod</option>';
|
||||
* html += '<option value="category">Kategoria</option>'; html += '<option
|
||||
* value="category">Kategoria</option>'; html += '<option
|
||||
* value="price">Cena po<br>upuście</option>'; html += '<option
|
||||
* value="total">Wartość</option>'; html += '</select>';
|
||||
*/
|
||||
$('#' + itemsTable).html(html);
|
||||
}
|
||||
function searchProducts() {
|
||||
var searchKey = $('#searchProductsInput').val();
|
||||
if (searchKey.length < 2 && searchKey != '%') {
|
||||
return;
|
||||
}
|
||||
$("#searchResultDiv").html(
|
||||
'<img src="modules/EcmReturns/images/loading.gif"/>');
|
||||
setTimeout(function() {
|
||||
if (searchKey == $('#searchProductsInput').val()) {
|
||||
var params = {
|
||||
job : 'searchProducts',
|
||||
searchKey : searchKey,
|
||||
searchCategory : $("#productSearchCategory :selected").val(),
|
||||
searchStock : $("#productSearchStock :selected").val(),
|
||||
searchSort : $("#productSearchSort :selected").val(),
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : ajax_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 createSearchResult(data) {
|
||||
var html = '<table style="border: 0.5px dashed black; border-collapse: collapse; text-align: center;">';
|
||||
html += '<theader><tr>';
|
||||
html += '<th style="border: 0.5px dashed black; width: 15pt; margin: auto auto;"> </th>';
|
||||
html += '<th style="border: 0.5px dashed black; width: 100pt; text-align: center;">Kod</th>';
|
||||
html += '<th style="border: 0.5px dashed black; width: 300pt; text-align: center;">Nazwa</th>';
|
||||
if ($("#productSearchStock :selected").val() != '1')
|
||||
html += '<th style="border: 0.5px dashed black; width: 30pt; text-align: center;">Stan</th>';
|
||||
html += '<th style="border: 0.5px dashed black; width: 15pt; margin: auto auto;"> </th>';
|
||||
|
||||
html += '</tr></thead>';
|
||||
|
||||
$
|
||||
.each(
|
||||
data,
|
||||
function(index, value) {
|
||||
html += '<tr style="height: 15pt;">';
|
||||
html += '<td style="border: 0.5px dashed black;"><input id="prod_'
|
||||
+ value.id + '" type="checkbox"/></td>';
|
||||
html += '<td style="border: 0.5px dashed black;" onClick="$(\'#prod_'
|
||||
+ value.id
|
||||
+ '\').prop(\'checked\', true);">'
|
||||
+ value.code + '</td>';
|
||||
html += '<td style="border: 0.5px dashed black;" onClick="unsetAllCheckboxes(); $(\'#prod_'
|
||||
+ value.id
|
||||
+ '\').prop(\'checked\', true); return addProducts();">'
|
||||
+ value.name + '</td>';
|
||||
if ($("#productSearchStock :selected").val() != '1')
|
||||
html += '<td style="border: 0.5px dashed black;">'
|
||||
+ value.stock_state + '</td>';
|
||||
html += '<td style="border: 0.5px dashed black;">';
|
||||
html += '<img style="cursor: pointer;" src="modules/EcmReturns/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);
|
||||
});
|
||||
// add button
|
||||
html += '</table><br>';
|
||||
html += 'Cena: <input type="text" id="searchInputPrice" value=""/> Ilość: <input type="text" id="searchInputQty" value=""/>';
|
||||
html += '<br><br><input type="button" value="Dodaj wiele" onClick="return addProducts();"/>';
|
||||
$('#searchResultDiv').html(html);
|
||||
}
|
||||
|
||||
function unsetAllCheckboxes() {
|
||||
$("#searchResultDiv input[type=checkbox]").each(function() {
|
||||
$(this).prop("checked", false);
|
||||
});
|
||||
}
|
||||
|
||||
function addProducts() {
|
||||
$(".loading_panel").css("display", "block");
|
||||
var products = new Array();
|
||||
$.each(searchedProducts, function(index, value) {
|
||||
if ($('#prod_' + value).is(':checked'))
|
||||
products[value] = true;
|
||||
});
|
||||
var pricebook = $("#pricebook_id :selected").val();
|
||||
for ( var key in products) {
|
||||
var params = {
|
||||
job : 'getProduct',
|
||||
id : key,
|
||||
pricebook : pricebook,
|
||||
account_id : $("#parent_id").val(),
|
||||
language : $("#ecmlanguage").val(),
|
||||
};
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : ajax_url,
|
||||
dataType : "json",
|
||||
async : false,
|
||||
success : function(data) {
|
||||
if (data != '-1') {
|
||||
var p = new Object();
|
||||
p.product_id = data.id;
|
||||
p.name = data.name;
|
||||
p.product_code = data.code;
|
||||
p.product_id = data.id;
|
||||
p.ecmvat_id = data.ecmvat_id;
|
||||
p.ecmvat_value = data.ecmvat_value;
|
||||
p.ecmvat_name = data.ecmvat_name;
|
||||
p.product_ean = data.ean;
|
||||
p.product_ean2 = data.ean2;
|
||||
p.unit_name = data.unit_name;
|
||||
p.unit_id = data.unit_id;
|
||||
//p.price_start = data.price_start;
|
||||
p.recipient_code = data.recipient_code;
|
||||
if ($("#searchInputPrice").val() != ''
|
||||
&& !isNaN(parseFloat(UnformatNumber($(
|
||||
"#searchInputPrice").val()))))
|
||||
p.price_start = $("#searchInputPrice").val();
|
||||
if ($("#searchInputQty").val() != ''
|
||||
&& !isNaN(parseFloat(UnformatNumber($(
|
||||
"#searchInputQty").val()))))
|
||||
p.quantity = $("#searchInputQty").val();
|
||||
items.push(p);
|
||||
}
|
||||
},
|
||||
data : params
|
||||
});
|
||||
}
|
||||
FillTable(items);
|
||||
// clear results
|
||||
$('#searchResultDiv').html('');
|
||||
searchedProducts = new Array();
|
||||
$('#searchProductsInput').val('');
|
||||
|
||||
$(".loading_panel").css("display", "none");
|
||||
}
|
||||
|
||||
function getItems(editview) {
|
||||
var record = '';
|
||||
if ($("#duplicate").val() == true)
|
||||
record = $("input[name='return_id']").val();
|
||||
else
|
||||
record = $("input[name='record']").val();
|
||||
if (isNaN(editview))
|
||||
editview = true;
|
||||
var params = {
|
||||
job : 'getItems',
|
||||
record : record,
|
||||
};
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : ajax_url,
|
||||
dataType : "json",
|
||||
success : function(data) {
|
||||
items = data;
|
||||
if (editview)
|
||||
FillTable(items, false);
|
||||
else
|
||||
FillTable(items, true);
|
||||
$(".loading_panel").css("display", "none");
|
||||
},
|
||||
data : params
|
||||
});
|
||||
}
|
||||
|
||||
function changeLanguage() {
|
||||
$(".loading_panel").css("display", "block");
|
||||
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||||
for (var index = 0; index != count; index++) {
|
||||
var params = {
|
||||
job : 'getTranslation',
|
||||
product_id : $("#product_id_" + index).val(),
|
||||
language : $("#ecmlanguage").val(),
|
||||
unit_id : $("#unit_id_" + index).val(),
|
||||
};
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : ajax_url,
|
||||
async : false,
|
||||
dataType : "json",
|
||||
success : function(data) {
|
||||
$("#name_" + index).val(data.name);
|
||||
$("#unit_name_" + index).val(data.unit_name);
|
||||
calculateRow(index);
|
||||
},
|
||||
data : params
|
||||
});
|
||||
}
|
||||
$(".loading_panel").css("display", "none");
|
||||
}
|
||||
|
||||
function getPricesInfo(index) {
|
||||
$("#price_start_div_" + index).show('slow');
|
||||
$("#price_start_div_" + index).html(
|
||||
'<img src="modules/EcmReturns/images/loading.gif"/>');
|
||||
|
||||
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 = '<ul style="font-size: 7pt;">';
|
||||
$
|
||||
.each(
|
||||
data,
|
||||
function(key, value) {
|
||||
console.log(value.price);
|
||||
if (value.name == 'pricebook') {
|
||||
html += '<li style="cursor:pointer;" onClick="$(\'#price_start_'
|
||||
+ index
|
||||
+ '\').val(\''
|
||||
+ FormatNumber(value.price)
|
||||
+ '\'); $(this).closest(\'div\').hide(\'slow\');calculateRow('
|
||||
+ index
|
||||
+ ')"><u>'
|
||||
+ $(
|
||||
"#pricebook_id :selected")
|
||||
.html()
|
||||
+ ': '
|
||||
+ FormatNumber(value.price)
|
||||
+ '</u></li>';
|
||||
} else if (value.name == $(
|
||||
"#ecmprice_name").val()) {
|
||||
html += '<li style="cursor:pointer;" onClick="$(\'#price_start_'
|
||||
+ index
|
||||
+ '\').val(\''
|
||||
+ FormatNumber(value.price)
|
||||
+ '\'); $(this).closest(\'div\').hide(\'slow\');calculateRow('
|
||||
+ index
|
||||
+ ');"><b>'
|
||||
+ value.name
|
||||
+ ': '
|
||||
+ FormatNumber(value.price)
|
||||
+ '</b></li>';
|
||||
} else {
|
||||
html += '<li style="cursor:pointer;" onClick="$(\'#price_start_'
|
||||
+ index
|
||||
+ '\').val(\''
|
||||
+ FormatNumber(value.price)
|
||||
+ '\'); $(this).closest(\'div\').hide(\'slow\');calculateRow('
|
||||
+ index
|
||||
+ ');">'
|
||||
+ value.name
|
||||
+ ': '
|
||||
+ FormatNumber(value.price)
|
||||
+ '</li>';
|
||||
}
|
||||
});
|
||||
html += '</ul>';
|
||||
},
|
||||
data : params
|
||||
});
|
||||
$("#price_start_div_" + index).html(html);
|
||||
}
|
||||
|
||||
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 : ajax_url,
|
||||
dataType : "json",
|
||||
async : false,
|
||||
success : function(data) {
|
||||
html += 'Ceny<br>';
|
||||
$.each(data, function(key, value) {
|
||||
if (value.name == 'pricebook')
|
||||
html += $("#pricebook_id :selected").html() + ': '
|
||||
+ FormatNumber(value.price) + '<br>';
|
||||
if (value.name == $("#ecmprice_name").val())
|
||||
html += '<b>' + value.name + ': '
|
||||
+ FormatNumber(value.price) + '</b><br>';
|
||||
else
|
||||
html += value.name + ': ' + FormatNumber(value.price)
|
||||
+ '<br>';
|
||||
});
|
||||
},
|
||||
data : params
|
||||
});
|
||||
html += '</td></tr></table></td><td><table><tr><td>';
|
||||
var params = {
|
||||
job : 'getStockArray',
|
||||
product_id : product_id,
|
||||
};
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : ajax_url,
|
||||
dataType : "json",
|
||||
async : false,
|
||||
success : function(data) {
|
||||
html += 'Stany<br>';
|
||||
$.each(data, function(key, value) {
|
||||
html += key + ': ' + FormatNumber(value)
|
||||
+ '<br>';
|
||||
});
|
||||
},
|
||||
data : params
|
||||
});
|
||||
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 : ajax_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);
|
||||
}
|
||||
|
||||
//sortable rows in main table
|
||||
$("#"+itemsTable+" tbody").sortable();
|
||||
//get parent info use ajax
|
||||
function getParentInfo(parent_id, parent_type) {
|
||||
var params = {
|
||||
id : parent_id,
|
||||
type : 'Accounts',
|
||||
job : 'getParentInfo'
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
dataType : "json",
|
||||
success: function(data) {
|
||||
if (data == '-1') {
|
||||
alert('Błąd');
|
||||
$("#parent_name").val('');
|
||||
$("#parent_id").val('');
|
||||
} else {
|
||||
setParentInfo(data);
|
||||
}
|
||||
},
|
||||
data: params
|
||||
});
|
||||
}
|
||||
|
||||
//insert parent info in fields
|
||||
function setParentInfo(data) {
|
||||
//pricebooks
|
||||
createPricebookSelect(data.pricebooks);
|
||||
if (data.ecmprice_id && data.ecmprice_name) {
|
||||
$("#ecmprice_id").val(data.ecmprice_id);
|
||||
$("#ecmprice_name").val(data.ecmprice_name);
|
||||
}
|
||||
if ($("#new_number").val() == false) return; //if edit exists load only pricebooks
|
||||
if (data.name)
|
||||
$("#parent_name_copy").val(data.name);
|
||||
if (data.parent_nip)
|
||||
$("#parent_nip").val(data.parent_nip);
|
||||
if (data.parent_address_street)
|
||||
$("#parent_address_street").val(data.parent_address_street);
|
||||
if (data.parent_address_city)
|
||||
$("#parent_address_city").val(data.parent_address_city);
|
||||
if (data.parent_address_postalcode)
|
||||
$("#parent_address_postalcode").val(data.parent_address_postalcode);
|
||||
if (data.parent_address_country)
|
||||
$("#parent_address_country").val(data.parent_address_country);
|
||||
if (data.invoice_type && data.invoice_type!='K')
|
||||
$("#no_tax").attr('checked', true);
|
||||
if (data.ecmpaymentcondition_id && data.ecmpaymentcondition_name) {
|
||||
$("#ecmpaymentcondition_id").val(data.ecmpaymentcondition_id);
|
||||
$("#ecmpaymentcondition_name").val(data.ecmpaymentcondition_name);
|
||||
}
|
||||
if (data.ecmdeliverycondition_id && data.ecmdeliverycondition_name) {
|
||||
$("#ecmdeliverycondition_id").val(data.ecmdeliverycondition_id);
|
||||
$("#ecmdeliverycondition_name").val(data.ecmdeliverycondition_name);
|
||||
}
|
||||
if (data.currency_id)
|
||||
$("#currency_id option[value=\""+data.currency_id+"\"]").attr('selected', 'selected');
|
||||
//hide loading
|
||||
$(".loading_panel").css("display", "none");
|
||||
}
|
||||
|
||||
function createPricebookSelect(pricebooks) {
|
||||
var s = $("<select id=\"pricebook_id\"/>");
|
||||
var opt = '';
|
||||
$.each(pricebooks, function(index, value) {
|
||||
opt+='<option value="'+value.id+'">'+value.name+'</option>';
|
||||
});
|
||||
s.html(opt);
|
||||
$("#pricebooks").append(s);
|
||||
}
|
||||
|
||||
function generateNumber() {
|
||||
var params = {
|
||||
job : 'generateNumber'
|
||||
};
|
||||
|
||||
$.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 = '<option value=""></option>';
|
||||
$.each(data, function(index, value){
|
||||
html+='<option value="'+value.id+'">'+value.name+'</option>';
|
||||
$("#productSearchCategory").html(html);
|
||||
});
|
||||
},
|
||||
data: params
|
||||
});
|
||||
}
|
||||
|
||||
function checkProducts() {
|
||||
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||||
var error = false; // hope :)
|
||||
for (var index = 0; index != count; index++) {
|
||||
var qty = UnformatNumber($("#quantity_" + index).val());
|
||||
if (qty < 1) error = true;
|
||||
}
|
||||
if (error)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
75
modules/EcmReturns/javascript/columndefs-detail.js
Normal file
75
modules/EcmReturns/javascript/columndefs-detail.js
Normal file
@@ -0,0 +1,75 @@
|
||||
columns = new Array();
|
||||
//define columns
|
||||
//begin: number
|
||||
columns[0] = {
|
||||
'name' : 'number',
|
||||
'label' : 'Lp.',
|
||||
'width' : 4,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[0]['content'][0] = {'name' : '', 'type': 'text', 'readonly' : true};
|
||||
//end: number
|
||||
//begin: code
|
||||
columns[1] = {
|
||||
'name' : 'product_',
|
||||
'label' : 'Kod',
|
||||
'width' : 6,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[1]['content'][0] = {'name' : 'code', 'type': 'hidden', 'readonly' : true};
|
||||
columns[1]['content'][1] = {'name' : 'id', 'type': 'hidden'};
|
||||
columns[1]['content'][2] = {'name' : 'link', 'type': 'text', 'readonly' : true};
|
||||
//end: code
|
||||
//begin: name
|
||||
columns[2] = {
|
||||
'name' : 'name',
|
||||
'label' : 'Nazwa',
|
||||
'width' : 20,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[2]['content'][0] = {'name' : '', 'type': 'text'};
|
||||
//end: name
|
||||
//begin: quantity
|
||||
columns[3] = {
|
||||
'name' : 'quantity',
|
||||
'label' : 'Ilość',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[3]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'};
|
||||
//end: quantity
|
||||
//begin: unit
|
||||
columns[4] = {
|
||||
'name' : 'unit_',
|
||||
'label' : 'J.M.',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'center',
|
||||
};
|
||||
columns[4]['content'][0] = {'name' : 'name', 'type': 'text','readonly' : true};
|
||||
columns[4]['content'][1] = {'name' : 'id', 'type': 'hidden'};
|
||||
//end: unit
|
||||
//begin: price_start
|
||||
columns[5] = {
|
||||
'name' : 'price_start',
|
||||
'label' : 'Cena',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[5]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'};
|
||||
columns[5]['content'][1] = {'name' : '_div', 'type': 'text'};
|
||||
//end: price_start
|
||||
//begin: discount
|
||||
columns[6] = {
|
||||
'name' : 'total_',
|
||||
'label' : 'Wartość',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[6]['content'][0] = {'name' : 'netto', 'type': 'text', 'isNumber' : true, 'readonly' : true};
|
||||
//end: total
|
||||
|
||||
//end: remarks
|
||||
79
modules/EcmReturns/javascript/columndefs.js
Normal file
79
modules/EcmReturns/javascript/columndefs.js
Normal file
@@ -0,0 +1,79 @@
|
||||
columns = new Array();
|
||||
//define columns
|
||||
//begin: number
|
||||
columns[0] = {
|
||||
'name' : 'number',
|
||||
'label' : 'Lp.',
|
||||
'width' : 4,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[0]['content'][0] = {'name' : '', 'type': 'text', 'readonly' : true};
|
||||
//end: number
|
||||
//begin: code
|
||||
columns[1] = {
|
||||
'name' : 'product_',
|
||||
'label' : 'Kod',
|
||||
'width' : 6,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[1]['content'][0] = {'name' : 'code', 'type': 'hidden', 'readonly' : true};
|
||||
columns[1]['content'][1] = {'name' : 'id', 'type': 'hidden'};
|
||||
columns[1]['content'][2] = {'name' : 'link', 'type': 'text', 'readonly' : true};
|
||||
//end: code
|
||||
//begin: name
|
||||
columns[2] = {
|
||||
'name' : 'name',
|
||||
'label' : 'Nazwa',
|
||||
'width' : 20,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[2]['content'][0] = {'name' : '', 'type': 'text'};
|
||||
//end: name
|
||||
//begin: quantity
|
||||
columns[3] = {
|
||||
'name' : 'quantity',
|
||||
'label' : 'Ilość',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[3]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'};
|
||||
//end: quantity
|
||||
//begin: unit
|
||||
columns[4] = {
|
||||
'name' : 'unit_',
|
||||
'label' : 'J.M.',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'center',
|
||||
};
|
||||
columns[4]['content'][0] = {'name' : 'name', 'type': 'text','readonly' : true};
|
||||
columns[4]['content'][1] = {'name' : 'id', 'type': 'hidden'};
|
||||
//end: unit
|
||||
//begin: price_start
|
||||
columns[5] = {
|
||||
'name' : 'price_start',
|
||||
'label' : 'Cena',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[5]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'};
|
||||
//end: price_start
|
||||
//begin: discou
|
||||
columns[6] = {
|
||||
'name' : 'total_',
|
||||
'label' : 'Wartość',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[6]['content'][0] = {'name' : 'netto', 'type': 'text', 'isNumber' : true, 'readonly' : true};
|
||||
//end: total
|
||||
//begin: recipient_code
|
||||
columns[7] = {
|
||||
'name' : 'options',
|
||||
'label' : 'Opcje',
|
||||
'width' : 3,
|
||||
'content' : new Array(),
|
||||
};
|
||||
270
modules/EcmReturns/javascript/helper.php
Normal file
270
modules/EcmReturns/javascript/helper.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('-1');
|
||||
if (!$_POST['job'] || $_POST['job']=='') die ('-1');
|
||||
switch ($_POST['job']) {
|
||||
case 'getParentInfo': getParentInfo($_POST['id'], $_POST['type']); break;
|
||||
case 'generateNumber': generateNumber(); break;
|
||||
case 'searchProducts': searchProducts($_POST['searchKey'], $_POST['searchCategory'], $_POST['searchStock'], $_POST['searchSort']); break;
|
||||
case 'getProduct': getProduct($_POST['id'], $_POST['pricebook'], $_POST['account_id'], $_POST['language']); break;
|
||||
case 'getItems': getItems($_POST['record']); break;
|
||||
case 'getCategoriesList': getCategoriesList(); break;
|
||||
case 'getTranslation': getTranslation($_POST['product_id'], $_POST['language'], $_REQUEST['unit_id']); break;
|
||||
case 'getPricesInfo': getPricesInfo($_POST['product_id'], $_POST['pricebook_id'], $_POST['account_id']); break;
|
||||
case 'getStockArray' : getStockArray($_POST['product_id']); break;
|
||||
case 'getPurchaseArray' : getPurchaseArray($_POST['product_id']); break;
|
||||
}
|
||||
|
||||
function getParentInfo($id, $type) {
|
||||
if (!$id || $id == '') die('-1');
|
||||
if (!$type || $type == '') die('-1');
|
||||
|
||||
if ($type == 'Accounts')
|
||||
$a = new Account();
|
||||
elseif ($type == 'Leads')
|
||||
$a = new Lead();
|
||||
else
|
||||
die(-1);
|
||||
|
||||
$a->retrieve($id);
|
||||
$data = array();
|
||||
$data['name'] = $a->name;
|
||||
$data['parent_nip'] = $a->to_vatid;
|
||||
$data['parent_address_street'] = $a->billing_address_street;
|
||||
$data['parent_address_postalcode'] = $a->billing_address_postalcode;
|
||||
$data['parent_address_city'] = $a->billing_address_city;
|
||||
$data['parent_address_country'] = $a->billing_address_country;
|
||||
$data['invoice_type'] = $a->invoice_type;
|
||||
$data['currency_id'] = $a->currency_id;
|
||||
if ($a->ecmpaymentcondition_id && $a->ecmpaymentcondition_id!='') {
|
||||
$pc = new EcmPaymentCondition();
|
||||
$pc->retrieve($a->ecmpaymentcondition_id);
|
||||
$data['ecmpaymentcondition_id'] = $pc->id;
|
||||
$data['ecmpaymentcondition_name'] = $pc->name;
|
||||
}
|
||||
if ($a->ecmdeliverycondition_id && $a->ecmdeliverycondition_id!='') {
|
||||
$pc = new EcmdeliveryCondition();
|
||||
$pc->retrieve($a->ecmdeliverycondition_id);
|
||||
$data['ecmdeliverycondition_id'] = $pc->id;
|
||||
$data['ecmdeliverycondition_name'] = $pc->name;
|
||||
}
|
||||
|
||||
if ($a->ecmprice_id && $a->ecmprice_id!='') {
|
||||
$pr = new EcmPrice();
|
||||
$pr->retrieve($a->ecmprice_id);
|
||||
$data['ecmprice_id'] = $pr->id;
|
||||
$data['ecmprice_name'] = $pr->name;
|
||||
}
|
||||
//get pricebooks, ownership pricebooks
|
||||
$pricebooks = array();
|
||||
$db=$GLOBALS['db'];
|
||||
$res = $db->query("SELECT id, name FROM ecmpricebooks WHERE account_id IN ('".$a->id."','".$a->parent_id."') AND active='1' AND deleted='0'");
|
||||
while ($row = $db->fetchByAssoc($res)) {
|
||||
$tmp = array();
|
||||
$tmp['id'] = $row['id'];
|
||||
$tmp['name'] = $row['name'];
|
||||
$pricebooks[] = $tmp;
|
||||
unset($tmp);
|
||||
}
|
||||
$data['pricebooks'] = $pricebooks;
|
||||
echo json_encode($data);
|
||||
unset($data);
|
||||
unset($a);
|
||||
unset($res);
|
||||
return;
|
||||
}
|
||||
function generateNumber() {
|
||||
$data = array();
|
||||
$data['number'] = EcmReturn::generateNumber();
|
||||
$data['document_no'] = EcmReturn::formatNumber($data['number']);
|
||||
echo json_encode($data);
|
||||
unset($data);
|
||||
return;
|
||||
}
|
||||
|
||||
function searchProducts($searchKey, $searchCategory, $searchStock, $searchSort) {
|
||||
|
||||
$db = $GLOBALS['db'];
|
||||
$q = "SELECT id, code, name FROM ecmproducts WHERE
|
||||
(UPPER(code) LIKE '%$searchKey%' OR
|
||||
UPPER(name) LIKE '%$searchKey%')
|
||||
AND deleted='0' ";
|
||||
if ($searchCategory && $searchCategory!="")
|
||||
$q.="AND product_category_id='$searchCategory' ";
|
||||
|
||||
if ($searchSort=='1')
|
||||
$q.="ORDER BY code";
|
||||
else if ($searchSort=='2')
|
||||
$q.="ORDER BY code DESC";
|
||||
else if ($searchSort=='3')
|
||||
$q.="ORDER BY name";
|
||||
else if ($searchSort=='4')
|
||||
$q.="ORDER BY name DESC";
|
||||
|
||||
$q.=" LIMIT 0,50";
|
||||
|
||||
$res = $db->query($q);
|
||||
$result = array();
|
||||
|
||||
if ($searchStock!='1') {
|
||||
//get main stock id
|
||||
$stock_res = $db->fetchByAssoc($db->query("SELECT id FROM ecmstocks WHERE main='1' LIMIT 0,1"));
|
||||
$stock_id = $stock_res['id'];
|
||||
}
|
||||
while ($row = $db->fetchByAssoc($res)) {
|
||||
$tmp = array();
|
||||
$tmp['id'] = $row['id'];
|
||||
$tmp['name'] = $row['name'];
|
||||
$tmp['code'] = $row['code'];
|
||||
|
||||
//get stock if necessary
|
||||
if ($searchStock!='1') {
|
||||
$tmp['stock_state'] = EcmStockOperation::getStock($row['id'], $stock_id);
|
||||
}
|
||||
|
||||
if ($searchStock=='3' && $tmp['stock_state']==0) continue; //don't show null stock
|
||||
|
||||
$result[] = $tmp;
|
||||
}
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
function getProduct($id, $pricebook_id, $account_id, $language) {
|
||||
$db = $GLOBALS['db'];
|
||||
$p = $db->fetchByAssoc($db->query("SELECT p.id, p.code, p.name, v.id as ecmvat_id, v.name as ecmvat_name, v.value as ecmvat_value, p.ean, p.ean2, p.unit_id FROM ecmproducts as p INNER JOIN ecmvats as v ON v.id=p.vat_id WHERE p.id='$id'"));
|
||||
global $app_list_strings;
|
||||
$p['unit_name'] = $app_list_strings['ecmproducts_unit_dom'][$p['unit_id']];
|
||||
//try get recipient_code and price from pricebook
|
||||
if ($pricebook_id && $pricebook_id!='') {
|
||||
$pr = $db->fetchByAssoc($db->query("SELECT price, recipient_code FROM ecmpricebooks_ecmproducts WHERE ecmpricebook_id='$pricebook_id' AND ecmproduct_id='$id' AND deleted='0'"));
|
||||
$p['price_start'] = $pr['price'];
|
||||
$p['recipient_code'] = $pr['recipient_code'];
|
||||
}
|
||||
if (!$p['price_start'] || floatval($p['price_start'])==0) {
|
||||
//try price from default prices
|
||||
$pr = $db->fetchByAssoc($db->query("SELECT pp.price FROM ecmprices_ecmproducts AS pp INNER JOIN ecmprices AS p ON pp.ecmprice_id=p.id INNER JOIN accounts AS a ON p.id=a.ecmprice_id WHERE a.id='$account_id' AND pp.ecmproduct_id='$id'"));
|
||||
$p['price_start'] = $pr['price'];
|
||||
}
|
||||
|
||||
if ($language=='en_us') {
|
||||
$r = $db->fetchByAssoc($db->query("SELECT short_description FROM ecmproduct_language WHERE ecmproduct_id='$id' AND language='en'"));
|
||||
$p['name'] = htmlspecialchars_decode($r['short_description']);
|
||||
|
||||
$lists = return_app_list_strings_language($language);
|
||||
$p['unit_name'] = $lists['ecmproducts_unit_dom'][$p['unit_id']];
|
||||
unset($lists);
|
||||
}
|
||||
echo json_encode($p);
|
||||
return;
|
||||
}
|
||||
|
||||
function getItems($record) {
|
||||
$of = new EcmReturn();
|
||||
$of->retrieve($record);
|
||||
$pl = $of->getPositionList(true);
|
||||
unset($of);
|
||||
echo json_encode($pl);
|
||||
return;
|
||||
}
|
||||
|
||||
function getCategoriesList() {
|
||||
$db = $GLOBALS['db'];
|
||||
$res = $db->query("SELECT id, name FROM ecmproductcategories WHERE deleted='0'");
|
||||
$result = array();
|
||||
while ($row = $db->fetchByAssoc($res)) {
|
||||
$tmp = array();
|
||||
$tmp['id'] = $row['id'];
|
||||
$tmp['name'] = $row['name'];
|
||||
$result[] = $tmp;
|
||||
}
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
function getTranslation($product_id, $language, $unit_id) {
|
||||
$db = $GLOBALS['db'];
|
||||
$result = array();
|
||||
if ($language=='en_us') {
|
||||
$r = $db->fetchByAssoc($db->query("SELECT short_description FROM ecmproduct_language WHERE ecmproduct_id='$product_id' AND language='en'"));
|
||||
$result['name'] = htmlspecialchars_decode($r['short_description']);
|
||||
} else if ($language=='pl_pl') {
|
||||
$p = new EcmProduct();
|
||||
$p->retrieve($product_id);
|
||||
$result['name'] = htmlspecialchars_decode($p->name);
|
||||
unset($p);
|
||||
}
|
||||
$lists = return_app_list_strings_language($language);
|
||||
$result['unit_name'] = $lists['ecmproducts_unit_dom'][$unit_id];
|
||||
unset($lists);
|
||||
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
function getPricesInfo($product_id, $pricebook_id, $account_id) {
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
$result = array();
|
||||
if ($pricebook_id && $pricebook_id!='') {
|
||||
//try get price from pricebook
|
||||
$res = $db->fetchByAssoc($db->query("SELECT price FROM ecmpricebooks_ecmproducts WHERE ecmpricebook_id='$pricebook_id' AND ecmproduct_id='$product_id' AND deleted='0'"));
|
||||
if ($res['price'] && $res['price']!='' && $res['price']!=0) {
|
||||
$tmp = array();
|
||||
$tmp['name'] = 'pricebook';
|
||||
$tmp['price'] = $res['price'];
|
||||
$result[] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
//get from ecmprices
|
||||
$res = $db->query("SELECT p.name, pp.price FROM ecmprices_ecmproducts AS pp
|
||||
INNER JOIN ecmprices AS p
|
||||
ON p.id=pp.ecmprice_id
|
||||
WHERE
|
||||
pp.ecmproduct_id='$product_id'
|
||||
AND pp.price!=0");
|
||||
while ($row = $db->fetchByAssoc($res)) {
|
||||
$tmp = array();
|
||||
$tmp['name'] = $row['name'];
|
||||
$tmp['price'] = $row['price'];
|
||||
$result[] = $tmp;
|
||||
}
|
||||
|
||||
//get last invoice price
|
||||
if ($account_id && $account_id!='') {
|
||||
$res = $db->fetchByAssoc($db->query("SELECT ii.subprice, i.id, i.document_no FROM ecminvoiceoutitems AS ii
|
||||
INNER JOIN ecminvoiceouts AS i
|
||||
ON ii.ecminvoiceout_id=i.id
|
||||
WHERE ii.ecmproduct_id='$product_id'
|
||||
AND i.parent_id='$account_id'
|
||||
AND ii.deleted='0'
|
||||
AND i.deleted='0'
|
||||
AND i.canceled='0'
|
||||
ORDER BY i.register_date DESC
|
||||
LIMIT 0,1"));
|
||||
if ($res && $res['subprice']!='') {
|
||||
$tmp = array();
|
||||
$tmp['name'] = $res['document_no'];
|
||||
$tmp['price'] = $res['subprice'];
|
||||
$result[] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
function getStockArray($product_id) {
|
||||
$o = new EcmStockOperation();
|
||||
echo json_encode($o->getStockArray($product_id));
|
||||
unset($o);
|
||||
return;
|
||||
}
|
||||
|
||||
function getPurchaseArray($product_id) {
|
||||
$o = new EcmStockOperation();
|
||||
echo json_encode($o->getPurchaseArray($product_id));
|
||||
unset($o);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user