2004-10-19 22:24:10 +00:00
< ? php
2005-07-30 23:22:07 +00:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2014-10-11 23:59:21 +00:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 14:13:49 +00:00
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis . houssin @ capnetworks . com >
2011-02-18 17:12:22 +00:00
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
2004-05-01 00:50:27 +00: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 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2004-05-01 00:50:27 +00: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-07-31 23:24:38 +00:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2004-05-01 00:50:27 +00:00
*/
2005-06-11 11:35:12 +00:00
/**
2009-07-29 22:52:08 +00:00
* \defgroup contrat Module contract
* \brief Module pour gerer la tenue de contrat de services
2011-10-24 12:11:49 +00:00
* \file htdocs / core / modules / modContrat . class . php
2009-07-29 22:52:08 +00:00
* \ingroup contrat
* \brief Fichier de description et activation du module Contrat
2009-05-04 11:40:00 +00:00
*/
2004-08-14 12:21:24 +00:00
2012-08-23 00:04:35 +00:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2004-05-01 00:50:27 +00:00
2005-08-14 18:19:30 +00:00
/**
2015-09-07 13:55:26 +00:00
* Class to describe and enable module Contrat
2009-05-04 11:40:00 +00:00
*/
2004-05-01 00:50:27 +00:00
class modContrat extends DolibarrModules
{
2009-05-04 11:40:00 +00:00
/**
2011-09-26 14:22:35 +00:00
* Constructor . Define names , constants , directories , boxes , permissions
*
2012-01-04 20:23:50 +00:00
* @ param DoliDB $db Database handler
2009-05-04 11:40:00 +00:00
*/
2012-07-30 15:17:33 +00:00
function __construct ( $db )
2009-05-04 11:40:00 +00:00
{
2015-08-26 18:25:52 +00:00
global $conf , $langs ;
2015-02-22 12:16:49 +00:00
2012-01-04 20:23:50 +00:00
$this -> db = $db ;
$this -> numero = 54 ;
2005-08-14 18:19:30 +00:00
2009-05-04 11:40:00 +00:00
$this -> family = " crm " ;
2008-10-01 19:10:17 +00: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 13:09:42 +00:00
$this -> name = preg_replace ( '/^mod/i' , '' , get_class ( $this ));
2009-05-04 11:40:00 +00:00
$this -> description = " Gestion des contrats de services " ;
2005-08-14 18:19:30 +00:00
2008-12-15 22:25:59 +00:00
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this -> version = 'dolibarr' ;
2009-05-04 11:40:00 +00:00
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
$this -> special = 0 ;
$this -> picto = 'contract' ;
// Data directories to create when module is enabled
2013-08-26 12:29:46 +00:00
$this -> dirs = array ( " /contract/temp " );
2009-05-04 11:40:00 +00:00
2015-09-07 13:29:51 +00:00
// Dependencies
2014-07-19 20:05:35 +00:00
$this -> depends = array ( " modSociete " );
2009-05-04 11:40:00 +00:00
$this -> requiredby = array ();
2011-05-03 17:58:01 +00:00
2011-02-18 17:12:22 +00:00
// Config pages
$this -> config_page_url = array ( " contract.php " );
2009-05-04 11:40:00 +00:00
2015-09-07 13:40:55 +00:00
// Constants
2009-05-04 11:40:00 +00:00
$this -> const = array ();
2017-05-18 10:40:20 +00:00
$r = 0 ;
$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 ++ ;
$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 ++ ;
$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 ++ ;
2010-04-19 06:43:15 +00:00
// Boxes
2014-05-01 17:17:45 +00:00
$this -> boxes = array (
0 => array ( 'file' => 'box_contracts.php' , 'enabledbydefaulton' => 'Home' ),
1 => array ( 'file' => 'box_services_expired.php' , 'enabledbydefaulton' => 'Home' )
);
2009-05-04 11:40:00 +00:00
// Permissions
$this -> rights = array ();
$this -> rights_class = 'contrat' ;
2015-05-10 21:37:04 +00:00
$r = 0 ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 161 ;
$this -> rights [ $r ][ 1 ] = 'Lire les contrats' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
2016-06-04 10:16:30 +00:00
$this -> rights [ $r ][ 3 ] = 0 ;
2015-05-10 21:37:04 +00: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' ;
2016-09-30 11:02:13 +00:00
// Menus
//-------
$this -> menu = 1 ; // This module add menu entries. They are coded into menu manager.
2014-09-02 08:45:53 +00:00
// Exports
//--------
2015-08-26 18:25:52 +00:00
$langs -> load ( " contracts " );
2014-09-02 08:45:53 +00:00
$r = 1 ;
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
2015-05-07 11:35:09 +00:00
$this -> export_label [ $r ] = 'ContractsAndLine' ; // Translation key (used only if key ExportDataset_xxx_z not found)
2014-09-02 08:45:53 +00:00
$this -> export_icon [ $r ] = 'contract' ;
$this -> export_permission [ $r ] = array ( array ( " contrat " , " export " ));
2014-10-11 23:59:21 +00:00
$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' ,
2014-09-02 08:45:53 +00:00
's.code_compta_fournisseur' => 'SupplierAccountancyCode' , 's.tva_intra' => 'VATIntra' ,
2015-08-26 19:01:01 +00:00
'co.rowid' => " Id " , 'co.ref' => " Ref " , 'co.datec' => " DateCreation " , 'co.date_contrat' => " DateContract " , 'co.mise_en_service' => " ContractStartDate " ,
'co.fin_validite' => " ContractEndDate " , 'co.date_cloture' => " Closing " , 'co.note_private' => " NotePrivate " , 'co.note_public' => " NotePublic " ,
2014-09-02 08:45:53 +00:00
'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 " ,
2015-08-26 19:01:01 +00:00
'cod.date_ouverture' => " DateStart " , 'cod.date_ouverture_prevue' => " DateStartPlanned " , 'cod.date_fin_validite' => " DateEndPlanned " , 'cod.date_cloture' => " DateEnd " ,
2014-09-02 08:45:53 +00:00
'p.rowid' => 'ProductId' , 'p.ref' => 'ProductRef' , 'p.label' => 'ProductLabel' );
2014-10-11 23:59:21 +00:00
$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' ,
2014-09-02 08:45:53 +00:00
's.idprof4' => 'company' , 's.code_compta' => 'company' , 's.code_compta_fournisseur' => 'company' , 's.tva_intra' => 'company' ,
2015-08-25 19:59:46 +00:00
'co.rowid' => " contract " , 'co.ref' => " contract " , 'co.datec' => " contract " , 'co.date_contrat' => " contract " , 'co.mise_en_service' => " contract " ,
'co.fin_validite' => " contract " , 'co.date_cloture' => " contract " , 'co.note_private' => " contract " , 'co.note_public' => " contract " ,
2014-09-02 08:45:53 +00:00
'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' );
2014-10-11 23:59:21 +00:00
$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' ,
2014-09-02 08:45:53 +00:00
's.code_compta_fournisseur' => 'Text' , 's.tva_intra' => 'Text' ,
'co.ref' => " Text " , 'co.datec' => " Date " , 'co.date_contrat' => " Date " , 'co.mise_en_service' => " Date " ,
2014-10-11 23:59:21 +00:00
'co.fin_validite' => " Date " , 'co.date_cloture' => " Date " , 'co.note_private' => " Text " , 'co.note_public' => " Text " ,
2014-09-02 08:45:53 +00:00
'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 " ,
2015-05-05 10:39:27 +00:00
'p.rowid' => 'List:product:label' , 'p.ref' => 'Text' , 'p.label' => 'Text' );
2014-09-02 08:45:53 +00:00
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'societe as s' ;
2014-10-11 23:59:21 +00:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as c on s.fk_pays = c.rowid,' ;
2014-09-02 08:45:53 +00:00
$this -> export_sql_end [ $r ] .= ' ' . MAIN_DB_PREFIX . 'contrat as co,' ;
$this -> export_sql_end [ $r ] .= ' ' . MAIN_DB_PREFIX . 'contratdet as cod' ;
2015-02-22 12:16:49 +00:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p on (cod.fk_product = p.rowid)' ;
2014-09-02 08:45:53 +00:00
$this -> export_sql_end [ $r ] .= ' WHERE co.fk_soc = s.rowid and co.rowid = cod.fk_contrat' ;
2017-05-30 16:50:54 +00:00
$this -> export_sql_end [ $r ] .= ' AND co.entity IN (' . getEntity ( 'contract' ) . ')' ;
2009-05-04 11:40:00 +00:00
}
/**
2012-01-04 20:23:50 +00: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
*
* @ param string $options Options when enabling module ( '' , 'noboxes' )
* @ return int 1 if OK , 0 if KO
2009-05-04 11:40:00 +00:00
*/
2012-01-04 20:23:50 +00:00
function init ( $options = '' )
2009-05-04 11:40:00 +00:00
{
global $conf ;
2011-05-03 17:58:01 +00:00
// Nettoyage avant activation
2012-03-03 16:37:45 +00:00
$this -> remove ( $options );
2011-05-03 17:58:01 +00:00
2017-05-18 10:40:20 +00:00
//ODT template
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/contracts/template_contract.odt' ;
$dirodt = DOL_DATA_ROOT . '/doctemplates/contracts' ;
$dest = $dirodt . '/template_contract.odt' ;
if ( file_exists ( $src ) && ! file_exists ( $dest ))
{
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 ;
}
}
$sql = array (
" 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 . " ) "
);
2012-01-04 20:23:50 +00:00
return $this -> _init ( $sql , $options );
2009-05-04 11:40:00 +00:00
}
2004-05-01 00:50:27 +00:00
}