From ffc861d4e2a5f5b75ccf52ee2b99ad676e04c82d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 16 Mar 2020 18:04:22 +0100 Subject: [PATCH] FIX Autoadd product when barcode match Show barcode value in tooltips --- htdocs/takepos/ajax/ajax.php | 17 +++++++++--- htdocs/takepos/css/pos.css.php | 20 ++++++++++++-- htdocs/takepos/floors.php | 14 ++++++++++ htdocs/takepos/freezone.php | 4 +++ htdocs/takepos/index.php | 50 +++++++++++++++++++++++++++++----- htdocs/takepos/invoice.php | 5 ++++ htdocs/takepos/pay.php | 4 +++ htdocs/takepos/phone.php | 5 ++++ htdocs/takepos/receipt.php | 4 +++ htdocs/takepos/reduction.php | 4 +++ htdocs/takepos/send.php | 5 ++++ htdocs/takepos/smpcb.php | 12 +++++++- 12 files changed, 129 insertions(+), 15 deletions(-) diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index 07de9e50a51..56c30b69283 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -85,10 +85,10 @@ elseif ($action == 'search' && $term != '') { } } - $sql = 'SELECT rowid, ref, label, tosell, tobuy FROM '.MAIN_DB_PREFIX.'product as p'; + $sql = 'SELECT rowid, ref, label, tosell, tobuy, barcode, price FROM '.MAIN_DB_PREFIX.'product as p'; $sql .= ' WHERE entity IN ('.getEntity('product').')'; if ($filteroncategids) { - $sql.= ' AND rowid IN (SELECT DISTINCT fk_product FROM '.MAIN_DB_PREFIX.'categorie_product WHERE fk_categorie IN ('.$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 ('.$filteroncategids.'))'; } $sql .= ' AND tosell = 1'; $sql .= natural_search(array('ref', 'label', 'barcode'), $term); @@ -96,8 +96,17 @@ elseif ($action == 'search' && $term != '') { if ($resql) { $rows = array(); - while ($row = $db->fetch_object($resql)) { - $rows[] = $row; + while ($obj = $db->fetch_object($resql)) { + $rows[] = array( + 'rowid' => $obj->rowid, + 'ref' => $obj->ref, + 'label' => $obj->label, + 'tosell' => $obj->tosell, + 'tobuy' => $obj->tobuy, + 'barcode' => $obj->barcode, + 'price' => $obj->price + //'price_formated' => price(price2num($obj->price, 'MU'), 1, $langs, 1, -1, -1, $conf->currency) + ); } echo json_encode($rows); } diff --git a/htdocs/takepos/css/pos.css.php b/htdocs/takepos/css/pos.css.php index 32b7d7b7104..b541cdd6bad 100644 --- a/htdocs/takepos/css/pos.css.php +++ b/htdocs/takepos/css/pos.css.php @@ -286,7 +286,7 @@ div.paymentbordline .row1withhead{ margin: 0 auto; width: 100%; - height: calc(50% - 50px); + height: calc(45% - 50px); padding-top: 5px; } @@ -299,7 +299,7 @@ div.paymentbordline .row2withhead{ margin: 0 auto; width: 100%; - height: 50%; + height: 55%; } .div1{ @@ -488,6 +488,20 @@ div#moreinfo, div#infowarehouse { padding: 0 8px 0 8px; } +.productprice { + position: absolute; + top: 5px; + right: 5px; + background: var(--colorbackhmenu1); + color: var(--colortextbackhmenu); + font-size: 2em; + padding: 5px; + border-radius: 2px; + opacity: 0.9; + padding-left: 8px; + padding-right: 8px; +} + @media screen and (min-width: 892px) { .actionbutton{ @@ -561,7 +575,7 @@ div#moreinfo, div#infowarehouse { } .row1withhead{ - height: calc(50% - 100px); + height: calc(45% - 100px); } diff --git a/htdocs/takepos/floors.php b/htdocs/takepos/floors.php index 6a067a76268..260813dd3b6 100644 --- a/htdocs/takepos/floors.php +++ b/htdocs/takepos/floors.php @@ -47,6 +47,15 @@ $place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place $newname = GETPOST('newname', 'alpha'); $mode = GETPOST('mode', 'alpha'); +if (empty($user->rights->takepos->run)) { + access_forbidden(); +} + + +/* + * Actions + */ + if ($action == "getTables") { $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM ".MAIN_DB_PREFIX."takepos_floor_tables where floor=".$floor; @@ -81,6 +90,11 @@ if ($action == "add") $db->query("update ".MAIN_DB_PREFIX."takepos_floor_tables set label=rowid where label=''"); // No empty table names } + +/* + * View + */ + // Title $title = 'TakePOS - Dolibarr '.DOL_VERSION; if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE; diff --git a/htdocs/takepos/freezone.php b/htdocs/takepos/freezone.php index e8cce00abb3..5e58910928a 100644 --- a/htdocs/takepos/freezone.php +++ b/htdocs/takepos/freezone.php @@ -40,6 +40,10 @@ $place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place $idline = GETPOST('idline', 'int'); $action = GETPOST('action', 'alpha'); +if (empty($user->rights->takepos->run)) { + access_forbidden(); +} + /* * View diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 9685e14ffd8..9615f90d539 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -263,6 +263,8 @@ function LoadProducts(position, issubcat) { if (currentcat==val.fk_parent) { $("#prodivdesc"+ishow).show(); $("#prodesc"+ishow).text(val.label); + $("#proprice"+ishow).attr("class", "hidden"); + $("#proprice"+ishow).html(""); $("#proimg"+ishow).attr("src","genimg/index.php?query=cat&id="+val.rowid); $("#prodiv"+ishow).data("rowid",val.rowid); $("#prodiv"+ishow).data("iscat",1); @@ -281,6 +283,8 @@ function LoadProducts(position, issubcat) { if (typeof (data[idata]) == "undefined") { $("#prodivdesc"+ishow).hide(); $("#prodesc"+ishow).text(""); + $("#proprice"+ishow).attr("class", "hidden"); + $("#proprice"+ishow).html(""); $("#proimg"+ishow).attr("title",""); $("#proimg"+ishow).attr("src","genimg/empty.png"); $("#prodiv"+ishow).data("rowid",""); @@ -289,9 +293,17 @@ function LoadProducts(position, issubcat) { ishow++; //Next product to show after print data product } else if ((data[idata]['status']) == "1") { // Only show products with status=1 (for sell) - var titlestring = 'transnoentities('Ref').': '); ?>'+data[idata]['ref']; + transnoentities('Ref').': ')."' + data[idata]['ref']"; + $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']"; + ?> + var titlestring = ; $("#prodivdesc"+ishow).show(); $("#prodesc"+ishow).text(data[parseInt(idata)]['label']); + if (data[parseInt(idata)]['price_formated']) { + $("#proprice"+ishow).attr("class", "productprice"); + $("#proprice"+ishow).html(data[parseInt(idata)]['price_formated']); + } $("#proimg"+ishow).attr("title", titlestring); $("#proimg"+ishow).attr("src", "genimg/index.php?query=pro&id="+data[idata]['id']); $("#prodiv"+ishow).data("rowid", data[idata]['id']); @@ -337,6 +349,8 @@ function MoreProducts(moreorless) { if (typeof (data[idata]) == "undefined") { $("#prodivdesc"+ishow).hide(); $("#prodesc"+ishow).text(""); + $("#proprice"+ishow).attr("class", ""); + $("#proprice"+ishow).html(""); $("#proimg"+ishow).attr("src","genimg/empty.png"); $("#prodiv"+ishow).data("rowid",""); ishow++; //Next product to show after print data product @@ -345,6 +359,10 @@ function MoreProducts(moreorless) { //Only show products with status=1 (for sell) $("#prodivdesc"+ishow).show(); $("#prodesc"+ishow).text(data[parseInt(idata)]['label']); + if (data[parseInt(idata)]['price_formated']) { + $("#proprice"+ishow).attr("class", "productprice"); + $("#proprice"+ishow).html(data[parseInt(idata)]['price_formated']); + } $("#proimg"+ishow).attr("src","genimg/index.php?query=pro&id="+data[idata]['id']); $("#prodiv"+ishow).data("rowid",data[idata]['id']); $("#prodiv"+ishow).data("iscat",0); @@ -462,7 +480,7 @@ function New() { * return {void} */ function Search2(keyCodeForEnter) { - console.log("Search2 Call ajax search to replace products"); + console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter); var search = false; var eventKeyCode = window.event.keyCode; @@ -477,20 +495,37 @@ function Search2(keyCodeForEnter) { for (i = 0; i < ; i++) { if (typeof (data[i]) == "undefined") { $("#prodesc" + i).text(""); + $("#proprice" + i).attr("class", "hidden"); + $("#proprice" + i).html(""); $("#proimg" + i).attr("src", "genimg/empty.png"); $("#prodiv" + i).data("rowid", ""); continue; } - var titlestring = 'transnoentities('Ref').': '); ?>' + data[i]['ref']; + transnoentities('Ref').': ')."' + data[i]['ref']"; + $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']"; + ?> + var titlestring = ; $("#prodesc" + i).text(data[i]['label']); $("#prodivdesc" + i).show(); + if (data[i]['price_formated']) { + $("#proprice" + i).attr("class", "productprice"); + $("#proprice" + i).html(data[i]['price_formated']); + } $("#proimg" + i).attr("title", titlestring); $("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']); $("#prodiv" + i).data("rowid", data[i]['rowid']); $("#prodiv" + i).data("iscat", 0); } }).always(function (data) { - if ($('#search').val().length > 0 && data.length == 1) ClickProduct(0); + // If there is only 1 answer + if ($('#search').val().length > 0 && data.length == 1) { + console.log($('#search').val()+' - '+data[0]['barcode']); + if ($('#search').val() == data[0]['barcode']) { + console.log("There is only 1 answer with barcode matching the search, so we add the product in basket"); + ClickProduct(0); + } + } }); } } @@ -924,15 +959,16 @@ if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) { '; - echo ''; + print ''; } elseif ($count == ($MAXPRODUCT - 1)) { //echo ''; - echo ''; + print ''; } else { - echo ''; + print '
'; + print ''; } ?> diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 3ca20a9ddee..bf68713a806 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -70,6 +70,11 @@ if ($conf->global->TAKEPOS_PHONE_BASIC_LAYOUT == 1 && $conf->browser->layout == '; } +if (empty($user->rights->takepos->run)) { + access_forbidden(); +} + + /** * Abort invoice creationg with a given error message * diff --git a/htdocs/takepos/pay.php b/htdocs/takepos/pay.php index fb2442b5aba..f79e310f36b 100644 --- a/htdocs/takepos/pay.php +++ b/htdocs/takepos/pay.php @@ -38,6 +38,10 @@ $place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place $invoiceid = GETPOST('invoiceid', 'int'); +if (empty($user->rights->takepos->run)) { + access_forbidden(); +} + /* * View diff --git a/htdocs/takepos/phone.php b/htdocs/takepos/phone.php index 5d0346a495c..c32561d3f52 100644 --- a/htdocs/takepos/phone.php +++ b/htdocs/takepos/phone.php @@ -48,6 +48,11 @@ if ($setterminal > 0) $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter")); +if (empty($user->rights->takepos->run)) { + access_forbidden(); +} + + /* * View */ diff --git a/htdocs/takepos/receipt.php b/htdocs/takepos/receipt.php index 66043f7139c..31390c347bd 100644 --- a/htdocs/takepos/receipt.php +++ b/htdocs/takepos/receipt.php @@ -34,6 +34,10 @@ $place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place $facid = GETPOST('facid', 'int'); +if (empty($user->rights->takepos->run)) { + access_forbidden(); +} + /* * View diff --git a/htdocs/takepos/reduction.php b/htdocs/takepos/reduction.php index a2d57ea3a6e..613b78d5578 100644 --- a/htdocs/takepos/reduction.php +++ b/htdocs/takepos/reduction.php @@ -38,6 +38,10 @@ $place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place $invoiceid = GETPOST('invoiceid', 'int'); +if (empty($user->rights->takepos->run)) { + access_forbidden(); +} + /* * View diff --git a/htdocs/takepos/send.php b/htdocs/takepos/send.php index 0b16f555e2f..8078ddc1787 100644 --- a/htdocs/takepos/send.php +++ b/htdocs/takepos/send.php @@ -37,6 +37,11 @@ require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; $invoiceid = GETPOST('facid', 'int'); +if (empty($user->rights->takepos->run)) { + access_forbidden(); +} + + /* * View */ diff --git a/htdocs/takepos/smpcb.php b/htdocs/takepos/smpcb.php index 445bc6da9cc..6bf81b1cdf6 100644 --- a/htdocs/takepos/smpcb.php +++ b/htdocs/takepos/smpcb.php @@ -1,5 +1,15 @@ rights->takepos->run)) { + access_forbidden(); +} if (isset($_GET['status'])) { die(strtoupper($_SESSION['SMP_CURRENT_PAYMENT']));