FIX multiple bugs for show products/categories

This commit is contained in:
Regis Houssin 2019-03-14 16:35:36 +01:00
parent 3ab5c3e6ab
commit daa940d75b
4 changed files with 66 additions and 57 deletions

View File

@ -49,9 +49,10 @@ if ($action=="getProducts") {
echo json_encode($prods); echo json_encode($prods);
} }
if ($action=="search") { else if ($action=="search") {
$sql = 'SELECT * FROM '.MAIN_DB_PREFIX.'product'; $sql = 'SELECT * FROM '.MAIN_DB_PREFIX.'product';
$sql .= ' WHERE entity IN ('.getEntity('product').')'; $sql .= ' WHERE entity IN ('.getEntity('product').')';
$sql .= ' AND tosell = 1';
$sql .= natural_search(array('label','barcode'), $term); $sql .= natural_search(array('label','barcode'), $term);
$resql = $db->query($sql); $resql = $db->query($sql);
$rows = array(); $rows = array();

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com> * Copyright (C) 2005-2019 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr> * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
@ -45,7 +45,7 @@ $show_files=GETPOST('show_files', 'int');
$confirm=GETPOST('confirm', 'alpha'); $confirm=GETPOST('confirm', 'alpha');
$toselect = GETPOST('toselect', 'array'); $toselect = GETPOST('toselect', 'array');
$idcustomer = GETPOST('idcustomer', 'int'); $idcustomer = GETPOST('idcustomer', 'int');
$place = GETPOST('place', 'int'); $place = (GETPOSTISSET('place')?GETPOST('place', 'int'):0);
$_GET['optioncss'] = 'print'; $_GET['optioncss'] = 'print';

View File

@ -25,39 +25,28 @@ if (!defined('NOTOKENRENEWAL')) { define('NOTOKENRENEWAL', '1'); }
if (!defined('NOREQUIREMENU')) { define('NOREQUIREMENU', '1'); } if (!defined('NOREQUIREMENU')) { define('NOREQUIREMENU', '1'); }
if (!defined('NOREQUIREHTML')) { define('NOREQUIREHTML', '1'); } if (!defined('NOREQUIREHTML')) { define('NOREQUIREHTML', '1'); }
if (!defined('NOREQUIREAJAX')) { define('NOREQUIREAJAX', '1'); } if (!defined('NOREQUIREAJAX')) { define('NOREQUIREAJAX', '1'); }
require '../main.inc.php'; 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/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
$langs->loadLangs( $langs->loadLangs(array("bills", "cashdesk"));
array(
"bills",
"cashdesk"
)
);
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$idproduct = GETPOST('idproduct', 'int'); $idproduct = GETPOST('idproduct', 'int');
$place = GETPOST('place', 'int'); $place = (GETPOSTISSET('place')?GETPOST('place', 'int'):0); // $place is id of POS
$number = GETPOST('number'); $number = GETPOST('number');
$idline = GETPOST('idline'); $idline = GETPOST('idline');
$desc = GETPOST('desc', 'alpha'); $desc = GETPOST('desc', 'alpha');
$pay = GETPOST('pay'); $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 $placeid = 0; // $placeid is id of invoice
} else
{ $invoice = new Facture($db);
$invoice = new Facture($db); $ret = $invoice->fetch('', '(PROV-POS-'.$place.')');
$invoice->fetch($placeid); if ($ret > 0) $placeid = $invoice->id;
}
/* /*
* Actions * Actions
@ -65,53 +54,68 @@ if (!$placeid) { $placeid = 0; // not necessary
if ($action == 'valid' && $user->rights->facture->creer) if ($action == 'valid' && $user->rights->facture->creer)
{ {
if ($pay=="cash") $bankaccount=$conf->global->CASHDESK_ID_BANKACCOUNT_CASH; if ($pay == "cash") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH;
elseif ($pay=="card") $bankaccount=$conf->global->CASHDESK_ID_BANKACCOUNT_CB; elseif ($pay == "card") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CB;
elseif ($pay=="cheque") $bankaccount=$conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; elseif ($pay == "cheque") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE;
$now=dol_now(); $now=dol_now();
$invoice = new Facture($db); $invoice = new Facture($db);
$invoice->fetch($placeid); $invoice->fetch($placeid);
if (! empty($conf->stock->enabled) and $conf->global->CASHDESK_NO_DECREASE_STOCK!="1") $invoice->validate($user, '', $conf->global->CASHDESK_ID_WAREHOUSE); 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); else $invoice->validate($user);
// Add the payment // Add the payment
$payment=new Paiement($db); $payment=new Paiement($db);
$payment->datepaye=$now; $payment->datepaye = $now;
$payment->bank_account=$bankaccount; $payment->bank_account = $bankaccount;
$payment->amounts[$invoice->id]=$invoice->total_ttc; $payment->amounts[$invoice->id] = $invoice->total_ttc;
if ($pay=="cash") $payment->paiementid=4; if ($pay=="cash") $payment->paiementid = 4;
elseif ($pay=="card") $payment->paiementid=6; elseif ($pay=="card") $payment->paiementid = 6;
elseif ($pay=="cheque") $payment->paiementid=7; elseif ($pay=="cheque") $payment->paiementid = 7;
$payment->num_paiement=$invoice->ref; $payment->num_payment = $invoice->ref;
$payment->create($user); $payment->create($user);
$payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', ''); $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 $invoice->socid = $conf->global->CASHDESK_ID_THIRDPARTY;
if ($placeid==0) $invoice->date = dol_now();
{ $invoice->ref = "(PROV-POS-".$place.")";
$invoice = new Facture($db); $invoice->module_source = 'takepos';
$invoice->socid=$conf->global->CASHDESK_ID_THIRDPARTY; $invoice->pos_source = (string) $place;
$invoice->date=dol_now();
$invoice->ref="(PROV-POS)";
$invoice->module_source = 'takepos';
$invoice->pos_source = (string) (empty($place)?'0':$place);
$placeid=$invoice->create($user); $placeid = $invoice->create($user);
$sql="UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS-".$place.")' where rowid=".$placeid;
$db->query($sql);
}
} }
if ($action == "addline") { if ($action == "addline") {
$prod = new Product($db);
$prod = new Product($db);
$prod->fetch($idproduct); $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); $invoice->fetch($placeid);
} }

View File

@ -65,21 +65,25 @@ $categorie = new Categorie($db);
$categories = $categorie->get_full_arbo('product'); $categories = $categorie->get_full_arbo('product');
$maincategories = array_filter($categories, function ($item) { $maincategories = array_filter($categories, function ($item) {
if (($item['level']==1) !== false) { if (($item['level']==1) !== false && ($item['visible']==1) !== false) {
return true; return true;
} }
return false; return false;
}); });
sort($maincategories);
$subcategories = array_filter($categories, function ($item) { $subcategories = array_filter($categories, function ($item) {
if (($item['level']!=1) !== false) { if (($item['level']!=1) !== false && ($item['visible']==1) !== false) {
return true; return true;
} }
return false; return false;
}); });
sort($subcategories);
?> ?>
var categories = <?php echo json_encode($categories); ?>; var categories = <?php echo json_encode($maincategories); ?>;
var subcategories = <?php echo json_encode($subcategories); ?>; var subcategories = <?php echo json_encode($subcategories); ?>;
var currentcat; var currentcat;
@ -151,7 +155,7 @@ function LoadProducts(position, issubcat=false){
idata=0; //product data counter idata=0; //product data counter
$.getJSON('./ajax.php?action=getProducts&category='+currentcat, function(data) { $.getJSON('./ajax.php?action=getProducts&category='+currentcat, function(data) {
while (idata < 30 && ishow < 30) { while (ishow < 30) {
if (typeof (data[idata]) == "undefined") { if (typeof (data[idata]) == "undefined") {
$("#prodesc"+ishow).text(""); $("#prodesc"+ishow).text("");
$("#proimg"+ishow).attr("src","genimg/empty.png"); $("#proimg"+ishow).attr("src","genimg/empty.png");
@ -191,7 +195,7 @@ function MoreProducts(moreorless){
} }
idata=30*pageproducts; //product data counter idata=30*pageproducts; //product data counter
ishow=0; //product to show counter ishow=0; //product to show counter
while (idata < (30*pageproducts)+30) { while (ishow < 30) {
if (typeof (data[idata]) == "undefined") { if (typeof (data[idata]) == "undefined") {
$("#prodesc"+ishow).text(""); $("#prodesc"+ishow).text("");
$("#proimg"+ishow).attr("src","genimg/empty.png"); $("#proimg"+ishow).attr("src","genimg/empty.png");