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