dolibarr  16.0.5
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  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
429  $error++;
430  }
431  } else {
432  setEventMessages($srcobject->error, $srcobject->errors, 'errors');
433  $error++;
434  }
435  } else {
436  setEventMessages($object->error, $object->errors, 'errors');
437  $error++;
438  }
439  } else {
440  // Standard creation
441  $id = $object->create($user);
442  }
443 
444  if ($id > 0) {
445  if (!$error) {
446  $db->commit();
447 
448  // Define output language
449  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
450  $outputlangs = $langs;
451  $newlang = '';
452  if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
453  $newlang = GETPOST('lang_id', 'aZ09');
454  }
455  if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
456  $newlang = $object->thirdparty->default_lang;
457  }
458  if (!empty($newlang)) {
459  $outputlangs = new Translate("", $conf);
460  $outputlangs->setDefaultLang($newlang);
461  }
462  $model = $object->model_pdf;
463 
464  $ret = $object->fetch($id); // Reload to get new records
465  $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
466  if ($result < 0) {
467  dol_print_error($db, $result);
468  }
469  }
470 
471  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
472  exit();
473  } else {
474  $db->rollback();
475  $action = 'create';
476  }
477  } else {
478  setEventMessages($object->error, $object->errors, 'errors');
479  $db->rollback();
480  $action = 'create';
481  }
482  }
483  }
484  } elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) {
485  // Reopen proposal
486  // prevent browser refresh from reopening proposal several times
487  if ($object->statut == SupplierProposal::STATUS_SIGNED || $object->statut == SupplierProposal::STATUS_NOTSIGNED || $object->statut == SupplierProposal::STATUS_CLOSE) {
488  $object->reopen($user, SupplierProposal::STATUS_VALIDATED);
489  }
490  } elseif ($action == 'close' && $usercanclose && !GETPOST('cancel', 'alpha')) {
491  // Close proposal
492  // prevent browser refresh from reopening proposal several times
493  if ($object->statut == SupplierProposal::STATUS_SIGNED) {
494  $object->setStatut(SupplierProposal::STATUS_CLOSE);
495  }
496  } elseif ($action == 'setstatut' && $usercanclose && !GETPOST('cancel', 'alpha')) {
497  // Set accepted/refused
498  if (!GETPOST('statut')) {
499  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("CloseAs")), null, 'errors');
500  $action = 'statut';
501  } else {
502  // prevent browser refresh from closing proposal several times
503  if ($object->statut == SupplierProposal::STATUS_VALIDATED) {
504  $object->cloture($user, GETPOST('statut'), GETPOST('note', 'restricthtml'));
505  }
506  }
507  }
508 
509  // Actions when printing a doc from card
510  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
511 
512  // Actions to send emails
513  $triggersendname = 'PROPOSAL_SUPPLIER_SENTBYMAIL';
514  $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
515  $trackid = 'spro'.$object->id;
516  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
517 
518  // Actions to build doc
519  $upload_dir = $conf->supplier_proposal->dir_output;
520  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
521 
522 
523  // Go back to draft
524  if ($action == 'modif' && $usercancreate) {
525  $object->setDraft($user);
526 
527  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
528  // Define output language
529  $outputlangs = $langs;
530  if (!empty($conf->global->MAIN_MULTILANGS)) {
531  $outputlangs = new Translate("", $conf);
532  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
533  $outputlangs->setDefaultLang($newlang);
534  }
535  $ret = $object->fetch($id); // Reload to get new records
536  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
537  }
538  } elseif ($action == "setabsolutediscount" && $usercancreate) {
539  if (GETPOST("remise_id", 'int')) {
540  if ($object->id > 0) {
541  $result = $object->insert_discount(GETPOST("remise_id", 'int'));
542  if ($result < 0) {
543  setEventMessages($object->error, $object->errors, 'errors');
544  }
545  }
546  }
547  }
548 
549  // Add a product line
550  if ($action == 'addline' && $usercancreate) {
551  $langs->load('errors');
552  $error = 0;
553 
554  // Set if we used free entry or predefined product
555  $predef = '';
556  $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
557  $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'));
558  $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'));
559 
560  $ref_supplier = GETPOST('fourn_ref', 'alpha');
561 
562  $prod_entry_mode = GETPOST('prod_entry_mode');
563  if ($prod_entry_mode == 'free') {
564  $idprod = 0;
565  } else {
566  $idprod = GETPOST('idprod', 'int');
567  }
568 
569  $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)'
570 
571  $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
572  $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
573  $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
574  $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
575  $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
576 
577  $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
578  if (empty($remise_percent)) {
579  $remise_percent = 0;
580  }
581 
582  // Extrafields
583  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
584  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
585  // Unset extrafield
586  if (is_array($extralabelsline)) {
587  // Get extra fields
588  foreach ($extralabelsline as $key => $value) {
589  unset($_POST["options_".$key]);
590  }
591  }
592 
593  if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) {
594  setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
595  $error++;
596  }
597  if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
598  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
599  $error++;
600  }
601 
602  if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && GETPOST('multicurrency_price_ht') === '') { // Unit price can be 0 but not ''. Also price can be negative for proposal.
603  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPrice")), null, 'errors');
604  $error++;
605  }
606  if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
607  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
608  $error++;
609  }
610  if (!$error && ($qty >= 0)) {
611  $pu_ht = price2num($price_ht, 'MU');
612  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
613  $price_min = 0;
614  $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
615 
616  $db->begin();
617 
618  if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
619  $productsupplier = new ProductFournisseur($db);
620 
621  $idprod = 0;
622  if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') {
623  $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, ...)
624  }
625 
626  $reg = array();
627  if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) {
628  $idprod = $reg[1];
629  $res = $productsupplier->fetch($idprod); // Load product from its id
630  // Call to init some price properties of $productsupplier
631  // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
632  if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
633  $fksoctosearch = 0;
634  $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
635  if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price
636  $productsupplier->ref_supplier = '';
637  }
638  } else {
639  $fksoctosearch = $object->thirdparty->id;
640  $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
641  }
642  } elseif (GETPOST('idprodfournprice', 'alpha') > 0) {
643  //$qtytosearch=$qty; // Just to see if a price exists for the quantity. Not used to found vat.
644  $qtytosearch = -1; // We force qty to -1 to be sure to find if the supplier price that exists
645  $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch);
646  $res = $productsupplier->fetch($idprod);
647  }
648 
649  if ($idprod > 0) {
650  $label = $productsupplier->label;
651 
652  // Define output language
653  if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
654  $outputlangs = $langs;
655  $newlang = '';
656  if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
657  $newlang = GETPOST('lang_id', 'aZ09');
658  }
659  if (empty($newlang)) {
660  $newlang = $object->thirdparty->default_lang;
661  }
662  if (!empty($newlang)) {
663  $outputlangs = new Translate("", $conf);
664  $outputlangs->setDefaultLang($newlang);
665  }
666  $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description;
667  } else {
668  $desc = $productsupplier->description;
669  }
670  // if we use supplier description of the products
671  if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
672  $desc = $productsupplier->desc_supplier;
673  }
674 
675  //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time
676  if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
677  $product_desc='';
678  }
679 
680  if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
681  $desc = $product_desc;
682  }
683  if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
684  $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
685  }
686 
687  $ref_supplier = $productsupplier->ref_supplier;
688 
689  // Get vat rate
690  $tva_npr = 0;
691  if (!GETPOSTISSET('tva_tx')) { // If vat rate not provided from the form (the form has the priority)
692  $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
693  $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
694  }
695  if (empty($tva_tx)) {
696  $tva_npr = 0;
697  }
698  $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
699  $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
700 
701  $type = $productsupplier->type;
702  if (GETPOST('price_ht') != '' || GETPOST('price_ht_devise') != '') {
703  $price_base_type = 'HT';
704  $pu = price2num($price_ht, 'MU');
705  $pu_devise = price2num($price_ht_devise, 'CU');
706  } elseif (GETPOST('price_ttc') != '' || GETPOST('price_ttc_devise') != '') {
707  $price_base_type = 'TTC';
708  $pu = price2num($price_ttc, 'MU');
709  $pu_devise = price2num($price_ttc_devise, 'CU');
710  } else {
711  $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
712  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
713  $pu = $productsupplier->fourn_pu;
714  $pu_devise = 0;
715  } else {
716  $pu = $productsupplier->fourn_pu;
717  $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
718  }
719  }
720 
721  if (empty($pu)) {
722  $pu = 0; // If pu is '' or null, we force to have a numeric value
723  }
724 
725  // 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)
726  $fournprice = (is_numeric(GETPOST('idprodfournprice', 'alpha')) ? GETPOST('idprodfournprice', 'alpha') : -1);
727  $buyingprice = 0;
728 
729  $result = $object->addline(
730  $desc,
731  ($price_base_type == 'HT' ? $pu : 0),
732  $qty,
733  $tva_tx,
734  $localtax1_tx,
735  $localtax2_tx,
736  $productsupplier->id,
737  $remise_percent,
738  $price_base_type,
739  ($price_base_type == 'TTC' ? $pu : 0),
740  $tva_npr,
741  $type,
742  min($rank, count($object->lines) + 1),
743  0,
744  GETPOST('fk_parent_line'),
745  $fournprice,
746  $buyingprice,
747  $label,
748  $array_options,
749  $ref_supplier,
750  $productsupplier->fk_unit,
751  '',
752  0,
753  $pu_devise,
754  $date_start,
755  $date_end
756  );
757 
758  //var_dump($tva_tx);
759  //var_dump($productsupplier->fourn_pu);
760  //var_dump($price_base_type);exit;
761  if ($result < 0) {
762  $error++;
763  setEventMessages($object->error, $object->errors, 'errors');
764  }
765  }
766  if ($idprod == -99 || $idprod == 0) {
767  // Product not selected
768  $error++;
769  $langs->load("errors");
770  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")).' '.$langs->trans("or").' '.$langs->trans("NoPriceDefinedForThisSupplier"), null, 'errors');
771  }
772  if ($idprod == -1) {
773  // Quantity too low
774  $error++;
775  $langs->load("errors");
776  setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors');
777  }
778  } elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '' || GETPOST('multicurrency_price_ht') != '') && empty($error)) { // Free product. // $price_ht is already set
779  $pu_ht = price2num($price_ht, 'MU');
780  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
781 
782  $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
783  $tva_tx = str_replace('*', '', $tva_tx);
784  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
785  $desc = $product_desc;
786  $type = GETPOST('type');
787 
788  $fk_unit = GETPOST('units', 'alpha');
789 
790  if (!preg_match('/\((.*)\)/', $tva_tx)) {
791  $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'
792  }
793 
794  // Local Taxes
795  $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
796  $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
797 
798  if (GETPOST('price_ht') != '' || GETPOST('price_ht_devise') != '') {
799  $pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
800  } else {
801  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
802  $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
803  }
804  $price_base_type = 'HT';
805  $pu_ht_devise = price2num($price_ht_devise, 'CU');
806  $info_bits = 0;
807 
808  $result = $object->addline(
809  $desc,
810  $pu_ht,
811  $qty,
812  $tva_tx,
813  $localtax1_tx,
814  $localtax2_tx,
815  $idprod,
816  $remise_percent,
817  $price_base_type,
818  $pu_ttc,
819  $info_bits,
820  $type,
821  -1, // rang
822  0, // special_code
823  GETPOST('fk_parent_line'),
824  $fournprice,
825  $buyingprice,
826  $label,
827  $array_options,
828  $ref_supplier,
829  $fk_unit,
830  '', // origin
831  0, // origin_id
832  $pu_ht_devise
833  );
834  }
835 
836 
837  if (!$error && $result > 0) {
838  $db->commit();
839 
840  $ret = $object->fetch($object->id); // Reload to get new records
841 
842  // Define output language
843  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
844  $outputlangs = $langs;
845  $newlang = '';
846  if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
847  $newlang = GETPOST('lang_id', 'aZ09');
848  }
849  if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
850  $newlang = $object->thirdparty->default_lang;
851  }
852  if (!empty($newlang)) {
853  $outputlangs = new Translate("", $conf);
854  $outputlangs->setDefaultLang($newlang);
855  }
856  $model = $object->model_pdf;
857  $ret = $object->fetch($id); // Reload to get new records
858 
859  $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
860  if ($result < 0) {
861  dol_print_error($db, $result);
862  }
863  }
864 
865  unset($_POST['prod_entry_mode']);
866 
867  unset($_POST['qty']);
868  unset($_POST['type']);
869  unset($_POST['remise_percent']);
870  unset($_POST['pu']);
871  unset($_POST['price_ht']);
872  unset($_POST['multicurrency_price_ht']);
873  unset($_POST['price_ttc']);
874  unset($_POST['fourn_ref']);
875  unset($_POST['tva_tx']);
876  unset($_POST['label']);
877  unset($_POST['product_ref']);
878  unset($_POST['product_label']);
879  unset($_POST['product_desc']);
880  unset($_POST['fournprice']);
881  unset($_POST['buying_price']);
882  unset($localtax1_tx);
883  unset($localtax2_tx);
884  unset($_POST['np_marginRate']);
885  unset($_POST['np_markRate']);
886  unset($_POST['dp_desc']);
887  unset($_POST['idprodfournprice']);
888  unset($_POST['units']);
889 
890  unset($_POST['idprod']);
891 
892  unset($_POST['date_starthour']);
893  unset($_POST['date_startmin']);
894  unset($_POST['date_startsec']);
895  unset($_POST['date_startday']);
896  unset($_POST['date_startmonth']);
897  unset($_POST['date_startyear']);
898  unset($_POST['date_endhour']);
899  unset($_POST['date_endmin']);
900  unset($_POST['date_endsec']);
901  unset($_POST['date_endday']);
902  unset($_POST['date_endmonth']);
903  unset($_POST['date_endyear']);
904  } else {
905  $db->rollback();
906 
907  setEventMessages($object->error, $object->errors, 'errors');
908  }
909  }
910  } elseif ($action == 'updateline' && $usercancreate && GETPOST('save') == $langs->trans("Save")) {
911  // Mise a jour d'une ligne dans la demande de prix
912  $vat_rate = (GETPOST('tva_tx') ?GETPOST('tva_tx') : 0);
913 
914  // Define info_bits
915  $info_bits = 0;
916  if (preg_match('/\*/', $vat_rate)) {
917  $info_bits |= 0x01;
918  }
919 
920  // Clean parameters
921  $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
922 
923  // Define vat_rate
924  $vat_rate = str_replace('*', '', $vat_rate);
925  $localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
926  $localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
927 
928  if (GETPOST('price_ht') != '') {
929  $price_base_type = 'HT';
930  $ht = price2num(GETPOST('price_ht'), '', 2);
931  } else {
932  $reg = array();
933  $vatratecleaned = $vat_rate;
934  if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) { // If vat is "xx (yy)"
935  $vatratecleaned = trim($reg[1]);
936  $vatratecode = $reg[2];
937  }
938 
939  $ttc = price2num(GETPOST('price_ttc'), '', 2);
940  $ht = $ttc / (1 + ($vatratecleaned / 100));
941  $price_base_type = 'HT';
942  }
943 
944  $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), 'CU', 2);
945 
946  // Add buying price
947  $fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
948  $buyingprice = (GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
949 
950  // Extrafields Lines
951  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
952  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
953  // Unset extrafield POST Data
954  if (is_array($extralabelsline)) {
955  foreach ($extralabelsline as $key => $value) {
956  unset($_POST["options_".$key]);
957  }
958  }
959 
960  // Define special_code for special lines
961  $special_code = GETPOST('special_code');
962  if (!GETPOST('qty')) {
963  $special_code = 3;
964  }
965 
966  // Check minimum price
967  $productid = GETPOST('productid', 'int');
968  if (!empty($productid)) {
969  $productsupplier = new ProductFournisseur($db);
970  if (!empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY)) {
971  if ($productid > 0 && $productsupplier->get_buyprice(0, price2num(GETPOST('qty')), $productid, 'none', GETPOST('socid', 'int')) < 0) {
972  setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'warnings');
973  }
974  }
975 
976  $product = new Product($db);
977  $res = $product->fetch($productid);
978 
979  $type = $product->type;
980 
981  $price_min = $product->price_min;
982  if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
983  $price_min = $product->multiprices_min [$object->thirdparty->price_level];
984  }
985 
986  $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
987  } else {
988  $type = GETPOST('type');
989  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
990 
991  // Check parameters
992  if (GETPOST('type') < 0) {
993  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
994  $error++;
995  }
996  }
997 
998  if (!$error) {
999  $db->begin();
1000 
1001  $ref_supplier = GETPOST('fourn_ref', 'alpha');
1002  $fk_unit = GETPOST('units');
1003 
1004  $result = $object->updateline(
1005  GETPOST('lineid', 'int'),
1006  $ht,
1007  price2num(GETPOST('qty'), 'MS', 2),
1008  price2num(GETPOST('remise_percent'), '', 2),
1009  $vat_rate,
1010  $localtax1_rate,
1011  $localtax2_rate,
1012  $description,
1013  $price_base_type,
1014  $info_bits,
1015  $special_code,
1016  GETPOST('fk_parent_line', 'int'),
1017  0,
1018  $fournprice,
1019  $buyingprice,
1020  $label,
1021  $type,
1022  $array_options,
1023  $ref_supplier,
1024  $fk_unit,
1025  $pu_ht_devise
1026  );
1027 
1028  if ($result >= 0) {
1029  $db->commit();
1030 
1031  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1032  // Define output language
1033  $outputlangs = $langs;
1034  if (!empty($conf->global->MAIN_MULTILANGS)) {
1035  $outputlangs = new Translate("", $conf);
1036  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
1037  $outputlangs->setDefaultLang($newlang);
1038  }
1039  $ret = $object->fetch($id); // Reload to get new records
1040  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1041  }
1042 
1043  unset($_POST['qty']);
1044  unset($_POST['type']);
1045  unset($_POST['productid']);
1046  unset($_POST['remise_percent']);
1047  unset($_POST['price_ht']);
1048  unset($_POST['multicurrency_price_ht']);
1049  unset($_POST['price_ttc']);
1050  unset($_POST['tva_tx']);
1051  unset($_POST['product_ref']);
1052  unset($_POST['product_label']);
1053  unset($_POST['product_desc']);
1054  unset($_POST['fournprice']);
1055  unset($_POST['buying_price']);
1056 
1057  unset($_POST['date_starthour']);
1058  unset($_POST['date_startmin']);
1059  unset($_POST['date_startsec']);
1060  unset($_POST['date_startday']);
1061  unset($_POST['date_startmonth']);
1062  unset($_POST['date_startyear']);
1063  unset($_POST['date_endhour']);
1064  unset($_POST['date_endmin']);
1065  unset($_POST['date_endsec']);
1066  unset($_POST['date_endday']);
1067  unset($_POST['date_endmonth']);
1068  unset($_POST['date_endyear']);
1069  } else {
1070  $db->rollback();
1071 
1072  setEventMessages($object->error, $object->errors, 'errors');
1073  }
1074  }
1075  } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
1076  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
1077  exit();
1078  } elseif ($action == 'classin' && $usercancreate) {
1079  // Set project
1080  $object->setProject(GETPOST('projectid'), 'int');
1081  } elseif ($action == 'setavailability' && $usercancreate) {
1082  // Delivery delay
1083  $result = $object->availability(GETPOST('availability_id'));
1084  } elseif ($action == 'setconditions' && $usercancreate) {
1085  // Terms of payments
1086  $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
1087  } elseif ($action == 'setremisepercent' && $usercancreate) {
1088  $result = $object->set_remise_percent($user, price2num(GETPOST('remise_percent'), '', 2));
1089  } elseif ($action == 'setremiseabsolue' && $usercancreate) {
1090  $result = $object->set_remise_absolue($user, price2num(GETPOST('remise_absolue'), 'MU', 2));
1091  } elseif ($action == 'setmode' && $usercancreate) {
1092  // Payment mode
1093  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
1094  } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
1095  // Multicurrency Code
1096  $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
1097  } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
1098  // Multicurrency rate
1099  $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int'));
1100  } elseif ($action == 'update_extras') {
1101  $object->oldcopy = dol_clone($object);
1102 
1103  // Fill array 'array_options' with data from update form
1104  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
1105  if ($ret < 0) {
1106  $error++;
1107  }
1108 
1109  if (!$error) {
1110  $result = $object->insertExtraFields('PROPOSAL_SUPPLIER_MODIFY');
1111  if ($result < 0) {
1112  setEventMessages($object->error, $object->errors, 'errors');
1113  $error++;
1114  }
1115  }
1116 
1117  if ($error) {
1118  $action = 'edit_extras';
1119  }
1120  }
1121 }
1122 
1123 
1124 /*
1125  * View
1126  */
1127 $title = $langs->trans('CommRequest')." - ".$langs->trans('Card');
1128 $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
1129 llxHeader('', $title, $help_url);
1130 
1131 $form = new Form($db);
1132 $formother = new FormOther($db);
1133 $formfile = new FormFile($db);
1134 $formmargin = new FormMargin($db);
1135 $companystatic = new Societe($db);
1136 if (!empty($conf->project->enabled)) {
1137  $formproject = new FormProjets($db);
1138 }
1139 
1140 $now = dol_now();
1141 
1142 // Add new askprice
1143 if ($action == 'create') {
1144  $currency_code = $conf->currency;
1145 
1146  print load_fiche_titre($langs->trans("NewAskPrice"), '', 'supplier_proposal');
1147 
1148  $soc = new Societe($db);
1149  if ($socid > 0) {
1150  $res = $soc->fetch($socid);
1151  }
1152 
1153  // Load objectsrc
1154  if (!empty($origin) && !empty($originid)) {
1155  $element = $subelement = GETPOST('origin');
1156  if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs)) {
1157  $element = $regs[1];
1158  $subelement = $regs[2];
1159  }
1160 
1161  // For compatibility
1162  if ($element == 'order' || $element == 'commande') {
1163  $element = $subelement = 'commande';
1164  }
1165  if ($element == 'propal') {
1166  $element = 'comm/propal';
1167  $subelement = 'propal';
1168  }
1169 
1170  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1171 
1172  $classname = ucfirst($subelement);
1173  $objectsrc = new $classname($db);
1174  $objectsrc->fetch($originid);
1175  if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1176  $objectsrc->fetch_lines();
1177  }
1178  $objectsrc->fetch_thirdparty();
1179 
1180  $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
1181  $soc = $objectsrc->thirdparty;
1182 
1183  $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
1184  $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1185  $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
1186  $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1187 
1188  // Replicate extrafields
1189  $objectsrc->fetch_optionals();
1190  $object->array_options = $objectsrc->array_options;
1191 
1192  if (!empty($conf->multicurrency->enabled)) {
1193  if (!empty($objectsrc->multicurrency_code)) {
1194  $currency_code = $objectsrc->multicurrency_code;
1195  }
1196  if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1197  $currency_tx = $objectsrc->multicurrency_tx;
1198  }
1199  }
1200  } else {
1201  $cond_reglement_id = $soc->cond_reglement_supplier_id;
1202  $mode_reglement_id = $soc->mode_reglement_supplier_id;
1203  if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) {
1204  $currency_code = $soc->multicurrency_code;
1205  }
1206  }
1207 
1208  $object = new SupplierProposal($db);
1209 
1210  print '<form name="addprop" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1211  print '<input type="hidden" name="token" value="'.newToken().'">';
1212  print '<input type="hidden" name="action" value="add">';
1213  if ($origin != 'project' && $originid) {
1214  print '<input type="hidden" name="origin" value="'.$origin.'">';
1215  print '<input type="hidden" name="originid" value="'.$originid.'">';
1216  }
1217 
1218  print dol_get_fiche_head();
1219 
1220  print '<table class="border centpercent">';
1221 
1222  // Reference
1223  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
1224 
1225  // Third party
1226  print '<tr>';
1227  print '<td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
1228  if ($socid > 0) {
1229  print '<td colspan="2">';
1230  print $soc->getNomUrl(1, 'supplier');
1231  print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1232  print '</td>';
1233  } else {
1234  print '<td colspan="2">';
1235  print img_picto('', 'company').$form->select_company('', 'socid', 's.fournisseur=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300');
1236  // reload page to retrieve customer informations
1237  if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE)) {
1238  print '<script>
1239  $(document).ready(function() {
1240  $("#socid").change(function() {
1241  var socid = $(this).val();
1242  // reload page
1243  window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid;
1244  });
1245  });
1246  </script>';
1247  }
1248  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>';
1249  print '</td>';
1250  }
1251  print '</tr>'."\n";
1252 
1253  if ($soc->id > 0) {
1254  // Discounts for third party
1255  print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
1256 
1257  $absolute_discount = $soc->getAvailableDiscounts('', '', 0, 1);
1258 
1259  $thirdparty = $soc;
1260  $discount_type = 1;
1261  $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
1262  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1263 
1264  print '</td></tr>';
1265  }
1266 
1267  // Terms of payment
1268  print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
1269  $form->select_conditions_paiements(GETPOST('cond_reglement_id') > 0 ? GETPOST('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id', -1, 1);
1270  print '</td></tr>';
1271 
1272  // Mode of payment
1273  print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
1274  $form->select_types_paiements(GETPOST('mode_reglement_id') > 0 ? GETPOST('mode_reglement_id') : $mode_reglement_id, 'mode_reglement_id');
1275  print '</td></tr>';
1276 
1277  // Bank Account
1278  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && !empty($conf->banque->enabled)) {
1279  print '<tr><td>'.$langs->trans('BankAccount').'</td><td colspan="2">';
1280  $form->select_comptes(GETPOST('fk_account') > 0 ? GETPOST('fk_account', 'int') : $fk_account, 'fk_account', 0, '', 1);
1281  print '</td></tr>';
1282  }
1283 
1284  // Shipping Method
1285  if (!empty($conf->expedition->enabled)) {
1286  print '<tr><td>'.$langs->trans('SendingMethod').'</td><td colspan="2">';
1287  print $form->selectShippingMethod(GETPOST('shipping_method_id') > 0 ? GETPOST('shipping_method_id', 'int') : "", 'shipping_method_id', '', 1);
1288  print '</td></tr>';
1289  }
1290 
1291  // Delivery date (or manufacturing)
1292  print '<tr><td>'.$langs->trans("DeliveryDate").'</td>';
1293  print '<td colspan="2">';
1294  $datedelivery = dol_mktime(0, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
1295  if (!empty($conf->global->DATE_LIVRAISON_WEEK_DELAY)) {
1296  $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
1297  $syear = date("Y", $tmpdte);
1298  $smonth = date("m", $tmpdte);
1299  $sday = date("d", $tmpdte);
1300  print $form->selectDate($syear."-".$smonth."-".$sday, 'liv_', '', '', '', "addask");
1301  } else {
1302  print $form->selectDate($datedelivery ? $datedelivery : -1, 'liv_', '', '', '', "addask", 1, 1);
1303  }
1304  print '</td></tr>';
1305 
1306 
1307  // Model
1308  print '<tr>';
1309  print '<td>'.$langs->trans("DefaultModel").'</td>';
1310  print '<td colspan="2">';
1312  $preselected = (!empty($conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT) ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT : $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF);
1313  print $form->selectarray('model', $list, $preselected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
1314  print "</td></tr>";
1315 
1316  // Project
1317  if (!empty($conf->project->enabled)) {
1318  $langs->load("projects");
1319 
1320  $formproject = new FormProjets($db);
1321 
1322  if ($origin == 'project') {
1323  $projectid = ($originid ? $originid : 0);
1324  }
1325 
1326  print '<tr>';
1327  print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
1328  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');
1329  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>';
1330 
1331  print '</td>';
1332  print '</tr>';
1333  }
1334 
1335  // Multicurrency
1336  if (!empty($conf->multicurrency->enabled)) {
1337  print '<tr>';
1338  print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1339  print '<td colspan="3" class="maxwidthonsmartphone">';
1340  print $form->selectMultiCurrency($currency_code, 'multicurrency_code');
1341  print '</td></tr>';
1342  }
1343 
1344  // Other attributes
1345  $parameters = array('colspan' => ' colspan="3"', 'cols' => 3);
1346  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1347  print $hookmanager->resPrint;
1348  if (empty($reshook)) {
1349  print $object->showOptionals($extrafields, 'create', $parameters);
1350  }
1351 
1352 
1353  // Lines from source
1354  if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1355  // TODO for compatibility
1356  if ($origin == 'contrat') {
1357  // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
1358  $objectsrc->remise_absolue = $remise_absolue;
1359  $objectsrc->remise_percent = $remise_percent;
1360  $objectsrc->update_price(1, - 1, 1);
1361  }
1362 
1363  print "\n<!-- ".$classname." info -->";
1364  print "\n";
1365  print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
1366  print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
1367  print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
1368  print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1369  print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1370 
1371  print '<tr><td>'.$langs->trans('CommRequest').'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
1372  print '<tr><td>'.$langs->trans('AmountHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
1373  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
1374  if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1
1375  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
1376  }
1377 
1378  if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2
1379  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
1380  }
1381  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
1382 
1383  if (!empty($conf->multicurrency->enabled)) {
1384  print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
1385  print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_tva)."</td></tr>";
1386  print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ttc)."</td></tr>";
1387  }
1388  }
1389 
1390  print "</table>\n";
1391 
1392 
1393  /*
1394  * Combobox pour la fonction de copie
1395  */
1396 
1397  if (empty($conf->global->SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE)) {
1398  print '<input type="hidden" name="createmode" value="empty">';
1399  }
1400 
1401  if (!empty($conf->global->SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE)) {
1402  print '<br><table>';
1403 
1404  // For backward compatibility
1405  print '<tr>';
1406  print '<td><input type="radio" name="createmode" value="copy"></td>';
1407  print '<td>'.$langs->trans("CopyAskFrom").' </td>';
1408  print '<td>';
1409  $liste_ask = array();
1410  $liste_ask [0] = '';
1411 
1412  $sql = "SELECT p.rowid as id, p.ref, s.nom";
1413  $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal p";
1414  $sql .= ", ".MAIN_DB_PREFIX."societe s";
1415  $sql .= " WHERE s.rowid = p.fk_soc";
1416  $sql .= " AND p.entity = ".$conf->entity;
1417  $sql .= " AND p.fk_statut <> ".SupplierProposal::STATUS_DRAFT;
1418  $sql .= " ORDER BY Id";
1419 
1420  $resql = $db->query($sql);
1421  if ($resql) {
1422  $num = $db->num_rows($resql);
1423  $i = 0;
1424  while ($i < $num) {
1425  $row = $db->fetch_row($resql);
1426  $askPriceSupplierRefAndSocName = $row [1]." - ".$row [2];
1427  $liste_ask [$row [0]] = $askPriceSupplierRefAndSocName;
1428  $i++;
1429  }
1430  print $form->selectarray("copie_supplier_proposal", $liste_ask, 0);
1431  } else {
1432  dol_print_error($db);
1433  }
1434  print '</td></tr>';
1435 
1436  print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
1437  print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyAsk").'</td></tr>';
1438  }
1439 
1440  if (!empty($conf->global->SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE)) {
1441  print '</table>';
1442  }
1443 
1444  print dol_get_fiche_end();
1445 
1446  print $form->buttonsSaveCancel("CreateDraft");
1447 
1448  print "</form>";
1449 
1450 
1451  // Show origin lines
1452  if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1453  print '<br>';
1454 
1455  $title = $langs->trans('ProductsAndServices');
1456  print load_fiche_titre($title);
1457 
1458  print '<div class="div-table-responsive-no-min">';
1459  print '<table class="noborder centpercent">';
1460 
1461  $objectsrc->printOriginLinesList();
1462 
1463  print '</table>';
1464  print '</div>';
1465  }
1466 } else {
1467  /*
1468  * Show object in view mode
1469  */
1470 
1471  $soc = new Societe($db);
1472  $soc->fetch($object->socid);
1473 
1474  $head = supplier_proposal_prepare_head($object);
1475  print dol_get_fiche_head($head, 'comm', $langs->trans('CommRequest'), -1, 'supplier_proposal');
1476 
1477  $formconfirm = '';
1478 
1479  // Clone confirmation
1480  if ($action == 'clone') {
1481  // Create an array for form
1482  $formquestion = array(
1483  // 'text' => $langs->trans("ConfirmClone"),
1484  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
1485  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' =>
1486  // 1),
1487  array(
1488  'type' => 'other',
1489  'name' => 'socid',
1490  'label' => $langs->trans("SelectThirdParty"),
1491  'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', 's.fournisseur=1'))
1492  );
1493  // Paiement incomplet. On demande si motif = escompte ou autre
1494  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1495  } elseif ($action == 'delete') {
1496  // Confirm delete
1497  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAsk'), $langs->trans('ConfirmDeleteAsk', $object->ref), 'confirm_delete', '', 0, 1);
1498  } elseif ($action == 'reopen') {
1499  // Confirm reopen
1500  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenAsk', $object->ref), 'confirm_reopen', '', 0, 1);
1501  } elseif ($action == 'ask_deleteline') {
1502  // Confirmation delete product/service line
1503  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
1504  } elseif ($action == 'validate') {
1505  // Confirm validate askprice
1506  $error = 0;
1507 
1508  // on verifie si l'objet est en numerotation provisoire
1509  $ref = substr($object->ref, 1, 4);
1510  if ($ref == 'PROV') {
1511  $numref = $object->getNextNumRef($soc);
1512  if (empty($numref)) {
1513  $error++;
1514  setEventMessages($object->error, $object->errors, 'errors');
1515  }
1516  } else {
1517  $numref = $object->ref;
1518  }
1519 
1520  $text = $langs->trans('ConfirmValidateAsk', $numref);
1521  if (!empty($conf->notification->enabled)) {
1522  require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1523  $notify = new Notify($db);
1524  $text .= '<br>';
1525  $text .= $notify->confirmMessage('PROPOSAL_SUPPLIER_VALIDATE', $object->socid, $object);
1526  }
1527 
1528  if (!$error) {
1529  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateAsk'), $text, 'confirm_validate', '', 0, 1);
1530  }
1531  }
1532 
1533  // Call Hook formConfirm
1534  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
1535  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1536  if (empty($reshook)) {
1537  $formconfirm .= $hookmanager->resPrint;
1538  } elseif ($reshook > 0) {
1539  $formconfirm = $hookmanager->resPrint;
1540  }
1541 
1542  // Print form confirm
1543  print $formconfirm;
1544 
1545 
1546  // Supplier proposal card
1547  $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1548 
1549 
1550  $morehtmlref = '<div class="refidno">';
1551  // Ref supplier
1552  //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', 0, 1);
1553  //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', null, null, '', 1);
1554  // Thirdparty
1555  $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'supplier');
1556  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
1557  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherProposals").'</a>)';
1558  }
1559  // Project
1560  if (!empty($conf->project->enabled)) {
1561  $langs->load("projects");
1562  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
1563  if ($usercancreate) {
1564  if ($action != 'classify') {
1565  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
1566  }
1567  if ($action == 'classify') {
1568  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1569  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1570  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
1571  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
1572  $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);
1573  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1574  $morehtmlref .= '</form>';
1575  } else {
1576  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1577  }
1578  } else {
1579  if (!empty($object->fk_project)) {
1580  $proj = new Project($db);
1581  $proj->fetch($object->fk_project);
1582  $morehtmlref .= ' : '.$proj->getNomUrl(1);
1583  if ($proj->title) {
1584  $morehtmlref .= ' - '.$proj->title;
1585  }
1586  } else {
1587  $morehtmlref .= '';
1588  }
1589  }
1590  }
1591  $morehtmlref .= '</div>';
1592 
1593 
1594  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1595 
1596 
1597  print '<div class="fichecenter">';
1598  print '<div class="fichehalfleft">';
1599  print '<div class="underbanner clearboth"></div>';
1600 
1601  print '<table class="border tableforfield" width="100%">';
1602 
1603  // Relative and absolute discounts
1604  if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
1605  $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
1606  $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
1607  } else {
1608  $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
1609  $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
1610  }
1611 
1612  print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td>';
1613 
1614  $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
1615  $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote, 0, 1);
1616  $absolute_discount = price2num($absolute_discount, 'MT');
1617  $absolute_creditnote = price2num($absolute_creditnote, 'MT');
1618 
1619  $thirdparty = $soc;
1620  $discount_type = 1;
1621  $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
1622  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1623 
1624  print '</td></tr>';
1625 
1626  // Payment term
1627  print '<tr><td class="titlefield">';
1628  print '<table class="nobordernopadding" width="100%"><tr><td>';
1629  print $langs->trans('PaymentConditionsShort');
1630  print '</td>';
1631  if ($action != 'editconditions' && $object->statut != SupplierProposal::STATUS_NOTSIGNED) {
1632  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>';
1633  }
1634  print '</tr></table>';
1635  print '</td><td class="valuefield">';
1636  if ($action == 'editconditions') {
1637  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
1638  } else {
1639  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1);
1640  }
1641  print '</td>';
1642  print '</tr>';
1643 
1644  // Delivery date
1645  $langs->load('deliveries');
1646  print '<tr><td>';
1647  print '<table class="nobordernopadding" width="100%"><tr><td>';
1648  print $langs->trans('DeliveryDate');
1649  print '</td>';
1650  if ($action != 'editdate_livraison' && $object->statut == SupplierProposal::STATUS_VALIDATED) {
1651  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>';
1652  }
1653  print '</tr></table>';
1654  print '</td><td class="valuefield">';
1655  if ($action == 'editdate_livraison') {
1656  print '<form name="editdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post" class="formconsumeproduce">';
1657  print '<input type="hidden" name="token" value="'.newToken().'">';
1658  print '<input type="hidden" name="action" value="setdate_livraison">';
1659  print $form->selectDate($object->delivery_date, 'liv_', '', '', '', "editdate_livraison");
1660  print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
1661  print '</form>';
1662  } else {
1663  print dol_print_date($object->delivery_date, 'daytext');
1664  }
1665  print '</td>';
1666  print '</tr>';
1667 
1668  // Payment mode
1669  print '<tr>';
1670  print '<td>';
1671  print '<table class="nobordernopadding" width="100%"><tr><td>';
1672  print $langs->trans('PaymentMode');
1673  print '</td>';
1674  if ($action != 'editmode' && $object->statut != SupplierProposal::STATUS_NOTSIGNED) {
1675  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>';
1676  }
1677  print '</tr></table>';
1678  print '</td><td class="valuefield">';
1679  if ($action == 'editmode') {
1680  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1);
1681  } else {
1682  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
1683  }
1684  print '</td></tr>';
1685 
1686  // Multicurrency
1687  if (!empty($conf->multicurrency->enabled)) {
1688  // Multicurrency code
1689  print '<tr>';
1690  print '<td>';
1691  print '<table class="nobordernopadding" width="100%"><tr><td>';
1692  print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
1693  print '</td>';
1694  if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_VALIDATED) {
1695  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>';
1696  }
1697  print '</tr></table>';
1698  print '</td><td class="valuefield">';
1699  if ($action == 'editmulticurrencycode') {
1700  $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
1701  } else {
1702  $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
1703  }
1704  print '</td></tr>';
1705 
1706  // Multicurrency rate
1707  if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1708  print '<tr>';
1709  print '<td>';
1710  print '<table class="nobordernopadding" width="100%"><tr><td>';
1711  print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
1712  print '</td>';
1713  if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_VALIDATED && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1714  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>';
1715  }
1716  print '</tr></table>';
1717  print '</td><td class="valuefield">';
1718  if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
1719  if ($action == 'actualizemulticurrencyrate') {
1720  list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
1721  }
1722  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
1723  } else {
1724  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
1725  if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1726  print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
1727  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
1728  print '</div>';
1729  }
1730  }
1731  print '</td></tr>';
1732  }
1733  }
1734 
1735  /* Not for supplier proposals
1736  if ($soc->outstanding_limit)
1737  {
1738  // Outstanding Bill
1739  print '<tr><td>';
1740  print $langs->trans('OutstandingBill');
1741  print '</td><td class="valuefield">';
1742  $arrayoutstandingbills = $soc->getOutstandingBills('supplier');
1743  $outstandingBills = $arrayoutstandingbills['opened'];
1744  print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency);
1745  print '</td>';
1746  print '</tr>';
1747  }*/
1748 
1749  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && !empty($conf->banque->enabled)) {
1750  // Bank Account
1751  print '<tr><td>';
1752  print '<table width="100%" class="nobordernopadding"><tr><td>';
1753  print $langs->trans('BankAccount');
1754  print '</td>';
1755  if ($action != 'editbankaccount' && $usercancreate) {
1756  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>';
1757  }
1758  print '</tr></table>';
1759  print '</td><td class="valuefield">';
1760  if ($action == 'editbankaccount') {
1761  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
1762  } else {
1763  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
1764  }
1765  print '</td>';
1766  print '</tr>';
1767  }
1768 
1769  // Other attributes
1770  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1771 
1772  print '</table>';
1773 
1774  print '</div>';
1775  print '<div class="fichehalfright">';
1776  print '<div class="underbanner clearboth"></div>';
1777 
1778  print '<table class="border tableforfield centpercent">';
1779 
1780  if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) {
1781  // Multicurrency Amount HT
1782  print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';
1783  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>';
1784  print '</tr>';
1785 
1786  // Multicurrency Amount VAT
1787  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';
1788  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>';
1789  print '</tr>';
1790 
1791  // Multicurrency Amount TTC
1792  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';
1793  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>';
1794  print '</tr>';
1795  }
1796 
1797  // Amount HT
1798  print '<tr><td class="titlefieldmiddle">'.$langs->trans('AmountHT').'</td>';
1799  print '<td class="valuefield nowrap right amountcard">'.price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1800  print '</tr>';
1801 
1802  // Amount VAT
1803  print '<tr><td>'.$langs->trans('AmountVAT').'</td>';
1804  print '<td class="valuefield nowrap right amountcard">'.price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1805  print '</tr>';
1806 
1807  // Amount Local Taxes
1808  if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { // Localtax1
1809  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
1810  print '<td class="valuefield nowrap right amountcard">'.price($object->total_localtax1, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1811  print '</tr>';
1812  }
1813  if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { // Localtax2
1814  print '<tr><td height="10">'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
1815  print '<td class="valuefield nowrap right amountcard">'.price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1816  print '</tr>';
1817  }
1818 
1819  // Amount TTC
1820  print '<tr><td height="10">'.$langs->trans('AmountTTC').'</td>';
1821  print '<td class="valuefield nowrap right amountcard">'.price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
1822  print '</tr>';
1823 
1824  print '</table>';
1825 
1826  // Margin Infos
1827  /*if (! empty($conf->margin->enabled)) {
1828  $formmargin->displayMarginInfos($object);
1829  }*/
1830 
1831  print '</div>';
1832  print '</div>';
1833 
1834  print '<div class="clearboth"></div><br>';
1835 
1836  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
1837  $blocname = 'contacts';
1838  $title = $langs->trans('ContactsAddresses');
1839  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1840  }
1841 
1842  if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
1843  $blocname = 'notes';
1844  $title = $langs->trans('Notes');
1845  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1846  }
1847 
1848  /*
1849  * Lines
1850  */
1851 
1852  // Show object lines
1853  $result = $object->getLinesArray();
1854 
1855  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#add' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
1856  <input type="hidden" name="token" value="' . newToken().'">
1857  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
1858  <input type="hidden" name="mode" value="">
1859  <input type="hidden" name="id" value="' . $object->id.'">
1860  ';
1861 
1862  if (!empty($conf->use_javascript_ajax) && $object->statut == SupplierProposal::STATUS_DRAFT) {
1863  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
1864  }
1865 
1866  print '<div class="div-table-responsive-no-min">';
1867  print '<table id="tablelines" class="noborder noshadow" width="100%">';
1868 
1869  // Add free products/services form
1870  global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
1871  $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
1872  $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty.
1873  if (!empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY)) {
1874  $senderissupplier = 1;
1875  }
1876 
1877  if (!empty($object->lines)) {
1878  $ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, $dateSelector);
1879  }
1880 
1881  // Form to add new line
1882  if ($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) {
1883  if ($action != 'editline') {
1884  // Add products/services form
1885 
1886  $parameters = array();
1887  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1888  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1889  if (empty($reshook))
1890  $object->formAddObjectLine($dateSelector, $soc, $mysoc);
1891  }
1892  }
1893 
1894  print '</table>';
1895  print '</div>';
1896  print "</form>\n";
1897 
1898  print dol_get_fiche_end();
1899 
1900  if ($action == 'statut') {
1901  // Form to set proposal accepted/refused
1902  $form_close = '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST" id="formacceptrefuse" class="formconsumeproduce paddingbottom paddingleft paddingright">';
1903  $form_close .= '<input type="hidden" name="token" value="'.newToken().'">';
1904  $form_close .= '<input type="hidden" name="action" value="setstatut">';
1905 
1906  if (!empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL)) {
1907  $form_close .= '<p class="notice">'.$langs->trans('SupplierProposalRefFournNotice').'</p>'; // TODO Suggest a permanent checkbox instead of option
1908  }
1909  $form_close .= '<table class="border centpercent marginleftonly marginrightonly">';
1910  $form_close .= '<tr><td>'.$langs->trans("CloseAs").'</td><td class="left">';
1911  $form_close .= '<select id="statut" name="statut" class="flat">';
1912  $form_close .= '<option value="0">&nbsp;</option>';
1913  $form_close .= '<option value="2">'.$langs->trans('SupplierProposalStatusSigned').'</option>';
1914  $form_close .= '<option value="3">'.$langs->trans('SupplierProposalStatusNotSigned').'</option>';
1915  $form_close .= '</select>';
1916  $form_close .= '</td></tr>';
1917  $form_close .= '<tr><td class="left">'.$langs->trans('Note').'</td><td class="left"><textarea cols="70" rows="'.ROWS_3.'" wrap="soft" name="note">';
1918  $form_close .= $object->note_private;
1919  $form_close .= '</textarea></td></tr>';
1920  $form_close .= '</table>';
1921  $form_close .= $form->buttonsSaveCancel();
1922  $form_close .= '<a id="acceptedrefused">&nbsp;</a>';
1923  $form_close .= '</form>';
1924 
1925  print $form_close;
1926  }
1927 
1928  /*
1929  * Boutons Actions
1930  */
1931  if ($action != 'presend') {
1932  print '<div class="tabsAction">';
1933 
1934  $parameters = array();
1935  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1936  // modified by hook
1937  if (empty($reshook)) {
1938  if ($action != 'statut' && $action != 'editline') {
1939  // Validate
1940  if ($object->statut == SupplierProposal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0 && $usercanvalidate) {
1941  if (count($object->lines) > 0) {
1942  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a></div>';
1943  }
1944  // else print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Validate').'</a>';
1945  }
1946 
1947  // Edit
1948  if ($object->statut == SupplierProposal::STATUS_VALIDATED && $usercancreate) {
1949  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>';
1950  }
1951 
1952  // ReOpen
1953  if (($object->statut == SupplierProposal::STATUS_SIGNED || $object->statut == SupplierProposal::STATUS_NOTSIGNED || $object->statut == SupplierProposal::STATUS_CLOSE) && $usercanclose) {
1954  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').'"';
1955  print '>'.$langs->trans('ReOpen').'</a></div>';
1956  }
1957 
1958  // Send
1959  if (empty($user->socid)) {
1960  if ($object->statut == SupplierProposal::STATUS_VALIDATED || $object->statut == SupplierProposal::STATUS_SIGNED) {
1961  if ($usercansend) {
1962  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>';
1963  } else {
1964  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
1965  }
1966  }
1967  }
1968 
1969  // Create an order
1970  if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) && $object->statut == SupplierProposal::STATUS_SIGNED) {
1971  if ($usercancreateorder) {
1972  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.'&amp;token='.newToken().'">'.$langs->trans("AddSupplierOrderShort").'</a></div>';
1973  }
1974  }
1975 
1976  // Set accepted/refused
1977  if ($object->statut == SupplierProposal::STATUS_VALIDATED && $usercanclose) {
1978  print '<div class="inline-block divButAction"><a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;token='.newToken().'&amp;action=statut'.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#acceptedrefused').'"';
1979  print '>'.$langs->trans('SetAcceptedRefused').'</a></div>';
1980  }
1981 
1982  // Close
1983  if ($object->statut == SupplierProposal::STATUS_SIGNED && $usercanclose) {
1984  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;token='.newToken().'&amp;action=close'.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#close').'"';
1985  print '>'.$langs->trans('Close').'</a></div>';
1986  }
1987 
1988  // Clone
1989  if ($usercancreate) {
1990  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&object='.$object->element.'&amp;token='.newToken().'">'.$langs->trans("ToClone").'</a></div>';
1991  }
1992 
1993  // Delete
1994  if (($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) || $usercandelete) {
1995  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&token='.newToken().'"';
1996  print '>'.$langs->trans('Delete').'</a></div>';
1997  }
1998  }
1999  }
2000 
2001  print '</div>';
2002  }
2003 
2004  if ($action != 'presend') {
2005  print '<div class="fichecenter"><div class="fichehalfleft">';
2006 
2007  /*
2008  * Generated documents
2009  */
2010  $filename = dol_sanitizeFileName($object->ref);
2011  $filedir = $conf->supplier_proposal->dir_output."/".dol_sanitizeFileName($object->ref);
2012  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2013  $genallowed = $usercanread;
2014  $delallowed = $usercancreate;
2015 
2016  print $formfile->showdocuments('supplier_proposal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang);
2017 
2018 
2019  // Show links to link elements
2020  $linktoelem = $form->showLinkToObjectBlock($object, null, array('supplier_proposal'));
2021  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2022 
2023 
2024  print '</div><div class="fichehalfright">';
2025 
2026  // List of actions on element
2027  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2028  $formactions = new FormActions($db);
2029  $somethingshown = $formactions->showactions($object, 'supplier_proposal', $socid, 1);
2030 
2031  print '</div></div>';
2032  }
2033 
2034  // Select mail models is same action as presend
2035  if (GETPOST('modelselected')) {
2036  $action = 'presend';
2037  }
2038 
2039  // Presend form
2040  $modelmail = 'supplier_proposal_send';
2041  $defaulttopic = 'SendAskRef';
2042  $diroutput = $conf->supplier_proposal->dir_output;
2043  $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
2044  $trackid = 'spro'.$object->id;
2045 
2046  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2047 }
2048 
2049 // End of page
2050 llxFooter();
2051 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Project
Class to manage projects.
Definition: project.class.php:35
ProductFournisseur
Class to manage predefined suppliers products.
Definition: fournisseur.product.class.php:41
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
Translate
Class to manage translations.
Definition: translate.class.php:30
SupplierProposal\STATUS_NOTSIGNED
const STATUS_NOTSIGNED
Not signed quote, canceled.
Definition: supplier_proposal.class.php:215
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormMargin
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formmargin.class.php:29
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
dol_clone
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
Definition: functions.lib.php:1158
Notify
Class to manage notifications.
Definition: notify.class.php:33
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
SupplierProposal\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: supplier_proposal.class.php:205
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
dol_concatdesc
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Definition: functions.lib.php:7248
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
$formactions
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
Definition: agenda_other.php:178
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
get_default_npr
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
Definition: functions.lib.php:6405
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
get_localtax
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
Definition: functions.lib.php:5837
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
MultiCurrency\getIdAndTxFromCode
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Definition: multicurrency.class.php:526
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_htmlcleanlastbr
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
Definition: functions.lib.php:7036
get_default_tva
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
Definition: functions.lib.php:6304
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
ModelePDFSupplierProposal\liste_modeles
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Definition: modules_supplier_proposal.php:53
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$parameters
$parameters
Actions.
Definition: card.php:78
SupplierProposal\STATUS_CLOSE
const STATUS_CLOSE
Billed or closed/processed quote.
Definition: supplier_proposal.class.php:220
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
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
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
SupplierProposal
Class to manage price ask supplier.
Definition: supplier_proposal.class.php:50
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
SupplierProposal\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: supplier_proposal.class.php:200
llxHeader
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
SupplierProposal\STATUS_SIGNED
const STATUS_SIGNED
Signed quote.
Definition: supplier_proposal.class.php:210