49 global
$conf, $user, $hookmanager;
54 $this->family =
"crm";
55 $this->module_position =
'10';
57 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
58 $this->
description =
"Management of quotes or commercial proposals";
63 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
64 $this->picto =
'propal';
67 $this->dirs = array(
"/propale/temp");
70 $this->hidden =
false;
71 $this->depends = array(
"modSociete");
72 $this->requiredby = array();
73 $this->conflictwith = array();
74 $this->phpmin = array(7, 0);
75 $this->config_page_url = array(
"propal.php");
76 $this->langfiles = array(
"propal",
"bills",
"companies",
"sendings",
"products");
79 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
85 'Name of the proposal generation manager in PDF format',
92 'Name of proposal numbering manager',
96 "PROPALE_VALIDITY_DURATION",
99 'Duration of validity of business proposals',
103 "PROPALE_ADDON_PDF_ODT_PATH",
105 "DOL_DATA_ROOT".($conf->entity > 1 ?
'/'.$conf->entity :
'').
"/doctemplates/proposals",
110 "PROPOSAL_ALLOW_ONLINESIGN",
117 "PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN",
125 "PROPOSAL_MAIL_FROM",
132 "PROPOSAL_EMAIL_TEMPLATE_REMIND_EXPIRATION",
133 "emailtemplate:propal",
134 "(SendingReminderForExpiringProposal)",
147 $this->boxes = array(
148 0 => array(
'file' =>
'box_graph_propales_permonth.php',
'enabledbydefaulton' =>
'Home'),
149 1 => array(
'file' =>
'box_propales.php',
'enabledbydefaulton' =>
'Home'),
154 $datestart =
dol_mktime(22, 0, 0, $arraydate[
'mon'], $arraydate[
'mday'], $arraydate[
'year']);
155 $this->cronjobs = array(
157 'label' =>
'SendReminderForExpiringProposalsTitle',
158 'jobtype' =>
'method',
'class' =>
'comm/propal/class/propal.class.php',
159 'objectname' =>
'Propal',
160 'method' =>
'sendReminderForExpiringProposals',
161 'parameters' =>
'10',
162 'comment' =>
'SendReminderForExpiringProposals',
164 'unitfrequency' => 3600 * 24,
167 'test' =>
'isModEnabled("propal")',
168 'datestart' => $datestart
173 $this->rights = array();
174 $this->rights_class =
'propale';
178 $this->rights[$r][0] = 21;
179 $this->rights[$r][1] =
'Read commercial proposals';
180 $this->rights[$r][2] =
'r';
181 $this->rights[$r][3] = 0;
182 $this->rights[$r][4] =
'lire';
185 $this->rights[$r][0] = 22;
186 $this->rights[$r][1] =
'Create and update commercial proposals';
187 $this->rights[$r][2] =
'w';
188 $this->rights[$r][3] = 0;
189 $this->rights[$r][4] =
'creer';
192 $this->rights[$r][0] = 24;
193 $this->rights[$r][1] =
'Validate commercial proposals';
194 $this->rights[$r][2] =
'd';
195 $this->rights[$r][3] = 0;
196 $this->rights[$r][4] =
'propal_advance';
197 $this->rights[$r][5] =
'validate';
200 $this->rights[$r][0] = 25;
201 $this->rights[$r][1] =
'Send commercial proposals to customers';
202 $this->rights[$r][2] =
'd';
203 $this->rights[$r][3] = 0;
204 $this->rights[$r][4] =
'propal_advance';
205 $this->rights[$r][5] =
'send';
208 $this->rights[$r][0] = 26;
209 $this->rights[$r][1] =
'Close commercial proposals';
210 $this->rights[$r][2] =
'd';
211 $this->rights[$r][3] = 0;
212 $this->rights[$r][4] =
'propal_advance';
213 $this->rights[$r][5] =
'close';
216 $this->rights[$r][0] = 27;
217 $this->rights[$r][1] =
'Delete commercial proposals';
218 $this->rights[$r][2] =
'd';
219 $this->rights[$r][3] = 0;
220 $this->rights[$r][4] =
'supprimer';
223 $this->rights[$r][0] = 28;
224 $this->rights[$r][1] =
'Exporting commercial proposals and attributes';
225 $this->rights[$r][2] =
'r';
226 $this->rights[$r][3] = 0;
227 $this->rights[$r][4] =
'export';
230 $this->rights[$r][0] = 29;
231 $this->rights[$r][1] =
'Reopen commercial proposals';
232 $this->rights[$r][2] =
'w';
233 $this->rights[$r][3] = 0;
234 $this->rights[$r][4] =
'propal_advance';
235 $this->rights[$r][5] =
'reopen';
247 $this->export_code[$r] = $this->rights_class.
'_'.$r;
248 $this->export_label[$r] =
'ProposalsAndProposalsLines';
249 $this->export_permission[$r] = array(array(
"propale",
"export"));
250 $this->export_fields_array[$r] = array(
251 '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',
252 's.siren' =>
'ProfId1',
's.siret' =>
'ProfId2',
's.ape' =>
'ProfId3',
's.idprof4' =>
'ProfId4',
'c.rowid' =>
"Id",
'c.ref' =>
"Ref",
'c.ref_client' =>
"RefCustomer",
253 'c.fk_soc' =>
"IdCompany",
'c.datec' =>
"DateCreation",
'c.datep' =>
"DatePropal",
'c.fin_validite' =>
"DateEndPropal",
254 'c.total_ht' =>
"TotalHT",
'c.total_ttc' =>
"TotalTTC",
255 'cir.label' =>
'Source',
258 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
259 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
260 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
261 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
262 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
264 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
265 'c.fk_statut' =>
'Status',
'c.note_public' =>
"NotePublic",
'c.note_private' =>
"NotePrivate",
'c.date_livraison' =>
'DeliveryDate',
266 'c.fk_user_author' =>
'CreatedById',
'uc.login' =>
'CreatedByLogin',
267 'c.fk_user_valid' =>
'ValidatedById',
'uv.login' =>
'ValidatedByLogin'));
269 $this->export_fields_array[$r][
'pj.ref'] =
'ProjectRef';
271 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
272 'cd.rowid' =>
'LineId',
'cd.description' =>
"LineDescription",
'cd.product_type' =>
'TypeOfLineServiceOrProduct',
273 'cd.tva_tx' =>
"LineVATRate",
'cd.qty' =>
"LineQty",
'cd.total_ht' =>
"LineTotalHT",
'cd.total_tva' =>
"LineTotalVAT",
'cd.total_ttc' =>
"LineTotalTTC",
275 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
276 'p.rowid' =>
'ProductId',
'p.ref' =>
'ProductRef',
'p.label' =>
'ProductLabel'
280 $nbofallowedentities = count(explode(
',',
getEntity(
'propal')));
281 if (
isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
282 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
292 $this->export_TypeFields_array[$r] = array(
293 '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',
294 's.ape' =>
'Text',
's.idprof4' =>
'Text',
'c.ref' =>
"Text",
'c.ref_client' =>
"Text",
'c.datec' =>
"Date",
'c.datep' =>
"Date",
'c.fin_validite' =>
"Date",
295 'c.total_ht' =>
"Numeric",
'c.total_ttc' =>
"Numeric",
'c.fk_statut' =>
'Status',
'c.note_public' =>
"Text",
'c.note_private' =>
"Text",
'c.date_livraison' =>
'Date',
296 'pj.ref' =>
'Text',
'cd.description' =>
"Text",
'cd.product_type' =>
'Boolean',
'cd.tva_tx' =>
"Numeric",
'cd.qty' =>
"Numeric",
'cd.total_ht' =>
"Numeric",
297 'cd.total_tva' =>
"Numeric",
'cd.total_ttc' =>
"Numeric",
'p.ref' =>
'Text',
'p.label' =>
'Text',
298 'c.entity' =>
'List:entity:label:rowid',
299 'cir.label' =>
'Text',
301 $this->export_entities_array[$r] = array(
302 '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',
303 's.siren' =>
'company',
's.ape' =>
'company',
's.idprof4' =>
'company',
's.siret' =>
'company',
'c.rowid' =>
"propal",
'c.ref' =>
"propal",
'c.ref_client' =>
"propal",
304 'c.fk_soc' =>
"propal",
'c.datec' =>
"propal",
'c.datep' =>
"propal",
'c.fin_validite' =>
"propal",
'c.total_ht' =>
"propal",
305 'c.total_ttc' =>
"propal",
'c.fk_statut' =>
"propal",
'c.note_public' =>
"propal",
'c.note_private' =>
"propal",
'c.date_livraison' =>
"propal",
306 'c.fk_user_author' =>
'user',
'uc.login' =>
'user',
307 'c.fk_user_valid' =>
'user',
'uv.login' =>
'user',
308 'pj.ref' =>
'project',
309 'cd.rowid' =>
'propal_line',
310 'cd.description' =>
"propal_line",
'cd.product_type' =>
'propal_line',
'cd.tva_tx' =>
"propal_line",
'cd.qty' =>
"propal_line",
311 'cd.total_ht' =>
"propal_line",
'cd.total_tva' =>
"propal_line",
'cd.total_ttc' =>
"propal_line",
'p.rowid' =>
'product',
'p.ref' =>
'product',
'p.label' =>
'product'
313 $this->export_dependencies_array[$r] = array(
'propal_line' =>
'cd.rowid',
'product' =>
'cd.rowid');
314 $keyforselect =
'propal';
315 $keyforelement =
'propal';
316 $keyforaliasextra =
'extra';
317 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
318 $keyforselect =
'propaldet';
319 $keyforelement =
'propal_line';
320 $keyforaliasextra =
'extra2';
321 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
322 $keyforselect =
'product';
323 $keyforelement =
'product';
324 $keyforaliasextra =
'extra3';
325 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
326 $keyforselect =
'societe';
327 $keyforelement =
'company';
328 $keyforaliasextra =
'extra4';
329 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
331 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
332 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s ';
333 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
334 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
335 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
336 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
338 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
339 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'propal as c';
340 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
341 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
342 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
343 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
344 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propal_extrafields as extra ON c.rowid = extra.fk_object';
345 $this->export_sql_end[$r] .=
', '.MAIN_DB_PREFIX.
'propaldet as cd';
346 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
347 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (cd.fk_product = p.rowid)';
348 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
349 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
350 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'propal').
')';
351 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
352 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
354 $parameters = array();
355 $hookmanager->executeHooks(
'printExportWhere', $parameters, $this);
356 $this->export_sql_end[$r] .= $hookmanager->resPrint;
363 $this->import_code[$r] = $this->rights_class.
'_'.$r;
364 $this->import_label[$r] =
'Proposals';
365 $this->import_icon[$r] = $this->picto;
366 $this->import_entities_array[$r] = array();
367 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'propal',
'extra' => MAIN_DB_PREFIX.
'propal_extrafields');
368 $this->import_tables_creator_array[$r] = array(
'c' =>
'fk_user_author');
369 $this->import_fields_array[$r] = array(
371 'c.ref_client' =>
'RefCustomer',
372 'c.fk_soc' =>
'ThirdPartyName*',
373 'c.datec' =>
'DateCreation',
374 'c.datep' =>
'DatePropal',
375 'c.fin_validite' =>
'DateEndPropal',
376 'c.total_ht' =>
'TotalHT',
377 'c.total_ttc' =>
'TotalTTC',
378 'c.fk_statut' =>
'Status*',
379 'c.note_public' =>
'NotePublic',
380 'c.note_private' =>
'NotePrivate',
381 'c.date_livraison' =>
'DeliveryDate',
382 'c.fk_user_valid' =>
'ValidatedById'
385 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
386 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
387 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
388 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
389 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
392 $import_extrafield_sample = array();
393 $keyforselect =
'propal';
394 $keyforelement =
'propal';
395 $keyforaliasextra =
'extra';
396 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinimport.inc.php';
397 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propal'];
398 $this->import_regex_array[$r] = [
'c.ref' =>
'[^ ]'];
400 'c.ref' =>
'PROV0077',
401 'c.ref_client' =>
'Client1',
402 'c.fk_soc' =>
'MyBigCompany',
403 'c.datec' =>
'2020-01-01',
404 'c.datep' =>
'2020-01-01',
405 'c.fin_validite' =>
'2020-01-01',
407 'c.total_ttc' =>
'0',
408 'c.fk_statut' =>
'1',
409 'c.note_public' =>
'',
410 'c.note_private' =>
'',
411 'c.date_livraison' =>
'2020-01-01',
412 'c.fk_user_valid' =>
'1',
413 'c.multicurrency_code' =>
'',
414 'c.multicurrency_tx' =>
'1',
415 'c.multicurrency_total_ht' =>
'0',
416 'c.multicurrency_total_tva' =>
'0',
417 'c.multicurrency_total_ttc' =>
'0'
419 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
420 $this->import_updatekeys_array[$r] = array(
'c.ref' =>
'Ref');
421 $this->import_convertvalue_array[$r] = array(
423 'rule' =>
'getrefifauto',
425 'path' =>
"/core/modules/propale/".(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' :
$conf->global->PROPALE_ADDON).
'.php',
426 'classobject' =>
'Propal',
427 'pathobject' =>
'/comm/propal/class/propal.class.php',
430 'rule' =>
'fetchidfromref',
431 'file' =>
'/societe/class/societe.class.php',
432 'class' =>
'Societe',
434 'element' =>
'ThirdParty'
440 $this->import_code[$r] = $this->rights_class.
'line_'.$r;
441 $this->import_label[$r] =
"ProposalLines";
442 $this->import_icon[$r] = $this->picto;
443 $this->import_entities_array[$r] = array();
444 $this->import_tables_array[$r] = array(
445 'cd' => MAIN_DB_PREFIX.
'propaldet',
446 'extra' => MAIN_DB_PREFIX.
'propaldet_extrafields'
448 $this->import_fields_array[$r] = array(
449 'cd.fk_propal' =>
'Proposal*',
450 'cd.fk_parent_line' =>
'ParentLine',
451 'cd.fk_product' =>
'IdProduct',
452 'cd.description' =>
'LineDescription',
453 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
454 'cd.tva_tx' =>
'LineVATRate',
455 'cd.qty' =>
'LineQty',
456 'cd.remise_percent' =>
'Reduc. Percent',
457 'cd.price' =>
'Price',
458 'cd.subprice' =>
'Sub Price',
459 'cd.total_ht' =>
'LineTotalHT',
460 'cd.total_tva' =>
'LineTotalVAT',
461 'cd.total_ttc' =>
'LineTotalTTC',
462 'cd.date_start' =>
'Start Date',
463 'cd.date_end' =>
'End Date',
464 'cd.buy_price_ht' =>
'LineBuyPriceHT'
467 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
468 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
469 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
470 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
471 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
474 $import_extrafield_sample = array();
475 $keyforselect =
'propaldet';
476 $keyforelement =
'propal';
477 $keyforaliasextra =
'extra';
478 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinimport.inc.php';
479 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propaldet');
480 $this->import_regex_array[$r] = array(
'cd.product_type' =>
'[0|1]$');
481 $import_sample = array(
482 'cd.fk_propal' =>
'PROV(0001)',
483 'cd.fk_parent_line' =>
'',
484 'cd.fk_product' =>
'',
485 'cd.description' =>
'Line description',
486 'cd.product_type' =>
'1',
489 'cd.remise_percent' =>
'0',
491 'cd.subprice' =>
'5000',
492 'cd.total_ht' =>
'10000',
493 'cd.total_tva' =>
'0',
494 'cd.total_ttc' =>
'10100',
495 'cd.date_start' =>
'',
497 'cd.buy_price_ht' =>
'7000',
498 'cd.multicurrency_code' =>
'JPY',
499 'cd.multicurrency_tx' =>
'1',
500 'cd.multicurrency_total_ht' =>
'10000',
501 'cd.multicurrency_total_tva' =>
'0',
502 'cd.multicurrency_total_ttc' =>
'10100'
504 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
505 $this->import_updatekeys_array[$r] = array(
'cd.fk_propal' =>
'Quotation Id',
'cd.fk_product' =>
'Product Id');
506 $this->import_convertvalue_array[$r] = array(
507 'cd.fk_propal' => array(
508 'rule' =>
'fetchidfromref',
509 'file' =>
'/comm/propal/class/propal.class.php',