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') {
72 if ($category ==
"supplements") {
74 if (empty($category)) {
75 echo
'Error, the category to use for supplements is not defined. Go into setup of module TakePOS.';
80 $result = $object->fetch($category);
84 $filter = array(
'customsql' =>
'o.tosell = '.((
int) $tosell));
86 $prods = $object->getObjectsInCateg(
"product", 0, $limit, $offset,
getDolGlobalString(
'TAKEPOS_SORTPRODUCTFIELD'),
'ASC', $filter);
89 if (is_array($prods) && count($prods) > 0) {
90 foreach ($prods as $prod) {
93 $prod->load_stock(
'nobatch,novirtual');
94 if ($prod->stock_warehouse[
getDolGlobalString(
'CASHDESK_ID_WAREHOUSE'.$_SESSION[
'takeposterminal'])]->real <= 0) {
101 $prod->price_formated =
price(
price2num($prod->price,
'MT'), 1, $langs, 1, -1, -1, $conf->currency);
102 $prod->price_ttc_formated =
price(
price2num($prod->price_ttc,
'MT'), 1, $langs, 1, -1, -1, $conf->currency);
107 echo json_encode($res);
109 echo
'Failed to load category with id='.dol_escape_htmltag($category);
111 } elseif ($action ==
'search' && $term !=
'') {
115 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
117 $thirdparty =
new Societe($db);
118 $result = $thirdparty->fetch(
'',
'',
'', $term);
120 if ($result && $thirdparty->id > 0) {
123 'rowid' => $thirdparty->id,
124 'name' => $thirdparty->name,
125 'barcode' => $thirdparty->barcode,
126 'object' =>
'thirdparty'
128 echo json_encode($rows);
133 $filteroncategids =
'';
134 if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
137 $arrayofcateg = $object->get_full_arbo(
'product', $conf->global->TAKEPOS_ROOT_CATEGORY_ID, 1);
138 if (is_array($arrayofcateg) && count($arrayofcateg) > 0) {
139 foreach ($arrayofcateg as $val) {
140 $filteroncategids .= ($filteroncategids ?
', ' :
'').$val[
'id'];
146 if (
isModEnabled(
'barcode') && !empty($barcode_rules)) {
147 $barcode_rules_list = array();
150 $barcode_char_nb = 0;
151 $barcode_rules_arr = explode(
'+', $barcode_rules);
152 foreach ($barcode_rules_arr as $barcode_rules_values) {
153 $barcode_rules_values_arr = explode(
':', $barcode_rules_values);
154 if (count($barcode_rules_values_arr) == 2) {
155 $char_nb = intval($barcode_rules_values_arr[1]);
156 $barcode_rules_list[] = array(
'code' => $barcode_rules_values_arr[0],
'char_nb' => $char_nb);
157 $barcode_char_nb += $char_nb;
161 $barcode_value_list = array();
164 if ($barcode_length == $barcode_char_nb) {
168 foreach ($barcode_rules_list as $barcode_rule_arr) {
169 $code = $barcode_rule_arr[
'code'];
170 $char_nb = $barcode_rule_arr[
'char_nb'];
171 $barcode_value_list[$code] = substr($term, $barcode_offset, $char_nb);
172 $barcode_offset += $char_nb;
175 if (isset($barcode_value_list[
'ref'])) {
177 $sql =
"SELECT rowid, ref, label, tosell, tobuy, barcode, price, price_ttc";
178 $sql .=
" FROM " . $db->prefix() .
"product as p";
180 $sql .=
" AND ref = '" . $db->escape($barcode_value_list[
'ref']) .
"'";
181 if ($filteroncategids) {
182 $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).
"))";
184 $sql .=
" AND tosell = 1";
185 $sql .=
" AND (barcode IS NULL OR barcode <> '" . $db->escape($term) .
"')";
187 $resql = $db->query(
$sql);
188 if ($resql && $db->num_rows($resql) == 1) {
189 if ($obj = $db->fetch_object($resql)) {
191 if (isset($barcode_value_list[
'qu'])) {
192 $qty_str = $barcode_value_list[
'qu'];
193 if (isset($barcode_value_list[
'qd'])) {
194 $qty_str .=
'.' . $barcode_value_list[
'qd'];
196 $qty = floatval($qty_str);
199 $ig =
'../public/theme/common/nophoto.png';
200 if (empty($conf->global->TAKEPOS_HIDE_PRODUCT_IMAGES)) {
202 $objProd->fetch($obj->rowid);
203 $image = $objProd->show_photos(
'product', $conf->product->multidir_output[$objProd->entity],
'small', 1);
206 preg_match(
'@src="([^"]+)"@', $image, $match);
207 $file = array_pop($match);
210 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
211 $ig = $file.
'&cache=1';
213 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
219 'rowid' => $obj->rowid,
221 'label' => $obj->label,
222 'tosell' => $obj->tosell,
223 'tobuy' => $obj->tobuy,
224 'barcode' => $obj->barcode,
225 'price' => $obj->price,
226 'price_ttc' => $obj->price_ttc,
227 'object' =>
'product',
236 if (count($rows) == 1) {
237 echo json_encode($rows);
243 $sql =
'SELECT p.rowid, p.ref, p.label, p.tosell, p.tobuy, p.barcode, p.price, p.price_ttc' ;
249 $parameters = array();
250 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
252 $sql .= $hookmanager->resPrint;
255 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
257 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'product_stock as ps';
258 $sql .=
' ON (p.rowid = ps.fk_product';
259 $sql .=
" AND ps.fk_entrepot = ".((int)
getDolGlobalInt(
"CASHDESK_ID_WAREHOUSE".$_SESSION[
'takeposterminal']));
264 $parameters = array();
265 $reshook = $hookmanager->executeHooks(
'printFieldListTables', $parameters);
267 $sql .= $hookmanager->resPrint;
270 $sql .=
' WHERE entity IN ('.getEntity(
'product').
')';
271 if ($filteroncategids) {
272 $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).
'))';
274 $sql .=
' AND p.tosell = 1';
276 $sql .=
' AND ps.reel > 0';
280 $parameters = array();
281 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
283 $sql .= $hookmanager->resPrint;
287 $sql.= $db->plimit($search_limit, $search_start);
289 $resql = $db->query(
$sql);
293 while ($obj = $db->fetch_object($resql)) {
295 $objProd->fetch($obj->rowid);
296 $image = $objProd->show_photos(
'product', $conf->product->multidir_output[$objProd->entity],
'small', 1);
299 preg_match(
'@src="([^"]+)"@', $image, $match);
300 $file = array_pop($match);
303 $ig =
'../public/theme/common/nophoto.png';
305 if (!defined(
'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
306 $ig = $file.
'&cache=1';
308 $ig = $file.
'&cache=1&publictakepos=1&modulepart=product';
313 'rowid' => $obj->rowid,
315 'label' => $obj->label,
316 'tosell' => $obj->tosell,
317 'tobuy' => $obj->tobuy,
318 'barcode' => $obj->barcode,
319 'price' => $obj->price,
320 'price_ttc' => $obj->price_ttc,
321 'object' =>
'product',
324 'price_formated' =>
price(
price2num($obj->price,
'MT'), 1, $langs, 1, -1, -1, $conf->currency),
325 'price_ttc_formated' =>
price(
price2num($obj->price_ttc,
'MT'), 1, $langs, 1, -1, -1, $conf->currency)
329 $parameters[
'row'] = $row;
330 $parameters[
'obj'] = $obj;
331 $reshook = $hookmanager->executeHooks(
'completeAjaxReturnArray', $parameters);
334 if (count($hookmanager->resArray)) {
335 $row = $hookmanager->resArray;
341 if (count($hookmanager->resArray)) {
342 $rows[] = $hookmanager->resArray;
348 echo json_encode($rows);
350 echo
'Failed to search product : '.$db->lasterror();
352 } elseif ($action ==
"opendrawer" && $term !=
'') {
353 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
357 $printer->initPrinter(
getDolGlobalInt(
'TAKEPOS_PRINTER_TO_USE'.$term));
362 } elseif ($action ==
"printinvoiceticket" && $term !=
'' && $id > 0 && $user->hasRight(
'facture',
'lire')) {
363 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolreceiptprinter.class.php';
364 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
372 } elseif ($action ==
'getInvoice') {
375 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
382 echo json_encode($object);
383 } elseif ($action ==
'thecheck') {
384 $place =
GETPOST(
'place',
'alpha');
385 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
386 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') && $user->hasRight('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') && $user->hasRight('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)) $sql
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.
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 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.