2008-09-30 01:18:52 +02:00
|
|
|
<?php
|
2015-06-13 10:43:55 +02:00
|
|
|
/* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
|
|
|
|
|
* Copyright (C) 2008-2009 Laurent Destailleur <eldy@uers.sourceforge.net>
|
2018-10-27 14:43:12 +02:00
|
|
|
* Copyright (C) 2015 Regis Houssin <regis.houssin@inodbox.com>
|
2009-05-22 00:55:53 +02:00
|
|
|
*
|
2008-09-30 01:18:52 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2008-09-30 01:18:52 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2008-09-30 01:18:52 +02:00
|
|
|
*/
|
|
|
|
|
|
2009-10-20 17:23:32 +02:00
|
|
|
/**
|
2013-12-14 01:28:59 +01:00
|
|
|
* \file htdocs/cashdesk/facturation_dhtml.php
|
|
|
|
|
* \ingroup cashdesk
|
|
|
|
|
* \brief This page is called each time we press a key in the code search form to show product combo list.
|
2009-10-20 17:23:32 +02:00
|
|
|
*/
|
2008-09-30 01:18:52 +02:00
|
|
|
|
2009-09-27 23:10:09 +02:00
|
|
|
|
2021-02-23 17:58:31 +01:00
|
|
|
if (!defined('NOREQUIRESOC')) {
|
|
|
|
|
define('NOREQUIRESOC', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOCSRFCHECK')) {
|
|
|
|
|
define('NOCSRFCHECK', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOTOKENRENEWAL')) {
|
|
|
|
|
define('NOTOKENRENEWAL', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIREMENU')) {
|
|
|
|
|
define('NOREQUIREMENU', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIREHTML')) {
|
|
|
|
|
define('NOREQUIREHTML', '1');
|
|
|
|
|
}
|
|
|
|
|
if (!defined('NOREQUIREAJAX')) {
|
|
|
|
|
define('NOREQUIREAJAX', '1');
|
|
|
|
|
}
|
2010-07-14 13:19:25 +02:00
|
|
|
|
|
|
|
|
// Change this following line to use the correct relative path (../, ../../, etc)
|
2012-08-22 23:24:21 +02:00
|
|
|
require '../main.inc.php';
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php';
|
2010-07-14 13:19:25 +02:00
|
|
|
|
2021-03-24 13:32:09 +01:00
|
|
|
if (empty($user->rights->cashdesk->run)) {
|
|
|
|
|
accessforbidden();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
|
|
|
|
|
2017-05-09 21:01:37 +02:00
|
|
|
top_httphead('text/html');
|
2010-07-14 13:19:25 +02:00
|
|
|
|
2015-06-13 10:43:55 +02:00
|
|
|
$search = GETPOST("code", "alpha");
|
|
|
|
|
|
2010-07-14 13:19:25 +02:00
|
|
|
// Search from criteria
|
2021-02-23 17:58:31 +01:00
|
|
|
if (dol_strlen($search) >= 0) { // If search criteria is on char length at least
|
2009-11-12 10:09:05 +01:00
|
|
|
$sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx";
|
2021-02-23 17:58:31 +01:00
|
|
|
if (!empty($conf->stock->enabled) && !empty($conf_fkentrepot)) {
|
|
|
|
|
$sql .= ", ps.reel";
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
|
2021-02-23 17:58:31 +01:00
|
|
|
if (!empty($conf->stock->enabled) && !empty($conf_fkentrepot)) {
|
|
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$db->escape($conf_fkentrepot)."'";
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " WHERE p.entity IN (".getEntity('product').")";
|
|
|
|
|
$sql .= " AND p.tosell = 1";
|
|
|
|
|
$sql .= " AND p.fk_product_type = 0";
|
2010-07-14 13:37:56 +02:00
|
|
|
// Add criteria on ref/label
|
2021-02-23 17:58:31 +01:00
|
|
|
if (!empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) {
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " AND (p.ref LIKE '".$db->escape($search)."%' OR p.label LIKE '".$db->escape($search)."%'";
|
2021-02-23 17:58:31 +01:00
|
|
|
if (!empty($conf->barcode->enabled)) {
|
|
|
|
|
$sql .= " OR p.barcode LIKE '".$db->escape($search)."%'";
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= ")";
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " AND (p.ref LIKE '%".$db->escape($search)."%' OR p.label LIKE '%".$db->escape($search)."%'";
|
2021-02-23 17:58:31 +01:00
|
|
|
if (!empty($conf->barcode->enabled)) {
|
|
|
|
|
$sql .= " OR p.barcode LIKE '%".$db->escape($search)."%'";
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= ")";
|
2010-07-14 13:37:56 +02:00
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " ORDER BY label";
|
2010-07-14 13:19:25 +02:00
|
|
|
|
2014-06-12 11:31:53 +02:00
|
|
|
dol_syslog("facturation_dhtml.php", LOG_DEBUG);
|
2009-11-12 10:09:05 +01:00
|
|
|
$result = $db->query($sql);
|
2008-09-30 01:18:52 +02:00
|
|
|
|
2021-02-23 17:58:31 +01:00
|
|
|
if ($result) {
|
|
|
|
|
if ($nbr = $db->num_rows($result)) {
|
2009-11-12 10:09:05 +01:00
|
|
|
$resultat = '<ul class="dhtml_bloc">';
|
2010-07-14 13:19:25 +02:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$ret = array(); $i = 0;
|
2021-02-23 17:58:31 +01:00
|
|
|
while ($tab = $db->fetch_array($result)) {
|
|
|
|
|
foreach ($tab as $cle => $valeur) {
|
2009-11-12 10:09:05 +01:00
|
|
|
$ret[$i][$cle] = $valeur;
|
|
|
|
|
}
|
|
|
|
|
$i++;
|
2008-11-18 23:44:53 +01:00
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$tab = $ret;
|
2010-07-14 13:19:25 +02:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$tab_size = count($tab);
|
2021-02-23 17:58:31 +01:00
|
|
|
for ($i = 0; $i < $tab_size; $i++) {
|
2009-11-12 10:09:05 +01:00
|
|
|
$resultat .= '
|
2008-09-30 01:18:52 +02:00
|
|
|
<li class="dhtml_defaut" title="'.$tab[$i]['ref'].'"
|
|
|
|
|
onMouseOver="javascript: this.className = \'dhtml_selection\';"
|
|
|
|
|
onMouseOut="javascript: this.className = \'dhtml_defaut\';"
|
2010-07-14 13:19:25 +02:00
|
|
|
>'.$tab[$i]['ref'].' - '.$tab[$i]['label'].'</li>
|
2008-09-30 01:18:52 +02:00
|
|
|
';
|
2009-11-12 10:09:05 +01:00
|
|
|
}
|
2010-07-14 13:19:25 +02:00
|
|
|
|
2009-11-12 10:09:05 +01:00
|
|
|
$resultat .= '</ul>';
|
2010-07-14 13:19:25 +02:00
|
|
|
|
2009-11-12 10:09:05 +01:00
|
|
|
print $resultat;
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2010-10-22 04:00:50 +02:00
|
|
|
$langs->load("cashdesk");
|
2010-07-14 13:19:25 +02:00
|
|
|
|
2009-11-12 10:09:05 +01:00
|
|
|
print '<ul class="dhtml_bloc">';
|
|
|
|
|
print '<li class="dhtml_defaut">'.$langs->trans("NoResults").'</li>';
|
|
|
|
|
print '</ul>';
|
2009-09-27 23:10:09 +02:00
|
|
|
}
|
2008-09-30 01:18:52 +02:00
|
|
|
}
|
2009-09-27 23:10:09 +02:00
|
|
|
}
|