FIX Prices visible on TakePOS KO with multiprices support

This commit is contained in:
Laurent Destailleur 2023-09-09 14:29:16 +02:00
parent 5a9b2ce8de
commit 9bd406ca1e
5 changed files with 51 additions and 21 deletions

View File

@ -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";

View File

@ -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 '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formfilter" autocomplete="off">';

View File

@ -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();

View File

@ -322,7 +322,7 @@ function LoadProducts(position, issubcat) {
});
idata=0; //product data counter
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&category='+currentcat, function(data) {
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&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 = <?php echo $place; ?>, js place="+place+", invoiceid="+invoiceid);
@ -631,7 +631,7 @@ function Search2(keyCodeForEnter, moreorless) {
pageproducts = 0;
jQuery(".wrapper2 .catwatermark").hide();
var nbsearchresults = 0;
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&token=<?php echo newToken();?>&term=' + search_term + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&token=<?php echo newToken();?>&term=' + search_term + '&thirdpartyid=' + jQuery('#thirdpartyid').val() + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
if (typeof (data[i]) == "undefined") {
$("#prowatermark" + i).html("");

View File

@ -1316,7 +1316,9 @@ print '<tr class="liste_titre nodrag nodrop">';
print '<td class="linecoldescription">';
// In phone version only show when it is invoice page
if (empty($mobilepage) || $mobilepage == "invoice") {
print '<!-- hidden var used by some js functions -->';
print '<input type="hidden" name="invoiceid" id="invoiceid" value="'.$invoice->id.'">';
print '<input type="hidden" name="thirdpartyid" id="thirdpartyid" value="'.$invoice->socid.'">';
}
if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
$sql = "SELECT floor, label FROM ".MAIN_DB_PREFIX."takepos_floor_tables where rowid=".((int) $place);