New: works on sharings between entities

Fix: problem with tosell and tobuy
This commit is contained in:
Regis Houssin 2011-04-18 08:38:51 +00:00
parent f7daa88752
commit 783c050df0
2 changed files with 33 additions and 25 deletions

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -37,9 +37,17 @@ if ($type=='0') $result=restrictedArea($user,'produit',$id,'product','','',$fiel
else if ($type=='1') $result=restrictedArea($user,'service',$id,'service','','',$fieldid);
else $result=restrictedArea($user,'produit|service',$id,'service','','',$fieldid);
$langs->load("products");
$product_static = new Product($db);
$langs->load("products");
// Sharings between entities
if ($conf->global->MAIN_MODULE_MULTICOMPANY)
{
dol_include_once('/multicompany/class/actions_multicompany.class.php');
$mc = new ActionsMulticompany($db);
$mc->getEntitySharing('product');
}
/*
@ -107,7 +115,7 @@ $prodser[0][0]=$prodser[0][1]=$prodser[1][0]=$prodser[1][1]=0;
$sql = "SELECT COUNT(p.rowid) as total, p.fk_product_type, p.tosell, p.tobuy";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= " WHERE p.entity = ".$conf->entity;
$sql.= " WHERE p.entity IN (0,".($mc->share ? $mc->share : $conf->entity).")";
$sql.= " GROUP BY p.fk_product_type, p.tosell, p.tobuy";
$result = $db->query($sql);
while ($objp = $db->fetch_object($result))
@ -122,7 +130,7 @@ print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Statistics").'</
if ($conf->product->enabled)
{
$statProducts = "<tr $bc[0]>";
$statProducts.= '<td><a href="liste.php?type=0&amp;tosell=0">'.$langs->trans("ProductsNotOnSell").'</a></td><td align="right">'.round($prodser[0][0]).'</td>';
$statProducts.= '<td><a href="liste.php?type=0&amp;tosell=0&amp;tobuy=0">'.$langs->trans("ProductsNotOnSell").'</a></td><td align="right">'.round($prodser[0][0]).'</td>';
$statProducts.= "</tr>";
$statProducts.= "<tr $bc[1]>";
$statProducts.= '<td><a href="liste.php?type=0&amp;tosell=1">'.$langs->trans("ProductsOnSell").'</a></td><td align="right">'.round($prodser[0][1]).'</td>';
@ -131,7 +139,7 @@ if ($conf->product->enabled)
if ($conf->service->enabled)
{
$statServices = "<tr $bc[0]>";
$statServices.= '<td><a href="liste.php?type=1&amp;tosell=0">'.$langs->trans("ServicesNotOnSell").'</a></td><td align="right">'.round($prodser[1][0]).'</td>';
$statServices.= '<td><a href="liste.php?type=1&amp;tosell=0&amp;tobuy=0">'.$langs->trans("ServicesNotOnSell").'</a></td><td align="right">'.round($prodser[1][0]).'</td>';
$statServices.= "</tr>";
$statServices.= "<tr $bc[1]>";
$statServices.= '<td><a href="liste.php?type=1&amp;tosell=1">'.$langs->trans("ServicesOnSell").'</a></td><td align="right">'.round($prodser[1][1]).'</td>';
@ -167,7 +175,7 @@ $max=15;
$sql = "SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy,";
$sql.= " p.tms as datem";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= " WHERE p.entity = ".$conf->entity;
$sql.= " WHERE p.entity IN (0,".($mc->share ? $mc->share : $conf->entity).")";
if (empty($user->rights->produit->hidden) && empty($user->rights->service->hidden)) $sql.=' AND p.hidden=0';
else
{

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -40,6 +40,8 @@ $sall=GETPOST("sall");
$type=GETPOST("type","int");
$search_sale = GETPOST("search_sale");
$search_categ = GETPOST("search_categ");
$tosell = GETPOST("tosell");
$tobuy = GETPOST("tobuy");
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
@ -79,6 +81,13 @@ else
else $result=restrictedArea($user,'produit|service',$id,'service','','',$fieldid);
}
// Sharings between entities
if ($conf->global->MAIN_MODULE_MULTICOMPANY)
{
dol_include_once('/multicompany/class/actions_multicompany.class.php');
$mc = new ActionsMulticompany($db);
$mc->getEntitySharing('product');
}
/*
@ -147,7 +156,7 @@ if ($_GET["fourn_id"] > 0) // The DISTINCT is used to avoid duplicate from this
$fourn_id = $_GET["fourn_id"];
$sql.= ", ".MAIN_DB_PREFIX."product_fournisseur as pf";
}
$sql.= " WHERE p.entity = ".$conf->entity;
$sql.= " WHERE p.entity IN (0,".($mc->share ? $mc->share : $conf->entity).")";
if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
if (!$user->rights->produit->hidden && !$user->rights->service->hidden)
{
@ -160,7 +169,7 @@ else
}
if ($sall)
{
$sql.= " AND (p.ref like '%".$db->escape($sall)."%' OR p.label like '%".$db->escape($sall)."%' OR p.description like '%".$db->escape($sall)."%' OR p.note like '%".$db->escape($sall)."%')";
$sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%')";
}
# if the type is not 1, we show all products (type = 0,2,3)
if (dol_strlen($type))
@ -174,13 +183,13 @@ if (dol_strlen($type))
if ($sref) $sql.= " AND p.ref like '%".$sref."%'";
if ($sbarcode) $sql.= " AND p.barcode like '%".$sbarcode."%'";
if ($snom) $sql.= " AND p.label like '%".$db->escape($snom)."%'";
if (isset($_GET["tosell"]) && dol_strlen($_GET["tosell"]) > 0)
if (isset($tosell) && dol_strlen($tosell) > 0)
{
$sql.= " AND p.tosell = ".$db->escape($_GET["tosell"]);
$sql.= " AND p.tosell = ".$db->escape($tosell);
}
if (isset($_GET["tobuy"]) && dol_strlen($_GET["tobuy"]) > 0)
if (isset($tobuy) && dol_strlen($tobuy) > 0)
{
$sql.= " AND p.tobuy = ".$_GET["tobuy"];
$sql.= " AND p.tobuy = ".$db->escape($tobuy);
}
if (dol_strlen($canvas) > 0)
{
@ -213,22 +222,13 @@ if ($resql)
$i = 0;
if ($num == 1 && ($sall || $snom || $sref || $sbarcode) && $_POST["action"] != 'list')
if ($num == 1 && ($sall || $snom || $sref || $sbarcode) && $action != 'list')
{
$objp = $db->fetch_object($resql);
Header("Location: fiche.php?id=".$objp->rowid);
exit;
}
if (isset($_GET["tosell"]) || isset($_POST["tosell"]))
{
$tosell = (isset($_GET["tosell"])?$_GET["tosell"]:$_POST["tosell"]);
}
if (isset($_GET["tobuy"]) || isset($_POST["tobuy"]))
{
$tosell = (isset($_GET["tobuy"])?$_GET["tobuy"]:$_POST["tobuy"]);
}
$helpurl='';
if (isset($_GET["type"]) && $_GET["type"] == 0)
{