2004-10-20 00:24:10 +02:00
< ? php
2005-05-14 16:22:08 +02:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2010-03-13 02:10:27 +01:00
* Copyright ( C ) 2004 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-05-14 16:22:08 +02:00
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2009-04-28 11:41:30 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis @ dolibarr . fr >
2003-08-11 20:44:32 +02: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
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
2005-04-12 22:01:42 +02:00
/**
2009-07-30 00:52:08 +02:00
* \defgroup produit Module products
2009-03-07 02:30:47 +01:00
* \brief Module pour gerer le suivi de produits predefinis
* \version $Id $
2008-10-01 21:10:17 +02:00
*/
2004-08-14 14:21:24 +02:00
2005-01-14 19:46:23 +01:00
/**
2009-02-06 22:56:55 +01:00
* \file htdocs / includes / modules / modProduit . class . php
* \ingroup produit
* \brief Fichier de description et activation du module Produit
2008-10-01 21:10:17 +02:00
*/
2004-08-14 14:21:24 +02:00
2007-10-10 01:15:25 +02:00
include_once ( DOL_DOCUMENT_ROOT . " /includes/modules/DolibarrModules.class.php " );
2003-11-13 16:09:12 +01:00
2005-04-12 22:01:42 +02:00
/**
2009-02-06 22:56:55 +01:00
* \class modProduit
* \brief Classe de description et activation du module Produit
2008-10-01 21:10:17 +02:00
*/
2003-11-13 16:09:12 +01:00
class modProduit extends DolibarrModules
2003-08-11 20:44:32 +02:00
{
2008-10-01 21:10:17 +02:00
/**
* \brief Constructeur . Definit les noms , constantes et boites
2009-02-06 22:56:55 +01:00
* \param DB handler d ' acces base
2008-10-01 21:10:17 +02:00
*/
function modProduit ( $DB )
{
global $conf ;
2010-03-13 00:40:39 +01:00
$this -> db = $DB ;
$this -> numero = 50 ;
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 produits " ;
2008-12-15 23:25:59 +01:00
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this -> version = 'dolibarr' ;
2009-01-21 14:20:26 +01: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 = 'product' ;
2009-04-28 15:04:35 +02:00
// Data directories to create when module is enabled
2009-05-04 13:40:00 +02:00
$this -> dirs = array ( " /produit/temp " );
2008-10-01 21:10:17 +02:00
2008-12-05 00:06:45 +01:00
// Dependencies
2008-10-01 21:10:17 +02:00
$this -> depends = array ();
2009-06-08 20:14:37 +02:00
$this -> requiredby = array ( " modStock " , " modBarcode " );
2008-10-01 21:10:17 +02:00
// Config pages
$this -> config_page_url = array ( " produit.php " );
2009-06-08 20:44:53 +02:00
$this -> langfiles = array ( " products " , " companies " , " stocks " , " bills " );
2008-10-01 21:10:17 +02:00
2009-06-08 20:44:53 +02:00
// Constants
2008-10-01 21:10:17 +02:00
$this -> const = array ();
$r = 0 ;
$this -> const [ $r ][ 0 ] = " MAIN_SEARCHFORM_PRODUITSERVICE " ;
$this -> const [ $r ][ 1 ] = " yesno " ;
$this -> const [ $r ][ 2 ] = " 1 " ;
$this -> const [ $r ][ 3 ] = " Affichage formulaire de recherche des Produits et Services dans la barre de gauche " ;
$this -> const [ $r ][ 4 ] = 0 ;
2010-04-03 12:26:33 +02:00
$this -> const [ $r ][ 5 ] = 'allentities' ;
2008-10-01 21:10:17 +02:00
$r ++ ;
// Boxes
$this -> boxes = array ();
$this -> boxes [ 0 ][ 1 ] = " box_produits.php " ;
// Permissions
$this -> rights = array ();
$this -> rights_class = 'produit' ;
$r = 0 ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 31 ; // id de la permission
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 1 ] = 'Lire les produits' ; // libelle de la permission
2009-04-28 11:41:30 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ; // type de la permission (deprecie a ce jour)
$this -> rights [ $r ][ 3 ] = 1 ; // La permission est-elle une permission par defaut
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 4 ] = 'lire' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 32 ; // id de la permission
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 1 ] = 'Creer/modifier les produits' ; // libelle de la permission
2009-04-28 11:41:30 +02:00
$this -> rights [ $r ][ 2 ] = 'w' ; // type de la permission (deprecie a ce jour)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par defaut
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 4 ] = 'creer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 34 ; // id de la permission
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 1 ] = 'Supprimer les produits' ; // libelle de la permission
2009-04-28 11:41:30 +02:00
$this -> rights [ $r ][ 2 ] = 'd' ; // type de la permission (deprecie a ce jour)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par defaut
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 4 ] = 'supprimer' ;
2010-03-13 00:40:39 +01:00
$this -> rights [ $r ][ 0 ] = 36 ; // id de la permission
$this -> rights [ $r ][ 1 ] = 'Voir/gérer les produits cachés' ; // libelle de la permission
$this -> rights [ $r ][ 2 ] = 'r' ; // type de la permission (deprecated)
$this -> rights [ $r ][ 3 ] = 1 ; // La permission est-elle une permission par defaut
$this -> rights [ $r ][ 4 ] = 'hidden' ;
$r ++ ;
2008-10-01 21:10:17 +02:00
$r ++ ;
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 0 ] = 38 ; // Must be same permission than in service module
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 1 ] = 'Exporter les produits' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'export' ;
// Exports
//--------
$r = 0 ;
$r ++ ;
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
2009-06-08 20:44:53 +02:00
$this -> export_label [ $r ] = " Products " ; // 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 ( " produit " , " export " ));
2010-03-20 21:24:32 +01:00
$this -> export_fields_array [ $r ] = array ( 'p.rowid' => " Id " , 'p.ref' => " Ref " , 'p.label' => " Label " , 'p.description' => " Description " , 'p.accountancy_code_sell' => " ProductAccountancySellCode " , 'p.accountancy_code_buy' => " ProductAccountancyBuyCode " , 'p.note' => " Note " , 'p.length' => " Length " , 'p.surface' => " Surface " , 'p.volume' => " Volume " , 'p.weight' => " Weight " , 'p.price_base_type' => " PriceBase " , 'p.price' => " UnitPriceHT " , 'p.price_ttc' => " UnitPriceTTC " , 'p.tva_tx' => 'VATRate' , 'p.envente' => " OnSell " , 'p.datec' => 'DateCreation' , 'p.tms' => 'DateModification' );
2010-03-13 02:10:27 +01:00
if ( ! empty ( $conf -> stock -> enabled )) $this -> export_fields_array [ $r ] = array_merge ( $this -> export_fields_array [ $r ], array ( 'p.stock' => 'Stock' , 'p.pmp' => 'PMPValue' ));
if ( ! empty ( $conf -> barcode -> enabled )) $this -> export_fields_array [ $r ] = array_merge ( $this -> export_fields_array [ $r ], array ( 'p.barcode' => 'Barcode' ));
2010-03-20 21:24:32 +01:00
$this -> export_entities_array [ $r ] = array ( 'p.rowid' => " product " , 'p.ref' => " product " , 'p.label' => " product " , 'p.description' => " product " , 'p.accountancy_code_sell' => 'product' , 'p.accountancy_code_sell' => 'product' , 'p.note' => " product " , 'p.length' => " product " , 'p.surface' => " product " , 'p.volume' => " product " , 'p.weight' => " product " , 'p.price_base_type' => " product " , 'p.price' => " product " , 'p.price_ttc' => " product " , 'p.tva_tx' => " product " , 'p.envente' => " product " , 'p.datec' => " product " , 'p.tms' => " product " );
2010-03-13 02:10:27 +01:00
if ( ! empty ( $conf -> stock -> enabled )) $this -> export_entities_array [ $r ] = array_merge ( $this -> export_entities_array [ $r ], array ( 'p.stock' => 'product' , 'p.pmp' => 'product' ));
if ( ! empty ( $conf -> barcode -> enabled )) $this -> export_entities_array [ $r ] = array_merge ( $this -> export_entities_array [ $r ], array ( 'p.barcode' => 'product' ));
2010-03-20 21:24:32 +01:00
$this -> export_alias_array [ $r ] = array ( 'p.rowid' => " id " , 'p.ref' => " ref " , 'p.label' => " label " , 'p.description' => " description " , 'p.accountancy_code_sell' => 'accountancy_code_sell' , 'p.accountancy_code_buy' => 'accountancy_code_buy' , 'p.note' => " note " , 'p.length' => " length " , 'p.surface' => " area " , 'p.volume' => " volume " , 'p.weight' => " weight " , 'p.price_base_type' => 'pricebase' , 'p.price' => " priceht " , 'p.price_ttc' => " pricettc " , 'p.tva_tx' => 'vat' , 'p.envente' => " onsell " , 'p.datec' => 'datecreation' , 'p.tms' => 'datemodification' );
2010-03-13 02:10:27 +01:00
if ( ! empty ( $conf -> stock -> enabled )) $this -> export_alias_array [ $r ] = array_merge ( $this -> export_alias_array [ $r ], array ( 'p.stock' => 'stock' , 'p.pmp' => 'pmp' ));
if ( ! empty ( $conf -> barcode -> enabled )) $this -> export_alias_array [ $r ] = array_merge ( $this -> export_alias_array [ $r ], array ( 'p.barcode' => 'barcode' ));
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' ;
2009-06-08 20:44:53 +02:00
$this -> export_sql_end [ $r ] .= ' WHERE p.fk_product_type = 0 AND p.entity = ' . $conf -> entity ;
2008-10-01 21:10:17 +02:00
// Imports
//--------
$r = 0 ;
$r ++ ;
2009-01-21 14:20:26 +01:00
$this -> import_code [ $r ] = $this -> rights_class . '_' . $r ;
2009-06-08 20:44:53 +02:00
$this -> import_label [ $r ] = " Products " ; // Translation key
2009-11-08 20:28:44 +01:00
$this -> import_icon [ $r ] = 'product' ;
2009-10-04 00:32:10 +02:00
$this -> import_tables_array [ $r ] = array ( 'p' => MAIN_DB_PREFIX . 'product' );
2009-10-17 15:12:55 +02:00
$this -> import_tables_creator_array [ $r ] = array ( 'p' => 'fk_user_author' ); // Fields to store import user id
$this -> import_fields_array [ $r ] = array ( 'p.ref' => " Ref* " , 'p.label' => " Label* " , 'p.description' => " Description " , 'p.note' => " Note " , 'p.price' => " SellingPriceHT " , 'p.price_ttc' => " SellingPriceTTC " , 'p.tva_tx' => 'VAT' , 'p.envente' => " OnSell* " , 'p.fk_product_type' => " Type* " , 'p.finished' => 'Nature' , 'p.duration' => " Duration " , 'p.weight' => " Weight " , 'p.volume' => " Volume " , 'p.datec' => 'DateCreation*' );
2009-11-08 20:28:44 +01:00
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use another picto
2009-10-17 15:12:55 +02:00
$this -> import_regex_array [ $r ] = array ( 'p.ref' => '[^ ]' , 'p.envente' => '^[0|1]' , 'p.fk_product_type' => '^[0|1]' , 'p.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' );
$this -> import_examplevalues_array [ $r ] = array ( 'p.ref' => " PR123456 " , 'p.label' => " My product " , 'p.description' => " This is a description example for record " , 'p.note' => " Some note " , 'p.price' => " 100 " , 'p.price_ttc' => " 110 " , 'p.tva_tx' => '10' , 'p.envente' => " 0 or 1 " , 'p.fk_product_type' => " 0 for product, 1 for service " , 'p.finished' => '' , 'p.duration' => " 1y " , 'p.datec' => '2008-12-31' );
2006-05-11 00:18:51 +02:00
}
2005-05-14 16:22:08 +02:00
2008-10-01 21:10:17 +02:00
/**
2009-04-28 11:41:30 +02:00
* \brief Fonction appelee lors de l ' activation du module . Insere en base les constantes , boites , permissions du module .
* Definit egalement les repertoires de donnees a creer pour ce module .
2008-10-01 21:10:17 +02:00
*/
function init ()
{
// Permissions
$this -> remove ();
2005-05-14 16:22:08 +02:00
2008-10-01 21:10:17 +02:00
$sql = array ();
2003-11-13 16:09:12 +01:00
2008-10-01 21:10:17 +02:00
return $this -> _init ( $sql );
}
2004-11-23 21:04:19 +01:00
2008-10-01 21:10:17 +02:00
/**
2009-04-28 11:41:30 +02:00
* \brief Fonction appelee lors de la desactivation d ' un module .
2008-10-01 21:10:17 +02:00
* Supprime de la base les constantes , boites et permissions du module .
*/
function remove ()
{
$sql = array ();
2003-08-30 14:30:46 +02:00
2008-10-01 21:10:17 +02:00
return $this -> _remove ( $sql );
}
2003-08-11 20:44:32 +02:00
}
?>