24 if (!defined(
'NOTOKENRENEWAL')) {
25 define(
'NOTOKENRENEWAL',
'1');
27 if (!defined(
'NOREQUIREMENU')) {
28 define(
'NOREQUIREMENU',
'1');
30 if (!defined(
'NOREQUIREHTML')) {
31 define(
'NOREQUIREHTML',
'1');
33 if (!defined(
'NOREQUIREAJAX')) {
34 define(
'NOREQUIREAJAX',
'1');
36 if (!defined(
'NOBROWSERNOTIF')) {
37 define(
'NOBROWSERNOTIF',
'1');
41 require
'../../main.inc.php';
42 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
43 require_once DOL_DOCUMENT_ROOT.
"/product/class/product.class.php";
44 require_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');
53 if (empty($user->rights->takepos->run)) {
58 $hookmanager->initHooks(array(
'takeposproductsearch'));
70 if ($action ==
'getProducts') {
75 $result = $thirdparty->fetch(
GETPOSTINT(
'thirdpartyid'));
77 $pricelevel = $thirdparty->price_level;
82 if ($category ==
"supplements") {
85 $result = $object->fetch($category);
87 $prods = $object->getObjectsInCateg(
"product", 0, 0, 0,
getDolGlobalString(
'TAKEPOS_SORTPRODUCTFIELD'),
'ASC');
90 if (is_array($prods) && count($prods) > 0) {
91 foreach ($prods as $prod) {
94 $prod->load_stock(
'nobatch,novirtual');
95 if ($prod->stock_warehouse[
getDolGlobalString(
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
'takeposterminal'])]->real <= 0) {
102 $prod->price_formated =
price(
price2num(empty($prod->multiprices[$pricelevel]) ? $prod->price : $prod->multiprices[$pricelevel],
'MT'), 1, $langs, 1, -1, -1, $conf->currency);
103 $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);
108 echo json_encode($res);
110 echo
'Failed to load category with id='.dol_escape_htmltag($category);
112 } elseif ($action ==
'search' && $term !=
'') {
116 $result = $thirdparty->fetch(
'',
'',
'', $term);
118 if ($result && $thirdparty->id > 0) {
121 'rowid' => $thirdparty->id,
122 'name' => $thirdparty->name,
123 'barcode' => $thirdparty->barcode,
124 'object' =>
'thirdparty'
126 echo json_encode($rows);
132 $result = $thirdparty->fetch(
GETPOSTINT(
'thirdpartyid'));
134 $pricelevel = $thirdparty->price_level;
139 $filteroncategids =
'';
140 if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
143 $arrayofcateg = $object->get_full_arbo(
'product', $conf->global->TAKEPOS_ROOT_CATEGORY_ID, 1);
144 if (is_array($arrayofcateg) && count($arrayofcateg) > 0) {
145 foreach ($arrayofcateg as $val) {
146 $filteroncategids .= ($filteroncategids ?
', ' :
'').$val[
'id'];
152 if (
isModEnabled(
'barcode') && !empty($barcode_rules)) {
153 $barcode_rules_list = array();
156 $barcode_char_nb = 0;
157 $barcode_rules_arr = explode(
'+', $barcode_rules);
158 foreach ($barcode_rules_arr as $barcode_rules_values) {
159 $barcode_rules_values_arr = explode(
':', $barcode_rules_values);
160 if (count($barcode_rules_values_arr) == 2) {
161 $char_nb = intval($barcode_rules_values_arr[1]);
162 $barcode_rules_list[] = array(
'code' => $barcode_rules_values_arr[0],
'char_nb' => $char_nb);
163 $barcode_char_nb += $char_nb;
167 $barcode_value_list = array();
170 if ($barcode_length == $barcode_char_nb) {
174 foreach ($barcode_rules_list as $barcode_rule_arr) {
175 $code = $barcode_rule_arr[
'code'];
176 $char_nb = $barcode_rule_arr[
'char_nb'];
177 $barcode_value_list[$code] = substr($term, $barcode_offset, $char_nb);
178 $barcode_offset += $char_nb;
181 if (isset($barcode_value_list[
'ref'])) {
183 $sql =
"SELECT rowid, ref, label, tosell, tobuy, barcode, price, price_ttc";
184 $sql .=
" FROM " . $db->prefix() .
"product as p";
185 $sql .=
" WHERE entity IN (" .
getEntity(
'product') .
")";
186 $sql .=
" AND ref = '" . $db->escape($barcode_value_list[
'ref']) .
"'";
187 if ($filteroncategids) {
188 $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).
"))";
190 $sql .=
" AND tosell = 1";
191 $sql .=
" AND (barcode IS NULL OR barcode <> '" . $db->escape($term) .
"')";
193 $resql = $db->query($sql);
195 if ($obj = $db->fetch_object(
$resql)) {
197 if (isset($barcode_value_list[
'qu'])) {
198 $qty_str = $barcode_value_list[
'qu'];
199 if (isset($barcode_value_list[
'qd'])) {
200 $qty_str .=
'.' . $barcode_value_list[
'qd'];
202 $qty = floatval($qty_str);
206 $objProd->fetch($obj->rowid);
208 $ig =
'../public/theme/common/nophoto.png';
209 if (empty($conf->global->TAKEPOS_HIDE_PRODUCT_IMAGES)) {
210 $image = $objProd->show_photos(
'product', $conf->product->multidir_output[$objProd->entity],
'small', 1);
213 preg_match(
'@src="([^"]+)"@', $image, $match);
214 $file = array_pop($match);
217 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
218 $ig = $file.
'&cache=1';
220 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
226 'rowid' => $obj->rowid,
228 'label' => $obj->label,
229 'tosell' => $obj->tosell,
230 'tobuy' => $obj->tobuy,
231 'barcode' => $obj->barcode,
232 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
233 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
234 'object' =>
'product',
243 if (count($rows) == 1) {
244 echo json_encode($rows);
250 $sql =
'SELECT p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc' ;
259 $parameters = array();
260 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
262 $sql .= $hookmanager->resPrint;
265 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
272 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'product_stock as ps';
273 $sql .=
' ON (p.rowid = ps.fk_product';
274 $sql .=
" AND ps.fk_entrepot = ".((int)
getDolGlobalInt(
"CASHDESK_ID_WAREHOUSE".$_SESSION[
'takeposterminal']));
279 $parameters = array();
280 $reshook = $hookmanager->executeHooks(
'printFieldListTables', $parameters);
282 $sql .= $hookmanager->resPrint;
285 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
286 if ($filteroncategids) {
287 $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).
'))';
289 $sql .=
' AND p.tosell = 1';
291 $sql .=
' AND ps.reel > 0';
295 $parameters = array();
296 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
298 $sql .= $hookmanager->resPrint;
302 $sql.= $db->plimit($search_limit, $search_start);
304 $resql = $db->query($sql);
308 while ($obj = $db->fetch_object(
$resql)) {
310 $objProd->fetch($obj->rowid);
311 $image = $objProd->show_photos(
'product', $conf->product->multidir_output[$objProd->entity],
'small', 1);
314 preg_match(
'@src="([^"]+)"@', $image, $match);
315 $file = array_pop($match);
318 $ig =
'../public/theme/common/nophoto.png';
320 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
321 $ig = $file.
'&cache=1';
323 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
328 'rowid' => $obj->rowid,
330 'label' => $obj->label,
331 'tosell' => $obj->tosell,
332 'tobuy' => $obj->tobuy,
333 'barcode' => $obj->barcode,
334 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
335 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
336 'object' =>
'product',
339 'price_formated' =>
price(
price2num(empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
'MT'), 1, $langs, 1, -1, -1, $conf->currency),
340 '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)
344 $parameters[
'row'] = $row;
345 $parameters[
'obj'] = $obj;
346 $reshook = $hookmanager->executeHooks(
'completeAjaxReturnArray', $parameters);
349 if (count($hookmanager->resArray)) {
350 $row = $hookmanager->resArray;
356 if (count($hookmanager->resArray)) {
357 $rows[] = $hookmanager->resArray;
363 echo json_encode($rows);
365 echo
'Failed to search product : '.$db->lasterror();
367 } elseif ($action ==
"opendrawer" && $term !=
'') {
368 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
372 $printer->initPrinter(
getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term));
377 } elseif ($action ==
"printinvoiceticket" && $term !=
'' && $id > 0 && !empty($user->rights->facture->lire)) {
378 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
379 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
387 } elseif ($action ==
'getInvoice') {
390 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
397 echo json_encode($object);
398 } elseif ($action ==
'thecheck') {
399 $place =
GETPOST(
'place',
'alpha');
400 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
401 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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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 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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return 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(!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.