PageRenderTime 236ms CodeModel.GetById 131ms app.highlight 11ms RepoModel.GetById 91ms app.codeStats 0ms

/htdocs/core/modules/modProduct.class.php

https://github.com/asterix14/dolibarr
PHP | 187 lines | 97 code | 32 blank | 58 comment | 8 complexity | 29dec99fcd2645c6fadeb971b3c5e8ea MD5 | raw file
  1<?php
  2/* Copyright (C) 2003      Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
  4 * Copyright (C) 2004      Sebastien Di Cintio  <sdicintio@ressource-toi.org>
  5 * Copyright (C) 2004      Benoit Mortier       <benoit.mortier@opensides.be>
  6 * Copyright (C) 2005-2009 Regis Houssin        <regis@dolibarr.fr>
  7 *
  8 * This program is free software; you can redistribute it and/or modify
  9 * it under the terms of the GNU General Public License as published by
 10 * the Free Software Foundation; either version 2 of the License, or
 11 * (at your option) any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 20 */
 21
 22/**
 23 *	\defgroup   produit     Module products
 24 *	\brief      Module pour gerer le suivi de produits predefinis
 25 *	\file       htdocs/core/modules/modProduct.class.php
 26 *	\ingroup    produit
 27 *	\brief      Fichier de description et activation du module Produit
 28 */
 29
 30include_once(DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php");
 31
 32
 33/**
 34 *	\class      modProduct
 35 *	\brief      Classe de description et activation du module Produit
 36 */
 37class modProduct extends DolibarrModules
 38{
 39	/**
 40	 *   Constructor. Define names, constants, directories, boxes, permissions
 41	 *
 42	 *   @param      DoliDB		$DB      Database handler
 43	 */
 44	function modProduct($DB)
 45	{
 46		global $conf;
 47
 48		$this->db = $DB;
 49		$this->numero = 50;
 50
 51		$this->family = "products";
 52		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
 53		$this->name = preg_replace('/^mod/i','',get_class($this));
 54		$this->description = "Gestion des produits";
 55
 56		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
 57		$this->version = 'dolibarr';
 58
 59		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
 60		$this->special = 0;
 61		$this->picto='product';
 62
 63		// Data directories to create when module is enabled
 64		$this->dirs = array("/product/temp");
 65
 66		// Dependencies
 67		$this->depends = array();
 68		$this->requiredby = array("modStock","modBarcode");
 69
 70		// Config pages
 71		$this->config_page_url = array("produit.php@product");
 72		$this->langfiles = array("products","companies","stocks","bills");
 73
 74		// Constants
 75		$this->const = array();
 76		$r=0;
 77
 78		$this->const[$r][0] = "MAIN_SEARCHFORM_PRODUITSERVICE";
 79		$this->const[$r][1] = "yesno";
 80		$this->const[$r][2] = "1";
 81		$this->const[$r][3] = "Show form for quick product search";
 82		$this->const[$r][4] = 0;
 83		$r++;
 84
 85		// Boxes
 86		$this->boxes = array();
 87		$this->boxes[0][1] = "box_produits.php";
 88
 89		// Permissions
 90		$this->rights = array();
 91		$this->rights_class = 'produit';
 92		$r=0;
 93
 94		$this->rights[$r][0] = 31; // id de la permission
 95		$this->rights[$r][1] = 'Lire les produits'; // libelle de la permission
 96		$this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
 97		$this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
 98		$this->rights[$r][4] = 'lire';
 99		$r++;
100
101		$this->rights[$r][0] = 32; // id de la permission
102		$this->rights[$r][1] = 'Creer/modifier les produits'; // libelle de la permission
103		$this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
104		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
105		$this->rights[$r][4] = 'creer';
106		$r++;
107
108		$this->rights[$r][0] = 34; // id de la permission
109		$this->rights[$r][1] = 'Supprimer les produits'; // libelle de la permission
110		$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
111		$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
112		$this->rights[$r][4] = 'supprimer';
113        $r++;
114
115		$this->rights[$r][0] = 38;	// Must be same permission than in service module
116		$this->rights[$r][1] = 'Exporter les produits';
117		$this->rights[$r][2] = 'r';
118		$this->rights[$r][3] = 0;
119		$this->rights[$r][4] = 'export';
120        $r++;
121
122
123		// Exports
124		//--------
125		$r=0;
126
127		$r++;
128		$this->export_code[$r]=$this->rights_class.'_'.$r;
129		$this->export_label[$r]="Products";	// Translation key (used only if key ExportDataset_xxx_z not found)
130		$this->export_permission[$r]=array(array("produit","export"));
131		$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.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification');
132		//if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge ($this->export_fields_array[$r],array('p.stock'=>'Stock','p.pmp'=>'PMPValue'));
133		if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge ($this->export_fields_array[$r],array('p.pmp'=>'PMPValue'));
134		if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge ($this->export_fields_array[$r],array('p.barcode'=>'Barcode'));
135		$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.customcode'=>'product','p.price_base_type'=>"product",'p.price'=>"product",'p.price_ttc'=>"product",'p.tva_tx'=>"product",'p.tosell'=>"product",'p.tobuy'=>"product",'p.datec'=>"product",'p.tms'=>"product");
136		//if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge ($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product'));
137		if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge ($this->export_entities_array[$r],array('p.pmp'=>'product'));
138		if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge ($this->export_entities_array[$r],array('p.barcode'=>'product'));
139
140		$this->export_sql_start[$r]='SELECT DISTINCT ';
141		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'product as p';
142		$this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity = '.$conf->entity;
143
144
145		// Imports
146		//--------
147		$r=0;
148
149		$r++;
150		$this->import_code[$r]=$this->rights_class.'_'.$r;
151		$this->import_label[$r]="Products";	// Translation key
152		$this->import_icon[$r]=$this->picto;
153		$this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product');
154		$this->import_tables_creator_array[$r]=array('p'=>'fk_user_author');	// Fields to store import user id
155		$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.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.duration'=>"Duration",'p.weight'=>"Weight",'p.volume'=>"Volume",'p.datec'=>'DateCreation*');
156		$this->import_entities_array[$r]=array();	// We define here only fields that use another picto
157		$this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]','p.tobuy'=>'^[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]$');
158		$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.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31');
159	}
160
161
162	/**
163	 *   \brief      Fonction appelee lors de l'activation du module. Insere en base les constantes, boites, permissions du module.
164	 *               Definit egalement les repertoires de donnees a creer pour ce module.
165	 */
166	function init()
167	{
168		// Permissions
169		$this->remove();
170
171		$sql = array();
172
173		return $this->_init($sql);
174	}
175
176	/**
177	 *    \brief      Fonction appelee lors de la desactivation d'un module.
178	 *                Supprime de la base les constantes, boites et permissions du module.
179	 */
180	function remove()
181	{
182		$sql = array();
183
184		return $this->_remove($sql);
185	}
186}
187?>