25if (!defined(
'NOTOKENRENEWAL')) {
26 define(
'NOTOKENRENEWAL',
'1');
28if (!defined(
'NOREQUIREMENU')) {
29 define(
'NOREQUIREMENU',
'1');
31if (!defined(
'NOREQUIREHTML')) {
32 define(
'NOREQUIREHTML',
'1');
34if (!defined(
'NOREQUIREAJAX')) {
35 define(
'NOREQUIREAJAX',
'1');
37if (!defined(
'NOBROWSERNOTIF')) {
38 define(
'NOBROWSERNOTIF',
'1');
42require
'../../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
44require_once DOL_DOCUMENT_ROOT.
"/product/class/product.class.php";
45require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
54$category =
GETPOST(
'category',
'alphanohtml');
55$action =
GETPOST(
'action',
'aZ09');
56$term =
GETPOST(
'term',
'alpha');
61if (!$user->hasRight(
'takepos',
'run')) {
66$hookmanager->initHooks(array(
'takeposproductsearch'));
78if ($action ==
'getProducts' && $user->hasRight(
'takepos',
'run')) {
79 $tosell = GETPOSTISSET(
'tosell') ?
GETPOSTINT(
'tosell') :
'';
80 $limit = GETPOSTISSET(
'limit') ?
GETPOSTINT(
'limit') : 0;
81 $offset = GETPOSTISSET(
'offset') ?
GETPOSTINT(
'offset') : 0;
87 $result = $thirdparty->fetch(
GETPOSTINT(
'thirdpartyid'));
89 $pricelevel = $thirdparty->price_level;
94 if ($category ==
"supplements") {
96 if (empty($category)) {
97 echo
'Error, the category to use for supplements is not defined. Go into setup of module TakePOS.';
102 $result =
$object->fetch($category);
106 $filter =
'(o.tosell:=:'.((int) $tosell).
')';
108 $prods =
$object->getObjectsInCateg(
"product", 0, $limit, $offset,
getDolGlobalString(
'TAKEPOS_SORTPRODUCTFIELD'),
'ASC', $filter);
111 if (is_array($prods) && count($prods) > 0) {
112 foreach ($prods as $prod) {
115 $prod->load_stock(
'nobatch,novirtual');
116 if ($prod->stock_warehouse[
getDolGlobalString(
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
'takeposterminal'])]->real <= 0) {
120 unset($prod->fields);
123 $prod->price_formated =
price(
price2num(empty($prod->multiprices[$pricelevel]) ? $prod->price : $prod->multiprices[$pricelevel],
'MT'), 1, $langs, 1, -1, -1,
$conf->currency);
124 $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);
129 echo json_encode($res);
131 echo
'Failed to load category with id='.dol_escape_htmltag($category);
133} elseif ($action ==
'search' && $term !=
'' && $user->hasRight(
'takepos',
'run')) {
137 $result = $thirdparty->fetch(
'',
'',
'', $term);
139 if ($result && $thirdparty->id > 0) {
142 'rowid' => $thirdparty->id,
143 'name' => $thirdparty->name,
144 'barcode' => $thirdparty->barcode,
145 'object' =>
'thirdparty'
147 echo json_encode($rows);
153 $result = $thirdparty->fetch(
GETPOSTINT(
'thirdpartyid'));
155 $pricelevel = $thirdparty->price_level;
160 $filteroncategids =
'';
165 if (is_array($arrayofcateg) && count($arrayofcateg) > 0) {
166 foreach ($arrayofcateg as $val) {
167 $filteroncategids .= ($filteroncategids ?
', ' :
'').$val[
'id'];
173 if (isModEnabled(
'barcode') && !empty($barcode_rules)) {
174 $barcode_rules_list = array();
177 $barcode_char_nb = 0;
178 $barcode_rules_arr = explode(
'+', $barcode_rules);
179 foreach ($barcode_rules_arr as $barcode_rules_values) {
180 $barcode_rules_values_arr = explode(
':', $barcode_rules_values);
181 if (count($barcode_rules_values_arr) == 2) {
182 $char_nb = intval($barcode_rules_values_arr[1]);
183 $barcode_rules_list[] = array(
'code' => $barcode_rules_values_arr[0],
'char_nb' => $char_nb);
184 $barcode_char_nb += $char_nb;
188 $barcode_value_list = array();
191 if ($barcode_length == $barcode_char_nb) {
195 foreach ($barcode_rules_list as $barcode_rule_arr) {
196 $code = $barcode_rule_arr[
'code'];
197 $char_nb = $barcode_rule_arr[
'char_nb'];
198 $barcode_value_list[$code] = substr($term, $barcode_offset, $char_nb);
199 $barcode_offset += $char_nb;
202 if (isset($barcode_value_list[
'ref'])) {
204 $sql =
"SELECT rowid, ref, label, tosell, tobuy, barcode, price, price_ttc";
205 $sql .=
" FROM " . $db->prefix() .
"product as p";
206 $sql .=
" WHERE entity IN (" .
getEntity(
'product') .
")";
207 $sql .=
" AND ref = '" . $db->escape($barcode_value_list[
'ref']) .
"'";
208 if ($filteroncategids) {
209 $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).
"))";
211 $sql .=
" AND tosell = 1";
212 $sql .=
" AND (barcode IS NULL OR barcode <> '" . $db->escape($term) .
"')";
214 $resql = $db->query($sql);
215 if ($resql && $db->num_rows($resql) == 1) {
216 if ($obj = $db->fetch_object($resql)) {
218 if (isset($barcode_value_list[
'qu'])) {
219 $qty_str = $barcode_value_list[
'qu'];
220 if (isset($barcode_value_list[
'qd'])) {
221 $qty_str .=
'.' . $barcode_value_list[
'qd'];
223 $qty = (float) $qty_str;
227 $objProd->fetch($obj->rowid);
229 $ig =
'../public/theme/common/nophoto.png';
231 $image = $objProd->show_photos(
'product',
$conf->product->multidir_output[$objProd->entity],
'small', 1);
234 preg_match(
'@src="([^"]+)"@', $image, $match);
235 $file = array_pop($match);
238 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
239 $ig = $file.
'&cache=1';
241 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
247 'rowid' => $obj->rowid,
249 'label' => $obj->label,
250 'tosell' => $obj->tosell,
251 'tobuy' => $obj->tobuy,
253 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
254 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
255 'object' =>
'product',
264 if (count($rows) == 1) {
265 echo json_encode($rows);
271 $sql =
'SELECT p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc' ;
273 if (
getDolGlobalInt(
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
'takeposterminal'])) {
276 $sql .=
', SUM(ps.reel) as reel';
284 $parameters = array();
285 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
287 $sql .= $hookmanager->resPrint;
290 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
297 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_stock as ps';
298 $sql .=
' ON (p.rowid = ps.fk_product';
300 $sql .=
" AND ps.fk_entrepot = ".((int)
getDolGlobalInt(
"CASHDESK_ID_WAREHOUSE".$_SESSION[
'takeposterminal']));
306 $parameters = array();
307 $reshook = $hookmanager->executeHooks(
'printFieldListTables', $parameters);
309 $sql .= $hookmanager->resPrint;
312 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
313 if ($filteroncategids) {
314 $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).
'))';
316 $sql .=
' AND p.tosell = 1';
318 $sql .=
' AND ps.reel > 0';
322 $parameters = array();
323 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
325 $sql .= $hookmanager->resPrint;
329 $sql .=
' GROUP BY p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc';
331 $parameters = array();
332 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
334 $sql .= $hookmanager->resPrint;
336 $sql .=
' HAVING SUM(ps.reel) > 0';
340 $sql.= $db->plimit($search_limit, $search_start);
342 $resql = $db->query($sql);
346 while ($obj = $db->fetch_object($resql)) {
348 $objProd->fetch($obj->rowid);
349 $image = $objProd->show_photos(
'product',
$conf->product->multidir_output[$objProd->entity],
'small', 1);
352 preg_match(
'@src="([^"]+)"@', $image, $match);
353 $file = array_pop($match);
356 $ig =
'../public/theme/common/nophoto.png';
358 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
359 $ig = $file.
'&cache=1';
361 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
366 'rowid' => $obj->rowid,
368 'label' => $obj->label,
369 'tosell' => $obj->tosell,
370 'tobuy' => $obj->tobuy,
371 'barcode' => $obj->barcode,
372 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
373 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
374 'object' =>
'product',
377 'price_formated' =>
price(
price2num(empty($objProd->multiprices[$pricelevel]) ? $obj->
price : $objProd->multiprices[$pricelevel],
'MT'), 1, $langs, 1, -1, -1,
$conf->currency),
378 '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)
382 $parameters[
'row'] = $row;
383 $parameters[
'obj'] = $obj;
384 $reshook = $hookmanager->executeHooks(
'completeAjaxReturnArray', $parameters);
387 if (count($hookmanager->resArray)) {
388 $row = $hookmanager->resArray;
395 if (count($hookmanager->resArray)) {
396 $rows[] = $hookmanager->resArray;
402 echo json_encode($rows);
404 echo
'Failed to search product : '.$db->lasterror();
406} elseif ($action ==
"opendrawer" && $term !=
'' && $user->hasRight(
'takepos',
'run')) {
408 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
412 $printer->initPrinter(
getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term));
414 if ($printer->getPrintConnector()) {
418 print
'Failed to init printer with ID='.getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term);
421} elseif ($action ==
"printinvoiceticket" && $term !=
'' && $id > 0 && $user->hasRight(
'takepos',
'run') && $user->hasRight(
'facture',
'lire')) {
424 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
425 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
433} elseif ($action ==
'getInvoice' && $user->hasRight(
'takepos',
'run')) {
436 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
444} elseif ($action ==
'thecheck' && $user->hasRight(
'takepos',
'run')) {
447 $place =
GETPOST(
'place',
'alpha');
448 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
449 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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 the value of a $_GET or $_POST supervariable, converted into integer.
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 a 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.