48 $this->family =
"crm";
49 $this->module_position =
'41';
51 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
52 $this->
description =
"Gestion des contrats de services";
55 $this->version =
'dolibarr';
57 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
58 $this->picto =
'contract';
61 $this->dirs = array(
"/contract/temp");
64 $this->depends = array(
"modSociete");
65 $this->requiredby = array();
68 $this->config_page_url = array(
"contract.php");
71 $this->
const = array();
74 $this->
const[$r][0] =
"CONTRACT_ADDON";
75 $this->
const[$r][1] =
"chaine";
76 $this->
const[$r][2] =
"mod_contract_serpis";
77 $this->
const[$r][3] =
'Nom du gestionnaire de numerotation des contrats';
78 $this->
const[$r][4] = 0;
81 $this->
const[$r][0] =
"CONTRACT_ADDON_PDF";
82 $this->
const[$r][1] =
"chaine";
83 $this->
const[$r][2] =
"strato";
84 $this->
const[$r][3] =
'Name of PDF model of contract';
85 $this->
const[$r][4] = 0;
88 $this->
const[$r][0] =
"CONTRACT_ADDON_PDF_ODT_PATH";
89 $this->
const[$r][1] =
"chaine";
90 $this->
const[$r][2] =
"DOL_DATA_ROOT/doctemplates/contracts";
91 $this->
const[$r][3] =
"";
92 $this->
const[$r][4] = 0;
97 0=>array(
'file'=>
'box_contracts.php',
'enabledbydefaulton'=>
'Home'),
98 1=>array(
'file'=>
'box_services_expired.php',
'enabledbydefaulton'=>
'Home')
102 $this->rights = array();
103 $this->rights_class =
'contrat';
107 $this->rights[$r][0] = 161;
108 $this->rights[$r][1] =
'Lire les contrats';
109 $this->rights[$r][2] =
'r';
110 $this->rights[$r][3] = 0;
111 $this->rights[$r][4] =
'lire';
114 $this->rights[$r][0] = 162;
115 $this->rights[$r][1] =
'Creer / modifier les contrats';
116 $this->rights[$r][2] =
'w';
117 $this->rights[$r][3] = 0;
118 $this->rights[$r][4] =
'creer';
121 $this->rights[$r][0] = 163;
122 $this->rights[$r][1] =
'Activer un service d\'un contrat';
123 $this->rights[$r][2] =
'w';
124 $this->rights[$r][3] = 0;
125 $this->rights[$r][4] =
'activer';
128 $this->rights[$r][0] = 164;
129 $this->rights[$r][1] =
'Desactiver un service d\'un contrat';
130 $this->rights[$r][2] =
'w';
131 $this->rights[$r][3] = 0;
132 $this->rights[$r][4] =
'desactiver';
135 $this->rights[$r][0] = 165;
136 $this->rights[$r][1] =
'Supprimer un contrat';
137 $this->rights[$r][2] =
'd';
138 $this->rights[$r][3] = 0;
139 $this->rights[$r][4] =
'supprimer';
142 $this->rights[$r][0] = 167;
143 $this->rights[$r][1] =
'Export contracts';
144 $this->rights[$r][2] =
'r';
145 $this->rights[$r][3] = 0;
146 $this->rights[$r][4] =
'export';
156 $langs->load(
"contracts");
160 $this->export_code[$r] = $this->rights_class.
'_'.$r;
161 $this->export_label[$r] =
'ContractsAndLine';
162 $this->export_icon[$r] =
'contract';
163 $this->export_permission[$r] = array(array(
"contrat",
"export"));
164 $this->export_fields_array[$r] = array(
's.rowid'=>
"IdCompany",
's.nom'=>
'CompanyName',
's.address'=>
'Address',
's.zip'=>
'Zip',
's.town'=>
'Town',
'c.code'=>
'CountryCode',
165 's.email'=>
'Email',
's.phone'=>
'Phone',
's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
's.code_compta'=>
'CustomerAccountancyCode',
166 's.code_compta_fournisseur'=>
'SupplierAccountancyCode',
's.tva_intra'=>
'VATIntra',
167 'co.rowid'=>
"Id",
'co.ref'=>
"Ref",
'co.datec'=>
"DateCreation",
'co.date_contrat'=>
"DateContract",
168 'co.fin_validite'=>
"ContractEndDate",
'co.date_cloture'=>
"DateClosing",
'co.note_private'=>
"NotePrivate",
'co.note_public'=>
"NotePublic",
169 'cod.rowid'=>
'LineId',
'cod.label'=>
"LineLabel",
'cod.description'=>
"LineDescription",
'cod.price_ht'=>
"LineUnitPrice",
'cod.tva_tx'=>
"LineVATRate",
170 'cod.qty'=>
"LineQty",
'cod.total_ht'=>
"LineTotalHT",
'cod.total_tva'=>
"LineTotalVAT",
'cod.total_ttc'=>
"LineTotalTTC",
171 'cod.date_ouverture'=>
"DateStart",
'cod.date_ouverture_prevue'=>
"DateStartPlanned",
'cod.date_fin_validite'=>
"DateEndPlanned",
'cod.date_cloture'=>
"DateEnd",
172 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel');
174 $this->export_entities_array[$r] = array(
's.rowid'=>
"company",
's.nom'=>
'company',
's.address'=>
'company',
's.zip'=>
'company',
175 's.town'=>
'company',
'c.code'=>
'company',
's.email'=>
'company',
's.phone'=>
'company',
's.siren'=>
'company',
's.siret'=>
'company',
's.ape'=>
'company',
176 's.idprof4'=>
'company',
's.code_compta'=>
'company',
's.code_compta_fournisseur'=>
'company',
's.tva_intra'=>
'company',
177 'co.rowid'=>
"contract",
'co.ref'=>
"contract",
'co.datec'=>
"contract",
'co.date_contrat'=>
"contract",
178 'co.fin_validite'=>
"contract",
'co.date_cloture'=>
"contract",
'co.note_private'=>
"contract",
'co.note_public'=>
"contract",
179 'cod.rowid'=>
'contract_line',
'cod.label'=>
"contract_line",
'cod.description'=>
"contract_line",
'cod.price_ht'=>
"contract_line",
'cod.tva_tx'=>
"contract_line",
180 'cod.qty'=>
"contract_line",
'cod.total_ht'=>
"contract_line",
'cod.total_tva'=>
"contract_line",
'cod.total_ttc'=>
"contract_line",
181 'cod.date_ouverture'=>
"contract_line",
'cod.date_ouverture_prevue'=>
"contract_line",
'cod.date_fin_validite'=>
"contract_line",
'cod.date_cloture'=>
"contract_line",
182 'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product');
184 $this->export_TypeFields_array[$r] = array(
's.rowid'=>
"Numeric",
's.nom'=>
'Text',
's.address'=>
'Text',
's.zip'=>
'Text',
's.town'=>
'Text',
'c.code'=>
'Text',
185 's.email'=>
'Text',
's.phone'=>
'Text',
's.siren'=>
'Text',
's.siret'=>
'Text',
's.ape'=>
'Text',
's.idprof4'=>
'Text',
's.code_compta'=>
'Text',
186 's.code_compta_fournisseur'=>
'Text',
's.tva_intra'=>
'Text',
187 'co.ref'=>
"Text",
'co.datec'=>
"Date",
'co.date_contrat'=>
"Date",
188 'co.fin_validite'=>
"Date",
'co.date_cloture'=>
"Date",
'co.note_private'=>
"Text",
'co.note_public'=>
"Text",
189 'cod.label'=>
"Text",
'cod.description'=>
"Text",
'cod.price_ht'=>
"Numeric",
'cod.tva_tx'=>
"Numeric",
190 'cod.qty'=>
"Numeric",
'cod.total_ht'=>
"Numeric",
'cod.total_tva'=>
"Numeric",
'cod.total_ttc'=>
"Numeric",
191 'cod.date_ouverture'=>
"Date",
'cod.date_ouverture_prevue'=>
"Date",
'cod.date_fin_validite'=>
"Date",
'cod.date_cloture'=>
"Date",
192 'p.rowid'=>
'List:product:label',
'p.ref'=>
'Text',
'p.label'=>
'Text');
195 $keyforselect =
'contrat';
196 $keyforelement =
'contract';
197 $keyforaliasextra =
'coextra';
198 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
199 $keyforselect =
'contratdet';
200 $keyforelement =
'contract_line';
201 $keyforaliasextra =
'codextra';
202 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
204 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
205 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s';
206 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c on s.fk_pays = c.rowid';
207 $this->export_sql_end[$r] .=
' INNER JOIN '.MAIN_DB_PREFIX.
'contrat as co ON co.fk_soc = s.rowid';
208 $this->export_sql_end[$r] .=
' INNER JOIN '.MAIN_DB_PREFIX.
'contratdet as cod ON co.rowid = cod.fk_contrat';
209 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (cod.fk_product = p.rowid)';
210 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'contrat_extrafields as coextra on (co.rowid = coextra.fk_object)';
211 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'contratdet_extrafields as codextra on (cod.rowid = codextra.fk_object)';
212 $this->export_sql_end[$r] .=
' WHERE co.entity IN ('.getEntity(
'contract').
')';
224 public function init($options =
'')
226 global $conf, $langs;
229 $this->
remove($options);
232 $src = DOL_DOCUMENT_ROOT.
'/install/doctemplates/contracts/template_contract.odt';
233 $dirodt = DOL_DATA_ROOT.
'/doctemplates/contracts';
234 $dest = $dirodt.
'/template_contract.odt';
236 if (file_exists($src) && !file_exists($dest)) {
237 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
239 $result =
dol_copy($src, $dest, 0, 0);
241 $langs->load(
"errors");
242 $this->error = $langs->trans(
'ErrorFailToCopyFile', $src, $dest);
248 "DELETE FROM ".MAIN_DB_PREFIX.
"document_model WHERE nom = '".$this->db->escape($this->const[1][2]).
"' AND type = 'contract' AND entity = ".((
int) $conf->entity),
249 "INSERT INTO ".MAIN_DB_PREFIX.
"document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2]).
"', 'contract', ".((
int) $conf->entity).
")"
252 return $this->
_init($sql, $options);