2004-10-20 00:24:10 +02:00
< ? php
2005-07-31 01:22:07 +02:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2014-10-12 01:59:21 +02:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis . houssin @ inodbox . com >
2011-02-18 18:12:22 +01:00
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
2004-05-01 02:50:27 +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
2004-05-01 02:50:27 +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 />.
2004-05-01 02:50:27 +02:00
*/
2005-06-11 13:35:12 +02:00
/**
2009-07-30 00:52:08 +02:00
* \defgroup contrat Module contract
* \brief Module pour gerer la tenue de contrat de services
2011-10-24 14:11:49 +02:00
* \file htdocs / core / modules / modContrat . class . php
2009-07-30 00:52:08 +02:00
* \ingroup contrat
* \brief Fichier de description et activation du module Contrat
2009-05-04 13:40:00 +02:00
*/
2004-08-14 14:21:24 +02:00
2020-04-10 10:59:32 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2004-05-01 02:50:27 +02:00
2005-08-14 20:19:30 +02:00
/**
2015-09-07 15:55:26 +02:00
* Class to describe and enable module Contrat
2009-05-04 13:40:00 +02:00
*/
2004-05-01 02:50:27 +02:00
class modContrat extends DolibarrModules
{
2009-05-04 13:40:00 +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
2009-05-04 13:40:00 +02:00
*/
2019-02-25 20:35:59 +01:00
public function __construct ( $db )
2009-05-04 13:40:00 +02:00
{
2015-08-26 20:25:52 +02:00
global $conf , $langs ;
2015-02-22 13:16:49 +01:00
2012-01-04 21:23:50 +01:00
$this -> db = $db ;
$this -> numero = 54 ;
2005-08-14 20:19:30 +02:00
2009-05-04 13:40:00 +02:00
$this -> family = " crm " ;
2020-05-02 00:41:27 +02:00
$this -> module_position = '41' ;
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 ));
2009-05-04 13:40:00 +02:00
$this -> description = " Gestion des contrats de services " ;
2005-08-14 20:19:30 +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
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
2020-04-10 10:59:32 +02:00
$this -> picto = 'contract' ;
2009-05-04 13:40:00 +02:00
// Data directories to create when module is enabled
2013-08-26 14:29:46 +02:00
$this -> dirs = array ( " /contract/temp " );
2009-05-04 13:40:00 +02:00
2015-09-07 15:29:51 +02:00
// Dependencies
2014-07-19 22:05:35 +02:00
$this -> depends = array ( " modSociete " );
2009-05-04 13:40:00 +02:00
$this -> requiredby = array ();
2011-05-03 19:58:01 +02:00
2011-02-18 18:12:22 +01:00
// Config pages
$this -> config_page_url = array ( " contract.php " );
2009-05-04 13:40:00 +02:00
2015-09-07 15:40:55 +02:00
// Constants
2009-05-04 13:40:00 +02:00
$this -> const = array ();
2020-04-10 10:59:32 +02:00
$r = 0 ;
2018-02-25 10:55:02 +01:00
2017-05-18 12:40:20 +02:00
$this -> const [ $r ][ 0 ] = " CONTRACT_ADDON " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " mod_contract_serpis " ;
$this -> const [ $r ][ 3 ] = 'Nom du gestionnaire de numerotation des contrats' ;
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2018-02-25 10:55:02 +01:00
2017-05-18 12:40:20 +02:00
$this -> const [ $r ][ 0 ] = " CONTRACT_ADDON_PDF " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " strato " ;
$this -> const [ $r ][ 3 ] = 'Name of PDF model of contract' ;
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2018-02-25 10:55:02 +01:00
2017-05-18 12:40:20 +02:00
$this -> const [ $r ][ 0 ] = " CONTRACT_ADDON_PDF_ODT_PATH " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " DOL_DATA_ROOT/doctemplates/contracts " ;
$this -> const [ $r ][ 3 ] = " " ;
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2018-02-25 10:55:02 +01:00
2010-04-19 08:43:15 +02:00
// Boxes
2014-05-01 19:17:45 +02:00
$this -> boxes = array (
2020-04-10 10:59:32 +02:00
0 => array ( 'file' => 'box_contracts.php' , 'enabledbydefaulton' => 'Home' ),
1 => array ( 'file' => 'box_services_expired.php' , 'enabledbydefaulton' => 'Home' )
2014-05-01 19:17:45 +02:00
);
2009-05-04 13:40:00 +02:00
// Permissions
$this -> rights = array ();
$this -> rights_class = 'contrat' ;
2020-04-10 10:59:32 +02:00
$r = 0 ;
2018-02-25 10:55:02 +01:00
2015-05-10 23:37:04 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 161 ;
$this -> rights [ $r ][ 1 ] = 'Lire les contrats' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
2016-06-04 12:16:30 +02:00
$this -> rights [ $r ][ 3 ] = 0 ;
2015-05-10 23:37:04 +02:00
$this -> rights [ $r ][ 4 ] = 'lire' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 162 ;
$this -> rights [ $r ][ 1 ] = 'Creer / modifier les contrats' ;
$this -> rights [ $r ][ 2 ] = 'w' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'creer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 163 ;
$this -> rights [ $r ][ 1 ] = 'Activer un service d\'un contrat' ;
$this -> rights [ $r ][ 2 ] = 'w' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'activer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 164 ;
$this -> rights [ $r ][ 1 ] = 'Desactiver un service d\'un contrat' ;
$this -> rights [ $r ][ 2 ] = 'w' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'desactiver' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 165 ;
$this -> rights [ $r ][ 1 ] = 'Supprimer un contrat' ;
$this -> rights [ $r ][ 2 ] = 'd' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'supprimer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 167 ;
$this -> rights [ $r ][ 1 ] = 'Export contracts' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'export' ;
2018-02-25 10:55:02 +01:00
2016-09-30 13:02:13 +02:00
// Menus
//-------
2020-04-10 10:59:32 +02:00
$this -> menu = 1 ; // This module add menu entries. They are coded into menu manager.
2018-02-25 10:55:02 +01:00
2014-09-02 10:45:53 +02:00
// Exports
//--------
2015-08-26 20:25:52 +02:00
$langs -> load ( " contracts " );
2020-04-10 10:59:32 +02:00
$r = 1 ;
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> export_label [ $r ] = 'ContractsAndLine' ; // Translation key (used only if key ExportDataset_xxx_z not found)
$this -> export_icon [ $r ] = 'contract' ;
$this -> export_permission [ $r ] = array ( array ( " contrat " , " export " ));
$this -> export_fields_array [ $r ] = array ( 's.rowid' => " IdCompany " , 's.nom' => 'CompanyName' , 's.address' => 'Address' , 's.zip' => 'Zip' , 's.town' => 'Town' , 'c.code' => 'CountryCode' ,
's.phone' => 'Phone' , 's.siren' => 'ProfId1' , 's.siret' => 'ProfId2' , 's.ape' => 'ProfId3' , 's.idprof4' => 'ProfId4' , 's.code_compta' => 'CustomerAccountancyCode' ,
's.code_compta_fournisseur' => 'SupplierAccountancyCode' , 's.tva_intra' => 'VATIntra' ,
'co.rowid' => " Id " , 'co.ref' => " Ref " , 'co.datec' => " DateCreation " , 'co.date_contrat' => " DateContract " ,
'co.fin_validite' => " ContractEndDate " , 'co.date_cloture' => " Closing " , 'co.note_private' => " NotePrivate " , 'co.note_public' => " NotePublic " ,
'cod.rowid' => 'LineId' , 'cod.label' => " LineLabel " , 'cod.description' => " LineDescription " , 'cod.price_ht' => " LineUnitPrice " , 'cod.tva_tx' => " LineVATRate " ,
'cod.qty' => " LineQty " , 'cod.total_ht' => " LineTotalHT " , 'cod.total_tva' => " LineTotalVAT " , 'cod.total_ttc' => " LineTotalTTC " ,
'cod.date_ouverture' => " DateStart " , 'cod.date_ouverture_prevue' => " DateStartPlanned " , 'cod.date_fin_validite' => " DateEndPlanned " , 'cod.date_cloture' => " DateEnd " ,
'p.rowid' => 'ProductId' , 'p.ref' => 'ProductRef' , 'p.label' => 'ProductLabel' );
$this -> export_entities_array [ $r ] = array ( 's.rowid' => " company " , 's.nom' => 'company' , 's.address' => 'company' , 's.zip' => 'company' ,
's.town' => 'company' , 'c.code' => 'company' , 's.phone' => 'company' , 's.siren' => 'company' , 's.siret' => 'company' , 's.ape' => 'company' ,
's.idprof4' => 'company' , 's.code_compta' => 'company' , 's.code_compta_fournisseur' => 'company' , 's.tva_intra' => 'company' ,
'co.rowid' => " contract " , 'co.ref' => " contract " , 'co.datec' => " contract " , 'co.date_contrat' => " contract " ,
'co.fin_validite' => " contract " , 'co.date_cloture' => " contract " , 'co.note_private' => " contract " , 'co.note_public' => " contract " ,
'cod.rowid' => 'contract_line' , 'cod.label' => " contract_line " , 'cod.description' => " contract_line " , 'cod.price_ht' => " contract_line " , 'cod.tva_tx' => " contract_line " ,
'cod.qty' => " contract_line " , 'cod.total_ht' => " contract_line " , 'cod.total_tva' => " contract_line " , 'cod.total_ttc' => " contract_line " ,
'cod.date_ouverture' => " contract_line " , 'cod.date_ouverture_prevue' => " contract_line " , 'cod.date_fin_validite' => " contract_line " , 'cod.date_cloture' => " contract_line " ,
'p.rowid' => 'product' , 'p.ref' => 'product' , 'p.label' => 'product' );
$this -> export_TypeFields_array [ $r ] = array ( 's.rowid' => " List:societe:nom " , 's.nom' => 'Text' , 's.address' => 'Text' , 's.zip' => 'Text' , 's.town' => 'Text' , 'c.code' => 'Text' ,
's.phone' => 'Text' , 's.siren' => 'Text' , 's.siret' => 'Text' , 's.ape' => 'Text' , 's.idprof4' => 'Text' , 's.code_compta' => 'Text' ,
's.code_compta_fournisseur' => 'Text' , 's.tva_intra' => 'Text' ,
'co.ref' => " Text " , 'co.datec' => " Date " , 'co.date_contrat' => " Date " ,
'co.fin_validite' => " Date " , 'co.date_cloture' => " Date " , 'co.note_private' => " Text " , 'co.note_public' => " Text " ,
'cod.label' => " Text " , 'cod.description' => " Text " , 'cod.price_ht' => " Numeric " , 'cod.tva_tx' => " Numeric " ,
'cod.qty' => " Numeric " , 'cod.total_ht' => " Numeric " , 'cod.total_tva' => " Numeric " , 'cod.total_ttc' => " Numeric " ,
'cod.date_ouverture' => " Date " , 'cod.date_ouverture_prevue' => " Date " , 'cod.date_fin_validite' => " Date " , 'cod.date_cloture' => " Date " ,
'p.rowid' => 'List:product:label' , 'p.ref' => 'Text' , 'p.label' => 'Text' );
$keyforselect = 'contrat' ; $keyforelement = 'contract' ; $keyforaliasextra = 'coextra' ;
2020-03-18 09:53:13 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2020-04-10 10:59:32 +02:00
$keyforselect = 'contratdet' ; $keyforelement = 'contract_line' ; $keyforaliasextra = 'codextra' ;
2020-03-18 09:53:13 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2020-04-10 10:59:32 +02:00
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'societe as s' ;
$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 ] .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'contrat as co ON co.fk_soc = s.rowid' ;
$this -> export_sql_end [ $r ] .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'contratdet as cod ON co.rowid = cod.fk_contrat' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p ON (cod.fk_product = p.rowid)' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'contrat_extrafields as coextra on (co.rowid = coextra.fk_object)' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'contratdet_extrafields as codextra on (cod.rowid = codextra.fk_object)' ;
$this -> export_sql_end [ $r ] .= ' WHERE co.entity IN (' . getEntity ( 'contract' ) . ')' ;
2009-05-04 13:40:00 +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
*
2020-10-31 14:32:18 +01:00
* @ param string $options Options when enabling module ( '' , 'noboxes' )
2012-01-04 21:23:50 +01:00
* @ return int 1 if OK , 0 if KO
2009-05-04 13:40:00 +02:00
*/
2019-02-26 21:13:07 +01:00
public function init ( $options = '' )
2009-05-04 13:40:00 +02:00
{
2020-06-09 14:22:32 +02:00
global $conf , $langs ;
2009-05-04 13:40:00 +02:00
2011-05-03 19:58:01 +02:00
// Nettoyage avant activation
2012-03-03 17:37:45 +01:00
$this -> remove ( $options );
2011-05-03 19:58:01 +02:00
2017-05-18 12:40:20 +02:00
//ODT template
2020-04-10 10:59:32 +02:00
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/contracts/template_contract.odt' ;
$dirodt = DOL_DATA_ROOT . '/doctemplates/contracts' ;
$dest = $dirodt . '/template_contract.odt' ;
2018-02-25 10:55:02 +01:00
2020-04-10 10:59:32 +02:00
if ( file_exists ( $src ) && ! file_exists ( $dest ))
2017-05-18 12:40:20 +02:00
{
2020-10-31 14:32:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
dol_mkdir ( $dirodt );
$result = dol_copy ( $src , $dest , 0 , 0 );
if ( $result < 0 )
{
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( 'ErrorFailToCopyFile' , $src , $dest );
return 0 ;
}
2017-05-18 12:40:20 +02:00
}
2018-02-25 10:55:02 +01:00
2017-05-18 12:40:20 +02:00
$sql = array (
2020-10-31 14:32:18 +01:00
" DELETE FROM " . MAIN_DB_PREFIX . " document_model WHERE nom = ' " . $this -> db -> escape ( $this -> const [ 1 ][ 2 ]) . " ' AND type = 'contract' AND entity = " . $conf -> entity ,
" INSERT INTO " . MAIN_DB_PREFIX . " document_model (nom, type, entity) VALUES(' " . $this -> db -> escape ( $this -> const [ 1 ][ 2 ]) . " ','contract', " . $conf -> entity . " ) "
2017-05-18 12:40:20 +02:00
);
2018-02-25 10:55:02 +01:00
2019-01-27 11:55:16 +01:00
return $this -> _init ( $sql , $options );
2009-05-04 13:40:00 +02:00
}
2004-05-01 02:50:27 +02:00
}