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";
45 $category =
GETPOST(
'category',
'alphanohtml');
46 $action =
GETPOST(
'action',
'aZ09');
47 $term =
GETPOST(
'term',
'alpha');
49 $search_start =
GETPOST(
'search_start',
'int');
50 $search_limit =
GETPOST(
'search_limit',
'int');
52 if (empty($user->rights->takepos->run)) {
57 $hookmanager->initHooks(array(
'takeposproductsearch'));
64 if ($action ==
'getProducts') {
68 if ($category ==
"supplements") {
71 $result = $object->fetch($category);
73 $prods = $object->getObjectsInCateg(
"product", 0, 0, 0,
getDolGlobalString(
'TAKEPOS_SORTPRODUCTFIELD'),
'ASC');
76 if (is_array($prods) && count($prods) > 0) {
77 foreach ($prods as $prod) {
80 $prod->load_stock(
'nobatch,novirtual');
81 if ($prod->stock_warehouse[
getDolGlobalString(
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
'takeposterminal'])]->real <= 0) {
88 $prod->price_formated =
price(
price2num($prod->price,
'MT'), 1, $langs, 1, -1, -1, $conf->currency);
89 $prod->price_ttc_formated =
price(
price2num($prod->price_ttc,
'MT'), 1, $langs, 1, -1, -1, $conf->currency);
94 echo json_encode($res);
96 echo
'Failed to load category with id='.dol_escape_htmltag($category);
98 } elseif ($action ==
'search' && $term !=
'') {
102 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
104 $thirdparty =
new Societe($db);
105 $result = $thirdparty->fetch(
'',
'',
'', $term);
107 if ($result && $thirdparty->id > 0) {
110 'rowid' => $thirdparty->id,
111 'name' => $thirdparty->name,
112 'barcode' => $thirdparty->barcode,
113 'object' =>
'thirdparty'
115 echo json_encode($rows);
120 $filteroncategids =
'';
121 if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
124 $arrayofcateg = $object->get_full_arbo(
'product', $conf->global->TAKEPOS_ROOT_CATEGORY_ID, 1);
125 if (is_array($arrayofcateg) && count($arrayofcateg) > 0) {
126 foreach ($arrayofcateg as $val) {
127 $filteroncategids .= ($filteroncategids ?
', ' :
'').$val[
'id'];
133 if (
isModEnabled(
'barcode') && !empty($barcode_rules)) {
134 $barcode_rules_list = array();
137 $barcode_char_nb = 0;
138 $barcode_rules_arr = explode(
'+', $barcode_rules);
139 foreach ($barcode_rules_arr as $barcode_rules_values) {
140 $barcode_rules_values_arr = explode(
':', $barcode_rules_values);
141 if (count($barcode_rules_values_arr) == 2) {
142 $char_nb = intval($barcode_rules_values_arr[1]);
143 $barcode_rules_list[] = array(
'code' => $barcode_rules_values_arr[0],
'char_nb' => $char_nb);
144 $barcode_char_nb += $char_nb;
148 $barcode_value_list = array();
151 if ($barcode_length == $barcode_char_nb) {
155 foreach ($barcode_rules_list as $barcode_rule_arr) {
156 $code = $barcode_rule_arr[
'code'];
157 $char_nb = $barcode_rule_arr[
'char_nb'];
158 $barcode_value_list[$code] = substr($term, $barcode_offset, $char_nb);
159 $barcode_offset += $char_nb;
162 if (isset($barcode_value_list[
'ref'])) {
164 $sql =
"SELECT rowid, ref, label, tosell, tobuy, barcode, price, price_ttc";
165 $sql .=
" FROM " . $db->prefix() .
"product as p";
166 $sql .=
" WHERE entity IN (" .
getEntity(
'product') .
")";
167 $sql .=
" AND ref = '" . $db->escape($barcode_value_list[
'ref']) .
"'";
168 if ($filteroncategids) {
169 $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).
"))";
171 $sql .=
" AND tosell = 1";
172 $sql .=
" AND (barcode IS NULL OR barcode != '" . $db->escape($term) .
"')";
174 $resql = $db->query($sql);
176 if ($obj = $db->fetch_object(
$resql)) {
178 if (isset($barcode_value_list[
'qu'])) {
179 $qty_str = $barcode_value_list[
'qu'];
180 if (isset($barcode_value_list[
'qd'])) {
181 $qty_str .=
'.' . $barcode_value_list[
'qd'];
183 $qty = floatval($qty_str);
186 $ig =
'../public/theme/common/nophoto.png';
187 if (empty($conf->global->TAKEPOS_HIDE_PRODUCT_IMAGES)) {
189 $objProd->fetch($obj->rowid);
190 $image = $objProd->show_photos(
'product', $conf->product->multidir_output[$objProd->entity],
'small', 1);
193 preg_match(
'@src="([^"]+)"@', $image, $match);
194 $file = array_pop($match);
197 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
198 $ig = $file.
'&cache=1';
200 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
206 'rowid' => $obj->rowid,
208 'label' => $obj->label,
209 'tosell' => $obj->tosell,
210 'tobuy' => $obj->tobuy,
211 'barcode' => $obj->barcode,
212 'price' => $obj->price,
213 'price_ttc' => $obj->price_ttc,
214 'object' =>
'product',
223 if (count($rows) == 1) {
224 echo json_encode($rows);
230 $sql =
'SELECT p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc' ;
236 $parameters = array();
237 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
239 $sql .= $hookmanager->resPrint;
242 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
244 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_stock as ps';
245 $sql .=
' ON (p.rowid = ps.fk_product';
246 $sql .=
" AND ps.fk_entrepot = ".((int)
getDolGlobalInt(
"CASHDESK_ID_WAREHOUSE".$_SESSION[
'takeposterminal']));
250 $parameters = array();
251 $reshook = $hookmanager->executeHooks(
'printFieldListTables', $parameters);
253 $sql .= $hookmanager->resPrint;
256 $sql .=
' WHERE entity IN ('.getEntity(
'product').
')';
257 if ($filteroncategids) {
258 $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).
'))';
260 $sql .=
' AND tosell = 1';
262 $sql .=
' AND ps.reel > 0';
266 $parameters = array();
267 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
269 $sql .= $hookmanager->resPrint;
273 $sql.= $db->plimit($search_limit, $search_start);
275 $resql = $db->query($sql);
279 while ($obj = $db->fetch_object(
$resql)) {
281 $objProd->fetch($obj->rowid);
282 $image = $objProd->show_photos(
'product', $conf->product->multidir_output[$objProd->entity],
'small', 1);
285 preg_match(
'@src="([^"]+)"@', $image, $match);
286 $file = array_pop($match);
289 $ig =
'../public/theme/common/nophoto.png';
291 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
292 $ig = $file.
'&cache=1';
294 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
299 'rowid' => $obj->rowid,
301 'label' => $obj->label,
302 'tosell' => $obj->tosell,
303 'tobuy' => $obj->tobuy,
304 'barcode' => $obj->barcode,
305 'price' => $obj->price,
306 'price_ttc' => $obj->price_ttc,
307 'object' =>
'product',
310 'price_formated' =>
price(
price2num($obj->price,
'MT'), 1, $langs, 1, -1, -1, $conf->currency),
311 'price_ttc_formated' =>
price(
price2num($obj->price_ttc,
'MT'), 1, $langs, 1, -1, -1, $conf->currency)
315 $parameters[
'row'] = $row;
316 $parameters[
'obj'] = $obj;
317 $reshook = $hookmanager->executeHooks(
'completeAjaxReturnArray', $parameters);
320 if (count($hookmanager->resArray)) {
321 $row = $hookmanager->resArray;
327 if (count($hookmanager->resArray)) {
328 $rows[] = $hookmanager->resArray;
334 echo json_encode($rows);
336 echo
'Failed to search product : '.$db->lasterror();
338 } elseif ($action ==
"opendrawer" && $term !=
'') {
339 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
343 $printer->initPrinter(
getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term));
348 } elseif ($action ==
"printinvoiceticket" && $term !=
'' && $id > 0 && !empty($user->rights->facture->lire)) {
349 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
350 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
358 } elseif ($action ==
'getInvoice') {
361 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
368 echo json_encode($object);
369 } elseif ($action ==
'thecheck') {
370 $place =
GETPOST(
'place',
'alpha');
371 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
372 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.
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.