51 $this->family =
"crm";
52 $this->module_position =
'10';
54 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
55 $this->
description =
"Gestion des propositions commerciales";
58 $this->version =
'dolibarr';
60 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
61 $this->picto =
'propal';
64 $this->dirs = array(
"/propale/temp");
67 $this->hidden =
false;
68 $this->depends = array(
"modSociete");
69 $this->requiredby = array();
70 $this->conflictwith = array();
71 $this->phpmin = array(7, 0);
72 $this->config_page_url = array(
"propal.php");
73 $this->langfiles = array(
"propal",
"bills",
"companies",
"deliveries",
"products");
76 $this->
const = array();
79 $this->
const[$r][0] =
"PROPALE_ADDON_PDF";
80 $this->
const[$r][1] =
"chaine";
81 $this->
const[$r][2] =
"cyan";
82 $this->
const[$r][3] =
'Name of the proposal generation manager in PDF format';
83 $this->
const[$r][4] = 0;
86 $this->
const[$r][0] =
"PROPALE_ADDON";
87 $this->
const[$r][1] =
"chaine";
88 $this->
const[$r][2] =
"mod_propale_marbre";
89 $this->
const[$r][3] =
'Name of proposal numbering manager';
90 $this->
const[$r][4] = 0;
93 $this->
const[$r][0] =
"PROPALE_VALIDITY_DURATION";
94 $this->
const[$r][1] =
"chaine";
95 $this->
const[$r][2] =
"15";
96 $this->
const[$r][3] =
'Duration of validity of business proposals';
97 $this->
const[$r][4] = 0;
100 $this->
const[$r][0] =
"PROPALE_ADDON_PDF_ODT_PATH";
101 $this->
const[$r][1] =
"chaine";
102 $this->
const[$r][2] =
"DOL_DATA_ROOT/doctemplates/proposals";
103 $this->
const[$r][3] =
"";
104 $this->
const[$r][4] = 0;
107 $this->
const[$r][0] =
"PROPOSAL_ALLOW_ONLINESIGN";
108 $this->
const[$r][1] =
"chaine";
109 $this->
const[$r][2] =
"1";
110 $this->
const[$r][3] =
"";
111 $this->
const[$r][4] = 0;
121 $this->boxes = array(
122 0=>array(
'file'=>
'box_graph_propales_permonth.php',
'enabledbydefaulton'=>
'Home'),
123 1=>array(
'file'=>
'box_propales.php',
'enabledbydefaulton'=>
'Home'),
127 $this->rights = array();
128 $this->rights_class =
'propale';
132 $this->rights[$r][0] = 21;
133 $this->rights[$r][1] =
'Read commercial proposals';
134 $this->rights[$r][2] =
'r';
135 $this->rights[$r][3] = 0;
136 $this->rights[$r][4] =
'lire';
139 $this->rights[$r][0] = 22;
140 $this->rights[$r][1] =
'Create and update commercial proposals';
141 $this->rights[$r][2] =
'w';
142 $this->rights[$r][3] = 0;
143 $this->rights[$r][4] =
'creer';
146 $this->rights[$r][0] = 24;
147 $this->rights[$r][1] =
'Validate commercial proposals';
148 $this->rights[$r][2] =
'd';
149 $this->rights[$r][3] = 0;
150 $this->rights[$r][4] =
'propal_advance';
151 $this->rights[$r][5] =
'validate';
154 $this->rights[$r][0] = 25;
155 $this->rights[$r][1] =
'Send commercial proposals to customers';
156 $this->rights[$r][2] =
'd';
157 $this->rights[$r][3] = 0;
158 $this->rights[$r][4] =
'propal_advance';
159 $this->rights[$r][5] =
'send';
162 $this->rights[$r][0] = 26;
163 $this->rights[$r][1] =
'Close commercial proposals';
164 $this->rights[$r][2] =
'd';
165 $this->rights[$r][3] = 0;
166 $this->rights[$r][4] =
'propal_advance';
167 $this->rights[$r][5] =
'close';
170 $this->rights[$r][0] = 27;
171 $this->rights[$r][1] =
'Delete commercial proposals';
172 $this->rights[$r][2] =
'd';
173 $this->rights[$r][3] = 0;
174 $this->rights[$r][4] =
'supprimer';
177 $this->rights[$r][0] = 28;
178 $this->rights[$r][1] =
'Exporting commercial proposals and attributes';
179 $this->rights[$r][2] =
'r';
180 $this->rights[$r][3] = 0;
181 $this->rights[$r][4] =
'export';
194 $this->export_code[$r] = $this->rights_class.
'_'.$r;
195 $this->export_label[$r] =
'ProposalsAndProposalsLines';
196 $this->export_permission[$r] = array(array(
"propale",
"export"));
197 $this->export_fields_array[$r] = array(
198 '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',
199 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
'c.rowid'=>
"Id",
'c.ref'=>
"Ref",
'c.ref_client'=>
"RefCustomer",
200 'c.fk_soc'=>
"IdCompany",
'c.datec'=>
"DateCreation",
'c.datep'=>
"DatePropal",
'c.fin_validite'=>
"DateEndPropal",
201 'c.total_ht'=>
"TotalHT",
'c.total_ttc'=>
"TotalTTC",
202 'cir.label'=>
'Source',
204 if (isModEnabled(
"multicurrency")) {
205 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
206 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
207 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
208 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
209 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
211 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
212 'c.fk_statut'=>
'Status',
'c.note_public'=>
"NotePublic",
'c.note_private'=>
"NotePrivate",
'c.date_livraison'=>
'DeliveryDate',
213 'c.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
214 'c.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin'));
215 if (isModEnabled(
"project")) {
216 $this->export_fields_array[$r][
'pj.ref'] =
'ProjectRef';
218 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
219 'cd.rowid'=>
'LineId',
'cd.description'=>
"LineDescription",
'cd.product_type'=>
'TypeOfLineServiceOrProduct',
220 'cd.tva_tx'=>
"LineVATRate",
'cd.qty'=>
"LineQty",
'cd.total_ht'=>
"LineTotalHT",
'cd.total_tva'=>
"LineTotalVAT",
'cd.total_ttc'=>
"LineTotalTTC",
222 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
223 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel'
227 $nbofallowedentities = count(explode(
',',
getEntity(
'propal')));
228 if (isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
229 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
239 $this->export_TypeFields_array[$r] = array(
240 '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',
241 's.ape'=>
'Text',
's.idprof4'=>
'Text',
'c.ref'=>
"Text",
'c.ref_client'=>
"Text",
'c.datec'=>
"Date",
'c.datep'=>
"Date",
'c.fin_validite'=>
"Date",
242 'c.total_ht'=>
"Numeric",
'c.total_ttc'=>
"Numeric",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Text",
'c.note_private'=>
"Text",
'c.date_livraison'=>
'Date',
243 'pj.ref'=>
'Text',
'cd.description'=>
"Text",
'cd.product_type'=>
'Boolean',
'cd.tva_tx'=>
"Numeric",
'cd.qty'=>
"Numeric",
'cd.total_ht'=>
"Numeric",
244 'cd.total_tva'=>
"Numeric",
'cd.total_ttc'=>
"Numeric",
'p.ref'=>
'Text',
'p.label'=>
'Text',
245 'c.entity'=>
'List:entity:label:rowid',
248 $this->export_entities_array[$r] = array(
249 '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',
250 's.siren'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.siret'=>
'company',
'c.rowid'=>
"propal",
'c.ref'=>
"propal",
'c.ref_client'=>
"propal",
251 'c.fk_soc'=>
"propal",
'c.datec'=>
"propal",
'c.datep'=>
"propal",
'c.fin_validite'=>
"propal",
'c.total_ht'=>
"propal",
252 'c.total_ttc'=>
"propal",
'c.fk_statut'=>
"propal",
'c.note_public'=>
"propal",
'c.note_private'=>
"propal",
'c.date_livraison'=>
"propal",
253 'c.fk_user_author'=>
'user',
'uc.login'=>
'user',
254 'c.fk_user_valid'=>
'user',
'uv.login'=>
'user',
256 'cd.rowid'=>
'propal_line',
257 'cd.description'=>
"propal_line",
'cd.product_type'=>
'propal_line',
'cd.tva_tx'=>
"propal_line",
'cd.qty'=>
"propal_line",
258 'cd.total_ht'=>
"propal_line",
'cd.total_tva'=>
"propal_line",
'cd.total_ttc'=>
"propal_line",
'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product'
260 $this->export_dependencies_array[$r] = array(
'propal_line'=>
'cd.rowid',
'product'=>
'cd.rowid');
261 $keyforselect =
'propal';
262 $keyforelement =
'propal';
263 $keyforaliasextra =
'extra';
264 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
265 $keyforselect =
'propaldet';
266 $keyforelement =
'propal_line';
267 $keyforaliasextra =
'extra2';
268 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
269 $keyforselect =
'product';
270 $keyforelement =
'product';
271 $keyforaliasextra =
'extra3';
272 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
273 $keyforselect =
'societe';
274 $keyforelement =
'company';
275 $keyforaliasextra =
'extra4';
276 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
278 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
279 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s ';
280 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
281 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
282 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
283 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
285 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
286 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'propal as c';
287 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
288 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
289 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
290 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
291 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propal_extrafields as extra ON c.rowid = extra.fk_object';
292 $this->export_sql_end[$r] .=
', '.MAIN_DB_PREFIX.
'propaldet as cd';
293 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
294 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (cd.fk_product = p.rowid)';
295 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
296 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
297 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'propal').
')';
298 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
299 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
307 $this->import_code[$r] = $this->rights_class.
'_'.$r;
308 $this->import_label[$r] =
'Proposals';
309 $this->import_icon[$r] = $this->picto;
310 $this->import_entities_array[$r] = array();
311 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'propal',
'extra' => MAIN_DB_PREFIX.
'propal_extrafields');
312 $this->import_tables_creator_array[$r] = array(
'c'=>
'fk_user_author');
313 $this->import_fields_array[$r] = array(
315 'c.ref_client' =>
'RefCustomer',
316 'c.fk_soc' =>
'ThirdPartyName*',
317 'c.datec' =>
'DateCreation',
318 'c.datep' =>
'DatePropal',
319 'c.fin_validite' =>
'DateEndPropal',
320 'c.total_ht' =>
'TotalHT',
321 'c.total_ttc' =>
'TotalTTC',
322 'c.fk_statut' =>
'Status*',
323 'c.note_public' =>
'NotePublic',
324 'c.note_private' =>
'NotePrivate',
325 'c.date_livraison' =>
'DeliveryDate',
326 'c.fk_user_valid' =>
'ValidatedById'
328 if (isModEnabled(
"multicurrency")) {
329 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
330 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
331 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
332 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
333 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
336 $import_extrafield_sample = array();
337 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, ".$conf->entity.
")";
338 $resql = $this->db->query($sql);
340 while ($obj = $this->db->fetch_object($resql)) {
341 $fieldname =
'extra.'.$obj->name;
342 $fieldlabel = ucfirst($obj->label);
343 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
344 $import_extrafield_sample[$fieldname] = $fieldlabel;
348 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propal'];
349 $this->import_regex_array[$r] = [
'c.ref' =>
'[^ ]'];
351 'c.ref' =>
'PROV0077',
352 'c.ref_client' =>
'Client1',
353 'c.fk_soc' =>
'MyBigCompany',
354 'c.datec' =>
'2020-01-01',
355 'c.datep' =>
'2020-01-01',
356 'c.fin_validite' =>
'2020-01-01',
358 'c.total_ttc' =>
'0',
359 'c.fk_statut' =>
'1',
360 'c.note_public' =>
'',
361 'c.note_private' =>
'',
362 'c.date_livraison' =>
'2020-01-01',
363 'c.fk_user_valid' =>
'1',
364 'c.multicurrency_code' =>
'',
365 'c.multicurrency_tx' =>
'1',
366 'c.multicurrency_total_ht' =>
'0',
367 'c.multicurrency_total_tva' =>
'0',
368 'c.multicurrency_total_ttc' =>
'0'
370 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
371 $this->import_updatekeys_array[$r] = array(
'c.ref'=>
'Ref');
372 $this->import_convertvalue_array[$r] = array(
374 'rule'=>
'getrefifauto',
375 'class'=>(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON),
376 'path'=>
"/core/modules/propale/".(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' : $conf->global->PROPALE_ADDON).
'.php',
377 'classobject'=>
'Propal',
378 'pathobject'=>
'/comm/propal/class/propal.class.php',
381 'rule' =>
'fetchidfromref',
382 'file' =>
'/societe/class/societe.class.php',
383 'class' =>
'Societe',
385 'element' =>
'ThirdParty'
391 $this->import_code[$r] = $this->rights_class.
'line_'.$r;
392 $this->import_label[$r] =
"ProposalLines";
393 $this->import_icon[$r] = $this->picto;
394 $this->import_entities_array[$r] = array();
395 $this->import_tables_array[$r] = array(
396 'cd' => MAIN_DB_PREFIX.
'propaldet',
397 'extra' => MAIN_DB_PREFIX.
'propaldet_extrafields'
399 $this->import_fields_array[$r] = array(
400 'cd.fk_propal' =>
'Proposal*',
401 'cd.fk_parent_line' =>
'ParentLine',
402 'cd.fk_product' =>
'IdProduct',
403 'cd.description' =>
'LineDescription',
404 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
405 'cd.tva_tx' =>
'LineVATRate',
406 'cd.qty' =>
'LineQty',
407 'cd.remise_percent' =>
'Reduc. Percent',
408 'cd.price' =>
'Price',
409 'cd.subprice' =>
'Sub Price',
410 'cd.total_ht' =>
'LineTotalHT',
411 'cd.total_tva' =>
'LineTotalVAT',
412 'cd.total_ttc' =>
'LineTotalTTC',
413 'cd.date_start' =>
'Start Date',
414 'cd.date_end' =>
'End Date',
415 'cd.buy_price_ht' =>
'LineBuyPriceHT'
417 if (isModEnabled(
"multicurrency")) {
418 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
419 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
420 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
421 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
422 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
425 $import_extrafield_sample = array();
426 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, ".$conf->entity.
")";
427 $resql = $this->db->query($sql);
429 while ($obj = $this->db->fetch_object($resql)) {
430 $fieldname =
'extra.'.$obj->name;
431 $fieldlabel = ucfirst($obj->label);
432 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
433 $import_extrafield_sample[$fieldname] = $fieldlabel;
437 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propaldet');
438 $this->import_regex_array[$r] = array(
'cd.product_type' =>
'[0|1]$');
439 $import_sample = array(
440 'cd.fk_propal' =>
'PROV(0001)',
441 'cd.fk_parent_line' =>
'',
442 'cd.fk_product' =>
'',
443 'cd.description' =>
'Line description',
444 'cd.product_type' =>
'1',
447 'cd.remise_percent' =>
'0',
449 'cd.subprice' =>
'5000',
450 'cd.total_ht' =>
'10000',
451 'cd.total_tva' =>
'0',
452 'cd.total_ttc' =>
'10100',
453 'cd.date_start' =>
'',
455 'cd.buy_price_ht' =>
'7000',
456 'cd.multicurrency_code' =>
'JPY',
457 'cd.multicurrency_tx' =>
'1',
458 'cd.multicurrency_total_ht' =>
'10000',
459 'cd.multicurrency_total_tva' =>
'0',
460 'cd.multicurrency_total_ttc' =>
'10100'
462 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
463 $this->import_updatekeys_array[$r] = array(
'cd.fk_propal' =>
'Quotation Id',
'cd.fk_product' =>
'Product Id');
464 $this->import_convertvalue_array[$r] = array(
465 'cd.fk_propal' => array(
466 'rule'=>
'fetchidfromref',
467 'file'=>
'/comm/propal/class/propal.class.php',