48 global
$conf, $user, $hookmanager;
53 $this->family =
"crm";
54 $this->module_position =
'10';
56 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
57 $this->
description =
"Management of quotes or commercial proposals";
60 $this->version =
'dolibarr';
62 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
63 $this->picto =
'propal';
66 $this->dirs = array(
"/propale/temp");
69 $this->hidden =
false;
70 $this->depends = array(
"modSociete");
71 $this->requiredby = array();
72 $this->conflictwith = array();
73 $this->phpmin = array(7, 0);
74 $this->config_page_url = array(
"propal.php");
75 $this->langfiles = array(
"propal",
"bills",
"companies",
"sendings",
"products");
78 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
84 'Name of the proposal generation manager in PDF format',
91 'Name of proposal numbering manager',
95 "PROPALE_VALIDITY_DURATION",
98 'Duration of validity of business proposals',
102 "PROPALE_ADDON_PDF_ODT_PATH",
104 "DOL_DATA_ROOT".($conf->entity > 1 ?
'/'.$conf->entity :
'').
"/doctemplates/proposals",
109 "PROPOSAL_ALLOW_ONLINESIGN",
116 "PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN",
131 $this->boxes = array(
132 0=>array(
'file'=>
'box_graph_propales_permonth.php',
'enabledbydefaulton'=>
'Home'),
133 1=>array(
'file'=>
'box_propales.php',
'enabledbydefaulton'=>
'Home'),
137 $this->rights = array();
138 $this->rights_class =
'propale';
142 $this->rights[$r][0] = 21;
143 $this->rights[$r][1] =
'Read commercial proposals';
144 $this->rights[$r][2] =
'r';
145 $this->rights[$r][3] = 0;
146 $this->rights[$r][4] =
'lire';
149 $this->rights[$r][0] = 22;
150 $this->rights[$r][1] =
'Create and update commercial proposals';
151 $this->rights[$r][2] =
'w';
152 $this->rights[$r][3] = 0;
153 $this->rights[$r][4] =
'creer';
156 $this->rights[$r][0] = 24;
157 $this->rights[$r][1] =
'Validate commercial proposals';
158 $this->rights[$r][2] =
'd';
159 $this->rights[$r][3] = 0;
160 $this->rights[$r][4] =
'propal_advance';
161 $this->rights[$r][5] =
'validate';
164 $this->rights[$r][0] = 25;
165 $this->rights[$r][1] =
'Send commercial proposals to customers';
166 $this->rights[$r][2] =
'd';
167 $this->rights[$r][3] = 0;
168 $this->rights[$r][4] =
'propal_advance';
169 $this->rights[$r][5] =
'send';
172 $this->rights[$r][0] = 26;
173 $this->rights[$r][1] =
'Close commercial proposals';
174 $this->rights[$r][2] =
'd';
175 $this->rights[$r][3] = 0;
176 $this->rights[$r][4] =
'propal_advance';
177 $this->rights[$r][5] =
'close';
180 $this->rights[$r][0] = 27;
181 $this->rights[$r][1] =
'Delete commercial proposals';
182 $this->rights[$r][2] =
'd';
183 $this->rights[$r][3] = 0;
184 $this->rights[$r][4] =
'supprimer';
187 $this->rights[$r][0] = 28;
188 $this->rights[$r][1] =
'Exporting commercial proposals and attributes';
189 $this->rights[$r][2] =
'r';
190 $this->rights[$r][3] = 0;
191 $this->rights[$r][4] =
'export';
194 $this->rights[$r][0] = 29;
195 $this->rights[$r][1] =
'Reopen commercial proposals';
196 $this->rights[$r][2] =
'w';
197 $this->rights[$r][3] = 0;
198 $this->rights[$r][4] =
'propal_advance';
199 $this->rights[$r][5] =
'reopen';
211 $this->export_code[$r] = $this->rights_class.
'_'.$r;
212 $this->export_label[$r] =
'ProposalsAndProposalsLines';
213 $this->export_permission[$r] = array(array(
"propale",
"export"));
214 $this->export_fields_array[$r] = array(
215 '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',
216 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
'c.rowid'=>
"Id",
'c.ref'=>
"Ref",
'c.ref_client'=>
"RefCustomer",
217 'c.fk_soc'=>
"IdCompany",
'c.datec'=>
"DateCreation",
'c.datep'=>
"DatePropal",
'c.fin_validite'=>
"DateEndPropal",
218 'c.total_ht'=>
"TotalHT",
'c.total_ttc'=>
"TotalTTC",
219 'cir.label'=>
'Source',
222 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
223 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
224 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
225 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
226 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
228 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
229 'c.fk_statut'=>
'Status',
'c.note_public'=>
"NotePublic",
'c.note_private'=>
"NotePrivate",
'c.date_livraison'=>
'DeliveryDate',
230 'c.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
231 'c.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin'));
233 $this->export_fields_array[$r][
'pj.ref'] =
'ProjectRef';
235 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
236 'cd.rowid'=>
'LineId',
'cd.description'=>
"LineDescription",
'cd.product_type'=>
'TypeOfLineServiceOrProduct',
237 'cd.tva_tx'=>
"LineVATRate",
'cd.qty'=>
"LineQty",
'cd.total_ht'=>
"LineTotalHT",
'cd.total_tva'=>
"LineTotalVAT",
'cd.total_ttc'=>
"LineTotalTTC",
239 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
240 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel'
244 $nbofallowedentities = count(explode(
',',
getEntity(
'propal')));
245 if (
isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
246 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
256 $this->export_TypeFields_array[$r] = array(
257 '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',
258 's.ape'=>
'Text',
's.idprof4'=>
'Text',
'c.ref'=>
"Text",
'c.ref_client'=>
"Text",
'c.datec'=>
"Date",
'c.datep'=>
"Date",
'c.fin_validite'=>
"Date",
259 'c.total_ht'=>
"Numeric",
'c.total_ttc'=>
"Numeric",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Text",
'c.note_private'=>
"Text",
'c.date_livraison'=>
'Date',
260 'pj.ref'=>
'Text',
'cd.description'=>
"Text",
'cd.product_type'=>
'Boolean',
'cd.tva_tx'=>
"Numeric",
'cd.qty'=>
"Numeric",
'cd.total_ht'=>
"Numeric",
261 'cd.total_tva'=>
"Numeric",
'cd.total_ttc'=>
"Numeric",
'p.ref'=>
'Text',
'p.label'=>
'Text',
262 'c.entity'=>
'List:entity:label:rowid',
265 $this->export_entities_array[$r] = array(
266 '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',
267 's.siren'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.siret'=>
'company',
'c.rowid'=>
"propal",
'c.ref'=>
"propal",
'c.ref_client'=>
"propal",
268 'c.fk_soc'=>
"propal",
'c.datec'=>
"propal",
'c.datep'=>
"propal",
'c.fin_validite'=>
"propal",
'c.total_ht'=>
"propal",
269 'c.total_ttc'=>
"propal",
'c.fk_statut'=>
"propal",
'c.note_public'=>
"propal",
'c.note_private'=>
"propal",
'c.date_livraison'=>
"propal",
270 'c.fk_user_author'=>
'user',
'uc.login'=>
'user',
271 'c.fk_user_valid'=>
'user',
'uv.login'=>
'user',
273 'cd.rowid'=>
'propal_line',
274 'cd.description'=>
"propal_line",
'cd.product_type'=>
'propal_line',
'cd.tva_tx'=>
"propal_line",
'cd.qty'=>
"propal_line",
275 'cd.total_ht'=>
"propal_line",
'cd.total_tva'=>
"propal_line",
'cd.total_ttc'=>
"propal_line",
'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product'
277 $this->export_dependencies_array[$r] = array(
'propal_line'=>
'cd.rowid',
'product'=>
'cd.rowid');
278 $keyforselect =
'propal';
279 $keyforelement =
'propal';
280 $keyforaliasextra =
'extra';
281 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
282 $keyforselect =
'propaldet';
283 $keyforelement =
'propal_line';
284 $keyforaliasextra =
'extra2';
285 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
286 $keyforselect =
'product';
287 $keyforelement =
'product';
288 $keyforaliasextra =
'extra3';
289 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
290 $keyforselect =
'societe';
291 $keyforelement =
'company';
292 $keyforaliasextra =
'extra4';
293 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
295 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
296 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s ';
297 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
298 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
299 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
300 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
302 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
303 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'propal as c';
304 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
305 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
306 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
307 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
308 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propal_extrafields as extra ON c.rowid = extra.fk_object';
309 $this->export_sql_end[$r] .=
', '.MAIN_DB_PREFIX.
'propaldet as cd';
310 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
311 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (cd.fk_product = p.rowid)';
312 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
313 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
314 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'propal').
')';
315 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
316 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
318 $parameters = array();
319 $hookmanager->executeHooks(
'printExportWhere', $parameters, $this);
320 $this->export_sql_end[$r] .= $hookmanager->resPrint;
327 $this->import_code[$r] = $this->rights_class.
'_'.$r;
328 $this->import_label[$r] =
'Proposals';
329 $this->import_icon[$r] = $this->picto;
330 $this->import_entities_array[$r] = array();
331 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'propal',
'extra' => MAIN_DB_PREFIX.
'propal_extrafields');
332 $this->import_tables_creator_array[$r] = array(
'c'=>
'fk_user_author');
333 $this->import_fields_array[$r] = array(
335 'c.ref_client' =>
'RefCustomer',
336 'c.fk_soc' =>
'ThirdPartyName*',
337 'c.datec' =>
'DateCreation',
338 'c.datep' =>
'DatePropal',
339 'c.fin_validite' =>
'DateEndPropal',
340 'c.total_ht' =>
'TotalHT',
341 'c.total_ttc' =>
'TotalTTC',
342 'c.fk_statut' =>
'Status*',
343 'c.note_public' =>
'NotePublic',
344 'c.note_private' =>
'NotePrivate',
345 'c.date_livraison' =>
'DeliveryDate',
346 'c.fk_user_valid' =>
'ValidatedById'
349 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
350 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
351 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
352 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
353 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
356 $import_extrafield_sample = array();
357 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, ".
$conf->entity.
")";
358 $resql = $this->db->query($sql);
360 while ($obj = $this->db->fetch_object($resql)) {
361 $fieldname =
'extra.'.$obj->name;
362 $fieldlabel = ucfirst($obj->label);
363 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
364 $import_extrafield_sample[$fieldname] = $fieldlabel;
368 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propal'];
369 $this->import_regex_array[$r] = [
'c.ref' =>
'[^ ]'];
371 'c.ref' =>
'PROV0077',
372 'c.ref_client' =>
'Client1',
373 'c.fk_soc' =>
'MyBigCompany',
374 'c.datec' =>
'2020-01-01',
375 'c.datep' =>
'2020-01-01',
376 'c.fin_validite' =>
'2020-01-01',
378 'c.total_ttc' =>
'0',
379 'c.fk_statut' =>
'1',
380 'c.note_public' =>
'',
381 'c.note_private' =>
'',
382 'c.date_livraison' =>
'2020-01-01',
383 'c.fk_user_valid' =>
'1',
384 'c.multicurrency_code' =>
'',
385 'c.multicurrency_tx' =>
'1',
386 'c.multicurrency_total_ht' =>
'0',
387 'c.multicurrency_total_tva' =>
'0',
388 'c.multicurrency_total_ttc' =>
'0'
390 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
391 $this->import_updatekeys_array[$r] = array(
'c.ref'=>
'Ref');
392 $this->import_convertvalue_array[$r] = array(
394 'rule'=>
'getrefifauto',
396 'path'=>
"/core/modules/propale/".(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' :
$conf->global->PROPALE_ADDON).
'.php',
397 'classobject'=>
'Propal',
398 'pathobject'=>
'/comm/propal/class/propal.class.php',
401 'rule' =>
'fetchidfromref',
402 'file' =>
'/societe/class/societe.class.php',
403 'class' =>
'Societe',
405 'element' =>
'ThirdParty'
411 $this->import_code[$r] = $this->rights_class.
'line_'.$r;
412 $this->import_label[$r] =
"ProposalLines";
413 $this->import_icon[$r] = $this->picto;
414 $this->import_entities_array[$r] = array();
415 $this->import_tables_array[$r] = array(
416 'cd' => MAIN_DB_PREFIX.
'propaldet',
417 'extra' => MAIN_DB_PREFIX.
'propaldet_extrafields'
419 $this->import_fields_array[$r] = array(
420 'cd.fk_propal' =>
'Proposal*',
421 'cd.fk_parent_line' =>
'ParentLine',
422 'cd.fk_product' =>
'IdProduct',
423 'cd.description' =>
'LineDescription',
424 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
425 'cd.tva_tx' =>
'LineVATRate',
426 'cd.qty' =>
'LineQty',
427 'cd.remise_percent' =>
'Reduc. Percent',
428 'cd.price' =>
'Price',
429 'cd.subprice' =>
'Sub Price',
430 'cd.total_ht' =>
'LineTotalHT',
431 'cd.total_tva' =>
'LineTotalVAT',
432 'cd.total_ttc' =>
'LineTotalTTC',
433 'cd.date_start' =>
'Start Date',
434 'cd.date_end' =>
'End Date',
435 'cd.buy_price_ht' =>
'LineBuyPriceHT'
438 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
439 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
440 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
441 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
442 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
445 $import_extrafield_sample = array();
446 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, ".
$conf->entity.
")";
447 $resql = $this->db->query($sql);
449 while ($obj = $this->db->fetch_object($resql)) {
450 $fieldname =
'extra.'.$obj->name;
451 $fieldlabel = ucfirst($obj->label);
452 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
453 $import_extrafield_sample[$fieldname] = $fieldlabel;
457 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propaldet');
458 $this->import_regex_array[$r] = array(
'cd.product_type' =>
'[0|1]$');
459 $import_sample = array(
460 'cd.fk_propal' =>
'PROV(0001)',
461 'cd.fk_parent_line' =>
'',
462 'cd.fk_product' =>
'',
463 'cd.description' =>
'Line description',
464 'cd.product_type' =>
'1',
467 'cd.remise_percent' =>
'0',
469 'cd.subprice' =>
'5000',
470 'cd.total_ht' =>
'10000',
471 'cd.total_tva' =>
'0',
472 'cd.total_ttc' =>
'10100',
473 'cd.date_start' =>
'',
475 'cd.buy_price_ht' =>
'7000',
476 'cd.multicurrency_code' =>
'JPY',
477 'cd.multicurrency_tx' =>
'1',
478 'cd.multicurrency_total_ht' =>
'10000',
479 'cd.multicurrency_total_tva' =>
'0',
480 'cd.multicurrency_total_ttc' =>
'10100'
482 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
483 $this->import_updatekeys_array[$r] = array(
'cd.fk_propal' =>
'Quotation Id',
'cd.fk_product' =>
'Product Id');
484 $this->import_convertvalue_array[$r] = array(
485 'cd.fk_propal' => array(
486 'rule'=>
'fetchidfromref',
487 'file'=>
'/comm/propal/class/propal.class.php',