dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
6  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7  * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
8  * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2010-2019 Philippe Grand <philippe.grand@atoo-net.com>
10  * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
11  * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
12  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
13  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
14  * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.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 <https://www.gnu.org/licenses/>.
28  */
29 
36 require '../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/lib/supplier_proposal.lib.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
46 if (!empty($conf->projet->enabled)) {
47  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
48  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
49 }
50 
51 // Load translation files required by the page
52 $langs->loadLangs(array('companies', 'supplier_proposal', 'compta', 'bills', 'propal', 'orders', 'products', 'deliveries', 'sendings'));
53 if (!empty($conf->margin->enabled))
54  $langs->load('margins');
55 
56 $error = 0;
57 
58 $id = GETPOST('id', 'int');
59 $ref = GETPOST('ref', 'alpha');
60 $socid = GETPOST('socid', 'int');
61 $action = GETPOST('action', 'aZ09');
62 $origin = GETPOST('origin', 'alpha');
63 $originid = GETPOST('originid', 'int');
64 $confirm = GETPOST('confirm', 'alpha');
65 $projectid = GETPOST('projectid', 'int');
66 $lineid = GETPOST('lineid', 'int');
67 $contactid = GETPOST('contactid', 'int');
68 
69 // PDF
70 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
71 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
72 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
73 
74 // Nombre de ligne pour choix de produit/service predefinis
75 $NBLINES = 4;
76 
77 // Security check
78 if (!empty($user->socid)) $socid = $user->socid;
79 $result = restrictedArea($user, 'supplier_proposal', $id);
80 
81 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
82 $hookmanager->initHooks(array('supplier_proposalcard', 'globalcard'));
83 
84 $object = new SupplierProposal($db);
85 $extrafields = new ExtraFields($db);
86 
87 // fetch optionals attributes and labels
88 $extrafields->fetch_name_optionals_label($object->table_element);
89 
90 // Load object
91 if ($id > 0 || !empty($ref)) {
92  $ret = $object->fetch($id, $ref);
93  if ($ret > 0)
94  $ret = $object->fetch_thirdparty();
95  if ($ret < 0)
96  dol_print_error('', $object->error);
97 }
98 
99 // Common permissions
100 $usercanread = $user->rights->supplier_proposal->lire;
101 $usercancreate = $user->rights->supplier_proposal->creer;
102 $usercandelete = $user->rights->supplier_proposal->supprimer;
103 
104 // Advanced permissions
105 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->supplier_proposal->validate_advance)));
106 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->supplier_proposal->send_advance);
107 
108 // Additional area permissions
109 $usercanclose = $user->rights->supplier_proposal->cloturer;
110 $usercancreateorder = $user->rights->fournisseur->commande->creer;
111 
112 // Permissions for includes
113 $permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
114 $permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php
115 $permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
116 
117 
118 /*
119  * Actions
120  */
121 
122 $parameters = array('socid' => $socid);
123 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
124 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
125 
126 if (empty($reshook))
127 {
128  if ($cancel)
129  {
130  if (!empty($backtopage))
131  {
132  header("Location: ".$backtopage);
133  exit;
134  }
135  $action = '';
136  }
137 
138  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
139 
140  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
141 
142  include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
143 
144  // Action clone object
145  if ($action == 'confirm_clone' && $confirm == 'yes')
146  {
147  if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers'))
148  {
149  setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
150  } else {
151  if ($object->id > 0) {
152  $result = $object->createFromClone($user, $socid);
153  if ($result > 0) {
154  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
155  exit();
156  } else {
157  setEventMessages($object->error, $object->errors, 'errors');
158  $action = '';
159  }
160  }
161  }
162  }
163 
164  // Delete askprice
165  elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete)
166  {
167  $result = $object->delete($user);
168  if ($result > 0) {
169  header('Location: '.DOL_URL_ROOT.'/supplier_proposal/list.php');
170  exit();
171  } else {
172  $langs->load("errors");
173  setEventMessages($langs->trans($object->error), null, 'errors');
174  }
175  }
176 
177  // Remove line
178  elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate)
179  {
180  $result = $object->deleteline($lineid);
181  // reorder lines
182  if ($result)
183  $object->line_order(true);
184 
185  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
186  // Define output language
187  $outputlangs = $langs;
188  if (!empty($conf->global->MAIN_MULTILANGS)) {
189  $outputlangs = new Translate("", $conf);
190  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
191  $outputlangs->setDefaultLang($newlang);
192  }
193  $ret = $object->fetch($id); // Reload to get new records
194  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
195  }
196 
197  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
198  exit();
199  }
200 
201  // Validation
202  elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate)
203  {
204  $result = $object->valid($user);
205  if ($result >= 0)
206  {
207  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
208  {
209  // Define output language
210  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
211  {
212  $outputlangs = $langs;
213  $newlang = '';
214  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
215  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
216  if (!empty($newlang)) {
217  $outputlangs = new Translate("", $conf);
218  $outputlangs->setDefaultLang($newlang);
219  }
220  $model = $object->model_pdf;
221  $ret = $object->fetch($id); // Reload to get new records
222 
223  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
224  }
225  }
226  } else {
227  $langs->load("errors");
228  if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors');
229  else setEventMessages($langs->trans($object->error), null, 'errors');
230  }
231  } elseif ($action == 'setdate_livraison' && $usercancreate) {
232  $result = $object->setDeliveryDate($user, dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']));
233  if ($result < 0)
234  dol_print_error($db, $object->error);
235  }
236 
237  // Create supplier proposal
238  elseif ($action == 'add' && $usercancreate)
239  {
240  $object->socid = $socid;
241  $object->fetch_thirdparty();
242 
243  $date_delivery = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
244 
245  if ($socid < 1) {
246  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
247  $action = 'create';
248  $error++;
249  }
250 
251  if (!$error)
252  {
253  $db->begin();
254 
255  // Si on a selectionne une demande a copier, on realise la copie
256  if (GETPOST('createmode') == 'copy' && GETPOST('copie_supplier_proposal'))
257  {
258  if ($object->fetch(GETPOST('copie_supplier_proposal')) > 0) {
259  $object->ref = GETPOST('ref');
260  $object->date_livraison = $date_delivery; // deprecated
261  $object->delivery_date = $date_delivery;
262  $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
263  $object->cond_reglement_id = GETPOST('cond_reglement_id');
264  $object->mode_reglement_id = GETPOST('mode_reglement_id');
265  $object->fk_account = GETPOST('fk_account', 'int');
266  $object->remise_percent = GETPOST('remise_percent');
267  $object->remise_absolue = GETPOST('remise_absolue');
268  $object->socid = GETPOST('socid');
269  $object->fk_project = GETPOST('projectid', 'int');
270  $object->model_pdf = GETPOST('model');
271  $object->author = $user->id; // deprecated
272  $object->note = GETPOST('note', 'restricthtml');
273  $object->note_private = GETPOST('note', 'restricthtml');
274  $object->statut = SupplierProposal::STATUS_DRAFT;
275  } else {
276  setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_supplier_proposal')), null, 'errors');
277  }
278  } else {
279  $object->ref = GETPOST('ref');
280  $object->date_livraison = $date_delivery;
281  $object->delivery_date = $date_delivery;
282  $object->demand_reason_id = GETPOST('demand_reason_id');
283  $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
284  $object->cond_reglement_id = GETPOST('cond_reglement_id');
285  $object->mode_reglement_id = GETPOST('mode_reglement_id');
286  $object->fk_account = GETPOST('fk_account', 'int');
287  $object->fk_project = GETPOST('projectid', 'int');
288  $object->model_pdf = GETPOST('model');
289  $object->author = $user->id; // deprecated
290  $object->note = GETPOST('note', 'restricthtml');
291  $object->note_private = GETPOST('note', 'restricthtml');
292 
293  $object->origin = GETPOST('origin');
294  $object->origin_id = GETPOST('originid');
295 
296  // Multicurrency
297  if (!empty($conf->multicurrency->enabled))
298  {
299  $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
300  }
301 
302  // Fill array 'array_options' with data from add form
303  $ret = $extrafields->setOptionalsFromPost(null, $object);
304  if ($ret < 0) {
305  $error++;
306  $action = 'create';
307  }
308  }
309 
310  if (!$error)
311  {
312  if ($origin && $originid)
313  {
314  $element = 'supplier_proposal';
315  $subelement = 'supplier_proposal';
316 
317  $object->origin = $origin;
318  $object->origin_id = $originid;
319 
320  // Possibility to add external linked objects with hooks
321  $object->linked_objects [$object->origin] = $object->origin_id;
322  if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
323  $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
324  }
325 
326  $id = $object->create($user);
327  if ($id > 0)
328  {
329  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
330 
331  $classname = ucfirst($subelement);
332  $srcobject = new $classname($db);
333 
334  dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
335  $result = $srcobject->fetch($object->origin_id);
336 
337  if ($result > 0)
338  {
339  $lines = $srcobject->lines;
340  if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
341  {
342  $srcobject->fetch_lines();
343  $lines = $srcobject->lines;
344  }
345 
346  $fk_parent_line = 0;
347  $num = count($lines);
348  for ($i = 0; $i < $num; $i++)
349  {
350  $label = (!empty($lines[$i]->label) ? $lines[$i]->label : '');
351  $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
352 
353  // Positive line
354  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
355 
356  // Reset fk_parent_line for no child products and special product
357  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
358  $fk_parent_line = 0;
359  }
360 
361  // Extrafields
362  if (method_exists($lines[$i], 'fetch_optionals')) {
363  $lines[$i]->fetch_optionals();
364  $array_options = $lines[$i]->array_options;
365  }
366 
367  $result = $object->addline(
368  $desc,
369  $lines[$i]->subprice,
370  $lines[$i]->qty,
371  $lines[$i]->tva_tx,
372  $lines[$i]->localtax1_tx,
373  $lines[$i]->localtax2_tx,
374  $lines[$i]->fk_product,
375  $lines[$i]->remise_percent,
376  'HT',
377  0,
378  $lines[$i]->info_bits,
379  $product_type,
380  $lines[$i]->rang,
381  $lines[$i]->special_code,
382  $fk_parent_line,
383  $lines[$i]->fk_fournprice,
384  $lines[$i]->pa_ht, $label,
385  $array_options,
386  $lines[$i]->ref_supplier,
387  $lines[$i]->fk_unit
388  );
389 
390  if ($result > 0) {
391  $lineid = $result;
392  } else {
393  $lineid = 0;
394  $error++;
395  break;
396  }
397 
398  // Defined the new fk_parent_line
399  if ($result > 0 && $lines[$i]->product_type == 9) {
400  $fk_parent_line = $result;
401  }
402  }
403 
404  // Hooks
405  $parameters = array('objFrom' => $srcobject);
406  $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
407  // modified by hook
408  if ($reshook < 0) {
409  $error++;
410  }
411  } else {
412  setEventMessages($srcobject->error, $srcobject->errors, 'errors');
413  $error++;
414  }
415  } else {
416  setEventMessages($object->error, $object->errors, 'errors');
417  $error++;
418  }
419  } // Standard creation
420  else {
421  $id = $object->create($user);
422  }
423 
424  if ($id > 0)
425  {
426  if (!$error)
427  {
428  $db->commit();
429 
430  // Define output language
431  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
432  {
433  $outputlangs = $langs;
434  $newlang = '';
435  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
436  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
437  if (!empty($newlang)) {
438  $outputlangs = new Translate("", $conf);
439  $outputlangs->setDefaultLang($newlang);
440  }
441  $model = $object->model_pdf;
442 
443  $ret = $object->fetch($id); // Reload to get new records
444  $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
445  if ($result < 0) dol_print_error($db, $result);
446  }
447 
448  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
449  exit();
450  } else {
451  $db->rollback();
452  $action = 'create';
453  }
454  } else {
455  setEventMessages($object->error, $object->errors, 'errors');
456  $db->rollback();
457  $action = 'create';
458  }
459  }
460  }
461  }
462 
463  // Reopen proposal
464  elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) {
465  // prevent browser refresh from reopening proposal several times
466  if ($object->statut == SupplierProposal::STATUS_SIGNED || $object->statut == SupplierProposal::STATUS_NOTSIGNED || $object->statut == SupplierProposal::STATUS_CLOSE) {
467  $object->reopen($user, SupplierProposal::STATUS_VALIDATED);
468  }
469  }
470 
471  // Close proposal
472  elseif ($action == 'close' && $usercanclose && !GETPOST('cancel', 'alpha')) {
473  // prevent browser refresh from reopening proposal several times
474  if ($object->statut == SupplierProposal::STATUS_SIGNED) {
475  $object->setStatut(SupplierProposal::STATUS_CLOSE);
476  }
477  }
478 
479  // Set accepted/refused
480  elseif ($action == 'setstatut' && $usercanclose && !GETPOST('cancel', 'alpha')) {
481  if (!GETPOST('statut')) {
482  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("CloseAs")), null, 'errors');
483  $action = 'statut';
484  } else {
485  // prevent browser refresh from closing proposal several times
486  if ($object->statut == SupplierProposal::STATUS_VALIDATED) {
487  $object->cloture($user, GETPOST('statut'), GETPOST('note', 'restricthtml'));
488  }
489  }
490  }
491 
492  // Actions when printing a doc from card
493  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
494 
495  // Actions to send emails
496  $triggersendname = 'PROPOSAL_SUPPLIER_SENTBYMAIL';
497  $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
498  $trackid = 'spro'.$object->id;
499  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
500 
501  // Actions to build doc
502  $upload_dir = $conf->supplier_proposal->dir_output;
503  $permissiontoadd = $usercancreate;
504  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
505 
506 
507  // Go back to draft
508  if ($action == 'modif' && $usercancreate)
509  {
510  $object->setDraft($user);
511 
512  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
513  {
514  // Define output language
515  $outputlangs = $langs;
516  if (!empty($conf->global->MAIN_MULTILANGS)) {
517  $outputlangs = new Translate("", $conf);
518  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
519  $outputlangs->setDefaultLang($newlang);
520  }
521  $ret = $object->fetch($id); // Reload to get new records
522  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
523  }
524  } elseif ($action == "setabsolutediscount" && $usercancreate) {
525  if ($_POST["remise_id"]) {
526  if ($object->id > 0) {
527  $result = $object->insert_discount($_POST["remise_id"]);
528  if ($result < 0) {
529  setEventMessages($object->error, $object->errors, 'errors');
530  }
531  }
532  }
533  }
534 
535  // Add a product line
536  if ($action == 'addline' && $usercancreate)
537  {
538  $langs->load('errors');
539  $error = 0;
540 
541  // Set if we used free entry or predefined product
542  $predef = '';
543  $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
544  $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'));
545  $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'));
546  $ref_supplier = GETPOST('fourn_ref', 'alpha');
547  $prod_entry_mode = GETPOST('prod_entry_mode');
548  if ($prod_entry_mode == 'free') {
549  $idprod = 0;
550  $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
551  $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
552  } else {
553  $idprod = GETPOST('idprod', 'int');
554  $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
555  $tva_tx = '';
556  }
557 
558  $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
559  $remise_percent = GETPOST('remise_percent'.$predef);
560  $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
561 
562  // Extrafields
563  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
564  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
565  // Unset extrafield
566  if (is_array($extralabelsline)) {
567  // Get extra fields
568  foreach ($extralabelsline as $key => $value) {
569  unset($_POST["options_".$key]);
570  }
571  }
572 
573  if ($prod_entry_mode == 'free' && empty($idprod) && GETPOST('type') < 0) {
574  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
575  $error++;
576  }
577 
578  if ($prod_entry_mode == 'free' && empty($idprod) && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && $price_ht_devise === '') // Unit price can be 0 but not ''. Also price can be negative for proposal.
579  {
580  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPrice")), null, 'errors');
581  $error++;
582  }
583  if ($prod_entry_mode == 'free' && empty($idprod) && empty($product_desc)) {
584  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
585  $error++;
586  }
587  if (!$error && ($qty >= 0)) {
588  $pu_ht = price2num($price_ht, 'MU');
589  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
590  $price_min = 0;
591  $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
592 
593  $db->begin();
594 
595  // Ecrase $pu par celui du produit
596  // Ecrase $desc par celui du produit
597  // Ecrase $txtva par celui du produit
598  if (($prod_entry_mode != 'free') && empty($error)) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
599  {
600  $productsupplier = new ProductFournisseur($db);
601 
602  $idprod = 0;
603  if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') $idprod = -99; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...)
604 
605  $reg = array();
606  if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg))
607  {
608  $idprod = $reg[1];
609  $res = $productsupplier->fetch($idprod); // Load product from its ID
610  // Call to init some price properties of $productsupplier
611  // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
612  if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER))
613  {
614  $fksoctosearch = 0;
615  $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
616  if ($productsupplier->fourn_socid != $socid) // The price we found is for another supplier, so we clear supplier price
617  {
618  $productsupplier->ref_supplier = '';
619  }
620  } else {
621  $fksoctosearch = $object->thirdparty->id;
622  $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
623  }
624  } elseif (GETPOST('idprodfournprice', 'alpha') > 0)
625  {
626  //$qtytosearch=$qty; // Just to see if a price exists for the quantity. Not used to found vat.
627  $qtytosearch = -1; // We force qty to -1 to be sure to find if the supplier price that exists
628  $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch);
629  $res = $productsupplier->fetch($idprod);
630  }
631 
632  if ($idprod > 0)
633  {
634  $label = $productsupplier->label;
635 
636  // if we use supplier description of the products
637  if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
638  $desc = $productsupplier->desc_supplier;
639  } else $desc = $productsupplier->description;
640 
641  if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
642 
643  $type = $productsupplier->type;
644  $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
645 
646  $ref_supplier = $productsupplier->ref_supplier;
647 
648  $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
649  $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
650  if (empty($tva_tx)) $tva_npr = 0;
651  $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
652  $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
653 
654  if (empty($pu_ht)) $pu_ht = 0; // If pu is '' or null, we force to have a numeric value
655 
656  // If GETPOST('idprodfournprice') is a numeric, we can use it. If it is empty or if it is 'idprod_123', we should use -1 (not used)
657  $fournprice = (is_numeric(GETPOST('idprodfournprice', 'alpha')) ? GETPOST('idprodfournprice', 'alpha') : -1);
658  $buyingprice = 0;
659  $pu_ht_devise = price2num($price_ht_devise, 'MU');
660 
661  $result = $object->addline(
662  $desc,
663  $pu_ht,
664  $qty,
665  $tva_tx,
666  $localtax1_tx,
667  $localtax2_tx,
668  $productsupplier->id,
669  $remise_percent,
670  $price_base_type,
671  $pu_ttc,
672  $tva_npr,
673  $type,
674  -1,
675  0,
676  GETPOST('fk_parent_line'),
677  $fournprice,
678  $buyingprice,
679  $label,
680  $array_options,
681  $ref_supplier,
682  $productsupplier->fk_unit,
683  '',
684  0,
685  $pu_ht_devise,
686  $date_start,
687  $date_end
688  );
689 
690  //var_dump($tva_tx);var_dump($productsupplier->fourn_pu);var_dump($price_base_type);exit;
691  if ($result < 0)
692  {
693  $error++;
694  setEventMessages($object->error, $object->errors, 'errors');
695  }
696  }
697  if ($idprod == -99 || $idprod == 0)
698  {
699  // Product not selected
700  $error++;
701  $langs->load("errors");
702  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")).' '.$langs->trans("or").' '.$langs->trans("NoPriceDefinedForThisSupplier"), null, 'errors');
703  }
704  if ($idprod == -1)
705  {
706  // Quantity too low
707  $error++;
708  $langs->load("errors");
709  setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors');
710  }
711  } elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '' || GETPOST('multicurrency_price_ht') != '') && empty($error)) // Free product. // $price_ht is already set
712  {
713  $pu_ht = price2num($price_ht, 'MU');
714  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
715  $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
716  $tva_tx = str_replace('*', '', $tva_tx);
717  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
718  $desc = $product_desc;
719  $type = GETPOST('type');
720 
721  $fk_unit = GETPOST('units', 'alpha');
722 
723  if (!preg_match('/\((.*)\)/', $tva_tx)) {
724  $tva_tx = price2num($tva_tx); // When vat is text input field
725  }
726 
727  // Local Taxes
728  $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
729  $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
730 
731  if ($price_ht !== '')
732  {
733  $pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
734  } else {
735  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
736  $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
737  }
738  $price_base_type = 'HT';
739  $pu_ht_devise = price2num($price_ht_devise, 'MU');
740 
741  $result = $object->addline(
742  $desc,
743  $pu_ht,
744  $qty,
745  $tva_tx,
746  $localtax1_tx,
747  $localtax2_tx,
748  $idprod,
749  $remise_percent,
750  $price_base_type,
751  $pu_ttc,
752  $info_bits,
753  $type,
754  -1, // rang
755  0, // special_code
756  GETPOST('fk_parent_line'),
757  $fournprice,
758  $buyingprice,
759  $label,
760  $array_options,
761  $ref_supplier,
762  $fk_unit,
763  '', // origin
764  0, // origin_id
765  $pu_ht_devise);
766  }
767 
768 
769  if (!$error && $result > 0)
770  {
771  $db->commit();
772 
773  $ret = $object->fetch($object->id); // Reload to get new records
774 
775  // Define output language
776  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
777  {
778  $outputlangs = $langs;
779  $newlang = '';
780  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
781  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
782  if (!empty($newlang)) {
783  $outputlangs = new Translate("", $conf);
784  $outputlangs->setDefaultLang($newlang);
785  }
786  $model = $object->model_pdf;
787  $ret = $object->fetch($id); // Reload to get new records
788 
789  $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
790  if ($result < 0) dol_print_error($db, $result);
791  }
792 
793  unset($_POST['prod_entry_mode']);
794 
795  unset($_POST['qty']);
796  unset($_POST['type']);
797  unset($_POST['remise_percent']);
798  unset($_POST['pu']);
799  unset($_POST['price_ht']);
800  unset($_POST['multicurrency_price_ht']);
801  unset($_POST['price_ttc']);
802  unset($_POST['tva_tx']);
803  unset($_POST['label']);
804  unset($_POST['product_ref']);
805  unset($_POST['product_label']);
806  unset($_POST['product_desc']);
807  unset($_POST['fournprice']);
808  unset($_POST['buying_price']);
809  unset($localtax1_tx);
810  unset($localtax2_tx);
811  unset($_POST['np_marginRate']);
812  unset($_POST['np_markRate']);
813  unset($_POST['dp_desc']);
814  unset($_POST['idprodfournprice']);
815  unset($_POST['idprod']);
816 
817  unset($_POST['date_starthour']);
818  unset($_POST['date_startmin']);
819  unset($_POST['date_startsec']);
820  unset($_POST['date_startday']);
821  unset($_POST['date_startmonth']);
822  unset($_POST['date_startyear']);
823  unset($_POST['date_endhour']);
824  unset($_POST['date_endmin']);
825  unset($_POST['date_endsec']);
826  unset($_POST['date_endday']);
827  unset($_POST['date_endmonth']);
828  unset($_POST['date_endyear']);
829  } else {
830  $db->rollback();
831 
832  setEventMessages($object->error, $object->errors, 'errors');
833  }
834  }
835  }
836 
837  // Mise a jour d'une ligne dans la demande de prix
838  elseif ($action == 'updateline' && $usercancreate && GETPOST('save') == $langs->trans("Save")) {
839  $vat_rate = (GETPOST('tva_tx') ?GETPOST('tva_tx') : 0);
840 
841  // Define info_bits
842  $info_bits = 0;
843  if (preg_match('/\*/', $vat_rate))
844  $info_bits |= 0x01;
845 
846  // Clean parameters
847  $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
848 
849  // Define vat_rate
850  $vat_rate = str_replace('*', '', $vat_rate);
851  $localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
852  $localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
853 
854  if (GETPOST('price_ht') != '')
855  {
856  $ht = price2num(GETPOST('price_ht'), '', 2);
857  }
858 
859  if (GETPOST('price_ttc') != '')
860  {
861  $reg = array();
862  $vatratecleaned = $vat_rate;
863  if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) // If vat is "xx (yy)"
864  {
865  $vatratecleaned = trim($reg[1]);
866  $vatratecode = $reg[2];
867  }
868 
869  $ttc = price2num(GETPOST('price_ttc'), '', 2);
870  $ht = $ttc / (1 + ($vatratecleaned / 100));
871  }
872 
873  $price_base_type = 'HT';
874  $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), 'CU');
875 
876  // Add buying price
877  $fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
878  $buyingprice = (GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
879 
880  // Extrafields Lines
881  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
882  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
883  // Unset extrafield POST Data
884  if (is_array($extralabelsline)) {
885  foreach ($extralabelsline as $key => $value) {
886  unset($_POST["options_".$key]);
887  }
888  }
889 
890  // Define special_code for special lines
891  $special_code = GETPOST('special_code');
892  if (!GETPOST('qty')) $special_code = 3;
893 
894  // Check minimum price
895  $productid = GETPOST('productid', 'int');
896  if (!empty($productid)) {
897  $productsupplier = new ProductFournisseur($db);
898  if (!empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY))
899  {
900  if ($productid > 0 && $productsupplier->get_buyprice(0, price2num($_POST['qty']), $productid, 'none', GETPOST('socid', 'int')) < 0)
901  {
902  setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'warnings');
903  }
904  }
905 
906  $product = new Product($db);
907  $res = $product->fetch($productid);
908 
909  $type = $product->type;
910 
911  $price_min = $product->price_min;
912  if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level))
913  $price_min = $product->multiprices_min [$object->thirdparty->price_level];
914 
915  $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
916  } else {
917  $type = GETPOST('type');
918  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
919 
920  // Check parameters
921  if (GETPOST('type') < 0) {
922  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
923  $error++;
924  }
925  }
926 
927  if (!$error) {
928  $db->begin();
929 
930  $ref_supplier = GETPOST('fourn_ref', 'alpha');
931  $fk_unit = GETPOST('units');
932 
933  $result = $object->updateline(
934  GETPOST('lineid'),
935  $ht,
936  GETPOST('qty'),
937  GETPOST('remise_percent'),
938  $vat_rate,
939  $localtax1_rate,
940  $localtax2_rate,
941  $description,
942  $price_base_type,
943  $info_bits,
944  $special_code,
945  GETPOST('fk_parent_line'),
946  0,
947  $fournprice,
948  $buyingprice,
949  $label,
950  $type,
951  $array_options,
952  $ref_supplier,
953  $fk_unit,
954  $pu_ht_devise
955  );
956 
957  if ($result >= 0) {
958  $db->commit();
959 
960  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
961  // Define output language
962  $outputlangs = $langs;
963  if (!empty($conf->global->MAIN_MULTILANGS)) {
964  $outputlangs = new Translate("", $conf);
965  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
966  $outputlangs->setDefaultLang($newlang);
967  }
968  $ret = $object->fetch($id); // Reload to get new records
969  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
970  }
971 
972  unset($_POST['qty']);
973  unset($_POST['type']);
974  unset($_POST['productid']);
975  unset($_POST['remise_percent']);
976  unset($_POST['price_ht']);
977  unset($_POST['multicurrency_price_ht']);
978  unset($_POST['price_ttc']);
979  unset($_POST['tva_tx']);
980  unset($_POST['product_ref']);
981  unset($_POST['product_label']);
982  unset($_POST['product_desc']);
983  unset($_POST['fournprice']);
984  unset($_POST['buying_price']);
985 
986  unset($_POST['date_starthour']);
987  unset($_POST['date_startmin']);
988  unset($_POST['date_startsec']);
989  unset($_POST['date_startday']);
990  unset($_POST['date_startmonth']);
991  unset($_POST['date_startyear']);
992  unset($_POST['date_endhour']);
993  unset($_POST['date_endmin']);
994  unset($_POST['date_endsec']);
995  unset($_POST['date_endday']);
996  unset($_POST['date_endmonth']);
997  unset($_POST['date_endyear']);
998  } else {
999  $db->rollback();
1000 
1001  setEventMessages($object->error, $object->errors, 'errors');
1002  }
1003  }
1004  } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
1005  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
1006  exit();
1007  }
1008 
1009  // Set project
1010  elseif ($action == 'classin' && $usercancreate) {
1011  $object->setProject(GETPOST('projectid'), 'int');
1012  }
1013 
1014  // Delivery delay
1015  elseif ($action == 'setavailability' && $usercancreate) {
1016  $result = $object->availability($_POST['availability_id']);
1017  }
1018 
1019  // Terms of payments
1020  elseif ($action == 'setconditions' && $usercancreate) {
1021  $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
1022  } elseif ($action == 'setremisepercent' && $usercancreate) {
1023  $result = $object->set_remise_percent($user, GETPOST('remise_percent', 'alpha'));
1024  } elseif ($action == 'setremiseabsolue' && $usercancreate) {
1025  $result = $object->set_remise_absolue($user, GETPOST('remise_absolue', 'alpha'));
1026  }
1027 
1028  // Payment mode
1029  elseif ($action == 'setmode' && $usercancreate) {
1030  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
1031  }
1032 
1033  // Multicurrency Code
1034  elseif ($action == 'setmulticurrencycode' && $usercancreate) {
1035  $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
1036  }
1037 
1038  // Multicurrency rate
1039  elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
1040  $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int'));
1041  } elseif ($action == 'update_extras') {
1042  $object->oldcopy = dol_clone($object);
1043 
1044  // Fill array 'array_options' with data from update form
1045  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
1046  if ($ret < 0) $error++;
1047 
1048  if (!$error)
1049  {
1050  $result = $object->insertExtraFields('PROPOSAL_SUPPLIER_MODIFY');
1051  if ($result < 0)
1052  {
1053  setEventMessages($object->error, $object->errors, 'errors');
1054  $error++;
1055  }
1056  }
1057 
1058  if ($error) $action = 'edit_extras';
1059  }
1060 }
1061 
1062 
1063 /*
1064  * View
1065  */
1066 
1067 llxHeader('', $langs->trans('CommRequests'), 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur');
1068 
1069 $form = new Form($db);
1070 $formother = new FormOther($db);
1071 $formfile = new FormFile($db);
1072 $formmargin = new FormMargin($db);
1073 $companystatic = new Societe($db);
1074 if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
1075 
1076 $now = dol_now();
1077 
1078 // Add new askprice
1079 if ($action == 'create')
1080 {
1081  $currency_code = $conf->currency;
1082 
1083  print load_fiche_titre($langs->trans("NewAskPrice"), '', 'supplier_proposal');
1084 
1085  $soc = new Societe($db);
1086  if ($socid > 0)
1087  $res = $soc->fetch($socid);
1088 
1089  // Load objectsrc
1090  if (!empty($origin) && !empty($originid))
1091  {
1092  $element = 'supplier_proposal';
1093  $subelement = 'supplier_proposal';
1094 
1095  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1096 
1097  $classname = ucfirst($subelement);
1098  $objectsrc = new $classname($db);
1099  $objectsrc->fetch($originid);
1100  if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
1101  {
1102  $objectsrc->fetch_lines();
1103  }
1104  $objectsrc->fetch_thirdparty();
1105 
1106  $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
1107  $soc = $objectsrc->thirdparty;
1108 
1109  $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0)); // TODO maybe add default value option
1110  $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1111  $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
1112  $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1113 
1114  // Replicate extrafields
1115  $objectsrc->fetch_optionals();
1116  $object->array_options = $objectsrc->array_options;
1117 
1118  if (!empty($conf->multicurrency->enabled))
1119  {
1120  if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code;
1121  if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx;
1122  }
1123  } else {
1124  $cond_reglement_id = $soc->cond_reglement_supplier_id;
1125  $mode_reglement_id = $soc->mode_reglement_supplier_id;
1126  if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code;
1127  }
1128 
1129  $object = new SupplierProposal($db);
1130 
1131  print '<form name="addprop" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1132  print '<input type="hidden" name="token" value="'.newToken().'">';
1133  print '<input type="hidden" name="action" value="add">';
1134  if ($origin != 'project' && $originid) {
1135  print '<input type="hidden" name="origin" value="'.$origin.'">';
1136  print '<input type="hidden" name="originid" value="'.$originid.'">';
1137  }
1138 
1140 
1141  print '<table class="border centpercent">';
1142 
1143  // Reference
1144  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
1145 
1146  // Third party
1147  print '<tr>';
1148  print '<td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
1149  if ($socid > 0) {
1150  print '<td colspan="2">';
1151  print $soc->getNomUrl(1);
1152  print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1153  print '</td>';
1154  } else {
1155  print '<td colspan="2">';
1156  print img_picto('', 'company').$form->select_company('', 'socid', 's.fournisseur=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300');
1157  print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1158  print '</td>';
1159  }
1160  print '</tr>'."\n";
1161 
1162  if ($soc->id > 0)
1163  {
1164  // Discounts for third party
1165  print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
1166 
1167  $absolute_discount = $soc->getAvailableDiscounts('', '', 0, 1);
1168 
1169  $thirdparty = $soc;
1170  $discount_type = 1;
1171  $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
1172  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1173 
1174  print '</td></tr>';
1175  }
1176 
1177  // Terms of payment
1178  print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
1179  $form->select_conditions_paiements(GETPOST('cond_reglement_id') > 0 ? GETPOST('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id', -1, 1);
1180  print '</td></tr>';
1181 
1182  // Mode of payment
1183  print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
1184  $form->select_types_paiements(GETPOST('mode_reglement_id') > 0 ? GETPOST('mode_reglement_id') : $mode_reglement_id, 'mode_reglement_id');
1185  print '</td></tr>';
1186 
1187  // Bank Account
1188  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && !empty($conf->banque->enabled)) {
1189  print '<tr><td>'.$langs->trans('BankAccount').'</td><td colspan="2">';
1190  $form->select_comptes(GETPOST('fk_account') > 0 ? GETPOST('fk_account', 'int') : $fk_account, 'fk_account', 0, '', 1);
1191  print '</td></tr>';
1192  }
1193 
1194  // Shipping Method
1195  if (!empty($conf->expedition->enabled)) {
1196  print '<tr><td>'.$langs->trans('SendingMethod').'</td><td colspan="2">';
1197  print $form->selectShippingMethod(GETPOST('shipping_method_id') > 0 ? GETPOST('shipping_method_id', 'int') : $shipping_method_id, 'shipping_method_id', '', 1);
1198  print '</td></tr>';
1199  }
1200 
1201  // Delivery date (or manufacturing)
1202  print '<tr><td>'.$langs->trans("DeliveryDate").'</td>';
1203  print '<td colspan="2">';
1204  $datedelivery = dol_mktime(0, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
1205  if ($conf->global->DATE_LIVRAISON_WEEK_DELAY != "") {
1206  $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
1207  $syear = date("Y", $tmpdte);
1208  $smonth = date("m", $tmpdte);
1209  $sday = date("d", $tmpdte);
1210  print $form->selectDate($syear."-".$smonth."-".$sday, 'liv_', '', '', '', "addask");
1211  } else {
1212  print $form->selectDate($datedelivery ? $datedelivery : -1, 'liv_', '', '', '', "addask", 1, 1);
1213  }
1214  print '</td></tr>';
1215 
1216 
1217  // Model
1218  print '<tr>';
1219  print '<td>'.$langs->trans("DefaultModel").'</td>';
1220  print '<td colspan="2">';
1222  $preselected = ($conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT : $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF);
1223  print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
1224  print "</td></tr>";
1225 
1226  // Project
1227  if (!empty($conf->projet->enabled))
1228  {
1229  $langs->load("projects");
1230 
1231  $formproject = new FormProjets($db);
1232 
1233  if ($origin == 'project') $projectid = ($originid ? $originid : 0);
1234 
1235  print '<tr>';
1236  print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
1237  print img_picto('', 'project').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
1238  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).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
1239 
1240  print '</td>';
1241  print '</tr>';
1242  }
1243 
1244  // Multicurrency
1245  if (!empty($conf->multicurrency->enabled)) {
1246  print '<tr>';
1247  print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1248  print '<td colspan="3" class="maxwidthonsmartphone">';
1249  print $form->selectMultiCurrency($currency_code, 'multicurrency_code');
1250  print '</td></tr>';
1251  }
1252 
1253  // Other attributes
1254  $parameters = array('colspan' => ' colspan="3"', 'cols' => 3);
1255  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1256  print $hookmanager->resPrint;
1257  if (empty($reshook)) {
1258  print $object->showOptionals($extrafields, 'edit', $parameters);
1259  }
1260 
1261 
1262  // Lines from source
1263  if (!empty($origin) && !empty($originid) && is_object($objectsrc))
1264  {
1265  // TODO for compatibility
1266  if ($origin == 'contrat') {
1267  // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
1268  $objectsrc->remise_absolue = $remise_absolue;
1269  $objectsrc->remise_percent = $remise_percent;
1270  $objectsrc->update_price(1, - 1, 1);
1271  }
1272 
1273  print "\n<!-- ".$classname." info -->";
1274  print "\n";
1275  print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
1276  print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
1277  print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
1278  print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1279  print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1280 
1281  print '<tr><td>'.$langs->trans('CommRequest').'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
1282  print '<tr><td>'.$langs->trans('AmountHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
1283  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
1284  if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) // Localtax1
1285  {
1286  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
1287  }
1288 
1289  if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2
1290  {
1291  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
1292  }
1293  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
1294 
1295  if (!empty($conf->multicurrency->enabled))
1296  {
1297  print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
1298  print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_tva)."</td></tr>";
1299  print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ttc)."</td></tr>";
1300  }
1301  }
1302 
1303  print "</table>\n";
1304 
1305 
1306  /*
1307  * Combobox pour la fonction de copie
1308  */
1309 
1310  if (empty($conf->global->SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE)) print '<input type="hidden" name="createmode" value="empty">';
1311 
1312  if (!empty($conf->global->SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE))
1313  {
1314  print '<br><table>';
1315 
1316  // For backward compatibility
1317  print '<tr>';
1318  print '<td><input type="radio" name="createmode" value="copy"></td>';
1319  print '<td>'.$langs->trans("CopyAskFrom").' </td>';
1320  print '<td>';
1321  $liste_ask = array();
1322  $liste_ask [0] = '';
1323 
1324  $sql = "SELECT p.rowid as id, p.ref, s.nom";
1325  $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal p";
1326  $sql .= ", ".MAIN_DB_PREFIX."societe s";
1327  $sql .= " WHERE s.rowid = p.fk_soc";
1328  $sql .= " AND p.entity = ".$conf->entity;
1329  $sql .= " AND p.fk_statut <> ".SupplierProposal::STATUS_DRAFT;
1330  $sql .= " ORDER BY Id";
1331 
1332  $resql = $db->query($sql);
1333  if ($resql) {
1334  $num = $db->num_rows($resql);
1335  $i = 0;
1336  while ($i < $num) {
1337  $row = $db->fetch_row($resql);
1338  $askPriceSupplierRefAndSocName = $row [1]." - ".$row [2];
1339  $liste_ask [$row [0]] = $askPriceSupplierRefAndSocName;
1340  $i++;
1341  }
1342  print $form->selectarray("copie_supplier_proposal", $liste_ask, 0);
1343  } else {
1344  dol_print_error($db);
1345  }
1346  print '</td></tr>';
1347 
1348  print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
1349  print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyAsk").'</td></tr>';
1350  }
1351 
1352  if (!empty($conf->global->SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE)) print '</table>';
1353 
1355 
1356  print '<div class="center">';
1357  print '<input type="submit" class="button" value="'.$langs->trans("CreateDraft").'">';
1358  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1359  print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
1360  print '</div>';
1361 
1362  print "</form>";
1363 
1364 
1365  // Show origin lines
1366  if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1367  print '<br>';
1368 
1369  $title = $langs->trans('ProductsAndServices');
1370  print load_fiche_titre($title);
1371 
1372  print '<table class="noborder centpercent">';
1373 
1374  $objectsrc->printOriginLinesList();
1375 
1376  print '</table>';
1377  }
1378 } else {
1379  /*
1380  * Show object in view mode
1381  */
1382 
1383  $soc = new Societe($db);
1384  $soc->fetch($object->socid);
1385 
1386  $head = supplier_proposal_prepare_head($object);
1387  print dol_get_fiche_head($head, 'comm', $langs->trans('CommRequest'), -1, 'supplier_proposal');
1388 
1389  $formconfirm = '';
1390 
1391  // Clone confirmation
1392  if ($action == 'clone') {
1393  // Create an array for form
1394  $formquestion = array(
1395  // 'text' => $langs->trans("ConfirmClone"),
1396  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
1397  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' =>
1398  // 1),
1399  array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', 's.fournisseur=1')));
1400  // Paiement incomplet. On demande si motif = escompte ou autre
1401  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1402  }
1403 
1404  // Confirm delete
1405  elseif ($action == 'delete') {
1406  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAsk'), $langs->trans('ConfirmDeleteAsk', $object->ref), 'confirm_delete', '', 0, 1);
1407  }
1408 
1409  // Confirm reopen
1410  elseif ($action == 'reopen') {
1411  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenAsk', $object->ref), 'confirm_reopen', '', 0, 1);
1412  }
1413 
1414  // Confirmation delete product/service line
1415  elseif ($action == 'ask_deleteline') {
1416  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
1417  }
1418 
1419  // Confirm validate askprice
1420  elseif ($action == 'validate') {
1421  $error = 0;
1422 
1423  // on verifie si l'objet est en numerotation provisoire
1424  $ref = substr($object->ref, 1, 4);
1425  if ($ref == 'PROV') {
1426  $numref = $object->getNextNumRef($soc);
1427  if (empty($numref)) {
1428  $error++;
1429  setEventMessages($object->error, $object->errors, 'errors');
1430  }
1431  } else {
1432  $numref = $object->ref;
1433  }
1434 
1435  $text = $langs->trans('ConfirmValidateAsk', $numref);
1436  if (!empty($conf->notification->enabled)) {
1437  require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1438  $notify = new Notify($db);
1439  $text .= '<br>';
1440  $text .= $notify->confirmMessage('PROPOSAL_SUPPLIER_VALIDATE', $object->socid, $object);
1441  }
1442 
1443  if (!$error)
1444  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateAsk'), $text, 'confirm_validate', '', 0, 1);
1445  }
1446 
1447  // Call Hook formConfirm
1448  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
1449  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1450  if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
1451  elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
1452 
1453  // Print form confirm
1454  print $formconfirm;
1455 
1456 
1457  // Supplier proposal card
1458  $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1459 
1460 
1461  $morehtmlref = '<div class="refidno">';
1462  // Ref supplier
1463  //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', 0, 1);
1464  //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', null, null, '', 1);
1465  // Thirdparty
1466  $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
1467  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherProposals").'</a>)';
1468  // Project
1469  if (!empty($conf->projet->enabled))
1470  {
1471  $langs->load("projects");
1472  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
1473  if ($usercancreate)
1474  {
1475  if ($action != 'classify') {
1476  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
1477  }
1478  if ($action == 'classify') {
1479  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1480  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1481  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
1482  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
1483  $morehtmlref .= $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1484  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1485  $morehtmlref .= '</form>';
1486  } else {
1487  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1488  }
1489  } else {
1490  if (!empty($object->fk_project)) {
1491  $proj = new Project($db);
1492  $proj->fetch($object->fk_project);
1493  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
1494  $morehtmlref .= $proj->ref;
1495  $morehtmlref .= '</a>';
1496  } else {
1497  $morehtmlref .= '';
1498  }
1499  }
1500  }
1501  $morehtmlref .= '</div>';
1502 
1503 
1504  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1505 
1506 
1507  print '<div class="fichecenter">';
1508  print '<div class="fichehalfleft">';
1509  print '<div class="underbanner clearboth"></div>';
1510 
1511  print '<table class="border tableforfield" width="100%">';
1512 
1513  // Relative and absolute discounts
1514  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
1515  $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
1516  $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
1517  } else {
1518  $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
1519  $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
1520  }
1521 
1522  print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td>';
1523 
1524  $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
1525  $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote, 0, 1);
1526  $absolute_discount = price2num($absolute_discount, 'MT');
1527  $absolute_creditnote = price2num($absolute_creditnote, 'MT');
1528 
1529  $thirdparty = $soc;
1530  $discount_type = 1;
1531  $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
1532  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1533 
1534  print '</td></tr>';
1535 
1536  // Payment term
1537  print '<tr><td class="titlefield">';
1538  print '<table class="nobordernopadding" width="100%"><tr><td>';
1539  print $langs->trans('PaymentConditionsShort');
1540  print '</td>';
1541  if ($action != 'editconditions' && $object->statut != SupplierProposal::STATUS_NOTSIGNED)
1542  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'), 1).'</a></td>';
1543  print '</tr></table>';
1544  print '</td><td colspan="3">';
1545  if ($action == 'editconditions') {
1546  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
1547  } else {
1548  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1);
1549  }
1550  print '</td>';
1551  print '</tr>';
1552 
1553  // Delivery date
1554  $langs->load('deliveries');
1555  print '<tr><td>';
1556  print '<table class="nobordernopadding" width="100%"><tr><td>';
1557  print $langs->trans('DeliveryDate');
1558  print '</td>';
1559  if ($action != 'editdate_livraison' && $object->statut == SupplierProposal::STATUS_VALIDATED)
1560  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryDate'), 1).'</a></td>';
1561  print '</tr></table>';
1562  print '</td><td colspan="3">';
1563  if ($action == 'editdate_livraison') {
1564  print '<form name="editdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post" class="formconsumeproduce">';
1565  print '<input type="hidden" name="token" value="'.newToken().'">';
1566  print '<input type="hidden" name="action" value="setdate_livraison">';
1567  print $form->selectDate($object->delivery_date, 'liv_', '', '', '', "editdate_livraison");
1568  print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1569  print '</form>';
1570  } else {
1571  print dol_print_date($object->delivery_date, 'daytext');
1572  }
1573  print '</td>';
1574  print '</tr>';
1575 
1576  // Payment mode
1577  print '<tr>';
1578  print '<td>';
1579  print '<table class="nobordernopadding" width="100%"><tr><td>';
1580  print $langs->trans('PaymentMode');
1581  print '</td>';
1582  if ($action != 'editmode' && $object->statut != SupplierProposal::STATUS_NOTSIGNED)
1583  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'), 1).'</a></td>';
1584  print '</tr></table>';
1585  print '</td><td colspan="3">';
1586  if ($action == 'editmode') {
1587  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1);
1588  } else {
1589  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
1590  }
1591  print '</td></tr>';
1592 
1593  // Multicurrency
1594  if (!empty($conf->multicurrency->enabled))
1595  {
1596  // Multicurrency code
1597  print '<tr>';
1598  print '<td>';
1599  print '<table class="nobordernopadding" width="100%"><tr><td>';
1600  print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
1601  print '</td>';
1602  if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_VALIDATED)
1603  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencycode&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
1604  print '</tr></table>';
1605  print '</td><td colspan="3">';
1606  if ($action == 'editmulticurrencycode') {
1607  $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
1608  } else {
1609  $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
1610  }
1611  print '</td></tr>';
1612 
1613  // Multicurrency rate
1614  if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1)
1615  {
1616  print '<tr>';
1617  print '<td>';
1618  print '<table class="nobordernopadding" width="100%"><tr><td>';
1619  print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
1620  print '</td>';
1621  if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_VALIDATED && $object->multicurrency_code && $object->multicurrency_code != $conf->currency)
1622  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencyrate&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
1623  print '</tr></table>';
1624  print '</td><td colspan="3">';
1625  if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
1626  if ($action == 'actualizemulticurrencyrate') {
1627  list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
1628  }
1629  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
1630  } else {
1631  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
1632  if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1633  print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
1634  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
1635  print '</div>';
1636  }
1637  }
1638  print '</td></tr>';
1639  }
1640  }
1641 
1642  /* Not for supplier proposals
1643  if ($soc->outstanding_limit)
1644  {
1645  // Outstanding Bill
1646  print '<tr><td>';
1647  print $langs->trans('OutstandingBill');
1648  print '</td><td class=right colspan="3">';
1649  $arrayoutstandingbills = $soc->getOutstandingBills('supplier');
1650  $outstandingBills = $arrayoutstandingbills['opened'];
1651  print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency);
1652  print '</td>';
1653  print '</tr>';
1654  }*/
1655 
1656  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && !empty($conf->banque->enabled))
1657  {
1658  // Bank Account
1659  print '<tr><td>';
1660  print '<table width="100%" class="nobordernopadding"><tr><td>';
1661  print $langs->trans('BankAccount');
1662  print '</td>';
1663  if ($action != 'editbankaccount' && $usercancreate)
1664  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
1665  print '</tr></table>';
1666  print '</td><td colspan="3">';
1667  if ($action == 'editbankaccount') {
1668  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
1669  } else {
1670  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
1671  }
1672  print '</td>';
1673  print '</tr>';
1674  }
1675 
1676  // Other attributes
1677  $cols = 2;
1678  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1679 
1680  print '</table>';
1681 
1682  print '</div>';
1683  print '<div class="fichehalfright">';
1684  print '<div class="ficheaddleft">';
1685  print '<div class="underbanner clearboth"></div>';
1686 
1687  print '<table class="border tableforfield centpercent">';
1688 
1689  if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
1690  {
1691  // Multicurrency Amount HT
1692  print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';
1693  print '<td>'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
1694  print '</tr>';
1695 
1696  // Multicurrency Amount VAT
1697  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';
1698  print '<td>'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
1699  print '</tr>';
1700 
1701  // Multicurrency Amount TTC
1702  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';
1703  print '<td>'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
1704  print '</tr>';
1705  }
1706 
1707  // Amount HT
1708  print '<tr><td class="titlefieldmiddle">'.$langs->trans('AmountHT').'</td>';
1709  print '<td>'.price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1710  print '</tr>';
1711 
1712  // Amount VAT
1713  print '<tr><td>'.$langs->trans('AmountVAT').'</td>';
1714  print '<td>'.price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1715  print '</tr>';
1716 
1717  // Amount Local Taxes
1718  if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1
1719  {
1720  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
1721  print '<td class="nowrap">'.price($object->total_localtax1, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1722  print '</tr>';
1723  }
1724  if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) // Localtax2
1725  {
1726  print '<tr><td height="10">'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
1727  print '<td class="nowrap">'.price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1728  print '</tr>';
1729  }
1730 
1731  // Amount TTC
1732  print '<tr><td height="10">'.$langs->trans('AmountTTC').'</td>';
1733  print '<td class="nowrap">'.price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1734  print '</tr>';
1735 
1736  print '</table>';
1737 
1738  // Margin Infos
1739  /*if (! empty($conf->margin->enabled)) {
1740  $formmargin->displayMarginInfos($object);
1741  }*/
1742 
1743  print '</div>';
1744  print '</div>';
1745  print '</div>';
1746 
1747  print '<div class="clearboth"></div><br>';
1748 
1749  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
1750  $blocname = 'contacts';
1751  $title = $langs->trans('ContactsAddresses');
1752  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1753  }
1754 
1755  if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
1756  $blocname = 'notes';
1757  $title = $langs->trans('Notes');
1758  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1759  }
1760 
1761  /*
1762  * Lines
1763  */
1764 
1765  // Show object lines
1766  $result = $object->getLinesArray();
1767 
1768  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#add' : '#line_'.GETPOST('lineid')).'" method="POST">
1769  <input type="hidden" name="token" value="' . newToken().'">
1770  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
1771  <input type="hidden" name="mode" value="">
1772  <input type="hidden" name="id" value="' . $object->id.'">
1773  ';
1774 
1775  if (!empty($conf->use_javascript_ajax) && $object->statut == SupplierProposal::STATUS_DRAFT) {
1776  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
1777  }
1778 
1779  print '<div class="div-table-responsive-no-min">';
1780  print '<table id="tablelines" class="noborder noshadow" width="100%">';
1781 
1782  // Add free products/services form
1783  global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
1784  $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
1785  $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty.
1786  if (!empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY)) $senderissupplier = 1;
1787 
1788  if (!empty($object->lines))
1789  $ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, $dateSelector);
1790 
1791  // Form to add new line
1792  if ($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate)
1793  {
1794  if ($action != 'editline')
1795  {
1796  // Add products/services form
1797  $object->formAddObjectLine($dateSelector, $soc, $mysoc);
1798 
1799  $parameters = array();
1800  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1801  }
1802  }
1803 
1804  print '</table>';
1805  print '</div>';
1806  print "</form>\n";
1807 
1808  print dol_get_fiche_end();
1809 
1810  if ($action == 'statut')
1811  {
1812  // Form to set proposal accepted/refused
1813  $form_close = '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST" id="formacceptrefuse" class="formconsumeproduce">';
1814  $form_close .= '<input type="hidden" name="token" value="'.newToken().'">';
1815  $form_close .= '<input type="hidden" name="action" value="setstatut">';
1816 
1817  if (!empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL)) $form_close .= '<p class="notice">'.$langs->trans('SupplierProposalRefFournNotice').'</p>'; // TODO Suggest a permanent checkbox instead of option
1818  $form_close .= '<table class="border centpercent">';
1819  $form_close .= '<tr><td width="150" class="left">'.$langs->trans("CloseAs").'</td><td class="left">';
1820  $form_close .= '<select id="statut" name="statut" class="flat">';
1821  $form_close .= '<option value="0">&nbsp;</option>';
1822  $form_close .= '<option value="2">'.$langs->trans('SupplierProposalStatusSigned').'</option>';
1823  $form_close .= '<option value="3">'.$langs->trans('SupplierProposalStatusNotSigned').'</option>';
1824  $form_close .= '</select>';
1825  $form_close .= '</td></tr>';
1826  $form_close .= '<tr><td width="150" class="left">'.$langs->trans('Note').'</td><td class="left"><textarea cols="70" rows="'.ROWS_3.'" wrap="soft" name="note">';
1827  $form_close .= $object->note;
1828  $form_close .= '</textarea></td></tr>';
1829  $form_close .= '<tr><td class="center" colspan="2">';
1830  $form_close .= '<input type="submit" class="button button-save" name="validate" value="'.$langs->trans("Save").'">';
1831  $form_close .= ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1832  $form_close .= '<a name="acceptedrefused">&nbsp;</a>';
1833  $form_close .= '</td>';
1834  $form_close .= '</tr></table></form>';
1835 
1836  print $form_close;
1837  }
1838 
1839  /*
1840  * Boutons Actions
1841  */
1842  if ($action != 'presend') {
1843  print '<div class="tabsAction">';
1844 
1845  $parameters = array();
1846  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1847  // modified by hook
1848  if (empty($reshook))
1849  {
1850  if ($action != 'statut' && $action != 'editline')
1851  {
1852  // Validate
1853  if ($object->statut == SupplierProposal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0 && $usercanvalidate)
1854  {
1855  if (count($object->lines) > 0)
1856  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a></div>';
1857  // else print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Validate').'</a>';
1858  }
1859 
1860  // Edit
1861  if ($object->statut == SupplierProposal::STATUS_VALIDATED && $usercancreate) {
1862  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a></div>';
1863  }
1864 
1865  // ReOpen
1866  if (($object->statut == SupplierProposal::STATUS_SIGNED || $object->statut == SupplierProposal::STATUS_NOTSIGNED || $object->statut == SupplierProposal::STATUS_CLOSE) && $usercanclose) {
1867  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').'"';
1868  print '>'.$langs->trans('ReOpen').'</a></div>';
1869  }
1870 
1871  // Send
1872  if (empty($user->socid)) {
1873  if ($object->statut == SupplierProposal::STATUS_VALIDATED || $object->statut == SupplierProposal::STATUS_SIGNED) {
1874  if ($usercansend) {
1875  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
1876  } else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
1877  }
1878  }
1879 
1880  // Create an order
1881  if (!empty($conf->fournisseur->enabled) && $object->statut == SupplierProposal::STATUS_SIGNED) {
1882  if ($usercancreateorder) {
1883  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddOrder").'</a></div>';
1884  }
1885  }
1886 
1887  // Set accepted/refused
1888  if ($object->statut == SupplierProposal::STATUS_VALIDATED && $usercanclose) {
1889  print '<div class="inline-block divButAction"><a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=statut'.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#acceptedrefused').'"';
1890  print '>'.$langs->trans('SetAcceptedRefused').'</a></div>';
1891  }
1892 
1893  // Close
1894  if ($object->statut == SupplierProposal::STATUS_SIGNED && $usercanclose) {
1895  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=close'.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#close').'"';
1896  print '>'.$langs->trans('Close').'</a></div>';
1897  }
1898 
1899  // Clone
1900  if ($usercancreate) {
1901  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>';
1902  }
1903 
1904  // Delete
1905  if (($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) || $usercandelete) {
1906  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'"';
1907  print '>'.$langs->trans('Delete').'</a></div>';
1908  }
1909  }
1910  }
1911 
1912  print '</div>';
1913  }
1914 
1915  if ($action != 'presend')
1916  {
1917  print '<div class="fichecenter"><div class="fichehalfleft">';
1918 
1919  /*
1920  * Documents generes
1921  */
1922  $filename = dol_sanitizeFileName($object->ref);
1923  $filedir = $conf->supplier_proposal->dir_output."/".dol_sanitizeFileName($object->ref);
1924  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1925  $genallowed = $usercanread;
1926  $delallowed = $usercancreate;
1927 
1928  print $formfile->showdocuments('supplier_proposal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang);
1929 
1930 
1931  // Show links to link elements
1932  $linktoelem = $form->showLinkToObjectBlock($object, null, array('supplier_proposal'));
1933  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1934 
1935 
1936  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
1937 
1938  // List of actions on element
1939  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1940  $formactions = new FormActions($db);
1941  $somethingshown = $formactions->showactions($object, 'supplier_proposal', $socid, 1);
1942 
1943  print '</div></div></div>';
1944  }
1945 
1946  // Select mail models is same action as presend
1947  if (GETPOST('modelselected')) {
1948  $action = 'presend';
1949  }
1950 
1951  // Presend form
1952  $modelmail = 'supplier_proposal_send';
1953  $defaulttopic = 'SendAskRef';
1954  $diroutput = $conf->supplier_proposal->dir_output;
1955  $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
1956  $trackid = 'spro'.$object->id;
1957 
1958  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1959 }
1960 
1961 // End of page
1962 llxFooter();
1963 $db->close();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage notifications.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
const STATUS_NOTSIGNED
Not signed quote, canceled.
Class to manage building of HTML components.
static getIdAndTxFromCode($db, $code, $date_document= '')
Get id and rate of currency from code.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
const STATUS_CLOSE
Billed or closed/processed quote.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
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.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
const STATUS_SIGNED
Signed quote.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Classe permettant la generation de composants html autre Only common components are here...
Class to manage building of HTML components.
const STATUS_VALIDATED
Validated status.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const STATUS_DRAFT
Draft status.
Class to manage price ask supplier.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 ...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
Class to manage predefined suppliers products.