2004-10-20 00:24:10 +02:00
< ? php
2005-07-21 15:15:16 +02:00
/* Copyright ( C ) 2003 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2013-03-09 16:58:55 +01:00
* Copyright ( C ) 2004 - 2013 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 >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2013 Regis Houssin < regis . houssin @ inodbox . com >
2014-07-14 19:38:00 +02:00
* Copyright ( C ) 2012 - 2014 Juanjo Menent < jmenent @ 2 byte . es >
2022-03-04 10:06:24 +01:00
* Copyright ( C ) 2022 Ferran Marcet < fmarcet @ 2 byte . es >
2003-09-12 23:32:56 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-09-12 23:32:56 +02: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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2003-09-12 23:32:56 +02:00
*/
2008-10-01 21:10:17 +02:00
/**
2009-05-19 02:14:27 +02:00
* \defgroup societe Module societe
* \brief Module to manage third parties ( customers , prospects )
2011-10-24 14:11:49 +02:00
* \file htdocs / core / modules / modSociete . class . php
2009-04-10 02:29:23 +02:00
* \ingroup societe
2021-03-20 13:55:43 +01:00
* \brief Description and activation file for the module societe ( thirdparty )
2008-10-01 21:10:17 +02:00
*/
2019-11-13 19:37:08 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2007-10-10 01:15:25 +02:00
2003-09-12 23:32:56 +02:00
2008-10-01 21:10:17 +02:00
/**
2015-09-07 15:55:26 +02:00
* Class to describe and enable module Societe
2008-10-01 21:10:17 +02:00
*/
2003-11-13 16:09:12 +01:00
class modSociete extends DolibarrModules
2003-09-12 23:32:56 +02:00
{
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
*/
2019-02-25 20:35:59 +01:00
public function __construct ( $db )
2008-10-01 21:10:17 +02:00
{
2016-06-06 16:21:05 +02:00
global $conf , $user ;
2009-05-04 13:40:00 +02:00
2012-01-04 21:23:50 +01:00
$this -> db = $db ;
$this -> numero = 1 ;
2008-10-01 21:10:17 +02:00
$this -> family = " crm " ;
2019-06-21 13:25:40 +02:00
$this -> module_position = '09' ;
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)
2019-01-27 11:55:16 +01:00
$this -> name = preg_replace ( '/^mod/i' , '' , get_class ( $this ));
2017-11-21 15:17:02 +01:00
$this -> description = " Gestion des sociétés et contacts " ;
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-04-10 02:29:23 +02:00
2008-10-06 09:39:52 +02:00
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
2011-09-28 14:13:48 +02:00
$this -> config_page_url = array ( " societe.php@societe " );
2009-05-08 14:08:54 +02:00
// Name of image file used for this module.
2019-11-13 19:37:08 +01:00
$this -> picto = 'company' ;
2008-10-01 21:10:17 +02:00
2009-04-28 16:28:58 +02:00
// Data directories to create when module is enabled
2009-07-02 02:16:50 +02:00
$this -> dirs = array ( " /societe/temp " );
2009-05-19 02:14:27 +02:00
2015-09-07 15:29:51 +02:00
// Dependencies
2019-11-13 19:37:08 +01:00
$this -> hidden = false ; // A condition to hide module
$this -> depends = array (); // List of module class names as string that must be enabled if this module is enabled
$this -> requiredby = array ( " modExpedition " , " modFacture " , " modFournisseur " , " modFicheinter " , " modPropale " , " modContrat " , " modCommande " ); // List of module ids to disable if this one is disabled
$this -> conflictwith = array (); // List of module class names as string this module is in conflict with
2021-02-06 13:48:31 +01:00
$this -> phpmin = array ( 5 , 6 ); // Minimum version of PHP required by module
2019-12-23 14:13:26 +01:00
$this -> langfiles = array ( " companies " , 'bills' , " compta " , " admin " , " banks " );
2008-10-01 21:10:17 +02:00
2015-09-07 15:40:55 +02:00
// Constants
2008-10-01 21:10:17 +02:00
$this -> const = array ();
2019-11-13 19:37:08 +01:00
$r = 0 ;
2012-08-15 18:55:32 +02:00
$this -> const [ $r ][ 0 ] = " SOCIETE_CODECLIENT_ADDON " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
2016-07-30 12:31:32 +02:00
$this -> const [ $r ][ 2 ] = " mod_codeclient_monkey " ;
2012-08-15 18:55:32 +02:00
$this -> const [ $r ][ 3 ] = 'Module to control third parties codes' ;
2012-08-15 09:06:36 +02:00
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2012-08-15 18:55:32 +02:00
$this -> const [ $r ][ 0 ] = " SOCIETE_CODECOMPTA_ADDON " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " mod_codecompta_panicum " ;
$this -> const [ $r ][ 3 ] = 'Module to control third parties codes' ;
$this -> const [ $r ][ 4 ] = 0 ;
2012-08-15 09:06:36 +02:00
$r ++ ;
2008-10-01 21:10:17 +02:00
$this -> const [ $r ][ 0 ] = " SOCIETE_FISCAL_MONTH_START " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " 0 " ;
2017-11-22 23:11:36 +01:00
$this -> const [ $r ][ 3 ] = " Enter the month number of the first month of the fiscal year, e. g. 9 for September " ;
2011-01-16 02:41:44 +01:00
$this -> const [ $r ][ 4 ] = 0 ;
2008-10-01 21:10:17 +02:00
$r ++ ;
2010-04-02 10:22:42 +02:00
$this -> const [ $r ][ 0 ] = " COMPANY_ADDON_PDF_ODT_PATH " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
2010-05-09 15:45:27 +02:00
$this -> const [ $r ][ 2 ] = " DOL_DATA_ROOT/doctemplates/thirdparties " ;
2010-04-02 10:22:42 +02:00
$this -> const [ $r ][ 3 ] = " " ;
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2011-07-02 01:07:26 +02:00
2013-05-14 09:24:05 +02:00
/*
2013-05-11 17:10:11 +02:00
$this -> const [ $r ][ 0 ] = " COMPANY_HIDE_INACTIVE_IN_COMBOBOX " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " 0 " ;
$this -> const [ $r ][ 3 ] = " hide thirdparty customer inative in combobox " ;
2013-05-14 09:24:05 +02:00
$this -> const [ $r ][ 4 ] = 1 ;
2013-05-11 17:10:11 +02:00
$r ++ ;
2013-05-14 09:24:05 +02:00
*/
2014-08-28 16:59:10 +02:00
2013-08-30 18:18:58 +02:00
$this -> const [ $r ][ 0 ] = " SOCIETE_ADD_REF_IN_LIST " ;
$this -> const [ $r ][ 1 ] = " yesno " ;
$this -> const [ $r ][ 2 ] = " 0 " ;
$this -> const [ $r ][ 3 ] = " Display customer ref into select list " ;
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2013-05-11 17:10:11 +02:00
2008-10-01 21:10:17 +02:00
// Boxes
2020-12-07 11:42:35 +01:00
$this -> boxes = array (
0 => array ( 'file' => 'box_clients.php' , 'enabledbydefaulton' => 'Home' ),
1 => array ( 'file' => 'box_prospect.php' , 'enabledbydefaulton' => 'Home' ),
2 => array ( 'file' => 'box_contacts.php' , 'enabledbydefaulton' => 'Home' ),
3 => array ( 'file' => 'box_activity.php' , 'enabledbydefaulton' => 'Home' , 'note' => '(WarningUsingThisBoxSlowDown)' ),
4 => array ( 'file' => 'box_goodcustomers.php' , 'enabledbydefaulton' => 'Home' , 'note' => '(WarningUsingThisBoxSlowDown)' ),
);
2008-10-01 21:10:17 +02:00
// Permissions
$this -> rights = array ();
$this -> rights_class = 'societe' ;
2019-11-13 19:37:08 +01:00
$r = 0 ;
2008-10-01 21:10:17 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 121 ; // id de la permission
2017-11-22 23:11:36 +01:00
$this -> rights [ $r ][ 1 ] = 'Read third parties' ; // libelle de la permission
2008-10-01 21:10:17 +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
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 4 ] = 'lire' ;
2020-04-16 00:42:57 +02:00
/* $r ++ ;
2012-07-28 11:28:37 +02:00
$this -> rights [ $r ][ 0 ] = 241 ;
$this -> rights [ $r ][ 1 ] = 'Read thirdparties customers' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'thirparty_customer_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2012-07-27 19:26:54 +02:00
$this -> rights [ $r ][ 5 ] = 'read' ;
2012-07-28 11:28:37 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 242 ;
$this -> rights [ $r ][ 1 ] = 'Read thirdparties suppliers' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'thirdparty_supplier_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2012-07-27 19:26:54 +02:00
$this -> rights [ $r ][ 5 ] = 'read' ;
2021-02-23 22:03:23 +01:00
*/
2012-07-27 19:26:54 +02:00
2008-10-01 21:10:17 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 122 ; // id de la permission
2017-11-22 23:11:36 +01:00
$this -> rights [ $r ][ 1 ] = 'Create and update third parties' ; // libelle de la permission
2008-10-01 21:10:17 +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' ;
2020-04-16 00:42:57 +02:00
/* $r ++ ;
2019-10-27 17:01:23 +01:00
$this -> rights [ $r ][ 0 ] = 251 ;
2012-07-28 11:28:37 +02:00
$this -> rights [ $r ][ 1 ] = 'Create thirdparties customers' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'thirparty_customer_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
$this -> rights [ $r ][ 5 ] = 'read' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 252 ;
$this -> rights [ $r ][ 1 ] = 'Create thirdparties suppliers' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'thirdparty_supplier_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
$this -> rights [ $r ][ 5 ] = 'read' ;
2021-02-23 22:03:23 +01:00
*/
2012-07-27 19:26:54 +02:00
2008-10-01 21:10:17 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 125 ; // id de la permission
2017-11-22 23:11:36 +01:00
$this -> rights [ $r ][ 1 ] = 'Delete third parties' ; // libelle de la permission
2008-10-01 21:10:17 +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' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 126 ; // id de la permission
2017-11-22 23:11:36 +01:00
$this -> rights [ $r ][ 1 ] = 'Export third parties' ; // libelle de la permission
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ; // 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 ] = 'export' ;
2021-11-02 04:52:16 +01:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 130 ;
$this -> rights [ $r ][ 1 ] = 'Modify thirdparty information payment' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2021-11-16 04:32:09 +01:00
$this -> rights [ $r ][ 4 ] = 'thirdparty_paymentinformation_advance' ; // Visible if option MAIN_USE_ADVANCED_PERMS is on
2021-11-02 04:52:16 +01:00
$this -> rights [ $r ][ 5 ] = 'write' ;
2021-01-25 18:59:04 +01:00
// 262 : Restrict access to sales representative
2008-10-01 21:10:17 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 262 ;
2021-01-25 18:59:04 +01:00
$this -> rights [ $r ][ 1 ] = 'Read all third parties (and their objects) by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).' ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ;
2016-06-04 12:16:30 +02:00
$this -> rights [ $r ][ 3 ] = 0 ;
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 4 ] = 'client' ;
$this -> rights [ $r ][ 5 ] = 'voir' ;
2021-01-25 18:59:04 +01:00
/*
$r ++ ;
$this -> rights [ $r ][ 0 ] = 263 ;
$this -> rights [ $r ][ 1 ] = 'Read all third parties (without their objects) by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'client' ;
$this -> rights [ $r ][ 5 ] = 'readallthirdparties_advance' ;
*/
2008-10-01 21:10:17 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 281 ; // id de la permission
2017-11-22 23:11:36 +01:00
$this -> rights [ $r ][ 1 ] = 'Read contacts' ; // libelle de la permission
2008-10-01 21:10:17 +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
2008-10-01 21:10:17 +02:00
$this -> rights [ $r ][ 4 ] = 'contact' ;
$this -> rights [ $r ][ 5 ] = 'lire' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 282 ; // id de la permission
2017-11-22 23:11:36 +01:00
$this -> rights [ $r ][ 1 ] = 'Create and update contact' ; // libelle de la permission
2008-10-01 21:10:17 +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 ] = 'contact' ;
$this -> rights [ $r ][ 5 ] = 'creer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 283 ; // id de la permission
2017-11-22 23:11:36 +01:00
$this -> rights [ $r ][ 1 ] = 'Delete contacts' ; // libelle de la permission
2008-10-01 21:10:17 +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 ] = 'contact' ;
$this -> rights [ $r ][ 5 ] = 'supprimer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 286 ; // id de la permission
2017-11-22 23:11:36 +01:00
$this -> rights [ $r ][ 1 ] = 'Export contacts' ; // libelle de la permission
2008-10-01 21:10:17 +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 ] = 'contact' ;
$this -> rights [ $r ][ 5 ] = 'export' ;
2016-11-25 10:55:09 +01:00
2016-09-30 13:02:13 +02:00
// Menus
//-------
2020-02-13 12:36:05 +01:00
$this -> menu = 1 ; // This module add menu entries. They are coded into menu manager.
2016-11-25 10:55:09 +01:00
2008-10-01 21:10:17 +02:00
// Exports
//--------
2020-02-13 12:36:05 +01:00
$r = 0 ;
2008-10-01 21:10:17 +02:00
2009-05-19 02:14:27 +02:00
// Export list of third parties and attributes
2008-10-01 21:10:17 +02:00
$r ++ ;
2020-02-13 12:36:05 +01:00
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> export_label [ $r ] = 'ExportDataset_company_1' ;
$this -> export_icon [ $r ] = 'company' ;
$this -> export_permission [ $r ] = array ( array ( " societe " , " export " ));
$this -> export_fields_array [ $r ] = array (
2020-08-24 01:20:07 +02:00
's.rowid' => " Id " , 's.nom' => " Name " , 's.name_alias' => " AliasNameShort " , 'ps.nom' => " ParentCompany " ,
2020-08-24 01:01:35 +02:00
's.status' => " Status " , 's.client' => " Customer " , 's.fournisseur' => " Supplier " , 's.datec' => " DateCreation " , 's.tms' => " DateLastModification " ,
2020-02-13 12:36:05 +01:00
's.code_client' => " CustomerCode " , 's.code_fournisseur' => " SupplierCode " , 's.code_compta' => " AccountancyCode " , 's.code_compta_fournisseur' => " SupplierAccountancyCode " ,
2020-08-24 01:01:35 +02:00
's.address' => " Address " , 's.zip' => " Zip " , 's.town' => " Town " , 'd.nom' => 'State' , 'r.nom' => 'Region' , 'c.label' => " Country " , 'c.code' => " CountryCode " , 's.phone' => " Phone " , 's.fax' => " Fax " ,
2020-09-16 12:17:33 +02:00
's.url' => " Url " , 's.email' => " Email " , 's.default_lang' => " DefaultLang " , 's.canvas' => " Canvas " , 's.siren' => " ProfId1 " , 's.siret' => " ProfId2 " , 's.ape' => " ProfId3 " , 's.idprof4' => " ProfId4 " ,
2020-02-13 12:36:05 +01:00
's.idprof5' => " ProfId5 " , 's.idprof6' => " ProfId6 " , 's.tva_intra' => " VATIntraShort " , 's.capital' => " Capital " , 's.note_private' => " NotePrivate " , 's.note_public' => " NotePublic " ,
't.libelle' => " ThirdPartyType " , 'ce.code' => " Staff " , " cfj.libelle " => " JuridicalStatus " , 's.fk_prospectlevel' => 'ProspectLevel' ,
2020-08-24 01:01:35 +02:00
'st.code' => 'ProspectStatus' , 'payterm.libelle' => 'PaymentConditions' , 'paymode.libelle' => 'PaymentMode' ,
's.outstanding_limit' => 'OutstandingBill' , 'pbacc.ref' => 'PaymentBankAccount' , 'incoterm.code' => 'IncotermLabel'
2018-05-27 15:04:12 +02:00
);
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_USEPREFIX )) {
$this -> export_fields_array [ $r ][ 's.prefix' ] = 'Prefix' ;
}
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
$this -> export_fields_array [ $r ][ 's.price_level' ] = 'PriceLevel' ;
}
2021-09-25 07:49:08 +02:00
if ( ! empty ( $conf -> global -> ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY )) {
$this -> export_fields_array [ $r ] += array ( 's.accountancy_code_sell' => 'ProductAccountancySellCode' , 's.accountancy_code_buy' => 'ProductAccountancyBuyCode' );
}
2017-01-17 10:50:19 +01:00
// Add multicompany field
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED )) {
2020-04-16 00:42:57 +02:00
$nbofallowedentities = count ( explode ( ',' , getEntity ( 'societe' ))); // If project are shared, nb will be > 1
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $nbofallowedentities > 1 ) {
$this -> export_fields_array [ $r ] += array ( 's.entity' => 'Entity' );
}
2017-01-17 10:50:19 +01:00
}
2021-03-01 20:37:16 +01:00
$keyforselect = 'societe' ;
$keyforelement = 'company' ;
$keyforaliasextra = 'extra' ;
2016-02-24 16:56:24 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2020-02-13 12:36:05 +01:00
$this -> export_fields_array [ $r ] += array ( 'u.login' => 'SaleRepresentativeLogin' , 'u.firstname' => 'SaleRepresentativeFirstname' , 'u.lastname' => 'SaleRepresentativeLastname' );
2020-08-24 01:01:35 +02:00
2018-05-27 15:04:12 +02:00
//$this->export_TypeFields_array[$r]=array(
2018-12-20 16:49:17 +01:00
// 's.rowid'=>"List:societe:nom",'s.nom'=>"Text",'s.status'=>"Text",'s.client'=>"Boolean",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",
2018-05-27 15:04:12 +02:00
// 's.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",
2020-09-16 12:17:33 +02:00
// 'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.default_lang'=>"Text",'s.canvas' => "Canvas",'s.siret'=>"Text",'s.siren'=>"Text",
2018-05-27 15:04:12 +02:00
// 's.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note'=>"Text",
// 't.libelle'=>"Text",'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
// 's.fk_stcomm'=>'List:c_stcomm:libelle:code','d.nom'=>'List:c_departements:nom:rowid'
//);
2020-02-13 12:36:05 +01:00
$this -> export_TypeFields_array [ $r ] = array (
2020-08-24 01:20:07 +02:00
's.rowid' => " Numeric " , 's.nom' => " Text " , 's.name_alias' => " Text " , 'ps.nom' => " Text " ,
2020-08-24 01:01:35 +02:00
's.status' => " Numeric " , 's.client' => " Numeric " , 's.fournisseur' => " Boolean " , 's.datec' => " Date " , 's.tms' => " Date " ,
's.code_client' => " Text " , 's.code_fournisseur' => " Text " , 's.code_compta' => " Text " , 's.code_compta_fournisseur' => " Text " ,
2020-10-31 14:32:18 +01:00
's.address' => " Text " , 's.zip' => " Text " , 's.town' => " Text " ,
2020-09-17 19:33:29 +02:00
'd.nom' => 'Text' , 'r.nom' => 'Text' , 'c.label' => " List:c_country:label:label " , 'c.code' => " Text " ,
's.phone' => " Text " , 's.fax' => " Text " ,
's.url' => " Text " , 's.email' => " Text " , 's.default_lang' => " Text " , 's.canvas' => " Canvas " ,
's.siret' => " Text " , 's.siren' => " Text " , 's.ape' => " Text " , 's.idprof4' => " Text " , 's.idprof5' => " Text " , 's.idprof6' => " Text " ,
's.tva_intra' => " Text " , 's.capital' => " Numeric " , 's.note_private' => " Text " , 's.note_public' => " Text " ,
2020-08-24 01:01:35 +02:00
't.libelle' => " Text " , 'ce.code' => " List:c_effectif:libelle:code " , " cfj.libelle " => " Text " , 's.fk_prospectlevel' => 'List:c_prospectlevel:label:code' ,
2020-09-17 19:33:29 +02:00
'st.code' => 'List:c_stcomm:libelle:code' ,
'payterm.libelle' => 'Text' , 'paymode.libelle' => 'Text' ,
2020-08-24 01:01:35 +02:00
's.outstanding_limit' => 'Numeric' , 'pbacc.ref' => 'Text' , 'incoterm.code' => 'Text' ,
'u.login' => 'Text' , 'u.firstname' => 'Text' , 'u.lastname' => 'Text' ,
2021-12-17 12:38:13 +01:00
's.entity' => 'List:entity:label:rowid' , 's.price_level' => 'Numeric' ,
2021-09-25 07:49:08 +02:00
's.accountancy_code_sell' => 'Text' , 's.accountancy_code_buy' => 'Text'
2018-05-27 15:04:12 +02:00
);
2016-04-19 12:43:50 +02:00
2020-02-13 12:36:05 +01:00
$this -> export_entities_array [ $r ] = array ( 'u.login' => 'user' , 'u.firstname' => 'user' , 'u.lastname' => 'user' ); // We define here only fields that use another picto
$this -> export_examplevalues_array [ $r ] = array ( 's.client' => '0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)' , 's.fournisseur' => '0 (not a supplier) or 1 (supplier)' );
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'societe as s' ;
2020-04-16 00:42:57 +02:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_extrafields as extra ON s.rowid = extra.fk_object' ;
2020-08-24 01:01:35 +02:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as ps ON s.parent = ps.rowid' ;
2020-02-13 12:36:05 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_typent as t ON s.fk_typent = t.id' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as c ON s.fk_pays = c.rowid' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_effectif as ce ON s.fk_effectif = ce.id' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_departements as d ON s.fk_departement = d.rowid' ;
2020-08-24 01:01:35 +02:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_regions as r ON r.code_region = d.fk_region AND r.fk_pays = s.fk_pays' ;
2020-02-13 12:36:05 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_stcomm as st ON s.fk_stcomm = st.id' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON sc.fk_soc = s.rowid LEFT JOIN ' . MAIN_DB_PREFIX . 'user as u ON sc.fk_user = u.rowid' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_payment_term as payterm ON s.cond_reglement = payterm.rowid' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_paiement as paymode ON s.mode_reglement = paymode.id' ;
2020-08-24 01:01:35 +02:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as pbacc ON s.fk_account = pbacc.rowid' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_incoterms as incoterm ON s.fk_incoterms = incoterm.rowid' ;
2020-02-13 12:36:05 +01:00
$this -> export_sql_end [ $r ] .= ' WHERE s.entity IN (' . getEntity ( 'societe' ) . ')' ;
2017-01-15 23:32:14 +01:00
if ( is_object ( $user ) && empty ( $user -> rights -> societe -> client -> voir )) {
2021-08-28 00:55:51 +02:00
$this -> export_sql_end [ $r ] .= ' AND (sc.fk_user = ' . (( int ) $user -> id ) . ' ' ;
2020-02-13 12:36:05 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_EXPORT_SUBORDINATES_CHILDS )) {
2016-12-13 16:52:49 +01:00
$subordinatesids = $user -> getAllChildIds ();
2021-03-22 12:00:41 +01:00
$this -> export_sql_end [ $r ] .= count ( $subordinatesids ) > 0 ? ' OR (sc.fk_user IN (' . $this -> db -> sanitize ( implode ( ',' , $subordinatesids )) . ')' : '' ;
2016-12-13 16:52:49 +01:00
}
2020-02-13 12:36:05 +01:00
$this -> export_sql_end [ $r ] .= ')' ;
2016-12-09 16:14:43 +01:00
}
2016-11-25 10:55:09 +01:00
2009-05-19 02:14:27 +02:00
// Export list of contacts and attributes
2008-10-01 21:10:17 +02:00
$r ++ ;
2020-02-13 12:36:05 +01:00
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> export_label [ $r ] = 'ExportDataset_company_2' ;
$this -> export_icon [ $r ] = 'contact' ;
$this -> export_permission [ $r ] = array ( array ( " societe " , " contact " , " export " ));
$this -> export_fields_array [ $r ] = array (
'c.rowid' => " IdContact " , 'c.civility' => " CivilityCode " , 'c.lastname' => 'Lastname' , 'c.firstname' => 'Firstname' , 'c.poste' => 'PostOrFunction' ,
'c.datec' => " DateCreation " , 'c.tms' => " DateLastModification " , 'c.priv' => " ContactPrivate " , 'c.address' => " Address " , 'c.zip' => " Zip " , 'c.town' => " Town " ,
2020-08-24 01:01:35 +02:00
'd.nom' => 'State' , 'r.nom' => 'Region' , 'co.label' => " Country " , 'co.code' => " CountryCode " , 'c.phone' => " Phone " , 'c.fax' => " Fax " , 'c.phone_mobile' => " Mobile " , 'c.email' => " EMail " ,
2019-03-28 18:29:36 +01:00
'c.statut' => " Status " ,
2020-02-13 12:36:05 +01:00
's.rowid' => " IdCompany " , 's.nom' => " CompanyName " , 's.status' => " Status " , 's.code_client' => " CustomerCode " , 's.code_fournisseur' => " SupplierCode " ,
's.code_compta' => " AccountancyCode " , 's.code_compta_fournisseur' => " SupplierAccountancyCode " ,
's.client' => 'Customer' , 's.fournisseur' => 'Supplier' ,
2020-04-16 00:42:57 +02:00
's.address' => 'Address' , 's.zip' => " Zip " , 's.town' => " Town " , 's.phone' => 'Phone' , 's.email' => " Email " ,
't.libelle' => " ThirdPartyType "
2018-05-27 15:04:12 +02:00
);
2021-12-17 12:38:13 +01:00
// Add multicompany field
if ( ! empty ( $conf -> global -> MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED )) {
if ( ! empty ( $conf -> multicompany -> enabled )) {
2022-03-18 12:05:59 +01:00
$nbofallowedentities = count ( explode ( ',' , getEntity ( 'contact' )));
2021-12-17 12:41:44 +01:00
if ( $nbofallowedentities > 1 ) {
2021-12-17 12:38:13 +01:00
$this -> export_fields_array [ $r ][ 'c.entity' ] = 'Entity' ;
}
$nbofallowedentities = count ( explode ( ',' , getEntity ( 'societe' )));
if ( $nbofallowedentities > 1 ) {
$this -> export_fields_array [ $r ][ 's.entity' ] = 'Entity' ;
}
}
}
2020-02-13 12:36:05 +01:00
$this -> export_examplevalues_array [ $r ] = array ( 's.client' => '0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)' , 's.fournisseur' => '0 (not a supplier) or 1 (supplier)' );
$this -> export_TypeFields_array [ $r ] = array (
'c.civility' => " List:c_civility:label:code " , 'c.lastname' => 'Text' , 'c.firstname' => 'Text' , 'c.poste' => 'Text' , 'c.datec' => " Date " , 'c.priv' => " Boolean " ,
2020-08-24 01:01:35 +02:00
'c.address' => " Text " , 'c.zip' => " Text " , 'c.town' => " Text " , 'd.nom' => 'Text' , 'r.nom' => 'Text' , 'co.label' => " List:c_country:label:rowid " , 'co.code' => " Text " , 'c.phone' => " Text " ,
2020-02-13 12:36:05 +01:00
'c.fax' => " Text " , 'c.email' => " Text " ,
2020-04-16 00:42:57 +02:00
'c.statut' => " Status " ,
's.rowid' => " List:societe:nom::thirdparty " , 's.nom' => " Text " , 's.status' => " Status " , 's.code_client' => " Text " , 's.code_fournisseur' => " Text " ,
2020-02-13 12:36:05 +01:00
's.code_compta' => " Text " , 's.code_compta_fournisseur' => " Text " ,
's.client' => " Text " , 's.fournisseur' => " Text " ,
2020-04-16 00:42:57 +02:00
's.address' => " Text " , 's.zip' => " Text " , 's.town' => " Text " , 's.phone' => " Text " , 's.email' => " Text " ,
2021-12-17 12:38:13 +01:00
't.libelle' => " Text " ,
'c.entity' => 'List:entity:label:rowid' ,
's.entity' => 'List:entity:label:rowid' ,
2018-05-27 15:04:12 +02:00
);
2020-02-13 12:36:05 +01:00
$this -> export_entities_array [ $r ] = array (
's.rowid' => " company " , 's.nom' => " company " , 's.status' => 'company' , 's.code_client' => " company " , 's.code_fournisseur' => " company " ,
's.code_compta' => " company " , 's.code_compta_fournisseur' => " company " ,
2020-02-10 06:06:27 +01:00
's.client' => " company " , 's.fournisseur' => " company " ,
2020-04-16 00:42:57 +02:00
's.address' => " company " , 's.zip' => " company " , 's.town' => " company " , 's.phone' => " company " , 's.email' => " company " ,
2021-12-17 12:38:13 +01:00
't.libelle' => " company " ,
's.entity' => 'company' ,
2020-02-13 12:36:05 +01:00
); // We define here only fields that use another picto
2021-04-11 04:24:21 +02:00
if ( empty ( $conf -> fournisseur -> enabled ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD ) || ! empty ( $conf -> supplier_order -> enabled ) || ! empty ( $conf -> supplier_invoice -> enabled )) {
2020-04-16 00:42:57 +02:00
unset ( $this -> export_fields_array [ $r ][ 's.code_fournisseur' ]);
unset ( $this -> export_entities_array [ $r ][ 's.code_fournisseur' ]);
}
2021-03-01 20:37:16 +01:00
$keyforselect = 'socpeople' ;
$keyforelement = 'contact' ;
$keyforaliasextra = 'extra' ;
2020-04-16 00:42:57 +02:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2021-03-01 20:37:16 +01:00
$keyforselect = 'societe' ;
$keyforelement = 'company' ;
$keyforaliasextra = 'extrasoc' ;
2020-04-16 00:42:57 +02:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
2020-02-13 12:36:05 +01:00
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'socpeople as c' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as s ON c.fk_soc = s.rowid' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_extrafields as extrasoc ON s.rowid = extrasoc.fk_object' ;
2021-02-23 22:03:23 +01:00
if ( is_object ( $user ) && empty ( $user -> rights -> societe -> client -> voir )) {
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON sc.fk_soc = s.rowid' ;
}
2020-02-13 12:36:05 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_departements as d ON c.fk_departement = d.rowid' ;
2020-08-24 01:01:35 +02:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_regions as r ON r.code_region = d.fk_region AND r.fk_pays = c.fk_pays' ;
2020-02-13 12:36:05 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as co ON c.fk_pays = co.rowid' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'socpeople_extrafields as extra ON extra.fk_object = c.rowid' ;
2020-04-16 00:42:57 +02:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_typent as t ON s.fk_typent = t.id' ;
2022-03-18 12:05:59 +01:00
$this -> export_sql_end [ $r ] .= ' WHERE c.entity IN (' . getEntity ( 'contact' ) . ')' ;
2017-01-15 23:32:14 +01:00
if ( is_object ( $user ) && empty ( $user -> rights -> societe -> client -> voir )) {
2021-08-28 00:55:51 +02:00
$this -> export_sql_end [ $r ] .= ' AND (sc.fk_user = ' . (( int ) $user -> id ) . ' ' ;
2020-02-13 12:36:05 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_EXPORT_SUBORDINATES_CHILDS )) {
2016-12-13 16:52:49 +01:00
$subordinatesids = $user -> getAllChildIds ();
2021-03-22 12:00:41 +01:00
$this -> export_sql_end [ $r ] .= count ( $subordinatesids ) > 0 ? ' OR (sc.fk_user IN (' . $this -> db -> sanitize ( implode ( ',' , $subordinatesids )) . ')' : '' ;
2016-12-13 16:52:49 +01:00
}
2020-02-13 12:36:05 +01:00
$this -> export_sql_end [ $r ] .= ')' ;
2016-12-09 16:14:43 +01:00
}
2009-05-19 02:14:27 +02:00
2020-04-16 00:42:57 +02:00
// Imports
//--------
$r = 0 ;
// Import list of third parties and attributes
$r ++ ;
$this -> import_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> import_label [ $r ] = 'ImportDataset_company_1' ;
$this -> import_icon [ $r ] = 'company' ;
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use a different icon from the one defined in import_icon
$this -> import_tables_array [ $r ] = array (
's' => MAIN_DB_PREFIX . 'societe' ,
'extra' => MAIN_DB_PREFIX . 'societe_extrafields'
); // List of tables to insert into (insert done in same order)
$this -> import_fields_array [ $r ] = array ( //field order as per structure of table llx_societe
's.nom' => " Name* " ,
's.name_alias' => " AliasNameShort " ,
2020-08-24 01:20:07 +02:00
's.parent' => " ParentCompany " ,
2020-04-16 00:42:57 +02:00
's.status' => " Status " ,
's.code_client' => " CustomerCode " ,
's.code_fournisseur' => " SupplierCode " ,
's.code_compta' => " CustomerAccountancyCode " ,
's.code_compta_fournisseur' => " SupplierAccountancyCode " ,
's.address' => " Address " ,
's.zip' => " Zip " ,
's.town' => " Town " ,
's.fk_departement' => " StateCode " ,
's.fk_pays' => " CountryCode " ,
's.phone' => " Phone " ,
's.fax' => " Fax " ,
's.url' => " Url " ,
's.email' => " Email " ,
's.fk_effectif' => " Staff " ,
's.fk_typent' => " ThirdPartyType " ,
" s.fk_forme_juridique " => " JuridicalStatus " ,
's.siren' => " ProfId1 " ,
's.siret' => " ProfId2 " ,
's.ape' => " ProfId3 " ,
's.idprof4' => " ProfId4 " ,
's.idprof5' => " ProfId5 " ,
's.idprof6' => " ProfId6 " ,
's.tva_intra' => " VATIntraShort " ,
's.capital' => " Capital " ,
's.fk_stcomm' => 'ProspectStatus' ,
's.note_private' => " NotePrivate " ,
's.note_public' => " NotePublic " ,
's.client' => " Customer* " ,
's.fournisseur' => " Supplier* " ,
's.fk_prospectlevel' => 'ProspectLevel' ,
's.mode_reglement' => 'PaymentTypeCustomer' ,
's.cond_reglement' => " PaymentTermsCustomer " ,
's.mode_reglement_supplier' => 'PaymentTypeSupplier' ,
's.cond_reglement_supplier' => " PaymentTermsSupplier " ,
2020-08-24 01:01:35 +02:00
's.outstanding_limit' => 'OutstandingBill' ,
's.fk_account' => 'PaymentBankAccount' ,
's.fk_incoterms' => 'IncotermLabel' ,
2020-04-16 00:42:57 +02:00
's.tva_assuj' => 'VATIsUsed' ,
's.barcode' => 'BarCode' ,
's.default_lang' => 'DefaultLanguage' ,
's.canvas' => " Canvas " ,
's.datec' => " DateCreation " ,
's.fk_multicurrency' => 'MulticurrencyUsed' ,
's.multicurrency_code' => 'MulticurrencyCurrency'
);
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
$this -> import_fields_array [ $r ][ 's.price_level' ] = 'PriceLevel' ;
}
2021-09-25 07:49:08 +02:00
if ( ! empty ( $conf -> global -> ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY )) {
$this -> import_fields_array [ $r ] += array ( 's.accountancy_code_sell' => 'ProductAccountancySellCode' , 's.accountancy_code_buy' => 'ProductAccountancyBuyCode' );
}
2020-04-16 00:42:57 +02:00
// Add extra fields
2021-10-31 14:33:44 +01:00
$sql = " SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . " extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, " . $conf -> entity . " ) " ;
2020-04-16 00:42:57 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) { // This can fail when class is used on old database (during migration for example)
2020-04-16 00:42:57 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
$fieldname = 'extra.' . $obj -> name ;
$fieldlabel = ucfirst ( $obj -> label );
$this -> import_fields_array [ $r ][ $fieldname ] = $fieldlabel . ( $obj -> fieldrequired ? '*' : '' );
}
}
// End add extra fields
$this -> import_fieldshidden_array [ $r ] = array (
's.fk_user_creat' => 'user->id' ,
'extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'societe'
); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
$this -> import_convertvalue_array [ $r ] = array ( //field order as per structure of table llx_societe
's.code_client' => array ( 'rule' => 'getcustomercodeifauto' ),
's.code_fournisseur' => array ( 'rule' => 'getsuppliercodeifauto' ),
's.code_compta' => array ( 'rule' => 'getcustomeraccountancycodeifauto' ),
's.code_compta_fournisseur' => array ( 'rule' => 'getsupplieraccountancycodeifauto' ),
's.fk_departement' => array (
'rule' => 'fetchidfromcodeid' ,
'classfile' => '/core/class/cstate.class.php' ,
'class' => 'Cstate' ,
'method' => 'fetch' ,
2020-12-03 19:45:36 +01:00
'dict' => 'DictionaryStateCode'
2020-04-16 00:42:57 +02:00
),
's.fk_pays' => array (
'rule' => 'fetchidfromcodeid' ,
'classfile' => '/core/class/ccountry.class.php' ,
'class' => 'Ccountry' ,
'method' => 'fetch' ,
'dict' => 'DictionaryCountry'
),
's.fk_typent' => array (
'rule' => 'fetchidfromcodeorlabel' ,
'classfile' => '/core/class/ctypent.class.php' ,
'class' => 'Ctypent' ,
'method' => 'fetch' ,
'dict' => 'DictionaryCompanyType'
),
's.capital' => array ( 'rule' => 'numeric' ),
's.fk_stcomm' => array ( 'rule' => 'zeroifnull' ),
2020-08-24 01:01:35 +02:00
's.parent' => array (
'rule' => 'fetchidfromref' ,
'file' => '/societe/class/societe.class.php' ,
'class' => 'Societe' ,
'method' => 'fetch' ,
'element' => 'ThirdParty'
),
's.outstanding_limit' => array ( 'rule' => 'numeric' ),
's.fk_account' => array (
'rule' => 'fetchidfromcodeid' ,
'classfile' => '/compta/bank/class/account.class.php' ,
'class' => 'Account' ,
'method' => 'fetch' ,
'element' => 'BankAccount'
2020-08-24 01:20:07 +02:00
// ),
// TODO
// 's.fk_incoterms' => array(
// 'rule' => 'fetchidfromcodeid',
// 'classfile' => '/core/class/cincoterm.class.php',
// 'class' => 'Cincoterm',
// 'method' => 'fetch',
// 'dict' => 'IncotermLabel'
)
2020-04-16 00:42:57 +02:00
);
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
$this -> import_regex_array [ $r ] = array ( //field order as per structure of table llx_societe
's.status' => '^[0|1]' ,
's.fk_typent' => 'id@' . MAIN_DB_PREFIX . 'c_typent' ,
's.client' => '^[0|1|2|3]' ,
's.fournisseur' => '^[0|1]' ,
's.mode_reglement' => 'id@' . MAIN_DB_PREFIX . 'c_paiement' ,
's.cond_reglement' => 'rowid@' . MAIN_DB_PREFIX . 'c_payment_term' ,
's.mode_reglement_supplier' => 'id@' . MAIN_DB_PREFIX . 'c_paiement' ,
's.cond_reglement_supplier' => 'rowid@' . MAIN_DB_PREFIX . 'c_payment_term' ,
2020-08-24 01:01:35 +02:00
's.fk_incoterms' => 'rowid@' . MAIN_DB_PREFIX . 'c_incoterms' ,
2020-04-16 00:42:57 +02:00
's.tva_assuj' => '^[0|1]' ,
's.fk_multicurrency' => '^[0|1]' ,
's.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$' ,
's.multicurrency_code' => 'code_iso@' . MAIN_DB_PREFIX . 'c_currencies'
);
$this -> import_examplevalues_array [ $r ] = array ( //field order as per structure of table llx_societe
's.nom' => " TPBigCompany " ,
's.name_alias' => " Alias for TPBigCompany " ,
2020-08-24 01:01:35 +02:00
's.parent' => " TPMotherCompany " ,
2020-04-16 00:42:57 +02:00
's.status' => " 0 (closed) / 1 (active) " ,
's.code_client' => 'eg. CU01-0001 / empty / "auto"' ,
's.code_fournisseur' => 'eg. SU01-0001 / empty / "auto"' ,
's.code_compta' => " Code or empty to be auto-created " ,
's.code_compta_fournisseur' => " Code or empty to be auto-created " ,
's.address' => " 61 Jump Street " ,
's.zip' => " 123456 " ,
's.town' => " Bigtown " ,
's.fk_departement' => 'matches field "code_departement" in table "' . MAIN_DB_PREFIX . 'c_departements"' ,
's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "' . MAIN_DB_PREFIX . 'c_country"' ,
's.phone' => " eg: +34123456789 " ,
's.fax' => " eg. +34987654321 " ,
's.url' => " e.g. https://www.mybigcompany.com " ,
's.email' => " e.g. test@mybigcompany.com " ,
's.fk_effectif' => " 1/2/3/5: represents one of the five ranges of employees " ,
's.fk_typent' => 'matches field "id" (1-9 etc.) OR "code" (TE_SMALL etc.) in table "' . MAIN_DB_PREFIX . 'c_typent"' ,
's.fk_forme_juridique' => '1/2/3 etc...matches field "code" in table "' . MAIN_DB_PREFIX . 'c_forme_juridique"' ,
's.siret' => " " ,
's.siren' => " " ,
's.ape' => " " ,
's.idprof4' => " " ,
's.idprof5' => " " ,
's.idprof6' => " " ,
's.tva_intra' => 'VAT number e.g."FR0123456789"' ,
's.capital' => " 10000 " ,
's.fk_stcomm' => '-1/0/1/2 etc... matches field "id" in table "' . MAIN_DB_PREFIX . 'c_stcomm"' ,
's.note_private' => " Example of a PRIVATE note. " ,
's.note_public' => " Example of a PUBLIC note. " ,
's.client' => '0 (no customer no prospect) / 1 (customer) / 2 (prospect)/ 3 (customer and prospect)' ,
's.fournisseur' => '0 (not supplier) / 1 (supplier)' ,
's.fk_prospectlevel' => 'eg. "PL_MEDIUM" matches field "code" in table "' . MAIN_DB_PREFIX . 'c_prospectlevel"' ,
's.mode_reglement' => '1/2/3...matches field "id" in table "' . MAIN_DB_PREFIX . 'c_paiement"' ,
's.cond_reglement' => '1/2/3...matches field "rowid" in table "' . MAIN_DB_PREFIX . 'c_payment_term"' ,
's.mode_reglement_supplier' => '1/2/3...matches field "id" in table "' . MAIN_DB_PREFIX . 'c_paiement"' ,
's.cond_reglement_supplier' => '1/2/3...matches field "rowid" in table "' . MAIN_DB_PREFIX . 'c_payment_term"' ,
2020-08-24 01:01:35 +02:00
's.outstanding_limit' => " 5000 " ,
's.fk_account' => " rowid or ref " ,
's.fk_incoterms' => '1/2/3...matches field "rowid" in table "' . MAIN_DB_PREFIX . 'c_incoterms"' ,
2020-04-16 00:42:57 +02:00
's.tva_assuj' => '0 (VAT not used) / 1 (VAT used)' ,
's.barcode' => '123456789' ,
's.default_lang' => 'en_US / es_ES etc...matches a language directory in htdocs/langs/' ,
's.canvas' => " empty / a custom canvas form layout url e.g. mycanvas@mymodule " ,
's.datec' => 'formatted as ' . dol_print_date ( dol_now (), '%Y-%m-%d' ),
's.fk_multicurrency' => '0 (use system default currency) / 1 (use local currency)' ,
2021-09-25 07:49:08 +02:00
's.multicurrency_code' => 'GBP/USD etc... matches field "code_iso" in table "' . MAIN_DB_PREFIX . 'c_currencies"' ,
's.accountancy_code_sell' => '707' ,
's.accountancy_code_buy' => '607' ,
2020-04-16 00:42:57 +02:00
);
$this -> import_updatekeys_array [ $r ] = array (
's.nom' => 'Name' ,
's.code_client' => 'CustomerCode' ,
's.code_fournisseur' => 'SupplierCode' ,
's.code_compta' => 'CustomerAccountancyCode' ,
's.code_compta_fournisseur' => 'SupplierAccountancyCode'
);
// Import list of contacts/additional addresses and attributes
$r ++ ;
$this -> import_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> import_label [ $r ] = 'ImportDataset_company_2' ;
$this -> import_icon [ $r ] = 'contact' ;
$this -> import_entities_array [ $r ] = array ( 's.fk_soc' => 'company' ); // We define here only fields that use a different icon than the one defined in import_icon
$this -> import_tables_array [ $r ] = array (
's' => MAIN_DB_PREFIX . 'socpeople' ,
'extra' => MAIN_DB_PREFIX . 'socpeople_extrafields'
); // List of tables to insert into (insert done in same order)
$this -> import_fields_array [ $r ] = array ( //field order as per structure of table llx_socpeople
2020-04-22 10:44:23 +02:00
's.rowid' => 'Id' ,
2020-04-16 00:42:57 +02:00
's.datec' => " DateCreation " ,
's.fk_soc' => 'ThirdPartyName' ,
's.civility' => 'UserTitle' ,
's.lastname' => " Lastname* " ,
's.firstname' => " Firstname " ,
's.address' => " Address " ,
's.zip' => " Zip " ,
's.town' => " Town " ,
's.fk_departement' => " StateCode " ,
's.fk_pays' => " CountryCode " ,
2020-09-16 00:47:44 +02:00
's.birthday' => " DateOfBirth " ,
2020-04-16 00:42:57 +02:00
's.poste' => " Role " ,
's.phone' => " Phone " ,
's.phone_perso' => " PhonePerso " ,
's.phone_mobile' => " PhoneMobile " ,
's.fax' => " Fax " ,
's.email' => " Email " ,
's.note_private' => " NotePrivate " ,
's.note_public' => " NotePublic "
);
// Add extra fields
2021-10-29 12:25:50 +02:00
$sql = " SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . " extrafields WHERE type != 'separate' AND elementtype = 'socpeople' AND entity IN (0, " . $conf -> entity . " ) " ;
2020-04-16 00:42:57 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) { // This can fail when class is used on an old database (during a migration for example)
2020-04-16 00:42:57 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
$fieldname = 'extra.' . $obj -> name ;
$fieldlabel = ucfirst ( $obj -> label );
$this -> import_fields_array [ $r ][ $fieldname ] = $fieldlabel . ( $obj -> fieldrequired ? '*' : '' );
}
}
// End add extra fields
$this -> import_fieldshidden_array [ $r ] = array (
's.fk_user_creat' => 'user->id' ,
'extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'socpeople'
); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
$this -> import_convertvalue_array [ $r ] = array (
's.fk_soc' => array (
'rule' => 'fetchidfromref' ,
'file' => '/societe/class/societe.class.php' ,
'class' => 'Societe' ,
'method' => 'fetch' ,
'element' => 'ThirdParty'
),
's.fk_departement' => array (
'rule' => 'fetchidfromcodeid' ,
'classfile' => '/core/class/cstate.class.php' ,
'class' => 'Cstate' ,
'method' => 'fetch' ,
2020-12-03 19:45:36 +01:00
'dict' => 'DictionaryStateCode'
2020-04-16 00:42:57 +02:00
),
's.fk_pays' => array (
'rule' => 'fetchidfromcodeid' ,
'classfile' => '/core/class/ccountry.class.php' ,
'class' => 'Ccountry' ,
'method' => 'fetch' ,
'dict' => 'DictionaryCountry'
),
);
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
$this -> import_regex_array [ $r ] = array (
's.birthday' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' ,
's.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$'
);
$this -> import_examplevalues_array [ $r ] = array ( //field order as per structure of table llx_socpeople
2020-04-22 10:44:23 +02:00
's.rowid' => '1' ,
2020-04-16 00:42:57 +02:00
's.datec' => 'formatted as ' . dol_print_date ( dol_now (), '%Y-%m-%d' ),
's.fk_soc' => 'Third Party name eg. TPBigCompany' ,
's.civility' => 'Title of civility eg: MR...matches field "code" in table "' . MAIN_DB_PREFIX . 'c_civility"' ,
's.lastname' => " lastname or label " ,
's.firstname' => 'John' ,
's.address' => '61 Jump street' ,
's.zip' => '75000' ,
's.town' => 'Bigtown' ,
's.fk_departement' => 'matches field "code_departement" in table "' . MAIN_DB_PREFIX . 'c_departements"' ,
's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "' . MAIN_DB_PREFIX . 'c_country"' ,
's.birthday' => 'formatted as ' . dol_print_date ( dol_now (), '%Y-%m-%d' ),
's.poste' => " Director " ,
's.phone' => " 5551122 " ,
's.phone_perso' => " 5551133 " ,
's.phone_mobile' => " 5551144 " ,
's.fax' => " 5551155 " ,
's.email' => " johnsmith@email.com " ,
's.note_private' => " My private note " ,
's.note_public' => " My public note "
);
2020-04-22 10:44:23 +02:00
$this -> import_updatekeys_array [ $r ] = array (
's.rowid' => 'Id'
);
2020-04-16 00:42:57 +02:00
// Import Bank Accounts
$r ++ ;
$this -> import_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> import_label [ $r ] = " ImportDataset_company_3 " ; // Translation key
$this -> import_icon [ $r ] = 'company' ;
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use a different icon to the one defined in import_icon
$this -> import_tables_array [ $r ] = array ( 'sr' => MAIN_DB_PREFIX . 'societe_rib' );
$this -> import_fields_array [ $r ] = array ( //field order as per structure of table llx_societe_rib
'sr.label' => " Label* " ,
'sr.fk_soc' => " ThirdPartyName* " ,
'sr.datec' => " DateCreation* " ,
'sr.bank' => " Bank " ,
'sr.code_banque' => " BankCode " ,
'sr.code_guichet' => " DeskCode " ,
2021-11-12 11:46:18 +01:00
'sr.number' => " BankAccountNumber " ,
2020-04-16 00:42:57 +02:00
'sr.cle_rib' => " BankAccountNumberKey " ,
'sr.bic' => " BIC " ,
'sr.iban_prefix' => " IBAN " ,
'sr.domiciliation' => " BankAccountDomiciliation " ,
'sr.proprio' => " BankAccountOwner " ,
'sr.owner_address' => " BankAccountOwnerAddress " ,
'sr.default_rib' => 'Default' ,
'sr.rum' => 'RUM' ,
2021-11-12 11:46:37 +01:00
'sr.frstrecur' => " WithdrawMode " ,
2020-02-24 15:14:01 +01:00
'sr.type' => " Type ban is defaut " ,
2020-04-16 00:42:57 +02:00
);
$this -> import_convertvalue_array [ $r ] = array (
'sr.fk_soc' => array (
'rule' => 'fetchidfromref' ,
'classfile' => '/societe/class/societe.class.php' ,
'class' => 'Societe' ,
'method' => 'fetch' ,
'element' => 'ThirdParty'
)
);
$this -> import_examplevalues_array [ $r ] = array ( //field order as per structure of table llx_societe_rib
'sr.label' => 'eg. "account1"' ,
'sr.fk_soc' => 'eg. "TPBigCompany"' ,
2021-02-23 22:03:23 +01:00
'sr.datec' => 'date used for creating direct debit UMR formatted as ' . dol_print_date (
dol_now (),
'%Y-%m-%d'
),
2020-04-16 00:42:57 +02:00
'sr.bank' => 'bank name eg: "ING-Direct"' ,
'sr.code_banque' => 'account sort code (GB)/Routing number (US) eg. "8456"' ,
'sr.code_guichet' => " bank code for office/branch " ,
'sr.number' => 'account number eg. "3333333333"' ,
'sr.cle_rib' => 'account checksum/control digits (if used) eg. "22"' ,
'sr.bic' => 'bank identifier eg. "USHINGMMXXX"' ,
'sr.iban_prefix' => 'complete account IBAN eg. "GB78CPBK08925068637123"' ,
'sr.domiciliation' => 'bank branch address eg. "PARIS"' ,
'sr.proprio' => 'name on the bank account' ,
'sr.owner_address' => 'address of account holder' ,
'sr.default_rib' => '1 (default account) / 0 (not default)' ,
'sr.rum' => 'RUM code' ,
2021-11-12 11:46:37 +01:00
'sr.frstrecur' => 'FRST' ,
2020-02-24 15:14:01 +01:00
'sr.type' => 'ban' ,
2020-04-16 00:42:57 +02:00
);
2016-11-25 10:55:09 +01:00
2018-12-04 21:25:59 +01:00
// Import Company Sales representatives
2015-08-19 16:59:43 +02:00
$r ++ ;
2019-11-13 19:37:08 +01:00
$this -> import_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> import_label [ $r ] = " ImportDataset_company_4 " ; // Translation key
$this -> import_icon [ $r ] = 'company' ;
$this -> import_entities_array [ $r ] = array ( 'sr.fk_user' => 'user' ); // We define here only fields that use another icon that the one defined into import_icon
$this -> import_tables_array [ $r ] = array ( 'sr' => MAIN_DB_PREFIX . 'societe_commerciaux' );
$this -> import_fields_array [ $r ] = array ( 'sr.fk_soc' => " ThirdPartyName* " , 'sr.fk_user' => " User* " );
$this -> import_convertvalue_array [ $r ] = array (
'sr.fk_soc' => array ( 'rule' => 'fetchidfromref' , 'classfile' => '/societe/class/societe.class.php' , 'class' => 'Societe' , 'method' => 'fetch' , 'element' => 'ThirdParty' ),
'sr.fk_user' => array ( 'rule' => 'fetchidfromref' , 'classfile' => '/user/class/user.class.php' , 'class' => 'User' , 'method' => 'fetch' , 'element' => 'User' )
2015-08-19 16:59:43 +02:00
);
2019-11-13 19:37:08 +01:00
$this -> import_examplevalues_array [ $r ] = array ( 'sr.fk_soc' => " MyBigCompany " , 'sr.fk_user' => " login " );
2008-10-01 21:10:17 +02:00
}
2020-04-16 00:42:57 +02:00
/**
2019-02-26 21:13:07 +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
2012-01-04 21:23:50 +01:00
*
2020-04-16 00:42:57 +02:00
* @ param string $options Options when enabling module ( '' , 'noboxes' )
2019-02-26 21:13:07 +01:00
* @ return int 1 if OK , 0 if KO
2020-04-16 00:42:57 +02:00
*/
public function init ( $options = '' )
{
2012-04-05 11:07:16 +02:00
global $conf , $langs ;
2010-03-24 14:06:29 +01:00
2010-04-28 17:31:49 +02:00
// We disable this to prevent pb of modules not correctly disabled
2009-03-20 15:33:56 +01:00
//$this->remove($options);
2008-10-01 21:10:17 +02:00
2012-08-01 14:42:24 +02:00
//ODT template
2019-11-13 19:37:08 +01:00
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/thirdparties/template_thirdparty.odt' ;
$dirodt = DOL_DATA_ROOT . '/doctemplates/thirdparties' ;
$dest = $dirodt . '/template_thirdparty.odt' ;
2012-08-01 14:42:24 +02:00
2021-02-23 22:03:23 +01:00
if ( file_exists ( $src ) && ! file_exists ( $dest )) {
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2012-08-01 14:42:24 +02:00
dol_mkdir ( $dirodt );
2019-11-13 19:37:08 +01:00
$result = dol_copy ( $src , $dest , 0 , 0 );
2021-02-23 22:03:23 +01:00
if ( $result < 0 ) {
2012-08-01 14:42:24 +02:00
$langs -> load ( " errors " );
2019-11-13 19:37:08 +01:00
$this -> error = $langs -> trans ( 'ErrorFailToCopyFile' , $src , $dest );
2012-08-01 14:42:24 +02:00
return 0 ;
}
2012-02-05 19:37:52 +01:00
}
2008-10-01 21:10:17 +02:00
2010-03-24 14:06:29 +01:00
$sql = array ();
2010-03-21 21:29:29 +01:00
2019-01-27 11:55:16 +01:00
return $this -> _init ( $sql , $options );
2008-10-01 21:10:17 +02:00
}
2003-09-12 23:32:56 +02:00
}