From daa940d75bcdad741091bd37e1ebaa4b79184bd8 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 14 Mar 2019 16:35:36 +0100 Subject: [PATCH] FIX multiple bugs for show products/categories --- htdocs/takepos/ajax.php | 3 +- htdocs/takepos/customers.php | 4 +- htdocs/takepos/invoice.php | 102 ++++++++++++++++++----------------- htdocs/takepos/takepos.php | 14 +++-- 4 files changed, 66 insertions(+), 57 deletions(-) diff --git a/htdocs/takepos/ajax.php b/htdocs/takepos/ajax.php index 4b16cc9ec81..db8b3fdff56 100644 --- a/htdocs/takepos/ajax.php +++ b/htdocs/takepos/ajax.php @@ -49,9 +49,10 @@ if ($action=="getProducts") { echo json_encode($prods); } -if ($action=="search") { +else if ($action=="search") { $sql = 'SELECT * FROM '.MAIN_DB_PREFIX.'product'; $sql .= ' WHERE entity IN ('.getEntity('product').')'; + $sql .= ' AND tosell = 1'; $sql .= natural_search(array('label','barcode'), $term); $resql = $db->query($sql); $rows = array(); diff --git a/htdocs/takepos/customers.php b/htdocs/takepos/customers.php index 3bf79f38382..16884e48f1d 100644 --- a/htdocs/takepos/customers.php +++ b/htdocs/takepos/customers.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2016 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2019 Regis Houssin * Copyright (C) 2012 Marcos García * Copyright (C) 2013-2015 Raphaël Doursenaud * Copyright (C) 2015 Florian Henry @@ -45,7 +45,7 @@ $show_files=GETPOST('show_files', 'int'); $confirm=GETPOST('confirm', 'alpha'); $toselect = GETPOST('toselect', 'array'); $idcustomer = GETPOST('idcustomer', 'int'); -$place = GETPOST('place', 'int'); +$place = (GETPOSTISSET('place')?GETPOST('place', 'int'):0); $_GET['optioncss'] = 'print'; diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 4d8130daeb4..35509165732 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -25,39 +25,28 @@ if (!defined('NOTOKENRENEWAL')) { define('NOTOKENRENEWAL', '1'); } if (!defined('NOREQUIREMENU')) { define('NOREQUIREMENU', '1'); } if (!defined('NOREQUIREHTML')) { define('NOREQUIREHTML', '1'); } if (!defined('NOREQUIREAJAX')) { define('NOREQUIREAJAX', '1'); } + require '../main.inc.php'; - - // Load $user and permissions - require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; - require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; -$langs->loadLangs( - array( - "bills", - "cashdesk" - ) -); +$langs->loadLangs(array("bills", "cashdesk")); + $id = GETPOST('id', 'int'); $action = GETPOST('action', 'alpha'); $idproduct = GETPOST('idproduct', 'int'); -$place = GETPOST('place', 'int'); +$place = (GETPOSTISSET('place')?GETPOST('place', 'int'):0); // $place is id of POS $number = GETPOST('number'); $idline = GETPOST('idline'); $desc = GETPOST('desc', 'alpha'); $pay = GETPOST('pay'); -$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS-".$place.")'"; -$resql = $db->query($sql); -$row = $db->fetch_array($resql); -$placeid = $row[0]; -if (!$placeid) { $placeid = 0; // not necessary -} else -{ - $invoice = new Facture($db); - $invoice->fetch($placeid); -} +$placeid = 0; // $placeid is id of invoice + +$invoice = new Facture($db); +$ret = $invoice->fetch('', '(PROV-POS-'.$place.')'); +if ($ret > 0) $placeid = $invoice->id; + /* * Actions @@ -65,53 +54,68 @@ if (!$placeid) { $placeid = 0; // not necessary if ($action == 'valid' && $user->rights->facture->creer) { - if ($pay=="cash") $bankaccount=$conf->global->CASHDESK_ID_BANKACCOUNT_CASH; - elseif ($pay=="card") $bankaccount=$conf->global->CASHDESK_ID_BANKACCOUNT_CB; - elseif ($pay=="cheque") $bankaccount=$conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; + if ($pay == "cash") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH; + elseif ($pay == "card") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CB; + elseif ($pay == "cheque") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; + $now=dol_now(); + $invoice = new Facture($db); $invoice->fetch($placeid); + if (! empty($conf->stock->enabled) and $conf->global->CASHDESK_NO_DECREASE_STOCK!="1") $invoice->validate($user, '', $conf->global->CASHDESK_ID_WAREHOUSE); else $invoice->validate($user); + // Add the payment $payment=new Paiement($db); - $payment->datepaye=$now; - $payment->bank_account=$bankaccount; - $payment->amounts[$invoice->id]=$invoice->total_ttc; + $payment->datepaye = $now; + $payment->bank_account = $bankaccount; + $payment->amounts[$invoice->id] = $invoice->total_ttc; - if ($pay=="cash") $payment->paiementid=4; - elseif ($pay=="card") $payment->paiementid=6; - elseif ($pay=="cheque") $payment->paiementid=7; - $payment->num_paiement=$invoice->ref; + if ($pay=="cash") $payment->paiementid = 4; + elseif ($pay=="card") $payment->paiementid = 6; + elseif ($pay=="cheque") $payment->paiementid = 7; + $payment->num_payment = $invoice->ref; - $payment->create($user); + $payment->create($user); $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', ''); - $invoice->set_paid($user); + $invoice->set_paid($user); } -if (($action=="addline" || $action=="freezone") && $placeid==0) +if (($action=="addline" || $action=="freezone") && $placeid == 0) { - // $place is id of POS, $placeid is id of invoice - if ($placeid==0) - { - $invoice = new Facture($db); - $invoice->socid=$conf->global->CASHDESK_ID_THIRDPARTY; - $invoice->date=dol_now(); - $invoice->ref="(PROV-POS)"; - $invoice->module_source = 'takepos'; - $invoice->pos_source = (string) (empty($place)?'0':$place); + $invoice->socid = $conf->global->CASHDESK_ID_THIRDPARTY; + $invoice->date = dol_now(); + $invoice->ref = "(PROV-POS-".$place.")"; + $invoice->module_source = 'takepos'; + $invoice->pos_source = (string) $place; - $placeid=$invoice->create($user); - $sql="UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS-".$place.")' where rowid=".$placeid; - $db->query($sql); - } + $placeid = $invoice->create($user); } if ($action == "addline") { - $prod = new Product($db); + + $prod = new Product($db); $prod->fetch($idproduct); - $invoice->addline($prod->description, $prod->price, 1, $prod->tva_tx, $prod->localtax1_tx, $prod->localtax2_tx, $idproduct, $prod->remise_percent, '', 0, 0, 0, '', $prod->price_base_type, $prod->price_ttc, $prod->type, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); + + $price = $prod->price; + $tva_tx = $prod->tva_tx; + $price_ttc = $prod->price_ttc; + $price_base_type = $prod->price_base_type; + + if (! empty($conf->global->PRODUIT_MULTIPRICES)) + { + $customer = new Societe($db); + $customer->fetch($invoice->socid); + + $price = $prod->multiprices[$customer->price_level]; + $tva_tx = $prod->multiprices_tva_tx[$customer->price_level]; + $price_ttc = $prod->multiprices_ttc[$customer->price_level]; + $price_base_type = $prod->multiprices_base_type[$customer->price_level]; + } + + $invoice->addline($prod->description, $price, 1, $tva_tx, $prod->localtax1_tx, $prod->localtax2_tx, $idproduct, $prod->remise_percent, '', 0, 0, 0, '', $price_base_type, $price_ttc, $prod->type, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); $invoice->fetch($placeid); } diff --git a/htdocs/takepos/takepos.php b/htdocs/takepos/takepos.php index 41f4c99a508..8e7053b8242 100644 --- a/htdocs/takepos/takepos.php +++ b/htdocs/takepos/takepos.php @@ -65,21 +65,25 @@ $categorie = new Categorie($db); $categories = $categorie->get_full_arbo('product'); $maincategories = array_filter($categories, function ($item) { - if (($item['level']==1) !== false) { + if (($item['level']==1) !== false && ($item['visible']==1) !== false) { return true; } return false; }); +sort($maincategories); + $subcategories = array_filter($categories, function ($item) { - if (($item['level']!=1) !== false) { + if (($item['level']!=1) !== false && ($item['visible']==1) !== false) { return true; } return false; }); + +sort($subcategories); ?> -var categories = ; +var categories = ; var subcategories = ; var currentcat; @@ -151,7 +155,7 @@ function LoadProducts(position, issubcat=false){ idata=0; //product data counter $.getJSON('./ajax.php?action=getProducts&category='+currentcat, function(data) { - while (idata < 30 && ishow < 30) { + while (ishow < 30) { if (typeof (data[idata]) == "undefined") { $("#prodesc"+ishow).text(""); $("#proimg"+ishow).attr("src","genimg/empty.png"); @@ -191,7 +195,7 @@ function MoreProducts(moreorless){ } idata=30*pageproducts; //product data counter ishow=0; //product to show counter - while (idata < (30*pageproducts)+30) { + while (ishow < 30) { if (typeof (data[idata]) == "undefined") { $("#prodesc"+ishow).text(""); $("#proimg"+ishow).attr("src","genimg/empty.png");