FIX multiple bugs for show products/categories
This commit is contained in:
parent
3ab5c3e6ab
commit
daa940d75b
@ -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();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* 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) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
|
||||
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
|
||||
@ -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';
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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 = <?php echo json_encode($categories); ?>;
|
||||
var categories = <?php echo json_encode($maincategories); ?>;
|
||||
var subcategories = <?php echo json_encode($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");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user