24if (!defined(
'NOTOKENRENEWAL')) {
25 define(
'NOTOKENRENEWAL',
'1');
27if (!defined(
'NOREQUIREMENU')) {
28 define(
'NOREQUIREMENU',
'1');
30if (!defined(
'NOREQUIREHTML')) {
31 define(
'NOREQUIREHTML',
'1');
33if (!defined(
'NOREQUIREAJAX')) {
34 define(
'NOREQUIREAJAX',
'1');
36if (!defined(
'NOBROWSERNOTIF')) {
37 define(
'NOBROWSERNOTIF',
'1');
41require
'../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
43require_once DOL_DOCUMENT_ROOT.
"/product/class/product.class.php";
44require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
46$category =
GETPOST(
'category',
'alphanohtml');
47$action =
GETPOST(
'action',
'aZ09');
48$term =
GETPOST(
'term',
'alpha');
50$search_start =
GETPOST(
'search_start',
'int');
51$search_limit =
GETPOST(
'search_limit',
'int');
53if (!$user->hasRight(
'takepos',
'run')) {
58$hookmanager->initHooks(array(
'takeposproductsearch'));
70if ($action ==
'getProducts') {
71 $tosell = GETPOSTISSET(
'tosell') ?
GETPOST(
'tosell',
'int') :
'';
72 $limit = GETPOSTISSET(
'limit') ?
GETPOST(
'limit',
'int') : 0;
73 $offset = GETPOSTISSET(
'offset') ?
GETPOST(
'offset',
'int') : 0;
79 $result = $thirdparty->fetch(
GETPOSTINT(
'thirdpartyid'));
81 $pricelevel = $thirdparty->price_level;
86 if ($category ==
"supplements") {
88 if (empty($category)) {
89 echo
'Error, the category to use for supplements is not defined. Go into setup of module TakePOS.';
94 $result = $object->fetch($category);
98 $filter = array(
'customsql' =>
'o.tosell = '.((
int) $tosell));
100 $prods = $object->getObjectsInCateg(
"product", 0, $limit, $offset,
getDolGlobalString(
'TAKEPOS_SORTPRODUCTFIELD'),
'ASC', $filter);
103 if (is_array($prods) && count($prods) > 0) {
104 foreach ($prods as $prod) {
107 $prod->load_stock(
'nobatch,novirtual');
108 if ($prod->stock_warehouse[
getDolGlobalString(
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
'takeposterminal'])]->real <= 0) {
112 unset($prod->fields);
115 $prod->price_formated =
price(
price2num(empty($prod->multiprices[$pricelevel]) ? $prod->price : $prod->multiprices[$pricelevel],
'MT'), 1, $langs, 1, -1, -1, $conf->currency);
116 $prod->price_ttc_formated =
price(
price2num(empty($prod->multiprices_ttc[$pricelevel]) ? $prod->price_ttc : $prod->multiprices_ttc[$pricelevel],
'MT'), 1, $langs, 1, -1, -1, $conf->currency);
121 echo json_encode($res);
123 echo
'Failed to load category with id='.dol_escape_htmltag($category);
125} elseif ($action ==
'search' && $term !=
'') {
129 $result = $thirdparty->fetch(
'',
'',
'', $term);
131 if ($result && $thirdparty->id > 0) {
134 'rowid' => $thirdparty->id,
135 'name' => $thirdparty->name,
136 'barcode' => $thirdparty->barcode,
137 'object' =>
'thirdparty'
139 echo json_encode($rows);
145 $result = $thirdparty->fetch(
GETPOSTINT(
'thirdpartyid'));
147 $pricelevel = $thirdparty->price_level;
152 $filteroncategids =
'';
156 $arrayofcateg = $object->get_full_arbo(
'product', $conf->global->TAKEPOS_ROOT_CATEGORY_ID, 1);
157 if (is_array($arrayofcateg) && count($arrayofcateg) > 0) {
158 foreach ($arrayofcateg as $val) {
159 $filteroncategids .= ($filteroncategids ?
', ' :
'').$val[
'id'];
165 if (isModEnabled(
'barcode') && !empty($barcode_rules)) {
166 $barcode_rules_list = array();
169 $barcode_char_nb = 0;
170 $barcode_rules_arr = explode(
'+', $barcode_rules);
171 foreach ($barcode_rules_arr as $barcode_rules_values) {
172 $barcode_rules_values_arr = explode(
':', $barcode_rules_values);
173 if (count($barcode_rules_values_arr) == 2) {
174 $char_nb = intval($barcode_rules_values_arr[1]);
175 $barcode_rules_list[] = array(
'code' => $barcode_rules_values_arr[0],
'char_nb' => $char_nb);
176 $barcode_char_nb += $char_nb;
180 $barcode_value_list = array();
183 if ($barcode_length == $barcode_char_nb) {
187 foreach ($barcode_rules_list as $barcode_rule_arr) {
188 $code = $barcode_rule_arr[
'code'];
189 $char_nb = $barcode_rule_arr[
'char_nb'];
190 $barcode_value_list[$code] = substr($term, $barcode_offset, $char_nb);
191 $barcode_offset += $char_nb;
194 if (isset($barcode_value_list[
'ref'])) {
196 $sql =
"SELECT rowid, ref, label, tosell, tobuy, barcode, price, price_ttc";
197 $sql .=
" FROM " . $db->prefix() .
"product as p";
198 $sql .=
" WHERE entity IN (" .
getEntity(
'product') .
")";
199 $sql .=
" AND ref = '" . $db->escape($barcode_value_list[
'ref']) .
"'";
200 if ($filteroncategids) {
201 $sql .=
" AND EXISTS (SELECT cp.fk_product FROM " . $db->prefix() .
"categorie_product as cp WHERE cp.fk_product = p.rowid AND cp.fk_categorie IN (".$db->sanitize($filteroncategids).
"))";
203 $sql .=
" AND tosell = 1";
204 $sql .=
" AND (barcode IS NULL OR barcode <> '" . $db->escape($term) .
"')";
206 $resql = $db->query($sql);
207 if ($resql && $db->num_rows($resql) == 1) {
208 if ($obj = $db->fetch_object($resql)) {
210 if (isset($barcode_value_list[
'qu'])) {
211 $qty_str = $barcode_value_list[
'qu'];
212 if (isset($barcode_value_list[
'qd'])) {
213 $qty_str .=
'.' . $barcode_value_list[
'qd'];
215 $qty = (float) $qty_str;
219 $objProd->fetch($obj->rowid);
221 $ig =
'../public/theme/common/nophoto.png';
223 $image = $objProd->show_photos(
'product', $conf->product->multidir_output[$objProd->entity],
'small', 1);
226 preg_match(
'@src="([^"]+)"@', $image, $match);
227 $file = array_pop($match);
230 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
231 $ig = $file.
'&cache=1';
233 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
239 'rowid' => $obj->rowid,
241 'label' => $obj->label,
242 'tosell' => $obj->tosell,
243 'tobuy' => $obj->tobuy,
245 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
246 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
247 'object' =>
'product',
256 if (count($rows) == 1) {
257 echo json_encode($rows);
263 $sql =
'SELECT p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc' ;
265 if (
getDolGlobalInt(
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
'takeposterminal'])) {
268 $sql .=
', SUM(ps.reel) as reel';
276 $parameters = array();
277 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
279 $sql .= $hookmanager->resPrint;
282 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
289 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_stock as ps';
290 $sql .=
' ON (p.rowid = ps.fk_product';
292 $sql .=
" AND ps.fk_entrepot = ".((int)
getDolGlobalInt(
"CASHDESK_ID_WAREHOUSE".$_SESSION[
'takeposterminal']));
298 $parameters = array();
299 $reshook = $hookmanager->executeHooks(
'printFieldListTables', $parameters);
301 $sql .= $hookmanager->resPrint;
304 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
305 if ($filteroncategids) {
306 $sql .=
' AND EXISTS (SELECT cp.fk_product FROM '.MAIN_DB_PREFIX.
'categorie_product as cp WHERE cp.fk_product = p.rowid AND cp.fk_categorie IN ('.$db->sanitize($filteroncategids).
'))';
308 $sql .=
' AND p.tosell = 1';
310 $sql .=
' AND ps.reel > 0';
314 $parameters = array();
315 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
317 $sql .= $hookmanager->resPrint;
321 $sql .=
' GROUP BY p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc';
323 $parameters = array();
324 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
326 $sql .= $hookmanager->resPrint;
328 $sql .=
' HAVING SUM(ps.reel) > 0';
332 $sql.= $db->plimit($search_limit, $search_start);
334 $resql = $db->query($sql);
338 while ($obj = $db->fetch_object($resql)) {
340 $objProd->fetch($obj->rowid);
341 $image = $objProd->show_photos(
'product', $conf->product->multidir_output[$objProd->entity],
'small', 1);
344 preg_match(
'@src="([^"]+)"@', $image, $match);
345 $file = array_pop($match);
348 $ig =
'../public/theme/common/nophoto.png';
350 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
351 $ig = $file.
'&cache=1';
353 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
358 'rowid' => $obj->rowid,
360 'label' => $obj->label,
361 'tosell' => $obj->tosell,
362 'tobuy' => $obj->tobuy,
363 'barcode' => $obj->barcode,
364 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
365 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
366 'object' =>
'product',
369 'price_formated' =>
price(
price2num(empty($objProd->multiprices[$pricelevel]) ? $obj->
price : $objProd->multiprices[$pricelevel],
'MT'), 1, $langs, 1, -1, -1, $conf->currency),
370 'price_ttc_formated' =>
price(
price2num(empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
'MT'), 1, $langs, 1, -1, -1, $conf->currency)
374 $parameters[
'row'] = $row;
375 $parameters[
'obj'] = $obj;
376 $reshook = $hookmanager->executeHooks(
'completeAjaxReturnArray', $parameters);
379 if (count($hookmanager->resArray)) {
380 $row = $hookmanager->resArray;
387 if (count($hookmanager->resArray)) {
388 $rows[] = $hookmanager->resArray;
394 echo json_encode($rows);
396 echo
'Failed to search product : '.$db->lasterror();
398} elseif ($action ==
"opendrawer" && $term !=
'') {
399 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
403 $printer->initPrinter(
getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term));
408} elseif ($action ==
"printinvoiceticket" && $term !=
'' && $id > 0 && $user->hasRight(
'facture',
'lire')) {
409 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
410 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
418} elseif ($action ==
'getInvoice') {
421 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
428 echo json_encode($object);
429} elseif ($action ==
'thecheck') {
430 $place =
GETPOST(
'place',
'alpha');
431 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
432 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
Class to manage categories.
Class to manage invoices.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Receipt Printers.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.