2004-10-20 00:24:10 +02:00
< ? php
2005-04-12 22:01:42 +02:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2014-05-25 17:14:33 +02:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-04-12 22:01:42 +02:00
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2003-11-17 17:35:49 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-11-17 17:35:49 +01:00
* ( 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-17 17:35:49 +01:00
*/
2005-04-12 22:01:42 +02:00
/**
2009-07-30 00:52:08 +02:00
* \defgroup service Module services
2009-06-08 20:14:37 +02:00
* \brief Module pour gerer le suivi de services predefinis
2011-10-24 14:11:49 +02:00
* \file htdocs / core / modules / modService . class . php
2009-06-08 20:14:37 +02:00
* \ingroup service
* \brief Fichier de description et activation du module Service
2008-10-01 21:10:17 +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-17 17:35:49 +01:00
2012-03-30 00:54:41 +02:00
/**
2015-09-07 15:55:26 +02:00
* Class to describe and enable module Service
2008-10-01 21:10:17 +02:00
*/
2003-11-17 17:35:49 +01:00
class modService 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
{
2018-08-10 15:39:49 +02:00
global $conf , $mysoc ;
2009-06-08 20:44:53 +02:00
2012-01-04 21:23:50 +01:00
$this -> db = $db ;
$this -> numero = 53 ;
2008-10-01 21:10:17 +02:00
$this -> family = " products " ;
2015-11-17 00:58:12 +01:00
$this -> module_position = 30 ;
2008-10-01 21:10:17 +02:00
// 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 ));
2017-05-04 20:16:55 +02:00
$this -> description = " Service management " ;
2008-10-01 21:10:17 +02:00
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 -> picto = 'service' ;
2009-05-04 13:40:00 +02:00
2009-04-28 15:04:35 +02:00
// Data directories to create when module is enabled
2014-10-03 02:00:50 +02:00
$this -> dirs = array ( " /product/temp " );
2008-10-01 21:10:17 +02:00
2009-05-04 13:40:00 +02:00
// Dependancies
2009-06-08 20:14:37 +02:00
$this -> depends = array ();
2014-07-19 22:05:35 +02:00
$this -> requiredby = array ();
2008-10-01 21:10:17 +02:00
2009-06-08 20:44:53 +02:00
// Config pages
2012-03-03 16:33:38 +01:00
$this -> config_page_url = array ( " product.php@product " );
2009-06-08 20:44:53 +02:00
$this -> langfiles = array ( " products " , " companies " , " bills " );
2009-05-04 13:40:00 +02:00
// Constants
2008-10-01 21:10:17 +02:00
$this -> const = array ();
2009-05-04 13:40:00 +02:00
// Boxes
2013-10-26 16:18:28 +02:00
$this -> boxes = array (
0 => array ( 'file' => 'box_services_contracts.php' , 'enabledbydefaulton' => 'Home' ),
1 => array ( 'file' => 'box_graph_product_distribution.php' , 'enabledbydefaulton' => 'Home' )
);
2008-10-01 21:10:17 +02:00
// Permissions
$this -> rights = array ();
$this -> rights_class = 'service' ;
2009-06-08 20:14:37 +02:00
$r = 0 ;
$this -> rights [ $r ][ 0 ] = 531 ; // id de la permission
2018-05-01 11:09:03 +02:00
$this -> rights [ $r ][ 1 ] = 'Read services' ; // libelle de la permission
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ; // type de la permission (deprecie a ce jour)
2016-06-04 12:16:30 +02:00
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par defaut
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 4 ] = 'lire' ;
2010-08-17 10:18:46 +02:00
$r ++ ;
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 0 ] = 532 ; // id de la permission
2018-05-01 11:09:03 +02:00
$this -> rights [ $r ][ 1 ] = 'Create/modify services' ; // libelle de la permission
2009-06-08 20:14:37 +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
$this -> rights [ $r ][ 4 ] = 'creer' ;
2010-08-17 10:18:46 +02:00
$r ++ ;
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 0 ] = 534 ; // id de la permission
2018-05-01 11:09:03 +02:00
$this -> rights [ $r ][ 1 ] = 'Delete les services' ; // libelle de la permission
2009-06-08 20:14:37 +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
$this -> rights [ $r ][ 4 ] = 'supprimer' ;
2010-08-17 10:18:46 +02:00
$r ++ ;
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 0 ] = 538 ; // Must be same permission than in product module
2018-05-01 11:09:03 +02:00
$this -> rights [ $r ][ 1 ] = 'Export services' ;
2009-06-08 20:14:37 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'export' ;
2010-08-17 10:18:46 +02:00
$r ++ ;
2009-06-08 20:44:53 +02:00
2014-02-18 20:49:22 +01:00
/* We can ' t enable this here because it must be enabled in both product and service module and this create duplicate insert
$r = 0 ;
2016-02-16 12:46:39 +01:00
$this -> menu [ $r ] = array ( 'fk_menu' => 'fk_mainmenu=home,fk_leftmenu=admintools' , // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
2014-02-18 20:49:22 +01:00
'type' => 'left' , // This is a Left menu entry
'titre' => 'ProductVatMassChange' ,
2016-02-16 12:46:39 +01:00
'url' => '/product/admin/product_tools.php?mainmenu=home&leftmenu=admintools' ,
2014-02-19 02:27:13 +01:00
'langs' => 'products' , // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
2014-02-18 20:49:22 +01:00
'position' => 300 ,
2018-06-19 13:17:46 +02:00
'enabled' => '$conf->product->enabled && preg_match(\'/^(admintools|all)/\',$leftmenu)' , // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
2014-02-18 20:49:22 +01:00
'perms' => '1' , // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target' => '' ,
'user' => 0 ); // 0=Menu for internal users, 1=external users, 2=both
$r ++ ;
*/
2016-09-30 13:02:13 +02:00
// Menus
//-------
$this -> menu = 1 ; // This module add menu entries. They are coded into menu manager.
2017-11-06 12:59:58 +01:00
2016-09-30 13:02:13 +02:00
// Exports
2009-06-08 20:44:53 +02:00
//--------
$r = 0 ;
$r ++ ;
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> export_label [ $r ] = " Services " ; // Translation key (used only if key ExportDataset_xxx_z not found)
$this -> export_permission [ $r ] = array ( array ( " service " , " export " ));
2014-08-29 20:25:54 +02: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.price_base_type' => " PriceBase " , 'p.price' => " UnitPriceHT " , 'p.price_ttc' => " UnitPriceTTC " , 'p.tva_tx' => 'VATRate' , 'p.tosell' => " OnSell " , 'p.tobuy' => " OnBuy " , 'p.duration' => " Duration " , 'p.datec' => 'DateCreation' , 'p.tms' => 'DateModification' );
2012-03-13 09:38:00 +01:00
if ( ! empty ( $conf -> stock -> enabled )) $this -> export_fields_array [ $r ] = array_merge ( $this -> export_fields_array [ $r ], array ( 'p.stock' => 'Stock' ));
2017-07-18 10:20:16 +02:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) $this -> export_fields_array [ $r ][ 'p.fk_unit' ] = 'Unit' ;
2015-09-12 15:19:19 +02:00
//$this->export_TypeFields_array[$r]=array('p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",'p.note'=>"Text",'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.duration'=>"Duree",'p.datec'=>'Date','p.tms'=>'Date');
$this -> export_TypeFields_array [ $r ] = array ( 'p.ref' => " Text " , 'p.label' => " Text " , 'p.description' => " Text " , 'p.accountancy_code_sell' => " Text " , 'p.accountancy_code_buy' => " Text " , 'p.note' => " Text " , 'p.price_base_type' => " Text " , 'p.price' => " Numeric " , 'p.price_ttc' => " Numeric " , 'p.tva_tx' => 'Numeric' , 'p.tosell' => " Boolean " , 'p.tobuy' => " Boolean " , 'p.duration' => " Duree " , 'p.datec' => 'Date' , 'p.tms' => 'Date' );
if ( ! empty ( $conf -> stock -> enabled )) $this -> export_TypeFields_array [ $r ] = array_merge ( $this -> export_TypeFields_array [ $r ], array ( 'p.stock' => 'Numeric' ));
2012-11-14 00:27:25 +01:00
if ( ! empty ( $conf -> barcode -> enabled )) $this -> export_TypeFields_array [ $r ] = array_merge ( $this -> export_TypeFields_array [ $r ], array ( 'p.barcode' => 'Text' ));
2014-08-29 20:25:54 +02:00
$this -> export_entities_array [ $r ] = array ( 'p.rowid' => " service " , 'p.ref' => " service " , 'p.label' => " service " , 'p.description' => " service " , 'p.accountancy_code_sell' => 'service' , 'p.note' => " service " , 'p.price_base_type' => " service " , 'p.price' => " service " , 'p.price_ttc' => " service " , 'p.tva_tx' => " service " , 'p.tosell' => " service " , 'p.tobuy' => " service " , 'p.duration' => " service " , 'p.datec' => " service " , 'p.tms' => " service " );
2012-11-14 00:27:25 +01:00
if ( ! empty ( $conf -> stock -> enabled )) $this -> export_entities_array [ $r ] = array_merge ( $this -> export_entities_array [ $r ], array ( 'p.stock' => 'service' ));
if ( ! empty ( $conf -> barcode -> enabled )) $this -> export_entities_array [ $r ] = array_merge ( $this -> export_entities_array [ $r ], array ( 'p.barcode' => 'service' ));
2012-03-03 16:33:38 +01:00
// Add extra fields
2014-10-03 02:00:50 +02:00
$sql = " SELECT name, label, type FROM " . MAIN_DB_PREFIX . " extrafields WHERE elementtype = 'product' " ;
2012-03-03 16:33:38 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) // This can fail when class is used on old database (during migration for example)
{
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
$fieldname = 'extra.' . $obj -> name ;
$fieldlabel = ucfirst ( $obj -> label );
2014-10-03 02:00:50 +02:00
$typeFilter = " Text " ;
switch ( $obj -> type )
{
case 'int' :
case 'double' :
case 'price' :
$typeFilter = " Numeric " ;
break ;
case 'date' :
case 'datetime' :
$typeFilter = " Date " ;
break ;
case 'boolean' :
$typeFilter = " Boolean " ;
break ;
case 'sellist' :
2015-04-02 16:58:36 +02:00
$tmp = '' ;
$tmpparam = unserialize ( $obj -> param ); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
if ( $tmpparam [ 'options' ] && is_array ( $tmpparam [ 'options' ])) $tmp = array_shift ( array_keys ( $tmpparam [ 'options' ]));
if ( preg_match ( '/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/' , $tmp )) $typeFilter = " List: " . $tmp ;
2014-10-03 02:00:50 +02:00
break ;
}
$this -> export_fields_array [ $r ][ $fieldname ] = $fieldlabel ;
$this -> export_TypeFields_array [ $r ][ $fieldname ] = $typeFilter ;
$this -> export_entities_array [ $r ][ $fieldname ] = 'product' ;
2012-03-03 16:33:38 +01:00
}
}
2012-10-25 22:30:17 +02:00
// End add extra fields
2009-06-08 20:44:53 +02:00
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'product as p' ;
2012-03-03 16:33:38 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_extrafields as extra ON p.rowid = extra.fk_object' ;
2014-10-03 02:00:50 +02:00
if ( ! empty ( $conf -> fournisseur -> enabled )) $this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN ' . MAIN_DB_PREFIX . 'societe s ON s.rowid = pf.fk_soc' ;
2017-05-30 18:50:54 +02:00
$this -> export_sql_end [ $r ] .= ' WHERE p.fk_product_type = 1 AND p.entity IN (' . getEntity ( 'product' ) . ')' ;
2009-06-08 20:44:53 +02:00
2012-03-03 16:33:38 +01:00
2014-05-11 17:52:16 +02:00
if ( empty ( $conf -> product -> enabled )) // We enable next import templates only if module product not already enabled (to avoid duplicate entries)
{
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ))
{
// Exports product multiprice
$r ++ ;
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> export_label [ $r ] = " ProductsMultiPrice " ; // Translation key (used only if key ExportDataset_xxx_z not found)
$this -> export_permission [ $r ] = array ( array ( " produit " , " export " ));
$this -> export_fields_array [ $r ] = array ( 'p.rowid' => " Id " , 'p.ref' => " Ref " ,
'pr.price_base_type' => " PriceLevelPriceBase " , 'pr.price_level' => " PriceLevel " ,
'pr.price' => " PriceLevelUnitPriceHT " , 'pr.price_ttc' => " PriceLevelUnitPriceTTC " ,
'pr.price_min' => " MinPriceLevelUnitPriceHT " , 'pr.price_min_ttc' => " MinPriceLevelUnitPriceTTC " ,
'pr.tva_tx' => 'PriceLevelVATRate' ,
'pr.date_price' => 'DateCreation' );
2018-05-27 15:04:12 +02:00
//$this->export_TypeFields_array[$r]=array(
// 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
// 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
// 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
// 'p.datec'=>'Date','p.tms'=>'Date'
//);
2014-05-11 17:52:16 +02:00
$this -> export_entities_array [ $r ] = array ( 'p.rowid' => " product " , 'p.ref' => " product " ,
'pr.price_base_type' => " product " , 'pr.price_level' => " product " , 'pr.price' => " product " ,
'pr.price_ttc' => " product " ,
2014-10-03 02:00:50 +02:00
'pr.price_min' => " product " , 'pr.price_min_ttc' => " product " ,
2014-05-11 17:52:16 +02:00
'pr.tva_tx' => 'product' ,
'pr.date_price' => " product " );
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'product as p' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_price as pr ON p.rowid = pr.fk_product' ;
2017-05-30 18:50:54 +02:00
$this -> export_sql_end [ $r ] .= ' WHERE p.fk_product_type = 0 AND p.entity IN (' . getEntity ( 'product' ) . ')' ;
2014-05-11 17:52:16 +02:00
}
}
2012-03-03 16:33:38 +01:00
// Imports
//--------
$r = 0 ;
$r ++ ;
$this -> import_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> import_label [ $r ] = " Products " ; // Translation key
$this -> import_icon [ $r ] = $this -> picto ;
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use another icon that the one defined into import_icon
$this -> import_tables_array [ $r ] = array ( 'p' => MAIN_DB_PREFIX . 'product' , 'extra' => MAIN_DB_PREFIX . 'product_extrafields' );
$this -> import_tables_creator_array [ $r ] = array ( 'p' => 'fk_user_author' ); // Fields to store import user id
2018-05-27 15:04:12 +02:00
$this -> import_fields_array [ $r ] = array (
'p.ref' => " Ref* " , 'p.label' => " Label* " , 'p.description' => " Description " , 'p.url' => " PublicUrl " , '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.duration' => " Duration " , 'p.customcode' => 'CustomCode' , '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.datec' => 'DateCreation'
);
2014-05-25 17:14:33 +02:00
if ( ! empty ( $conf -> barcode -> enabled )) $this -> import_fields_array [ $r ] = array_merge ( $this -> import_fields_array [ $r ], array ( 'p.barcode' => 'BarCode' ));
2017-07-18 10:20:16 +02:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) $this -> import_fields_array [ $r ][ 'p.fk_unit' ] = 'Unit' ;
2014-05-25 17:14:33 +02:00
// Add extra fields
2018-11-30 19:23:05 +01:00
$sql = " SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . " extrafields WHERE elementtype = 'product' AND entity IN (0, " . $conf -> entity . " ) " ;
2012-03-03 16:33:38 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) // This can fail when class is used on old database (during migration for example)
{
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
$fieldname = 'extra.' . $obj -> name ;
$fieldlabel = ucfirst ( $obj -> label );
2012-10-25 13:11:55 +02:00
$this -> import_fields_array [ $r ][ $fieldname ] = $fieldlabel . ( $obj -> fieldrequired ? '*' : '' );
2012-03-03 16:33:38 +01:00
}
}
// End add extra fields
$this -> import_fieldshidden_array [ $r ] = array ( 'extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'product' ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
$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]$' );
2014-10-03 02:00:50 +02:00
$this -> import_examplevalues_array [ $r ] = array ( 'p.ref' => " PREF123456 " , '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' );
2014-05-11 17:52:16 +02:00
if ( empty ( $conf -> product -> enabled )) // We enable next import templates only if module product not already enabled (to avoid duplicate entries)
{
if ( ! empty ( $conf -> fournisseur -> enabled ))
{
// Import suppliers prices (note: this code is duplicated into module product)
$r ++ ;
$this -> import_code [ $r ] = $this -> rights_class . '_supplierprices' ;
$this -> import_label [ $r ] = " SuppliersPricesOfProductsOrServices " ; // Translation key
$this -> import_icon [ $r ] = $this -> picto ;
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use another icon that the one defined into import_icon
$this -> import_tables_array [ $r ] = array ( 'sp' => MAIN_DB_PREFIX . 'product_fournisseur_price' );
$this -> import_tables_creator_array [ $r ] = array ( 'sp' => 'fk_user' );
2018-02-06 10:03:06 +01:00
$this -> import_fields_array [ $r ] = array (
'sp.fk_product' => " ProductOrService* " ,
'sp.fk_soc' => " Supplier* " , 'sp.ref_fourn' => 'SupplierRef' , 'sp.quantity' => " QtyMin* " , 'sp.tva_tx' => 'VATRate' , 'sp.default_vat_code' => 'VATCode'
2014-05-11 17:52:16 +02:00
);
2018-02-06 10:03:06 +01:00
if ( is_object ( $mysoc ) && $mysoc -> useNPR ()) $this -> import_fields_array [ $r ] = array_merge ( $this -> import_fields_array [ $r ], array ( 'sp.recuperableonly' => 'VATNPR' ));
if ( is_object ( $mysoc ) && $mysoc -> useLocalTax ( 1 )) $this -> import_fields_array [ $r ] = array_merge ( $this -> import_fields_array [ $r ], array ( 'sp.localtax1_tx' => 'LT1' , 'sp.localtax1_type' => 'LT1Type' ));
if ( is_object ( $mysoc ) && $mysoc -> useLocalTax ( 2 )) $this -> import_fields_array [ $r ] = array_merge ( $this -> import_fields_array [ $r ], array ( 'sp.localtax2_tx' => 'LT2' , 'sp.localtax2_type' => 'LT2Type' ));
$this -> import_fields_array [ $r ] = array_merge ( $this -> import_fields_array [ $r ], array (
'sp.price' => " PriceQtyMinHT* " ,
'sp.unitprice' => 'UnitPriceHT*' , // TODO Make this field not required and calculate it from price and qty
'sp.remise_percent' => 'DiscountQtyMin'
));
2014-05-11 17:52:16 +02:00
$this -> import_convertvalue_array [ $r ] = array (
'sp.fk_soc' => array ( 'rule' => 'fetchidfromref' , 'classfile' => '/societe/class/societe.class.php' , 'class' => 'Societe' , 'method' => 'fetch' , 'element' => 'ThirdParty' ),
'sp.fk_product' => array ( 'rule' => 'fetchidfromref' , 'classfile' => '/product/class/product.class.php' , 'class' => 'Product' , 'method' => 'fetch' , 'element' => 'Product' )
);
$this -> import_examplevalues_array [ $r ] = array ( 'sp.fk_product' => " PREF123456 " ,
'sp.fk_soc' => " My Supplier " , 'sp.ref_fourn' => " SupplierRef " , 'sp.quantity' => " 1 " , 'sp.tva_tx' => '21' ,
'sp.price' => " 50 " ,
'sp.unitprice' => '50' ,
'sp.remise_percent' => '0'
);
}
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES ))
{
// Import product multiprice
$r ++ ;
$this -> import_code [ $r ] = $this -> rights_class . '_multiprice' ;
$this -> import_label [ $r ] = " ProductsOrServiceMultiPrice " ; // Translation key
$this -> import_icon [ $r ] = $this -> picto ;
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use another icon that the one defined into import_icon
$this -> import_tables_array [ $r ] = array ( 'pr' => MAIN_DB_PREFIX . 'product_price' );
$this -> import_tables_creator_array [ $r ] = array ( 'pr' => 'fk_user_author' ); // Fields to store import user id
$this -> import_fields_array [ $r ] = array ( 'pr.fk_product' => " ProductRowid* " ,
'pr.price_base_type' => " PriceLevelPriceBase " , 'pr.price_level' => " PriceLevel " ,
'pr.price' => " PriceLevelUnitPriceHT " , 'pr.price_ttc' => " PriceLevelUnitPriceTTC " ,
'pr.price_min' => " MinPriceLevelUnitPriceHT " , 'pr.price_min_ttc' => " MinPriceLevelUnitPriceTTC " ,
'pr.tva_tx' => 'PriceLevelVATRate' ,
'pr.date_price' => 'DateCreation*' );
$this -> import_regex_array [ $r ] = array ( 'pr.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' );
$this -> import_examplevalues_array [ $r ] = array ( 'pr.fk_product' => " 1 " ,
'pr.price_base_type' => " HT " , 'pr.price_level' => " 1 " ,
'pr.price' => " 100 " , 'pr.price_ttc' => " 110 " ,
'pr.price_min' => " 100 " , 'pr.price_min_ttc' => " 110 " ,
'pr.tva_tx' => '19.6' ,
'pr.date_price' => '2013-04-10' );
}
2017-11-06 12:59:58 +01:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ))
{
$r ++ ;
$this -> import_code [ $r ] = $this -> rights_class . '_languages' ;
$this -> import_label [ $r ] = " ProductsOrServicesTranslations " ;
$this -> import_icon [ $r ] = $this -> picto ;
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use another icon that the one defined into import_icon
$this -> import_tables_array [ $r ] = array ( 'l' => MAIN_DB_PREFIX . 'product_lang' );
// multiline translation, one line per translation
$this -> import_fields_array [ $r ] = array ( 'l.fk_product' => 'Ref' , 'l.lang' => 'Language' , 'l.label' => 'TranslatedLabel' , 'l.description' => 'TranslatedDescription' );
//$this->import_fields_array[$r]['l.note']='TranslatedNote';
$this -> import_convertvalue_array [ $r ] = array (
'l.fk_product' => array ( 'rule' => 'fetchidfromref' , 'classfile' => '/product/class/product.class.php' , 'class' => 'Product' , 'method' => 'fetch' , 'element' => 'Product' )
);
$this -> import_examplevalues_array [ $r ] = array ( 'l.fk_product' => 'MyProductRef' , 'l.lang' => 'en_US' , 'l.label' => 'Label in en_US' , 'l.description' => 'Desc in en_US' );
$this -> import_updatekeys_array [ $r ] = array ( 'l.fk_product' => 'Ref' , 'l.lang' => 'Language' );
}
2014-05-11 17:52:16 +02:00
}
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
*
2013-10-26 16:18:28 +02:00
* @ param string $options Options when enabling module ( '' , 'newboxdefonly' , 'noboxes' )
2012-01-04 21:23:50 +01:00
* @ 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
{
2012-03-03 17:37:45 +01:00
$this -> remove ( $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
}
2003-11-17 17:35:49 +01:00
}