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".($conf->entity > 1 ?
'/'.$conf->entity :
'').
"/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';
185 $this->rights[$r][0] = 29;
186 $this->rights[$r][1] =
'Reopen commercial proposals';
187 $this->rights[$r][2] =
'w';
188 $this->rights[$r][3] = 0;
189 $this->rights[$r][4] =
'propal_advance';
190 $this->rights[$r][5] =
'reopen';
202 $this->export_code[$r] = $this->rights_class.
'_'.$r;
203 $this->export_label[$r] =
'ProposalsAndProposalsLines';
204 $this->export_permission[$r] = array(array(
"propale",
"export"));
205 $this->export_fields_array[$r] = array(
206 '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',
207 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
'c.rowid'=>
"Id",
'c.ref'=>
"Ref",
'c.ref_client'=>
"RefCustomer",
208 'c.fk_soc'=>
"IdCompany",
'c.datec'=>
"DateCreation",
'c.datep'=>
"DatePropal",
'c.fin_validite'=>
"DateEndPropal",
209 'c.total_ht'=>
"TotalHT",
'c.total_ttc'=>
"TotalTTC",
210 'cir.label'=>
'Source',
212 if (isModEnabled(
"multicurrency")) {
213 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
214 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
215 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
216 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
217 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
219 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
220 'c.fk_statut'=>
'Status',
'c.note_public'=>
"NotePublic",
'c.note_private'=>
"NotePrivate",
'c.date_livraison'=>
'DeliveryDate',
221 'c.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
222 'c.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin'));
223 if (isModEnabled(
"project")) {
224 $this->export_fields_array[$r][
'pj.ref'] =
'ProjectRef';
226 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
227 'cd.rowid'=>
'LineId',
'cd.description'=>
"LineDescription",
'cd.product_type'=>
'TypeOfLineServiceOrProduct',
228 'cd.tva_tx'=>
"LineVATRate",
'cd.qty'=>
"LineQty",
'cd.total_ht'=>
"LineTotalHT",
'cd.total_tva'=>
"LineTotalVAT",
'cd.total_ttc'=>
"LineTotalTTC",
230 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
231 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel'
235 $nbofallowedentities = count(explode(
',',
getEntity(
'propal')));
236 if (isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
237 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
247 $this->export_TypeFields_array[$r] = array(
248 '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',
249 's.ape'=>
'Text',
's.idprof4'=>
'Text',
'c.ref'=>
"Text",
'c.ref_client'=>
"Text",
'c.datec'=>
"Date",
'c.datep'=>
"Date",
'c.fin_validite'=>
"Date",
250 'c.total_ht'=>
"Numeric",
'c.total_ttc'=>
"Numeric",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Text",
'c.note_private'=>
"Text",
'c.date_livraison'=>
'Date',
251 'pj.ref'=>
'Text',
'cd.description'=>
"Text",
'cd.product_type'=>
'Boolean',
'cd.tva_tx'=>
"Numeric",
'cd.qty'=>
"Numeric",
'cd.total_ht'=>
"Numeric",
252 'cd.total_tva'=>
"Numeric",
'cd.total_ttc'=>
"Numeric",
'p.ref'=>
'Text',
'p.label'=>
'Text',
253 'c.entity'=>
'List:entity:label:rowid',
256 $this->export_entities_array[$r] = array(
257 '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',
258 's.siren'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.siret'=>
'company',
'c.rowid'=>
"propal",
'c.ref'=>
"propal",
'c.ref_client'=>
"propal",
259 'c.fk_soc'=>
"propal",
'c.datec'=>
"propal",
'c.datep'=>
"propal",
'c.fin_validite'=>
"propal",
'c.total_ht'=>
"propal",
260 'c.total_ttc'=>
"propal",
'c.fk_statut'=>
"propal",
'c.note_public'=>
"propal",
'c.note_private'=>
"propal",
'c.date_livraison'=>
"propal",
261 'c.fk_user_author'=>
'user',
'uc.login'=>
'user',
262 'c.fk_user_valid'=>
'user',
'uv.login'=>
'user',
264 'cd.rowid'=>
'propal_line',
265 'cd.description'=>
"propal_line",
'cd.product_type'=>
'propal_line',
'cd.tva_tx'=>
"propal_line",
'cd.qty'=>
"propal_line",
266 'cd.total_ht'=>
"propal_line",
'cd.total_tva'=>
"propal_line",
'cd.total_ttc'=>
"propal_line",
'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product'
268 $this->export_dependencies_array[$r] = array(
'propal_line'=>
'cd.rowid',
'product'=>
'cd.rowid');
269 $keyforselect =
'propal';
270 $keyforelement =
'propal';
271 $keyforaliasextra =
'extra';
272 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
273 $keyforselect =
'propaldet';
274 $keyforelement =
'propal_line';
275 $keyforaliasextra =
'extra2';
276 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
277 $keyforselect =
'product';
278 $keyforelement =
'product';
279 $keyforaliasextra =
'extra3';
280 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
281 $keyforselect =
'societe';
282 $keyforelement =
'company';
283 $keyforaliasextra =
'extra4';
284 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
286 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
287 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s ';
288 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
289 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
290 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
291 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
293 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
294 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'propal as c';
295 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
296 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
297 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
298 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
299 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propal_extrafields as extra ON c.rowid = extra.fk_object';
300 $this->export_sql_end[$r] .=
', '.MAIN_DB_PREFIX.
'propaldet as cd';
301 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
302 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (cd.fk_product = p.rowid)';
303 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
304 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
305 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'propal').
')';
306 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
307 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
315 $this->import_code[$r] = $this->rights_class.
'_'.$r;
316 $this->import_label[$r] =
'Proposals';
317 $this->import_icon[$r] = $this->picto;
318 $this->import_entities_array[$r] = array();
319 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'propal',
'extra' => MAIN_DB_PREFIX.
'propal_extrafields');
320 $this->import_tables_creator_array[$r] = array(
'c'=>
'fk_user_author');
321 $this->import_fields_array[$r] = array(
323 'c.ref_client' =>
'RefCustomer',
324 'c.fk_soc' =>
'ThirdPartyName*',
325 'c.datec' =>
'DateCreation',
326 'c.datep' =>
'DatePropal',
327 'c.fin_validite' =>
'DateEndPropal',
328 'c.total_ht' =>
'TotalHT',
329 'c.total_ttc' =>
'TotalTTC',
330 'c.fk_statut' =>
'Status*',
331 'c.note_public' =>
'NotePublic',
332 'c.note_private' =>
'NotePrivate',
333 'c.date_livraison' =>
'DeliveryDate',
334 'c.fk_user_valid' =>
'ValidatedById'
336 if (isModEnabled(
"multicurrency")) {
337 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
338 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
339 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
340 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
341 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
344 $import_extrafield_sample = array();
345 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, ".
$conf->entity.
")";
346 $resql = $this->db->query($sql);
348 while ($obj = $this->db->fetch_object($resql)) {
349 $fieldname =
'extra.'.$obj->name;
350 $fieldlabel = ucfirst($obj->label);
351 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
352 $import_extrafield_sample[$fieldname] = $fieldlabel;
356 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propal'];
357 $this->import_regex_array[$r] = [
'c.ref' =>
'[^ ]'];
359 'c.ref' =>
'PROV0077',
360 'c.ref_client' =>
'Client1',
361 'c.fk_soc' =>
'MyBigCompany',
362 'c.datec' =>
'2020-01-01',
363 'c.datep' =>
'2020-01-01',
364 'c.fin_validite' =>
'2020-01-01',
366 'c.total_ttc' =>
'0',
367 'c.fk_statut' =>
'1',
368 'c.note_public' =>
'',
369 'c.note_private' =>
'',
370 'c.date_livraison' =>
'2020-01-01',
371 'c.fk_user_valid' =>
'1',
372 'c.multicurrency_code' =>
'',
373 'c.multicurrency_tx' =>
'1',
374 'c.multicurrency_total_ht' =>
'0',
375 'c.multicurrency_total_tva' =>
'0',
376 'c.multicurrency_total_ttc' =>
'0'
378 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
379 $this->import_updatekeys_array[$r] = array(
'c.ref'=>
'Ref');
380 $this->import_convertvalue_array[$r] = array(
382 'rule'=>
'getrefifauto',
384 'path'=>
"/core/modules/propale/".(!
getDolGlobalString(
'PROPALE_ADDON') ?
'mod_propale_marbre' :
$conf->global->PROPALE_ADDON).
'.php',
385 'classobject'=>
'Propal',
386 'pathobject'=>
'/comm/propal/class/propal.class.php',
389 'rule' =>
'fetchidfromref',
390 'file' =>
'/societe/class/societe.class.php',
391 'class' =>
'Societe',
393 'element' =>
'ThirdParty'
399 $this->import_code[$r] = $this->rights_class.
'line_'.$r;
400 $this->import_label[$r] =
"ProposalLines";
401 $this->import_icon[$r] = $this->picto;
402 $this->import_entities_array[$r] = array();
403 $this->import_tables_array[$r] = array(
404 'cd' => MAIN_DB_PREFIX.
'propaldet',
405 'extra' => MAIN_DB_PREFIX.
'propaldet_extrafields'
407 $this->import_fields_array[$r] = array(
408 'cd.fk_propal' =>
'Proposal*',
409 'cd.fk_parent_line' =>
'ParentLine',
410 'cd.fk_product' =>
'IdProduct',
411 'cd.description' =>
'LineDescription',
412 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
413 'cd.tva_tx' =>
'LineVATRate',
414 'cd.qty' =>
'LineQty',
415 'cd.remise_percent' =>
'Reduc. Percent',
416 'cd.price' =>
'Price',
417 'cd.subprice' =>
'Sub Price',
418 'cd.total_ht' =>
'LineTotalHT',
419 'cd.total_tva' =>
'LineTotalVAT',
420 'cd.total_ttc' =>
'LineTotalTTC',
421 'cd.date_start' =>
'Start Date',
422 'cd.date_end' =>
'End Date',
423 'cd.buy_price_ht' =>
'LineBuyPriceHT'
425 if (isModEnabled(
"multicurrency")) {
426 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
427 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
428 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
429 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
430 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
433 $import_extrafield_sample = array();
434 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, ".
$conf->entity.
")";
435 $resql = $this->db->query($sql);
437 while ($obj = $this->db->fetch_object($resql)) {
438 $fieldname =
'extra.'.$obj->name;
439 $fieldlabel = ucfirst($obj->label);
440 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
441 $import_extrafield_sample[$fieldname] = $fieldlabel;
445 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propaldet');
446 $this->import_regex_array[$r] = array(
'cd.product_type' =>
'[0|1]$');
447 $import_sample = array(
448 'cd.fk_propal' =>
'PROV(0001)',
449 'cd.fk_parent_line' =>
'',
450 'cd.fk_product' =>
'',
451 'cd.description' =>
'Line description',
452 'cd.product_type' =>
'1',
455 'cd.remise_percent' =>
'0',
457 'cd.subprice' =>
'5000',
458 'cd.total_ht' =>
'10000',
459 'cd.total_tva' =>
'0',
460 'cd.total_ttc' =>
'10100',
461 'cd.date_start' =>
'',
463 'cd.buy_price_ht' =>
'7000',
464 'cd.multicurrency_code' =>
'JPY',
465 'cd.multicurrency_tx' =>
'1',
466 'cd.multicurrency_total_ht' =>
'10000',
467 'cd.multicurrency_total_tva' =>
'0',
468 'cd.multicurrency_total_ttc' =>
'10100'
470 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
471 $this->import_updatekeys_array[$r] = array(
'cd.fk_propal' =>
'Quotation Id',
'cd.fk_product' =>
'Product Id');
472 $this->import_convertvalue_array[$r] = array(
473 'cd.fk_propal' => array(
474 'rule'=>
'fetchidfromref',
475 'file'=>
'/comm/propal/class/propal.class.php',