query($query);
$res=$db->fetchByAssoc($zap);
if($res['value1']==''){
$res['value1']=1;
} else {
$res['value1']++;
}
$json = json_encode($res);
print $json;
}
function savePartNumber(){
$db = $GLOBALS['db'];
$query="SELECT id, value1 FROM operating_values WHERE name='PartNumber' AND module_name='EcmProducts'";
$zap=$db->query($query);
$res=$db->fetchByAssoc($zap);
if($res['value1']==''){
$res['value1']=1;
} else {
$res['value1']++;
}
$query="UPDATE operating_values SET value1='".$res['value1']."' where id='" .$res['id'] ."'";
$db->query($query);
$json = json_encode($res['value1']);
print $json;
}
function searchProductsAutocomplite($searchKey, $searchStock, $searchStockId, $index) {
// contains utility functions mb_stripos_all() and apply_highlight()
require_once 'modules/EcmSales/javascript/local_utils.php';
$db = $GLOBALS['db'];
$result = array();
$q = "SELECT p.id, p.code, p.name,p.unit_id FROM ecmproducts p ";
if ($searchCategory != 'bf900339-6c7b-f278-2737-542023796730' &&
$searchStock == 3) {
$q .= ' inner join ecmstockstates s on p.id=s.product_id';
}
$q .= ' WHERE p.deleted=0 and (UPPER(p.code) LIKE "%' . $searchKey . '%" OR
UPPER(p.name) LIKE "%' . $searchKey . '%") ';
if ($searchCategory && $searchCategory != "")
$q .= "AND p.product_category_id='$searchCategory' ";
if ($searchStock == 3 &&
$searchCategory != 'bf900339-6c7b-f278-2737-542023796730')
$q .= "and s.stock_id='$searchStockId' and s.quantity>0 ";
if ($searchSort == '1')
$q .= "ORDER BY p.code";
else if ($searchSort == '2')
$q .= "ORDER BY p.code DESC";
else if ($searchSort == '3')
$q .= "ORDER BY p.name";
else if ($searchSort == '4')
$q .= "ORDER BY p.name DESC";
$q.=' LIMIT 0,50';
$rs = $db->query($q);
if ($rs->num_rows > 0) {
while ($row = $db->fetchByAssoc($rs)) {
$a_json_row["id"] = $row['id'];
$a_json_row["value"] = $row['name'];
if ($searchStock != '1') {
$a_json_row['stock_state'] = EcmStockOperation::getStock($row['id'], $searchStockId);
$quantity = '
Stan: ' . $a_json_row['stock_state'] . '';
}
$a_json_row["label"] = "Indeks: " . $row['code'] . "
Nazwa: " . $row['name'] . '' . $quantity;
$result[] = $a_json_row;
}
} else {
$a_json_row["label"] = "Brak produktu o szukanej nazwie";
$a_json_row["value"] = $searchKey;
$a_json_row["id"] = '';
$result[] = $a_json_row;
}
$json = json_encode($result);
print $json;
}
function searchEcmActionsAutocomplite($searchKey, $category = '') {
// contains utility functions mb_stripos_all() and apply_highlight()
// require_once 'modules/EcmSales/javascript/local_utils.php';
global $current_language;
$app_list_strings = return_app_list_strings_language($current_language);
$db = $GLOBALS ['db'];
$where = '';
if ($category != '') {
$where = " category = '" . $category . "' AND ";
}
$nazwa = '';
if ($searchKey != '') {
$nazwa = ' AND (UPPER(indeks) LIKE "%' . $searchKey . '%" OR UPPER(name) LIKE "%' . $searchKey . '%") ';
}
$result = array();
$q = 'SELECT id, name, indeks, time, cost_action, cost_hour, category FROM ecmactions WHERE ' . $where . ' deleted=0 ' . $nazwa . ' LIMIT 0,50';
$rs = $db->query($q);
if ($rs->num_rows > 0) {
while ($row = $db->fetchByAssoc($rs)) {
$a_json_row ['id'] = $row ['id'];
$a_json_row ['name'] = $row ['name'];
$a_json_row ['indeks'] = $row ['indeks'];
$a_json_row ['time'] = $row ['time'];
$a_json_row ['cost_action'] = $row ['cost_action']; // $app_list_strings ['ecmactions_unit_dom'] [$row ['ecmactions_unit_dom']];
$a_json_row ['cost_hour'] = $row ['cost_hour'];
$a_json_row ['category'] = $app_list_strings ['ecmactions_category_dom'] [$row ['category']];
$a_json_row ['label'] = "Kategoria: " . $a_json_row ['category'] . "
Indeks: " . $row ['indeks'] . "
Nazwa: " . $row ['name'] . '';
$a_json_row ['value'] = '';
$result [] = $a_json_row;
}
} else {
$a_json_row ['id'] = '';
$a_json_row ['name'] = '';
$a_json_row ['indeks'] = '';
$a_json_row ['time'] = '';
$a_json_row ['cost_action'] = '';
$a_json_row ['cost_hour'] = '';
$a_json_row ['category'] = '';
$a_json_row ["label"] = "Brak czynności o szukanej nazwie";
$a_json_row ['value'] = '';
$result [] = $a_json_row;
}
$json = json_encode($result);
print $json;
}
function searchComponentsAutocomplite($searchKey, $source = '', $category = '') {
// contains utility functions mb_stripos_all() and apply_highlight()
// require_once 'modules/EcmSales/javascript/local_utils.php';
global $current_language;
$app_list_strings = return_app_list_strings_language($current_language);
$db = $GLOBALS ['db'];
$where = '';
if ($category != '') {
$where = " category = '" . $category . "' AND ";
}
$nazwa = '';
if ($searchKey != '') {
$nazwa = ' AND (UPPER(code) LIKE "%' . $searchKey . '%" OR UPPER(name) LIKE "%' . $searchKey . '%") ';
}
$result = array();
$q = 'SELECT id, name, code, product_category_id, product_category_name,srp_price, unit_id FROM ecmproducts WHERE ' . $where . ' deleted=0 ' . $nazwa . ' LIMIT 0,50';
$rs = $db->query($q);
if ($rs->num_rows > 0) {
while ($row = $db->fetchByAssoc($rs)) {
$a_json_row ['ecmcomponent_id'] = $row ['id'];
$a_json_row ['name'] = $row ['name'];
$a_json_row ['code'] = $row ['code'];
$a_json_row ['product_category_id'] = $row ['product_category_id'];
$a_json_row ['product_category_name'] = $row ['product_category_name'];
$a_json_row ['unit_id'] = $row ['unit_id'];
$a_json_row ['label'] = "Kategoria: " . $a_json_row ['product_category_name'] . "
Indeks: " . $row ['code'] . "
Nazwa: " . $row ['name'] . '';
$a_json_row ['srp_price'] =($row['srp_price']);
if ($source == 'code') {
$a_json_row ['value'] = $row ['code'];
} else {
$a_json_row ['value'] = $row ['name'];
}
$result [] = $a_json_row;
}
} else {
$a_json_row ['ecmcomponent_id'] = '';
$a_json_row ['name'] = '';
$a_json_row ['code'] = '';
$a_json_row ['product_category_id'] = '';
$a_json_row ['product_category_name'] = '';
$a_json_row ['unit_id'] = '';
$a_json_row ["label"] = "Brak produktu o szukanej nazwie";
$a_json_row ['value'] = '';
$result [] = $a_json_row;
}
$json = json_encode($result);
print $json;
}
function searchActionsList($searchKey, $category = '') {
// contains utility functions mb_stripos_all() and apply_highlight()
// require_once 'modules/EcmSales/javascript/local_utils.php';
global $current_language;
$app_list_strings = return_app_list_strings_language($current_language);
$db = $GLOBALS ['db'];
$where = '';
if ($category != '') {
$where = " category = '" . $category . "' AND ";
}
$nazwa = '';
if ($searchKey != '') {
$nazwa = ' AND (UPPER(indeks) LIKE "%' . $searchKey . '%" OR UPPER(name) LIKE "%' . $searchKey . '%") ';
}
$result = array();
$q = 'SELECT id, name, indeks, time, cost_action, cost_hour, category FROM ecmactions WHERE ' . $where . ' deleted=0 ' . $nazwa . ' LIMIT 0,50';
$rs = $db->query($q);
if ($rs->num_rows > 0) {
while ($row = $db->fetchByAssoc($rs)) {
$a_json_row ['id'] = $row ['id'];
$a_json_row ['ecmactionid'] = $row ['id'];
$a_json_row ['name'] = $row ['name'];
$a_json_row ['indeks'] = $row ['indeks'];
$a_json_row ['time'] = $row ['time'];
$a_json_row ['cost_action'] = $row ['cost_action']; // $app_list_strings ['ecmactions_unit_dom'] [$row ['ecmactions_unit_dom']];
$a_json_row ['cost_hour'] = $row ['cost_hour'];
$a_json_row ['category'] = $app_list_strings ['ecmactions_category_dom'] [$row ['category']];
$a_json_row ['price1'] = format_number($row ['cost_action']);
$hours = 0;
$minutes = 0;
$seconds = 0;
$time = intval($row ['time']);
$minutes = intval(floor($time / 60));
$hours = intval(floor($minutes / 60));
$seconds = $time - ($minutes * 60);
$minutes = $minutes - ($hours * 60);
if ($hours < 10) {
$hours = "0" . $hours;
}
if ($minutes < 10) {
$minutes = "0" . $minutes;
}
if ($seconds < 10) {
$seconds = "0" . $seconds;
}
//return ("" + $hours + "." + $minutes + ":" + $seconds);
$a_json_row ['displaytime'] = "" . $hours . "." . $minutes . ":" . $seconds;
$result [] = $a_json_row;
}
}
$json = json_encode($result);
//$json = json_encode($a_json_row ['displaytime']);
print $json;
}
function searchProducts($searchKey, $searchCategory, $searchStock, $searchStockId, $searchSort, $searchStart, $searchCount, $groupKs) {
$db = $GLOBALS['db'];
$result = array();
global $app_list_strings;
$q = "SELECT p.id, p.code, p.name,p.unit_id FROM ecmproducts p";
if ($searchCategory != 'bf900339-6c7b-f278-2737-542023796730' &&
($searchStock == 3 || $searchStock == 4)) {
$q .= ' inner join ecmstockstates s on p.id=s.product_id';
}
/*
$q .= " WHERE
(p.id in ( select id from ecmproducts where
(UPPER(code) LIKE '%$searchKey%' OR
UPPER(name) LIKE '%$searchKey%') ) or p.id in ( select product_id from ecmstockoperations where
UPPER(part_no) LIKE '%$searchKey%'))
AND p.deleted='0' ";
*/
$q .= " WHERE (
UPPER(p.code) LIKE '%$searchKey%' OR
UPPER(p.name) LIKE '%$searchKey%') OR
ean LIKE '%$searchKey%' OR
ean2 LIKE '%$searchKey%'
AND p.deleted='0' ";
if ($searchCategory && $searchCategory != "")
$q .= "AND p.product_category_id='$searchCategory' ";
if ($searchStock == 3 &&
$searchCategory != 'bf900339-6c7b-f278-2737-542023796730') {
$q .= "and s.stock_id='$searchStockId' and s.quantity>0 ";
}
if ($searchStock == 4 &&
$searchCategory != 'bf900339-6c7b-f278-2737-542023796730') {
$q .= "and s.stock_id='$searchStockId' ";
}
if ($groupKs && $groupKs != ""){
$q .= " AND p.ks_group NOT IN ('$groupKs') ";
}
if ($searchSort == '1')
$q .= "ORDER BY p.code ASC";
else if ($searchSort == '2')
$q .= "ORDER BY p.code DESC";
else if ($searchSort == '3')
$q .= "ORDER BY p.name ASC";
else if ($searchSort == '4')
$q .= "ORDER BY p.name DESC";
$c = $db->query($q);
$result['count'] = $c->num_rows;
if ($searchStart == 0) {
$LIMIT1 = 0;
$LIMIT2 = 50;
} else
if ($searchStart > 0) {
$LIMIT1 = $searchStart;
$LIMIT2 = 50;
}
// echo $LIMIT1. ' '.$LIMIT2;
// pagination end
$q .= " LIMIT " . $LIMIT1 . "," . $LIMIT2;
//echo $q;
$res = $db->query($q);
while ($row = $db->fetchByAssoc($res)) {
$tmp = array();
$tmp['id'] = $row['id'];
$tmp['name'] = $row['name'];
$tmp['code'] = $row['code'];
$tmp['unit_name'] = $app_list_strings['ecmproducts_unit_dom'][$row['unit_id']];
// get stock if necessary
if ($searchStock != '1') {
//$tmp['stock_state'] = EcmStockOperation::getStock($row['id'], $searchStockId);
}
if ($searchStock == '3' && $tmp['stock_state'] == 0)
continue; // don't
// show
// null
// stock
$result[] = $tmp;
}
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;
}
function getStockProductDetails($record, $stock_id) {
$db = $GLOBALS['db'];
$r = $db->query(
"select * from ecmstockoperations where
product_id='" . $record . "'
and stock_id='" . $stock_id . "'
and in_id is null and used=0 and type=0");
$docs = array();
$l = 0;
while ($tmp = $db->fetchByAssoc($r)) {
$ii = $db->query(
"select * from ecmstockoperations where in_id='" . $tmp['id'] .
"' and type=1");
if ($ii->num_rows > 0) {
$quantity_tmp = $tmp['quantity'];
while ($tmp2 = $db->fetchByAssoc($ii)) {
$quantity_tmp -= $tmp2['quantity'];
}
$doc['quantity'] = $quantity_tmp;
$doc['parent_name'] = $tmp['parent_name'];
$doc['price'] = $tmp['price'];
$doc['parent_type'] = $tmp['parent_type'];
$doc['parent_id'] = $tmp['parent_id'];
$docs[] = $doc;
} else {
$doc['quantity'] = $tmp['quantity'];
$doc['parent_name'] = $tmp['parent_name'];
$doc['price'] = $tmp['price'];
$doc['parent_type'] = $tmp['parent_type'];
$doc['parent_id'] = $tmp['parent_id'];
$docs[] = $doc;
}
}
echo json_encode($docs);
return;
}
?>