From 9bd406ca1e04132a3ced0369a9fb6cf34130b3b2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 9 Sep 2023 14:29:16 +0200 Subject: [PATCH] FIX Prices visible on TakePOS KO with multiprices support --- htdocs/categories/class/categorie.class.php | 2 +- htdocs/societe/list.php | 2 +- htdocs/takepos/ajax/ajax.php | 60 +++++++++++++++------ htdocs/takepos/index.php | 6 +-- htdocs/takepos/invoice.php | 2 + 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index ae97601f910..3a8fc93a248 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -863,7 +863,7 @@ class Categorie extends CommonObject $sql .= " WHERE o.entity IN (".getEntity($obj->element).")"; $sql .= " AND c.fk_categorie = ".((int) $this->id); // Compatibility with actioncomm table which has id instead of rowid - if ($this->MAP_OBJ_TABLE[$type] == "actioncomm" || $type == "actioncomm") { + if ((!empty($this->MAP_OBJ_TABLE[$type]) && $this->MAP_OBJ_TABLE[$type] == "actioncomm" ) || $type == "actioncomm") { $sql .= " AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = o.id"; } else { $sql .= " AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = o.rowid"; diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index a499f7f88a7..cfe615c21cb 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -984,7 +984,7 @@ if ($contextpage != 'poslist') { } elseif ($user->hasRight("societe", "creer")) { $url = DOL_URL_ROOT.'/societe/card.php?action=create&type=t&contextpage=poslist&optioncss=print&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type=t&contextpage=poslist&nomassaction=1&optioncss=print&place='.$place); $label = 'MenuNewCustomer'; - $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', $url); + $newcardbutton = dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', $url); } print '
'; diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index 47a552650d4..40492741030 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -41,6 +41,7 @@ if (!defined('NOBROWSERNOTIF')) { require '../../main.inc.php'; // Load $user and permissions require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php"; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $category = GETPOST('category', 'alphanohtml'); // Can be id of category or 'supplements' $action = GETPOST('action', 'aZ09'); @@ -56,14 +57,27 @@ if (empty($user->rights->takepos->run)) { // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks $hookmanager->initHooks(array('takeposproductsearch')); // new context for product search hooks +$pricelevel = 1; // default price level if PRODUIT_MULTIPRICES. TODO Get price level from thirdparty. + + /* * View */ +$thirdparty = new Societe($db); + if ($action == 'getProducts') { top_httphead('application/json'); + // Search + if (GETPOSTINT('thirdpartyid') > 0) { + $result = $thirdparty->fetch(GETPOSTINT('thirdpartyid')); + if ($result > 0) { + $pricelevel = $thirdparty->price_level; + } + } + $object = new Categorie($db); if ($category == "supplements") { $category = getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY'); @@ -85,8 +99,8 @@ if ($action == 'getProducts') { unset($prod->fields); unset($prod->db); - $prod->price_formated = price(price2num($prod->price, 'MT'), 1, $langs, 1, -1, -1, $conf->currency); - $prod->price_ttc_formated = price(price2num($prod->price_ttc, 'MT'), 1, $langs, 1, -1, -1, $conf->currency); + $prod->price_formated = price(price2num(empty($prod->multiprices[$pricelevel]) ? $prod->price : $prod->multiprices[$pricelevel], 'MT'), 1, $langs, 1, -1, -1, $conf->currency); + $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); $res[] = $prod; } @@ -98,10 +112,7 @@ if ($action == 'getProducts') { } elseif ($action == 'search' && $term != '') { top_httphead('application/json'); - // Change thirdparty with barcode - require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; - - $thirdparty = new Societe($db); + // Search barcode into thirdparties. If found, it means we want to change thirdparties. $result = $thirdparty->fetch('', '', '', $term); if ($result && $thirdparty->id > 0) { @@ -116,6 +127,14 @@ if ($action == 'getProducts') { exit; } + // Search + if (GETPOSTINT('thirdpartyid') > 0) { + $result = $thirdparty->fetch(GETPOSTINT('thirdpartyid')); + if ($result > 0) { + $pricelevel = $thirdparty->price_level; + } + } + // Define $filteroncategids, the filter on category ID if there is a Root category defined. $filteroncategids = ''; if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) { // A root category is defined, we must filter on products inside this category tree @@ -183,10 +202,11 @@ if ($action == 'getProducts') { $qty = floatval($qty_str); } + $objProd = new Product($db); + $objProd->fetch($obj->rowid); + $ig = '../public/theme/common/nophoto.png'; if (empty($conf->global->TAKEPOS_HIDE_PRODUCT_IMAGES)) { - $objProd = new Product($db); - $objProd->fetch($obj->rowid); $image = $objProd->show_photos('product', $conf->product->multidir_output[$objProd->entity], 'small', 1); $match = array(); @@ -209,8 +229,8 @@ if ($action == 'getProducts') { 'tosell' => $obj->tosell, 'tobuy' => $obj->tobuy, 'barcode' => $obj->barcode, - 'price' => $obj->price, - 'price_ttc' => $obj->price_ttc, + 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel], + 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel], 'object' => 'product', 'img' => $ig, 'qty' => $qty, @@ -231,7 +251,10 @@ if ($action == 'getProducts') { if (getDolGlobalInt('TAKEPOS_PRODUCT_IN_STOCK') == 1) { $sql .= ', ps.reel'; } - + /* this will be possible when field archive will be supported into llx_product_price + if (getDolGlobalString('PRODUIT_MULTIPRICES')) { + $sql .= ', pp.price_level, pp.price as multiprice_ht, pp.price_ttc as multiprice_ttc'; + }*/ // Add fields from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); @@ -240,6 +263,11 @@ if ($action == 'getProducts') { } $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; + /* this will be possible when field archive will be supported into llx_product_price + if (getDolGlobalString('PRODUIT_MULTIPRICES')) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_price as pp ON pp.fk_product = p.rowid AND pp.entity = ".((int) $conf->entity)." AND pp.price_level = ".((int) $pricelevel); + $sql .= " AND archive = 0"; + }*/ if (getDolGlobalInt('TAKEPOS_PRODUCT_IN_STOCK') == 1) { $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'product_stock as ps'; $sql .= ' ON (p.rowid = ps.fk_product'; @@ -254,7 +282,7 @@ if ($action == 'getProducts') { $sql .= $hookmanager->resPrint; } - $sql .= ' WHERE entity IN ('.getEntity('product').')'; + $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; if ($filteroncategids) { $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).'))'; } @@ -303,13 +331,13 @@ if ($action == 'getProducts') { 'tosell' => $obj->tosell, 'tobuy' => $obj->tobuy, 'barcode' => $obj->barcode, - 'price' => $obj->price, - 'price_ttc' => $obj->price_ttc, + 'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel], + 'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel], 'object' => 'product', 'img' => $ig, 'qty' => 1, - 'price_formated' => price(price2num($obj->price, 'MT'), 1, $langs, 1, -1, -1, $conf->currency), - 'price_ttc_formated' => price(price2num($obj->price_ttc, 'MT'), 1, $langs, 1, -1, -1, $conf->currency) + 'price_formated' => price(price2num(empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel], 'MT'), 1, $langs, 1, -1, -1, $conf->currency), + '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) ); // Add entries to row from hooks $parameters=array(); diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 4ae532010e5..c1fa77f91a2 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -322,7 +322,7 @@ function LoadProducts(position, issubcat) { }); idata=0; //product data counter - $.getJSON('/takepos/ajax/ajax.php?action=getProducts&token=&category='+currentcat, function(data) { + $.getJSON('/takepos/ajax/ajax.php?action=getProducts&token=&thirdpartyid=' + jQuery('#thirdpartyid').val() + '&category='+currentcat, function(data) { console.log("Call ajax.php (in LoadProducts) to get Products of category "+currentcat+" then loop on result to fill image thumbs"); console.log(data); while (ishow < maxproduct) { @@ -557,7 +557,7 @@ function Refresh() { function New() { // If we go here,it means $conf->global->TAKEPOS_BAR_RESTAURANT is not defined - invoiceid = $("#invoiceid").val(); + invoiceid = $("#invoiceid").val(); // This is a hidden field added by invoice.php console.log("New with place = , js place="+place+", invoiceid="+invoiceid); @@ -631,7 +631,7 @@ function Search2(keyCodeForEnter, moreorless) { pageproducts = 0; jQuery(".wrapper2 .catwatermark").hide(); var nbsearchresults = 0; - $.getJSON('/takepos/ajax/ajax.php?action=search&token=&term=' + search_term + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) { + $.getJSON('/takepos/ajax/ajax.php?action=search&token=&term=' + search_term + '&thirdpartyid=' + jQuery('#thirdpartyid').val() + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) { for (i = 0; i < ; i++) { if (typeof (data[i]) == "undefined") { $("#prowatermark" + i).html(""); diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 1921fc6f342..4eed0d1ca15 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -1316,7 +1316,9 @@ print ''; print ''; // In phone version only show when it is invoice page if (empty($mobilepage) || $mobilepage == "invoice") { + print ''; print ''; + print ''; } if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) { $sql = "SELECT floor, label FROM ".MAIN_DB_PREFIX."takepos_floor_tables where rowid=".((int) $place);