31 include_once DOL_DOCUMENT_ROOT.
'/core/modules/DolibarrModules.class.php';
51 $this->family =
"crm";
52 $this->module_position =
'10';
54 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
55 $this->
description =
"Gestion des propositions commerciales";
58 $this->version =
'dolibarr';
60 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
61 $this->picto =
'propal';
64 $this->dirs = array(
"/propale/temp");
67 $this->hidden =
false;
68 $this->depends = array(
"modSociete");
69 $this->requiredby = array();
70 $this->conflictwith = array();
71 $this->phpmin = array(7, 0);
72 $this->config_page_url = array(
"propal.php");
73 $this->langfiles = array(
"propal",
"bills",
"companies",
"deliveries",
"products");
76 $this->
const = array();
79 $this->
const[$r][0] =
"PROPALE_ADDON_PDF";
80 $this->
const[$r][1] =
"chaine";
81 $this->
const[$r][2] =
"cyan";
82 $this->
const[$r][3] =
'Name of the proposal generation manager in PDF format';
83 $this->
const[$r][4] = 0;
86 $this->
const[$r][0] =
"PROPALE_ADDON";
87 $this->
const[$r][1] =
"chaine";
88 $this->
const[$r][2] =
"mod_propale_marbre";
89 $this->
const[$r][3] =
'Name of proposal numbering manager';
90 $this->
const[$r][4] = 0;
93 $this->
const[$r][0] =
"PROPALE_VALIDITY_DURATION";
94 $this->
const[$r][1] =
"chaine";
95 $this->
const[$r][2] =
"15";
96 $this->
const[$r][3] =
'Duration of validity of business proposals';
97 $this->
const[$r][4] = 0;
100 $this->
const[$r][0] =
"PROPALE_ADDON_PDF_ODT_PATH";
101 $this->
const[$r][1] =
"chaine";
102 $this->
const[$r][2] =
"DOL_DATA_ROOT/doctemplates/proposals";
103 $this->
const[$r][3] =
"";
104 $this->
const[$r][4] = 0;
114 $this->boxes = array(
115 0=>array(
'file'=>
'box_graph_propales_permonth.php',
'enabledbydefaulton'=>
'Home'),
116 1=>array(
'file'=>
'box_propales.php',
'enabledbydefaulton'=>
'Home'),
120 $this->rights = array();
121 $this->rights_class =
'propale';
125 $this->rights[$r][0] = 21;
126 $this->rights[$r][1] =
'Read commercial proposals';
127 $this->rights[$r][2] =
'r';
128 $this->rights[$r][3] = 0;
129 $this->rights[$r][4] =
'lire';
132 $this->rights[$r][0] = 22;
133 $this->rights[$r][1] =
'Create and update commercial proposals';
134 $this->rights[$r][2] =
'w';
135 $this->rights[$r][3] = 0;
136 $this->rights[$r][4] =
'creer';
139 $this->rights[$r][0] = 24;
140 $this->rights[$r][1] =
'Validate commercial proposals';
141 $this->rights[$r][2] =
'd';
142 $this->rights[$r][3] = 0;
143 $this->rights[$r][4] =
'propal_advance';
144 $this->rights[$r][5] =
'validate';
147 $this->rights[$r][0] = 25;
148 $this->rights[$r][1] =
'Send commercial proposals to customers';
149 $this->rights[$r][2] =
'd';
150 $this->rights[$r][3] = 0;
151 $this->rights[$r][4] =
'propal_advance';
152 $this->rights[$r][5] =
'send';
155 $this->rights[$r][0] = 26;
156 $this->rights[$r][1] =
'Close commercial proposals';
157 $this->rights[$r][2] =
'd';
158 $this->rights[$r][3] = 0;
159 $this->rights[$r][4] =
'propal_advance';
160 $this->rights[$r][5] =
'close';
163 $this->rights[$r][0] = 27;
164 $this->rights[$r][1] =
'Delete commercial proposals';
165 $this->rights[$r][2] =
'd';
166 $this->rights[$r][3] = 0;
167 $this->rights[$r][4] =
'supprimer';
170 $this->rights[$r][0] = 28;
171 $this->rights[$r][1] =
'Exporting commercial proposals and attributes';
172 $this->rights[$r][2] =
'r';
173 $this->rights[$r][3] = 0;
174 $this->rights[$r][4] =
'export';
187 $this->export_code[$r] = $this->rights_class.
'_'.$r;
188 $this->export_label[$r] =
'ProposalsAndProposalsLines';
189 $this->export_permission[$r] = array(array(
"propale",
"export"));
190 $this->export_fields_array[$r] = array(
191 's.rowid'=>
"IdCompany",
's.nom'=>
'CompanyName',
'ps.nom'=>
'ParentCompany',
's.address'=>
'Address',
's.zip'=>
'Zip',
's.town'=>
'Town',
'co.code'=>
'CountryCode',
's.phone'=>
'Phone',
192 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
'c.rowid'=>
"Id",
'c.ref'=>
"Ref",
'c.ref_client'=>
"RefCustomer",
193 'c.fk_soc'=>
"IdCompany",
'c.datec'=>
"DateCreation",
'c.datep'=>
"DatePropal",
'c.fin_validite'=>
"DateEndPropal",
194 'c.total_ht'=>
"TotalHT",
'c.total_ttc'=>
"TotalTTC",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Note",
'c.date_livraison'=>
'DeliveryDate',
195 'c.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
'c.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin',
196 'pj.ref'=>
'ProjectRef',
'cd.rowid'=>
'LineId',
'cd.description'=>
"LineDescription",
'cd.product_type'=>
'TypeOfLineServiceOrProduct',
197 'cd.tva_tx'=>
"LineVATRate",
'cd.qty'=>
"LineQty",
'cd.total_ht'=>
"LineTotalHT",
'cd.total_tva'=>
"LineTotalVAT",
'cd.total_ttc'=>
"LineTotalTTC",
198 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel'
201 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
202 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
203 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
204 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
205 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
208 if (!empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED)) {
209 $nbofallowedentities = count(explode(
',',
getEntity(
'propal')));
210 if (
isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
211 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
221 $this->export_TypeFields_array[$r] = array(
222 's.nom'=>
'Text',
'ps.nom'=>
'Text',
's.address'=>
'Text',
's.zip'=>
'Text',
's.town'=>
'Text',
'co.code'=>
'Text',
's.phone'=>
'Text',
's.siren'=>
'Text',
's.siret'=>
'Text',
223 's.ape'=>
'Text',
's.idprof4'=>
'Text',
'c.ref'=>
"Text",
'c.ref_client'=>
"Text",
'c.datec'=>
"Date",
'c.datep'=>
"Date",
'c.fin_validite'=>
"Date",
224 'c.total_ht'=>
"Numeric",
'c.total_ttc'=>
"Numeric",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Text",
'c.date_livraison'=>
'Date',
225 'pj.ref'=>
'Text',
'cd.description'=>
"Text",
'cd.product_type'=>
'Boolean',
'cd.tva_tx'=>
"Numeric",
'cd.qty'=>
"Numeric",
'cd.total_ht'=>
"Numeric",
226 'cd.total_tva'=>
"Numeric",
'cd.total_ttc'=>
"Numeric",
'p.ref'=>
'Text',
'p.label'=>
'Text',
227 'c.entity'=>
'List:entity:label:rowid',
229 $this->export_entities_array[$r] = array(
230 's.rowid'=>
"company",
's.nom'=>
'company',
'ps.nom'=>
'company',
's.address'=>
'company',
's.zip'=>
'company',
's.town'=>
'company',
'co.code'=>
'company',
's.phone'=>
'company',
231 's.siren'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.siret'=>
'company',
'c.rowid'=>
"propal",
'c.ref'=>
"propal",
'c.ref_client'=>
"propal",
232 'c.fk_soc'=>
"propal",
'c.datec'=>
"propal",
'c.datep'=>
"propal",
'c.fin_validite'=>
"propal",
'c.total_ht'=>
"propal",
233 'c.total_ttc'=>
"propal",
'c.fk_statut'=>
"propal",
'c.note_public'=>
"propal",
'c.date_livraison'=>
"propal",
'pj.ref'=>
'project',
'cd.rowid'=>
'propal_line',
234 'cd.description'=>
"propal_line",
'cd.product_type'=>
'propal_line',
'cd.tva_tx'=>
"propal_line",
'cd.qty'=>
"propal_line",
235 'cd.total_ht'=>
"propal_line",
'cd.total_tva'=>
"propal_line",
'cd.total_ttc'=>
"propal_line",
'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product'
237 $this->export_dependencies_array[$r] = array(
'propal_line'=>
'cd.rowid',
'product'=>
'cd.rowid');
238 $keyforselect =
'propal';
239 $keyforelement =
'propal';
240 $keyforaliasextra =
'extra';
241 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
242 $keyforselect =
'propaldet';
243 $keyforelement =
'propal_line';
244 $keyforaliasextra =
'extra2';
245 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
246 $keyforselect =
'product';
247 $keyforelement =
'product';
248 $keyforaliasextra =
'extra3';
249 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
250 $keyforselect =
'societe';
251 $keyforelement =
'company';
252 $keyforaliasextra =
'extra4';
253 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
255 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
256 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s ';
257 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
258 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
259 if (empty($user->rights->societe->client->voir)) {
260 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
262 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
263 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'propal as c';
264 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
265 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
266 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
267 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propal_extrafields as extra ON c.rowid = extra.fk_object';
268 $this->export_sql_end[$r] .=
', '.MAIN_DB_PREFIX.
'propaldet as cd';
269 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
270 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (cd.fk_product = p.rowid)';
271 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
272 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
273 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'propal').
')';
274 if (empty($user->rights->societe->client->voir)) {
275 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
283 $this->import_code[$r] = $this->rights_class.
'_'.$r;
284 $this->import_label[$r] =
'Proposals';
285 $this->import_icon[$r] = $this->picto;
286 $this->import_entities_array[$r] = array();
287 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'propal',
'extra' => MAIN_DB_PREFIX.
'propal_extrafields');
288 $this->import_tables_creator_array[$r] = array(
'c'=>
'fk_user_author');
289 $this->import_fields_array[$r] = array(
291 'c.ref_client' =>
'RefCustomer',
292 'c.fk_soc' =>
'ThirdPartyName*',
293 'c.datec' =>
'DateCreation',
294 'c.datep' =>
'DatePropal',
295 'c.fin_validite' =>
'DateEndPropal',
296 'c.total_ht' =>
'TotalHT',
297 'c.total_ttc' =>
'TotalTTC',
298 'c.fk_statut' =>
'Status*',
299 'c.note_public' =>
'Note',
300 'c.date_livraison' =>
'DeliveryDate',
301 'c.fk_user_valid' =>
'ValidatedById'
304 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
305 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
306 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
307 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
308 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
311 $import_extrafield_sample = array();
312 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, ".$conf->entity.
")";
315 while ($obj = $this->
db->fetch_object(
$resql)) {
316 $fieldname =
'extra.'.$obj->name;
317 $fieldlabel = ucfirst($obj->label);
318 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
319 $import_extrafield_sample[$fieldname] = $fieldlabel;
323 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propal'];
324 $this->import_regex_array[$r] = [
'c.ref' =>
'[^ ]'];
326 'c.ref' =>
'PROV0077',
327 'c.ref_client' =>
'Client1',
328 'c.fk_soc' =>
'MyBigCompany',
329 'c.datec' =>
'2020-01-01',
330 'c.datep' =>
'2020-01-01',
331 'c.fin_validite' =>
'2020-01-01',
333 'c.total_ttc' =>
'0',
334 'c.fk_statut' =>
'1',
335 'c.note_public' =>
'',
336 'c.date_livraison' =>
'2020-01-01',
337 'c.fk_user_valid' =>
'1',
338 'c.multicurrency_code' =>
'',
339 'c.multicurrency_tx' =>
'1',
340 'c.multicurrency_total_ht' =>
'0',
341 'c.multicurrency_total_tva' =>
'0',
342 'c.multicurrency_total_ttc' =>
'0'
344 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
345 $this->import_updatekeys_array[$r] = array(
'c.ref'=>
'Ref');
346 $this->import_convertvalue_array[$r] = array(
348 'rule'=>
'getrefifauto',
349 'class'=>(empty($conf->global->PROPALE_ADDON) ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON),
350 'path'=>
"/core/modules/propale/".(empty($conf->global->PROPALE_ADDON) ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON).
'.php',
351 'classobject'=>
'Propal',
352 'pathobject'=>
'/comm/propal/class/propal.class.php',
355 'rule' =>
'fetchidfromref',
356 'file' =>
'/societe/class/societe.class.php',
357 'class' =>
'Societe',
359 'element' =>
'ThirdParty'
365 $this->import_code[$r] = $this->rights_class.
'line_'.$r;
366 $this->import_label[$r] =
"ProposalLines";
367 $this->import_icon[$r] = $this->picto;
368 $this->import_entities_array[$r] = array();
369 $this->import_tables_array[$r] = array(
370 'cd' => MAIN_DB_PREFIX.
'propaldet',
371 'extra' => MAIN_DB_PREFIX.
'propaldet_extrafields'
373 $this->import_fields_array[$r] = array(
374 'cd.fk_propal' =>
'Proposal*',
375 'cd.fk_parent_line' =>
'ParentLine',
376 'cd.fk_product' =>
'IdProduct',
377 'cd.description' =>
'LineDescription',
378 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
379 'cd.tva_tx' =>
'LineVATRate',
380 'cd.qty' =>
'LineQty',
381 'cd.remise_percent' =>
'Reduc. Percent',
382 'cd.price' =>
'Price',
383 'cd.subprice' =>
'Sub Price',
384 'cd.total_ht' =>
'LineTotalHT',
385 'cd.total_tva' =>
'LineTotalVAT',
386 'cd.total_ttc' =>
'LineTotalTTC',
387 'cd.date_start' =>
'Start Date',
388 'cd.date_end' =>
'End Date',
389 'cd.buy_price_ht' =>
'LineBuyPriceHT'
392 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
393 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
394 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
395 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
396 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
399 $import_extrafield_sample = array();
400 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, ".$conf->entity.
")";
403 while ($obj = $this->
db->fetch_object(
$resql)) {
404 $fieldname =
'extra.'.$obj->name;
405 $fieldlabel = ucfirst($obj->label);
406 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
407 $import_extrafield_sample[$fieldname] = $fieldlabel;
411 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propaldet');
412 $this->import_regex_array[$r] = array(
'cd.product_type' =>
'[0|1]$');
413 $import_sample = array(
414 'cd.fk_propal' =>
'PROV(0001)',
415 'cd.fk_parent_line' =>
'',
416 'cd.fk_product' =>
'',
417 'cd.description' =>
'Line description',
418 'cd.product_type' =>
'1',
421 'cd.remise_percent' =>
'0',
423 'cd.subprice' =>
'5000',
424 'cd.total_ht' =>
'10000',
425 'cd.total_tva' =>
'0',
426 'cd.total_ttc' =>
'10100',
427 'cd.date_start' =>
'',
429 'cd.buy_price_ht' =>
'7000',
430 'cd.multicurrency_code' =>
'JPY',
431 'cd.multicurrency_tx' =>
'1',
432 'cd.multicurrency_total_ht' =>
'10000',
433 'cd.multicurrency_total_tva' =>
'0',
434 'cd.multicurrency_total_ttc' =>
'10100'
436 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
437 $this->import_updatekeys_array[$r] = array(
'cd.fk_propal' =>
'Quotation Id',
'cd.fk_product' =>
'Product Id');
438 $this->import_convertvalue_array[$r] = array(
439 'cd.fk_propal' => array(
440 'rule'=>
'fetchidfromref',
441 'file'=>
'/comm/propal/class/propal.class.php',
457 public function init($options =
'')
459 global $conf, $langs;
462 $this->
remove($options);
465 $src = DOL_DOCUMENT_ROOT.
'/install/doctemplates/proposals/template_proposal.odt';
466 $dirodt = DOL_DATA_ROOT.
'/doctemplates/proposals';
467 $dest = $dirodt.
'/template_proposal.odt';
469 if (file_exists($src) && !file_exists($dest)) {
470 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
472 $result =
dol_copy($src, $dest, 0, 0);
474 $langs->load(
"errors");
475 $this->error = $langs->trans(
'ErrorFailToCopyFile', $src, $dest);
481 "DELETE FROM ".MAIN_DB_PREFIX.
"document_model WHERE nom = '".$this->db->escape($this->const[0][2]).
"' AND type = 'propal' AND entity = ".((
int) $conf->entity),
482 "INSERT INTO ".MAIN_DB_PREFIX.
"document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2]).
"','propal',".((
int) $conf->entity).
")",
485 return $this->
_init($sql, $options);
_init($array_sql, $options='')
Enables a module.
Class to describe and enable module Propale.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.