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