Added ability to assign a category of product to a customer

This commit is contained in:
Regis Houssin 2008-10-08 08:03:28 +00:00
parent 6554fde40d
commit deb94493dd
5 changed files with 21 additions and 13 deletions

View File

@ -124,11 +124,9 @@ class Categorie
*/ */
function create() function create()
{ {
global $langs; global $conf,$langs;
$langs->load('categories'); $langs->load('categories');
if ($this->socid == -1) $this->socid = 0;
if ($this->already_exists ()) if ($this->already_exists ())
{ {
$this->error=$langs->trans("ImpossibleAddCat"); $this->error=$langs->trans("ImpossibleAddCat");
@ -136,9 +134,17 @@ class Categorie
return -1; return -1;
} }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description, fk_soc, visible, type) "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description,";
if ($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)
{
$sql.= "fk_soc,";
}
$sql.= "visible, type) ";
$sql.= "VALUES ('".addslashes($this->label)."', '".addslashes($this->description)."',"; $sql.= "VALUES ('".addslashes($this->label)."', '".addslashes($this->description)."',";
$sql.= ($this->socid?$this->socid:"null").","; if ($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)
{
$sql.= ($this->socid != -1 ? $this->socid : 'null').",";
}
$sql.= "'".$this->visible."',".$this->type.")"; $sql.= "'".$this->visible."',".$this->type.")";
@ -186,7 +192,6 @@ class Categorie
// Clean parameters // Clean parameters
$this->label=trim($this->label); $this->label=trim($this->label);
$this->description=trim($this->description); $this->description=trim($this->description);
if ($this->socid == -1) $this->socid = 0;
$this->db->begin(); $this->db->begin();
@ -223,7 +228,7 @@ class Categorie
} }
if ($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) if ($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)
{ {
$sql .= ", fk_soc = ".$this->socid; $sql .= ", fk_soc = ".($this->socid != -1 ? $this->socid : 'null');
} }
$sql .= ", visible = '".$this->visible."'"; $sql .= ", visible = '".$this->visible."'";
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;

View File

@ -33,6 +33,8 @@ require "./pre.inc.php";
if (!$user->rights->categorie->lire) if (!$user->rights->categorie->lire)
accessforbidden(); accessforbidden();
$type=$_REQUEST['type'];
// If socid provided by ajax company selector // If socid provided by ajax company selector
if (! empty($_POST['socid_id'])) if (! empty($_POST['socid_id']))
{ {
@ -71,7 +73,7 @@ if ($_POST["action"] == 'update' && $user->rights->categorie->creer)
{ {
if ($categorie->update($user) > 0) if ($categorie->update($user) > 0)
{ {
header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id); header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id.'&type='.$type);
exit; exit;
} }
else else
@ -114,6 +116,7 @@ print "\n";
print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$categorie->id.'">'; print '<input type="hidden" name="id" value="'.$categorie->id.'">';
print '<input type="hidden" name="type" value="'.$type.'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td>'; print '<tr><td>';

View File

@ -34,7 +34,7 @@ if ($_REQUEST['id'] == "")
exit(); exit();
} }
$type=$_GET['type']; $type=$_REQUEST['type'];
// Securite // Securite
if (! $user->rights->categorie->lire) if (! $user->rights->categorie->lire)
@ -136,7 +136,7 @@ if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)
else else
{ {
print '<tr><td width="20%" class="notopnoleft">'; print '<tr><td width="20%" class="notopnoleft">';
print $langs->trans("InernalCategory").'</td><td>'; print $langs->trans("InternalCategory").'</td><td>';
print ($c->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); print ($c->visible ? $langs->trans("Visible") : $langs->trans("Invisible"));
print '</td></tr>'; print '</td></tr>';
} }
@ -161,7 +161,7 @@ print "<div class='tabsAction'>\n";
if ($user->rights->categorie->creer) if ($user->rights->categorie->creer)
{ {
print "<a class='butAction' href='edit.php?id=".$c->id."'>".$langs->trans("Modify")."</a>"; print "<a class='butAction' href='edit.php?id=".$c->id."&amp;type=".$type."'>".$langs->trans("Modify")."</a>";
} }
if ($user->rights->categorie->supprimer) if ($user->rights->categorie->supprimer)

View File

@ -34,7 +34,7 @@ alter table llx_rights_def modify column type varchar(1);
ALTER TABLE `llx_commandedet` ADD column `date_start` DATETIME DEFAULT NULL, ADD `date_end` DATETIME DEFAULT NULL ; ALTER TABLE `llx_commandedet` ADD column `date_start` DATETIME DEFAULT NULL, ADD `date_end` DATETIME DEFAULT NULL ;
alter table llx_categorie add column fk_soc integer DEFAULT 0 after description; alter table llx_categorie add column fk_soc integer DEFAULT NULL after description;
alter table llx_product drop column nbvente; alter table llx_product drop column nbvente;

View File

@ -25,7 +25,7 @@ create table llx_categorie
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
label VARCHAR(255), -- category name label VARCHAR(255), -- category name
description text, -- description of the category description text, -- description of the category
fk_soc integer DEFAULT 0, -- attribution of the category has a company (for product only) fk_soc integer DEFAULT NULL, -- attribution of the category has a company (for product only)
visible tinyint DEFAULT 1 NOT NULL, -- determine if the products are visible or not visible tinyint DEFAULT 1 NOT NULL, -- determine if the products are visible or not
type tinyint DEFAULT 1 NOT NULL -- category type (product, supplier, customer) type tinyint DEFAULT 1 NOT NULL -- category type (product, supplier, customer)
)type=innodb; )type=innodb;