47 global $conf, $user, $hookmanager;
52 $this->family =
"crm";
53 $this->module_position =
'10';
55 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
56 $this->
description =
"Gestion des propositions commerciales";
59 $this->version =
'dolibarr';
61 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
62 $this->picto =
'propal';
65 $this->dirs = array(
"/propale/temp");
68 $this->hidden =
false;
69 $this->depends = array(
"modSociete");
70 $this->requiredby = array();
71 $this->conflictwith = array();
72 $this->phpmin = array(7, 0);
73 $this->config_page_url = array(
"propal.php");
74 $this->langfiles = array(
"propal",
"bills",
"companies",
"sendings",
"products");
77 $this->
const = array();
80 $this->
const[$r][0] =
"PROPALE_ADDON_PDF";
81 $this->
const[$r][1] =
"chaine";
82 $this->
const[$r][2] =
"cyan";
83 $this->
const[$r][3] =
'Name of the proposal generation manager in PDF format';
84 $this->
const[$r][4] = 0;
87 $this->
const[$r][0] =
"PROPALE_ADDON";
88 $this->
const[$r][1] =
"chaine";
89 $this->
const[$r][2] =
"mod_propale_marbre";
90 $this->
const[$r][3] =
'Name of proposal numbering manager';
91 $this->
const[$r][4] = 0;
94 $this->
const[$r][0] =
"PROPALE_VALIDITY_DURATION";
95 $this->
const[$r][1] =
"chaine";
96 $this->
const[$r][2] =
"15";
97 $this->
const[$r][3] =
'Duration of validity of business proposals';
98 $this->
const[$r][4] = 0;
101 $this->
const[$r][0] =
"PROPALE_ADDON_PDF_ODT_PATH";
102 $this->
const[$r][1] =
"chaine";
103 $this->
const[$r][2] =
"DOL_DATA_ROOT".($conf->entity > 1 ?
'/'.$conf->entity :
'').
"/doctemplates/proposals";
104 $this->
const[$r][3] =
"";
105 $this->
const[$r][4] = 0;
108 $this->
const[$r][0] =
"PROPOSAL_ALLOW_ONLINESIGN";
109 $this->
const[$r][1] =
"chaine";
110 $this->
const[$r][2] =
"1";
111 $this->
const[$r][3] =
"";
112 $this->
const[$r][4] = 0;
115 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
116 $this->
const[$r][0] =
"PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN";
117 $this->
const[$r][1] =
"chaine";
119 $this->
const[$r][3] =
"";
120 $this->
const[$r][4] = 0;
132 $this->boxes = array(
133 0=>array(
'file'=>
'box_graph_propales_permonth.php',
'enabledbydefaulton'=>
'Home'),
134 1=>array(
'file'=>
'box_propales.php',
'enabledbydefaulton'=>
'Home'),
138 $this->rights = array();
139 $this->rights_class =
'propale';
143 $this->rights[$r][0] = 21;
144 $this->rights[$r][1] =
'Read commercial proposals';
145 $this->rights[$r][2] =
'r';
146 $this->rights[$r][3] = 0;
147 $this->rights[$r][4] =
'lire';
150 $this->rights[$r][0] = 22;
151 $this->rights[$r][1] =
'Create and update commercial proposals';
152 $this->rights[$r][2] =
'w';
153 $this->rights[$r][3] = 0;
154 $this->rights[$r][4] =
'creer';
157 $this->rights[$r][0] = 24;
158 $this->rights[$r][1] =
'Validate commercial proposals';
159 $this->rights[$r][2] =
'd';
160 $this->rights[$r][3] = 0;
161 $this->rights[$r][4] =
'propal_advance';
162 $this->rights[$r][5] =
'validate';
165 $this->rights[$r][0] = 25;
166 $this->rights[$r][1] =
'Send commercial proposals to customers';
167 $this->rights[$r][2] =
'd';
168 $this->rights[$r][3] = 0;
169 $this->rights[$r][4] =
'propal_advance';
170 $this->rights[$r][5] =
'send';
173 $this->rights[$r][0] = 26;
174 $this->rights[$r][1] =
'Close commercial proposals';
175 $this->rights[$r][2] =
'd';
176 $this->rights[$r][3] = 0;
177 $this->rights[$r][4] =
'propal_advance';
178 $this->rights[$r][5] =
'close';
181 $this->rights[$r][0] = 27;
182 $this->rights[$r][1] =
'Delete commercial proposals';
183 $this->rights[$r][2] =
'd';
184 $this->rights[$r][3] = 0;
185 $this->rights[$r][4] =
'supprimer';
188 $this->rights[$r][0] = 28;
189 $this->rights[$r][1] =
'Exporting commercial proposals and attributes';
190 $this->rights[$r][2] =
'r';
191 $this->rights[$r][3] = 0;
192 $this->rights[$r][4] =
'export';
195 $this->rights[$r][0] = 29;
196 $this->rights[$r][1] =
'Reopen commercial proposals';
197 $this->rights[$r][2] =
'w';
198 $this->rights[$r][3] = 0;
199 $this->rights[$r][4] =
'propal_advance';
200 $this->rights[$r][5] =
'reopen';
212 $this->export_code[$r] = $this->rights_class.
'_'.$r;
213 $this->export_label[$r] =
'ProposalsAndProposalsLines';
214 $this->export_permission[$r] = array(array(
"propale",
"export"));
215 $this->export_fields_array[$r] = array(
216 's.rowid'=>
"IdCompany",
's.nom'=>
'CompanyName',
'ps.nom'=>
'ParentCompany',
's.code_client'=>
'CustomerCode',
's.address'=>
'Address',
's.zip'=>
'Zip',
's.town'=>
'Town',
'co.code'=>
'CountryCode',
's.phone'=>
'Phone',
217 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
'c.rowid'=>
"Id",
'c.ref'=>
"Ref",
'c.ref_client'=>
"RefCustomer",
218 'c.fk_soc'=>
"IdCompany",
'c.datec'=>
"DateCreation",
'c.datep'=>
"DatePropal",
'c.fin_validite'=>
"DateEndPropal",
219 'c.total_ht'=>
"TotalHT",
'c.total_ttc'=>
"TotalTTC",
220 'cir.label'=>
'Source',
223 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
224 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
225 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
226 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
227 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
229 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
230 'c.fk_statut'=>
'Status',
'c.note_public'=>
"NotePublic",
'c.note_private'=>
"NotePrivate",
'c.date_livraison'=>
'DeliveryDate',
231 'c.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
232 'c.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin'));
234 $this->export_fields_array[$r][
'pj.ref'] =
'ProjectRef';
236 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
237 'cd.rowid'=>
'LineId',
'cd.description'=>
"LineDescription",
'cd.product_type'=>
'TypeOfLineServiceOrProduct',
238 'cd.tva_tx'=>
"LineVATRate",
'cd.qty'=>
"LineQty",
'cd.total_ht'=>
"LineTotalHT",
'cd.total_tva'=>
"LineTotalVAT",
'cd.total_ttc'=>
"LineTotalTTC",
240 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
241 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel'
245 $nbofallowedentities = count(explode(
',',
getEntity(
'propal')));
246 if (
isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
247 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
257 $this->export_TypeFields_array[$r] = array(
258 's.nom'=>
'Text',
'ps.nom'=>
'Text',
's.code_client'=>
'Text',
's.address'=>
'Text',
's.zip'=>
'Text',
's.town'=>
'Text',
'co.code'=>
'Text',
's.phone'=>
'Text',
's.siren'=>
'Text',
's.siret'=>
'Text',
259 's.ape'=>
'Text',
's.idprof4'=>
'Text',
'c.ref'=>
"Text",
'c.ref_client'=>
"Text",
'c.datec'=>
"Date",
'c.datep'=>
"Date",
'c.fin_validite'=>
"Date",
260 'c.total_ht'=>
"Numeric",
'c.total_ttc'=>
"Numeric",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Text",
'c.note_private'=>
"Text",
'c.date_livraison'=>
'Date',
261 'pj.ref'=>
'Text',
'cd.description'=>
"Text",
'cd.product_type'=>
'Boolean',
'cd.tva_tx'=>
"Numeric",
'cd.qty'=>
"Numeric",
'cd.total_ht'=>
"Numeric",
262 'cd.total_tva'=>
"Numeric",
'cd.total_ttc'=>
"Numeric",
'p.ref'=>
'Text',
'p.label'=>
'Text',
263 'c.entity'=>
'List:entity:label:rowid',
266 $this->export_entities_array[$r] = array(
267 's.rowid'=>
"company",
's.nom'=>
'company',
'ps.nom'=>
'company',
's.code_client'=>
'company',
's.address'=>
'company',
's.zip'=>
'company',
's.town'=>
'company',
'co.code'=>
'company',
's.phone'=>
'company',
268 's.siren'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.siret'=>
'company',
'c.rowid'=>
"propal",
'c.ref'=>
"propal",
'c.ref_client'=>
"propal",
269 'c.fk_soc'=>
"propal",
'c.datec'=>
"propal",
'c.datep'=>
"propal",
'c.fin_validite'=>
"propal",
'c.total_ht'=>
"propal",
270 'c.total_ttc'=>
"propal",
'c.fk_statut'=>
"propal",
'c.note_public'=>
"propal",
'c.note_private'=>
"propal",
'c.date_livraison'=>
"propal",
271 'c.fk_user_author'=>
'user',
'uc.login'=>
'user',
272 'c.fk_user_valid'=>
'user',
'uv.login'=>
'user',
274 'cd.rowid'=>
'propal_line',
275 'cd.description'=>
"propal_line",
'cd.product_type'=>
'propal_line',
'cd.tva_tx'=>
"propal_line",
'cd.qty'=>
"propal_line",
276 'cd.total_ht'=>
"propal_line",
'cd.total_tva'=>
"propal_line",
'cd.total_ttc'=>
"propal_line",
'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product'
278 $this->export_dependencies_array[$r] = array(
'propal_line'=>
'cd.rowid',
'product'=>
'cd.rowid');
279 $keyforselect =
'propal';
280 $keyforelement =
'propal';
281 $keyforaliasextra =
'extra';
282 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
283 $keyforselect =
'propaldet';
284 $keyforelement =
'propal_line';
285 $keyforaliasextra =
'extra2';
286 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
287 $keyforselect =
'product';
288 $keyforelement =
'product';
289 $keyforaliasextra =
'extra3';
290 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
291 $keyforselect =
'societe';
292 $keyforelement =
'company';
293 $keyforaliasextra =
'extra4';
294 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
296 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
297 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s ';
298 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
299 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
300 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
301 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
303 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
304 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'propal as c';
305 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
306 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
307 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
308 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
309 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propal_extrafields as extra ON c.rowid = extra.fk_object';
310 $this->export_sql_end[$r] .=
', '.MAIN_DB_PREFIX.
'propaldet as cd';
311 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
312 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (cd.fk_product = p.rowid)';
313 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
314 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
315 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'propal').
')';
316 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
317 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
319 $parameters = array();
320 $hookmanager->executeHooks(
'printExportWhere', $parameters, $this);
321 $this->export_sql_end[$r] .= $hookmanager->resPrint;
328 $this->import_code[$r] = $this->rights_class.
'_'.$r;
329 $this->import_label[$r] =
'Proposals';
330 $this->import_icon[$r] = $this->picto;
331 $this->import_entities_array[$r] = array();
332 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'propal',
'extra' => MAIN_DB_PREFIX.
'propal_extrafields');
333 $this->import_tables_creator_array[$r] = array(
'c'=>
'fk_user_author');
334 $this->import_fields_array[$r] = array(
336 'c.ref_client' =>
'RefCustomer',
337 'c.fk_soc' =>
'ThirdPartyName*',
338 'c.datec' =>
'DateCreation',
339 'c.datep' =>
'DatePropal',
340 'c.fin_validite' =>
'DateEndPropal',
341 'c.total_ht' =>
'TotalHT',
342 'c.total_ttc' =>
'TotalTTC',
343 'c.fk_statut' =>
'Status*',
344 'c.note_public' =>
'NotePublic',
345 'c.note_private' =>
'NotePrivate',
346 'c.date_livraison' =>
'DeliveryDate',
347 'c.fk_user_valid' =>
'ValidatedById'
350 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
351 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
352 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
353 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
354 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
357 $import_extrafield_sample = array();
358 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, ".$conf->entity.
")";
359 $resql = $this->db->query($sql);
361 while ($obj = $this->db->fetch_object($resql)) {
362 $fieldname =
'extra.'.$obj->name;
363 $fieldlabel = ucfirst($obj->label);
364 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
365 $import_extrafield_sample[$fieldname] = $fieldlabel;
369 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propal'];
370 $this->import_regex_array[$r] = [
'c.ref' =>
'[^ ]'];
372 'c.ref' =>
'PROV0077',
373 'c.ref_client' =>
'Client1',
374 'c.fk_soc' =>
'MyBigCompany',
375 'c.datec' =>
'2020-01-01',
376 'c.datep' =>
'2020-01-01',
377 'c.fin_validite' =>
'2020-01-01',
379 'c.total_ttc' =>
'0',
380 'c.fk_statut' =>
'1',
381 'c.note_public' =>
'',
382 'c.note_private' =>
'',
383 'c.date_livraison' =>
'2020-01-01',
384 'c.fk_user_valid' =>
'1',
385 'c.multicurrency_code' =>
'',
386 'c.multicurrency_tx' =>
'1',
387 'c.multicurrency_total_ht' =>
'0',
388 'c.multicurrency_total_tva' =>
'0',
389 'c.multicurrency_total_ttc' =>
'0'
391 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
392 $this->import_updatekeys_array[$r] = array(
'c.ref'=>
'Ref');
393 $this->import_convertvalue_array[$r] = array(
395 'rule'=>
'getrefifauto',
396 'class'=>(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON),
397 'path'=>
"/core/modules/propale/".(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON).
'.php',
398 'classobject'=>
'Propal',
399 'pathobject'=>
'/comm/propal/class/propal.class.php',
402 'rule' =>
'fetchidfromref',
403 'file' =>
'/societe/class/societe.class.php',
404 'class' =>
'Societe',
406 'element' =>
'ThirdParty'
412 $this->import_code[$r] = $this->rights_class.
'line_'.$r;
413 $this->import_label[$r] =
"ProposalLines";
414 $this->import_icon[$r] = $this->picto;
415 $this->import_entities_array[$r] = array();
416 $this->import_tables_array[$r] = array(
417 'cd' => MAIN_DB_PREFIX.
'propaldet',
418 'extra' => MAIN_DB_PREFIX.
'propaldet_extrafields'
420 $this->import_fields_array[$r] = array(
421 'cd.fk_propal' =>
'Proposal*',
422 'cd.fk_parent_line' =>
'ParentLine',
423 'cd.fk_product' =>
'IdProduct',
424 'cd.description' =>
'LineDescription',
425 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
426 'cd.tva_tx' =>
'LineVATRate',
427 'cd.qty' =>
'LineQty',
428 'cd.remise_percent' =>
'Reduc. Percent',
429 'cd.price' =>
'Price',
430 'cd.subprice' =>
'Sub Price',
431 'cd.total_ht' =>
'LineTotalHT',
432 'cd.total_tva' =>
'LineTotalVAT',
433 'cd.total_ttc' =>
'LineTotalTTC',
434 'cd.date_start' =>
'Start Date',
435 'cd.date_end' =>
'End Date',
436 'cd.buy_price_ht' =>
'LineBuyPriceHT'
439 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
440 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
441 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
442 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
443 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
446 $import_extrafield_sample = array();
447 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, ".$conf->entity.
")";
448 $resql = $this->db->query($sql);
450 while ($obj = $this->db->fetch_object($resql)) {
451 $fieldname =
'extra.'.$obj->name;
452 $fieldlabel = ucfirst($obj->label);
453 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
454 $import_extrafield_sample[$fieldname] = $fieldlabel;
458 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propaldet');
459 $this->import_regex_array[$r] = array(
'cd.product_type' =>
'[0|1]$');
460 $import_sample = array(
461 'cd.fk_propal' =>
'PROV(0001)',
462 'cd.fk_parent_line' =>
'',
463 'cd.fk_product' =>
'',
464 'cd.description' =>
'Line description',
465 'cd.product_type' =>
'1',
468 'cd.remise_percent' =>
'0',
470 'cd.subprice' =>
'5000',
471 'cd.total_ht' =>
'10000',
472 'cd.total_tva' =>
'0',
473 'cd.total_ttc' =>
'10100',
474 'cd.date_start' =>
'',
476 'cd.buy_price_ht' =>
'7000',
477 'cd.multicurrency_code' =>
'JPY',
478 'cd.multicurrency_tx' =>
'1',
479 'cd.multicurrency_total_ht' =>
'10000',
480 'cd.multicurrency_total_tva' =>
'0',
481 'cd.multicurrency_total_ttc' =>
'10100'
483 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
484 $this->import_updatekeys_array[$r] = array(
'cd.fk_propal' =>
'Quotation Id',
'cd.fk_product' =>
'Product Id');
485 $this->import_convertvalue_array[$r] = array(
486 'cd.fk_propal' => array(
487 'rule'=>
'fetchidfromref',
488 'file'=>
'/comm/propal/class/propal.class.php',