27if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL',
'1');
30if (!defined(
'NOREQUIREMENU')) {
31 define(
'NOREQUIREMENU',
'1');
33if (!defined(
'NOREQUIREHTML')) {
34 define(
'NOREQUIREHTML',
'1');
36if (!defined(
'NOREQUIREAJAX')) {
37 define(
'NOREQUIREAJAX',
'1');
39if (!defined(
'NOBROWSERNOTIF')) {
40 define(
'NOBROWSERNOTIF',
'1');
44require
'../../main.inc.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
53require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
54require_once DOL_DOCUMENT_ROOT.
"/product/class/product.class.php";
55require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
57$category =
GETPOST(
'category',
'alphanohtml');
58$action =
GETPOST(
'action',
'aZ09');
59$term =
GETPOST(
'term',
'alpha');
60$search_term =
GETPOST(
'search_term',
'alpha');
65if (!$user->hasRight(
'takepos',
'run')) {
70$hookmanager->initHooks(array(
'takeposproductsearch'));
82if ($action ==
'getProducts' && $user->hasRight(
'takepos',
'run')) {
91 $result = $thirdparty->fetch(
GETPOSTINT(
'thirdpartyid'));
93 $pricelevel = $thirdparty->price_level;
98 if ($category ==
"supplements") {
100 if (empty($category)) {
101 echo
'Error, the category to use for supplements is not defined. Go into setup of module TakePOS.';
106 $result =
$object->fetch($category);
110 $filter =
'(o.tosell:=:'.((int) $tosell).
')';
112 $prods =
$object->getObjectsInCateg(
"product", 0, $limit, $offset,
getDolGlobalString(
'TAKEPOS_SORTPRODUCTFIELD'),
'ASC', $filter);
115 if (is_array($prods) && count($prods) > 0) {
116 $productChildrenNb = 0;
117 foreach ($prods as $prod) {
118 '@phan-var-force Product $prod';
121 $productChildrenNb = $prod->hasFatherOrChild(1);
124 if ($productChildrenNb == 0) {
126 $prod->load_stock(
'nobatch,novirtual');
127 if ($prod->stock_warehouse[
getDolGlobalString(
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
'takeposterminal'])]->real <= 0) {
132 unset($prod->fields);
135 $prod->price_formated =
price(
price2num(empty($prod->multiprices[$pricelevel]) ? $prod->price : $prod->multiprices[$pricelevel],
'MT'), 1, $langs, 1, -1, -1,
$conf->currency);
136 $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);
143 $prod->rowid = $prod->id;
144 $parameters = array();
145 $parameters[
'row'] = array(
'rowid' => $prod->id,
'object' =>
'product');
146 $parameters[
'obj'] = $prod;
147 $hookmanager->executeHooks(
'takeposCompleteProductOrCategory', $parameters);
148 foreach ($hookmanager->resArray as $key => $val) {
149 if (!isset($prod->$key)) {
157 echo json_encode($res);
159 echo
'Failed to load category with id='.dol_escape_htmltag($category);
161} elseif ($action ==
'search' && $search_term !=
'' && $user->hasRight(
'takepos',
'run')) {
165 $result = $thirdparty->fetch(0,
'',
'', $search_term);
167 if ($result && $thirdparty->id > 0) {
170 'rowid' => $thirdparty->id,
171 'name' => $thirdparty->name,
172 'barcode' => $thirdparty->barcode,
173 'object' =>
'thirdparty'
175 echo json_encode($rows);
181 $result = $thirdparty->fetch(
GETPOSTINT(
'thirdpartyid'));
183 $pricelevel = $thirdparty->price_level;
188 $filteroncategids =
'';
193 if (is_array($arrayofcateg) && count($arrayofcateg) > 0) {
194 foreach ($arrayofcateg as $val) {
195 $filteroncategids .= ($filteroncategids ?
', ' :
'').$val[
'id'];
201 if (
isModEnabled(
'barcode') && !empty($barcode_rules)) {
202 $barcode_rules_list = array();
205 $barcode_char_nb = 0;
206 $barcode_rules_arr = explode(
'+', $barcode_rules);
207 foreach ($barcode_rules_arr as $barcode_rules_values) {
208 $barcode_rules_values_arr = explode(
':', $barcode_rules_values);
209 if (count($barcode_rules_values_arr) == 2) {
210 $char_nb = intval($barcode_rules_values_arr[1]);
211 $barcode_rules_list[] = array(
'code' => $barcode_rules_values_arr[0],
'char_nb' => $char_nb);
212 $barcode_char_nb += $char_nb;
216 $barcode_value_list = array();
219 if ($barcode_length == $barcode_char_nb) {
223 foreach ($barcode_rules_list as $barcode_rule_arr) {
224 $code = $barcode_rule_arr[
'code'];
225 $char_nb = $barcode_rule_arr[
'char_nb'];
226 $barcode_value_list[$code] = substr($search_term, $barcode_offset, $char_nb);
227 $barcode_offset += $char_nb;
230 if (isset($barcode_value_list[
'ref'])) {
232 $sql =
"SELECT rowid, ref, label, tosell, tobuy, barcode, price, price_ttc";
233 $sql .=
" FROM " . $db->prefix() .
"product as p";
234 $sql .=
" WHERE entity IN (" .
getEntity(
'product') .
")";
235 $sql .=
" AND ref = '" . $db->escape($barcode_value_list[
'ref']) .
"'";
236 if ($filteroncategids) {
237 $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).
"))";
239 $sql .=
" AND tosell = 1";
240 $sql .=
" AND (barcode IS NULL OR barcode <> '" . $db->escape($search_term) .
"')";
242 $resql = $db->query($sql);
243 if ($resql && $db->num_rows($resql) == 1) {
244 if ($obj = $db->fetch_object($resql)) {
246 if (isset($barcode_value_list[
'qu'])) {
247 $qty_str = $barcode_value_list[
'qu'];
248 if (isset($barcode_value_list[
'qd'])) {
249 $qty_str .=
'.' . $barcode_value_list[
'qd'];
251 $qty = (float) $qty_str;
255 $objProd->fetch($obj->rowid);
257 $ig =
'../public/theme/common/nophoto.png';
259 $image = $objProd->show_photos(
'product',
$conf->product->multidir_output[(
int) $objProd->entity],
'small', 1);
262 preg_match(
'@src="([^"]+)"@', $image, $match);
263 $file = array_pop($match);
266 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
267 $ig = $file.
'&cache=1';
269 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
275 'rowid' => $obj->rowid,
277 'label' => $obj->label,
278 'tosell' => $obj->tosell,
279 'tobuy' => $obj->tobuy,
280 'barcode' => $search_term,
281 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
282 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
283 'object' =>
'product',
292 if (count($rows) == 1) {
293 echo json_encode($rows);
299 $sql =
'SELECT p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc' ;
301 if (
getDolGlobalInt(
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
'takeposterminal'])) {
304 $sql .=
', SUM(ps.reel) as reel';
312 $parameters = array();
313 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
315 $sql .= $hookmanager->resPrint;
318 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
325 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_stock as ps';
326 $sql .=
' ON (p.rowid = ps.fk_product';
328 $sql .=
" AND ps.fk_entrepot = ".((int)
getDolGlobalInt(
"CASHDESK_ID_WAREHOUSE".$_SESSION[
'takeposterminal']));
334 $parameters = array();
335 $reshook = $hookmanager->executeHooks(
'printFieldListTables', $parameters);
337 $sql .= $hookmanager->resPrint;
340 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
341 if ($filteroncategids) {
342 $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).
'))';
344 $sql .=
' AND p.tosell = 1';
346 $sql .=
' AND ps.reel > 0';
348 $sql .=
natural_search(array(
'ref',
'label',
'barcode'), $search_term);
350 $parameters = array();
351 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
353 $sql .= $hookmanager->resPrint;
357 $sql .=
' GROUP BY p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc';
359 $parameters = array();
360 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
362 $sql .= $hookmanager->resPrint;
364 $sql .=
' HAVING SUM(ps.reel) > 0';
368 $sql .= $db->plimit($search_limit, $search_start);
370 $resql = $db->query($sql);
374 while ($obj = $db->fetch_object($resql)) {
376 $objProd->fetch($obj->rowid);
377 $image = $objProd->show_photos(
'product',
$conf->product->multidir_output[(
int) $objProd->entity],
'small', 1);
380 preg_match(
'@src="([^"]+)"@', $image, $match);
381 $file = array_pop($match);
384 $ig =
'../public/theme/common/nophoto.png';
386 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
387 $ig = $file.
'&cache=1';
389 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
394 'rowid' => $obj->rowid,
396 'label' => $obj->label,
397 'tosell' => $obj->tosell,
398 'tobuy' => $obj->tobuy,
399 'barcode' => $obj->barcode,
400 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
401 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
402 'object' =>
'product',
405 'price_formated' =>
price(
price2num(empty($objProd->multiprices[$pricelevel]) ? $obj->
price : $objProd->multiprices[$pricelevel],
'MT'), 1, $langs, 1, -1, -1,
$conf->currency),
406 '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)
409 $parameters = array();
410 $parameters[
'row'] = $row;
411 $parameters[
'obj'] = $obj;
412 $reshook = $hookmanager->executeHooks(
'takeposCompleteProductOrCategory', $parameters);
415 if (count($hookmanager->resArray)) {
416 $row = $hookmanager->resArray;
423 if (count($hookmanager->resArray)) {
424 $rows[] = $hookmanager->resArray;
430 echo json_encode($rows);
432 echo
'Failed to search product : '.$db->lasterror();
434} elseif ($action ==
"opendrawer" && $term !=
'' && $user->hasRight(
'takepos',
'run')) {
437 require_once DOL_DOCUMENT_ROOT.
'/takepos/class/dolreceiptprinter.class.php';
445 $printer->initPrinter(
getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term));
447 if ($printer->getPrintConnector()) {
451 print
'Failed to init printer with ID='.getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term);
454} elseif ($action ==
"printinvoiceticket" && $term !=
'' && $id > 0 && $user->hasRight(
'takepos',
'run')) {
457 require_once DOL_DOCUMENT_ROOT.
'/takepos/class/dolreceiptprinter.class.php';
458 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
466 $resultinccounter = 0;
467 $templateidtouse = 0;
479 $result =
$object->call_trigger(
'DOC_PREVIEW', $user);
485 $templateidtouse =
getDolGlobalInt(
'TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term);
488 if ($resultinccounter) {
492 print
'Failed to update print counter for object ID='.$object->id.
' so we refuse to print.';
495} elseif ($action ==
'getInvoice' && $user->hasRight(
'takepos',
'run')) {
498 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
511} elseif ($action ==
'thecheck' && $user->hasRight(
'takepos',
'run')) {
514 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
515 require_once DOL_DOCUMENT_ROOT.
'/takepos/class/dolreceiptprinter.class.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.