forked from Wavyzz/dolibarr
NEW add extrafields in warehouses
- create table - admin extrafields - object fecth, insert, update and delete extrafields - card and list
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
*/
|
||||
require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
|
||||
|
||||
// Load translation files required by the page
|
||||
$langs->loadLangs(array("admin", "stocks"));
|
||||
@@ -77,6 +78,10 @@ llxHeader('', $langs->trans("StockSetup"));
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print load_fiche_titre($langs->trans("StockSetup"), $linkback, 'title_setup');
|
||||
|
||||
$head = stock_admin_prepare_head();
|
||||
|
||||
dol_fiche_head($head, 'general', $langs->trans("StockSetup"), -1, 'stock');
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
|
||||
|
||||
@@ -78,3 +78,37 @@ function stock_prepare_head($object)
|
||||
|
||||
return $head;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array head with list of tabs to view object informations.
|
||||
*
|
||||
* @return array head array with tabs
|
||||
*/
|
||||
function stock_admin_prepare_head()
|
||||
{
|
||||
global $langs, $conf, $user;
|
||||
|
||||
$h = 0;
|
||||
$head = array();
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT.'/admin/stock.php';
|
||||
$head[$h][1] = $langs->trans("Miscellaneous");
|
||||
$head[$h][2] = 'general';
|
||||
$h++;
|
||||
|
||||
// Show more tabs from modules
|
||||
// Entries must be declared in modules descriptor with line
|
||||
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
|
||||
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
|
||||
complete_head_from_modules($conf, $langs, null, $head, $h, 'stock_admin');
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT.'/product/admin/stock_extrafields.php';
|
||||
$head[$h][1] = $langs->trans("ExtraFields");
|
||||
$head[$h][2] = 'attributes';
|
||||
$h++;
|
||||
|
||||
complete_head_from_modules($conf, $langs, null, $head, $h, 'stock_admin', 'remove');
|
||||
|
||||
return $head;
|
||||
}
|
||||
|
||||
|
||||
15
htdocs/install/mysql/migration/10.0.0-11.0.0.sql
Normal file
15
htdocs/install/mysql/migration/10.0.0-11.0.0.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
--
|
||||
-- Be carefull to requests order.
|
||||
-- This file must be loaded by calling /install/index.php page
|
||||
-- when current version is 11.0.0 or higher.
|
||||
|
||||
|
||||
create table llx_entrepot_extrafields
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp,
|
||||
fk_object integer NOT NULL,
|
||||
import_key varchar(14) -- import key
|
||||
) ENGINE=innodb;
|
||||
|
||||
ALTER TABLE llx_entrepot_extrafields ADD INDEX idx_entrepot_extrafields (fk_object);
|
||||
20
htdocs/install/mysql/tables/llx_entrepot_extrafields.key.sql
Normal file
20
htdocs/install/mysql/tables/llx_entrepot_extrafields.key.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- ===================================================================
|
||||
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
--
|
||||
-- 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
|
||||
-- the Free Software Foundation; either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- ===================================================================
|
||||
|
||||
|
||||
ALTER TABLE llx_entrepot_extrafields ADD INDEX idx_entrepot_extrafields (fk_object);
|
||||
26
htdocs/install/mysql/tables/llx_entrepot_extrafields.sql
Normal file
26
htdocs/install/mysql/tables/llx_entrepot_extrafields.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
-- ========================================================================
|
||||
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
--
|
||||
-- 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
|
||||
-- the Free Software Foundation; either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- ========================================================================
|
||||
|
||||
create table llx_entrepot_extrafields
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp,
|
||||
fk_object integer NOT NULL,
|
||||
import_key varchar(14) -- import key
|
||||
) ENGINE=innodb;
|
||||
|
||||
@@ -106,6 +106,7 @@ CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_emailcollector_email
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_emailcollector_emailcollectoraction FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_emailcollector_emailcollectorfilter FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_entrepot FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_entrepot_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_events FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_expedition FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_expensereport FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
|
||||
116
htdocs/product/admin/stock_extrafields.php
Normal file
116
htdocs/product/admin/stock_extrafields.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
|
||||
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/product/admin/stock_extrafields.php
|
||||
* \ingroup stock
|
||||
* \brief Page to setup extra fields of third party
|
||||
*/
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
|
||||
// Load translation files required by the page
|
||||
$langs->loadLangs(array('companies', 'admin', 'stock'));
|
||||
|
||||
$extrafields = new ExtraFields($db);
|
||||
$form = new Form($db);
|
||||
|
||||
// List of supported format
|
||||
$tmptype2label=ExtraFields::$type2label;
|
||||
$type2label=array('');
|
||||
foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val);
|
||||
|
||||
$action=GETPOST('action', 'alpha');
|
||||
$attrname=GETPOST('attrname', 'alpha');
|
||||
$elementtype='entrepot'; //Must be the $table_element of the class that manage extrafield
|
||||
|
||||
if (!$user->admin) accessforbidden();
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$textobject=$langs->transnoentitiesnoconv("Warehouses");
|
||||
|
||||
llxHeader('', $langs->trans("StockSetup"));
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print load_fiche_titre($langs->trans("StockSetup"), $linkback, 'title_setup');
|
||||
|
||||
|
||||
$head = stock_admin_prepare_head();
|
||||
|
||||
dol_fiche_head($head, 'attributes', $langs->trans("Warehouses"), -1, 'stock');
|
||||
|
||||
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
|
||||
// Buttons
|
||||
if ($action != 'create' && $action != 'edit')
|
||||
{
|
||||
print '<div class="tabsAction">';
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=create">'.$langs->trans("NewAttribute").'</a></div>';
|
||||
print "</div>";
|
||||
}
|
||||
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* Creation of an optional field */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
if ($action == 'create')
|
||||
{
|
||||
print "<br>";
|
||||
print load_fiche_titre($langs->trans('NewAttribute'));
|
||||
|
||||
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* Edition of an optional field */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
if ($action == 'edit' && ! empty($attrname))
|
||||
{
|
||||
print "<br>";
|
||||
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
|
||||
|
||||
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
|
||||
}
|
||||
|
||||
// End of page
|
||||
llxFooter();
|
||||
$db->close();
|
||||
@@ -33,6 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
|
||||
|
||||
// Load translation files required by the page
|
||||
$langs->loadLangs(array('products', 'stocks', 'companies', 'categories'));
|
||||
@@ -55,16 +56,32 @@ $backtopage=GETPOST('backtopage', 'alpha');
|
||||
//$result=restrictedArea($user,'stock', $id, 'entrepot&stock');
|
||||
$result=restrictedArea($user, 'stock');
|
||||
|
||||
$object = new Entrepot($db);
|
||||
$extrafields = new ExtraFields($db);
|
||||
|
||||
// fetch optionals attributes and labels
|
||||
$extralabels = $extrafields->fetch_name_optionals_label('entrepot');
|
||||
|
||||
// Load object
|
||||
if ($id > 0 || ! empty($ref)) {
|
||||
$ret = $object->fetch($id, $ref);
|
||||
// if ($ret > 0)
|
||||
// $ret = $object->fetch_thirdparty();
|
||||
if ($ret <= 0) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$action = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
|
||||
$hookmanager->initHooks(array('warehousecard','globalcard'));
|
||||
|
||||
$object = new Entrepot($db);
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
$error = 0;
|
||||
|
||||
$usercanread = (($user->rights->stock->lire));
|
||||
$usercancreate = (($user->rights->stock->creer));
|
||||
$usercandelete = (($user->rights->stock->supprimer));
|
||||
@@ -85,28 +102,31 @@ if ($action == 'add' && $user->rights->stock->creer)
|
||||
|
||||
if (! empty($object->libelle))
|
||||
{
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
|
||||
if ($ret < 0) {
|
||||
$error++;
|
||||
$action = 'create';
|
||||
}
|
||||
|
||||
if (! $error) {
|
||||
$id = $object->create($user);
|
||||
if ($id > 0)
|
||||
{
|
||||
if ($id > 0) {
|
||||
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
|
||||
|
||||
if (! empty($backtopage))
|
||||
{
|
||||
if (!empty($backtopage)) {
|
||||
header("Location: " . $backtopage);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
header("Location: card.php?id=" . $id);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$action = 'create';
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($langs->trans("ErrorWarehouseRefRequired"), null, 'errors');
|
||||
@@ -147,15 +167,21 @@ if ($action == 'update' && $cancel <> $langs->trans("Cancel"))
|
||||
$object->town = GETPOST("town");
|
||||
$object->country_id = GETPOST("country_id");
|
||||
|
||||
if ( $object->update($id, $user) > 0)
|
||||
{
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
|
||||
if ($ret < 0) $error++;
|
||||
|
||||
if (! $error) {
|
||||
$ret = $object->update($id, $user);
|
||||
if ($ret < 0) $error++;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
$action = 'edit';
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
} else {
|
||||
$action = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$action = 'edit';
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -163,6 +189,22 @@ if ($action == 'update' && $cancel <> $langs->trans("Cancel"))
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
elseif ($action == 'update_extras') {
|
||||
$object->oldcopy = dol_clone($object);
|
||||
|
||||
// Fill array 'array_options' with data from update form
|
||||
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none'));
|
||||
if ($ret < 0) $error++;
|
||||
if (! $error) {
|
||||
$result = $object->insertExtraFields();
|
||||
if ($result < 0) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
if ($error) $action = 'edit_extras';
|
||||
}
|
||||
|
||||
if ($cancel == $langs->trans("Cancel"))
|
||||
{
|
||||
@@ -257,6 +299,9 @@ if ($action == 'create')
|
||||
print '</select>';
|
||||
print '</td></tr>';
|
||||
|
||||
// Other attributes
|
||||
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
|
||||
|
||||
print '</table>';
|
||||
|
||||
dol_fiche_end();
|
||||
@@ -392,6 +437,9 @@ else
|
||||
}
|
||||
print "</td></tr>";
|
||||
|
||||
// Other attributes
|
||||
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
|
||||
|
||||
print "</table>";
|
||||
|
||||
print '</div>';
|
||||
@@ -638,6 +686,7 @@ else
|
||||
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Status
|
||||
print '<tr><td>'.$langs->trans("Status").'</td><td>';
|
||||
print '<select name="statut" class="flat">';
|
||||
foreach ($object->statuts as $key => $value)
|
||||
@@ -654,6 +703,15 @@ else
|
||||
print '</select>';
|
||||
print '</td></tr>';
|
||||
|
||||
// Other attributes
|
||||
$parameters=array('colspan' => ' colspan="3"', 'cols'=>3);
|
||||
$reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
if (empty($reshook))
|
||||
{
|
||||
print $object->showOptionals($extrafields, 'edit');
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
@@ -163,6 +163,19 @@ class Entrepot extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
// Actions on extra fields
|
||||
if (! $error)
|
||||
{
|
||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
||||
{
|
||||
$result=$this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
@@ -199,6 +212,10 @@ class Entrepot extends CommonObject
|
||||
*/
|
||||
public function update($id, $user)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$error=0;
|
||||
|
||||
if (empty($id)) $id = $this->id;
|
||||
|
||||
// Check if new parent is already a child of current warehouse
|
||||
@@ -239,13 +256,24 @@ class Entrepot extends CommonObject
|
||||
|
||||
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
|
||||
if (! $resql) {
|
||||
$error++;
|
||||
$this->errors[]="Error ".$this->db->lasterror();
|
||||
}
|
||||
|
||||
if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) {
|
||||
$result=$this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->db->rollback();
|
||||
$this->error=$this->db->lasterror();
|
||||
return -1;
|
||||
@@ -262,6 +290,10 @@ class Entrepot extends CommonObject
|
||||
*/
|
||||
public function delete($user, $notrigger = 0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$error = 0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
if (! $error && empty($notrigger))
|
||||
@@ -293,17 +325,30 @@ class Entrepot extends CommonObject
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."entrepot";
|
||||
$sql.= " WHERE rowid = " . $this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||
$resql1=$this->db->query($sql);
|
||||
if (!$resql1) $error++;
|
||||
|
||||
// Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET stock = (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)";
|
||||
|
||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||
$resql2=$this->db->query($sql);
|
||||
if (!$resql2) $error++;
|
||||
|
||||
if ($resql1 && $resql2)
|
||||
// Removed extrafields
|
||||
if (! $error) {
|
||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
||||
{
|
||||
$result=$this->deleteExtraFields();
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$errorflag=-4;
|
||||
dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
@@ -377,6 +422,10 @@ class Entrepot extends CommonObject
|
||||
$this->town = $obj->town;
|
||||
$this->country_id = $obj->country_id;
|
||||
|
||||
// Retreive all extrafield
|
||||
// fetch optionals attributes and labels
|
||||
$this->fetch_optionals();
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
$tmp=getCountry($this->country_id, 'all');
|
||||
$this->country=$tmp['label'];
|
||||
@@ -386,6 +435,7 @@ class Entrepot extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Record Not Found";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,16 @@ $offset = $limit * $page;
|
||||
|
||||
$year = strftime("%Y", time());
|
||||
|
||||
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
|
||||
$object = new Entrepot($db);
|
||||
$hookmanager->initHooks(array('stocklist'));
|
||||
$extrafields = new ExtraFields($db);
|
||||
|
||||
// fetch optionals attributes and labels
|
||||
$extralabels = $extrafields->fetch_name_optionals_label('entrepot');
|
||||
$search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
|
||||
|
||||
|
||||
// List of fields to search into when doing a "search in all"
|
||||
$fieldstosearchall = array(
|
||||
'e.ref'=>"Ref",
|
||||
@@ -60,6 +70,16 @@ $fieldstosearchall = array(
|
||||
);
|
||||
|
||||
|
||||
// Extra fields
|
||||
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
|
||||
{
|
||||
foreach($extrafields->attribute_label as $key => $val)
|
||||
{
|
||||
if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
@@ -85,14 +105,19 @@ $warehouse=new Entrepot($db);
|
||||
|
||||
$sql = "SELECT e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays, e.fk_parent,";
|
||||
$sql.= " SUM(p.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue, SUM(ps.reel) as stockqty";
|
||||
// Add fields from extrafields
|
||||
foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON e.rowid = ps.fk_entrepot";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid";
|
||||
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot_extrafields as ef on (e.rowid = ef.fk_object)";
|
||||
$sql.= " WHERE e.entity IN (".getEntity('stock').")";
|
||||
if ($search_ref) $sql.= natural_search("e.ref", $search_ref); // ref
|
||||
if ($search_label) $sql.= natural_search("e.lieu", $search_label); // label
|
||||
if ($search_status != '' && $search_status >= 0) $sql.= " AND e.statut = ".$search_status;
|
||||
if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
|
||||
// Add where from extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
|
||||
$sql.= " GROUP BY e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays, e.fk_parent";
|
||||
$totalnboflines=0;
|
||||
$result=$db->query($sql);
|
||||
@@ -131,6 +156,9 @@ if ($result)
|
||||
if ($search_status) $param.="&search_status=".urlencode($search_status);
|
||||
if ($sall) $param.="&sall=".urlencode($sall);
|
||||
|
||||
// Add $param from extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
|
||||
|
||||
$newcardbutton='';
|
||||
if ($user->rights->stock->creer)
|
||||
{
|
||||
@@ -173,6 +201,9 @@ if ($result)
|
||||
print '<td class="liste_titre" colspan="3">';
|
||||
print '</td>';
|
||||
|
||||
// Extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
|
||||
|
||||
print '<td class="liste_titre right">';
|
||||
print $form->selectarray('search_status', $warehouse->statuts, $search_status, 1, 0, 0, '', 1);
|
||||
print '</td>';
|
||||
@@ -190,6 +221,8 @@ if ($result)
|
||||
print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stockqty", '', $param, '', $sortfield, $sortorder, 'right ');
|
||||
print_liste_field_titre("EstimatedStockValue", $_SERVER["PHP_SELF"], "estimatedvalue", '', $param, '', $sortfield, $sortorder, 'right ');
|
||||
print_liste_field_titre("EstimatedStockValueSell", $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
|
||||
// Extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
|
||||
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.statut", '', $param, '', $sortfield, $sortorder, 'right ');
|
||||
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
|
||||
print "</tr>\n";
|
||||
@@ -198,40 +231,55 @@ if ($result)
|
||||
{
|
||||
$warehouse=new Entrepot($db);
|
||||
$var=false;
|
||||
$totalarray=array();
|
||||
while ($i < min($num, $limit))
|
||||
{
|
||||
$objp = $db->fetch_object($result);
|
||||
$obj = $db->fetch_object($result);
|
||||
|
||||
$warehouse->id = $objp->rowid;
|
||||
$warehouse->ref = $objp->ref;
|
||||
$warehouse->label = $objp->ref;
|
||||
$warehouse->lieu = $objp->lieu;
|
||||
$warehouse->fk_parent = $objp->fk_parent;
|
||||
$warehouse->id = $obj->rowid;
|
||||
$warehouse->ref = $obj->ref;
|
||||
$warehouse->label = $obj->ref;
|
||||
$warehouse->lieu = $obj->lieu;
|
||||
$warehouse->fk_parent = $obj->fk_parent;
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>' . $warehouse->getNomUrl(1) . '</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
// Location
|
||||
print '<td>'.$objp->lieu.'</td>';
|
||||
print '<td>'.$obj->lieu.'</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
// Stock qty
|
||||
print '<td class="right">'.price2num($objp->stockqty, 5).'</td>';
|
||||
print '<td class="right">'.price2num($obj->stockqty, 5).'</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
// PMP value
|
||||
print '<td class="right">';
|
||||
if (price2num($objp->estimatedvalue, 'MT')) print price(price2num($objp->estimatedvalue, 'MT'), 1);
|
||||
if (price2num($obj->estimatedvalue, 'MT')) print price(price2num($obj->estimatedvalue, 'MT'), 1);
|
||||
else print '';
|
||||
print '</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
// Selling value
|
||||
print '<td class="right">';
|
||||
if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($objp->sellvalue, 'MT'), 1);
|
||||
if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($obj->sellvalue, 'MT'), 1);
|
||||
else
|
||||
{
|
||||
$htmltext=$langs->trans("OptionMULTIPRICESIsOn");
|
||||
print $form->textwithtooltip($langs->trans("Variable"), $htmltext);
|
||||
}
|
||||
print '</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
// Extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
|
||||
|
||||
// Status
|
||||
print '<td class="right">'.$warehouse->LibStatut($objp->statut, 5).'</td>';
|
||||
print '<td class="right">'.$warehouse->LibStatut($obj->statut, 5).'</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
print '<td></td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
print "</tr>\n";
|
||||
|
||||
@@ -255,6 +303,7 @@ if ($result)
|
||||
print '</td>';
|
||||
print '<td></td>';
|
||||
print '<td></td>';
|
||||
print '<td></td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user