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 (empty($user->rights->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 =
'';
153 if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
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 = floatval($qty_str);
219 $objProd->fetch($obj->rowid);
221 $ig =
'../public/theme/common/nophoto.png';
222 if (empty($conf->global->TAKEPOS_HIDE_PRODUCT_IMAGES)) {
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,
244 'barcode' => $obj->barcode,
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' ;
272 $parameters = array();
273 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
275 $sql .= $hookmanager->resPrint;
278 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
285 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'product_stock as ps';
286 $sql .=
' ON (p.rowid = ps.fk_product';
287 $sql .=
" AND ps.fk_entrepot = ".((int)
getDolGlobalInt(
"CASHDESK_ID_WAREHOUSE".$_SESSION[
'takeposterminal']));
292 $parameters = array();
293 $reshook = $hookmanager->executeHooks(
'printFieldListTables', $parameters);
295 $sql .= $hookmanager->resPrint;
298 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
299 if ($filteroncategids) {
300 $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).
'))';
302 $sql .=
' AND p.tosell = 1';
304 $sql .=
' AND ps.reel > 0';
308 $parameters = array();
309 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
311 $sql .= $hookmanager->resPrint;
315 $sql.= $db->plimit($search_limit, $search_start);
317 $resql = $db->query($sql);
321 while ($obj = $db->fetch_object($resql)) {
323 $objProd->fetch($obj->rowid);
324 $image = $objProd->show_photos(
'product', $conf->product->multidir_output[$objProd->entity],
'small', 1);
327 preg_match(
'@src="([^"]+)"@', $image, $match);
328 $file = array_pop($match);
331 $ig =
'../public/theme/common/nophoto.png';
333 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
334 $ig = $file.
'&cache=1';
336 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
341 'rowid' => $obj->rowid,
343 'label' => $obj->label,
344 'tosell' => $obj->tosell,
345 'tobuy' => $obj->tobuy,
346 'barcode' => $obj->barcode,
347 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
348 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
349 'object' =>
'product',
352 'price_formated' =>
price(
price2num(empty($objProd->multiprices[$pricelevel]) ? $obj->
price : $objProd->multiprices[$pricelevel],
'MT'), 1, $langs, 1, -1, -1, $conf->currency),
353 '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)
357 $parameters[
'row'] = $row;
358 $parameters[
'obj'] = $obj;
359 $reshook = $hookmanager->executeHooks(
'completeAjaxReturnArray', $parameters);
362 if (count($hookmanager->resArray)) {
363 $row = $hookmanager->resArray;
369 if (count($hookmanager->resArray)) {
370 $rows[] = $hookmanager->resArray;
376 echo json_encode($rows);
378 echo
'Failed to search product : '.$db->lasterror();
380} elseif ($action ==
"opendrawer" && $term !=
'') {
381 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
385 $printer->initPrinter(
getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term));
390} elseif ($action ==
"printinvoiceticket" && $term !=
'' && $id > 0 && $user->hasRight(
'facture',
'lire')) {
391 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
392 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
400} elseif ($action ==
'getInvoice') {
403 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
410 echo json_encode($object);
411} elseif ($action ==
'thecheck') {
412 $place =
GETPOST(
'place',
'alpha');
413 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
414 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 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.