31 include_once DOL_DOCUMENT_ROOT.
'/core/modules/DolibarrModules.class.php';
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(5, 4);
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] =
"azur";
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;
115 $this->boxes = array(
116 0=>array(
'file'=>
'box_graph_propales_permonth.php',
'enabledbydefaulton'=>
'Home'),
117 1=>array(
'file'=>
'box_propales.php',
'enabledbydefaulton'=>
'Home'),
121 $this->rights = array();
122 $this->rights_class =
'propale';
126 $this->rights[$r][0] = 21;
127 $this->rights[$r][1] =
'Read commercial proposals';
128 $this->rights[$r][2] =
'r';
129 $this->rights[$r][3] = 0;
130 $this->rights[$r][4] =
'lire';
133 $this->rights[$r][0] = 22;
134 $this->rights[$r][1] =
'Create and update commercial proposals';
135 $this->rights[$r][2] =
'w';
136 $this->rights[$r][3] = 0;
137 $this->rights[$r][4] =
'creer';
140 $this->rights[$r][0] = 24;
141 $this->rights[$r][1] =
'Validate commercial proposals';
142 $this->rights[$r][2] =
'd';
143 $this->rights[$r][3] = 0;
144 $this->rights[$r][4] =
'propal_advance';
145 $this->rights[$r][5] =
'validate';
148 $this->rights[$r][0] = 25;
149 $this->rights[$r][1] =
'Send commercial proposals to customers';
150 $this->rights[$r][2] =
'd';
151 $this->rights[$r][3] = 0;
152 $this->rights[$r][4] =
'propal_advance';
153 $this->rights[$r][5] =
'send';
156 $this->rights[$r][0] = 26;
157 $this->rights[$r][1] =
'Close commercial proposals';
158 $this->rights[$r][2] =
'd';
159 $this->rights[$r][3] = 0;
160 $this->rights[$r][4] =
'cloturer';
163 $this->rights[$r][0] = 27;
164 $this->rights[$r][1] =
'Delete commercial proposals';
165 $this->rights[$r][2] =
'd';
166 $this->rights[$r][3] = 0;
167 $this->rights[$r][4] =
'supprimer';
170 $this->rights[$r][0] = 28;
171 $this->rights[$r][1] =
'Exporting commercial proposals and attributes';
172 $this->rights[$r][2] =
'r';
173 $this->rights[$r][3] = 0;
174 $this->rights[$r][4] =
'export';
187 $this->export_code[$r] = $this->rights_class.
'_'.$r;
188 $this->export_label[$r] =
'ProposalsAndProposalsLines';
189 $this->export_permission[$r] = array(array(
"propale",
"export"));
190 $this->export_fields_array[$r] = array(
191 's.rowid'=>
"IdCompany",
's.nom'=>
'CompanyName',
's.address'=>
'Address',
's.zip'=>
'Zip',
's.town'=>
'Town',
'co.code'=>
'CountryCode',
's.phone'=>
'Phone',
192 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
'c.rowid'=>
"Id",
'c.ref'=>
"Ref",
'c.ref_client'=>
"RefCustomer",
193 'c.fk_soc'=>
"IdCompany",
'c.datec'=>
"DateCreation",
'c.datep'=>
"DatePropal",
'c.fin_validite'=>
"DateEndPropal",
'c.remise_percent'=>
"GlobalDiscount",
194 'c.total_ht'=>
"TotalHT",
'c.total'=>
"TotalTTC",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Note",
'c.date_livraison'=>
'DeliveryDate',
195 'c.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
'c.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin',
196 'pj.ref'=>
'ProjectRef',
'cd.rowid'=>
'LineId',
'cd.label'=>
"Label",
'cd.description'=>
"LineDescription",
'cd.product_type'=>
'TypeOfLineServiceOrProduct',
197 'cd.tva_tx'=>
"LineVATRate",
'cd.qty'=>
"LineQty",
'cd.total_ht'=>
"LineTotalHT",
'cd.total_tva'=>
"LineTotalVAT",
'cd.total_ttc'=>
"LineTotalTTC",
198 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel'
200 if (!empty($conf->multicurrency->enabled))
202 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
203 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
204 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
205 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
206 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
215 $this->export_TypeFields_array[$r] = array(
216 's.nom'=>
'Text',
's.address'=>
'Text',
's.zip'=>
'Text',
's.town'=>
'Text',
'co.code'=>
'Text',
's.phone'=>
'Text',
's.siren'=>
'Text',
's.siret'=>
'Text',
217 's.ape'=>
'Text',
's.idprof4'=>
'Text',
'c.ref'=>
"Text",
'c.ref_client'=>
"Text",
'c.datec'=>
"Date",
'c.datep'=>
"Date",
'c.fin_validite'=>
"Date",
218 'c.remise_percent'=>
"Numeric",
'c.total_ht'=>
"Numeric",
'c.total'=>
"Numeric",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Text",
'c.date_livraison'=>
'Date',
219 'pj.ref'=>
'Text',
'cd.description'=>
"Text",
'cd.product_type'=>
'Boolean',
'cd.tva_tx'=>
"Numeric",
'cd.qty'=>
"Numeric",
'cd.total_ht'=>
"Numeric",
220 'cd.total_tva'=>
"Numeric",
'cd.total_ttc'=>
"Numeric",
'p.ref'=>
'Text',
'p.label'=>
'Text'
222 $this->export_entities_array[$r] = array(
223 's.rowid'=>
"company",
's.nom'=>
'company',
's.address'=>
'company',
's.zip'=>
'company',
's.town'=>
'company',
'co.code'=>
'company',
's.phone'=>
'company',
224 's.siren'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.siret'=>
'company',
'c.rowid'=>
"propal",
'c.ref'=>
"propal",
'c.ref_client'=>
"propal",
225 'c.fk_soc'=>
"propal",
'c.datec'=>
"propal",
'c.datep'=>
"propal",
'c.fin_validite'=>
"propal",
'c.remise_percent'=>
"propal",
'c.total_ht'=>
"propal",
226 'c.total'=>
"propal",
'c.fk_statut'=>
"propal",
'c.note_public'=>
"propal",
'c.date_livraison'=>
"propal",
'pj.ref'=>
'project',
'cd.rowid'=>
'propal_line',
227 'cd.label'=>
"propal_line",
'cd.description'=>
"propal_line",
'cd.product_type'=>
'propal_line',
'cd.tva_tx'=>
"propal_line",
'cd.qty'=>
"propal_line",
228 'cd.total_ht'=>
"propal_line",
'cd.total_tva'=>
"propal_line",
'cd.total_ttc'=>
"propal_line",
'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product'
230 $this->export_dependencies_array[$r] = array(
'propal_line'=>
'cd.rowid',
'product'=>
'cd.rowid');
231 $keyforselect =
'propal'; $keyforelement =
'propal'; $keyforaliasextra =
'extra';
232 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
233 $keyforselect =
'propaldet'; $keyforelement =
'propal_line'; $keyforaliasextra =
'extra2';
234 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
235 $keyforselect =
'product'; $keyforelement =
'product'; $keyforaliasextra =
'extra3';
236 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
237 $keyforselect =
'societe'; $keyforelement =
'societe'; $keyforaliasextra =
'extra4';
238 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
240 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
241 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s ';
242 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
244 if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
245 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
246 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'propal as c';
247 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
248 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
249 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
250 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propal_extrafields as extra ON c.rowid = extra.fk_object';
251 $this->export_sql_end[$r] .=
', '.MAIN_DB_PREFIX.
'propaldet as cd';
252 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
253 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (cd.fk_product = p.rowid)';
254 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
255 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
256 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'propal').
')';
257 if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
264 $this->import_code[$r] = $this->rights_class.
'_'.$r;
265 $this->import_label[$r] =
'Proposals';
266 $this->import_icon[$r] = $this->picto;
267 $this->import_entities_array[$r] = [];
268 $this->import_tables_array[$r] = [
'c' => MAIN_DB_PREFIX.
'propal',
'extra' => MAIN_DB_PREFIX.
'propal_extrafields'];
269 $this->import_tables_creator_array[$r] = [
'c'=>
'fk_user_author'];
270 $this->import_fields_array[$r] = [
271 'c.ref' =>
'Document Ref*',
272 'c.ref_client' =>
'RefCustomer',
273 'c.fk_soc' =>
'ThirdPartyName*',
274 'c.datec' =>
'DateCreation',
275 'c.datep' =>
'DatePropal',
276 'c.fin_validite' =>
'DateEndPropal',
277 'c.remise_percent' =>
'GlobalDiscount',
278 'c.total_ht' =>
'TotalHT',
279 'c.total' =>
'TotalTTC',
280 'c.fk_statut' =>
'Status*',
281 'c.note_public' =>
'Note',
282 'c.date_livraison' =>
'DeliveryDate',
283 'c.fk_user_valid' =>
'ValidatedById'
285 if (!empty($conf->multicurrency->enabled)) {
286 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
287 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
288 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
289 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
290 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
293 $import_extrafield_sample = [];
294 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'propal' AND entity IN (0, ".$conf->entity.
")";
297 while ($obj = $this->
db->fetch_object(
$resql)) {
298 $fieldname =
'extra.'.$obj->name;
299 $fieldlabel = ucfirst($obj->label);
300 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
301 $import_extrafield_sample[$fieldname] = $fieldlabel;
305 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propal'];
306 $this->import_regex_array[$r] = [
'c.ref' =>
'[^ ]'];
308 'c.ref' =>
'PROV0077',
309 'c.ref_client' =>
'Client1',
310 'c.fk_soc' =>
'MyBigCompany',
311 'c.datec' =>
'2020-01-01',
312 'c.datep' =>
'2020-01-01',
313 'c.fin_validite' =>
'2020-01-01',
314 'c.remise_percent' =>
'',
317 'c.fk_statut' =>
'1',
318 'c.note_public' =>
'',
319 'c.date_livraison' =>
'2020-01-01',
320 'c.fk_user_valid' =>
'1',
321 'c.multicurrency_code' =>
'',
322 'c.multicurrency_tx' =>
'1',
323 'c.multicurrency_total_ht' =>
'0',
324 'c.multicurrency_total_tva' =>
'0',
325 'c.multicurrency_total_ttc' =>
'0'
327 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
328 $this->import_updatekeys_array[$r] = [
'c.ref'=>
'Ref'];
329 $this->import_convertvalue_array[$r] = [
331 'rule' =>
'fetchidfromref',
332 'file' =>
'/societe/class/societe.class.php',
333 'class' =>
'Societe',
335 'element' =>
'ThirdParty'
341 $this->import_code[$r] = $this->rights_class.
'line_'.$r;
342 $this->import_label[$r] =
"ProposalLine";
343 $this->import_icon[$r] = $this->picto;
344 $this->import_entities_array[$r] = [];
345 $this->import_tables_array[$r] = [
346 'cd' => MAIN_DB_PREFIX.
'propaldet',
347 'extra' => MAIN_DB_PREFIX.
'propaldet_extrafields'
349 $this->import_fields_array[$r] = [
350 'cd.fk_propal' =>
'Document Ref*',
351 'cd.fk_parent_line' =>
'PrParentLine',
352 'cd.fk_product' =>
'IdProduct',
353 'cd.label' =>
'Label',
354 'cd.description' =>
'LineDescription',
355 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
356 'cd.tva_tx' =>
'LineVATRate',
357 'cd.qty' =>
'LineQty',
358 'cd.remise_percent' =>
'Reduc. Percent',
359 'cd.remise' =>
'Reduc.',
360 'cd.price' =>
'Price',
361 'cd.subprice' =>
'Sub Price',
362 'cd.total_ht' =>
'LineTotalHT',
363 'cd.total_tva' =>
'LineTotalVAT',
364 'cd.total_ttc' =>
'LineTotalTTC',
365 'cd.date_start' =>
'Start Date',
366 'cd.date_end' =>
'End Date',
367 'cd.buy_price_ht' =>
'LineBuyPriceHT'
369 if (!empty($conf->multicurrency->enabled)) {
370 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
371 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
372 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
373 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
374 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
377 $import_extrafield_sample = [];
378 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'propaldet' AND entity IN (0, ".$conf->entity.
")";
381 while ($obj = $this->
db->fetch_object(
$resql)) {
382 $fieldname =
'extra.'.$obj->name;
383 $fieldlabel = ucfirst($obj->label);
384 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
385 $import_extrafield_sample[$fieldname] = $fieldlabel;
389 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'propaldet'];
390 $this->import_regex_array[$r] = [
'cd.product_type' =>
'[0|1]$'];
392 'cd.fk_propal' =>
'PROV(0001)',
393 'cd.fk_parent_line' =>
'',
394 'cd.fk_product' =>
'',
396 'cd.description' =>
'Line description',
397 'cd.product_type' =>
'1',
400 'cd.remise_percent' =>
'0',
403 'cd.subprice' =>
'5000',
404 'cd.total_ht' =>
'10000',
405 'cd.total_tva' =>
'0',
406 'cd.total_ttc' =>
'10100',
407 'cd.date_start' =>
'',
409 'cd.buy_price_ht' =>
'7000',
410 'cd.multicurrency_code' =>
'JPY',
411 'cd.multicurrency_tx' =>
'1',
412 'cd.multicurrency_total_ht' =>
'10000',
413 'cd.multicurrency_total_tva' =>
'0',
414 'cd.multicurrency_total_ttc' =>
'10100'
416 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
417 $this->import_updatekeys_array[$r] = [
'cd.fk_propal' =>
'Quotation Id',
'cd.fk_product' =>
'Product Id'];
418 $this->import_convertvalue_array[$r] = [
420 'rule'=>
'fetchidfromref',
421 'file'=>
'/comm/propal/class/propal.class.php',
437 public function init($options =
'')
439 global $conf, $langs;
442 $this->
remove($options);
445 $src = DOL_DOCUMENT_ROOT.
'/install/doctemplates/proposals/template_proposal.odt';
446 $dirodt = DOL_DATA_ROOT.
'/doctemplates/proposals';
447 $dest = $dirodt.
'/template_proposal.odt';
449 if (file_exists($src) && !file_exists($dest))
451 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
453 $result =
dol_copy($src, $dest, 0, 0);
456 $langs->load(
"errors");
457 $this->error = $langs->trans(
'ErrorFailToCopyFile', $src, $dest);
463 "DELETE FROM ".MAIN_DB_PREFIX.
"document_model WHERE nom = '".$this->db->escape($this->const[0][2]).
"' AND type = 'propal' AND entity = ".$conf->entity,
464 "INSERT INTO ".MAIN_DB_PREFIX.
"document_model (nom, type, entity) VALUES('".$this->
db->escape($this->
const[0][2]).
"','propal',".$conf->entity.
")",
467 return $this->
_init($sql, $options);
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
__construct($db)
Constructor.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.
Class to describe and enable module Propale.
_init($array_sql, $options= '')
Enables a module.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
init($options= '')
Function called when module is enabled.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)