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",
"deliveries",
"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/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;
122 $this->boxes = array(
123 0=>array(
'file'=>
'box_graph_propales_permonth.php',
'enabledbydefaulton'=>
'Home'),
124 1=>array(
'file'=>
'box_propales.php',
'enabledbydefaulton'=>
'Home'),
128 $this->rights = array();
129 $this->rights_class =
'propale';
133 $this->rights[$r][0] = 21;
134 $this->rights[$r][1] =
'Read commercial proposals';
135 $this->rights[$r][2] =
'r';
136 $this->rights[$r][3] = 0;
137 $this->rights[$r][4] =
'lire';
140 $this->rights[$r][0] = 22;
141 $this->rights[$r][1] =
'Create and update commercial proposals';
142 $this->rights[$r][2] =
'w';
143 $this->rights[$r][3] = 0;
144 $this->rights[$r][4] =
'creer';
147 $this->rights[$r][0] = 24;
148 $this->rights[$r][1] =
'Validate commercial proposals';
149 $this->rights[$r][2] =
'd';
150 $this->rights[$r][3] = 0;
151 $this->rights[$r][4] =
'propal_advance';
152 $this->rights[$r][5] =
'validate';
155 $this->rights[$r][0] = 25;
156 $this->rights[$r][1] =
'Send commercial proposals to customers';
157 $this->rights[$r][2] =
'd';
158 $this->rights[$r][3] = 0;
159 $this->rights[$r][4] =
'propal_advance';
160 $this->rights[$r][5] =
'send';
163 $this->rights[$r][0] = 26;
164 $this->rights[$r][1] =
'Close commercial proposals';
165 $this->rights[$r][2] =
'd';
166 $this->rights[$r][3] = 0;
167 $this->rights[$r][4] =
'propal_advance';
168 $this->rights[$r][5] =
'close';
171 $this->rights[$r][0] = 27;
172 $this->rights[$r][1] =
'Delete commercial proposals';
173 $this->rights[$r][2] =
'd';
174 $this->rights[$r][3] = 0;
175 $this->rights[$r][4] =
'supprimer';
178 $this->rights[$r][0] = 28;
179 $this->rights[$r][1] =
'Exporting commercial proposals and attributes';
180 $this->rights[$r][2] =
'r';
181 $this->rights[$r][3] = 0;
182 $this->rights[$r][4] =
'export';
195 $this->export_code[$r] = $this->rights_class.
'_'.$r;
196 $this->export_label[$r] =
'ProposalsAndProposalsLines';
197 $this->export_permission[$r] = array(array(
"propale",
"export"));
198 $this->export_fields_array[$r] = array(
199 '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',
200 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
'c.rowid'=>
"Id",
'c.ref'=>
"Ref",
'c.ref_client'=>
"RefCustomer",
201 'c.fk_soc'=>
"IdCompany",
'c.datec'=>
"DateCreation",
'c.datep'=>
"DatePropal",
'c.fin_validite'=>
"DateEndPropal",
202 'c.total_ht'=>
"TotalHT",
'c.total_ttc'=>
"TotalTTC",
203 'cir.label'=>
'Source',
205 if (isModEnabled(
"multicurrency")) {
206 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
207 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
208 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
209 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
210 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
212 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
213 'c.fk_statut'=>
'Status',
'c.note_public'=>
"NotePublic",
'c.note_private'=>
"NotePrivate",
'c.date_livraison'=>
'DeliveryDate',
214 'c.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
215 'c.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin'));
216 if (isModEnabled(
"project")) {
217 $this->export_fields_array[$r][
'pj.ref'] =
'ProjectRef';
219 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
220 'cd.rowid'=>
'LineId',
'cd.description'=>
"LineDescription",
'cd.product_type'=>
'TypeOfLineServiceOrProduct',
221 'cd.tva_tx'=>
"LineVATRate",
'cd.qty'=>
"LineQty",
'cd.total_ht'=>
"LineTotalHT",
'cd.total_tva'=>
"LineTotalVAT",
'cd.total_ttc'=>
"LineTotalTTC",
223 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
224 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel'
228 $nbofallowedentities = count(explode(
',',
getEntity(
'propal')));
229 if (isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
230 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
240 $this->export_TypeFields_array[$r] = array(
241 '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',
242 's.ape'=>
'Text',
's.idprof4'=>
'Text',
'c.ref'=>
"Text",
'c.ref_client'=>
"Text",
'c.datec'=>
"Date",
'c.datep'=>
"Date",
'c.fin_validite'=>
"Date",
243 'c.total_ht'=>
"Numeric",
'c.total_ttc'=>
"Numeric",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Text",
'c.note_private'=>
"Text",
'c.date_livraison'=>
'Date',
244 'pj.ref'=>
'Text',
'cd.description'=>
"Text",
'cd.product_type'=>
'Boolean',
'cd.tva_tx'=>
"Numeric",
'cd.qty'=>
"Numeric",
'cd.total_ht'=>
"Numeric",
245 'cd.total_tva'=>
"Numeric",
'cd.total_ttc'=>
"Numeric",
'p.ref'=>
'Text',
'p.label'=>
'Text',
246 'c.entity'=>
'List:entity:label:rowid',
249 $this->export_entities_array[$r] = array(
250 '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',
251 's.siren'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.siret'=>
'company',
'c.rowid'=>
"propal",
'c.ref'=>
"propal",
'c.ref_client'=>
"propal",
252 'c.fk_soc'=>
"propal",
'c.datec'=>
"propal",
'c.datep'=>
"propal",
'c.fin_validite'=>
"propal",
'c.total_ht'=>
"propal",
253 'c.total_ttc'=>
"propal",
'c.fk_statut'=>
"propal",
'c.note_public'=>
"propal",
'c.note_private'=>
"propal",
'c.date_livraison'=>
"propal",
254 'c.fk_user_author'=>
'user',
'uc.login'=>
'user',
255 'c.fk_user_valid'=>
'user',
'uv.login'=>
'user',
257 'cd.rowid'=>
'propal_line',
258 'cd.description'=>
"propal_line",
'cd.product_type'=>
'propal_line',
'cd.tva_tx'=>
"propal_line",
'cd.qty'=>
"propal_line",
259 'cd.total_ht'=>
"propal_line",
'cd.total_tva'=>
"propal_line",
'cd.total_ttc'=>
"propal_line",
'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product'
261 $this->export_dependencies_array[$r] = array(
'propal_line'=>
'cd.rowid',
'product'=>
'cd.rowid');
262 $keyforselect =
'propal';
263 $keyforelement =
'propal';
264 $keyforaliasextra =
'extra';
265 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
266 $keyforselect =
'propaldet';
267 $keyforelement =
'propal_line';
268 $keyforaliasextra =
'extra2';
269 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
270 $keyforselect =
'product';
271 $keyforelement =
'product';
272 $keyforaliasextra =
'extra3';
273 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
274 $keyforselect =
'societe';
275 $keyforelement =
'company';
276 $keyforaliasextra =
'extra4';
277 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
279 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
280 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s ';
281 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
282 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
283 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
284 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
286 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
287 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'propal as c';
288 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
289 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
290 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
291 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
292 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propal_extrafields as extra ON c.rowid = extra.fk_object';
293 $this->export_sql_end[$r] .=
', '.MAIN_DB_PREFIX.
'propaldet as cd';
294 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
295 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (cd.fk_product = p.rowid)';
296 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
297 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
298 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'propal').
')';
299 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
300 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
308 $this->import_code[$r] = $this->rights_class.
'_'.$r;
309 $this->import_label[$r] =
'Proposals';
310 $this->import_icon[$r] = $this->picto;
311 $this->import_entities_array[$r] = array();
312 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'propal',
'extra' => MAIN_DB_PREFIX.
'propal_extrafields');
313 $this->import_tables_creator_array[$r] = array(
'c'=>
'fk_user_author');
314 $this->import_fields_array[$r] = array(
316 'c.ref_client' =>
'RefCustomer',
317 'c.fk_soc' =>
'ThirdPartyName*',
318 'c.datec' =>
'DateCreation',
319 'c.datep' =>
'DatePropal',
320 'c.fin_validite' =>
'DateEndPropal',
321 'c.total_ht' =>
'TotalHT',
322 'c.total_ttc' =>
'TotalTTC',
323 'c.fk_statut' =>
'Status*',
324 'c.note_public' =>
'NotePublic',
325 'c.note_private' =>
'NotePrivate',
326 'c.date_livraison' =>
'DeliveryDate',
327 'c.fk_user_valid' =>
'ValidatedById'
329 if (isModEnabled(
"multicurrency")) {
330 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
331 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
332 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
333 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
334 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
337 $import_extrafield_sample = array();
338 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, ".$conf->entity.
")";
339 $resql = $this->db->query($sql);
341 while ($obj = $this->db->fetch_object($resql)) {
342 $fieldname =
'extra.'.$obj->name;
343 $fieldlabel = ucfirst($obj->label);
344 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
345 $import_extrafield_sample[$fieldname] = $fieldlabel;
349 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propal'];
350 $this->import_regex_array[$r] = [
'c.ref' =>
'[^ ]'];
352 'c.ref' =>
'PROV0077',
353 'c.ref_client' =>
'Client1',
354 'c.fk_soc' =>
'MyBigCompany',
355 'c.datec' =>
'2020-01-01',
356 'c.datep' =>
'2020-01-01',
357 'c.fin_validite' =>
'2020-01-01',
359 'c.total_ttc' =>
'0',
360 'c.fk_statut' =>
'1',
361 'c.note_public' =>
'',
362 'c.note_private' =>
'',
363 'c.date_livraison' =>
'2020-01-01',
364 'c.fk_user_valid' =>
'1',
365 'c.multicurrency_code' =>
'',
366 'c.multicurrency_tx' =>
'1',
367 'c.multicurrency_total_ht' =>
'0',
368 'c.multicurrency_total_tva' =>
'0',
369 'c.multicurrency_total_ttc' =>
'0'
371 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
372 $this->import_updatekeys_array[$r] = array(
'c.ref'=>
'Ref');
373 $this->import_convertvalue_array[$r] = array(
375 'rule'=>
'getrefifauto',
376 'class'=>(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON),
377 'path'=>
"/core/modules/propale/".(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON).
'.php',
378 'classobject'=>
'Propal',
379 'pathobject'=>
'/comm/propal/class/propal.class.php',
382 'rule' =>
'fetchidfromref',
383 'file' =>
'/societe/class/societe.class.php',
384 'class' =>
'Societe',
386 'element' =>
'ThirdParty'
392 $this->import_code[$r] = $this->rights_class.
'line_'.$r;
393 $this->import_label[$r] =
"ProposalLines";
394 $this->import_icon[$r] = $this->picto;
395 $this->import_entities_array[$r] = array();
396 $this->import_tables_array[$r] = array(
397 'cd' => MAIN_DB_PREFIX.
'propaldet',
398 'extra' => MAIN_DB_PREFIX.
'propaldet_extrafields'
400 $this->import_fields_array[$r] = array(
401 'cd.fk_propal' =>
'Proposal*',
402 'cd.fk_parent_line' =>
'ParentLine',
403 'cd.fk_product' =>
'IdProduct',
404 'cd.description' =>
'LineDescription',
405 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
406 'cd.tva_tx' =>
'LineVATRate',
407 'cd.qty' =>
'LineQty',
408 'cd.remise_percent' =>
'Reduc. Percent',
409 'cd.price' =>
'Price',
410 'cd.subprice' =>
'Sub Price',
411 'cd.total_ht' =>
'LineTotalHT',
412 'cd.total_tva' =>
'LineTotalVAT',
413 'cd.total_ttc' =>
'LineTotalTTC',
414 'cd.date_start' =>
'Start Date',
415 'cd.date_end' =>
'End Date',
416 'cd.buy_price_ht' =>
'LineBuyPriceHT'
418 if (isModEnabled(
"multicurrency")) {
419 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
420 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
421 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
422 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
423 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
426 $import_extrafield_sample = array();
427 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, ".$conf->entity.
")";
428 $resql = $this->db->query($sql);
430 while ($obj = $this->db->fetch_object($resql)) {
431 $fieldname =
'extra.'.$obj->name;
432 $fieldlabel = ucfirst($obj->label);
433 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
434 $import_extrafield_sample[$fieldname] = $fieldlabel;
438 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propaldet');
439 $this->import_regex_array[$r] = array(
'cd.product_type' =>
'[0|1]$');
440 $import_sample = array(
441 'cd.fk_propal' =>
'PROV(0001)',
442 'cd.fk_parent_line' =>
'',
443 'cd.fk_product' =>
'',
444 'cd.description' =>
'Line description',
445 'cd.product_type' =>
'1',
448 'cd.remise_percent' =>
'0',
450 'cd.subprice' =>
'5000',
451 'cd.total_ht' =>
'10000',
452 'cd.total_tva' =>
'0',
453 'cd.total_ttc' =>
'10100',
454 'cd.date_start' =>
'',
456 'cd.buy_price_ht' =>
'7000',
457 'cd.multicurrency_code' =>
'JPY',
458 'cd.multicurrency_tx' =>
'1',
459 'cd.multicurrency_total_ht' =>
'10000',
460 'cd.multicurrency_total_tva' =>
'0',
461 'cd.multicurrency_total_ttc' =>
'10100'
463 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
464 $this->import_updatekeys_array[$r] = array(
'cd.fk_propal' =>
'Quotation Id',
'cd.fk_product' =>
'Product Id');
465 $this->import_convertvalue_array[$r] = array(
466 'cd.fk_propal' => array(
467 'rule'=>
'fetchidfromref',
468 'file'=>
'/comm/propal/class/propal.class.php',