Add php files
This commit is contained in:
491
include/ECM/PHPSearch.php
Executable file
491
include/ECM/PHPSearch.php
Executable file
@@ -0,0 +1,491 @@
|
||||
<?php
|
||||
|
||||
if (!defined('sugarEntry') || !sugarEntry)
|
||||
die('-1');
|
||||
if (!$_POST['job'] || $_POST['job'] == '')
|
||||
die('-1');
|
||||
switch ($_POST['job']) {
|
||||
case 'searchProductsAutocomplite':
|
||||
searchProductsAutocomplite($_POST['term'], $_POST['searchStock'], $_POST['searchStockId'], $_POST['index']);
|
||||
break;
|
||||
case 'searchEcmActionsAutocomplite':
|
||||
searchEcmActionsAutocomplite($_POST['term'],$_POST['category']);
|
||||
break;
|
||||
case 'searchComponentsAutocomplite':
|
||||
searchComponentsAutocomplite($_POST['term'], $_POST['source'], $_POST['category']);
|
||||
break;
|
||||
case 'searchActionsList':
|
||||
searchActionsList($_POST['term'],$_POST['category']);
|
||||
break;
|
||||
case 'searchProducts':
|
||||
searchProducts($_POST['searchKey'], $_POST['searchCategory'], $_POST['searchStock'], $_POST['searchStockId'], $_POST['searchSort'], $_POST['searchStart'], $_POST['searchCount'], $_POST['groupKs']);
|
||||
break;
|
||||
case 'getStockProductDetails':
|
||||
getStockProductDetails($_POST['record'], $_POST['stock_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;
|
||||
case 'getNextPartNumber':
|
||||
getMextPartNumber();
|
||||
break;
|
||||
case 'savePartNumber':
|
||||
savePartNumber();
|
||||
break;
|
||||
}
|
||||
|
||||
function getMextPartNumber(){
|
||||
$db = $GLOBALS['db'];
|
||||
$query="SELECT 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']++;
|
||||
}
|
||||
|
||||
$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 = '<br>Stan: <span style="color: blue;">' . $a_json_row['stock_state'] . '</span>';
|
||||
}
|
||||
$a_json_row["label"] = "Indeks: <span style='color: blue;'>" . $row['code'] . "</span><br>Nazwa: <span style='color: blue;'>" . $row['name'] . '</span>' . $quantity;
|
||||
$result[] = $a_json_row;
|
||||
}
|
||||
} else {
|
||||
$a_json_row["label"] = "<span style='color: red;'>Brak produktu o szukanej nazwie</span>";
|
||||
$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: <span style='color: blue;'>" . $a_json_row ['category'] . "</span><br>Indeks: <span style='color: blue;'>" . $row ['indeks'] . "</span><br>Nazwa: <span style='color: blue;'>" . $row ['name'] . '</span>';
|
||||
$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"] = "<span style='color: red;'>Brak czynności o szukanej nazwie</span>";
|
||||
$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: <span style='color: blue;'>" . $a_json_row ['product_category_name'] . "</span><br>Indeks: <span style='color: blue;'>" . $row ['code'] . "</span><br>Nazwa: <span style='color: blue;'>" . $row ['name'] . '</span>';
|
||||
$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"] = "<span style='color: red;'>Brak produktu o szukanej nazwie</span>";
|
||||
$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;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user