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 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
83 'Name of the proposal generation manager in PDF format',
90 'Name of proposal numbering manager',
94 "PROPALE_VALIDITY_DURATION",
97 'Duration of validity of business proposals',
101 "PROPALE_ADDON_PDF_ODT_PATH",
103 "DOL_DATA_ROOT".($conf->entity > 1 ?
'/'.$conf->entity :
'').
"/doctemplates/proposals",
108 "PROPOSAL_ALLOW_ONLINESIGN",
115 "PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN",
130 $this->boxes = array(
131 0=>array(
'file'=>
'box_graph_propales_permonth.php',
'enabledbydefaulton'=>
'Home'),
132 1=>array(
'file'=>
'box_propales.php',
'enabledbydefaulton'=>
'Home'),
136 $this->rights = array();
137 $this->rights_class =
'propale';
141 $this->rights[$r][0] = 21;
142 $this->rights[$r][1] =
'Read commercial proposals';
143 $this->rights[$r][2] =
'r';
144 $this->rights[$r][3] = 0;
145 $this->rights[$r][4] =
'lire';
148 $this->rights[$r][0] = 22;
149 $this->rights[$r][1] =
'Create and update commercial proposals';
150 $this->rights[$r][2] =
'w';
151 $this->rights[$r][3] = 0;
152 $this->rights[$r][4] =
'creer';
155 $this->rights[$r][0] = 24;
156 $this->rights[$r][1] =
'Validate 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] =
'validate';
163 $this->rights[$r][0] = 25;
164 $this->rights[$r][1] =
'Send commercial proposals to customers';
165 $this->rights[$r][2] =
'd';
166 $this->rights[$r][3] = 0;
167 $this->rights[$r][4] =
'propal_advance';
168 $this->rights[$r][5] =
'send';
171 $this->rights[$r][0] = 26;
172 $this->rights[$r][1] =
'Close commercial proposals';
173 $this->rights[$r][2] =
'd';
174 $this->rights[$r][3] = 0;
175 $this->rights[$r][4] =
'propal_advance';
176 $this->rights[$r][5] =
'close';
179 $this->rights[$r][0] = 27;
180 $this->rights[$r][1] =
'Delete commercial proposals';
181 $this->rights[$r][2] =
'd';
182 $this->rights[$r][3] = 0;
183 $this->rights[$r][4] =
'supprimer';
186 $this->rights[$r][0] = 28;
187 $this->rights[$r][1] =
'Exporting commercial proposals and attributes';
188 $this->rights[$r][2] =
'r';
189 $this->rights[$r][3] = 0;
190 $this->rights[$r][4] =
'export';
193 $this->rights[$r][0] = 29;
194 $this->rights[$r][1] =
'Reopen commercial proposals';
195 $this->rights[$r][2] =
'w';
196 $this->rights[$r][3] = 0;
197 $this->rights[$r][4] =
'propal_advance';
198 $this->rights[$r][5] =
'reopen';
210 $this->export_code[$r] = $this->rights_class.
'_'.$r;
211 $this->export_label[$r] =
'ProposalsAndProposalsLines';
212 $this->export_permission[$r] = array(array(
"propale",
"export"));
213 $this->export_fields_array[$r] = array(
214 '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',
215 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
'c.rowid'=>
"Id",
'c.ref'=>
"Ref",
'c.ref_client'=>
"RefCustomer",
216 'c.fk_soc'=>
"IdCompany",
'c.datec'=>
"DateCreation",
'c.datep'=>
"DatePropal",
'c.fin_validite'=>
"DateEndPropal",
217 'c.total_ht'=>
"TotalHT",
'c.total_ttc'=>
"TotalTTC",
218 'cir.label'=>
'Source',
221 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
222 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
223 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
224 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
225 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
227 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
228 'c.fk_statut'=>
'Status',
'c.note_public'=>
"NotePublic",
'c.note_private'=>
"NotePrivate",
'c.date_livraison'=>
'DeliveryDate',
229 'c.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
230 'c.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin'));
232 $this->export_fields_array[$r][
'pj.ref'] =
'ProjectRef';
234 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
235 'cd.rowid'=>
'LineId',
'cd.description'=>
"LineDescription",
'cd.product_type'=>
'TypeOfLineServiceOrProduct',
236 'cd.tva_tx'=>
"LineVATRate",
'cd.qty'=>
"LineQty",
'cd.total_ht'=>
"LineTotalHT",
'cd.total_tva'=>
"LineTotalVAT",
'cd.total_ttc'=>
"LineTotalTTC",
238 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
239 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel'
243 $nbofallowedentities = count(explode(
',',
getEntity(
'propal')));
244 if (
isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
245 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
255 $this->export_TypeFields_array[$r] = array(
256 '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',
257 's.ape'=>
'Text',
's.idprof4'=>
'Text',
'c.ref'=>
"Text",
'c.ref_client'=>
"Text",
'c.datec'=>
"Date",
'c.datep'=>
"Date",
'c.fin_validite'=>
"Date",
258 'c.total_ht'=>
"Numeric",
'c.total_ttc'=>
"Numeric",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Text",
'c.note_private'=>
"Text",
'c.date_livraison'=>
'Date',
259 'pj.ref'=>
'Text',
'cd.description'=>
"Text",
'cd.product_type'=>
'Boolean',
'cd.tva_tx'=>
"Numeric",
'cd.qty'=>
"Numeric",
'cd.total_ht'=>
"Numeric",
260 'cd.total_tva'=>
"Numeric",
'cd.total_ttc'=>
"Numeric",
'p.ref'=>
'Text',
'p.label'=>
'Text',
261 'c.entity'=>
'List:entity:label:rowid',
264 $this->export_entities_array[$r] = array(
265 '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',
266 's.siren'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.siret'=>
'company',
'c.rowid'=>
"propal",
'c.ref'=>
"propal",
'c.ref_client'=>
"propal",
267 'c.fk_soc'=>
"propal",
'c.datec'=>
"propal",
'c.datep'=>
"propal",
'c.fin_validite'=>
"propal",
'c.total_ht'=>
"propal",
268 'c.total_ttc'=>
"propal",
'c.fk_statut'=>
"propal",
'c.note_public'=>
"propal",
'c.note_private'=>
"propal",
'c.date_livraison'=>
"propal",
269 'c.fk_user_author'=>
'user',
'uc.login'=>
'user',
270 'c.fk_user_valid'=>
'user',
'uv.login'=>
'user',
272 'cd.rowid'=>
'propal_line',
273 'cd.description'=>
"propal_line",
'cd.product_type'=>
'propal_line',
'cd.tva_tx'=>
"propal_line",
'cd.qty'=>
"propal_line",
274 'cd.total_ht'=>
"propal_line",
'cd.total_tva'=>
"propal_line",
'cd.total_ttc'=>
"propal_line",
'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product'
276 $this->export_dependencies_array[$r] = array(
'propal_line'=>
'cd.rowid',
'product'=>
'cd.rowid');
277 $keyforselect =
'propal';
278 $keyforelement =
'propal';
279 $keyforaliasextra =
'extra';
280 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
281 $keyforselect =
'propaldet';
282 $keyforelement =
'propal_line';
283 $keyforaliasextra =
'extra2';
284 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
285 $keyforselect =
'product';
286 $keyforelement =
'product';
287 $keyforaliasextra =
'extra3';
288 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
289 $keyforselect =
'societe';
290 $keyforelement =
'company';
291 $keyforaliasextra =
'extra4';
292 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
294 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
295 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s ';
296 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
297 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
298 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
299 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
301 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
302 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'propal as c';
303 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
304 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
305 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
306 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
307 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propal_extrafields as extra ON c.rowid = extra.fk_object';
308 $this->export_sql_end[$r] .=
', '.MAIN_DB_PREFIX.
'propaldet as cd';
309 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
310 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (cd.fk_product = p.rowid)';
311 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
312 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
313 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'propal').
')';
314 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
315 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
317 $parameters = array();
318 $hookmanager->executeHooks(
'printExportWhere', $parameters, $this);
319 $this->export_sql_end[$r] .= $hookmanager->resPrint;
326 $this->import_code[$r] = $this->rights_class.
'_'.$r;
327 $this->import_label[$r] =
'Proposals';
328 $this->import_icon[$r] = $this->picto;
329 $this->import_entities_array[$r] = array();
330 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'propal',
'extra' => MAIN_DB_PREFIX.
'propal_extrafields');
331 $this->import_tables_creator_array[$r] = array(
'c'=>
'fk_user_author');
332 $this->import_fields_array[$r] = array(
334 'c.ref_client' =>
'RefCustomer',
335 'c.fk_soc' =>
'ThirdPartyName*',
336 'c.datec' =>
'DateCreation',
337 'c.datep' =>
'DatePropal',
338 'c.fin_validite' =>
'DateEndPropal',
339 'c.total_ht' =>
'TotalHT',
340 'c.total_ttc' =>
'TotalTTC',
341 'c.fk_statut' =>
'Status*',
342 'c.note_public' =>
'NotePublic',
343 'c.note_private' =>
'NotePrivate',
344 'c.date_livraison' =>
'DeliveryDate',
345 'c.fk_user_valid' =>
'ValidatedById'
348 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
349 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
350 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
351 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
352 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
355 $import_extrafield_sample = array();
356 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, ".$conf->entity.
")";
357 $resql = $this->db->query($sql);
359 while ($obj = $this->db->fetch_object($resql)) {
360 $fieldname =
'extra.'.$obj->name;
361 $fieldlabel = ucfirst($obj->label);
362 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
363 $import_extrafield_sample[$fieldname] = $fieldlabel;
367 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propal'];
368 $this->import_regex_array[$r] = [
'c.ref' =>
'[^ ]'];
370 'c.ref' =>
'PROV0077',
371 'c.ref_client' =>
'Client1',
372 'c.fk_soc' =>
'MyBigCompany',
373 'c.datec' =>
'2020-01-01',
374 'c.datep' =>
'2020-01-01',
375 'c.fin_validite' =>
'2020-01-01',
377 'c.total_ttc' =>
'0',
378 'c.fk_statut' =>
'1',
379 'c.note_public' =>
'',
380 'c.note_private' =>
'',
381 'c.date_livraison' =>
'2020-01-01',
382 'c.fk_user_valid' =>
'1',
383 'c.multicurrency_code' =>
'',
384 'c.multicurrency_tx' =>
'1',
385 'c.multicurrency_total_ht' =>
'0',
386 'c.multicurrency_total_tva' =>
'0',
387 'c.multicurrency_total_ttc' =>
'0'
389 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
390 $this->import_updatekeys_array[$r] = array(
'c.ref'=>
'Ref');
391 $this->import_convertvalue_array[$r] = array(
393 'rule'=>
'getrefifauto',
394 'class'=>(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON),
395 'path'=>
"/core/modules/propale/".(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON).
'.php',
396 'classobject'=>
'Propal',
397 'pathobject'=>
'/comm/propal/class/propal.class.php',
400 'rule' =>
'fetchidfromref',
401 'file' =>
'/societe/class/societe.class.php',
402 'class' =>
'Societe',
404 'element' =>
'ThirdParty'
410 $this->import_code[$r] = $this->rights_class.
'line_'.$r;
411 $this->import_label[$r] =
"ProposalLines";
412 $this->import_icon[$r] = $this->picto;
413 $this->import_entities_array[$r] = array();
414 $this->import_tables_array[$r] = array(
415 'cd' => MAIN_DB_PREFIX.
'propaldet',
416 'extra' => MAIN_DB_PREFIX.
'propaldet_extrafields'
418 $this->import_fields_array[$r] = array(
419 'cd.fk_propal' =>
'Proposal*',
420 'cd.fk_parent_line' =>
'ParentLine',
421 'cd.fk_product' =>
'IdProduct',
422 'cd.description' =>
'LineDescription',
423 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
424 'cd.tva_tx' =>
'LineVATRate',
425 'cd.qty' =>
'LineQty',
426 'cd.remise_percent' =>
'Reduc. Percent',
427 'cd.price' =>
'Price',
428 'cd.subprice' =>
'Sub Price',
429 'cd.total_ht' =>
'LineTotalHT',
430 'cd.total_tva' =>
'LineTotalVAT',
431 'cd.total_ttc' =>
'LineTotalTTC',
432 'cd.date_start' =>
'Start Date',
433 'cd.date_end' =>
'End Date',
434 'cd.buy_price_ht' =>
'LineBuyPriceHT'
437 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
438 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
439 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
440 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
441 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
444 $import_extrafield_sample = array();
445 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, ".$conf->entity.
")";
446 $resql = $this->db->query($sql);
448 while ($obj = $this->db->fetch_object($resql)) {
449 $fieldname =
'extra.'.$obj->name;
450 $fieldlabel = ucfirst($obj->label);
451 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
452 $import_extrafield_sample[$fieldname] = $fieldlabel;
456 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propaldet');
457 $this->import_regex_array[$r] = array(
'cd.product_type' =>
'[0|1]$');
458 $import_sample = array(
459 'cd.fk_propal' =>
'PROV(0001)',
460 'cd.fk_parent_line' =>
'',
461 'cd.fk_product' =>
'',
462 'cd.description' =>
'Line description',
463 'cd.product_type' =>
'1',
466 'cd.remise_percent' =>
'0',
468 'cd.subprice' =>
'5000',
469 'cd.total_ht' =>
'10000',
470 'cd.total_tva' =>
'0',
471 'cd.total_ttc' =>
'10100',
472 'cd.date_start' =>
'',
474 'cd.buy_price_ht' =>
'7000',
475 'cd.multicurrency_code' =>
'JPY',
476 'cd.multicurrency_tx' =>
'1',
477 'cd.multicurrency_total_ht' =>
'10000',
478 'cd.multicurrency_total_tva' =>
'0',
479 'cd.multicurrency_total_ttc' =>
'10100'
481 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
482 $this->import_updatekeys_array[$r] = array(
'cd.fk_propal' =>
'Quotation Id',
'cd.fk_product' =>
'Product Id');
483 $this->import_convertvalue_array[$r] = array(
484 'cd.fk_propal' => array(
485 'rule'=>
'fetchidfromref',
486 'file'=>
'/comm/propal/class/propal.class.php',