126 lines
4.4 KiB
PHP
126 lines
4.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||
|
|
|
||
|
|
if(isset($_REQUEST['as_inputSearch']) && $_REQUEST['as_inputSearch'] != '') {
|
||
|
|
$AS_INPUTSEARCH = strtoupper($_REQUEST['as_inputSearch']);
|
||
|
|
|
||
|
|
$language_translate = array(
|
||
|
|
'en_us' => 'en',
|
||
|
|
'ge_ge' => 'de',
|
||
|
|
'pl_pl' => 'pl'
|
||
|
|
);
|
||
|
|
|
||
|
|
if(isset($_REQUEST['ecmlanguage']) && $_REQUEST['ecmlanguage'] != '') {
|
||
|
|
if(isset($language_translate[$_REQUEST['ecmlanguage']]) && $language_translate[$_REQUEST['ecmlanguage']] != '') {
|
||
|
|
$use_language = $language_translate[$_REQUEST['ecmlanguage']];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$query = "SELECT DISTINCT";
|
||
|
|
$query .= " `pr`.`id`";
|
||
|
|
$query .= ", `pr`.`code`";
|
||
|
|
$query .= ", `pr`.`name`";
|
||
|
|
$query .= ", `pr`.`selling_price`";
|
||
|
|
$query .= ", `pr`.`purchase_price`";
|
||
|
|
$query .= ", `pr`.`vat_id`";
|
||
|
|
$query .= ", `pr`.`vat_name`";
|
||
|
|
$query .= ", `pr`.`vat_value`";
|
||
|
|
$query .= ", `pr`.`exchange_rate_id` as `currency_id`";
|
||
|
|
$query .= ", `pr`.`product_category_id` as `category_id`";
|
||
|
|
$query .= ", `pr`.`usage_unit_id` as `unit_id`";
|
||
|
|
|
||
|
|
if(isset($use_language)) {
|
||
|
|
$query .= ", `pr_lang`.`short_description`";
|
||
|
|
$query .= ", `pr_lang`.`long_description`";
|
||
|
|
}
|
||
|
|
|
||
|
|
$query .= " FROM";
|
||
|
|
$query .= " `ecmproducts` as `pr`";
|
||
|
|
if(isset($use_language))
|
||
|
|
$query .= " LEFT JOIN `ecmproduct_language_".$use_language."_view` as `pr_lang` ON `pr`.`id` = `pr_lang`.`ecmproduct_id`";
|
||
|
|
|
||
|
|
$query .= " WHERE";
|
||
|
|
$query .= " (";
|
||
|
|
$query .= "UPPER(`pr`.`code`) LIKE '%$AS_INPUTSEARCH'";
|
||
|
|
$query .= " || UPPER(`pr`.`code`) LIKE '$AS_INPUTSEARCH%'";
|
||
|
|
$query .= " || UPPER(`pr`.`code`) LIKE '%$AS_INPUTSEARCH%'";
|
||
|
|
$query .= " || UPPER(`pr`.`name`) LIKE '%$AS_INPUTSEARCH'";
|
||
|
|
$query .= " || UPPER(`pr`.`name`) LIKE '$AS_INPUTSEARCH%'";
|
||
|
|
$query .= " || UPPER(`pr`.`name`) LIKE '%$AS_INPUTSEARCH%'";
|
||
|
|
|
||
|
|
if(isset($use_language)) {
|
||
|
|
$query .= " || UPPER(`pr_lang`.`long_description`) LIKE '%$AS_INPUTSEARCH'";
|
||
|
|
$query .= " || UPPER(`pr_lang`.`long_description`) LIKE '%$AS_INPUTSEARCH%'";
|
||
|
|
$query .= " || UPPER(`pr_lang`.`long_description`) LIKE '$AS_INPUTSEARCH%'";
|
||
|
|
$query .= " || UPPER(`pr_lang`.`short_description`) LIKE '%$AS_INPUTSEARCH'";
|
||
|
|
$query .= " || UPPER(`pr_lang`.`short_description`) LIKE '%$AS_INPUTSEARCH%'";
|
||
|
|
$query .= " || UPPER(`pr_lang`.`short_description`) LIKE '$AS_INPUTSEARCH%'";
|
||
|
|
}
|
||
|
|
|
||
|
|
$query .= ")";
|
||
|
|
$query .= " AND `pr`.`deleted`='0'";
|
||
|
|
|
||
|
|
$result = $GLOBALS['db']->query($query);
|
||
|
|
//print $query;
|
||
|
|
|
||
|
|
global $sugar_config;
|
||
|
|
$defaultCurrency = $sugar_config['default_currency_symbol'];
|
||
|
|
$currencies = array ( -99 => $defaultCurrency );
|
||
|
|
|
||
|
|
$arr = array();
|
||
|
|
if($result)
|
||
|
|
while($row = $GLOBALS['db']->fetchByAssoc($result)) {
|
||
|
|
|
||
|
|
$row['price'] = $row['selling_price'];
|
||
|
|
|
||
|
|
$row['purchase_price'] = format_number($row['purchase_price']);
|
||
|
|
|
||
|
|
$row['selling_price'] = format_number($row['selling_price']);
|
||
|
|
|
||
|
|
|
||
|
|
if(array_key_exists($row['currency_id'],$currencies))
|
||
|
|
$row['currency_symbol'] = $currencies[$row['currency_id']];
|
||
|
|
else {
|
||
|
|
|
||
|
|
$query = "SELECT symbol FROM currencies WHERE id='".$row['currency_id']."' AND deleted=0;";
|
||
|
|
$result2 = $GLOBALS['db']->query($query);
|
||
|
|
if($result2) {
|
||
|
|
$row2 = $GLOBALS['db']->fetchByAssoc($result2);
|
||
|
|
if($row2) {
|
||
|
|
$currencies[$id] = $row2['symbol'];
|
||
|
|
$row['currency_symbol'] = $row2['symbol'];
|
||
|
|
} else $row['currency_symbol'] = '';
|
||
|
|
} else $row['currency_symbol'] = '';
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if(isset($use_language)) {
|
||
|
|
if(strpos(strtoupper($row['long_description']), $AS_INPUTSEARCH) !== false)
|
||
|
|
$row['name'] = $row['long_description'];
|
||
|
|
else
|
||
|
|
if(strpos(strtoupper($row['short_description']), $AS_INPUTSEARCH) !== false)
|
||
|
|
$row['name'] = $row['short_description'];
|
||
|
|
else
|
||
|
|
if(strpos(strtoupper($row['name']), $AS_INPUTSEARCH) === false || strpos(strtoupper($row['code']), $AS_INPUTSEARCH) !== false) {
|
||
|
|
if(isset($row['long_description']) && $row['long_description'] != '')
|
||
|
|
$row['name'] = $row['long_description'];
|
||
|
|
else
|
||
|
|
if(isset($row['short_description']) && $row['short_description'] != '')
|
||
|
|
$row['name'] = $row['short_description'];
|
||
|
|
}
|
||
|
|
unset($row['long_description'], $row['short_description']);
|
||
|
|
}
|
||
|
|
|
||
|
|
$arr[] = $row;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if(count($arr) > 0) {
|
||
|
|
$json = getJSONobj();
|
||
|
|
echo str_replace(""", '\"', $json->encode($arr));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
?>
|