dolibarr  7.0.0-beta
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-2014 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@capnetworks.com>
7  * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
8  * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2010-2015 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  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29 
30 
37 require '../../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
39 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
40 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formpropal.class.php';
41 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmargin.class.php';
42 require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
43 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
44 require_once DOL_DOCUMENT_ROOT . '/core/modules/propale/modules_propale.php';
45 require_once DOL_DOCUMENT_ROOT . '/core/lib/propal.lib.php';
46 require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
47 require_once DOL_DOCUMENT_ROOT . '/core/lib/signature.lib.php';
48 require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
49 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
50 if (! empty($conf->projet->enabled)) {
51  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
52  require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
53 }
54 
55 if (!empty($conf->variants->enabled)) {
56  require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
57 }
58 
59 $langs->load('companies');
60 $langs->load('propal');
61 $langs->load('compta');
62 $langs->load('bills');
63 $langs->load('orders');
64 $langs->load('products');
65 $langs->load("deliveries");
66 $langs->load('sendings');
67 if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
68 if (! empty($conf->margin->enabled))
69  $langs->load('margins');
70 
71 $error = 0;
72 
73 $id = GETPOST('id', 'int');
74 $ref = GETPOST('ref', 'alpha');
75 $socid = GETPOST('socid', 'int');
76 $action = GETPOST('action', 'alpha');
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 
84 // PDF
85 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
86 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
87 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
88 
89 // Nombre de ligne pour choix de produit/service predefinis
90 $NBLINES = 4;
91 
92 // Security check
93 if (! empty($user->societe_id)) $socid = $user->societe_id;
94 $result = restrictedArea($user, 'propal', $id);
95 
96 $object = new Propal($db);
97 $extrafields = new ExtraFields($db);
98 
99 // fetch optionals attributes and labels
100 $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
101 
102 // Load object
103 if ($id > 0 || ! empty($ref)) {
104  $ret = $object->fetch($id, $ref);
105  if ($ret > 0)
106  $ret = $object->fetch_thirdparty();
107  if ($ret < 0)
108  dol_print_error('', $object->error);
109 }
110 
111 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
112 $hookmanager->initHooks(array('propalcard','globalcard'));
113 
114 $permissionnote = $user->rights->propale->creer; // Used by the include of actions_setnotes.inc.php
115 $permissiondellink=$user->rights->propale->creer; // Used by the include of actions_dellink.inc.php
116 $permissiontoedit = $user->rights->propale->creer; // Used by the include of actions_lineupdown.inc.php
117 
118 
119 /*
120  * Actions
121  */
122 
123 $parameters = array('socid' => $socid);
124 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
125 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
126 
127 if (empty($reshook))
128 {
129  if ($cancel)
130  {
131  if (! empty($backtopage))
132  {
133  header("Location: ".$backtopage);
134  exit;
135  }
136  $action='';
137  }
138 
139  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
140 
141  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
142 
143  include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
144 
145  // Action clone object
146  if ($action == 'confirm_clone' && $confirm == 'yes')
147  {
148  if (! GETPOST('socid', 3))
149  {
150  setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
151  }
152  else
153  {
154  if ($object->id > 0) {
155  if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY)) {
156  //Get difference between old and new delivery date and change lines according to difference
157  $date_delivery = dol_mktime(12, 0, 0,
158  GETPOST('date_deliverymonth', 'int'),
159  GETPOST('date_deliveryday', 'int'),
160  GETPOST('date_deliveryyear', 'int')
161  );
162  if (!empty($object->date_livraison) && !empty($date_delivery))
163  {
164  //Attempt to get the date without possible hour rounding errors
165  $old_date_delivery = dol_mktime(12, 0, 0,
166  dol_print_date($object->date_livraison, '%m'),
167  dol_print_date($object->date_livraison, '%d'),
168  dol_print_date($object->date_livraison, '%Y')
169  );
170  //Calculate the difference and apply if necessary
171  $difference = $date_delivery - $old_date_delivery;
172  if ($difference != 0)
173  {
174  $object->date_livraison = $date_delivery;
175  foreach ($object->lines as $line)
176  {
177  if (isset($line->date_start)) $line->date_start = $line->date_start + $difference;
178  if (isset($line->date_end)) $line->date_end = $line->date_end + $difference;
179  }
180  }
181  }
182  }
183 
184  $result = $object->createFromClone($socid);
185  if ($result > 0) {
186  header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result);
187  exit();
188  } else {
189  if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors');
190  $action = '';
191  }
192  }
193  }
194  }
195 
196  // Delete proposal
197  else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propal->supprimer)
198  {
199  $result = $object->delete($user);
200  if ($result > 0) {
201  header('Location: ' . DOL_URL_ROOT . '/comm/propal/list.php');
202  exit();
203  } else {
204  $langs->load("errors");
205  setEventMessages($object->error, $object->errors, 'errors');
206  }
207  }
208 
209  // Remove line
210  else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propal->creer)
211  {
212  $result = $object->deleteline($lineid);
213  // reorder lines
214  if ($result)
215  $object->line_order(true);
216 
217  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
218  // Define output language
219  $outputlangs = $langs;
220  if (! empty($conf->global->MAIN_MULTILANGS)) {
221  $outputlangs = new Translate("", $conf);
222  $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang);
223  $outputlangs->setDefaultLang($newlang);
224  }
225  $ret = $object->fetch($id); // Reload to get new records
226  $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
227  }
228 
229  header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
230  exit();
231  }
232 
233  // Validation
234  else if ($action == 'confirm_validate' && $confirm == 'yes' &&
235  ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->creer))
236  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->propal_advance->validate)))
237  )
238  {
239  $result = $object->valid($user);
240  if ($result >= 0)
241  {
242  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
243  {
244  $outputlangs = $langs;
245  $newlang = '';
246  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
247  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
248  if (! empty($newlang)) {
249  $outputlangs = new Translate("", $conf);
250  $outputlangs->setDefaultLang($newlang);
251  }
252  $model=$object->modelpdf;
253  $ret = $object->fetch($id); // Reload to get new records
254 
255  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
256  }
257  } else {
258  $langs->load("errors");
259  if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors');
260  else setEventMessages($langs->trans($object->error), null, 'errors');
261  }
262  }
263 
264  else if ($action == 'setdate' && $user->rights->propal->creer)
265  {
266  $datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
267 
268  if (empty($datep)) {
269  $error ++;
270  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
271  }
272 
273  if (! $error) {
274  $result = $object->set_date($user, $datep);
275  if ($result < 0)
276  dol_print_error($db, $object->error);
277  }
278  }
279  else if ($action == 'setecheance' && $user->rights->propal->creer)
280  {
281  $result = $object->set_echeance($user, dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']));
282  if ($result < 0)
283  dol_print_error($db, $object->error);
284  }
285  else if ($action == 'setdate_livraison' && $user->rights->propal->creer)
286  {
287  $result = $object->set_date_livraison($user, dol_mktime(12, 0, 0, $_POST['date_livraisonmonth'], $_POST['date_livraisonday'], $_POST['date_livraisonyear']));
288  if ($result < 0)
289  dol_print_error($db, $object->error);
290  }
291 
292  // Positionne ref client
293  else if ($action == 'setref_client' && $user->rights->propal->creer)
294  {
295  $result = $object->set_ref_client($user, GETPOST('ref_client'));
296  if ($result < 0)
297  {
298  setEventMessages($object->error, $object->errors, 'errors');
299  }
300  }
301 
302  // Set incoterm
303  elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
304  {
305  $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
306  }
307 
308  // Create proposal
309  else if ($action == 'add' && $user->rights->propal->creer)
310  {
311  $object->socid = $socid;
312  $object->fetch_thirdparty();
313 
314  $datep = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
315  $date_delivery = dol_mktime(12, 0, 0, GETPOST('date_livraisonmonth'), GETPOST('date_livraisonday'), GETPOST('date_livraisonyear'));
316  $duration = GETPOST('duree_validite');
317 
318  if (empty($datep)) {
319  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
320  $action = 'create';
321  $error ++;
322  }
323  if (empty($duration)) {
324  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ValidityDuration")), null, 'errors');
325  $action = 'create';
326  $error ++;
327  }
328 
329  if ($socid < 1) {
330  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), null, 'errors');
331 
332  $action = 'create';
333  $error ++;
334  }
335 
336  if (! $error)
337  {
338  $db->begin();
339 
340  // If we select proposal to clone during creation (when option PROPAL_CLONE_ON_CREATE_PAGE is on)
341  if (GETPOST('createmode') == 'copy' && GETPOST('copie_propal'))
342  {
343  if ($object->fetch(GETPOST('copie_propal')) > 0) {
344  $object->ref = GETPOST('ref');
345  $object->datep = $datep;
346  $object->date_livraison = $date_delivery;
347  $object->availability_id = GETPOST('availability_id');
348  $object->demand_reason_id = GETPOST('demand_reason_id');
349  $object->fk_delivery_address = GETPOST('fk_address');
350  $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
351  $object->duree_validite = $duration;
352  $object->cond_reglement_id = GETPOST('cond_reglement_id');
353  $object->mode_reglement_id = GETPOST('mode_reglement_id');
354  $object->fk_account = GETPOST('fk_account', 'int');
355  $object->remise_percent = GETPOST('remise_percent');
356  $object->remise_absolue = GETPOST('remise_absolue');
357  $object->socid = GETPOST('socid');
358  $object->contactid = GETPOST('contactid');
359  $object->fk_project = GETPOST('projectid');
360  $object->modelpdf = GETPOST('model');
361  $object->author = $user->id; // deprecated
362  $object->note_private = GETPOST('note_private','none');
363  $object->note_public = GETPOST('note_public','none');
364  $object->statut = Propal::STATUS_DRAFT;
365  $object->fk_incoterms = GETPOST('incoterm_id', 'int');
366  $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
367 
368  // the create is done below and further more the existing create_from function is quite hilarating
369  //$id = $object->create_from($user);
370  } else {
371  setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_propal')), null, 'errors');
372  }
373  } else {
374  $object->ref = GETPOST('ref');
375  $object->ref_client = GETPOST('ref_client');
376  $object->datep = $datep;
377  $object->date_livraison = $date_delivery;
378  $object->availability_id = GETPOST('availability_id');
379  $object->demand_reason_id = GETPOST('demand_reason_id');
380  $object->fk_delivery_address = GETPOST('fk_address');
381  $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
382  $object->duree_validite = GETPOST('duree_validite');
383  $object->cond_reglement_id = GETPOST('cond_reglement_id');
384  $object->mode_reglement_id = GETPOST('mode_reglement_id');
385  $object->fk_account = GETPOST('fk_account', 'int');
386  $object->contactid = GETPOST('contactid');
387  $object->fk_project = GETPOST('projectid');
388  $object->modelpdf = GETPOST('model');
389  $object->author = $user->id; // deprecated
390  $object->note_private = GETPOST('note_private','none');
391  $object->note_public = GETPOST('note_public','none');
392  $object->fk_incoterms = GETPOST('incoterm_id', 'int');
393  $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
394 
395  $object->origin = GETPOST('origin');
396  $object->origin_id = GETPOST('originid');
397 
398  // Multicurrency
399  if (!empty($conf->multicurrency->enabled))
400  {
401  $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
402  }
403 
404  // Fill array 'array_options' with data from add form
405  $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
406  if ($ret < 0) {
407  $error ++;
408  $action = 'create';
409  }
410  }
411 
412  if (! $error)
413  {
414  if ($origin && $originid)
415  {
416  // Parse element/subelement (ex: project_task)
417  $element = $subelement = $origin;
418  if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
419  $element = $regs [1];
420  $subelement = $regs [2];
421  }
422 
423  // For compatibility
424  if ($element == 'order') {
425  $element = $subelement = 'commande';
426  }
427  if ($element == 'propal') {
428  $element = 'comm/propal';
429  $subelement = 'propal';
430  }
431  if ($element == 'contract') {
432  $element = $subelement = 'contrat';
433  }
434  if ($element == 'inter') {
435  $element = $subelement = 'ficheinter';
436  }
437  if ($element == 'shipping') {
438  $element = $subelement = 'expedition';
439  }
440 
441  $object->origin = $origin;
442  $object->origin_id = $originid;
443 
444  // Possibility to add external linked objects with hooks
445  $object->linked_objects [$object->origin] = $object->origin_id;
446  if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) {
447  $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
448  }
449 
450  $id = $object->create($user);
451  if ($id > 0)
452  {
453  dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
454 
455  $classname = ucfirst($subelement);
456  $srcobject = new $classname($db);
457 
458  dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
459  $result = $srcobject->fetch($object->origin_id);
460 
461  if ($result > 0)
462  {
463  $lines = $srcobject->lines;
464  if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
465  {
466  $srcobject->fetch_lines();
467  $lines = $srcobject->lines;
468  }
469 
470  $fk_parent_line=0;
471  $num=count($lines);
472  for ($i=0;$i<$num;$i++)
473  {
474  $label=(! empty($lines[$i]->label)?$lines[$i]->label:'');
475  $desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle);
476 
477  // Positive line
478  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
479 
480  // Date start
481  $date_start = false;
482  if ($lines[$i]->date_debut_prevue)
483  $date_start = $lines[$i]->date_debut_prevue;
484  if ($lines[$i]->date_debut_reel)
485  $date_start = $lines[$i]->date_debut_reel;
486  if ($lines[$i]->date_start)
487  $date_start = $lines[$i]->date_start;
488 
489  // Date end
490  $date_end = false;
491  if ($lines[$i]->date_fin_prevue)
492  $date_end = $lines[$i]->date_fin_prevue;
493  if ($lines[$i]->date_fin_reel)
494  $date_end = $lines[$i]->date_fin_reel;
495  if ($lines[$i]->date_end)
496  $date_end = $lines[$i]->date_end;
497 
498  // Reset fk_parent_line for no child products and special product
499  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
500  $fk_parent_line = 0;
501  }
502 
503  // Extrafields
504  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) {
505  $lines[$i]->fetch_optionals($lines[$i]->rowid);
506  $array_options = $lines[$i]->array_options;
507  }
508 
509  $tva_tx = $lines[$i]->tva_tx;
510  if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';
511 
512  $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);
513 
514  if ($result > 0) {
515  $lineid = $result;
516  } else {
517  $lineid = 0;
518  $error ++;
519  break;
520  }
521 
522  // Defined the new fk_parent_line
523  if ($result > 0 && $lines[$i]->product_type == 9) {
524  $fk_parent_line = $result;
525  }
526  }
527 
528  // Hooks
529  $parameters = array('objFrom' => $srcobject);
530  $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
531  // modified by hook
532  if ($reshook < 0)
533  $error ++;
534  } else {
535  setEventMessages($srcobject->error, $srcobject->errors, 'errors');
536  $error ++;
537  }
538  } else {
539  setEventMessages($object->error, $object->errors, 'errors');
540  $error ++;
541  }
542  } // Standard creation
543  else
544  {
545  $id = $object->create($user);
546  }
547 
548  if ($id > 0)
549  {
550  // Insertion contact par defaut si defini
551  if (GETPOST('contactid') > 0)
552  {
553  $result = $object->add_contact(GETPOST('contactid'), 'CUSTOMER', 'external');
554  if ($result < 0)
555  {
556  $error++;
557  setEventMessages($langs->trans("ErrorFailedToAddContact"), null, 'errors');
558  }
559  }
560 
561  if (! $error)
562  {
563  $db->commit();
564 
565  // Define output language
566  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
567  {
568  $outputlangs = $langs;
569  $newlang = '';
570  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
571  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
572  if (! empty($newlang)) {
573  $outputlangs = new Translate("", $conf);
574  $outputlangs->setDefaultLang($newlang);
575  }
576  $model=$object->modelpdf;
577 
578  $ret = $object->fetch($id); // Reload to get new records
579  $result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
580  if ($result < 0) dol_print_error($db,$result);
581  }
582 
583  header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id);
584  exit();
585  }
586  else
587  {
588  $db->rollback();
589  $action='create';
590  }
591  }
592  else
593  {
594  setEventMessages($object->error, $object->errors, 'errors');
595  $db->rollback();
596  $action='create';
597  }
598  }
599  }
600  }
601 
602  // Classify billed
603  else if ($action == 'classifybilled' && $user->rights->propal->cloturer)
604  {
605  $result=$object->cloture($user, 4, '');
606  if ($result < 0)
607  {
608  setEventMessages($object->error, $object->errors, 'errors');
609  $error++;
610  }
611  }
612 
613  // Close proposal
614  else if ($action == 'setstatut' && $user->rights->propal->cloturer && ! GETPOST('cancel','alpha'))
615  {
616  if (! GETPOST('statut','int')) {
617  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors');
618  $action = 'statut';
619  } else {
620  // prevent browser refresh from closing proposal several times
621  if ($object->statut == Propal::STATUS_VALIDATED)
622  {
623  $result=$object->cloture($user, GETPOST('statut','int'), GETPOST('note_private','none'));
624  if ($result < 0)
625  {
626  setEventMessages($object->error, $object->errors, 'errors');
627  $error++;
628  }
629  }
630  }
631  }
632 
633  // Reopen proposal
634  else if ($action == 'confirm_reopen' && $user->rights->propal->cloturer && ! GETPOST('cancel','alpha'))
635  {
636  // prevent browser refresh from reopening proposal several times
637  if ($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED)
638  {
639  $result=$object->reopen($user, 1);
640  if ($result < 0)
641  {
642  setEventMessages($object->error, $object->errors, 'errors');
643  $error++;
644  }
645  }
646  }
647 
648  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
649 
650  // Actions to send emails
651  $actiontypecode='AC_OTH_AUTO';
652  $trigger_name='PROPAL_SENTBYMAIL';
653  $autocopy='MAIN_MAIL_AUTOCOPY_PROPOSAL_TO';
654  $trackid='pro'.$object->id;
655  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
656 
657 
658  // Go back to draft
659  if ($action == 'modif' && $user->rights->propal->creer)
660  {
661  $object->set_draft($user);
662 
663  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
664  {
665  // Define output language
666  $outputlangs = $langs;
667  if (! empty($conf->global->MAIN_MULTILANGS)) {
668  $outputlangs = new Translate("", $conf);
669  $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang);
670  $outputlangs->setDefaultLang($newlang);
671  }
672  $ret = $object->fetch($id); // Reload to get new records
673  $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
674  }
675  }
676 
677  else if ($action == "setabsolutediscount" && $user->rights->propal->creer) {
678  if ($_POST["remise_id"]) {
679  if ($object->id > 0) {
680  $result = $object->insert_discount($_POST["remise_id"]);
681  if ($result < 0) {
682  setEventMessages($object->error, $object->errors, 'errors');
683  }
684  }
685  }
686  }
687 
688  // Add line
689  else if ($action == 'addline' && $user->rights->propal->creer) {
690 
691  // Set if we used free entry or predefined product
692  $predef='';
693  $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
694  $price_ht = GETPOST('price_ht');
695  $price_ht_devise = GETPOST('multicurrency_price_ht');
696  $prod_entry_mode = GETPOST('prod_entry_mode');
697  if ($prod_entry_mode == 'free')
698  {
699  $idprod=0;
700  $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
701  }
702  else
703  {
704  $idprod=GETPOST('idprod', 'int');
705  $tva_tx = '';
706  }
707 
708  $qty = GETPOST('qty' . $predef);
709  $remise_percent = GETPOST('remise_percent' . $predef);
710 
711  // Extrafields
712  $extrafieldsline = new ExtraFields($db);
713  $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
714  $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
715  // Unset extrafield
716  if (is_array($extralabelsline)) {
717  // Get extra fields
718  foreach ($extralabelsline as $key => $value) {
719  unset($_POST["options_" . $key]);
720  }
721  }
722 
723  if ($prod_entry_mode == 'free' && empty($idprod) && GETPOST('type') < 0) {
724  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
725  $error ++;
726  }
727 
728  if ($prod_entry_mode == 'free' && empty($idprod) && $price_ht == '' && $price_ht_devise == '') // Unit price can be 0 but not ''. Also price can be negative for proposal.
729  {
730  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
731  $error ++;
732  }
733  if ($prod_entry_mode == 'free' && empty($idprod) && empty($product_desc)) {
734  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
735  $error ++;
736  }
737 
738  if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode != 'free') {
739  if ($combinations = GETPOST('combinations', 'array')) {
740  //Check if there is a product with the given combination
741  $prodcomb = new ProductCombination($db);
742 
743  if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
744  $idprod = $res->fk_product_child;
745  } else {
746  setEventMessage($langs->trans('ErrorProductCombinationNotFound'), 'errors');
747  $error ++;
748  }
749  }
750  }
751 
752  if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) {
753  $pu_ht = 0;
754  $pu_ttc = 0;
755  $price_min = 0;
756  $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
757 
758  $db->begin();
759 
760  // $tva_tx can be 'x.x (XXX)'
761 
762  // Ecrase $pu par celui du produit
763  // Ecrase $desc par celui du produit
764  // Ecrase $tva_tx par celui du produit
765  // Replaces $fk_unit with the product unit
766  if (! empty($idprod)) {
767  $prod = new Product($db);
768  $prod->fetch($idprod);
769 
770  $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
771 
772  // Update if prices fields are defined
773  $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
774  $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
775  if (empty($tva_tx)) $tva_npr=0;
776 
777  // Price unique per product
778  $pu_ht = $prod->price;
779  $pu_ttc = $prod->price_ttc;
780  $price_min = $prod->price_min;
781  $price_base_type = $prod->price_base_type;
782 
783  // If price per segment
784  if (! empty($conf->global->PRODUIT_MULTIPRICES) && $object->thirdparty->price_level)
785  {
786  $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
787  $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
788  $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
789  $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
790  if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility
791  {
792  if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level];
793  if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level];
794  }
795  }
796  // If price per customer
797  elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
798  {
799  require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
800 
801  $prodcustprice = new Productcustomerprice($db);
802 
803  $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
804 
805  $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
806  if ($result) {
807  // If there is some prices specific to the customer
808  if (count($prodcustprice->lines) > 0) {
809  $pu_ht = price($prodcustprice->lines[0]->price);
810  $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
811  $price_base_type = $prodcustprice->lines[0]->price_base_type;
812  $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx . ' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx);
813  if ($prodcustprice->lines[0]->default_vat_code && ! preg_match('/\(.*\)/', $tva_tx)) $tva_tx.= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
814  $tva_npr = $prodcustprice->lines[0]->recuperableonly;
815  if (empty($tva_tx)) $tva_npr=0;
816  }
817  }
818  }
819  // If price per quantity
820  elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
821  {
822  if ($prod->prices_by_qty[0]) // yes, this product has some prices per quantity
823  {
824  // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
825  $pqp = GETPOST('pbq','int');
826 
827  // Search price into product_price_by_qty from $prod->id
828  foreach($prod->prices_by_qty_list[0] as $priceforthequantityarray)
829  {
830  if ($priceforthequantityarray['rowid'] != $pqp) continue;
831  // We found the price
832  if ($priceforthequantityarray['price_base_type'] == 'HT')
833  {
834  $pu_ht = $priceforthequantityarray['unitprice'];
835  }
836  else
837  {
838  $pu_ttc = $priceforthequantityarray['unitprice'];
839  }
840  // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
841  break;
842  }
843  }
844  }
845  // If price per quantity and customer
846  elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
847  {
848  // TODO Same than PRODUIT_CUSTOMER_PRICES_BY_QTY but using $object->thirdparty->price_level
849  }
850 
851  $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
852  $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
853 
854  // if price ht is forced (ie: calculated by margin rate and cost price). TODO Why this ?
855  if (! empty($price_ht)) {
856  $pu_ht = price2num($price_ht, 'MU');
857  $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
858  }
859  // On reevalue prix selon taux tva car taux tva transaction peut etre different
860  // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
861  elseif ($tmpvat != $tmpprodvat) {
862  if ($price_base_type != 'HT') {
863  $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
864  } else {
865  $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
866  }
867  }
868 
869  $desc = '';
870 
871  // Define output language
872  if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
873  $outputlangs = $langs;
874  $newlang = '';
875  if (empty($newlang) && GETPOST('lang_id','aZ09'))
876  $newlang = GETPOST('lang_id','aZ09');
877  if (empty($newlang))
878  $newlang = $object->thirdparty->default_lang;
879  if (! empty($newlang)) {
880  $outputlangs = new Translate("", $conf);
881  $outputlangs->setDefaultLang($newlang);
882  }
883 
884  $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
885  } else {
886  $desc = $prod->description;
887  }
888 
889  $desc = dol_concatdesc($desc, $product_desc);
890 
891  // Add dimensions into product description
892  /*if (empty($conf->global->MAIN_PRODUCT_DISABLE_AUTOADD_DIM))
893  {
894  $text='';
895  if ($prod->weight) $text.=($text?"\n":"").$outputlangs->trans("Weight").': '.$prod->weight.' '.$prod->weight_units;
896  if ($prod->length) $text.=($text?"\n":"").$outputlangs->trans("Length").': '.$prod->length.' '.$prod->length_units;
897  if ($prod->surface) $text.=($text?"\n":"").$outputlangs->trans("Surface").': '.$prod->surface.' '.$prod->surface_units;
898  if ($prod->volume) $text.=($text?"\n":"").$outputlangs->trans("Volume").': '.$prod->volume.' '.$prod->volume_units;
899 
900  $desc = dol_concatdesc($desc, $text);
901  }*/
902 
903  // Add custom code and origin country into description
904  if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
905  {
906  // Define output language
907  if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
908  $outputlangs = $langs;
909  $newlang = '';
910  if (empty($newlang) && GETPOST('lang_id','alpha'))
911  $newlang = GETPOST('lang_id','alpha');
912  if (empty($newlang))
913  $newlang = $object->thirdparty->default_lang;
914  if (! empty($newlang)) {
915  $outputlangs = new Translate("", $conf);
916  $outputlangs->setDefaultLang($newlang);
917  $outputlangs->load('products');
918  }
919  if (! empty($prod->customcode))
920  $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
921  if (! empty($prod->customcode) && ! empty($prod->country_code))
922  $tmptxt .= ' - ';
923  if (! empty($prod->country_code))
924  $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $outputlangs, 0);
925  } else {
926  if (! empty($prod->customcode))
927  $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
928  if (! empty($prod->customcode) && ! empty($prod->country_code))
929  $tmptxt .= ' - ';
930  if (! empty($prod->country_code))
931  $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
932  }
933  $tmptxt .= ')';
934  $desc = dol_concatdesc($desc, $tmptxt);
935  }
936 
937  $type = $prod->type;
938  $fk_unit = $prod->fk_unit;
939  } else {
940  $pu_ht = price2num($price_ht, 'MU');
941  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
942  $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
943  $tva_tx = str_replace('*', '', $tva_tx);
944  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
945  $desc = $product_desc;
946  $type = GETPOST('type');
947 
948  $fk_unit = GETPOST('units', 'alpha');
949  $pu_ht_devise = price2num($price_ht_devise, 'MU');
950  }
951 
952  // Margin
953  $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
954  $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we muste keep this value
955 
956  $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'));
957  $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'));
958 
959  // Local Taxes
960  $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
961  $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
962 
963  $info_bits = 0;
964  if ($tva_npr)
965  $info_bits |= 0x01;
966 
967  if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) {
968  $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
969  setEventMessages($mesg, null, 'errors');
970  } else {
971  // Insert line
972  $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, - 1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options, $fk_unit, '', 0, $pu_ht_devise);
973 
974  if ($result > 0) {
975  $db->commit();
976 
977  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
978  // Define output language
979  $outputlangs = $langs;
980  if (! empty($conf->global->MAIN_MULTILANGS)) {
981  $outputlangs = new Translate("", $conf);
982  $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang);
983  $outputlangs->setDefaultLang($newlang);
984  }
985  $ret = $object->fetch($id); // Reload to get new records
986  $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
987  }
988 
989  unset($_POST['prod_entry_mode']);
990 
991  unset($_POST['qty']);
992  unset($_POST['type']);
993  unset($_POST['remise_percent']);
994  unset($_POST['price_ht']);
995  unset($_POST['multicurrency_price_ht']);
996  unset($_POST['price_ttc']);
997  unset($_POST['tva_tx']);
998  unset($_POST['product_ref']);
999  unset($_POST['product_label']);
1000  unset($_POST['product_desc']);
1001  unset($_POST['fournprice']);
1002  unset($_POST['buying_price']);
1003  unset($_POST['np_marginRate']);
1004  unset($_POST['np_markRate']);
1005  unset($_POST['dp_desc']);
1006  unset($_POST['idprod']);
1007  unset($_POST['units']);
1008 
1009  unset($_POST['date_starthour']);
1010  unset($_POST['date_startmin']);
1011  unset($_POST['date_startsec']);
1012  unset($_POST['date_startday']);
1013  unset($_POST['date_startmonth']);
1014  unset($_POST['date_startyear']);
1015  unset($_POST['date_endhour']);
1016  unset($_POST['date_endmin']);
1017  unset($_POST['date_endsec']);
1018  unset($_POST['date_endday']);
1019  unset($_POST['date_endmonth']);
1020  unset($_POST['date_endyear']);
1021  } else {
1022  $db->rollback();
1023 
1024  setEventMessages($object->error, $object->errors, 'errors');
1025  }
1026  }
1027  }
1028  }
1029 
1030  // Update a line within proposal
1031  else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('save'))
1032  {
1033  // Define info_bits
1034  $info_bits = 0;
1035  if (preg_match('/\*/', GETPOST('tva_tx')))
1036  $info_bits |= 0x01;
1037 
1038  // Clean parameters
1039  $description = dol_htmlcleanlastbr(GETPOST('product_desc','none'));
1040 
1041  // Define vat_rate
1042  $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
1043  $vat_rate = str_replace('*', '', $vat_rate);
1044  $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1045  $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1046  $pu_ht = GETPOST('price_ht');
1047 
1048  // Add buying price
1049  $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
1050  $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
1051 
1052  $pu_ht_devise = GETPOST('multicurrency_subprice');
1053 
1054  $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
1055  $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
1056 
1057  // Extrafields
1058  $extrafieldsline = new ExtraFields($db);
1059  $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
1060  $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
1061  // Unset extrafield
1062  if (is_array($extralabelsline)) {
1063  // Get extra fields
1064  foreach ($extralabelsline as $key => $value) {
1065  unset($_POST["options_" . $key]);
1066  }
1067  }
1068 
1069  // Define special_code for special lines
1070  $special_code=GETPOST('special_code');
1071  if (! GETPOST('qty')) $special_code=3;
1072 
1073  // Check minimum price
1074  $productid = GETPOST('productid', 'int');
1075  if (! empty($productid)) {
1076  $product = new Product($db);
1077  $res = $product->fetch($productid);
1078 
1079  $type = $product->type;
1080 
1081  $price_min = $product->price_min;
1082  if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
1083  $price_min = $product->multiprices_min [$object->thirdparty->price_level];
1084 
1085  $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
1086 
1087  if ($price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
1088  setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
1089  $error ++;
1090  }
1091  } else {
1092  $type = GETPOST('type');
1093  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1094 
1095  // Check parameters
1096  if (GETPOST('type') < 0) {
1097  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1098  $error ++;
1099  }
1100  }
1101 
1102  if (! $error) {
1103  $db->begin();
1104 
1105  if (empty($user->rights->margins->creer))
1106  {
1107  foreach ($object->lines as &$line)
1108  {
1109  if ($line->id == GETPOST('lineid'))
1110  {
1111  $fournprice = $line->fk_fournprice;
1112  $buyingprice = $line->pa_ht;
1113  break;
1114  }
1115  }
1116  }
1117  $result = $object->updateline(GETPOST('lineid'), $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, $description, 'HT', $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, $_POST["units"], $pu_ht_devise);
1118 
1119  if ($result >= 0) {
1120  $db->commit();
1121 
1122  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1123  // Define output language
1124  $outputlangs = $langs;
1125  if (! empty($conf->global->MAIN_MULTILANGS)) {
1126  $outputlangs = new Translate("", $conf);
1127  $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang);
1128  $outputlangs->setDefaultLang($newlang);
1129  }
1130  $ret = $object->fetch($id); // Reload to get new records
1131  $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1132  }
1133 
1134  unset($_POST['qty']);
1135  unset($_POST['type']);
1136  unset($_POST['productid']);
1137  unset($_POST['remise_percent']);
1138  unset($_POST['price_ht']);
1139  unset($_POST['multicurrency_price_ht']);
1140  unset($_POST['price_ttc']);
1141  unset($_POST['tva_tx']);
1142  unset($_POST['product_ref']);
1143  unset($_POST['product_label']);
1144  unset($_POST['product_desc']);
1145  unset($_POST['fournprice']);
1146  unset($_POST['buying_price']);
1147 
1148  unset($_POST['date_starthour']);
1149  unset($_POST['date_startmin']);
1150  unset($_POST['date_startsec']);
1151  unset($_POST['date_startday']);
1152  unset($_POST['date_startmonth']);
1153  unset($_POST['date_startyear']);
1154  unset($_POST['date_endhour']);
1155  unset($_POST['date_endmin']);
1156  unset($_POST['date_endsec']);
1157  unset($_POST['date_endday']);
1158  unset($_POST['date_endmonth']);
1159  unset($_POST['date_endyear']);
1160  } else {
1161  $db->rollback();
1162 
1163  setEventMessages($object->error, $object->errors, 'errors');
1164  }
1165  }
1166  }
1167 
1168  else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('cancel','alpha'))
1169  {
1170  header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
1171  exit();
1172  }
1173 
1174  // Set project
1175  else if ($action == 'classin' && $user->rights->propal->creer) {
1176  $object->setProject(GETPOST('projectid','int'));
1177  }
1178 
1179  // Delai de livraison
1180  else if ($action == 'setavailability' && $user->rights->propal->creer) {
1181  $result = $object->set_availability($user, GETPOST('availability_id','int'));
1182  }
1183 
1184  // Origine de la propale
1185  else if ($action == 'setdemandreason' && $user->rights->propal->creer) {
1186  $result = $object->set_demand_reason($user, GETPOST('demand_reason_id','int'));
1187  }
1188 
1189  // Conditions de reglement
1190  else if ($action == 'setconditions' && $user->rights->propal->creer) {
1191  $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
1192  }
1193 
1194  else if ($action == 'setremisepercent' && $user->rights->propal->creer) {
1195  $result = $object->set_remise_percent($user, $_POST['remise_percent']);
1196  }
1197 
1198  else if ($action == 'setremiseabsolue' && $user->rights->propal->creer) {
1199  $result = $object->set_remise_absolue($user, $_POST['remise_absolue']);
1200  }
1201 
1202  // Mode de reglement
1203  else if ($action == 'setmode' && $user->rights->propal->creer) {
1204  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
1205  }
1206 
1207  // Multicurrency Code
1208  else if ($action == 'setmulticurrencycode' && $user->rights->propal->creer) {
1209  $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
1210  }
1211 
1212  // Multicurrency rate
1213  else if ($action == 'setmulticurrencyrate' && $user->rights->propal->creer) {
1214  $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')));
1215  }
1216 
1217  // bank account
1218  else if ($action == 'setbankaccount' && $user->rights->propal->creer) {
1219  $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
1220  }
1221 
1222  // shipping method
1223  else if ($action == 'setshippingmethod' && $user->rights->propal->creer) {
1224  $result=$object->setShippingMethod(GETPOST('shipping_method_id', 'int'));
1225  }
1226 
1227  else if ($action == 'update_extras') {
1228  // Fill array 'array_options' with data from update form
1229  $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
1230  $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
1231  if ($ret < 0) $error++;
1232  if (! $error)
1233  {
1234  $result = $object->insertExtraFields();
1235  if ($result < 0)
1236  {
1237  setEventMessages($object->error, $object->errors, 'errors');
1238  $error++;
1239  }
1240  }
1241  if ($error) $action = 'edit_extras';
1242  }
1243 
1244  if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer)
1245  {
1246  if ($action == 'addcontact')
1247  {
1248  if ($object->id > 0) {
1249  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
1250  $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
1251  }
1252 
1253  if ($result >= 0) {
1254  header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
1255  exit();
1256  } else {
1257  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1258  $langs->load("errors");
1259  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
1260  } else {
1261  setEventMessages($object->error, $object->errors, 'errors');
1262  }
1263  }
1264  }
1265 
1266  // Bascule du statut d'un contact
1267  else if ($action == 'swapstatut') {
1268  if ($object->fetch($id) > 0) {
1269  $result = $object->swapContactStatus(GETPOST('ligne'));
1270  } else {
1271  dol_print_error($db);
1272  }
1273  }
1274 
1275  // Efface un contact
1276  else if ($action == 'deletecontact') {
1277  $object->fetch($id);
1278  $result = $object->delete_contact($lineid);
1279 
1280  if ($result >= 0) {
1281  header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
1282  exit();
1283  } else {
1284  dol_print_error($db);
1285  }
1286  }
1287  }
1288 
1289  // Actions to build doc
1290  $upload_dir = $conf->propal->dir_output;
1291  $permissioncreate=$user->rights->propal->creer;
1292  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1293 
1294 }
1295 
1296 
1297 /*
1298  * View
1299  */
1300 
1301 llxHeader('', $langs->trans('Proposal'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
1302 
1303 $form = new Form($db);
1304 $formother = new FormOther($db);
1305 $formfile = new FormFile($db);
1306 $formpropal = new FormPropal($db);
1307 $formmargin = new FormMargin($db);
1308 $companystatic = new Societe($db);
1309 if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
1310 
1311 $now = dol_now();
1312 
1313 // Add new proposal
1314 if ($action == 'create')
1315 {
1316  $currency_code = $conf->currency;
1317 
1318  print load_fiche_titre($langs->trans("NewProp"));
1319 
1320  $soc = new Societe($db);
1321  if ($socid > 0)
1322  $res = $soc->fetch($socid);
1323 
1324  // Load objectsrc
1325  if (! empty($origin) && ! empty($originid))
1326  {
1327  // Parse element/subelement (ex: project_task)
1328  $element = $subelement = $origin;
1329  if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1330  $element = $regs [1];
1331  $subelement = $regs [2];
1332  }
1333 
1334  if ($element == 'project') {
1335  $projectid = $originid;
1336  } else {
1337  // For compatibility
1338  if ($element == 'order' || $element == 'commande') {
1339  $element = $subelement = 'commande';
1340  }
1341  if ($element == 'propal') {
1342  $element = 'comm/propal';
1343  $subelement = 'propal';
1344  }
1345  if ($element == 'contract') {
1346  $element = $subelement = 'contrat';
1347  }
1348  if ($element == 'shipping') {
1349  $element = $subelement = 'expedition';
1350  }
1351 
1352  dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
1353 
1354  $classname = ucfirst($subelement);
1355  $objectsrc = new $classname($db);
1356  $objectsrc->fetch($originid);
1357  if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
1358  {
1359  $objectsrc->fetch_lines();
1360  }
1361  $objectsrc->fetch_thirdparty();
1362 
1363  $projectid = (! empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
1364  $ref_client = (! empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
1365  $ref_int = (! empty($objectsrc->ref_int) ? $objectsrc->ref_int : '');
1366 
1367  $soc = $objectsrc->thirdparty;
1368 
1369  $cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
1370  $mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
1371  $remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0));
1372  $remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0));
1373  $dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$dateinvoice);
1374 
1375  // Replicate extrafields
1376  $objectsrc->fetch_optionals($originid);
1377  $object->array_options = $objectsrc->array_options;
1378 
1379  if (!empty($conf->multicurrency->enabled))
1380  {
1381  if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code;
1382  if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx;
1383  }
1384  }
1385  }
1386  else
1387  {
1388  if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code;
1389  }
1390 
1391  $object = new Propal($db);
1392 
1393  print '<form name="addprop" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
1394  print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
1395  print '<input type="hidden" name="action" value="add">';
1396  if ($origin != 'project' && $originid) {
1397  print '<input type="hidden" name="origin" value="' . $origin . '">';
1398  print '<input type="hidden" name="originid" value="' . $originid . '">';
1399  } elseif ($origin == 'project' && !empty($projectid)) {
1400  print '<input type="hidden" name="projectid" value="' . $projectid . '">';
1401  }
1402 
1403  dol_fiche_head();
1404 
1405  print '<table class="border" width="100%">';
1406 
1407  // Reference
1408  print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans('Ref') . '</td><td>' . $langs->trans("Draft") . '</td></tr>';
1409 
1410  // Ref customer
1411  print '<tr><td>' . $langs->trans('RefCustomer') . '</td><td>';
1412  print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'"></td>';
1413  print '</tr>';
1414 
1415  // Third party
1416  print '<tr>';
1417  print '<td class="fieldrequired">' . $langs->trans('Customer') . '</td>';
1418  if ($socid > 0) {
1419  print '<td>';
1420  print $soc->getNomUrl(1);
1421  print '<input type="hidden" name="socid" value="' . $soc->id . '">';
1422  print '</td>';
1423  if (! empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && ! empty($soc->shipping_method_id)) {
1424  $shipping_method_id = $soc->shipping_method_id;
1425  }
1426  } else {
1427  print '<td>';
1428  print $form->select_company('', 'socid', '(s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300');
1429  // reload page to retrieve customer informations
1430  if (!empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE))
1431  {
1432  print '<script type="text/javascript">
1433  $(document).ready(function() {
1434  $("#socid").change(function() {
1435  var socid = $(this).val();
1436  // reload page
1437  window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid+"&ref_client="+$("input[name=ref_client]").val();
1438  });
1439  });
1440  </script>';
1441  }
1442  print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'">'.$langs->trans("AddThirdParty").'</a>';
1443  print '</td>';
1444  }
1445  print '</tr>' . "\n";
1446 
1447  if ($socid > 0)
1448  {
1449  // Contacts (ask contact only if thirdparty already defined). TODO do this also into order and invoice.
1450  print "<tr><td>" . $langs->trans("DefaultContact") . '</td><td>';
1451  $form->select_contacts($soc->id, $contactid, 'contactid', 1, $srccontactslist);
1452  print '</td></tr>';
1453 
1454  // Ligne info remises tiers
1455  print '<tr><td>' . $langs->trans('Discounts') . '</td><td>';
1456  if ($soc->remise_percent)
1457  print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
1458  else
1459  print $langs->trans("CompanyHasNoRelativeDiscount");
1460  $absolute_discount = $soc->getAvailableDiscounts();
1461  print '. ';
1462  if ($absolute_discount)
1463  print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount, 0, $langs, 1, -1, -1, $conf->currency));
1464  else
1465  print $langs->trans("CompanyHasNoAbsoluteDiscount");
1466  print '.';
1467  print '</td></tr>';
1468  }
1469 
1470  // Date
1471  print '<tr><td class="fieldrequired">' . $langs->trans('Date') . '</td><td>';
1472  $form->select_date('', '', '', '', '', "addprop", 1, 1);
1473  print '</td></tr>';
1474 
1475  // Validaty duration
1476  print '<tr><td class="fieldrequired">' . $langs->trans("ValidityDuration") . '</td><td><input name="duree_validite" size="5" value="' . $conf->global->PROPALE_VALIDITY_DURATION . '"> ' . $langs->trans("days") . '</td></tr>';
1477 
1478  // Terms of payment
1479  print '<tr><td class="nowrap fieldrequired">' . $langs->trans('PaymentConditionsShort') . '</td><td>';
1480  $form->select_conditions_paiements($soc->cond_reglement_id, 'cond_reglement_id');
1481  print '</td></tr>';
1482 
1483  // Mode of payment
1484  print '<tr><td>' . $langs->trans('PaymentMode') . '</td><td>';
1485  $form->select_types_paiements($soc->mode_reglement_id, 'mode_reglement_id');
1486  print '</td></tr>';
1487 
1488  // Bank Account
1489  if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && ! empty($conf->banque->enabled)) {
1490  print '<tr><td>' . $langs->trans('BankAccount') . '</td><td>';
1491  $form->select_comptes($fk_account, 'fk_account', 0, '', 1);
1492  print '</td></tr>';
1493  }
1494 
1495  // What trigger creation
1496  print '<tr><td>' . $langs->trans('Source') . '</td><td>';
1497  $form->selectInputReason('', 'demand_reason_id', "SRC_PROP", 1);
1498  print '</td></tr>';
1499 
1500  // Delivery delay
1501  print '<tr class="fielddeliverydelay"><td>' . $langs->trans('AvailabilityPeriod') . '</td><td>';
1502  $form->selectAvailabilityDelay('', 'availability_id', '', 1);
1503  print '</td></tr>';
1504 
1505  // Shipping Method
1506  if (! empty($conf->expedition->enabled)) {
1507  print '<tr><td>' . $langs->trans('SendingMethod') . '</td><td>';
1508  print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1);
1509  print '</td></tr>';
1510  }
1511 
1512  // Delivery date (or manufacturing)
1513  print '<tr><td>' . $langs->trans("DeliveryDate") . '</td>';
1514  print '<td>';
1515  if ($conf->global->DATE_LIVRAISON_WEEK_DELAY != "") {
1516  $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
1517  $syear = date("Y", $tmpdte);
1518  $smonth = date("m", $tmpdte);
1519  $sday = date("d", $tmpdte);
1520  $form->select_date($syear."-".$smonth."-".$sday, 'date_livraison', '', '', '', "addprop");
1521  } else {
1522  $form->select_date(-1, 'date_livraison', '', '', '', "addprop", 1, 1);
1523  }
1524  print '</td></tr>';
1525 
1526  // Project
1527  if (! empty($conf->projet->enabled))
1528  {
1529  $projectid = GETPOST('projectid')?GETPOST('projectid'):0;
1530  if ($origin == 'project') $projectid = ($originid ? $originid : 0);
1531 
1532  $langs->load("projects");
1533  print '<tr>';
1534  print '<td>' . $langs->trans("Project") . '</td><td>';
1535  $numprojet = $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 1);
1536  print ' &nbsp; <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).'">' . $langs->trans("AddProject") . '</a>';
1537  print '</td>';
1538  print '</tr>';
1539  }
1540 
1541  // Incoterms
1542  if (!empty($conf->incoterm->enabled))
1543  {
1544  print '<tr>';
1545  print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $soc->libelle_incoterms, 1).'</label></td>';
1546  print '<td class="maxwidthonsmartphone">';
1547  print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms)?$soc->location_incoterms:''));
1548  print '</td></tr>';
1549  }
1550 
1551  // Template to use by default
1552  print '<tr>';
1553  print '<td>' . $langs->trans("DefaultModel") . '</td>';
1554  print '<td>';
1555  $liste = ModelePDFPropales::liste_modeles($db);
1556  print $form->selectarray('model', $liste, ($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT : $conf->global->PROPALE_ADDON_PDF));
1557  print "</td></tr>";
1558 
1559  // Multicurrency
1560  if (! empty($conf->multicurrency->enabled))
1561  {
1562  print '<tr>';
1563  print '<td>'.fieldLabel('Currency','multicurrency_code').'</td>';
1564  print '<td class="maxwidthonsmartphone">';
1565  print $form->selectMultiCurrency($currency_code, 'multicurrency_code', 0);
1566  print '</td></tr>';
1567  }
1568 
1569  // Public note
1570  print '<tr>';
1571  print '<td class="tdtop">' . $langs->trans('NotePublic') . '</td>';
1572  print '<td valign="top">';
1573  $note_public = $object->getDefaultCreateValueFor('note_public', (is_object($objectsrc)?$objectsrc->note_public:null));
1574  $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
1575  print $doleditor->Create(1);
1576 
1577  // Private note
1578  if (empty($user->societe_id))
1579  {
1580  print '<tr>';
1581  print '<td class="tdtop">' . $langs->trans('NotePrivate') . '</td>';
1582  print '<td valign="top">';
1583  $note_private = $object->getDefaultCreateValueFor('note_private', ((! empty($origin) && ! empty($originid) && is_object($objectsrc))?$objectsrc->note_private:null));
1584  $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
1585  print $doleditor->Create(1);
1586  // print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'.</textarea>
1587  print '</td></tr>';
1588  }
1589 
1590  // Other attributes
1591  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
1592 
1593  // Lines from source
1594  if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
1595  {
1596  // TODO for compatibility
1597  if ($origin == 'contrat') {
1598  // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
1599  $objectsrc->remise_absolue = $remise_absolue;
1600  $objectsrc->remise_percent = $remise_percent;
1601  $objectsrc->update_price(1, - 1, 1);
1602  }
1603 
1604  print "\n<!-- " . $classname . " info -->";
1605  print "\n";
1606  print '<input type="hidden" name="amount" value="' . $objectsrc->total_ht . '">' . "\n";
1607  print '<input type="hidden" name="total" value="' . $objectsrc->total_ttc . '">' . "\n";
1608  print '<input type="hidden" name="tva" value="' . $objectsrc->total_tva . '">' . "\n";
1609  print '<input type="hidden" name="origin" value="' . $objectsrc->element . '">';
1610  print '<input type="hidden" name="originid" value="' . $objectsrc->id . '">';
1611 
1612  $newclassname = $classname;
1613  if ($newclassname == 'Propal')
1614  $newclassname = 'CommercialProposal';
1615  elseif ($newclassname == 'Commande')
1616  $newclassname = 'Order';
1617  elseif ($newclassname == 'Expedition')
1618  $newclassname = 'Sending';
1619  elseif ($newclassname == 'Fichinter')
1620  $newclassname = 'Intervention';
1621 
1622  print '<tr><td>' . $langs->trans($newclassname) . '</td><td>' . $objectsrc->getNomUrl(1) . '</td></tr>';
1623  print '<tr><td>' . $langs->trans('TotalHT') . '</td><td>' . price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency) . '</td></tr>';
1624  print '<tr><td>' . $langs->trans('TotalVAT') . '</td><td>' . price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency) . "</td></tr>";
1625  if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0 ) // Localtax1
1626  {
1627  print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency) . "</td></tr>";
1628  }
1629 
1630  if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2
1631  {
1632  print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency) . "</td></tr>";
1633  }
1634  print '<tr><td>' . $langs->trans('TotalTTC') . '</td><td>' . price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency) . "</td></tr>";
1635  }
1636 
1637  print "</table>\n";
1638 
1639 
1640  /*
1641  * Combobox pour la fonction de copie
1642  */
1643 
1644  if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) print '<input type="hidden" name="createmode" value="empty">';
1645 
1646  if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE))
1647  {
1648  print '<br><table>';
1649 
1650  // For backward compatibility
1651  print '<tr>';
1652  print '<td><input type="radio" name="createmode" value="copy"></td>';
1653  print '<td>' . $langs->trans("CopyPropalFrom") . ' </td>';
1654  print '<td>';
1655  $liste_propal = array();
1656  $liste_propal [0] = '';
1657 
1658  $sql = "SELECT p.rowid as id, p.ref, s.nom";
1659  $sql .= " FROM " . MAIN_DB_PREFIX . "propal p";
1660  $sql .= ", " . MAIN_DB_PREFIX . "societe s";
1661  $sql .= " WHERE s.rowid = p.fk_soc";
1662  $sql .= " AND p.entity IN (".getEntity('propal').")";
1663  $sql .= " AND p.fk_statut <> 0";
1664  $sql .= " ORDER BY Id";
1665 
1666  $resql = $db->query($sql);
1667  if ($resql) {
1668  $num = $db->num_rows($resql);
1669  $i = 0;
1670  while ($i < $num) {
1671  $row = $db->fetch_row($resql);
1672  $propalRefAndSocName = $row [1] . " - " . $row [2];
1673  $liste_propal [$row [0]] = $propalRefAndSocName;
1674  $i ++;
1675  }
1676  print $form->selectarray("copie_propal", $liste_propal, 0);
1677  } else {
1678  dol_print_error($db);
1679  }
1680  print '</td></tr>';
1681 
1682  print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
1683  print '<td valign="top" colspan="2">' . $langs->trans("CreateEmptyPropal") . '</td></tr>';
1684  }
1685 
1686  if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) print '</table>';
1687 
1688  dol_fiche_end();
1689 
1690  $langs->load("bills");
1691  print '<div class="center">';
1692  print '<input type="submit" class="button" value="' . $langs->trans("CreateDraft") . '">';
1693  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1694  print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
1695  print '</div>';
1696 
1697  print "</form>";
1698 
1699 
1700  // Show origin lines
1701  if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) {
1702  print '<br>';
1703 
1704  $title = $langs->trans('ProductsAndServices');
1706 
1707  print '<table class="noborder" width="100%">';
1708 
1709  $objectsrc->printOriginLinesList();
1710 
1711  print '</table>';
1712  }
1713 
1714 } else {
1715  /*
1716  * Show object in view mode
1717  */
1718 
1719  $soc = new Societe($db);
1720  $soc->fetch($object->socid);
1721 
1722  $head = propal_prepare_head($object);
1723  dol_fiche_head($head, 'comm', $langs->trans('Proposal'), -1, 'propal');
1724 
1725  $formconfirm = '';
1726 
1727  // Clone confirmation
1728  if ($action == 'clone') {
1729  // Create an array for form
1730  $formquestion = array(
1731  // 'text' => $langs->trans("ConfirmClone"),
1732  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
1733  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' =>
1734  // 1),
1735  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)')));
1736  if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->date_livraison)) {
1737  $formquestion[] = array('type' => 'date','name' => 'date_delivery','label' => $langs->trans("DeliveryDate"),'value' => $object->date_livraison);
1738  }
1739  // Paiement incomplet. On demande si motif = escompte ou autre
1740  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ClonePropal'), $langs->trans('ConfirmClonePropal', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1741  }
1742 
1743  if ($action == 'statut')
1744  {
1745  //Form to close proposal (signed or not)
1746  $formquestion = array(
1747  array('type' => 'select','name' => 'statut','label' => $langs->trans("CloseAs"),'values' => array(2=>$object->labelstatut [2],3=>$object->labelstatut [3])),
1748  array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"),'value' => '') // Field to complete private note (not replace)
1749  );
1750 
1751  if (! empty($conf->notification->enabled)) {
1752  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
1753  $notify = new Notify($db);
1754  $formquestion = array_merge($formquestion, array(
1755  array('type' => 'onecolumn', 'value' => $notify->confirmMessage('PROPAL_CLOSE_SIGNED', $object->socid, $object)),
1756  ));
1757  }
1758 
1759  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('SetAcceptedRefused'), $text, 'setstatut', $formquestion, '', 1, 250);
1760 
1761  }
1762 
1763  // Confirm delete
1764  else if ($action == 'delete') {
1765  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp', $object->ref), 'confirm_delete', '', 0, 1);
1766  }
1767 
1768  // Confirm reopen
1769  else if ($action == 'reopen') {
1770  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp', $object->ref), 'confirm_reopen', '', 0, 1);
1771  }
1772 
1773  // Confirmation delete product/service line
1774  else if ($action == 'ask_deleteline') {
1775  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
1776  }
1777 
1778  // Confirm validate proposal
1779  else if ($action == 'validate') {
1780  $error = 0;
1781 
1782  // We verifie whether the object is provisionally numbering
1783  $ref = substr($object->ref, 1, 4);
1784  if ($ref == 'PROV') {
1785  $numref = $object->getNextNumRef($soc);
1786  if (empty($numref)) {
1787  $error ++;
1788  setEventMessages($object->error, $object->errors, 'errors');
1789  }
1790  } else {
1791  $numref = $object->ref;
1792  }
1793 
1794  $text = $langs->trans('ConfirmValidateProp', $numref);
1795  if (! empty($conf->notification->enabled)) {
1796  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
1797  $notify = new Notify($db);
1798  $text .= '<br>';
1799  $text .= $notify->confirmMessage('PROPAL_VALIDATE', $object->socid, $object);
1800  }
1801 
1802  if (! $error)
1803  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate', '', 0, 1);
1804  }
1805 
1806  if (! $formconfirm) {
1807  $parameters = array('lineid' => $lineid);
1808  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1809  if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
1810  elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
1811  }
1812 
1813  // Print form confirm
1814  print $formconfirm;
1815 
1816 
1817  // Proposal card
1818 
1819  $linkback = '<a href="' . DOL_URL_ROOT . '/comm/propal/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
1820 
1821 
1822  $morehtmlref='<div class="refidno">';
1823  // Ref customer
1824  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->propal->creer, 'string', '', 0, 1);
1825  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->propal->creer, 'string', '', null, null, '', 1);
1826  // Thirdparty
1827  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
1828  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' (<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherProposals").'</a>)';
1829  // Project
1830  if (! empty($conf->projet->enabled))
1831  {
1832  $langs->load("projects");
1833  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
1834  if ($user->rights->propal->creer)
1835  {
1836  if ($action != 'classify')
1837  $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
1838  if ($action == 'classify') {
1839  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1840  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1841  $morehtmlref.='<input type="hidden" name="action" value="classin">';
1842  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1843  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1844  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1845  $morehtmlref.='</form>';
1846  } else {
1847  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1848  }
1849  } else {
1850  if (! empty($object->fk_project)) {
1851  $proj = new Project($db);
1852  $proj->fetch($object->fk_project);
1853  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
1854  $morehtmlref.=$proj->ref;
1855  $morehtmlref.='</a>';
1856  } else {
1857  $morehtmlref.='';
1858  }
1859  }
1860  }
1861  $morehtmlref.='</div>';
1862 
1863 
1864  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1865 
1866 
1867  print '<div class="fichecenter">';
1868  print '<div class="fichehalfleft">';
1869  print '<div class="underbanner clearboth"></div>';
1870 
1871  print '<table class="border" width="100%">';
1872 
1873  // Link for thirdparty discounts
1874  print '<tr><td class="titlefield">' . $langs->trans('Discounts') . '</td><td>';
1875  if ($soc->remise_percent)
1876  print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
1877  else
1878  print $langs->trans("CompanyHasNoRelativeDiscount");
1879  print '. ';
1880  $absolute_discount = $soc->getAvailableDiscounts('', 'fk_facture_source IS NULL');
1881  $absolute_creditnote = $soc->getAvailableDiscounts('', 'fk_facture_source IS NOT NULL');
1882  $absolute_discount = price2num($absolute_discount, 'MT');
1883  $absolute_creditnote = price2num($absolute_creditnote, 'MT');
1884  if ($absolute_discount) {
1885  if ($object->statut > Propal::STATUS_DRAFT) {
1886  print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount, 0, $langs, 0, 0, -1, $conf->currency));
1887  } else {
1888  // Remise dispo de type non avoir
1889  $filter = 'fk_facture_source IS NULL';
1890  print '<br>';
1891  $form->form_remise_dispo($_SERVER["PHP_SELF"] . '?id=' . $object->id, 0, 'remise_id', $soc->id, $absolute_discount, $filter, 0, '', 1);
1892  }
1893  }
1894  if ($absolute_creditnote) {
1895  print $langs->trans("CompanyHasCreditNote", price($absolute_creditnote, 0, $langs, 0, 0, -1, $conf->currency)) . '. ';
1896  }
1897  if (! $absolute_discount && ! $absolute_creditnote)
1898  print $langs->trans("CompanyHasNoAbsoluteDiscount") . '.';
1899  print '</td></tr>';
1900 
1901  // Date of proposal
1902  print '<tr>';
1903  print '<td>';
1904  print '<table class="nobordernopadding" width="100%"><tr><td>';
1905  print $langs->trans('Date');
1906  print '</td>';
1907  if ($action != 'editdate' && ! empty($object->brouillon))
1908  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editdate&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetDate'), 1) . '</a></td>';
1909  print '</tr></table>';
1910  print '</td><td>';
1911  if (! empty($object->brouillon) && $action == 'editdate') {
1912  print '<form name="editdate" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
1913  print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
1914  print '<input type="hidden" name="action" value="setdate">';
1915  $form->select_date($object->date, 're', '', '', 0, "editdate");
1916  print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
1917  print '</form>';
1918  } else {
1919  if ($object->date) {
1920  print dol_print_date($object->date, 'daytext');
1921  } else {
1922  print '&nbsp;';
1923  }
1924  }
1925  print '</td>';
1926 
1927  // Date end proposal
1928  print '<tr>';
1929  print '<td>';
1930  print '<table class="nobordernopadding" width="100%"><tr><td>';
1931  print $langs->trans('DateEndPropal');
1932  print '</td>';
1933  if ($action != 'editecheance' && ! empty($object->brouillon))
1934  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editecheance&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetConditions'), 1) . '</a></td>';
1935  print '</tr></table>';
1936  print '</td><td>';
1937  if (! empty($object->brouillon) && $action == 'editecheance') {
1938  print '<form name="editecheance" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
1939  print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
1940  print '<input type="hidden" name="action" value="setecheance">';
1941  $form->select_date($object->fin_validite, 'ech', '', '', '', "editecheance");
1942  print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
1943  print '</form>';
1944  } else {
1945  if (! empty($object->fin_validite)) {
1946  print dol_print_date($object->fin_validite, 'daytext');
1947  if ($object->statut == Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay))
1948  print img_warning($langs->trans("Late"));
1949  } else {
1950  print '&nbsp;';
1951  }
1952  }
1953  print '</td>';
1954  print '</tr>';
1955 
1956  // Payment term
1957  print '<tr><td>';
1958  print '<table class="nobordernopadding" width="100%"><tr><td>';
1959  print $langs->trans('PaymentConditionsShort');
1960  print '</td>';
1961  if ($action != 'editconditions' && ! empty($object->brouillon))
1962  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editconditions&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetConditions'), 1) . '</a></td>';
1963  print '</tr></table>';
1964  print '</td><td>';
1965  if ($action == 'editconditions') {
1966  $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id');
1967  } else {
1968  $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'none');
1969  }
1970  print '</td>';
1971  print '</tr>';
1972 
1973  // Delivery date
1974  $langs->load('deliveries');
1975  print '<tr><td>';
1976  print $form->editfieldkey($langs->trans('DeliveryDate'), 'date_livraison', $object->date_livraison, $object, $user->rights->propal->creer, 'datepicker');
1977  print '</td><td>';
1978  print $form->editfieldval($langs->trans('DeliveryDate'), 'date_livraison', $object->date_livraison, $object, $user->rights->propal->creer, 'datepicker');
1979  print '</td>';
1980  print '</tr>';
1981 
1982  // Delivery delay
1983  print '<tr class="fielddeliverydelay"><td>';
1984  print '<table class="nobordernopadding" width="100%"><tr><td>';
1985  print $langs->trans('AvailabilityPeriod');
1986  if (! empty($conf->commande->enabled))
1987  print ' (' . $langs->trans('AfterOrder') . ')';
1988  print '</td>';
1989  if ($action != 'editavailability' && ! empty($object->brouillon))
1990  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editavailability&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetAvailability'), 1) . '</a></td>';
1991  print '</tr></table>';
1992  print '</td><td>';
1993  if ($action == 'editavailability') {
1994  $form->form_availability($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->availability_id, 'availability_id', 1);
1995  } else {
1996  $form->form_availability($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->availability_id, 'none', 1);
1997  }
1998 
1999  print '</td>';
2000  print '</tr>';
2001 
2002  // Shipping Method
2003  if (! empty($conf->expedition->enabled)) {
2004  print '<tr><td>';
2005  print '<table width="100%" class="nobordernopadding"><tr><td>';
2006  print $langs->trans('SendingMethod');
2007  print '</td>';
2008  if ($action != 'editshippingmethod' && $user->rights->propal->creer)
2009  print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshippingmethod&amp;id='.$object->id.'">'.img_edit($langs->trans('SetShippingMode'),1).'</a></td>';
2010  print '</tr></table>';
2011  print '</td><td>';
2012  if ($action == 'editshippingmethod') {
2013  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
2014  } else {
2015  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none');
2016  }
2017  print '</td>';
2018  print '</tr>';
2019  }
2020 
2021  // Origin of demand
2022  print '<tr><td>';
2023  print '<table class="nobordernopadding" width="100%"><tr><td>';
2024  print $langs->trans('Source');
2025  print '</td>';
2026  if ($action != 'editdemandreason' && ! empty($object->brouillon))
2027  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editdemandreason&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetDemandReason'), 1) . '</a></td>';
2028  print '</tr></table>';
2029  print '</td><td>';
2030  if ($action == 'editdemandreason') {
2031  $form->formInputReason($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->demand_reason_id, 'demand_reason_id', 1);
2032  } else {
2033  $form->formInputReason($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->demand_reason_id, 'none');
2034  }
2035  print '</td>';
2036  print '</tr>';
2037 
2038  // Payment mode
2039  print '<tr>';
2040  print '<td>';
2041  print '<table class="nobordernopadding" width="100%"><tr><td>';
2042  print $langs->trans('PaymentMode');
2043  print '</td>';
2044  if ($action != 'editmode' && ! empty($object->brouillon))
2045  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmode&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMode'), 1) . '</a></td>';
2046  print '</tr></table>';
2047  print '</td><td>';
2048  if ($action == 'editmode') {
2049  $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id');
2050  } else {
2051  $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none');
2052  }
2053  print '</td></tr>';
2054 
2055  // Multicurrency
2056  if (! empty($conf->multicurrency->enabled))
2057  {
2058  // Multicurrency code
2059  print '<tr>';
2060  print '<td>';
2061  print '<table class="nobordernopadding" width="100%"><tr><td>';
2062  print fieldLabel('Currency','multicurrency_code');
2063  print '</td>';
2064  if ($action != 'editmulticurrencycode' && ! empty($object->brouillon))
2065  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencycode&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
2066  print '</tr></table>';
2067  print '</td><td>';
2068  if ($action == 'editmulticurrencycode') {
2069  $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'multicurrency_code');
2070  } else {
2071  $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'none');
2072  }
2073  print '</td></tr>';
2074 
2075  // Multicurrency rate
2076  print '<tr>';
2077  print '<td>';
2078  print '<table class="nobordernopadding" width="100%"><tr><td>';
2079  print fieldLabel('CurrencyRate','multicurrency_tx');
2080  print '</td>';
2081  if ($action != 'editmulticurrencyrate' && ! empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency)
2082  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencyrate&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
2083  print '</tr></table>';
2084  print '</td><td>';
2085  if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
2086  if($action == 'actualizemulticurrencyrate') {
2087  list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
2088  }
2089  $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
2090  } else {
2091  $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
2092  if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2093  print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
2094  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
2095  print '</div>';
2096  }
2097  }
2098  print '</td></tr>';
2099  }
2100 
2101  if ($soc->outstanding_limit)
2102  {
2103  // Outstanding Bill
2104  print '<tr><td>';
2105  print $langs->trans('OutstandingBill');
2106  print '</td><td align="right">';
2107  print price($soc->get_OutstandingBill()) . ' / ';
2108  print price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency);
2109  print '</td>';
2110  print '</tr>';
2111  }
2112 
2113  if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && ! empty($conf->banque->enabled))
2114  {
2115  // Bank Account
2116  print '<tr><td>';
2117  print '<table width="100%" class="nobordernopadding"><tr><td>';
2118  print $langs->trans('BankAccount');
2119  print '</td>';
2120  if ($action != 'editbankaccount' && $user->rights->propal->creer)
2121  print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
2122  print '</tr></table>';
2123  print '</td><td>';
2124  if ($action == 'editbankaccount') {
2125  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
2126  } else {
2127  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
2128  }
2129  print '</td>';
2130  print '</tr>';
2131  }
2132 
2133  // Incoterms
2134  if (!empty($conf->incoterm->enabled))
2135  {
2136  print '<tr><td>';
2137  print '<table width="100%" class="nobordernopadding"><tr><td>';
2138  print $langs->trans('IncotermLabel');
2139  print '<td><td align="right">';
2140  if ($user->rights->propal->creer) print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
2141  else print '&nbsp;';
2142  print '</td></tr></table>';
2143  print '</td>';
2144  print '<td>';
2145  if ($action != 'editincoterm')
2146  {
2147  print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
2148  }
2149  else
2150  {
2151  print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id);
2152  }
2153  print '</td></tr>';
2154  }
2155 
2156  // Other attributes
2157  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2158 
2159  print '</table>';
2160 
2161  print '</div>';
2162  print '<div class="fichehalfright">';
2163  print '<div class="ficheaddleft">';
2164  print '<div class="underbanner clearboth"></div>';
2165 
2166  print '<table class="border centpercent">';
2167 
2168  if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
2169  {
2170  // Multicurrency Amount HT
2171  print '<tr><td class="titlefieldmiddle">' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '</td>';
2172  print '<td class="nowrap">' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
2173  print '</tr>';
2174 
2175  // Multicurrency Amount VAT
2176  print '<tr><td>' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '</td>';
2177  print '<td class="nowrap">' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
2178  print '</tr>';
2179 
2180  // Multicurrency Amount TTC
2181  print '<tr><td>' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '</td>';
2182  print '<td class="nowrap">' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
2183  print '</tr>';
2184  }
2185 
2186  // Amount HT
2187  print '<tr><td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
2188  print '<td class="nowrap">' . price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
2189  print '</tr>';
2190 
2191  // Amount VAT
2192  print '<tr><td>' . $langs->trans('AmountVAT') . '</td>';
2193  print '<td class="nowrap">' . price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
2194  print '</tr>';
2195 
2196  // Amount Local Taxes
2197  if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1
2198  {
2199  print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
2200  print '<td class="nowrap">' . price($object->total_localtax1, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
2201  print '</tr>';
2202  }
2203  if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) // Localtax2
2204  {
2205  print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
2206  print '<td class="nowrap">' . price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
2207  print '</tr>';
2208  }
2209 
2210  // Amount TTC
2211  print '<tr><td>' . $langs->trans('AmountTTC') . '</td>';
2212  print '<td class="nowrap">' . price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
2213  print '</tr>';
2214 
2215  // Statut
2216  //print '<tr><td height="10">' . $langs->trans('Status') . '</td><td align="left" colspan="2">' . $object->getLibStatut(4) . '</td></tr>';
2217 
2218  print '</table>';
2219 
2220  // Margin Infos
2221  if (! empty($conf->margin->enabled))
2222  {
2223  $formmargin->displayMarginInfos($object);
2224  }
2225 
2226  print '</div>';
2227  print '</div>';
2228  print '</div>';
2229 
2230  print '<div class="clearboth"></div><br>';
2231 
2232  if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2233  $blocname = 'contacts';
2234  $title = $langs->trans('ContactsAddresses');
2235  include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
2236  }
2237 
2238  if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2239  $blocname = 'notes';
2240  $title = $langs->trans('Notes');
2241  include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
2242  }
2243 
2244  /*
2245  * Lines
2246  */
2247 
2248  // Show object lines
2249  $result = $object->getLinesArray();
2250 
2251  print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#addline' : '#line_' . GETPOST('lineid')) . '" method="POST">
2252  <input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
2253  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateligne') . '">
2254  <input type="hidden" name="mode" value="">
2255  <input type="hidden" name="id" value="' . $object->id . '">
2256  ';
2257 
2258  if (! empty($conf->use_javascript_ajax) && $object->statut == Propal::STATUS_DRAFT) {
2259  include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
2260  }
2261 
2262  print '<div class="div-table-responsive-no-min">';
2263  print '<table id="tablelines" class="noborder noshadow" width="100%">';
2264 
2265  if (! empty($object->lines))
2266  $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2267 
2268  // Form to add new line
2269  if ($object->statut == Propal::STATUS_DRAFT && $user->rights->propal->creer)
2270  {
2271  if ($action != 'editline')
2272  {
2273  // Add products/services form
2274  $object->formAddObjectLine(1, $mysoc, $soc);
2275 
2276  $parameters = array();
2277  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2278  }
2279  }
2280 
2281  print '</table>';
2282  print '</div>';
2283 
2284  print "</form>\n";
2285 
2286  dol_fiche_end();
2287 
2288  /*
2289  * Boutons Actions
2290  */
2291  if ($action != 'presend') {
2292  print '<div class="tabsAction">';
2293 
2294  $parameters = array();
2295  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2296  // modified by hook
2297  if (empty($reshook))
2298  {
2299  if ($action != 'editline')
2300  {
2301  // Validate
2302  if ($object->statut == Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0)
2303  {
2304  if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->creer))
2305  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->propal_advance->validate)))
2306  {
2307  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=validate">' . $langs->trans('Validate') . '</a></div>';
2308  }
2309  else
2310  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans('Validate') . '</a></div>';
2311  }
2312  // Create event
2313  /*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.
2314  {
2315  print '<div class="inline-block divButAction"><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>';
2316  }*/
2317  // Edit
2318  if ($object->statut == Propal::STATUS_VALIDATED && $user->rights->propal->creer) {
2319  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=modif">' . $langs->trans('Modify') . '</a></div>';
2320  }
2321 
2322  // ReOpen
2323  if (($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED) && $user->rights->propal->cloturer) {
2324  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=reopen' . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#reopen') . '"';
2325  print '>' . $langs->trans('ReOpen') . '</a></div>';
2326  }
2327 
2328  // Send
2329  if ($object->statut == Propal::STATUS_VALIDATED || $object->statut == Propal::STATUS_SIGNED) {
2330  if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) {
2331  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendByMail') . '</a></div>';
2332  } else
2333  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans('SendByMail') . '</a></div>';
2334  }
2335 
2336  // Create an order
2337  if (! empty($conf->commande->enabled) && $object->statut == Propal::STATUS_SIGNED) {
2338  if ($user->rights->commande->creer) {
2339  print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/commande/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddOrder") . '</a></div>';
2340  }
2341  }
2342 
2343  // Create an intervention
2344  if (! empty($conf->service->enabled) && ! empty($conf->ficheinter->enabled) && $object->statut == Propal::STATUS_SIGNED) {
2345  if ($user->rights->ficheinter->creer) {
2346  $langs->load("interventions");
2347  print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/fichinter/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddIntervention") . '</a></div>';
2348  }
2349  }
2350 
2351  // Create contract
2352  if ($conf->contrat->enabled && $object->statut == Propal::STATUS_SIGNED) {
2353  $langs->load("contracts");
2354 
2355  if ($user->rights->contrat->creer) {
2356  print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/contrat/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans('AddContract') . '</a></div>';
2357  }
2358  }
2359 
2360  // Create an invoice and classify billed
2361  if ($object->statut == Propal::STATUS_SIGNED)
2362  {
2363  if (! empty($conf->facture->enabled) && $user->rights->facture->creer)
2364  {
2365  print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddBill") . '</a></div>';
2366  }
2367 
2368  $arrayofinvoiceforpropal = $object->getInvoiceArrayList();
2369  if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED))
2370  {
2371  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=classifybilled&amp;socid=' . $object->socid . '">' . $langs->trans("ClassifyBilled") . '</a></div>';
2372  }
2373  }
2374 
2375  // Set accepted/refused
2376  if ($object->statut == Propal::STATUS_VALIDATED && $user->rights->propal->cloturer) {
2377  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=statut' . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#close') . '"';
2378  print '>' . $langs->trans('SetAcceptedRefused') . '</a></div>';
2379  }
2380 
2381  // Clone
2382  if ($user->rights->propal->creer) {
2383  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&amp;socid=' . $object->socid . '&amp;action=clone&amp;object=' . $object->element . '">' . $langs->trans("ToClone") . '</a></div>';
2384  }
2385 
2386  // Delete
2387  if ($user->rights->propal->supprimer) {
2388  print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=delete"';
2389  print '>' . $langs->trans('Delete') . '</a></div>';
2390  }
2391  }
2392  }
2393 
2394  print '</div>';
2395  }
2396 
2397  //Select mail models is same action as presend
2398  if (GETPOST('modelselected')) $action = 'presend';
2399 
2400  if ($action != 'presend')
2401  {
2402  print '<div class="fichecenter"><div class="fichehalfleft">';
2403  print '<a name="builddoc"></a>'; // ancre
2404  /*
2405  * Documents generes
2406  */
2407  $filename = dol_sanitizeFileName($object->ref);
2408  $filedir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
2409  $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
2410  $genallowed = $user->rights->propal->lire;
2411  $delallowed = $user->rights->propal->creer;
2412 
2413  print $formfile->showdocuments('propal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang, '', $object);
2414 
2415  // Show links to link elements
2416  $linktoelem = $form->showLinkToObjectBlock($object, null, array('propal'));
2417  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2418 
2419  // Show online signature link
2420  $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok
2421 
2422  if ($object->statut != Propal::STATUS_DRAFT && $useonlinesignature)
2423  {
2424  print '<br><!-- Link to sign -->';
2425  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
2426  print showOnlineSignatureUrl('proposal', $object->ref).'<br>';
2427  }
2428 
2429  // Show direct download link
2430  if ($object->statut != Propal::STATUS_DRAFT && ! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD))
2431  {
2432  print '<br><!-- Link to download main doc -->'."\n";
2433  print showDirectDownloadLink($object).'<br>';
2434  }
2435 
2436  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2437 
2438  // List of actions on element
2439  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2440  $formactions = new FormActions($db);
2441  $somethingshown = $formactions->showactions($object, 'propal', $socid, 1);
2442 
2443  print '</div></div></div>';
2444  }
2445 
2446  // Presend form
2447  $modelmail='propal_send';
2448  $defaulttopic='SendPropalRef';
2449  $diroutput = $conf->propal->dir_output;
2450  $trackid = 'pro'.$object->id;
2451 
2452  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2453 }
2454 
2455 // End of page
2456 llxFooter();
2457 $db->close();
File of class to manage predefined price products or services by customer.
llxFooter()
Empty footer.
Definition: wrapper.php:58
Class to manage notifications.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage building of HTML components.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
Class to manage products or services.
Class to manage interventions.
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.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_concatdesc($text1, $text2, $forxml=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
Class to manage generation of HTML components for proposal management.
if(empty($reshook)) $form
View.
Definition: perms.php:103
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage standard extra fields.
showDirectDownloadLink($object)
Return string with full Url.
Class to manage generation of HTML components Only common components must be here.
const STATUS_NOTSIGNED
Not signed quote.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
Class to manage projects.
const STATUS_BILLED
Billed or processed quote.
Classe permettant la generation de composants html autre Only common components are here...
Class to manage building of HTML components.
const STATUS_SIGNED
Signed quote.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
Class to manage shipments.
dol_fiche_end($notab=0)
Show tab footer of a card.
Classe permettant la generation de composants html autre Only common components are here...
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage translations.
dol_now($mode='gmt')
Return date for now.
Class ProductCombination Used to represent a product combination.
Class to offer components to list and upload files.
propal_prepare_head($object)
Prepare array with list of tabs.
Definition: propal.lib.php:32
const STATUS_DRAFT
Draft status.
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...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
print
Draft customers invoices.
Definition: index.php:91
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
if(preg_match('/set_(.*)/', $action, $reg)) if(preg_match('/del_(.*)/', $action, $reg)) if($action== 'set') else if($action== 'specimen') else if($action== 'setmodel') else if($action== 'del') else if($action== 'setdoc' $formactions)
View.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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) Si ...
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Return a prefix to use for this Dolibarr instance, for session/cookie names or email id...
Class to manage a WYSIWYG editor.
const STATUS_VALIDATED
Validated status.
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.
Class to manage proposals.
$parameters
Actions.
Definition: card.php:112
static getIdAndTxFromCode(&$db, $code, $date_document='')
Get id and rate of currency from code.