2004-10-20 00:24:10 +02:00
< ? php
2006-12-04 12:31:06 +01:00
/* Copyright ( C ) 2003 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2008-03-31 07:56:45 +02:00
* Copyright ( C ) 2004 - 2008 Laurent Destailleur < eldy @ users . sourceforge . net >
2009-04-28 11:41:30 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis @ dolibarr . fr >
2003-11-13 16:12:07 +01:00
*
* 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 2 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
2011-08-01 01:24:38 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2003-11-13 16:12:07 +01:00
*/
2005-04-01 00:17:49 +02:00
/**
2009-07-30 00:52:08 +02:00
* \defgroup stock Module stocks
2008-12-04 21:27:01 +01:00
* \brief Module pour gerer la tenue de stocks produits
2011-10-24 14:11:49 +02:00
* \file htdocs / core / modules / modStock . class . php
2008-12-04 21:27:01 +01:00
* \ingroup stock
* \brief Fichier de description et activation du module Stock
2008-10-01 21:10:17 +02:00
*/
2004-08-14 14:21:24 +02:00
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2007-10-10 01:15:25 +02:00
2003-11-13 16:12:07 +01:00
2005-04-01 00:17:49 +02:00
/**
2008-12-04 21:27:01 +01:00
* \class modStock
* \brief Classe de description et activation du module Stock
2008-10-01 21:10:17 +02:00
*/
2003-11-13 16:12:07 +01:00
class modStock extends DolibarrModules
{
2008-10-01 21:10:17 +02:00
/**
2011-09-26 16:22:35 +02:00
* Constructor . Define names , constants , directories , boxes , permissions
*
2012-01-04 21:23:50 +01:00
* @ param DoliDB $db Database handler
2008-10-01 21:10:17 +02:00
*/
2012-07-30 17:17:33 +02:00
function __construct ( $db )
2008-10-01 21:10:17 +02:00
{
2009-04-28 11:41:30 +02:00
global $conf ;
2009-05-04 13:40:00 +02:00
2012-01-04 21:23:50 +01:00
$this -> db = $db ;
$this -> numero = 52 ;
2008-10-01 21:10:17 +02:00
$this -> family = " products " ;
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
2009-10-21 15:09:42 +02:00
$this -> name = preg_replace ( '/^mod/i' , '' , get_class ( $this ));
2008-10-01 21:10:17 +02:00
$this -> description = " Gestion des stocks " ;
2008-12-15 23:25:59 +01:00
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this -> version = 'dolibarr' ;
2009-05-04 13:40:00 +02:00
2008-10-06 09:39:52 +02:00
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
2008-10-01 21:10:17 +02:00
$this -> special = 0 ;
$this -> picto = 'stock' ;
2009-05-04 13:40:00 +02:00
// Data directories to create when module is enabled
2008-10-01 21:10:17 +02:00
$this -> dirs = array ();
$this -> config_page_url = array ( " stock.php " );
// Dependencies
2010-04-29 16:18:42 +02:00
$this -> depends = array ( " modProduct " );
2008-10-01 21:10:17 +02:00
$this -> requiredby = array ();
$this -> langfiles = array ( " stocks " );
2009-05-04 13:40:00 +02:00
// Constants
2008-10-01 21:10:17 +02:00
$this -> const = array ();
// Boxes
$this -> boxes = array ();
// Permissions
$this -> rights = array ();
$this -> rights_class = 'stock' ;
$this -> rights [ 0 ][ 0 ] = 1001 ;
$this -> rights [ 0 ][ 1 ] = 'Lire les stocks' ;
$this -> rights [ 0 ][ 2 ] = 'r' ;
$this -> rights [ 0 ][ 3 ] = 1 ;
$this -> rights [ 0 ][ 4 ] = 'lire' ;
$this -> rights [ 0 ][ 5 ] = '' ;
$this -> rights [ 1 ][ 0 ] = 1002 ;
$this -> rights [ 1 ][ 1 ] = 'Creer/Modifier les stocks' ;
$this -> rights [ 1 ][ 2 ] = 'w' ;
$this -> rights [ 1 ][ 3 ] = 0 ;
$this -> rights [ 1 ][ 4 ] = 'creer' ;
$this -> rights [ 1 ][ 5 ] = '' ;
$this -> rights [ 2 ][ 0 ] = 1003 ;
$this -> rights [ 2 ][ 1 ] = 'Supprimer les stocks' ;
$this -> rights [ 2 ][ 2 ] = 'd' ;
$this -> rights [ 2 ][ 3 ] = 0 ;
$this -> rights [ 2 ][ 4 ] = 'supprimer' ;
$this -> rights [ 2 ][ 5 ] = '' ;
$this -> rights [ 3 ][ 0 ] = 1004 ;
$this -> rights [ 3 ][ 1 ] = 'Lire mouvements de stocks' ;
$this -> rights [ 3 ][ 2 ] = 'r' ;
$this -> rights [ 3 ][ 3 ] = 1 ;
$this -> rights [ 3 ][ 4 ] = 'mouvement' ;
$this -> rights [ 3 ][ 5 ] = 'lire' ;
$this -> rights [ 4 ][ 0 ] = 1005 ;
$this -> rights [ 4 ][ 1 ] = 'Creer/modifier mouvements de stocks' ;
$this -> rights [ 4 ][ 2 ] = 'w' ;
$this -> rights [ 4 ][ 3 ] = 0 ;
$this -> rights [ 4 ][ 4 ] = 'mouvement' ;
$this -> rights [ 4 ][ 5 ] = 'creer' ;
// Exports
//--------
$r = 0 ;
$r ++ ;
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
2008-12-04 21:27:01 +01:00
$this -> export_label [ $r ] = " WarehousesAndProducts " ; // Translation key (used only if key ExportDataset_xxx_z not found)
2008-10-01 21:10:17 +02:00
$this -> export_permission [ $r ] = array ( array ( " stock " , " lire " ));
2012-07-27 16:03:20 +02:00
$this -> export_fields_array [ $r ] = array ( 'e.rowid' => 'IdWarehouse' , 'e.label' => 'LocationSummary' , 'e.description' => 'DescWareHouse' , 'e.lieu' => 'LieuWareHouse' , 'e.address' => 'Address' , 'e.cp' => 'Zip' , 'e.ville' => 'Town' , 'p.rowid' => " ProductId " , 'p.ref' => " Ref " , 'p.fk_product_type' => " Type " , 'p.label' => " Label " , 'p.description' => " Description " , 'p.note' => " Note " , 'p.price' => " Price " , 'p.tva_tx' => 'VAT' , 'p.tosell' => " OnSell " , 'p.duration' => " Duration " , 'p.datec' => 'DateCreation' , 'p.tms' => 'DateModification' , 'ps.reel' => 'Stock' );
$this -> export_entities_array [ $r ] = array ( 'e.rowid' => 'warehouse' , 'e.label' => 'warehouse' , 'e.description' => 'warehouse' , 'e.lieu' => 'warehouse' , 'e.address' => 'warehouse' , 'e.cp' => 'warehouse' , 'e.ville' => 'warehouse' , 'p.rowid' => " product " , 'p.ref' => " product " , 'p.fk_product_type' => " product " , 'p.label' => " product " , 'p.description' => " product " , 'p.note' => " product " , 'p.price' => " product " , 'p.tva_tx' => 'product' , 'p.tosell' => " product " , 'p.duration' => " product " , 'p.datec' => 'product' , 'p.tms' => 'product' , 'ps.reel' => 'stock' );
2011-10-19 13:20:59 +02:00
$this -> export_aggregate_array [ $r ] = array ( 'ps.reel' => 'SUM' ); // TODO Not used yet
2012-07-28 11:28:37 +02:00
$this -> export_dependencies_array [ $r ] = array ( 'stock' => array ( 'p.rowid' , 'e.rowid' )); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
2009-05-04 13:40:00 +02:00
2008-10-01 21:10:17 +02:00
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'product as p, ' . MAIN_DB_PREFIX . 'product_stock as ps, ' . MAIN_DB_PREFIX . 'entrepot as e' ;
$this -> export_sql_end [ $r ] .= ' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid' ;
2009-04-28 11:41:30 +02:00
$this -> export_sql_end [ $r ] .= ' AND e.entity = ' . $conf -> entity ;
2008-10-01 21:10:17 +02:00
}
/**
2012-01-04 21:23:50 +01:00
* Function called when module is enabled .
* The init function add constants , boxes , permissions and menus ( defined in constructor ) into Dolibarr database .
* It also creates data directories
*
* @ param string $options Options when enabling module ( '' , 'noboxes' )
* @ return int 1 if OK , 0 if KO
2008-10-01 21:10:17 +02:00
*/
2012-01-04 21:23:50 +01:00
function init ( $options = '' )
2008-10-01 21:10:17 +02:00
{
$sql = array ();
2012-01-04 21:23:50 +01:00
return $this -> _init ( $sql , $options );
2008-10-01 21:10:17 +02:00
}
2012-03-03 17:37:45 +01:00
/**
* Function called when module is disabled .
* Remove from database constants , boxes and permissions from Dolibarr database .
* Data directories are not deleted
*
* @ param string $options Options when enabling module ( '' , 'noboxes' )
* @ return int 1 if OK , 0 if KO
*/
function remove ( $options = '' )
{
2008-10-01 21:10:17 +02:00
$sql = array ();
2012-03-03 17:37:45 +01:00
return $this -> _remove ( $sql , $options );
}
2008-10-01 21:10:17 +02:00
2003-11-13 16:12:07 +01:00
}
?>