dolibarr  17.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
6  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7  * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
8  * Copyright (C) 2010-2023 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2010-2022 Philippe Grand <philippe.grand@atoo-net.com>
10  * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
11  * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
12  * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
13  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
14  * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
15  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
16  * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
17  * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <https://www.gnu.org/licenses/>.
31  */
32 
33 
40 // Load Dolibarr environment
41 require '../../main.inc.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
48 require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
49 require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
50 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
52 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
53 if (isModEnabled('project')) {
54  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
55  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
56 }
57 
58 if (isModEnabled('variants')) {
59  require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
60 }
61 
62 // Load translation files required by the page
63 $langs->loadLangs(array('companies', 'propal', 'compta', 'bills', 'orders', 'products', 'deliveries', 'sendings', 'other'));
64 if (isModEnabled('incoterm')) {
65  $langs->load('incoterm');
66 }
67 if (isModEnabled('margin')) {
68  $langs->load('margins');
69 }
70 
71 $error = 0;
72 
73 $id = GETPOST('id', 'int');
74 $ref = GETPOST('ref', 'alpha');
75 $socid = GETPOST('socid', 'int');
76 $action = GETPOST('action', 'aZ09');
77 $cancel = GETPOST('cancel', 'alpha');
78 $origin = GETPOST('origin', 'alpha');
79 $originid = GETPOST('originid', 'int');
80 $confirm = GETPOST('confirm', 'alpha');
81 $lineid = GETPOST('lineid', 'int');
82 $contactid = GETPOST('contactid', 'int');
83 $projectid = GETPOST('projectid', 'int');
84 $rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
85 
86 // PDF
87 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
88 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
89 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
90 
91 $object = new Propal($db);
92 $extrafields = new ExtraFields($db);
93 
94 // fetch optionals attributes and labels
95 $extrafields->fetch_name_optionals_label($object->table_element);
96 
97 // Load object
98 if ($id > 0 || !empty($ref)) {
99  $ret = $object->fetch($id, $ref);
100  if ($ret > 0) {
101  $ret = $object->fetch_thirdparty();
102  }
103  if ($ret <= 0) {
104  setEventMessages($object->error, $object->errors, 'errors');
105  $action = '';
106  }
107 }
108 
109 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
110 $hookmanager->initHooks(array('propalcard', 'globalcard'));
111 
112 $usercanread = $user->hasRight("propal", "lire");
113 $usercancreate = $user->hasRight("propal", "creer");
114 $usercandelete = $user->hasRight("propal", "supprimer");
115 
116 $usercanclose = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->close)));
117 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)));
118 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->send)));
119 
120 $usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
121 $usercancreateorder = $user->hasRight('commande', 'creer');
122 $usercancreateinvoice = $user->hasRight('facture', 'creer');
123 $usercancreatecontract = $user->hasRight('contrat', 'creer');
124 $usercancreateintervention = $user->hasRight('ficheinter', 'creer');
125 $usercancreatepurchaseorder = ($user->hasRight('fournisseur', 'commande', 'creer') || $user->hasRight('supplier_order', 'creer'));
126 
127 $permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
128 $permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php
129 $permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
130 
131 // Security check
132 if (!empty($user->socid)) {
133  $socid = $user->socid;
134 }
135 restrictedArea($user, 'propal', $object->id);
136 
137 
138 /*
139  * Actions
140  */
141 
142 $parameters = array('socid' => $socid);
143 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
144 if ($reshook < 0) {
145  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
146 }
147 
148 if (empty($reshook)) {
149  $backurlforlist = DOL_URL_ROOT.'/comm/propal/list.php';
150 
151  if (empty($backtopage) || ($cancel && empty($id))) {
152  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
153  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
154  $backtopage = $backurlforlist;
155  } else {
156  $backtopage = DOL_URL_ROOT.'/comm/propal/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
157  }
158  }
159  }
160 
161  if ($cancel) {
162  if (!empty($backtopageforcancel)) {
163  header("Location: ".$backtopageforcancel);
164  exit;
165  } elseif (!empty($backtopage)) {
166  header("Location: ".$backtopage);
167  exit;
168  }
169  $action = '';
170  }
171 
172  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
173 
174  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
175 
176  include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
177 
178  // Action clone object
179  if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
180  if (!GETPOST('socid', 3)) {
181  setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
182  } else {
183  if ($object->id > 0) {
184  if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY)) {
185  //Get difference between old and new delivery date and change lines according to difference
186  $date_delivery = dol_mktime(
187  12,
188  0,
189  0,
190  GETPOST('date_deliverymonth', 'int'),
191  GETPOST('date_deliveryday', 'int'),
192  GETPOST('date_deliveryyear', 'int')
193  );
194  $date_delivery_old = (empty($object->delivery_date) ? $object->date_livraison : $object->delivery_date);
195  if (!empty($date_delivery_old) && !empty($date_delivery)) {
196  //Attempt to get the date without possible hour rounding errors
197  $old_date_delivery = dol_mktime(
198  12,
199  0,
200  0,
201  dol_print_date($date_delivery_old, '%m'),
202  dol_print_date($date_delivery_old, '%d'),
203  dol_print_date($date_delivery_old, '%Y')
204  );
205  //Calculate the difference and apply if necessary
206  $difference = $date_delivery - $old_date_delivery;
207  if ($difference != 0) {
208  $object->date_livraison = $date_delivery;
209  $object->delivery_date = $date_delivery;
210  foreach ($object->lines as $line) {
211  if (isset($line->date_start)) {
212  $line->date_start = $line->date_start + $difference;
213  }
214  if (isset($line->date_end)) {
215  $line->date_end = $line->date_end + $difference;
216  }
217  }
218  }
219  }
220  }
221 
222  $result = $object->createFromClone($user, $socid, (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : null), (GETPOST('update_prices', 'aZ') ? true : false));
223  if ($result > 0) {
224  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
225  exit();
226  } else {
227  if (count($object->errors) > 0) {
228  setEventMessages($object->error, $object->errors, 'errors');
229  }
230  $action = '';
231  }
232  }
233  }
234  } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) {
235  // Delete proposal
236  $result = $object->delete($user);
237  if ($result > 0) {
238  header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1');
239  exit();
240  } else {
241  $langs->load("errors");
242  setEventMessages($object->error, $object->errors, 'errors');
243  }
244  } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
245  // Remove line
246  $result = $object->deleteline($lineid);
247  // reorder lines
248  if ($result > 0) {
249  $object->line_order(true);
250  } else {
251  $langs->load("errors");
252  setEventMessages($object->error, $object->errors, 'errors');
253  }
254 
255  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
256  // Define output language
257  $outputlangs = $langs;
258  if (getDolGlobalInt('MAIN_MULTILANGS')) {
259  $outputlangs = new Translate("", $conf);
260  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
261  $outputlangs->setDefaultLang($newlang);
262  }
263  $ret = $object->fetch($id); // Reload to get new records
264  if ($ret > 0) {
265  $object->fetch_thirdparty();
266  }
267  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
268  }
269 
270  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
271  exit();
272  } elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) {
273  // Validation
274  $idwarehouse = GETPOST('idwarehouse', 'int');
275  $result = $object->valid($user);
276  if ( $result > 0 && ! empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) ) {
277  $result = $object->closeProposal($user, $object::STATUS_SIGNED);
278  }
279  if ($result >= 0) {
280  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
281  $outputlangs = $langs;
282  $newlang = '';
283  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
284  $newlang = GETPOST('lang_id', 'aZ09');
285  }
286  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
287  $newlang = $object->thirdparty->default_lang;
288  }
289  if (!empty($newlang)) {
290  $outputlangs = new Translate("", $conf);
291  $outputlangs->setDefaultLang($newlang);
292  }
293  $model = $object->model_pdf;
294  $ret = $object->fetch($id); // Reload to get new records
295  if ($ret > 0) {
296  $object->fetch_thirdparty();
297  }
298 
299  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
300  }
301  } else {
302  $langs->load("errors");
303  if (count($object->errors) > 0) {
304  setEventMessages($object->error, $object->errors, 'errors');
305  } else {
306  setEventMessages($langs->trans($object->error), null, 'errors');
307  }
308  }
309  } elseif ($action == 'setdate' && $usercancreate) {
310  $datep = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
311 
312  if (empty($datep)) {
313  $error++;
314  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
315  }
316 
317  if (!$error) {
318  $result = $object->set_date($user, $datep);
319  if ($result > 0 && !empty($object->duree_validite) && !empty($object->fin_validite)) {
320  $datev = $datep + ($object->duree_validite * 24 * 3600);
321  $result = $object->set_echeance($user, $datev, 1);
322  }
323  if ($result < 0) {
324  dol_print_error($db, $object->error);
325  } elseif (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
326  $outputlangs = $langs;
327  $newlang = '';
328  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
329  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) $newlang = $object->thirdparty->default_lang;
330  if (!empty($newlang)) {
331  $outputlangs = new Translate("", $conf);
332  $outputlangs->setDefaultLang($newlang);
333  }
334  $model = $object->model_pdf;
335  $ret = $object->fetch($id); // Reload to get new records
336  if ($ret > 0) {
337  $object->fetch_thirdparty();
338  }
339 
340  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
341  }
342  }
343  } elseif ($action == 'setecheance' && $usercancreate) {
344  $result = $object->set_echeance($user, dol_mktime(12, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int')));
345  if ($result >= 0) {
346  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
347  $outputlangs = $langs;
348  $newlang = '';
349  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
350  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) $newlang = $object->thirdparty->default_lang;
351  if (!empty($newlang)) {
352  $outputlangs = new Translate("", $conf);
353  $outputlangs->setDefaultLang($newlang);
354  }
355  $model = $object->model_pdf;
356  $ret = $object->fetch($id); // Reload to get new records
357  if ($ret > 0) {
358  $object->fetch_thirdparty();
359  }
360 
361  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
362  }
363  } else {
364  setEventMessages($object->error, $object->errors, 'errors');
365  }
366  } elseif ($action == 'setdate_livraison' && $usercancreate) {
367  $result = $object->setDeliveryDate($user, dol_mktime(12, 0, 0, GETPOST('date_livraisonmonth', 'int'), GETPOST('date_livraisonday', 'int'), GETPOST('date_livraisonyear', 'int')));
368  if ($result < 0) {
369  dol_print_error($db, $object->error);
370  }
371  } elseif ($action == 'setref_client' && $usercancreate) {
372  // Positionne ref client
373  $result = $object->set_ref_client($user, GETPOST('ref_client'));
374  if ($result < 0) {
375  setEventMessages($object->error, $object->errors, 'errors');
376  }
377  } elseif ($action == 'set_incoterms' && isModEnabled('incoterm') && $usercancreate) {
378  // Set incoterm
379  $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
380  } elseif ($action == 'add' && $usercancreate) {
381  // Create proposal
382  $object->socid = $socid;
383  $object->fetch_thirdparty();
384 
385  $datep = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
386  $date_delivery = dol_mktime(12, 0, 0, GETPOST('date_livraisonmonth'), GETPOST('date_livraisonday'), GETPOST('date_livraisonyear'));
387  $duration = GETPOST('duree_validite', 'int');
388 
389  if (empty($datep)) {
390  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePropal")), null, 'errors');
391  $action = 'create';
392  $error++;
393  }
394  if (empty($duration)) {
395  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ValidityDuration")), null, 'errors');
396  $action = 'create';
397  $error++;
398  }
399 
400  if ($socid < 1) {
401  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), null, 'errors');
402 
403  $action = 'create';
404  $error++;
405  }
406 
407  if (!$error) {
408  $db->begin();
409 
410  // If we select proposal to clone during creation (when option PROPAL_CLONE_ON_CREATE_PAGE is on)
411  if (GETPOST('createmode') == 'copy' && GETPOST('copie_propal')) {
412  if ($object->fetch(GETPOST('copie_propal', 'int')) > 0) {
413  $object->ref = GETPOST('ref');
414  $object->datep = $datep;
415  $object->date = $datep;
416  $object->date_livraison = $date_delivery; // deprecated
417  $object->delivery_date = $date_delivery;
418  $object->availability_id = GETPOST('availability_id');
419  $object->demand_reason_id = GETPOST('demand_reason_id');
420  $object->fk_delivery_address = GETPOST('fk_address', 'int');
421  $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
422  $object->warehouse_id = GETPOST('warehouse_id', 'int');
423  $object->duree_validite = $duration;
424  $object->cond_reglement_id = GETPOST('cond_reglement_id');
425  $object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha');
426  $object->mode_reglement_id = GETPOST('mode_reglement_id');
427  $object->fk_account = GETPOST('fk_account', 'int');
428  $object->remise_absolue = price2num(GETPOST('remise_absolue'), 'MU', 2); // deprecated
429  $object->remise_percent = price2num(GETPOST('remise_percent'), '', 2);
430  $object->socid = GETPOST('socid', 'int');
431  $object->contact_id = GETPOST('contactid', 'int');
432  $object->fk_project = GETPOST('projectid', 'int');
433  $object->model_pdf = GETPOST('model', 'alphanohtml');
434  $object->author = $user->id; // deprecated
435  $object->user_author_id = $user->id;
436  $object->note_private = GETPOST('note_private', 'restricthtml');
437  $object->note_public = GETPOST('note_public', 'restricthtml');
438  $object->statut = Propal::STATUS_DRAFT;
439  $object->fk_incoterms = GETPOST('incoterm_id', 'int');
440  $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
441  } else {
442  setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_propal')), null, 'errors');
443  }
444  } else {
445  $object->ref = GETPOST('ref');
446  $object->ref_client = GETPOST('ref_client');
447  $object->datep = $datep;
448  $object->date = $datep;
449  $object->date_livraison = $date_delivery;
450  $object->delivery_date = $date_delivery;
451  $object->availability_id = GETPOST('availability_id', 'int');
452  $object->demand_reason_id = GETPOST('demand_reason_id', 'int');
453  $object->fk_delivery_address = GETPOST('fk_address', 'int');
454  $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
455  $object->warehouse_id = GETPOST('warehouse_id', 'int');
456  $object->duree_validite = price2num(GETPOST('duree_validite', 'alpha'));
457  $object->cond_reglement_id = GETPOST('cond_reglement_id', 'int');
458  $object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha');
459  $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int');
460  $object->fk_account = GETPOST('fk_account', 'int');
461  $object->contact_id = GETPOST('contactid', 'int');
462  $object->fk_project = GETPOST('projectid', 'int');
463  $object->model_pdf = GETPOST('model');
464  $object->author = $user->id; // deprecated
465  $object->note_private = GETPOST('note_private', 'restricthtml');
466  $object->note_public = GETPOST('note_public', 'restricthtml');
467  $object->fk_incoterms = GETPOST('incoterm_id', 'int');
468  $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
469 
470  $object->origin = GETPOST('origin');
471  $object->origin_id = GETPOST('originid');
472 
473  // Multicurrency
474  if (isModEnabled("multicurrency")) {
475  $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
476  }
477 
478  // Fill array 'array_options' with data from add form
479  $ret = $extrafields->setOptionalsFromPost(null, $object);
480  if ($ret < 0) {
481  $error++;
482  $action = 'create';
483  }
484  }
485 
486  if (!$error) {
487  if ($origin && $originid) {
488  // Parse element/subelement (ex: project_task)
489  $element = $subelement = $origin;
490  if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
491  $element = $regs [1];
492  $subelement = $regs [2];
493  }
494 
495  // For compatibility
496  if ($element == 'order') {
497  $element = $subelement = 'commande';
498  }
499  if ($element == 'propal') {
500  $element = 'comm/propal';
501  $subelement = 'propal';
502  }
503  if ($element == 'contract') {
504  $element = $subelement = 'contrat';
505  }
506  if ($element == 'inter') {
507  $element = $subelement = 'ficheinter';
508  }
509  if ($element == 'shipping') {
510  $element = $subelement = 'expedition';
511  }
512 
513  $object->origin = $origin;
514  $object->origin_id = $originid;
515 
516  // Possibility to add external linked objects with hooks
517  $object->linked_objects [$object->origin] = $object->origin_id;
518  if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
519  $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
520  }
521 
522  $id = $object->create($user);
523  if ($id > 0) {
524  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
525 
526  $classname = ucfirst($subelement);
527  $srcobject = new $classname($db);
528 
529  dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
530  $result = $srcobject->fetch($object->origin_id);
531 
532  if ($result > 0) {
533  $lines = $srcobject->lines;
534  if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
535  $srcobject->fetch_lines();
536  $lines = $srcobject->lines;
537  }
538 
539  $fk_parent_line = 0;
540  $num = count($lines);
541  for ($i = 0; $i < $num; $i++) {
542  $label = (!empty($lines[$i]->label) ? $lines[$i]->label : '');
543  $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
544 
545  // Positive line
546  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
547 
548  // Date start
549  $date_start = false;
550  if ($lines[$i]->date_debut_prevue) {
551  $date_start = $lines[$i]->date_debut_prevue;
552  }
553  if ($lines[$i]->date_debut_reel) {
554  $date_start = $lines[$i]->date_debut_reel;
555  }
556  if ($lines[$i]->date_start) {
557  $date_start = $lines[$i]->date_start;
558  }
559 
560  // Date end
561  $date_end = false;
562  if ($lines[$i]->date_fin_prevue) {
563  $date_end = $lines[$i]->date_fin_prevue;
564  }
565  if ($lines[$i]->date_fin_reel) {
566  $date_end = $lines[$i]->date_fin_reel;
567  }
568  if ($lines[$i]->date_end) {
569  $date_end = $lines[$i]->date_end;
570  }
571 
572  // Reset fk_parent_line for no child products and special product
573  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
574  $fk_parent_line = 0;
575  }
576 
577  // Extrafields
578  if (method_exists($lines[$i], 'fetch_optionals')) {
579  $lines[$i]->fetch_optionals();
580  $array_options = $lines[$i]->array_options;
581  }
582 
583  $tva_tx = $lines[$i]->tva_tx;
584  if (!empty($lines[$i]->vat_src_code) && !preg_match('/\(/', $tva_tx)) {
585  $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';
586  }
587 
588  $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);
589 
590  if ($result > 0) {
591  $lineid = $result;
592  } else {
593  $lineid = 0;
594  $error++;
595  break;
596  }
597 
598  // Defined the new fk_parent_line
599  if ($result > 0 && $lines[$i]->product_type == 9) {
600  $fk_parent_line = $result;
601  }
602  }
603 
604  // Hooks
605  $parameters = array('objFrom' => $srcobject);
606  $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
607  // modified by hook
608  if ($reshook < 0) {
609  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
610  $error++;
611  }
612  } else {
613  setEventMessages($srcobject->error, $srcobject->errors, 'errors');
614  $error++;
615  }
616  } else {
617  setEventMessages($object->error, $object->errors, 'errors');
618  $error++;
619  }
620  } else {
621  // Standard creation
622  $id = $object->create($user);
623  }
624 
625  if ($id > 0) {
626  // Insert default contacts if defined
627  if (GETPOST('contactid') > 0) {
628  $result = $object->add_contact(GETPOST('contactid'), 'CUSTOMER', 'external');
629  if ($result < 0) {
630  $error++;
631  setEventMessages($langs->trans("ErrorFailedToAddContact"), null, 'errors');
632  }
633  }
634 
635  if (!empty($conf->global->PROPOSAL_AUTO_ADD_AUTHOR_AS_CONTACT)) {
636  $result = $object->add_contact($user->id, 'SALESREPFOLL', 'internal');
637  if ($result < 0) {
638  $error++;
639  setEventMessages($langs->trans("ErrorFailedToAddUserAsContact"), null, 'errors');
640  }
641  }
642 
643  if (!$error) {
644  $db->commit();
645 
646  // Define output language
647  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
648  $outputlangs = $langs;
649  $newlang = '';
650  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
651  $newlang = GETPOST('lang_id', 'aZ09');
652  }
653  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
654  $newlang = $object->thirdparty->default_lang;
655  }
656  if (!empty($newlang)) {
657  $outputlangs = new Translate("", $conf);
658  $outputlangs->setDefaultLang($newlang);
659  }
660  $model = $object->model_pdf;
661 
662  $ret = $object->fetch($id); // Reload to get new records
663  $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
664  if ($result < 0) {
665  dol_print_error($db, $result);
666  }
667  }
668 
669  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
670  exit();
671  } else {
672  $db->rollback();
673  $action = 'create';
674  }
675  } else {
676  setEventMessages($object->error, $object->errors, 'errors');
677  $db->rollback();
678  $action = 'create';
679  }
680  }
681  }
682  } elseif ($action == 'classifybilled' && $usercanclose) {
683  // Classify billed
684  $db->begin();
685 
686  $result = $object->classifyBilled($user, 0, '');
687  if ($result < 0) {
688  setEventMessages($object->error, $object->errors, 'errors');
689  $error++;
690  }
691 
692  if (!$error) {
693  $db->commit();
694  } else {
695  $db->rollback();
696  }
697  } elseif ($action == 'confirm_closeas' && $usercanclose && !GETPOST('cancel', 'alpha')) {
698  // Close proposal
699  if (!(GETPOST('statut', 'int') > 0)) {
700  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors');
701  $action = 'closeas';
702  } elseif (GETPOST('statut', 'int') == $object::STATUS_SIGNED || GETPOST('statut', 'int') == $object::STATUS_NOTSIGNED) {
703  // prevent browser refresh from closing proposal several times
704  if ($object->statut == $object::STATUS_VALIDATED || ( ! empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) && $object->statut == $object::STATUS_DRAFT)) {
705  $db->begin();
706 
707  $result = $object->closeProposal($user, GETPOST('statut', 'int'), GETPOST('note_private', 'restricthtml'));
708  if ($result < 0) {
709  setEventMessages($object->error, $object->errors, 'errors');
710  $error++;
711  }
712 
713  $deposit = null;
714  $locationTarget = '';
715 
716  $deposit_percent_from_payment_terms = getDictionaryValue('c_payment_term', 'deposit_percent', $object->cond_reglement_id);
717 
718  if (
719  !$error && GETPOST('statut', 'int') == $object::STATUS_SIGNED && GETPOST('generate_deposit', 'alpha') == 'on'
720  && !empty($deposit_percent_from_payment_terms) && isModEnabled('facture') && !empty($user->rights->facture->creer)
721  ) {
722  require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
723 
724  $date = dol_mktime(0, 0, 0, GETPOST('datefmonth', 'int'), GETPOST('datefday', 'int'), GETPOST('datefyear', 'int'));
725  $forceFields = array();
726 
727  if (GETPOSTISSET('date_pointoftax')) {
728  $forceFields['date_pointoftax'] = dol_mktime(0, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'));
729  }
730 
731  $deposit = Facture::createDepositFromOrigin($object, $date, GETPOST('cond_reglement_id', 'int'), $user, 0, GETPOST('validate_generated_deposit', 'alpha') == 'on', $forceFields);
732 
733  if ($deposit) {
734  setEventMessage('DepositGenerated');
735  $locationTarget = DOL_URL_ROOT . '/compta/facture/card.php?id=' . $deposit->id;
736  } else {
737  $error++;
738  setEventMessages($object->error, $object->errors, 'errors');
739  }
740  }
741 
742  if (!$error) {
743  $db->commit();
744 
745  if ($deposit && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
746  $ret = $deposit->fetch($deposit->id); // Reload to get new records
747  $outputlangs = $langs;
748 
749  if (getDolGlobalInt('MAIN_MULTILANGS')) {
750  $outputlangs = new Translate('', $conf);
751  $outputlangs->setDefaultLang($deposit->thirdparty->default_lang);
752  $outputlangs->load('products');
753  }
754 
755  $result = $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
756 
757  if ($result < 0) {
758  setEventMessages($deposit->error, $deposit->errors, 'errors');
759  }
760  }
761 
762  if ($locationTarget) {
763  header('Location: ' . $locationTarget);
764  exit;
765  }
766  } else {
767  $db->rollback();
768  $action = '';
769  }
770  }
771  }
772  } elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) {
773  // Reopen proposal
774  // prevent browser refresh from reopening proposal several times
775  if ($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED) {
776  $db->begin();
777 
778  $result = $object->reopen($user, empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE));
779  if ($result < 0) {
780  setEventMessages($object->error, $object->errors, 'errors');
781  $error++;
782  }
783 
784  if (!$error) {
785  $db->commit();
786  } else {
787  $db->rollback();
788  }
789  }
790  } elseif ($action == 'import_lines_from_object'
791  && $user->rights->propal->creer
792  && $object->statut == Propal::STATUS_DRAFT
793  ) {
794  // add lines from objectlinked
795  $fromElement = GETPOST('fromelement');
796  $fromElementid = GETPOST('fromelementid');
797  $importLines = GETPOST('line_checkbox');
798 
799  if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
800  if ($fromElement == 'commande') {
801  dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php');
802  $lineClassName = 'OrderLine';
803  } elseif ($fromElement == 'propal') {
804  dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php');
805  $lineClassName = 'PropaleLigne';
806  }
807  $nextRang = count($object->lines) + 1;
808  $importCount = 0;
809  $error = 0;
810  foreach ($importLines as $lineId) {
811  $lineId = intval($lineId);
812  $originLine = new $lineClassName($db);
813  if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
814  $originLine->fetch_optionals();
815  $desc = $originLine->desc;
816  $pu_ht = $originLine->subprice;
817  $qty = $originLine->qty;
818  $txtva = $originLine->tva_tx;
819  $txlocaltax1 = $originLine->localtax1_tx;
820  $txlocaltax2 = $originLine->localtax2_tx;
821  $fk_product = $originLine->fk_product;
822  $remise_percent = $originLine->remise_percent;
823  $date_start = $originLine->date_start;
824  $date_end = $originLine->date_end;
825  $ventil = 0;
826  $info_bits = $originLine->info_bits;
827  $fk_remise_except = $originLine->fk_remise_except;
828  $price_base_type = 'HT';
829  $pu_ttc = 0;
830  $type = $originLine->product_type;
831  $rang = $nextRang++;
832  $special_code = $originLine->special_code;
833  $origin = $originLine->element;
834  $origin_id = $originLine->id;
835  $fk_parent_line = 0;
836  $fk_fournprice = $originLine->fk_fournprice;
837  $pa_ht = $originLine->pa_ht;
838  $label = $originLine->label;
839  $array_options = $originLine->array_options;
840  $situation_percent = 100;
841  $fk_prev_id = '';
842  $fk_unit = $originLine->fk_unit;
843  $pu_ht_devise = $originLine->multicurrency_subprice;
844 
845  $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, $rang, $special_code, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $date_start, $date_end, $array_options, $fk_unit, $origin, $origin_id, $pu_ht_devise, $fk_remise_except);
846 
847  if ($res > 0) {
848  $importCount++;
849  } else {
850  $error++;
851  }
852  } else {
853  $error++;
854  }
855  }
856 
857  if ($error) {
858  setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors');
859  }
860  }
861  }
862 
863  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
864 
865  // Actions to send emails
866  $actiontypecode = 'AC_OTH_AUTO';
867  $triggersendname = 'PROPAL_SENTBYMAIL';
868  $autocopy = 'MAIN_MAIL_AUTOCOPY_PROPOSAL_TO';
869  $trackid = 'pro'.$object->id;
870  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
871 
872 
873  // Go back to draft
874  if ($action == 'modif' && $usercancreate) {
875  $object->setDraft($user);
876 
877  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
878  // Define output language
879  $outputlangs = $langs;
880  if (getDolGlobalInt('MAIN_MULTILANGS')) {
881  $outputlangs = new Translate("", $conf);
882  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
883  $outputlangs->setDefaultLang($newlang);
884  }
885  $ret = $object->fetch($id); // Reload to get new records
886  if ($ret > 0) {
887  $object->fetch_thirdparty();
888  }
889  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
890  }
891  } elseif ($action == "setabsolutediscount" && $usercancreate) {
892  if (GETPOST("remise_id", "int")) {
893  if ($object->id > 0) {
894  $result = $object->insert_discount(GETPOST("remise_id", "int"));
895  if ($result < 0) {
896  setEventMessages($object->error, $object->errors, 'errors');
897  }
898  }
899  }
900  } elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('vatforalllines', 'alpha') !== '' && $usercancreate) {
901  // Define a vat_rate for all lines
902  $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
903  $vat_rate = str_replace('*', '', $vat_rate);
904  $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
905  $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
906  foreach ($object->lines as $line) {
907  $result = $object->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
908  }
909  } elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('remiseforalllines', 'alpha') !== '' && $usercancreate) {
910  // Define a discount for all lines
911  $remise_percent = (GETPOST('remiseforalllines') ? GETPOST('remiseforalllines') : 0);
912  $remise_percent = str_replace('*', '', $remise_percent);
913  foreach ($object->lines as $line) {
914  $result = $object->updateline($line->id, $line->subprice, $line->qty, $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
915  }
916  } elseif ($action == 'addline' && $usercancreate) { // Add line
917  // Set if we used free entry or predefined product
918  $predef = '';
919  $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
920 
921  $price_ht = '';
922  $price_ht_devise = '';
923  $price_ttc = '';
924  $price_ttc_devise = '';
925 
926  // TODO Implement if (getDolGlobalInt('MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES'))
927 
928  if (GETPOST('price_ht') !== '') {
929  $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
930  }
931  if (GETPOST('multicurrency_price_ht') !== '') {
932  $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
933  }
934  if (GETPOST('price_ttc') !== '') {
935  $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
936  }
937  if (GETPOST('multicurrency_price_ttc') !== '') {
938  $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
939  }
940 
941  $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
942  if ($prod_entry_mode == 'free') {
943  $idprod = 0;
944  $tva_tx = (GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0);
945  } else {
946  $idprod = GETPOST('idprod', 'int');
947  $tva_tx = '';
948  }
949 
950  $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
951  $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
952  if (empty($remise_percent)) {
953  $remise_percent = 0;
954  }
955 
956  // Extrafields
957  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
958  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
959  // Unset extrafield
960  if (is_array($extralabelsline)) {
961  // Get extra fields
962  foreach ($extralabelsline as $key => $value) {
963  unset($_POST["options_".$key]);
964  }
965  }
966 
967  if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
968  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
969  $error++;
970  }
971 
972  if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && $price_ht === '' && $price_ht_devise === '' && $price_ttc === '' && $price_ttc_devise === '') { // Unit price can be 0 but not ''. Also price can be negative for proposal.
973  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
974  $error++;
975  }
976  if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
977  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
978  $error++;
979  }
980 
981  if (!$error && isModEnabled('variants') && $prod_entry_mode != 'free') {
982  if ($combinations = GETPOST('combinations', 'array')) {
983  //Check if there is a product with the given combination
984  $prodcomb = new ProductCombination($db);
985 
986  if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
987  $idprod = $res->fk_product_child;
988  } else {
989  setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors');
990  $error++;
991  }
992  }
993  }
994 
995  if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
996  $pu_ht = 0;
997  $pu_ttc = 0;
998  $price_min = 0;
999  $price_min_ttc = 0;
1000  $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
1001 
1002  $db->begin();
1003 
1004  // $tva_tx can be 'x.x (XXX)'
1005 
1006  // Ecrase $pu par celui du produit
1007  // Ecrase $desc par celui du produit
1008  // Ecrase $tva_tx par celui du produit
1009  // Replaces $fk_unit with the product unit
1010  if (!empty($idprod) && $idprod > 0) {
1011  $prod = new Product($db);
1012  $prod->fetch($idprod);
1013 
1014  $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
1015 
1016  // Update if prices fields are defined
1017  $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
1018  $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
1019  if (empty($tva_tx)) {
1020  $tva_npr = 0;
1021  }
1022 
1023  // Price unique per product
1024  $pu_ht = $prod->price;
1025  $pu_ttc = $prod->price_ttc;
1026  $price_min = $prod->price_min;
1027  $price_min_ttc = $prod->price_min_ttc;
1028  $price_base_type = $prod->price_base_type;
1029 
1030  // If price per segment
1031  if (!empty($conf->global->PRODUIT_MULTIPRICES) && $object->thirdparty->price_level) {
1032  $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
1033  $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
1034  $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
1035  $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
1036  $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
1037  if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { // using this option is a bug. kept for backward compatibility
1038  if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
1039  $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
1040  }
1041  if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
1042  $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
1043  }
1044  }
1045  } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1046  // If price per customer
1047  require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
1048 
1049  $prodcustprice = new Productcustomerprice($db);
1050 
1051  $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
1052 
1053  $result = $prodcustprice->fetchAll('', '', 0, 0, $filter);
1054  if ($result) {
1055  // If there is some prices specific to the customer
1056  if (count($prodcustprice->lines) > 0) {
1057  $pu_ht = price($prodcustprice->lines[0]->price);
1058  $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
1059  $price_min = price($prodcustprice->lines[0]->price_min);
1060  $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc);
1061  $price_base_type = $prodcustprice->lines[0]->price_base_type;
1062  $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx);
1063  if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) {
1064  $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
1065  }
1066  $tva_npr = $prodcustprice->lines[0]->recuperableonly;
1067  if (empty($tva_tx)) {
1068  $tva_npr = 0;
1069  }
1070  }
1071  }
1072  } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
1073  // If price per quantity
1074  if ($prod->prices_by_qty[0]) { // yes, this product has some prices per quantity
1075  // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
1076  $pqp = GETPOST('pbq', 'int');
1077 
1078  // Search price into product_price_by_qty from $prod->id
1079  foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
1080  if ($priceforthequantityarray['rowid'] != $pqp) {
1081  continue;
1082  }
1083  // We found the price
1084  if ($priceforthequantityarray['price_base_type'] == 'HT') {
1085  $pu_ht = $priceforthequantityarray['unitprice'];
1086  } else {
1087  $pu_ttc = $priceforthequantityarray['unitprice'];
1088  }
1089  // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
1090  break;
1091  }
1092  }
1093  } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1094  // If price per quantity and customer
1095  if ($prod->prices_by_qty[$object->thirdparty->price_level]) { // yes, this product has some prices per quantity
1096  // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
1097  $pqp = GETPOST('pbq', 'int');
1098 
1099  // Search price into product_price_by_qty from $prod->id
1100  foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
1101  if ($priceforthequantityarray['rowid'] != $pqp) {
1102  continue;
1103  }
1104  // We found the price
1105  if ($priceforthequantityarray['price_base_type'] == 'HT') {
1106  $pu_ht = $priceforthequantityarray['unitprice'];
1107  } else {
1108  $pu_ttc = $priceforthequantityarray['unitprice'];
1109  }
1110  // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
1111  break;
1112  }
1113  }
1114  }
1115 
1116  $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
1117  $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
1118 
1119  // Set unit price to use
1120  if (!empty($price_ht) || $price_ht === '0') {
1121  $pu_ht = price2num($price_ht, 'MU');
1122  $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
1123  } elseif (!empty($price_ttc) || $price_ttc === '0') {
1124  $pu_ttc = price2num($price_ttc, 'MU');
1125  $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
1126  } elseif ($tmpvat != $tmpprodvat) {
1127  // Is this still used ?
1128  if ($price_base_type != 'HT') {
1129  $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
1130  } else {
1131  $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
1132  }
1133  }
1134 
1135  $desc = '';
1136 
1137  // Define output language
1138  if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1139  $outputlangs = $langs;
1140  $newlang = '';
1141  if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1142  $newlang = GETPOST('lang_id', 'aZ09');
1143  }
1144  if (empty($newlang)) {
1145  $newlang = $object->thirdparty->default_lang;
1146  }
1147  if (!empty($newlang)) {
1148  $outputlangs = new Translate("", $conf);
1149  $outputlangs->setDefaultLang($newlang);
1150  }
1151 
1152  $desc = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
1153  } else {
1154  $desc = $prod->description;
1155  }
1156 
1157  //If text set in desc is the same as product description (as now it's preloaded) whe add it only one time
1158  if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1159  $product_desc='';
1160  }
1161 
1162  if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1163  $desc = $product_desc;
1164  } else {
1165  $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1166  }
1167 
1168  // Add custom code and origin country into description
1169  if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
1170  $tmptxt = '(';
1171  // Define output language
1172  if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1173  $outputlangs = $langs;
1174  $newlang = '';
1175  if (empty($newlang) && GETPOST('lang_id', 'alpha')) {
1176  $newlang = GETPOST('lang_id', 'alpha');
1177  }
1178  if (empty($newlang)) {
1179  $newlang = $object->thirdparty->default_lang;
1180  }
1181  if (!empty($newlang)) {
1182  $outputlangs = new Translate("", $conf);
1183  $outputlangs->setDefaultLang($newlang);
1184  $outputlangs->load('products');
1185  }
1186  if (!empty($prod->customcode)) {
1187  $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
1188  }
1189  if (!empty($prod->customcode) && !empty($prod->country_code)) {
1190  $tmptxt .= ' - ';
1191  }
1192  if (!empty($prod->country_code)) {
1193  $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, 0, $db, $outputlangs, 0);
1194  }
1195  } else {
1196  if (!empty($prod->customcode)) {
1197  $tmptxt .= $langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
1198  }
1199  if (!empty($prod->customcode) && !empty($prod->country_code)) {
1200  $tmptxt .= ' - ';
1201  }
1202  if (!empty($prod->country_code)) {
1203  $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, 0, $db, $langs, 0);
1204  }
1205  }
1206  $tmptxt .= ')';
1207  $desc = dol_concatdesc($desc, $tmptxt);
1208  }
1209 
1210  $type = $prod->type;
1211  $fk_unit = $prod->fk_unit;
1212  } else {
1213  $pu_ht = price2num($price_ht, 'MU');
1214  $pu_ttc = price2num($price_ttc, 'MU');
1215  $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
1216  if (empty($tva_tx)) {
1217  $tva_npr = 0;
1218  }
1219  $tva_tx = str_replace('*', '', $tva_tx);
1220  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1221  $desc = $product_desc;
1222  $type = GETPOST('type');
1223  $fk_unit = GETPOST('units', 'alpha');
1224  $pu_ht_devise = price2num($price_ht_devise, 'MU');
1225  $pu_ttc_devise = price2num($price_ttc_devise, 'MU');
1226 
1227  if ($pu_ttc && !$pu_ht) {
1228  $price_base_type = 'TTC';
1229  }
1230  }
1231 
1232  // Margin
1233  $fournprice = price2num(GETPOST('fournprice'.$predef) ? GETPOST('fournprice'.$predef) : '');
1234  $buyingprice = price2num(GETPOST('buying_price'.$predef) != '' ? GETPOST('buying_price'.$predef) : ''); // If buying_price is '0', we muste keep this value
1235 
1236  $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
1237  $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
1238 
1239  // Prepare a price equivalent for minimum price check
1240  $pu_equivalent = $pu_ht;
1241  $pu_equivalent_ttc = $pu_ttc;
1242  $currency_tx = $object->multicurrency_tx;
1243 
1244  // Check if we have a foreing currency
1245  // If so, we update the pu_equiv as the equivalent price in base currency
1246  if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
1247  $pu_equivalent = $pu_ht_devise * $currency_tx;
1248  }
1249  if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') {
1250  $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1251  }
1252 
1253  // Local Taxes
1254  $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
1255  $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
1256 
1257  $info_bits = 0;
1258  if ($tva_npr) {
1259  $info_bits |= 0x01;
1260  }
1261 
1262  //var_dump(price2num($price_min)); var_dump(price2num($pu_ht)); var_dump($remise_percent);
1263  //var_dump(price2num($price_min_ttc)); var_dump(price2num($pu_ttc)); var_dump($remise_percent);exit;
1264 
1265  if ($usermustrespectpricemin) {
1266  if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
1267  $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1268  setEventMessages($mesg, null, 'errors');
1269  $error++;
1270  } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
1271  $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1272  setEventMessages($mesg, null, 'errors');
1273  $error++;
1274  }
1275  }
1276 
1277  if (!$error) {
1278  // Insert line
1279  $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, min($rank, count($object->lines) + 1), 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options, $fk_unit, '', 0, $pu_ht_devise);
1280 
1281  if ($result > 0) {
1282  $db->commit();
1283 
1284  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1285  // Define output language
1286  $outputlangs = $langs;
1287  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1288  $outputlangs = new Translate("", $conf);
1289  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
1290  $outputlangs->setDefaultLang($newlang);
1291  }
1292  $ret = $object->fetch($id); // Reload to get new records
1293  if ($ret > 0) {
1294  $object->fetch_thirdparty();
1295  }
1296  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1297  }
1298 
1299  unset($_POST['prod_entry_mode']);
1300 
1301  unset($_POST['qty']);
1302  unset($_POST['type']);
1303  unset($_POST['remise_percent']);
1304  unset($_POST['price_ht']);
1305  unset($_POST['multicurrency_price_ht']);
1306  unset($_POST['price_ttc']);
1307  unset($_POST['tva_tx']);
1308  unset($_POST['product_ref']);
1309  unset($_POST['product_label']);
1310  unset($_POST['product_desc']);
1311  unset($_POST['fournprice']);
1312  unset($_POST['buying_price']);
1313  unset($_POST['np_marginRate']);
1314  unset($_POST['np_markRate']);
1315  unset($_POST['dp_desc']);
1316  unset($_POST['idprod']);
1317  unset($_POST['units']);
1318 
1319  unset($_POST['date_starthour']);
1320  unset($_POST['date_startmin']);
1321  unset($_POST['date_startsec']);
1322  unset($_POST['date_startday']);
1323  unset($_POST['date_startmonth']);
1324  unset($_POST['date_startyear']);
1325  unset($_POST['date_endhour']);
1326  unset($_POST['date_endmin']);
1327  unset($_POST['date_endsec']);
1328  unset($_POST['date_endday']);
1329  unset($_POST['date_endmonth']);
1330  unset($_POST['date_endyear']);
1331  } else {
1332  $db->rollback();
1333 
1334  setEventMessages($object->error, $object->errors, 'errors');
1335  }
1336  }
1337  }
1338  } elseif ($action == 'updateline' && $usercancreate && GETPOST('save')) {
1339  // Update a line within proposal
1340  // Define info_bits
1341  $info_bits = 0;
1342  if (preg_match('/\*/', GETPOST('tva_tx'))) {
1343  $info_bits |= 0x01;
1344  }
1345 
1346  // Clean parameters
1347  $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
1348 
1349  // Define vat_rate
1350  $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
1351  $vat_rate = str_replace('*', '', $vat_rate);
1352  $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1353  $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1354  $pu_ht = price2num(GETPOST('price_ht'), '', 2);
1355  $pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
1356 
1357  // Add buying price
1358  $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
1359  $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
1360 
1361  $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
1362  $pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
1363 
1364  $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
1365  $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
1366 
1367  $remise_percent = price2num(GETPOST('remise_percent'), '', 2);
1368  if (empty($remise_percent)) {
1369  $remise_percent = 0;
1370  }
1371 
1372  // Prepare a price equivalent for minimum price check
1373  $pu_equivalent = $pu_ht;
1374  $pu_equivalent_ttc = $pu_ttc;
1375  $currency_tx = $object->multicurrency_tx;
1376 
1377  // Check if we have a foreing currency
1378  // If so, we update the pu_equiv as the equivalent price in base currency
1379  if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
1380  $pu_equivalent = $pu_ht_devise * $currency_tx;
1381  }
1382  if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') {
1383  $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1384  }
1385 
1386  // Extrafields
1387  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1388  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1389  // Unset extrafield
1390  if (is_array($extralabelsline)) {
1391  // Get extra fields
1392  foreach ($extralabelsline as $key => $value) {
1393  unset($_POST["options_".$key]);
1394  }
1395  }
1396 
1397  // Define special_code for special lines
1398  $special_code = GETPOST('special_code', 'int');
1399  if (!GETPOST('qty')) {
1400  $special_code = 3;
1401  }
1402 
1403  // Check minimum price
1404  $productid = GETPOST('productid', 'int');
1405  if (!empty($productid)) {
1406  $product = new Product($db);
1407  $res = $product->fetch($productid);
1408 
1409  $type = $product->type;
1410  $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
1411 
1412  $price_min = $product->price_min;
1413  if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
1414  $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1415  }
1416  $price_min_ttc = $product->price_min_ttc;
1417  if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
1418  $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1419  }
1420 
1421  //var_dump(price2num($price_min)); var_dump(price2num($pu_ht)); var_dump($remise_percent);
1422  //var_dump(price2num($price_min_ttc)); var_dump(price2num($pu_ttc)); var_dump($remise_percent);exit;
1423 
1424  if ($usermustrespectpricemin) {
1425  if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
1426  $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1427  setEventMessages($mesg, null, 'errors');
1428  $error++;
1429  $action = 'editline';
1430  } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
1431  $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1432  setEventMessages($mesg, null, 'errors');
1433  $error++;
1434  $action = 'editline';
1435  }
1436  }
1437  } else {
1438  $type = GETPOST('type');
1439  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1440 
1441  // Check parameters
1442  if (GETPOST('type') < 0) {
1443  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1444  $error++;
1445  }
1446  }
1447 
1448  if (!$error) {
1449  $db->begin();
1450 
1451  if (empty($user->rights->margins->creer)) {
1452  foreach ($object->lines as &$line) {
1453  if ($line->id == GETPOST('lineid', 'int')) {
1454  $fournprice = $line->fk_fournprice;
1455  $buyingprice = $line->pa_ht;
1456  break;
1457  }
1458  }
1459  }
1460 
1461  $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
1462 
1463  $pu = $pu_ht;
1464  $price_base_type = 'HT';
1465  if (empty($pu) && !empty($pu_ttc)) {
1466  $pu = $pu_ttc;
1467  $price_base_type = 'TTC';
1468  }
1469 
1470  $result = $object->updateline(GETPOST('lineid', 'int'), $pu, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $description, $price_base_type, $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, GETPOST("units"), $pu_ht_devise);
1471 
1472  if ($result >= 0) {
1473  $db->commit();
1474 
1475  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1476  // Define output language
1477  $outputlangs = $langs;
1478  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1479  $outputlangs = new Translate("", $conf);
1480  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
1481  $outputlangs->setDefaultLang($newlang);
1482  }
1483  $ret = $object->fetch($id); // Reload to get new records
1484  if ($ret > 0) {
1485  $object->fetch_thirdparty();
1486  }
1487  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1488  }
1489 
1490  unset($_POST['qty']);
1491  unset($_POST['type']);
1492  unset($_POST['productid']);
1493  unset($_POST['remise_percent']);
1494  unset($_POST['price_ht']);
1495  unset($_POST['multicurrency_price_ht']);
1496  unset($_POST['price_ttc']);
1497  unset($_POST['tva_tx']);
1498  unset($_POST['product_ref']);
1499  unset($_POST['product_label']);
1500  unset($_POST['product_desc']);
1501  unset($_POST['fournprice']);
1502  unset($_POST['buying_price']);
1503 
1504  unset($_POST['date_starthour']);
1505  unset($_POST['date_startmin']);
1506  unset($_POST['date_startsec']);
1507  unset($_POST['date_startday']);
1508  unset($_POST['date_startmonth']);
1509  unset($_POST['date_startyear']);
1510  unset($_POST['date_endhour']);
1511  unset($_POST['date_endmin']);
1512  unset($_POST['date_endsec']);
1513  unset($_POST['date_endday']);
1514  unset($_POST['date_endmonth']);
1515  unset($_POST['date_endyear']);
1516  } else {
1517  $db->rollback();
1518 
1519  setEventMessages($object->error, $object->errors, 'errors');
1520  }
1521  }
1522  } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha')) {
1523  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
1524  exit();
1525  } elseif ($action == 'classin' && $usercancreate) {
1526  // Set project
1527  $object->setProject(GETPOST('projectid', 'int'));
1528  } elseif ($action == 'setavailability' && $usercancreate) {
1529  // Delivery time
1530  $result = $object->set_availability($user, GETPOST('availability_id', 'int'));
1531  } elseif ($action == 'setdemandreason' && $usercancreate) {
1532  // Origin of the commercial proposal
1533  $result = $object->set_demand_reason($user, GETPOST('demand_reason_id', 'int'));
1534  } elseif ($action == 'setconditions' && $usercancreate) {
1535  // Terms of payment
1536  $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'alpha'));
1537  } elseif ($action == 'setremisepercent' && $usercancreate) {
1538  $result = $object->set_remise_percent($user, price2num(GETPOST('remise_percent'), '', 2));
1539  } elseif ($action == 'setremiseabsolue' && $usercancreate) {
1540  $result = $object->set_remise_absolue($user, price2num(GETPOST('remise_absolue'), 'MU', 2));
1541  } elseif ($action == 'setmode' && $usercancreate) {
1542  // Payment choice
1543  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
1544  } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
1545  // Multicurrency Code
1546  $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
1547  } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
1548  // Multicurrency rate
1549  $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int'));
1550  } elseif ($action == 'setbankaccount' && $usercancreate) {
1551  // bank account
1552  $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
1553  } elseif ($action == 'setshippingmethod' && $usercancreate) {
1554  // shipping method
1555  $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int'));
1556  } elseif ($action == 'setwarehouse' && $usercancreate) {
1557  // warehouse
1558  $result = $object->setWarehouse(GETPOST('warehouse_id', 'int'));
1559  } elseif ($action == 'update_extras') {
1560  $object->oldcopy = dol_clone($object);
1561 
1562  // Fill array 'array_options' with data from update form
1563  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
1564  if ($ret < 0) {
1565  $error++;
1566  }
1567  if (!$error) {
1568  $result = $object->insertExtraFields('PROPAL_MODIFY');
1569  if ($result < 0) {
1570  setEventMessages($object->error, $object->errors, 'errors');
1571  $error++;
1572  }
1573  }
1574  if ($error) {
1575  $action = 'edit_extras';
1576  }
1577  }
1578 
1579  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1580  if ($action == 'addcontact') {
1581  if ($object->id > 0) {
1582  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
1583  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
1584  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
1585  }
1586 
1587  if ($result >= 0) {
1588  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1589  exit();
1590  } else {
1591  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1592  $langs->load("errors");
1593  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
1594  } else {
1595  setEventMessages($object->error, $object->errors, 'errors');
1596  }
1597  }
1598  } elseif ($action == 'swapstatut') {
1599  // Toggle the status of a contact
1600  if ($object->fetch($id) > 0) {
1601  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
1602  } else {
1603  dol_print_error($db);
1604  }
1605  } elseif ($action == 'deletecontact') {
1606  // Delete a contact
1607  $object->fetch($id);
1608  $result = $object->delete_contact($lineid);
1609 
1610  if ($result >= 0) {
1611  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1612  exit();
1613  } else {
1614  dol_print_error($db);
1615  }
1616  }
1617  }
1618 
1619  // Actions to build doc
1620  $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output;
1621  $permissiontoadd = $usercancreate;
1622  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1623 }
1624 
1625 
1626 /*
1627  * View
1628  */
1629 
1630 $form = new Form($db);
1631 $formfile = new FormFile($db);
1632 $formpropal = new FormPropal($db);
1633 $formmargin = new FormMargin($db);
1634 if (isModEnabled('project')) {
1635  $formproject = new FormProjets($db);
1636 }
1637 
1638 $title = $object->ref." - ".$langs->trans('Card');
1639 if ($action == 'create') {
1640  $title = $langs->trans("NewPropal");
1641 }
1642 $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos|DE:Modul_Angebote';
1643 
1644 llxHeader('', $title, $help_url);
1645 
1646 $now = dol_now();
1647 
1648 // Add new proposal
1649 if ($action == 'create') {
1650  $currency_code = $conf->currency;
1651 
1652  print load_fiche_titre($langs->trans("NewProp"), '', 'propal');
1653 
1654  $soc = new Societe($db);
1655  if ($socid > 0) {
1656  $res = $soc->fetch($socid);
1657  }
1658 
1659  // Load objectsrc
1660  if (!empty($origin) && !empty($originid)) {
1661  // Parse element/subelement (ex: project_task)
1662  $element = $subelement = $origin;
1663  $regs = array();
1664  if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1665  $element = $regs[1];
1666  $subelement = $regs[2];
1667  }
1668 
1669  if ($element == 'project') {
1670  $projectid = $originid;
1671  } else {
1672  // For compatibility
1673  if ($element == 'order' || $element == 'commande') {
1674  $element = $subelement = 'commande';
1675  }
1676  if ($element == 'propal') {
1677  $element = 'comm/propal';
1678  $subelement = 'propal';
1679  }
1680  if ($element == 'contract') {
1681  $element = $subelement = 'contrat';
1682  }
1683  if ($element == 'shipping') {
1684  $element = $subelement = 'expedition';
1685  }
1686 
1687  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1688 
1689  $classname = ucfirst($subelement);
1690  $objectsrc = new $classname($db);
1691  $objectsrc->fetch($originid);
1692  if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1693  $objectsrc->fetch_lines();
1694  }
1695  $objectsrc->fetch_thirdparty();
1696 
1697  $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : 0);
1698  $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
1699 
1700  $soc = $objectsrc->thirdparty;
1701 
1702  $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0)); // TODO maybe add default value option
1703  $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1704  $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0)); // deprecated
1705  $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1706  $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1707  $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $dateinvoice);
1708 
1709  // Replicate extrafields
1710  $objectsrc->fetch_optionals();
1711  $object->array_options = $objectsrc->array_options;
1712 
1713  if (isModEnabled("multicurrency")) {
1714  if (!empty($objectsrc->multicurrency_code)) {
1715  $currency_code = $objectsrc->multicurrency_code;
1716  }
1717  if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1718  $currency_tx = $objectsrc->multicurrency_tx;
1719  }
1720  }
1721  }
1722  } else {
1723  if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) {
1724  $currency_code = $soc->multicurrency_code;
1725  }
1726  }
1727 
1728  //Warehouse default if null
1729  if ($soc->fk_warehouse > 0) {
1730  $warehouse_id = $soc->fk_warehouse;
1731  }
1732  if (isModEnabled('stock') && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1733  if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1734  $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1735  }
1736  if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1737  $warehouse_id = $user->fk_warehouse;
1738  }
1739  }
1740 
1741  print '<form name="addprop" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1742  print '<input type="hidden" name="token" value="'.newToken().'">';
1743  print '<input type="hidden" name="action" value="add">';
1744  if ($origin != 'project' && $originid) {
1745  print '<input type="hidden" name="origin" value="'.$origin.'">';
1746  print '<input type="hidden" name="originid" value="'.$originid.'">';
1747  } elseif ($origin == 'project' && !empty($projectid)) {
1748  print '<input type="hidden" name="projectid" value="'.$projectid.'">';
1749  }
1750 
1751  print dol_get_fiche_head();
1752 
1753  print '<table class="border centpercent">';
1754 
1755  // Reference
1756  print '<tr class="field_ref"><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td class="valuefieldcreate">'.$langs->trans("Draft").'</td></tr>';
1757 
1758  // Ref customer
1759  print '<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans('RefCustomer').'</td><td class="valuefieldcreate">';
1760  print '<input type="text" name="ref_client" value="'.(!empty($ref_client)?$ref_client:GETPOST('ref_client')).'"></td>';
1761  print '</tr>';
1762 
1763  // Third party
1764  print '<tr class="field_socid">';
1765  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans('Customer').'</td>';
1766  $shipping_method_id = 0;
1767  if ($socid > 0) {
1768  print '<td class="valuefieldcreate">';
1769  print $soc->getNomUrl(1, 'customer');
1770  print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1771  print '</td>';
1772  if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1773  $shipping_method_id = $soc->shipping_method_id;
1774  }
1775  //$warehouse_id = $soc->warehouse_id;
1776  } else {
1777  print '<td class="valuefieldcreate">';
1778  print img_picto('', 'company').$form->select_company('', 'socid', '((s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1)', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
1779  // reload page to retrieve customer informations
1780  if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1781  print '<script type="text/javascript">
1782  $(document).ready(function() {
1783  $("#socid").change(function() {
1784  console.log("We have changed the company - Reload page");
1785  var socid = $(this).val();
1786  // reload page
1787  $("input[name=action]").val("create");
1788  $("form[name=addprop]").submit();
1789  });
1790  });
1791  </script>';
1792  }
1793  print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1794  print '</td>';
1795  }
1796  print '</tr>'."\n";
1797 
1798  if ($socid > 0) {
1799  // Contacts (ask contact only if thirdparty already defined).
1800  print '<tr class="field_contactid"><td class="titlefieldcreate">'.$langs->trans("DefaultContact").'</td><td class="valuefieldcreate">';
1801  print img_picto('', 'contact');
1802  print $form->selectcontacts($soc->id, $contactid, 'contactid', 1, '', '', 0, 'minwidth300');
1803  print '</td></tr>';
1804 
1805  // Third party discounts info line
1806  print '<tr class="field_discount_info"><td class="titlefieldcreate">'.$langs->trans('Discounts').'</td><td class="valuefieldcreate">';
1807 
1808  $absolute_discount = $soc->getAvailableDiscounts();
1809 
1810  $thirdparty = $soc;
1811  $discount_type = 0;
1812  $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
1813  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1814  print '</td></tr>';
1815  }
1816 
1817  // Date
1818  print '<tr class="field_addprop"><td class="titlefieldcreate fieldrequired">'.$langs->trans('DatePropal').'</td><td class="valuefieldcreate">';
1819  print $form->selectDate('', '', '', '', '', "addprop", 1, 1);
1820  print '</td></tr>';
1821 
1822  // Validaty duration
1823  print '<tr class="field_duree_validitee"><td class="titlefieldcreate fieldrequired">'.$langs->trans("ValidityDuration").'</td><td class="valuefieldcreate">'.img_picto('', 'clock', 'class="paddingright"').'<input name="duree_validite" class="width50" value="'.(GETPOSTISSET('duree_validite') ? GETPOST('duree_validite', 'alphanohtml') : $conf->global->PROPALE_VALIDITY_DURATION).'"> '.$langs->trans("days").'</td></tr>';
1824 
1825  // Terms of payment
1826  print '<tr class="field_cond_reglement_id"><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
1827  print img_picto('', 'paiment');
1828  print $form->getSelectConditionsPaiements((GETPOSTISSET('cond_reglement_id') && GETPOST('cond_reglement_id', 'int') != 0) ? GETPOST('cond_reglement_id', 'int') : $soc->cond_reglement_id, 'cond_reglement_id', 1, 1, 0, '', (GETPOSTISSET('cond_reglement_id_deposit_percent') ? GETPOST('cond_reglement_id_deposit_percent', 'alpha') : $soc->deposit_percent));
1829  print '</td></tr>';
1830 
1831  // Mode of payment
1832  print '<tr class="field_mode_reglement_id"><td class="titlefieldcreate">'.$langs->trans('PaymentMode').'</td><td class="valuefieldcreate">';
1833  print img_picto('', 'bank', 'class="pictofixedwidth"');
1834  print $form->select_types_paiements((GETPOSTISSET('mode_reglement_id') && GETPOST('mode_reglement_id', 'int') != 0) ? GETPOST('mode_reglement_id', 'int') : $soc->mode_reglement_id, 'mode_reglement_id', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1);
1835  print '</td></tr>';
1836 
1837  // Bank Account
1838  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && isModEnabled("banque")) {
1839  print '<tr class="field_fk_account"><td class="titlefieldcreate">'.$langs->trans('BankAccount').'</td><td class="valuefieldcreate">';
1840  print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes($soc->fk_account, 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1);
1841  print '</td></tr>';
1842  }
1843 
1844  // Source / Channel - What trigger creation
1845  print '<tr class="field_demand_reason_id"><td class="titlefieldcreate">'.$langs->trans('Source').'</td><td class="valuefieldcreate">';
1846  print img_picto('', 'question', 'class="pictofixedwidth"');
1847  $form->selectInputReason((GETPOSTISSET('demand_reason_id') ? GETPOST('demand_reason_id', 'int') : ''), 'demand_reason_id', "SRC_PROP", 1, 'maxwidth200 widthcentpercentminusx');
1848  print '</td></tr>';
1849 
1850  // Delivery delay
1851  print '<tr class="field_availability_id"><td class="titlefieldcreate">'.$langs->trans('AvailabilityPeriod');
1852  if (isModEnabled('commande')) {
1853  print ' ('.$langs->trans('AfterOrder').')';
1854  }
1855  print '</td><td class="valuefieldcreate">';
1856  print img_picto('', 'clock', 'class="pictofixedwidth"');
1857  $form->selectAvailabilityDelay((GETPOSTISSET('availability_id') ? GETPOST('availability_id', 'int') : ''), 'availability_id', '', 1, 'maxwidth200 widthcentpercentminusx');
1858  print '</td></tr>';
1859 
1860  // Shipping Method
1861  if (isModEnabled("expedition")) {
1862  if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
1863  $shipping_method_id = $soc->shipping_method_id;
1864  }
1865  print '<tr class="field_shipping_method_id"><td class="titlefieldcreate">'.$langs->trans('SendingMethod').'</td><td class="valuefieldcreate">';
1866  print img_picto('', 'object_dollyrevert', 'class="pictofixedwidth"');
1867  $form->selectShippingMethod((GETPOSTISSET('shipping_method_id') ? GETPOST('shipping_method_id', 'int') : $shipping_method_id), 'shipping_method_id', '', 1, '', 0, 'maxwidth200 widthcentpercentminusx');
1868  print '</td></tr>';
1869  }
1870 
1871  // Warehouse
1872  if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
1873  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1874  $formproduct = new FormProduct($db);
1875  print '<tr class="field_warehouse_id"><td class="titlefieldcreate">'.$langs->trans('Warehouse').'</td><td class="valuefieldcreate">';
1876  print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($warehouse_id, 'warehouse_id', '', 1, 0, 0, '', 0, 0, array(), 'maxwidth500 widthcentpercentminusxx');
1877  print '</td></tr>';
1878  }
1879 
1880  // Delivery date (or manufacturing)
1881  print '<tr class="field_date_livraison"><td class="titlefieldcreate">'.$langs->trans("DeliveryDate").'</td>';
1882  print '<td class="valuefieldcreate">';
1883  if (isset($conf->global->DATE_LIVRAISON_WEEK_DELAY) && is_numeric($conf->global->DATE_LIVRAISON_WEEK_DELAY)) {
1884  $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
1885  $syear = date("Y", $tmpdte);
1886  $smonth = date("m", $tmpdte);
1887  $sday = date("d", $tmpdte);
1888  print $form->selectDate($syear."-".$smonth."-".$sday, 'date_livraison', '', '', '', "addprop");
1889  } else {
1890  print $form->selectDate(-1, 'date_livraison', '', '', '', "addprop", 1, 1);
1891  }
1892  print '</td></tr>';
1893 
1894  // Project
1895  if (isModEnabled('project')) {
1896  $langs->load("projects");
1897  print '<tr class="field_projectid">';
1898  print '<td class="titlefieldcreate">'.$langs->trans("Project").'</td><td class="valuefieldcreate">';
1899  print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
1900  print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>';
1901  print '</td>';
1902  print '</tr>';
1903  }
1904 
1905  // Incoterms
1906  if (isModEnabled('incoterm')) {
1907  print '<tr class="field_incoterm_id">';
1908  print '<td class="titlefieldcreate"><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $soc->label_incoterms, 1).'</label></td>';
1909  print '<td class="valuefieldcreate maxwidthonsmartphone">';
1910  print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms) ? $soc->location_incoterms : ''));
1911  print '</td></tr>';
1912  }
1913 
1914  // Template to use by default
1915  print '<tr class="field_model">';
1916  print '<td class="titlefieldcreate">'.$langs->trans("DefaultModel").'</td>';
1917  print '<td class="valuefieldcreate">';
1918  print img_picto('', 'pdf', 'class="pictofixedwidth"');
1919  $liste = ModelePDFPropales::liste_modeles($db);
1920  $preselected = (!empty($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT) ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT : getDolGlobalString("PROPALE_ADDON_PDF"));
1921  print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1);
1922  print "</td></tr>";
1923 
1924  // Multicurrency
1925  if (isModEnabled("multicurrency")) {
1926  print '<tr class="field_currency">';
1927  print '<td class="titlefieldcreate">'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1928  print '<td class="valuefieldcreate maxwidthonsmartphone">';
1929  print img_picto('', 'currency', 'class="pictofixedwidth"').$form->selectMultiCurrency($currency_code, 'multicurrency_code', 0);
1930  print '</td></tr>';
1931  }
1932 
1933  // Public note
1934  print '<tr class="field_note_public">';
1935  print '<td class="titlefieldcreate tdtop">'.$langs->trans('NotePublic').'</td>';
1936  print '<td class="valuefieldcreate">';
1937  $note_public = $object->getDefaultCreateValueFor('note_public', (!empty($objectsrc) ? $objectsrc->note_public : null));
1938  $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
1939  print $doleditor->Create(1);
1940 
1941  // Private note
1942  if (empty($user->socid)) {
1943  print '<tr class="field_note_private">';
1944  print '<td class="titlefieldcreate tdtop">'.$langs->trans('NotePrivate').'</td>';
1945  print '<td class="valuefieldcreate">';
1946  $note_private = $object->getDefaultCreateValueFor('note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc)) ? $objectsrc->note_private : null));
1947  $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
1948  print $doleditor->Create(1);
1949  // print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'.</textarea>
1950  print '</td></tr>';
1951  }
1952 
1953  // Other attributes
1954  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1955 
1956  // Lines from source
1957  if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1958  // TODO for compatibility
1959  if ($origin == 'contrat') {
1960  // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
1961  $objectsrc->remise_absolue = $remise_absolue; // deprecated
1962  $objectsrc->remise_percent = $remise_percent;
1963  $objectsrc->update_price(1, 'auto', 1);
1964  }
1965 
1966  print "\n<!-- ".$classname." info -->";
1967  print "\n";
1968  print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
1969  print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
1970  print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
1971  print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1972  print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1973 
1974  $newclassname = $classname;
1975  if ($newclassname == 'Propal') {
1976  $newclassname = 'CommercialProposal';
1977  } elseif ($newclassname == 'Commande') {
1978  $newclassname = 'Order';
1979  } elseif ($newclassname == 'Expedition') {
1980  $newclassname = 'Sending';
1981  } elseif ($newclassname == 'Fichinter') {
1982  $newclassname = 'Intervention';
1983  }
1984 
1985  print '<tr><td>'.$langs->trans($newclassname).'</td><td>'.$objectsrc->getNomUrl(1).'</td></tr>';
1986  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
1987  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency)."</td></tr>";
1988  if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1
1989  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency)."</td></tr>";
1990  }
1991 
1992  if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2
1993  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency)."</td></tr>";
1994  }
1995  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency)."</td></tr>";
1996 
1997  if (isModEnabled("multicurrency")) {
1998  print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td>'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
1999  print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td>'.price($objectsrc->multicurrency_total_tva)."</td></tr>";
2000  print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td>'.price($objectsrc->multicurrency_total_ttc)."</td></tr>";
2001  }
2002  }
2003 
2004  print "</table>\n";
2005 
2006 
2007  /*
2008  * Combobox for copy function
2009  */
2010 
2011  if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
2012  print '<input type="hidden" name="createmode" value="empty">';
2013  }
2014 
2015  if (!empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
2016  print '<br><table>';
2017 
2018  // For backward compatibility
2019  print '<tr>';
2020  print '<td><input type="radio" name="createmode" value="copy"></td>';
2021  print '<td>'.$langs->trans("CopyPropalFrom").' </td>';
2022  print '<td>';
2023  $liste_propal = array();
2024  $liste_propal [0] = '';
2025 
2026  $sql = "SELECT p.rowid as id, p.ref, s.nom";
2027  $sql .= " FROM ".MAIN_DB_PREFIX."propal p";
2028  $sql .= ", ".MAIN_DB_PREFIX."societe s";
2029  $sql .= " WHERE s.rowid = p.fk_soc";
2030  $sql .= " AND p.entity IN (".getEntity('propal').")";
2031  $sql .= " AND p.fk_statut <> 0";
2032  $sql .= " ORDER BY Id";
2033 
2034  $resql = $db->query($sql);
2035  if ($resql) {
2036  $num = $db->num_rows($resql);
2037  $i = 0;
2038  while ($i < $num) {
2039  $row = $db->fetch_row($resql);
2040  $propalRefAndSocName = $row[1]." - ".$row[2];
2041  $liste_propal[$row[0]] = $propalRefAndSocName;
2042  $i++;
2043  }
2044  print $form->selectarray("copie_propal", $liste_propal, 0);
2045  } else {
2046  dol_print_error($db);
2047  }
2048  print '</td></tr>';
2049 
2050  print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
2051  print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyPropal").'</td></tr>';
2052  print '</table>';
2053  }
2054 
2055  print dol_get_fiche_end();
2056 
2057  $langs->load("bills");
2058 
2059  print $form->buttonsSaveCancel("CreateDraft");
2060 
2061  print "</form>";
2062 
2063 
2064  // Show origin lines
2065  if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2066  print '<br>';
2067 
2068  $title = $langs->trans('ProductsAndServices');
2069  print load_fiche_titre($title);
2070 
2071  print '<div class="div-table-responsive-no-min">';
2072  print '<table class="noborder centpercent">';
2073 
2074  $objectsrc->printOriginLinesList();
2075 
2076  print '</table>';
2077  print '</div>';
2078  }
2079 } elseif ($object->id > 0) {
2080  /*
2081  * Show object in view mode
2082  */
2083 
2084  $soc = new Societe($db);
2085  $soc->fetch($object->socid);
2086 
2087  $head = propal_prepare_head($object);
2088  print dol_get_fiche_head($head, 'comm', $langs->trans('Proposal'), -1, 'propal');
2089 
2090  $formconfirm = '';
2091 
2092  // Clone confirmation
2093  if ($action == 'clone') {
2094  // Create an array for form
2095  $formquestion = array(
2096  // 'text' => $langs->trans("ConfirmClone"),
2097  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
2098  array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)', '', 0, 0, null, 0, 'maxwidth300')),
2099  array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans('PuttingPricesUpToDate'), 'value' => (!empty($conf->global->PROPOSAL_CLONE_UPDATE_PRICES) ? 1 : 0)),
2100  );
2101  if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->delivery_date)) {
2102  $formquestion[] = array('type' => 'date', 'name' => 'date_delivery', 'label' => $langs->trans("DeliveryDate"), 'value' => $object->delivery_date);
2103  }
2104  // Incomplete payment. We ask if reason = discount or other
2105  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmClonePropal', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
2106  }
2107 
2108  if ($action == 'closeas') {
2109  //Form to close proposal (signed or not)
2110  $formquestion = array();
2111  if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
2112  $formquestion[] = array('type' => 'select', 'name' => 'statut', 'label' => '<span class="fieldrequired">'.$langs->trans("CloseAs").'</span>', 'values' => array($object::STATUS_SIGNED => $object->LibStatut($object::STATUS_SIGNED), $object::STATUS_NOTSIGNED => $object->LibStatut($object::STATUS_NOTSIGNED)));
2113  }
2114  $formquestion[] = array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => ''); // Field to complete private note (not replace)
2115 
2116  if (getDolGlobalInt('PROPOSAL_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2117  // This is a hidden option:
2118  // Suggestion to create invoice during proposal signature is not enabled by default.
2119  // Such choice should be managed by the workflow module and trigger. This option generates conflicts with some setup.
2120  // It may also break step of creating an order when invoicing must be done from orders and not from proposal
2121  $deposit_percent_from_payment_terms = getDictionaryValue('c_payment_term', 'deposit_percent', $object->cond_reglement_id);
2122 
2123  if (!empty($deposit_percent_from_payment_terms) && isModEnabled('facture') && !empty($user->rights->facture->creer)) {
2124  require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
2125 
2126  $object->fetchObjectLinked();
2127 
2128  $eligibleForDepositGeneration = true;
2129 
2130  if (array_key_exists('facture', $object->linkedObjects)) {
2131  foreach ($object->linkedObjects['facture'] as $invoice) {
2132  if ($invoice->type == Facture::TYPE_DEPOSIT) {
2133  $eligibleForDepositGeneration = false;
2134  break;
2135  }
2136  }
2137  }
2138 
2139  if ($eligibleForDepositGeneration && array_key_exists('commande', $object->linkedObjects)) {
2140  foreach ($object->linkedObjects['commande'] as $order) {
2141  $order->fetchObjectLinked();
2142 
2143  if (array_key_exists('facture', $order->linkedObjects)) {
2144  foreach ($order->linkedObjects['facture'] as $invoice) {
2145  if ($invoice->type == Facture::TYPE_DEPOSIT) {
2146  $eligibleForDepositGeneration = false;
2147  break 2;
2148  }
2149  }
2150  }
2151  }
2152  }
2153 
2154 
2155  if ($eligibleForDepositGeneration) {
2156  $formquestion[] = array(
2157  'type' => 'checkbox',
2158  'tdclass' => 'showonlyifsigned',
2159  'name' => 'generate_deposit',
2160  'morecss' => 'margintoponly marginbottomonly',
2161  'label' => $form->textwithpicto($langs->trans('GenerateDeposit', $object->deposit_percent), $langs->trans('DepositGenerationPermittedByThePaymentTermsSelected'))
2162  );
2163 
2164  $formquestion[] = array(
2165  'type' => 'date',
2166  'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
2167  'name' => 'datef',
2168  'label' => $langs->trans('DateInvoice'),
2169  'value' => dol_now(),
2170  'datenow' => true
2171  );
2172 
2173  if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2174  $formquestion[] = array(
2175  'type' => 'date',
2176  'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
2177  'name' => 'date_pointoftax',
2178  'label' => $langs->trans('DatePointOfTax'),
2179  'value' => dol_now(),
2180  'datenow' => true
2181  );
2182  }
2183 
2184  $paymentTermsSelect = $form->getSelectConditionsPaiements(0, 'cond_reglement_id', -1, 0, 1, 'minwidth200');
2185 
2186  $formquestion[] = array(
2187  'type' => 'other',
2188  'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
2189  'name' => 'cond_reglement_id',
2190  'label' => $langs->trans('PaymentTerm'),
2191  'value' => $paymentTermsSelect
2192  );
2193 
2194  $formquestion[] = array(
2195  'type' => 'checkbox',
2196  'tdclass' => 'showonlyifgeneratedeposit',
2197  'name' => 'validate_generated_deposit',
2198  'morecss' => 'margintoponly marginbottomonly',
2199  'label' => $langs->trans('ValidateGeneratedDeposit')
2200  );
2201 
2202  $formquestion[] = array(
2203  'type' => 'onecolumn',
2204  'value' => '
2205  <script>
2206  let signedValue = ' . $object::STATUS_SIGNED . ';
2207 
2208  $(document).ready(function() {
2209  $("[name=generate_deposit]").change(function () {
2210  let $self = $(this);
2211  let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2212 
2213  if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2214  $target.show();
2215  } else {
2216  $target.hide();
2217  }
2218 
2219  return true;
2220  });
2221 
2222  $("#statut").change(function() {
2223  let $target = $(".showonlyifsigned").parent(".tagtr");
2224 
2225  if ($(this).val() == signedValue) {
2226  $target.show();
2227  } else {
2228  $target.hide();
2229  }
2230 
2231  $("[name=generate_deposit]").trigger("change");
2232 
2233  return true;
2234  });
2235 
2236  $("#statut").trigger("change");
2237  });
2238  </script>
2239  '
2240  );
2241  }
2242  }
2243  }
2244 
2245  if (isModEnabled('notification')) {
2246  require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
2247  $notify = new Notify($db);
2248  $formquestion = array_merge($formquestion, array(
2249  array('type' => 'onecolumn', 'value' => $notify->confirmMessage('PROPAL_CLOSE_SIGNED', $object->socid, $object)),
2250  ));
2251  }
2252 
2253  if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
2254  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), '', 'confirm_closeas', $formquestion, '', 1, 250);
2255  } else {
2256  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?statut=3&id=' . $object->id, $langs->trans('Close'), '', 'confirm_closeas', $formquestion, '', 1, 250);
2257  }
2258  } elseif ($action == 'delete') {
2259  // Confirm delete
2260  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp', $object->ref), 'confirm_delete', '', 0, 1);
2261  } elseif ($action == 'reopen') {
2262  // Confirm reopen
2263  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp', $object->ref), 'confirm_reopen', '', 0, 1);
2264  } elseif ($action == 'ask_deleteline') {
2265  // Confirmation delete product/service line
2266  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
2267  } elseif ($action == 'validate') {
2268  // Confirm validate proposal
2269  $error = 0;
2270 
2271  // We verify whether the object is provisionally numbering
2272  $ref = substr($object->ref, 1, 4);
2273  if ($ref == 'PROV' || $ref == '') {
2274  $numref = $object->getNextNumRef($soc);
2275  if (empty($numref)) {
2276  $error++;
2277  setEventMessages($object->error, $object->errors, 'errors');
2278  }
2279  } else {
2280  $numref = $object->ref;
2281  }
2282 
2283  $text = $langs->trans('ConfirmValidateProp', $numref);
2284  if (isModEnabled('notification')) {
2285  require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
2286  $notify = new Notify($db);
2287  $text .= '<br>';
2288  $text .= $notify->confirmMessage('PROPAL_VALIDATE', $object->socid, $object);
2289  }
2290 
2291  // mandatoryPeriod
2292  $nbMandated = 0;
2293  foreach ($object->lines as $line) {
2294  $res = $line->fetch_product();
2295  if ($res > 0 ) {
2296  if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2297  $nbMandated++;
2298  break;
2299  }
2300  }
2301  }
2302  if ($nbMandated > 0) {
2303  $text .= '<div><span class="clearboth nowraponall warning">'.$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'</span></div>';
2304  }
2305 
2306  if (!$error) {
2307  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate', '', 0, 1);
2308  }
2309  }
2310 
2311  // Call Hook formConfirm
2312  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
2313  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2314  if (empty($reshook)) {
2315  $formconfirm .= $hookmanager->resPrint;
2316  } elseif ($reshook > 0) {
2317  $formconfirm = $hookmanager->resPrint;
2318  }
2319 
2320  // Print form confirm
2321  print $formconfirm;
2322 
2323 
2324  // Proposal card
2325 
2326  $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
2327 
2328  $morehtmlref = '<div class="refidno">';
2329  // Ref customer
2330  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1);
2331  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE : ''), '', null, null, '', 1);
2332  // Thirdparty
2333  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
2334  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2335  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherProposals").'</a>)';
2336  }
2337  // Project
2338  if (isModEnabled('project')) {
2339  $langs->load("projects");
2340  $morehtmlref .= '<br>';
2341  if ($usercancreate) {
2342  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
2343  if ($action != 'classify') {
2344  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
2345  }
2346  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
2347  } else {
2348  if (!empty($object->fk_project)) {
2349  $proj = new Project($db);
2350  $proj->fetch($object->fk_project);
2351  $morehtmlref .= $proj->getNomUrl(1);
2352  if ($proj->title) {
2353  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
2354  }
2355  }
2356  }
2357  }
2358  $morehtmlref .= '</div>';
2359 
2360 
2361  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
2362 
2363 
2364  print '<div class="fichecenter">';
2365  print '<div class="fichehalfleft">';
2366  print '<div class="underbanner clearboth"></div>';
2367 
2368  print '<table class="border tableforfield centpercent">';
2369 
2370  // Link for thirdparty discounts
2371  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2372  $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
2373  $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
2374  } else {
2375  $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2376  $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2377  }
2378 
2379  print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td>';
2380 
2381  $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
2382  $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
2383  $absolute_discount = price2num($absolute_discount, 'MT');
2384  $absolute_creditnote = price2num($absolute_creditnote, 'MT');
2385 
2386  $caneditfield = ($object->statut != Propal::STATUS_SIGNED && $object->statut != Propal::STATUS_BILLED);
2387 
2388  $thirdparty = $soc;
2389  $discount_type = 0;
2390  $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
2391  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
2392 
2393  print '</td></tr>';
2394 
2395  // Date of proposal
2396  print '<tr>';
2397  print '<td>';
2398  // print '<table class="nobordernopadding" width="100%"><tr><td>';
2399  // print $langs->trans('DatePropal');
2400  // print '</td>';
2401  // if ($action != 'editdate' && $usercancreate && $caneditfield) {
2402  // print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
2403  // }
2404 
2405  // print '</tr></table>';
2406  $editenable = $usercancreate && $caneditfield && $object->statut == Propal::STATUS_DRAFT;
2407  print $form->editfieldkey("DatePropal", 'date', '', $object, $editenable);
2408  print '</td><td class="valuefield">';
2409  if ($action == 'editdate' && $usercancreate && $caneditfield) {
2410  print '<form name="editdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2411  print '<input type="hidden" name="token" value="'.newToken().'">';
2412  print '<input type="hidden" name="action" value="setdate">';
2413  print $form->selectDate($object->date, 're', '', '', 0, "editdate");
2414  print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2415  print '</form>';
2416  } else {
2417  if ($object->date) {
2418  print dol_print_date($object->date, 'day');
2419  } else {
2420  print '&nbsp;';
2421  }
2422  }
2423  print '</td>';
2424 
2425  // Date end proposal
2426  print '<tr>';
2427  print '<td>';
2428  print '<table class="nobordernopadding centpercent"><tr><td>';
2429  print $langs->trans('DateEndPropal');
2430  print '</td>';
2431  if ($action != 'editecheance' && $usercancreate && $caneditfield) {
2432  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editecheance&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
2433  }
2434  print '</tr></table>';
2435  print '</td><td class="valuefield">';
2436  if ($action == 'editecheance' && $usercancreate && $caneditfield) {
2437  print '<form name="editecheance" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2438  print '<input type="hidden" name="token" value="'.newToken().'">';
2439  print '<input type="hidden" name="action" value="setecheance">';
2440  print $form->selectDate($object->fin_validite, 'ech', '', '', '', "editecheance");
2441  print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2442  print '</form>';
2443  } else {
2444  if (!empty($object->fin_validite)) {
2445  print dol_print_date($object->fin_validite, 'day');
2446  if ($object->statut == Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) {
2447  print img_warning($langs->trans("Late"));
2448  }
2449  } else {
2450  print '&nbsp;';
2451  }
2452  }
2453  print '</td>';
2454  print '</tr>';
2455 
2456  // Payment term
2457  print '<tr><td>';
2458  print '<table class="nobordernopadding" width="100%"><tr><td>';
2459  print $langs->trans('PaymentConditionsShort');
2460  print '</td>';
2461  if ($action != 'editconditions' && $usercancreate && $caneditfield) {
2462  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'), 1).'</a></td>';
2463  }
2464  print '</tr></table>';
2465  print '</td><td class="valuefield">';
2466  if ($action == 'editconditions' && $usercancreate && $caneditfield) {
2467  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 0, '', 1, $object->deposit_percent);
2468  } else {
2469  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 0, '', 1, $object->deposit_percent);
2470  }
2471  print '</td>';
2472  print '</tr>';
2473 
2474  // Payment mode
2475  print '<tr class="field_mode_reglement_id">';
2476  print '<td class="titlefieldcreate">';
2477  print '<table class="nobordernopadding centpercent"><tr><td>';
2478  print $langs->trans('PaymentMode');
2479  print '</td>';
2480  if ($action != 'editmode' && $usercancreate && $caneditfield) {
2481  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'), 1).'</a></td>';
2482  }
2483  print '</tr></table>';
2484  print '</td><td class="valuefieldcreate">';
2485  if ($action == 'editmode' && $usercancreate && $caneditfield) {
2486  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
2487  } else {
2488  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
2489  }
2490  print '</td></tr>';
2491 
2492  // Delivery date
2493  $langs->load('deliveries');
2494  print '<tr><td>';
2495  print $form->editfieldkey($langs->trans('DeliveryDate'), 'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield, 'datepicker');
2496  print '</td><td class="valuefieldedit">';
2497  print $form->editfieldval($langs->trans('DeliveryDate'), 'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield, 'datepicker');
2498  print '</td>';
2499  print '</tr>';
2500 
2501  // Delivery delay
2502  print '<tr class="fielddeliverydelay"><td>';
2503  print '<table class="nobordernopadding" width="100%"><tr><td>';
2504  if (isModEnabled('commande')) {
2505  print $form->textwithpicto($langs->trans('AvailabilityPeriod'), $langs->trans('AvailabilityPeriod').' ('.$langs->trans('AfterOrder').')');
2506  } else {
2507  print $langs->trans('AvailabilityPeriod');
2508  }
2509  print '</td>';
2510  if ($action != 'editavailability' && $usercancreate && $caneditfield) {
2511  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editavailability&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'), 1).'</a></td>';
2512  }
2513  print '</tr></table>';
2514  print '</td><td class="valuefield">';
2515  if ($action == 'editavailability' && $usercancreate && $caneditfield) {
2516  $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1);
2517  } else {
2518  $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1);
2519  }
2520 
2521  print '</td>';
2522  print '</tr>';
2523 
2524  // Shipping Method
2525  if (isModEnabled("expedition")) {
2526  print '<tr><td>';
2527  print '<table class="nobordernopadding centpercent"><tr><td>';
2528  print $langs->trans('SendingMethod');
2529  print '</td>';
2530  if ($action != 'editshippingmethod' && $usercancreate && $caneditfield) {
2531  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshippingmethod&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetShippingMode'), 1).'</a></td>';
2532  }
2533  print '</tr></table>';
2534  print '</td><td class="valuefield">';
2535  if ($action == 'editshippingmethod' && $usercancreate && $caneditfield) {
2536  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
2537  } else {
2538  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none');
2539  }
2540  print '</td>';
2541  print '</tr>';
2542  }
2543 
2544  // Warehouse
2545  if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
2546  $langs->load('stocks');
2547  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2548  $formproduct = new FormProduct($db);
2549  print '<tr class="field_warehouse_id"><td class="titlefieldcreate">';
2550  $editenable = $usercancreate;
2551  print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $editenable);
2552  print '</td><td class="valuefieldcreate">';
2553  if ($action == 'editwarehouse') {
2554  $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1);
2555  } else {
2556  $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none');
2557  }
2558  print '</td>';
2559  print '</tr>';
2560  }
2561 
2562  // Origin of demand
2563  print '<tr><td>';
2564  print '<table class="nobordernopadding centpercent"><tr><td>';
2565  print $langs->trans('Source');
2566  print '</td>';
2567  if ($action != 'editdemandreason' && $usercancreate) {
2568  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'), 1).'</a></td>';
2569  }
2570  print '</tr></table>';
2571  print '</td><td class="valuefield">';
2572  if ($action == 'editdemandreason' && $usercancreate) {
2573  $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1);
2574  } else {
2575  $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none');
2576  }
2577  print '</td>';
2578  print '</tr>';
2579 
2580  // Multicurrency
2581  if (isModEnabled("multicurrency")) {
2582  // Multicurrency code
2583  print '<tr>';
2584  print '<td>';
2585  print '<table class="nobordernopadding" width="100%"><tr><td>';
2586  print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
2587  print '</td>';
2588  if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT && $usercancreate) {
2589  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencycode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
2590  }
2591  print '</tr></table>';
2592  print '</td><td class="valuefield">';
2593  if ($object->statut == $object::STATUS_DRAFT && $action == 'editmulticurrencycode' && $usercancreate) {
2594  $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
2595  } else {
2596  $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
2597  }
2598  print '</td></tr>';
2599 
2600  // Multicurrency rate
2601  if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2602  print '<tr>';
2603  print '<td>';
2604  print '<table class="nobordernopadding" width="100%"><tr>';
2605  print '<td>';
2606  print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
2607  print '</td>';
2608  if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $usercancreate) {
2609  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencyrate&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
2610  }
2611  print '</tr></table>';
2612  print '</td><td class="valuefield">';
2613  if ($object->statut == $object::STATUS_DRAFT && ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') && $usercancreate) {
2614  if ($action == 'actualizemulticurrencyrate') {
2615  list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
2616  }
2617  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
2618  } else {
2619  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
2620  if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2621  print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
2622  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
2623  print '</div>';
2624  }
2625  }
2626  print '</td></tr>';
2627  }
2628  }
2629 
2630  if ($soc->outstanding_limit) {
2631  // Outstanding Bill
2632  print '<tr><td>';
2633  print $langs->trans('OutstandingBill');
2634  print '</td><td class="valuefield">';
2635  $arrayoutstandingbills = $soc->getOutstandingBills();
2636  print ($arrayoutstandingbills['opened'] > $soc->outstanding_limit ? img_warning() : '');
2637  print price($arrayoutstandingbills['opened']).' / ';
2638  print price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency);
2639  print '</td>';
2640  print '</tr>';
2641  }
2642 
2643  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && isModEnabled("banque")) {
2644  // Bank Account
2645  print '<tr><td>';
2646  print '<table width="100%" class="nobordernopadding"><tr><td>';
2647  print $langs->trans('BankAccount');
2648  print '</td>';
2649  if ($action != 'editbankaccount' && $usercancreate) {
2650  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
2651  }
2652  print '</tr></table>';
2653  print '</td><td class="valuefield">';
2654  if ($action == 'editbankaccount') {
2655  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
2656  } else {
2657  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
2658  }
2659  print '</td>';
2660  print '</tr>';
2661  }
2662 
2663  $tmparray = $object->getTotalWeightVolume();
2664  $totalWeight = $tmparray['weight'];
2665  $totalVolume = $tmparray['volume'];
2666  if ($totalWeight) {
2667  print '<tr><td>'.$langs->trans("CalculatedWeight").'</td>';
2668  print '<td class="valuefield">';
2669  print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no', 0);
2670  print '</td></tr>';
2671  }
2672  if ($totalVolume) {
2673  print '<tr><td>'.$langs->trans("CalculatedVolume").'</td>';
2674  print '<td class="valuefield">';
2675  print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no', 0);
2676  print '</td></tr>';
2677  }
2678 
2679  // Incoterms
2680  if (isModEnabled('incoterm')) {
2681  print '<tr><td>';
2682  print '<table width="100%" class="nobordernopadding"><tr><td>';
2683  print $langs->trans('IncotermLabel');
2684  print '<td><td class="right">';
2685  if ($action != 'editincoterm' && $usercancreate && $caneditfield) {
2686  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
2687  } else {
2688  print '&nbsp;';
2689  }
2690  print '</td></tr></table>';
2691  print '</td>';
2692  print '<td class="valuefield">';
2693  if ($action == 'editincoterm' && $usercancreate && $caneditfield) {
2694  print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
2695  } else {
2696  print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2697  }
2698  print '</td></tr>';
2699  }
2700 
2701  // Other attributes
2702  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2703 
2704  print '</table>';
2705 
2706  print '</div>';
2707  print '<div class="fichehalfright">';
2708  print '<div class="underbanner clearboth"></div>';
2709 
2710  print '<table class="border tableforfield centpercent">';
2711 
2712  if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2713  // Multicurrency Amount HT
2714  print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';
2715  print '<td class="nowrap right amountcard">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
2716  print '</tr>';
2717 
2718  // Multicurrency Amount VAT
2719  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';
2720  print '<td class="nowrap right amountcard">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
2721  print '</tr>';
2722 
2723  // Multicurrency Amount TTC
2724  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';
2725  print '<td class="nowrap right amountcard">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
2726  print '</tr>';
2727  }
2728 
2729  // Amount HT
2730  print '<tr><td class="titlefieldmiddle">'.$langs->trans('AmountHT').'</td>';
2731  print '<td class="nowrap right amountcard">'.price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
2732  print '</tr>';
2733 
2734  // Amount VAT
2735  print '<tr><td>'.$langs->trans('AmountVAT').'</td>';
2736  print '<td class="nowrap right amountcard">'.price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
2737  print '</tr>';
2738 
2739  // Amount Local Taxes
2740  if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { // Localtax1
2741  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
2742  print '<td class="nowrap right amountcard">'.price($object->total_localtax1, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
2743  print '</tr>';
2744  }
2745  if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { // Localtax2
2746  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
2747  print '<td class="nowrap right amountcard">'.price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
2748  print '</tr>';
2749  }
2750 
2751  // Amount TTC
2752  print '<tr><td>'.$langs->trans('AmountTTC').'</td>';
2753  print '<td class="nowrap right amountcard">'.price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
2754  print '</tr>';
2755 
2756  // Statut
2757  //print '<tr><td height="10">' . $langs->trans('Status') . '</td><td class="left" colspan="2">' . $object->getLibStatut(4) . '</td></tr>';
2758 
2759  print '</table>';
2760 
2761  // Margin Infos
2762  if (isModEnabled('margin')) {
2763  $formmargin->displayMarginInfos($object);
2764  }
2765 
2766  print '</div>';
2767  print '</div>';
2768 
2769  print '<div class="clearboth"></div><br>';
2770 
2771  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2772  $blocname = 'contacts';
2773  $title = $langs->trans('ContactsAddresses');
2774  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2775  }
2776 
2777  if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2778  $blocname = 'notes';
2779  $title = $langs->trans('Notes');
2780  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2781  }
2782 
2783  /*
2784  * Lines
2785  */
2786 
2787  // Get object lines
2788  $result = $object->getLinesArray();
2789 
2790  // Add products/services form
2791  //$forceall = 1;
2792  global $inputalsopricewithtax;
2793  $inputalsopricewithtax = 1;
2794 
2795  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">
2796  <input type="hidden" name="token" value="' . newToken().'">
2797  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
2798  <input type="hidden" name="mode" value="">
2799  <input type="hidden" name="page_y" value="">
2800  <input type="hidden" name="id" value="' . $object->id.'">
2801  ';
2802 
2803  if (!empty($conf->use_javascript_ajax) && $object->statut == Propal::STATUS_DRAFT) {
2804  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
2805  }
2806 
2807  print '<div class="div-table-responsive-no-min">';
2808  if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) {
2809  print '<table id="tablelines" class="noborder noshadow" width="100%">';
2810  }
2811 
2812  if (!empty($object->lines)) {
2813  $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2814  }
2815 
2816  // Form to add new line
2817  if ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines') {
2818  if ($action != 'editline') {
2819  $parameters = array();
2820  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2821  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2822  if (empty($reshook))
2823  $object->formAddObjectLine(1, $mysoc, $soc);
2824  } else {
2825  $parameters = array();
2826  $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2827  }
2828  }
2829 
2830  if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) {
2831  print '</table>';
2832  }
2833  print '</div>';
2834 
2835  print "</form>\n";
2836 
2837  print dol_get_fiche_end();
2838 
2839 
2840  /*
2841  * Button Actions
2842  */
2843 
2844  if ($action != 'presend') {
2845  print '<div class="tabsAction">';
2846 
2847  $parameters = array();
2848  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2849  // modified by hook
2850  if (empty($reshook)) {
2851  if ($action != 'editline') {
2852  // Validate
2853  if (($object->statut == Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0)
2854  || ($object->statut == Propal::STATUS_DRAFT && !empty($conf->global->PROPAL_ENABLE_NEGATIVE) && count($object->lines) > 0)) {
2855  if ($usercanvalidate) {
2856  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=validate&token='.newToken().'">'.(empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) ? $langs->trans('Validate') : $langs->trans('ValidateAndSign')).'</a>';
2857  } else {
2858  print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Validate').'</a>';
2859  }
2860  }
2861  // Create event
2862  /*if ($conf->agenda->enabled && !empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page.
2863  {
2864  print '<a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddAction") . '</a></div>';
2865  }*/
2866  // Edit
2867  if ($object->statut == Propal::STATUS_VALIDATED && $usercancreate) {
2868  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=modif&token='.newToken().'">'.$langs->trans('Modify').'</a>';
2869  }
2870 
2871  // ReOpen
2872  if ( (( !empty($conf->global->PROPAL_REOPEN_UNSIGNED_ONLY) && $object->statut == Propal::STATUS_NOTSIGNED) || (empty($conf->global->PROPAL_REOPEN_UNSIGNED_ONLY) && ($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED))) && $usercanclose) {
2873  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#reopen').'"';
2874  print '>'.$langs->trans('ReOpen').'</a>';
2875  }
2876 
2877  // Send
2878  if (empty($user->socid)) {
2879  if ($object->statut == Propal::STATUS_VALIDATED || $object->statut == Propal::STATUS_SIGNED || !empty($conf->global->PROPOSAL_SENDBYEMAIL_FOR_ALL_STATUS)) {
2880  print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '', $usercansend);
2881  }
2882  }
2883 
2884  // Create a sale order
2885  if (isModEnabled('commande') && $object->statut == Propal::STATUS_SIGNED) {
2886  if ($usercancreateorder) {
2887  print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddOrder").'</a>';
2888  }
2889  }
2890 
2891  // Create a purchase order
2892  if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_PROPOSAL)) {
2893  if ($object->statut == Propal::STATUS_SIGNED && ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order"))) {
2894  if ($usercancreatepurchaseorder) {
2895  print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddPurchaseOrder").'</a>';
2896  }
2897  }
2898  }
2899 
2900  // Create an intervention
2901  if (isModEnabled("service") && isModEnabled('ficheinter') && $object->statut == Propal::STATUS_SIGNED) {
2902  if ($usercancreateintervention) {
2903  $langs->load("interventions");
2904  print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddIntervention").'</a>';
2905  }
2906  }
2907 
2908  // Create contract
2909  if (isModEnabled('contrat') && $object->statut == Propal::STATUS_SIGNED) {
2910  $langs->load("contracts");
2911 
2912  if ($usercancreatecontract) {
2913  print '<a class="butAction" href="'.DOL_URL_ROOT.'/contrat/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans('AddContract').'</a>';
2914  }
2915  }
2916 
2917  // Create an invoice and classify billed
2918  if ($object->statut == Propal::STATUS_SIGNED && empty($conf->global->PROPOSAL_ARE_NOT_BILLABLE)) {
2919  if (isModEnabled('facture') && $usercancreateinvoice) {
2920  print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
2921  }
2922 
2923  $arrayofinvoiceforpropal = $object->getInvoiceArrayList();
2924  if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED)) {
2925  if ($usercanclose) {
2926  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled&token='.newToken().'&socid='.$object->socid.'">'.$langs->trans("ClassifyBilled").'</a>';
2927  } else {
2928  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("ClassifyBilled").'</a>';
2929  }
2930  }
2931  }
2932 
2933  if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
2934  // Close as accepted/refused
2935  if ($object->statut == Propal::STATUS_VALIDATED) {
2936  if ($usercanclose) {
2937  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=closeas&token='.newToken().(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#close').'"';
2938  print '>'.$langs->trans('SetAcceptedRefused').'</a>';
2939  } else {
2940  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'"';
2941  print '>'.$langs->trans('SetAcceptedRefused').'</a>';
2942  }
2943  }
2944  } else {
2945  // Set not signed (close)
2946  if ($object->statut == Propal::STATUS_DRAFT && $usercanclose) {
2947  print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&token='.newToken().'&action=closeas&token='.newToken() . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#close') . '"';
2948  print '>' . $langs->trans('SetRefusedAndClose') . '</a>';
2949  }
2950  }
2951 
2952  // Clone
2953  if ($usercancreate) {
2954  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().'&object='.$object->element.'">'.$langs->trans("ToClone").'</a>';
2955  }
2956 
2957  // Delete
2958  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $usercandelete);
2959  }
2960  }
2961 
2962  print '</div>';
2963  }
2964 
2965  //Select mail models is same action as presend
2966  if (GETPOST('modelselected')) {
2967  $action = 'presend';
2968  }
2969 
2970  if ($action != 'presend') {
2971  print '<div class="fichecenter"><div class="fichehalfleft">';
2972  print '<a name="builddoc"></a>'; // ancre
2973  /*
2974  * Generated documents
2975  */
2976  $objref = dol_sanitizeFileName($object->ref);
2977  $filedir = $conf->propal->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
2978  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2979  $genallowed = $usercanread;
2980  $delallowed = $usercancreate;
2981 
2982  print $formfile->showdocuments('propal', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang, '', $object);
2983 
2984  // Show links to link elements
2985  $linktoelem = $form->showLinkToObjectBlock($object, null, array('propal'));
2986 
2987  $compatibleImportElementsList = false;
2988  if ($user->rights->propal->creer && $object->statut == Propal::STATUS_DRAFT) {
2989  $compatibleImportElementsList = array('commande', 'propal'); // import from linked elements
2990  }
2991  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2992 
2993  // Show online signature link
2994  $useonlinesignature = 1;
2995 
2996  if ($object->statut != Propal::STATUS_DRAFT && $useonlinesignature) {
2997  print '<br><!-- Link to sign -->';
2998  require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
2999  print showOnlineSignatureUrl('proposal', $object->ref).'<br>';
3000  }
3001 
3002  print '</div><div class="fichehalfright">';
3003 
3004  // List of actions on element
3005  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
3006  $formactions = new FormActions($db);
3007  $somethingshown = $formactions->showactions($object, 'propal', $socid, 1);
3008 
3009  print '</div></div>';
3010  }
3011 
3012  // Presend form
3013  $modelmail = 'propal_send';
3014  $defaulttopic = 'SendPropalRef';
3015  $diroutput = $conf->propal->multidir_output[$object->entity];
3016  $trackid = 'pro'.$object->id;
3017 
3018  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3019 }
3020 
3021 // End of page
3022 llxFooter();
3023 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:49
Propal\STATUS_SIGNED
const STATUS_SIGNED
Signed quote.
Definition: propal.class.php:365
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
Project
Class to manage projects.
Definition: project.class.php:35
ProductCombination
Class ProductCombination Used to represent a product combination.
Definition: ProductCombination.class.php:24
Productcustomerprice
File of class to manage predefined price products or services by customer.
Definition: productcustomerprice.class.php:29
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5360
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1032
Translate
Class to manage translations.
Definition: translate.class.php:30
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4670
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
FormMargin
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formmargin.class.php:29
FormPropal
Class to manage generation of HTML components for proposal management.
Definition: html.formpropal.class.php:28
dol_clone
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
Definition: functions.lib.php:1157
Notify
Class to manage notifications.
Definition: notify.class.php:33
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4538
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2082
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5823
Facture\TYPE_DEPOSIT
const TYPE_DEPOSIT
Deposit invoice.
Definition: facture.class.php:392
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2550
Propal\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: propal.class.php:357
dol_concatdesc
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Definition: functions.lib.php:7542
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4024
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
Facture\createDepositFromOrigin
static createDepositFromOrigin(CommonObject $origin, $date, $payment_terms_id, User $user, $notrigger=0, $autoValidateDeposit=false, $overrideFields=array())
Creates a deposit from a proposal or an order by grouping lines by VAT rates.
Definition: facture.class.php:1494
$formactions
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
Definition: agenda_other.php:179
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:614
Propal\STATUS_BILLED
const STATUS_BILLED
Billed or processed quote.
Definition: propal.class.php:373
get_default_npr
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
Definition: functions.lib.php:6591
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
get_localtax
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
Definition: functions.lib.php:6004
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
propal_prepare_head
propal_prepare_head($object)
Prepare array with list of tabs.
Definition: propal.lib.php:32
getDictionaryValue
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
Definition: functions.lib.php:10540
Propal\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: propal.class.php:361
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
setEventMessage
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Definition: functions.lib.php:8436
MultiCurrency\getIdAndTxFromCode
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Definition: multicurrency.class.php:526
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1858
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
dol_htmlcleanlastbr
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
Definition: functions.lib.php:7326
get_default_tva
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
Definition: functions.lib.php:6490
restrictedArea
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:346
FormProduct
Class with static methods for building HTML components related to products Only components common to ...
Definition: html.formproduct.class.php:30
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11290
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2054
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:421
dolGetButtonAction
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
Definition: functions.lib.php:10853
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
$parameters
$parameters
Actions.
Definition: card.php:79
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5697
getCountry
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
Definition: company.lib.php:515
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8465
ModelePDFPropales\liste_modeles
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Definition: modules_propale.php:53
Propal
Class to manage proposals.
Definition: propal.class.php:52
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2863
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
showDimensionInBestUnit
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
Definition: functions.lib.php:5955
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30
Propal\STATUS_NOTSIGNED
const STATUS_NOTSIGNED
Not signed quote.
Definition: propal.class.php:369