dolibarr 25.0.0-alpha
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-2026 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-2026 MDW <mdeweerd@users.noreply.github.com>
18 * Copyright (C) 2026 Lionel Vessiller <lvessiller@open-dsi.fr>
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <https://www.gnu.org/licenses/>.
32 */
33
40// Load Dolibarr environment
41require '../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
46require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
47require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/supplier_proposal.lib.php';
50require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
51require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
52if (isModEnabled('project')) {
53 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
54 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
55}
56
66// Load translation files required by the page
67$langs->loadLangs(array('companies', 'supplier_proposal', 'compta', 'bills', 'propal', 'orders', 'products', 'sendings'));
68if (isModEnabled('margin')) {
69 $langs->load('margins');
70}
71
72$error = 0;
73
74$id = GETPOSTINT('id');
75$ref = GETPOST('ref', 'alpha');
76$socid = GETPOSTINT('socid');
77$action = GETPOST('action', 'aZ09');
78$cancel = GETPOST('cancel', 'alpha');
79$backtopage = GETPOST('backtopage', 'alpha');
80$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
81
82$origin = GETPOST('origin', 'alpha');
83$originid = GETPOSTINT('originid');
84$confirm = GETPOST('confirm', 'alpha');
85$lineid = GETPOSTINT('lineid');
86$contactid = GETPOSTINT('contactid');
87$projectid = GETPOSTINT('projectid');
88$rank = (GETPOSTINT('rank') > 0) ? GETPOSTINT('rank') : -1;
89
90// PDF
91$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
92$hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
93$hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
94
95// Number of line to choose predefined product/service from
96$NBLINES = 4;
97
98// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
99$hookmanager->initHooks(array('supplier_proposalcard', 'globalcard'));
100
101$object = new SupplierProposal($db);
102$extrafields = new ExtraFields($db);
103
104$objectsrc = null;
105$classname = null;
106
107// fetch optionals attributes and labels
108$extrafields->fetch_name_optionals_label($object->table_element);
109
110// Load object
111if ($id > 0 || !empty($ref)) {
112 $ret = $object->fetch($id, $ref);
113 if ($ret > 0) {
114 $ret = $object->fetch_thirdparty();
115 }
116 if ($ret <= 0) {
117 setEventMessages($object->error, $object->errors, 'errors');
118 $action = '';
119 }
120}
121
122// Common permissions
123$usercanread = $user->hasRight('supplier_proposal', 'lire');
124$usercancreate = $user->hasRight('supplier_proposal', 'creer');
125$usercandelete = $user->hasRight('supplier_proposal', 'supprimer');
126
127// Advanced permissions
128$usercanvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('supplier_proposal', 'validate_advance')));
129$usercansend = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('supplier_proposal', 'send_advance'));
130
131// Additional area permissions
132$usercanclose = $user->hasRight('supplier_proposal', 'cloturer');
133$usercancreateorder = ($user->hasRight('fournisseur', 'commande', 'creer') || $user->hasRight('supplier_order', 'creer'));
134
135// Permissions for includes
136$permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
137$permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php
138$permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
139$permissiontoadd = $usercancreate;
140$permissiontoeditextra = $permissiontoadd;
141if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
142 // For action 'update_extras', is there a specific permission set for the attribute to update
143 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
144}
145
146// Security check
147if (!empty($user->socid)) {
148 $socid = $user->socid;
149}
150$result = restrictedArea($user, 'supplier_proposal', $object->id);
151
152
153/*
154 * Actions
155 */
156
157$parameters = array('socid' => $socid);
158$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
159if ($reshook < 0) {
160 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
161}
162
163$fournprice = 0;
164$buyingprice = 0;
165
166if (empty($reshook)) {
167 $backurlforlist = DOL_URL_ROOT.'/supplier_proposal/list.php';
168
169 if (empty($backtopage) || ($cancel && empty($id))) {
170 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
171 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
172 $backtopage = $backurlforlist;
173 } else {
174 $backtopage = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
175 }
176 }
177 }
178
179 if ($cancel && !($action == 'updateline' && $usercancreate)) {
180 if (!empty($backtopageforcancel)) {
181 header("Location: ".$backtopageforcancel);
182 exit;
183 } elseif (!empty($backtopage)) {
184 header("Location: ".$backtopage);
185 exit;
186 }
187 $action = '';
188 }
189
190 include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be 'include', not 'include_once'
191
192 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
193
194 include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
195
196 // Action clone object
197 if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
198 if (false && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
199 setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
200 } else {
201 if ($object->id > 0) {
202 $result = $object->createFromClone($user, $socid);
203 if ($result > 0) {
204 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
205 exit();
206 } else {
207 setEventMessages($object->error, $object->errors, 'errors');
208 $action = '';
209 }
210 }
211 }
212 } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) {
213 // Delete askprice
214 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
215 $result = $object->delete($user);
216 if ($result > 0) {
217 header('Location: '.DOL_URL_ROOT.'/supplier_proposal/list.php');
218 exit();
219 } else {
220 $langs->load("errors");
221 setEventMessages($langs->trans($object->error), null, 'errors');
222 }
223 } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
224 // Remove line
225 $result = $object->deleteLine($lineid);
226 // reorder lines
227 if ($result > 0) {
228 $object->line_order(true);
229 } else {
230 $langs->load("errors");
231 setEventMessages($object->error, $object->errors, 'errors');
232 }
233
234 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
235 // Define output language
236 $outputlangs = $langs;
237 if (getDolGlobalInt('MAIN_MULTILANGS')) {
238 $outputlangs = new Translate("", $conf);
239 $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
240 $outputlangs->setDefaultLang($newlang);
241 }
242 $ret = $object->fetch($id); // Reload to get new records
243 if ($ret > 0) {
244 $object->fetch_thirdparty();
245 }
246 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
247 }
248
249 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
250 exit();
251 } elseif ($action == 'confirm_delete_subtotalline' && $confirm == 'yes' && $usercancreate) {
252 // Delete line
253 $object->fetch($id);
254 $object->fetch_thirdparty();
255
256 $result = $object->deleteSubtotalLine($langs, GETPOSTINT('lineid'), (bool) GETPOST('deletecorrespondingsubtotalline'));
257 if ($result > 0) {
258 // reorder lines
259 $object->line_order(true);
260 // Define output language
261 $outputlangs = $langs;
262 $newlang = '';
263 if (getDolGlobalInt('MAIN_MULTILANGS') && GETPOST('lang_id')) {
264 $newlang = GETPOST('lang_id');
265 }
266 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
267 $newlang = $object->thirdparty->default_lang;
268 }
269 if (!empty($newlang)) {
270 $outputlangs = new Translate("", $conf);
271 $outputlangs->setDefaultLang($newlang);
272 $outputlangs->load('products');
273 }
274 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
275 $ret = $object->fetch($id); // Reload to get new records
276 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
277 }
278 if ($result >= 0) {
279 header('Location: '.dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $id]));
280 exit();
281 }
282 } else {
283 setEventMessages($object->error, $object->errors, 'errors');
284 $action = '';
285 }
286 } elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) {
287 // Validation
288 $result = $object->valid($user);
289 if ($result >= 0) {
290 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
291 $outputlangs = $langs;
292 $newlang = '';
293 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
294 $newlang = GETPOST('lang_id', 'aZ09');
295 }
296 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
297 $newlang = $object->thirdparty->default_lang;
298 }
299 if (!empty($newlang)) {
300 $outputlangs = new Translate("", $conf);
301 $outputlangs->setDefaultLang($newlang);
302 }
303 $model = $object->model_pdf;
304 $ret = $object->fetch($id); // Reload to get new records
305 if ($ret > 0) {
306 $object->fetch_thirdparty();
307 }
308
309 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
310 }
311 } else {
312 $langs->load("errors");
313 if (count($object->errors) > 0) {
314 setEventMessages($object->error, $object->errors, 'errors');
315 } else {
316 setEventMessages($langs->trans($object->error), null, 'errors');
317 }
318 }
319 } elseif ($action == 'setdate_livraison' && $usercancreate) {
320 $result = $object->setDeliveryDate($user, dol_mktime(12, 0, 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year')));
321 if ($result < 0) {
322 dol_print_error($db, $object->error);
323 }
324 } elseif ($action == 'add' && $usercancreate) {
325 // Create supplier proposal
326 $object->socid = $socid;
327 $object->fetch_thirdparty();
328
329 $date_delivery = dol_mktime(12, 0, 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
330
331 if ($socid < 1) {
332 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
333 $action = 'create';
334 $error++;
335 }
336
337 if (!$error) {
338 $db->begin();
339
340 $model_pdf = (GETPOST('model') != '0' && GETPOST('model') != '-1') ? GETPOST('model') : '';
341
342 // When a copy request was made, make the copy
343 if (GETPOST('createmode') == 'copy' && GETPOSTINT('copie_supplier_proposal') > 0) {
344 if ($object->fetch(GETPOSTINT('copie_supplier_proposal')) > 0) {
345 $object->ref = GETPOST('ref');
346 $object->delivery_date = $date_delivery;
347 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
348 $object->cond_reglement_id = GETPOSTINT('cond_reglement_id');
349 $object->deposit_percent = GETPOSTFLOAT('cond_reglement_id_deposit_percent');
350 $object->mode_reglement_id = GETPOSTINT('mode_reglement_id');
351 $object->fk_account = GETPOSTINT('fk_account');
352 $object->socid = GETPOSTINT('socid');
353 $object->fk_project = GETPOSTINT('projectid');
354 $object->model_pdf = $model_pdf;
355 $object->author = $user->id; // deprecated
356 $object->user_creation_id = $user->id;
357 $object->note = GETPOST('note', 'restricthtml');
358 $object->note_private = GETPOST('note', 'restricthtml');
361 } else {
362 setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_supplier_proposal')), null, 'errors');
363 }
364 } else {
365 $object->ref = GETPOST('ref');
366 $object->delivery_date = $date_delivery;
367 $object->demand_reason_id = GETPOSTINT('demand_reason_id');
368 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
369 $object->cond_reglement_id = GETPOSTINT('cond_reglement_id');
370 $object->deposit_percent = GETPOSTFLOAT('cond_reglement_id_deposit_percent');
371 $object->mode_reglement_id = GETPOSTINT('mode_reglement_id');
372 $object->fk_account = GETPOSTINT('fk_account');
373 $object->fk_project = GETPOSTINT('projectid');
374 $object->model_pdf = $model_pdf;
375 $object->author = $user->id; // deprecated
376 $object->user_creation_id = $user->id;
377 $object->note = GETPOST('note', 'restricthtml');
378 $object->note_private = GETPOST('note', 'restricthtml');
379
380 $object->origin = GETPOST('origin');
381 $object->origin_id = GETPOSTINT('originid');
382
383 // Multicurrency
384 if (isModEnabled("multicurrency")) {
385 $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
386 }
387
388 // Fill array 'array_options' with data from add form
389 $ret = $extrafields->setOptionalsFromPost(null, $object);
390 if ($ret < 0) {
391 $error++;
392 $action = 'create';
393 }
394 }
395
396 if (!$error) {
397 if ($origin && $originid) {
398 $object->origin = $origin;
399 $object->origin_type = $origin;
400 $object->origin_id = $originid;
401
402 // Possibility to add external linked objects with hooks
403 $object->linked_objects [$object->origin_type] = $object->origin_id;
404 if (GETPOSTISARRAY('other_linked_objects')) {
405 $object->linked_objects = array_merge($object->linked_objects, GETPOST('other_linked_objects', 'array:int'));
406 }
407
408 $id = $object->create($user);
409 if ($id > 0) {
410 dol_syslog("Try to find source object origin=".$object->origin_type." originid=".$object->origin_id." to add lines");
411
412 // Resolve and load the source object from its element type (propal, commande, contract, ...)
413 $srcobject = fetchObjectByElement($object->origin_id, $origin);
414
415 if (is_object($srcobject) && $srcobject->id > 0) {
416 '@phan-var-force Commande|Propal|Contrat|Fichinter|Expedition $srcobject'; // Maybe other class but CommonObject is too generic
417 $lines = $srcobject->lines;
418 if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
419 $srcobject->fetch_lines();
420 $lines = $srcobject->lines;
421 }
422
423 $fk_parent_line = 0;
424 $num = count($lines);
425 for ($i = 0; $i < $num; $i++) {
426 $label = (!empty($lines[$i]->label) ? $lines[$i]->label : '');
427 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : '');
428
429 // Positive line
430 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
431
432 // Reset fk_parent_line for no child products and special product
433 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
434 $fk_parent_line = 0;
435 }
436
437 // Extrafields
438 if (method_exists($lines[$i], 'fetch_optionals')) {
439 $lines[$i]->fetch_optionals();
440 $array_options = $lines[$i]->array_options;
441 } else {
442 $array_options = array();
443 }
444
445 // Preserve the TTC entry mode of the source line: a line entered including tax must
446 // stay in TTC so its total is computed from the typed value, without rounding drift.
447 $line_price_base_type = $lines[$i]->getPriceBaseType();
448 $result = $object->addline(
449 $desc,
450 $lines[$i]->subprice,
451 $lines[$i]->qty,
452 $lines[$i]->tva_tx,
453 $lines[$i]->localtax1_tx,
454 $lines[$i]->localtax2_tx,
455 $lines[$i]->fk_product,
456 $lines[$i]->remise_percent,
457 $line_price_base_type,
458 (float) $lines[$i]->subprice_ttc,
459 $lines[$i]->info_bits,
460 $product_type,
461 $lines[$i]->rang,
462 $lines[$i]->special_code,
463 $fk_parent_line,
464 $lines[$i]->fk_fournprice,
465 $lines[$i]->pa_ht,
466 $label,
467 $array_options,
468 $lines[$i]->ref_supplier,
469 $lines[$i]->fk_unit
470 );
471
472 if ($result > 0) {
473 $lineid = $result;
474 } else {
475 $lineid = 0;
476 $error++;
477 break;
478 }
479
480 // Keep the extra parameters of the source line (for example the options of subtotal lines)
481 if ($result > 0 && !empty($lines[$i]->extraparams)) {
482 $newline = new SupplierProposalLine($db);
483 $newline->id = $result;
484 $newline->extraparams = $lines[$i]->extraparams;
485 $newline->setExtraParameters();
486 }
487
488 // Defined the new fk_parent_line
489 if ($result > 0 && $lines[$i]->product_type == 9) {
490 $fk_parent_line = $result;
491 }
492 }
493
494 // Hooks
495 $parameters = array('objFrom' => $srcobject);
496 $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
497 // modified by hook
498 if ($reshook < 0) {
499 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
500 $error++;
501 }
502 } else {
503 if (is_object($srcobject) && !empty($srcobject->error)) {
504 setEventMessages($srcobject->error, $srcobject->errors, 'errors');
505 } else {
506 $langs->load("errors");
507 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
508 }
509 $error++;
510 }
511 } else {
512 setEventMessages($object->error, $object->errors, 'errors');
513 $error++;
514 }
515 } else {
516 // Standard creation
517 $id = $object->create($user);
518 }
519
520 if ($id > 0) {
521 if (isModEnabled('category')) {
522 $categories = GETPOST('categories', 'array');
523 $object->setCategories($categories);
524 }
525 if (!$error) {
526 $db->commit();
527
528 // Define output language
529 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
530 $outputlangs = $langs;
531 $newlang = '';
532 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
533 $newlang = GETPOST('lang_id', 'aZ09');
534 }
535 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
536 $newlang = $object->thirdparty->default_lang;
537 }
538 if (!empty($newlang)) {
539 $outputlangs = new Translate("", $conf);
540 $outputlangs->setDefaultLang($newlang);
541 }
542 $model = $object->model_pdf;
543
544 if (!empty($model)) {
545 $ret = $object->fetch($id); // Reload to get new records
546 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
547 if ($result < 0) {
548 dol_print_error($db, $object->error, $object->errors);
549 }
550 }
551 }
552
553 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
554 exit();
555 } else {
556 $db->rollback();
557 $action = 'create';
558 }
559 } else {
560 setEventMessages($object->error, $object->errors, 'errors');
561 $db->rollback();
562 $action = 'create';
563 }
564 }
565 }
566 } elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) {
567 // Reopen proposal
568 // prevent browser refresh from reopening proposal several times
571 }
572 } elseif ($action == 'close' && $usercanclose && !GETPOST('cancel', 'alpha')) {
573 // Close proposal
574 // prevent browser refresh from reopening proposal several times
577 }
578 } elseif ($action == 'setstatut' && $usercanclose && !GETPOST('cancel', 'alpha')) {
579 // Set accepted/refused
580 // Only the 2 values of the form are accepted (like for a customer proposal), not any status
582 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("CloseAs")), null, 'errors');
583 $action = 'statut';
584 } else {
585 // prevent browser refresh from closing proposal several times
587 $object->cloture($user, GETPOSTINT('statut'), GETPOST('note', 'restricthtml'));
588 }
589 }
590 } elseif ($action == 'addline' && GETPOST('updateallvatlinesblock', 'alpha') && GETPOST('vatforblocklines', 'alpha') !== '' && $usercancreate) {
591 $tx_tva = GETPOST('vatforblocklines') ? GETPOST('vatforblocklines') : 0;
592 $object->updateSubtotalLineBlockLines($langs, $object->getRangOfLine($lineid), 'tva', $tx_tva);
593 } elseif ($action == 'addline' && GETPOST('updatealldiscountlinesblock', 'alpha') && GETPOST('discountforblocklines', 'alpha') !== '' && $usercancreate) {
594 $discount = GETPOST('discountforblocklines') ? GETPOST('discountforblocklines') : 0;
595 $object->updateSubtotalLineBlockLines($langs, $object->getRangOfLine($lineid), 'discount', $discount);
596 } elseif ($action == 'settags' && isModEnabled('category') && $usercancreate) { // Set tags
597 $result = $object->setCategories(GETPOST('categories', 'array'));
598 }
599
600 // Actions when printing a doc from card
601 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
602
603 // Actions to send emails
604 $triggersendname = 'PROPOSAL_SUPPLIER_SENTBYMAIL';
605 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
606 $trackid = 'spro'.$object->id;
607 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
608
609 // Actions to build doc
610 $upload_dir = $conf->supplier_proposal->dir_output;
611 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
612
613 // Go back to draft
614 if ($action == 'modif' && $usercancreate) {
615 $object->setDraft($user);
616
617 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
618 // Define output language
619 $outputlangs = $langs;
620 if (getDolGlobalInt('MAIN_MULTILANGS')) {
621 $outputlangs = new Translate("", $conf);
622 $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
623 $outputlangs->setDefaultLang($newlang);
624 }
625 $ret = $object->fetch($id); // Reload to get new records
626 if ($ret > 0) {
627 $object->fetch_thirdparty();
628 }
629 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
630 }
631 } elseif ($action == "setabsolutediscount" && $usercancreate) {
632 if (GETPOSTINT("remise_id")) {
633 if ($object->id > 0) {
634 $result = $object->insert_discount(GETPOSTINT("remise_id"));
635 if ($result < 0) {
636 setEventMessages($object->error, $object->errors, 'errors');
637 }
638 }
639 }
640 }
641
642 // Add a product line
643 if ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && GETPOST('vatforalllines', 'alpha') && $usercancreate) {
644 // Define vat_rate
645 $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
646 $vat_rate = str_replace('*', '', $vat_rate);
647 $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
648 $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
649 foreach ($object->lines as $line) {
650 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
651 continue;
652 }
653 // Preserve the original entry mode of the line so the total is not drifted by rounding.
654 $line_price_base_type = $line->getPriceBaseType();
655 $line_pu = ($line_price_base_type === 'TTC') ? (float) $line->subprice_ttc : (float) $line->subprice;
656 // In TTC mode, do not forward the HT currency price: under multicurrency updateline() would reset
657 // the local price and recompute from the HT currency amount (read as TTC) -> the TTC value is lost.
658 $line_pu_devise = ($line_price_base_type === 'TTC') ? 0 : (float) $line->multicurrency_subprice;
659 $result = $object->updateline($line->id, $line_pu, $line->qty, (float) $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $line->desc, $line_price_base_type, $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_pu_devise);
660 }
661 } elseif ($action == 'confirm_addtextline' && $usercancreate) {
662 // Handling adding a new text line for subtotals module
663
664 $langs->load('subtotals');
665
666 $desc = GETPOST('subtotaltextcontent', 'restricthtml');
667
668 // Insert line
669 $result = $object->addSubtotalLine($langs, $desc, 0, array());
670
671 if ($result >= 0) {
672 if ($result == 0) {
673 setEventMessages($object->error, $object->errors, 'warnings');
674 }
675 $ret = $object->fetch($object->id); // Reload to get new records
676 $object->fetch_thirdparty();
677
678 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
679 // Define output language
680 $outputlangs = $langs;
681 $newlang = GETPOST('lang_id', 'alpha');
682 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
683 $newlang = $object->thirdparty->default_lang;
684 }
685 if (!empty($newlang)) {
686 $outputlangs = new Translate("", $conf);
687 $outputlangs->setDefaultLang($newlang);
688 }
689
690 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
691 }
692 } else {
693 setEventMessages($object->error, $object->errors, 'errors');
694 }
695 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
696 exit();
697 } elseif ($action == 'confirm_addtitleline' && $usercancreate) {
698 // Handling adding a new title line for subtotals module
699
700 $langs->load('subtotals');
701
702 $desc = GETPOST('subtotallinedesc', 'alphanohtml');
703 $depth = GETPOSTINT('subtotallinelevel') ?? 1;
704
705 $subtotal_options = array();
706
707 foreach (SupplierProposal::$TITLE_OPTIONS as $option) {
708 $value = GETPOST($option, 'alphanohtml');
709 if ($value) {
710 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
711 }
712 }
713
714 // Insert line
715 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
716
717 if ($result >= 0) {
718 if ($result == 0) {
719 setEventMessages($object->error, $object->errors, 'warnings');
720 }
721 $ret = $object->fetch($object->id); // Reload to get new records
722 $object->fetch_thirdparty();
723
724 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
725 // Define output language
726 $outputlangs = $langs;
727 $newlang = GETPOST('lang_id', 'alpha');
728 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
729 $newlang = $object->thirdparty->default_lang;
730 }
731 if (!empty($newlang)) {
732 $outputlangs = new Translate("", $conf);
733 $outputlangs->setDefaultLang($newlang);
734 }
735
736 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
737 }
738 } else {
739 setEventMessages($object->error, $object->errors, 'errors');
740 }
741 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
742 exit();
743 } elseif ($action == 'confirm_addsubtotalline' && $usercancreate) {
744 // Handling adding a new subtotal line for subtotals module
745
746 $langs->load('subtotals');
747
748 $choosen_line = GETPOST('subtotaltitleline', 'alphanohtml');
749 foreach ($object->lines as $line) {
750 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
751 $desc = $line->desc;
752 $depth = -$line->qty;
753 }
754 }
755
756 $subtotal_options = array();
757
758 foreach (SupplierProposal::$SUBTOTAL_OPTIONS as $option) {
759 $value = GETPOST($option, 'alphanohtml');
760 if ($value) {
761 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
762 }
763 }
764
765 // Insert line
766 if (isset($desc) && isset($depth)) {
767 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
768 } else {
769 $result = -1;
770 $object->errors[] = $langs->trans("CorrespondingTitleNotFound");
771 }
772
773 if ($result >= 0) {
774 $ret = $object->fetch($object->id); // Reload to get new records
775 $object->fetch_thirdparty();
776
777 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
778 // Define output language
779 $outputlangs = $langs;
780 $newlang = GETPOST('lang_id', 'alpha');
781 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
782 $newlang = $object->thirdparty->default_lang;
783 }
784 if (!empty($newlang)) {
785 $outputlangs = new Translate("", $conf);
786 $outputlangs->setDefaultLang($newlang);
787 }
788
789 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
790 }
791 } else {
792 setEventMessages($object->error, $object->errors, 'errors');
793 }
794 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
795 exit();
796 } elseif ($action == 'addline' && $usercancreate) {
797 $langs->load('errors');
798 $error = 0;
799
800 // Set if we used free entry or predefined product
801 $predef = '';
802 $line_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
803 $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'));
804 $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'));
805
806 $ref_supplier = GETPOST('fourn_ref', 'alpha');
807
808 $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
809 if ($prod_entry_mode == 'free') {
810 $idprod = 0;
811 } else {
812 $idprod = GETPOSTINT('idprod');
813 }
814
815 $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)'
816
817 $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
818 $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
819 $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
820 $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
821
822 $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
823
824 $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
825 if (empty($remise_percent)) {
826 $remise_percent = 0;
827 }
828
829 // Extrafields
830 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
831 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
832 // Unset extrafield
833 if (is_array($extralabelsline)) {
834 // Get extra fields
835 foreach ($extralabelsline as $key => $value) {
836 unset($_POST["options_".$key]);
837 }
838 }
839
840 if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) {
841 setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
842 $error++;
843 }
844 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
845 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
846 $error++;
847 }
848
849 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.
850 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPrice")), null, 'errors');
851 $error++;
852 }
853 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
854 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
855 $error++;
856 }
857 if (!$error && ($qty >= 0)) {
858 $pu_ht = price2num($price_ht, 'MU');
859 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
860 $price_min = 0;
861 $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
862
863 $db->begin();
864
865 if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
866 $productsupplier = new ProductFournisseur($db);
867
868 $idprod = 0;
869 if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') {
870 $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, ...)
871 }
872
873 $reg = array();
874 if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) {
875 $idprod = (int) $reg[1];
876 $res = $productsupplier->fetch($idprod); // Load product from its id
877 // Call to init some price properties of $productsupplier
878 // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
879 if (getDolGlobalString('SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
880 $fksoctosearch = 0;
881 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
882 if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price
883 $productsupplier->ref_supplier = '';
884 }
885 } else {
886 $fksoctosearch = $object->thirdparty->id;
887 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
888 }
889 } elseif (GETPOSTINT('idprodfournprice') > 0) { // id here.
890 //$qtytosearch=$qty; // Just to see if a price exists for the quantity. Not used to found vat.
891 $qtytosearch = -1; // We force qty to -1 to be sure to find if the supplier price that exists
892 $idprod = $productsupplier->get_buyprice(GETPOSTINT('idprodfournprice'), $qtytosearch);
893 $res = $productsupplier->fetch($idprod);
894 }
895
896 if ($idprod > 0) {
897 $label = $productsupplier->label;
898
899 // Define output language
900 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
901 $outputlangs = $langs;
902 $newlang = '';
903 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
904 $newlang = GETPOST('lang_id', 'aZ09');
905 }
906 if (empty($newlang)) {
907 $newlang = $object->thirdparty->default_lang;
908 }
909 if (!empty($newlang)) {
910 $outputlangs = new Translate("", $conf);
911 $outputlangs->setDefaultLang($newlang);
912 }
913 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description;
914 } else {
915 $desc = $productsupplier->description;
916 }
917 // if we use supplier description of the products
918 if (!empty($productsupplier->desc_supplier) && getDolGlobalString('PRODUIT_FOURN_TEXTS')) {
919 $desc = $productsupplier->desc_supplier;
920 }
921
922 if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 0) {
923 // 'DoNotAutofillButAutoConcat'
924 $desc = dol_concatdesc($desc, $line_desc, false, getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION') ? true : false);
925 } else {
926 //'AutoFillFormFieldBeforeSubmit' or 'DoNotUseDescriptionOfProdut' => User has already done the modification they want
927 $desc = $line_desc;
928 }
929
930 $ref_supplier = $productsupplier->ref_supplier;
931
932 // Get vat rate
933 $tva_npr = 0;
934 if (!GETPOSTISSET('tva_tx')) { // If vat rate not provided from the form (the form has the priority)
935 $tmpidprodfournprice = GETPOST('idprodfournprice', 'alpha'); // can be an id of price, or -1, -2, -99 or 'idprod_...'
936 if (is_numeric($tmpidprodfournprice) && (int) $tmpidprodfournprice > 0) {
937 $tmpidprodfournprice = (int) $tmpidprodfournprice;
938 } else {
939 $tmpidprodfournprice = 0;
940 }
941
942 $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, $tmpidprodfournprice);
943 $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, $tmpidprodfournprice);
944 }
945 if (empty($tva_tx)) {
946 $tva_npr = 0;
947 }
948 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
949 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
950
951 $type = $productsupplier->type;
952 if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
953 $price_base_type = 'HT';
954 $pu = price2num($price_ht, 'MU');
955 $pu_devise = price2num($price_ht_devise, 'CU');
956 } elseif (GETPOST('price_ttc') != '' || GETPOST('multicurrency_price_ttc') != '') {
957 $price_base_type = 'TTC';
958 $pu = price2num($price_ttc, 'MU');
959 $pu_devise = price2num($price_ttc_devise, 'CU');
960 } else {
961 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
962 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
963 $pu = $productsupplier->fourn_pu;
964 $pu_devise = 0;
965 } else {
966 $pu = $productsupplier->fourn_pu;
967 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
968 }
969 }
970
971 if (empty($pu)) {
972 $pu = 0; // If pu is '' or null, we force to have a numeric value
973 }
974
975 // 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)
976 $fournprice = (is_numeric(GETPOST('idprodfournprice', 'alpha')) ? GETPOST('idprodfournprice', 'alpha') : -1);
977 $buyingprice = 0;
978
979 $result = $object->addline(
980 $desc,
981 ($price_base_type == 'HT' ? $pu : 0),
982 (float) $qty,
983 $tva_tx,
984 $localtax1_tx,
985 $localtax2_tx,
986 $productsupplier->id,
987 $remise_percent,
988 $price_base_type,
989 ($price_base_type == 'TTC' ? $pu : 0),
990 $tva_npr,
991 $type,
992 min($rank, count($object->lines) + 1),
993 0,
994 GETPOSTINT('fk_parent_line'),
995 (int) $fournprice,
996 $buyingprice,
997 $label,
998 $array_options,
999 $ref_supplier,
1000 $productsupplier->fk_unit,
1001 '',
1002 0,
1003 $pu_devise,
1005 $date_end
1006 );
1007
1008 //var_dump($tva_tx);
1009 //var_dump($productsupplier->fourn_pu);
1010 //var_dump($price_base_type);exit;
1011 if ($result < 0) {
1012 $error++;
1013 setEventMessages($object->error, $object->errors, 'errors');
1014 }
1015 }
1016 if ($idprod == -99 || $idprod == 0) {
1017 // Product not selected
1018 $error++;
1019 $langs->load("errors");
1020 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")).' '.$langs->trans("or").' '.$langs->trans("NoPriceDefinedForThisSupplier"), null, 'errors');
1021 }
1022 if ($idprod == -1) {
1023 // Quantity too low
1024 $error++;
1025 $langs->load("errors");
1026 setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors');
1027 }
1028 } elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '' || GETPOST('multicurrency_price_ht') != '') && empty($error)) { // Free product. // $price_ht is already set
1029 $pu_ht = price2num($price_ht, 'MU');
1030 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
1031
1032 $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
1033 $tva_tx = str_replace('*', '', $tva_tx);
1034 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1035 $desc = $line_desc;
1036 $type = GETPOSTINT('type');
1037
1038 $fk_unit = GETPOSTINT('units');
1039
1040 if (!preg_match('/\‍((.*)\‍)/', $tva_tx)) {
1041 $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'
1042 }
1043
1044 // Local Taxes
1045 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1046 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1047
1048 // Keep the entry mode chosen by the user so the total is computed from the typed value (no rounding drift).
1049 if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
1050 $price_base_type = 'HT';
1051 $pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
1052 $pu_ttc = 0;
1053 $pu_ht_devise = price2num($price_ht_devise, 'CU');
1054 } else {
1055 $price_base_type = 'TTC';
1056 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
1057 $pu_ht = 0;
1058 $pu_ht_devise = price2num($price_ttc_devise, 'CU');
1059 }
1060 $info_bits = 0;
1061
1062 $result = $object->addline(
1063 $desc,
1064 (float) $pu_ht,
1065 (float) $qty,
1066 $tva_tx, // don't cast to float
1067 $localtax1_tx,
1068 $localtax2_tx,
1069 $idprod,
1070 $remise_percent,
1071 $price_base_type,
1072 (float) $pu_ttc,
1073 $info_bits,
1074 $type,
1075 -1, // rang
1076 0, // special_code
1077 GETPOSTINT('fk_parent_line'),
1078 (int) $fournprice,
1079 $buyingprice,
1080 $label,
1081 $array_options,
1082 $ref_supplier,
1083 $fk_unit,
1084 '', // origin
1085 0, // origin_id
1086 (float) $pu_ht_devise
1087 );
1088 }
1089
1090
1091 if (!$error && $result > 0) {
1092 $db->commit();
1093
1094 $ret = $object->fetch($object->id); // Reload to get new records
1095
1096 // Define output language
1097 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1098 $outputlangs = $langs;
1099 $newlang = '';
1100 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1101 $newlang = GETPOST('lang_id', 'aZ09');
1102 }
1103 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1104 $newlang = $object->thirdparty->default_lang;
1105 }
1106 if (!empty($newlang)) {
1107 $outputlangs = new Translate("", $conf);
1108 $outputlangs->setDefaultLang($newlang);
1109 }
1110 $model = $object->model_pdf;
1111 $ret = $object->fetch($id); // Reload to get new records
1112 if ($ret > 0) {
1113 $object->fetch_thirdparty();
1114 }
1115
1116 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1117 if ($result < 0) {
1118 dol_print_error($db, $object->error, $object->errors);
1119 }
1120 }
1121
1122 unset($_POST['prod_entry_mode']);
1123
1124 unset($_POST['qty']);
1125 unset($_POST['type']);
1126 unset($_POST['remise_percent']);
1127 unset($_POST['pu']);
1128 unset($_POST['price_ht']);
1129 unset($_POST['multicurrency_price_ht']);
1130 unset($_POST['price_ttc']);
1131 unset($_POST['fourn_ref']);
1132 unset($_POST['tva_tx']);
1133 unset($_POST['label']);
1134 unset($_POST['product_ref']);
1135 unset($_POST['product_label']);
1136 unset($_POST['product_desc']);
1137 unset($_POST['fournprice']);
1138 unset($_POST['buying_price']);
1139 unset($localtax1_tx);
1140 unset($localtax2_tx);
1141 unset($_POST['np_marginRate']);
1142 unset($_POST['np_markRate']);
1143 unset($_POST['dp_desc']);
1144 unset($_POST['idprodfournprice']);
1145 unset($_POST['units']);
1146
1147 unset($_POST['idprod']);
1148
1149 unset($_POST['date_starthour']);
1150 unset($_POST['date_startmin']);
1151 unset($_POST['date_startsec']);
1152 unset($_POST['date_startday']);
1153 unset($_POST['date_startmonth']);
1154 unset($_POST['date_startyear']);
1155 unset($_POST['date_endhour']);
1156 unset($_POST['date_endmin']);
1157 unset($_POST['date_endsec']);
1158 unset($_POST['date_endday']);
1159 unset($_POST['date_endmonth']);
1160 unset($_POST['date_endyear']);
1161 } else {
1162 $db->rollback();
1163
1164 setEventMessages($object->error, $object->errors, 'errors');
1165 }
1166 }
1167 } elseif ($action == 'updatetitleline' && GETPOSTISSET("save") && $usercancreate && !GETPOST('cancel', 'alpha')) {
1168 // Handling updating a title line for subtotals module
1169
1170 $langs->load('subtotals');
1171
1172 $desc = GETPOST('line_desc', 'alphanohtml') ?? $langs->trans("Title");
1173 $depth = GETPOSTINT('line_depth') ?? 1;
1174
1175 $subtotal_options = array();
1176
1177 foreach (SupplierProposal::$TITLE_OPTIONS as $option) {
1178 $value = GETPOST($option, 'alphanohtml');
1179 if ($value) {
1180 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
1181 }
1182 }
1183
1184 // Update line
1185 $result = $object->updateSubtotalLine($langs, GETPOSTINT('lineid'), $desc, $depth, $subtotal_options);
1186
1187 if ($result >= 0) {
1188 if ($result == 0) {
1189 setEventMessages($object->error, $object->errors, 'warnings');
1190 }
1191 $ret = $object->fetch($object->id); // Reload to get new records
1192 $object->fetch_thirdparty();
1193
1194 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1195 // Define output language
1196 $outputlangs = $langs;
1197 $newlang = GETPOST('lang_id', 'alpha');
1198 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1199 $newlang = $object->thirdparty->default_lang;
1200 }
1201 if (!empty($newlang)) {
1202 $outputlangs = new Translate("", $conf);
1203 $outputlangs->setDefaultLang($newlang);
1204 }
1205
1206 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1207 }
1208 } else {
1209 setEventMessages($object->error, $object->errors, 'errors');
1210 }
1211 } elseif ($action == 'updatetextline' && GETPOSTISSET("save") && $usercancreate && !GETPOST('cancel', 'alpha')) {
1212 // Handling updating a text line for subtotals module
1213
1214 $langs->load('subtotals');
1215
1216 $desc = GETPOST('line_desc', 'restricthtml');
1217
1218 // Update line
1219 $result = $object->updateSubtotalLine($langs, GETPOSTINT('lineid'), $desc, 0, array());
1220
1221 if ($result >= 0) {
1222 if ($result == 0) {
1223 setEventMessages($object->error, $object->errors, 'warnings');
1224 }
1225 $ret = $object->fetch($object->id); // Reload to get new records
1226 $object->fetch_thirdparty();
1227
1228 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1229 // Define output language
1230 $outputlangs = $langs;
1231 $newlang = GETPOST('lang_id', 'alpha');
1232 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1233 $newlang = $object->thirdparty->default_lang;
1234 }
1235 if (!empty($newlang)) {
1236 $outputlangs = new Translate("", $conf);
1237 $outputlangs->setDefaultLang($newlang);
1238 }
1239
1240 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1241 }
1242 } else {
1243 setEventMessages($object->error, $object->errors, 'errors');
1244 }
1245 } elseif ($action == 'updatesubtotalline' && GETPOSTISSET("save") && $usercancreate && !GETPOST('cancel', 'alpha')) {
1246 // Handling updating a subtotal line for subtotals module
1247
1248 $langs->load('subtotals');
1249
1250 $desc = GETPOST('line_desc', 'alphanohtml');
1251 $depth = GETPOSTINT('line_depth');
1252
1253 $subtotal_options = array();
1254
1255 foreach (SupplierProposal::$SUBTOTAL_OPTIONS as $option) {
1256 $value = GETPOST($option, 'alphanohtml');
1257 if ($value) {
1258 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
1259 }
1260 }
1261
1262 // Update line
1263 $result = $object->updateSubtotalLine($langs, GETPOSTINT('lineid'), $desc, $depth, $subtotal_options);
1264
1265 if ($result > 0) {
1266 $ret = $object->fetch($object->id); // Reload to get new records
1267 $object->fetch_thirdparty();
1268
1269 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1270 // Define output language
1271 $outputlangs = $langs;
1272 $newlang = GETPOST('lang_id', 'alpha');
1273 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1274 $newlang = $object->thirdparty->default_lang;
1275 }
1276 if (!empty($newlang)) {
1277 $outputlangs = new Translate("", $conf);
1278 $outputlangs->setDefaultLang($newlang);
1279 }
1280
1281 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1282 }
1283 } else {
1284 setEventMessages($object->error, $object->errors, 'errors');
1285 }
1286 } elseif ($action == 'updateline' && $usercancreate && GETPOST('save') == $langs->trans("Save")) {
1287 // Update a line within proposal
1288 $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
1289 $pu_ht = price2num(GETPOST('price_ht'), '', 2);
1290 $pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
1291
1292 // Define info_bits
1293 $info_bits = 0;
1294 if (preg_match('/\*/', $vat_rate)) {
1295 $info_bits |= 0x01;
1296 }
1297
1298 // Clean parameters
1299 $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
1300
1301 // Define vat_rate
1302 $vat_rate = str_replace('*', '', $vat_rate);
1303 $localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
1304 $localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
1305
1306 $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), 'CU', 2);
1307
1308 // Add buying price
1309 $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
1310 $buyingprice = price2num((GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''), '', 2); // If buying_price is '0', we must keep this value
1311
1312 // Extrafields Lines
1313 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1314 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1315 // Unset extrafield POST Data
1316 if (is_array($extralabelsline)) {
1317 foreach ($extralabelsline as $key => $value) {
1318 unset($_POST["options_".$key]);
1319 }
1320 }
1321
1322 // Define special_code for special lines
1323 $special_code = GETPOST('special_code');
1324 if (!GETPOST('qty')) {
1325 $special_code = 3;
1326 }
1327
1328 // The form JS clears the other field when the user edits one of them: only the modified field is filled.
1329 // When both fields are submitted, the user did not change the price - we must preserve the original
1330 // storage mode of the line, otherwise a no-op save would shift the total by rounding.
1331 $ht = $pu_ht;
1332 $price_base_type = 'HT';
1333 if (empty($pu_ht) && !empty($pu_ttc)) {
1334 $ht = $pu_ttc;
1335 $price_base_type = 'TTC';
1336 } elseif (!empty($pu_ht) && !empty($pu_ttc)) {
1337 foreach ($object->lines as $line_obj) {
1338 if ($line_obj->id == GETPOSTINT('lineid')) {
1339 // Line was originally entered in TTC mode (subprice_ttc filled by addline)
1340 if ($line_obj->wasEnteredIncludingTax()) {
1341 $ht = $pu_ttc;
1342 $price_base_type = 'TTC';
1343 }
1344 break;
1345 }
1346 }
1347 }
1348
1349 // Check minimum price
1350 $productid = GETPOSTINT('productid');
1351 if (!empty($productid)) {
1352 $productsupplier = new ProductFournisseur($db);
1353 if (getDolGlobalInt('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY') == 1) { // Not the common case
1354 if ($productid > 0 && $productsupplier->get_buyprice(0, (float) price2num(GETPOST('qty')), $productid, 'none', GETPOSTINT('socid')) < 0) {
1355 setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'warnings');
1356 }
1357 }
1358
1359 $product = new Product($db);
1360 $res = $product->fetch($productid);
1361
1362 $type = $product->type;
1363
1364 $price_min = $product->price_min;
1365 if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
1366 $price_min = $product->multiprices_min [$object->thirdparty->price_level];
1367 }
1368
1369 $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
1370 } else {
1371 $type = GETPOST('type');
1372 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1373
1374 // Check parameters
1375 if (GETPOST('type') < 0) {
1376 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1377 $error++;
1378 }
1379 }
1380
1381 if (!$error) {
1382 $db->begin();
1383
1384 $ref_supplier = GETPOST('fourn_ref', 'alpha');
1385 $fk_unit = GETPOSTINT('units');
1386
1387 // In TTC mode, do not forward the HT currency price: under multicurrency updateline() would reset
1388 // the local price and recompute from the HT currency amount (read as TTC) -> the TTC value is lost.
1389 if ($price_base_type === 'TTC') {
1390 $pu_ht_devise = 0;
1391 }
1392
1393 // Only the unit price incl. tax in currency was entered: it becomes the reference price of the line.
1394 // updateline() reads the currency price in the price_base_type, so it receives the TTC currency amount.
1395 if (GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && GETPOST('multicurrency_subprice') === '' && GETPOST('multicurrency_price_ttc') !== '') {
1396 $ht = 0;
1397 $price_base_type = 'TTC';
1398 $pu_ht_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
1399 }
1400
1401 $result = $object->updateline(
1402 GETPOSTINT('lineid'),
1403 (float) $ht,
1404 (float) price2num(GETPOST('qty'), 'MS', 2),
1405 (float) price2num(GETPOST('remise_percent'), '', 2),
1406 $vat_rate,
1407 $localtax1_rate,
1408 $localtax2_rate,
1409 $description,
1410 $price_base_type,
1411 $info_bits,
1412 $special_code,
1413 GETPOSTINT('fk_parent_line'),
1414 0,
1415 (int) $fournprice,
1416 $buyingprice,
1417 $label,
1418 $type,
1419 $array_options,
1420 $ref_supplier,
1421 $fk_unit,
1422 (float) $pu_ht_devise
1423 );
1424
1425 if ($result >= 0) {
1426 $db->commit();
1427
1428 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1429 // Define output language
1430 $outputlangs = $langs;
1431 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1432 $outputlangs = new Translate("", $conf);
1433 $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
1434 $outputlangs->setDefaultLang($newlang);
1435 }
1436 $ret = $object->fetch($id); // Reload to get new records
1437 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1438 }
1439
1440 unset($_POST['qty']);
1441 unset($_POST['type']);
1442 unset($_POST['productid']);
1443 unset($_POST['remise_percent']);
1444 unset($_POST['price_ht']);
1445 unset($_POST['multicurrency_price_ht']);
1446 unset($_POST['price_ttc']);
1447 unset($_POST['tva_tx']);
1448 unset($_POST['product_ref']);
1449 unset($_POST['product_label']);
1450 unset($_POST['product_desc']);
1451 unset($_POST['fournprice']);
1452 unset($_POST['buying_price']);
1453
1454 unset($_POST['date_starthour']);
1455 unset($_POST['date_startmin']);
1456 unset($_POST['date_startsec']);
1457 unset($_POST['date_startday']);
1458 unset($_POST['date_startmonth']);
1459 unset($_POST['date_startyear']);
1460 unset($_POST['date_endhour']);
1461 unset($_POST['date_endmin']);
1462 unset($_POST['date_endsec']);
1463 unset($_POST['date_endday']);
1464 unset($_POST['date_endmonth']);
1465 unset($_POST['date_endyear']);
1466 } else {
1467 $db->rollback();
1468
1469 setEventMessages($object->error, $object->errors, 'errors');
1470 }
1471 }
1472 } elseif ($action == 'updateline' && $usercancreate && $cancel) {
1473 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To re-display card in edit mode
1474 exit();
1475 } elseif ($action == 'classin' && $usercancreate) {
1476 // Set project
1477 $object->setProject(GETPOSTINT('projectid'));
1478 } elseif ($action == 'setavailability' && $usercancreate) {
1479 // Delivery delay
1480 $result = $object->availability(GETPOST('availability_id'));
1481 } elseif ($action == 'setconditions' && $usercancreate) {
1482 // Terms of payments
1483 $sql = "SELECT code ";
1484 $sql .= "FROM " . $db->prefix() . "c_payment_term";
1485 $sql .= " WHERE rowid = " . GETPOSTINT('cond_reglement_id');
1486 $result = $db->query($sql);
1487 if ($result) {
1488 $obj = $db->fetch_object($result);
1489 if ($obj->code == 'DEP30PCTDEL') {
1490 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id'), GETPOSTFLOAT('cond_reglement_id_deposit_percent'));
1491 } else {
1492 $object->deposit_percent = 0;
1493 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id'), $object->deposit_percent);
1494 }
1495 }
1496 } elseif ($action == 'setmode' && $usercancreate) {
1497 // Payment mode
1498 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
1499 } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
1500 // Multicurrency Code
1501 $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
1502 } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
1503 // Multicurrency rate
1504 if (!in_array(GETPOSTINT('calculation_mode'), array(1, 2))) {
1505 $langs->load("compta");
1506 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CalculationMode")), null, 'errors');
1507 $action = 'editmulticurrencyrate';
1508 } else {
1509 $result = $object->setMulticurrencyRate(GETPOSTFLOAT('multicurrency_tx'), GETPOSTINT('calculation_mode'));
1510 }
1511 } elseif ($action == 'update_extras' && $permissiontoeditextra) {
1512 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
1513
1514 $attribute_name = GETPOST('attribute', 'aZ09');
1515
1516 // Fill array 'array_options' with data from update form
1517 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
1518 if ($ret < 0) {
1519 $error++;
1520 }
1521
1522 if (!$error) {
1523 $result = $object->updateExtraField($attribute_name, 'PROPOSAL_SUPPLIER_MODIFY');
1524 if ($result < 0) {
1525 setEventMessages($object->error, $object->errors, 'errors');
1526 $error++;
1527 }
1528 }
1529
1530 if ($error) {
1531 $action = 'edit_extras';
1532 }
1533 }
1534}
1535
1536
1537/*
1538 * View
1539 */
1540
1541$title = $object->ref." - ".$langs->trans('Card');
1542if ($action == 'create') {
1543 $title = $langs->trans("SupplierProposalNew");
1544}
1545$help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
1546
1547llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-supplierproposal page-card');
1548
1549$form = new Form($db);
1550$formother = new FormOther($db);
1551$formfile = new FormFile($db);
1552$formmargin = new FormMargin($db);
1553$companystatic = new Societe($db);
1554if (isModEnabled('project')) {
1555 $formproject = new FormProjets($db);
1556}
1557
1558$now = dol_now();
1559
1560// Add new askprice
1561if ($action == 'create') {
1562 $currency_code = $conf->currency;
1563
1564 print load_fiche_titre($langs->trans("SupplierProposalNew"), '', 'supplier_proposal');
1565
1566 $soc = new Societe($db);
1567 if ($socid > 0) {
1568 $res = $soc->fetch($socid);
1569 }
1570
1571 // Load objectsrc
1572 if (!empty($origin) && !empty($originid)) {
1573 // Resolve and load the source object from its element type (propal, commande, ...)
1574 $objectsrc = fetchObjectByElement($originid, $origin);
1575
1576 if (is_object($objectsrc)) {
1577 '@phan-var-force Commande|Propal|CommandeFournisseur|SupplierProposal $objectsrc'; // Could be other classes, but CommonObject is too generic
1579 $classname = get_class($objectsrc);
1580
1581 if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1582 $objectsrc->fetch_lines();
1583 }
1584 $objectsrc->fetch_thirdparty();
1585
1586 $projectid = (int) $objectsrc->fk_project;
1587 $soc = $objectsrc->thirdparty;
1588
1589 $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
1590 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : 0));
1591 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1592 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1593
1594 // Replicate extrafields
1595 $objectsrc->fetch_optionals();
1596 $object->array_options = $objectsrc->array_options;
1597
1598 if (isModEnabled("multicurrency")) {
1599 if (!empty($objectsrc->multicurrency_code)) {
1600 $currency_code = $objectsrc->multicurrency_code;
1601 }
1602 if (getDolGlobalString('MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1603 $currency_tx = $objectsrc->multicurrency_tx;
1604 }
1605 }
1606 } else {
1607 $objectsrc = null;
1608 $cond_reglement_id = (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0);
1609 $deposit_percent = (!empty($soc->deposit_percent) ? $soc->deposit_percent : 0);
1610 $mode_reglement_id = (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0);
1611 $fk_account = (!empty($soc->fk_account) ? $soc->fk_account : 0);
1612 }
1613 } else {
1614 $cond_reglement_id = $soc->cond_reglement_supplier_id;
1615 $deposit_percent = !empty($soc->deposit_percent) ? $soc->deposit_percent : 0;
1616 $mode_reglement_id = $soc->mode_reglement_supplier_id;
1617 $fk_account = !empty($soc->fk_account) ? $soc->fk_account : 0;
1618 if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) {
1619 $currency_code = $soc->multicurrency_code;
1620 }
1621 }
1622 if (GETPOSTISSET('cond_reglement_id_deposit_percent')) {
1623 $deposit_percent = GETPOSTFLOAT('cond_reglement_id_deposit_percent');
1624 }
1625
1626 $object = new SupplierProposal($db);
1627
1628 print '<form name="addprop" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1629 print '<input type="hidden" name="token" value="'.newToken().'">';
1630 print '<input type="hidden" name="action" value="add">';
1631 if ($origin != 'project' && $originid) {
1632 print '<input type="hidden" name="origin" value="'.$origin.'">';
1633 print '<input type="hidden" name="originid" value="'.$originid.'">';
1634 }
1635 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1636 if ($backtopageforcancel) {
1637 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
1638 }
1639
1640 print dol_get_fiche_head();
1641
1642 // Call Hook tabContentCreateSupplierProposal
1643 $parameters = array();
1644 // Note that $action and $object may be modified by hook
1645 $reshook = $hookmanager->executeHooks('tabContentCreateSupplierProposal', $parameters, $object, $action);
1646 if (empty($reshook)) {
1647 print '<table class="border centpercent">';
1648
1649 // Reference
1650 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
1651
1652 // Third party
1653 print '<tr>';
1654 print '<td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
1655 if ($socid > 0) {
1656 print '<td colspan="2">';
1657 print $soc->getNomUrl(1, 'supplier');
1658 print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1659 print '</td>';
1660 } else {
1661 print '<td colspan="2">';
1662 $filter = '((s.fournisseur:=:1) AND (s.status:=:1))';
1663 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company((empty($socid) ? '' : $socid), 'socid', $filter, 'SelectThirdParty', 1, 0, array(), 0, 'minwidth175 maxwidth500 widthcentpercentminusxx');
1664 // reload page to retrieve customer information
1665 if (!getDolGlobalString('RELOAD_PAGE_ON_SUPPLIER_CHANGE_DISABLED')) {
1666 print '<script>
1667 $(document).ready(function() {
1668 $("#socid").change(function() {
1669 console.log("We have changed the company - Reload page");
1670 // reload page
1671 $("input[name=action]").val("create");
1672 $("form[name=addprop]").submit();
1673 });
1674 });
1675 </script>';
1676 }
1677 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>';
1678 print '</td>';
1679 }
1680 print '</tr>'."\n";
1681
1682 if ($soc->id > 0) {
1683 // Discounts for third party
1684 print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
1685
1686 $absolute_discount = $soc->getAvailableDiscounts(null, '', 0, 1);
1687
1688 $thirdparty = $soc;
1689 $discount_type = 1;
1690 $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
1691 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1692
1693 print '</td></tr>';
1694 }
1695
1696 // Terms of payment
1697 print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
1698 print img_picto('', 'payment', 'class="pictofixedwidth"');
1699 print $form->getSelectConditionsPaiements(GETPOSTISSET('cond_reglement_id') ? GETPOSTINT('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id', -1, 1, 0, '', $deposit_percent);
1700 print '</td></tr>';
1701
1702 // Mode of payment
1703 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
1704 print img_picto('', 'bank', 'class="pictofixedwidth"');
1705 $form->select_types_paiements(GETPOST('mode_reglement_id') > 0 ? GETPOST('mode_reglement_id') : $mode_reglement_id, 'mode_reglement_id');
1706 print '</td></tr>';
1707
1708 // Bank Account
1709 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL') && isModEnabled("bank")) {
1710 print '<tr><td>'.$langs->trans('BankAccount').'</td><td colspan="2">';
1711 print img_picto('', 'bank', 'class="pictofixedwidth"');
1712 $form->select_comptes(GETPOST('fk_account') > 0 ? GETPOSTINT('fk_account') : $fk_account, 'fk_account', 0, '', 1);
1713 print '</td></tr>';
1714 }
1715
1716 // Shipping Method
1717 if (isModEnabled("shipping")) {
1718 print '<tr><td>'.$langs->trans('SendingMethod').'</td><td colspan="2">';
1719 print img_picto('', 'dolly', 'class="pictofixedwidth"');
1720 $form->selectShippingMethod(GETPOST('shipping_method_id') > 0 ? GETPOSTINT('shipping_method_id') : "", 'shipping_method_id', '', 1);
1721 print '</td></tr>';
1722 }
1723
1724 // Delivery date (or manufacturing)
1725 print '<tr><td>'.$langs->trans("DeliveryDate").'</td>';
1726 print '<td colspan="2">';
1727 print img_picto('', 'action', 'class="pictofixedwidth"');
1728 $datedelivery = dol_mktime(0, 0, 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
1729 if (is_numeric(getDolGlobalString('DATE_LIVRAISON_WEEK_DELAY'))) { // If value set to 0 or a num, not empty
1730 $tmpdte = dol_now() + (7 * getDolGlobalInt('DATE_LIVRAISON_WEEK_DELAY') * 24 * 60 * 60);
1731 $syear = dol_print_date($tmpdte, "Y");
1732 $smonth = dol_print_date($tmpdte, "m");
1733 $sday = dol_print_date($tmpdte, "d");
1734 print $form->selectDate($syear."-".$smonth."-".$sday, 'liv_', 0, 0, 0, "addask");
1735 } else {
1736 print $form->selectDate($datedelivery ? $datedelivery : -1, 'liv_', 0, 0, 0, "addask", 1, 1);
1737 }
1738 print '</td></tr>';
1739
1740
1741 // Model
1743 if (count($list) > 0) {
1744 print '<tr>';
1745 print '<td>'.$langs->trans("DefaultModel").'</td>';
1746 print '<td colspan="2">';
1747 print img_picto('', 'pdf', 'class="pictofixedwidth"');
1748 $preselected = getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT', getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF'));
1749 print $form->selectarray('model', $list, $preselected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
1750 print "</td></tr>";
1751 }
1752
1753 // Project
1754 if (isModEnabled('project')) {
1755 $langs->load("projects");
1756
1757 $formproject = new FormProjets($db);
1758
1759 if ($origin == 'project') {
1760 $projectid = ($originid ? $originid : 0);
1761 }
1762
1763 print '<tr>';
1764 print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
1765 if (!empty($user->socid)) { // external user: restrict to their own third party
1766 $projSocFilter = $user->socid;
1767 } elseif (getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') || $socid == 0) {
1768 // Give priority to the constant (as on supplier invoice), so a supplier document created from a
1769 // customer project keeps that project selected after the supplier is chosen.
1770 $projSocFilter = -1;
1771 } else {
1772 $projSocFilter = $socid;
1773 }
1774 print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects($projSocFilter, $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
1775 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.((int) $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>';
1776 print '</td>';
1777 print '</tr>';
1778 }
1779
1780 // Multicurrency
1781 if (isModEnabled("multicurrency")) {
1782 print '<tr>';
1783 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1784 print '<td colspan="3" class="maxwidthonsmartphone">';
1785 print img_picto('', 'currency', 'class="pictofixedwidth"');
1786 print $form->selectMultiCurrency($currency_code, 'multicurrency_code');
1787 print '</td></tr>';
1788 }
1789 // Categories
1790 if (isModEnabled('category')) {
1791 print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
1792 print $form->selectCategories(Categorie::TYPE_SUPPLIER_PROPOSAL, 'categories', $object);
1793 print "</td></tr>";
1794 }
1795
1796 // Other attributes
1797 $parameters = array('colspan' => ' colspan="3"', 'cols' => 3);
1798 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1799 print $hookmanager->resPrint;
1800 if (empty($reshook)) {
1801 print $object->showOptionals($extrafields, 'create', $parameters);
1802 }
1803
1804
1805 // Lines from source
1806 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && $classname !== null) {
1807 // TODO for compatibility
1808 if ($origin == 'contrat') {
1809 // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
1810 $objectsrc->update_price(1, 'auto', 1);
1811 }
1812
1813 print "\n<!-- ".$classname." info -->";
1814 print "\n";
1815 print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
1816 print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
1817 print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
1818 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1819 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1820
1821 print '<tr><td>'.$langs->trans('CommRequest').'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
1822 print '<tr><td>'.$langs->trans('AmountHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
1823 print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
1824 if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1
1825 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
1826 }
1827
1828 if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2
1829 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
1830 }
1831 print '<tr><td>'.$langs->trans('AmountTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
1832
1833 if (isModEnabled("multicurrency")) {
1834 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>';
1835 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>";
1836 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>";
1837 }
1838 }
1839
1840 print "</table>\n";
1841
1842
1843 /*
1844 * Combobox for copy function
1845 */
1846
1847 if (!getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
1848 print '<input type="hidden" name="createmode" value="empty">';
1849 }
1850
1851 if (getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
1852 print '<br><table>';
1853
1854 // For backward compatibility
1855 print '<tr>';
1856 print '<td><input type="radio" name="createmode" value="copy"></td>';
1857 print '<td>'.$langs->trans("CopyAskFrom").' </td>';
1858 print '<td>';
1859 $liste_ask = array();
1860 $liste_ask [0] = '';
1861
1862 $sql = "SELECT p.rowid as id, p.ref, s.nom";
1863 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal p";
1864 $sql .= ", ".MAIN_DB_PREFIX."societe s";
1865 $sql .= " WHERE s.rowid = p.fk_soc";
1866 $sql .= " AND p.entityy IN (".getEntity('supplier_proposal').")";
1867 $sql .= " AND p.fk_statut <> ".SupplierProposal::STATUS_DRAFT;
1868 $sql .= " ORDER BY Id";
1869
1870 $resql = $db->query($sql);
1871 if ($resql) {
1872 $num = $db->num_rows($resql);
1873 $i = 0;
1874 while ($i < $num) {
1875 $row = $db->fetch_row($resql);
1876 $askPriceSupplierRefAndSocName = $row[1]." - ".$row[2];
1877 $liste_ask[$row[0]] = $askPriceSupplierRefAndSocName;
1878 $i++;
1879 }
1880 print $form->selectarray("copie_supplier_proposal", $liste_ask, 0);
1881 } else {
1882 dol_print_error($db);
1883 }
1884 print '</td></tr>';
1885
1886 print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
1887 print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyAsk").'</td></tr>';
1888 }
1889
1890 if (getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
1891 print '</table>';
1892 }
1893 }
1894
1895 print dol_get_fiche_end();
1896
1897 print $form->buttonsSaveCancel("CreateDraft");
1898
1899 print "</form>";
1900
1901
1902 // Show origin lines
1903 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1904 print '<br>';
1905
1906 $title = $langs->trans('ProductsAndServices');
1907 print load_fiche_titre($title);
1908
1909 print '<div class="div-table-responsive-no-min">';
1910 print '<table class="noborder centpercent">';
1911
1912 $objectsrc->printOriginLinesList();
1913
1914 print '</table>';
1915 print '</div>';
1916 }
1917} else {
1918 /*
1919 * Show object in view mode
1920 */
1921
1922 $soc = new Societe($db);
1923 $soc->fetch($object->socid);
1924
1925 $head = supplier_proposal_prepare_head($object);
1926 print dol_get_fiche_head($head, 'comm', $langs->trans('CommRequest'), -1, 'supplier_proposal', 0, '', '', 0, '', 1);
1927
1928 $formconfirm = '';
1929
1930 // Clone confirmation
1931 if ($action == 'clone') {
1932 $filter = '(s.fournisseur:=:1)';
1933 // Create an array for form
1934 $formquestion = array(
1935 // 'text' => $langs->trans("ConfirmClone"),
1936 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
1937 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' =>
1938 // 1),
1939 array(
1940 'type' => 'other',
1941 'name' => 'socid',
1942 'label' => $langs->trans("SelectThirdParty"),
1943 'value' => $form->select_company(GETPOSTINT('socid'), 'socid', $filter))
1944 );
1945 // Paiement incomplet. On demande si motif = escompte ou autre
1946 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1947 } elseif ($action == 'delete') {
1948 // Confirm delete
1949 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAsk'), $langs->trans('ConfirmDeleteAsk', $object->ref), 'confirm_delete', '', 0, 1);
1950 } elseif ($action == 'reopen') {
1951 // Confirm reopen
1952 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenAsk', $object->ref), 'confirm_reopen', '', 0, 1);
1953 } elseif ($action == 'ask_deleteline') {
1954 // Confirmation delete product/service line
1955 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
1956 } elseif ($action == 'ask_subtotal_deleteline') {
1957 // Generate form to ask confirmation to delete a subtotal line
1958 $langs->load("subtotals");
1959 $title = "DeleteSubtotalLine";
1960 $question = "ConfirmDeleteSubtotalLine";
1961 if (GETPOST('type') == 'title') {
1962 $formconfirm = [
1963 [
1964 'type' => 'checkbox',
1965 'name' => 'deletecorrespondingsubtotalline',
1966 'label' => $langs->trans("DeleteCorrespondingSubtotalLine"),
1967 'value' => 0,
1968 ],
1969 ];
1970 $title = "DeleteTitleLine";
1971 $question = "ConfirmDeleteTitleLine";
1972 }
1973 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans($title), $langs->trans($question), 'confirm_delete_subtotalline', $formconfirm, 'no', 1);
1974 } elseif ($action == 'validate') {
1975 // Confirm validate askprice
1976 $error = 0;
1977
1978 // Verify if the object has a temporary number
1979 $ref = substr($object->ref, 1, 4);
1980 if ($ref == 'PROV') {
1981 $numref = $object->getNextNumRef($soc);
1982 if (empty($numref)) {
1983 $error++;
1984 setEventMessages($object->error, $object->errors, 'errors');
1985 }
1986 } else {
1987 $numref = (string) $object->ref;
1988 }
1989
1990 $text = $langs->trans('ConfirmValidateAsk', $numref);
1991 if (isModEnabled('notification')) {
1992 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1993 $notify = new Notify($db);
1994 $text .= '<br>';
1995 $text .= $notify->confirmMessage('PROPOSAL_SUPPLIER_VALIDATE', $object->socid, $object);
1996 }
1997
1998 if (!$error) {
1999 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateAsk'), $text, 'confirm_validate', '', 0, 1);
2000 }
2001 }
2002 // Subtotal line form
2003 if ($action == 'add_title_line') {
2004 $langs->load('subtotals');
2005 $type = 'title';
2006 $depth_array = $object->getPossibleLevels($langs);
2007 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
2008 } elseif ($action == 'add_subtotal_line') {
2009 $langs->load('subtotals');
2010 $type = 'subtotal';
2011 $titles = $object->getPossibleTitles();
2012 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
2013 } elseif ($action == 'add_text_line') {
2014 $langs->load('subtotals');
2015 $type = 'text';
2016 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
2017 }
2018
2019 // Call Hook formConfirm
2020 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
2021 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2022 if (empty($reshook)) {
2023 $formconfirm .= $hookmanager->resPrint;
2024 } elseif ($reshook > 0) {
2025 $formconfirm = $hookmanager->resPrint;
2026 }
2027
2028 // Print form confirm
2029 print $formconfirm;
2030
2031
2032 // Supplier proposal card
2033 $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
2034
2035
2036 $morehtmlref = '<div class="refidno">';
2037 // Ref supplier
2038 //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', 0, 1);
2039 //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', null, null, '', 1);
2040 // Thirdparty
2041 $morehtmlref .= $object->thirdparty->getNomUrl(1, 'supplier');
2042 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
2043 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherProposals").'</a>)';
2044 }
2045 // Project
2046 if (isModEnabled('project')) {
2047 $langs->load("projects");
2048 $morehtmlref .= '<br>';
2049 if ($usercancreate) {
2050 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
2051 if ($action != 'classify') {
2052 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
2053 }
2054 $canLinkAll = getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS');
2055 $canLinkAll = ($canLinkAll === '' || $canLinkAll === false) ? 0 : $canLinkAll;
2056 $currentSocId = ($object->id > 0) ? $object->socid : $socid;
2057 $projectSocId = ((int) $canLinkAll == 1) ? -1 : $currentSocId;
2058 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $projectSocId, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
2059 } else {
2060 if (!empty($object->fk_project)) {
2061 $proj = new Project($db);
2062 $proj->fetch($object->fk_project);
2063 $morehtmlref .= $proj->getNomUrl(1);
2064 if ($proj->title) {
2065 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
2066 }
2067 }
2068 }
2069 }
2070 $morehtmlref .= '</div>';
2071
2072
2073 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
2074
2075 // Call Hook tabContentViewSupplierProposal
2076 $parameters = array();
2077 // Note that $action and $object may be modified by hook
2078 $reshook = $hookmanager->executeHooks('tabContentViewSupplierProposal', $parameters, $object, $action);
2079 if (empty($reshook)) {
2080 print '<div class="fichecenter">';
2081 print '<div class="fichehalfleft">';
2082 print '<div class="underbanner clearboth"></div>';
2083
2084 print '<table class="border tableforfield centpercent">';
2085
2086 // Relative and absolute discounts
2087 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
2088 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
2089 $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
2090 } else {
2091 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2092 $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2093 }
2094
2095 print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td>';
2096
2097 $absolute_discount = $soc->getAvailableDiscounts(null, $filterabsolutediscount, 0, 1);
2098 $absolute_creditnote = $soc->getAvailableDiscounts(null, $filtercreditnote, 0, 1);
2099 $absolute_discount = price2num($absolute_discount, 'MT');
2100 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
2101
2102 $thirdparty = $soc;
2103 $discount_type = 1;
2104 $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
2105 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
2106
2107 print '</td></tr>';
2108
2109 // Payment term
2110 print '<tr><td class="titlefield">';
2111 print '<table class="nobordernopadding" width="100%"><tr><td>';
2112 print $langs->trans('PaymentConditionsShort');
2113 print '</td>';
2114 if ($action != 'editconditions' && $object->status != SupplierProposal::STATUS_NOTSIGNED) {
2115 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>';
2116 }
2117 print '</tr></table>';
2118 print '</td><td class="valuefield">';
2119 if ($action == 'editconditions') {
2120 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent);
2121 } else {
2122 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->cond_reglement_id, 'none', 1, '', 1, $object->deposit_percent);
2123 }
2124 print '</td>';
2125 print '</tr>';
2126
2127 // Delivery date
2128 print '<tr><td>';
2129 print '<table class="nobordernopadding" width="100%"><tr><td>';
2130 print $langs->trans('DeliveryDate');
2131 print '</td>';
2132 if ($action != 'editdate_livraison' && $object->status != SupplierProposal::STATUS_NOTSIGNED) {
2133 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>';
2134 }
2135 print '</tr></table>';
2136 print '</td><td class="valuefield">';
2137 if ($action == 'editdate_livraison') {
2138 print '<form name="editdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2139 print '<input type="hidden" name="token" value="'.newToken().'">';
2140 print '<input type="hidden" name="action" value="setdate_livraison">';
2141 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2142 print $form->selectDate($object->delivery_date, 'liv_', 0, 0, 0, "editdate_livraison");
2143 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2144 print '</form>';
2145 } else {
2146 print dol_print_date($object->delivery_date, 'daytext');
2147 }
2148 print '</td>';
2149 print '</tr>';
2150
2151 // Payment mode
2152 print '<tr>';
2153 print '<td>';
2154 print '<table class="nobordernopadding" width="100%"><tr><td>';
2155 print $langs->trans('PaymentMode');
2156 print '</td>';
2157 if ($action != 'editmode' && $object->status != SupplierProposal::STATUS_NOTSIGNED) {
2158 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>';
2159 }
2160 print '</tr></table>';
2161 print '</td><td class="valuefield">';
2162 if ($action == 'editmode') {
2163 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1);
2164 } else {
2165 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->mode_reglement_id, 'none');
2166 }
2167 print '</td></tr>';
2168
2169 /* Not for supplier proposals
2170 if ($soc->outstanding_limit) {
2171 // Outstanding Bill
2172 print '<tr><td>';
2173 print $langs->trans('OutstandingBill');
2174 print '</td><td class="valuefield">';
2175 $arrayoutstandingbills = $soc->getOutstandingBills('supplier');
2176 $outstandingBills = $arrayoutstandingbills['opened'];
2177 print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency);
2178 print '</td>';
2179 print '</tr>';
2180 }*/
2181
2182 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL') && isModEnabled("bank")) {
2183 // Bank Account
2184 print '<tr><td>';
2185 print '<table width="100%" class="nobordernopadding"><tr><td>';
2186 print $langs->trans('BankAccount');
2187 print '</td>';
2188 if ($action != 'editbankaccount' && $usercancreate) {
2189 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>';
2190 }
2191 print '</tr></table>';
2192 print '</td><td class="valuefield">';
2193 if ($action == 'editbankaccount') {
2194 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'fk_account', 1);
2195 } else {
2196 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'none');
2197 }
2198 print '</td>';
2199 print '</tr>';
2200 }
2201 // Categories
2202 if (isModEnabled('category')) {
2203 print '<tr><td>';
2204 print '<table class="nobordernopadding centpercent"><tr><td>';
2205 print $langs->trans("Categories");
2206 print '<td><td class="right">';
2207 if ($usercancreate) {
2208 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$object->id.'&action=edittags&token='.newToken().'">'.img_edit().'</a>';
2209 } else {
2210 print '&nbsp;';
2211 }
2212 print '</td></tr></table>';
2213 print '</td>';
2214 print '<td>';
2215 if ($action == 'edittags') {
2216 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
2217 print '<input type="hidden" name="action" value="settags">';
2218 print '<input type="hidden" name="token" value="'.newToken().'">';
2219 print $form->selectCategories(Categorie::TYPE_SUPPLIER_PROPOSAL, 'categories', $object);
2220 print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
2221 print '</form>';
2222 } else {
2223 print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER_PROPOSAL, 1);
2224 }
2225 print "</td></tr>";
2226 }
2227 // Other attributes
2228 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2229
2230 print '</table>';
2231
2232 print '</div>';
2233 print '<div class="fichehalfright">';
2234 print '<div class="underbanner clearboth"></div>';
2235
2236 print '<table class="border tableforfield centpercent">';
2237
2238 include DOL_DOCUMENT_ROOT.'/core/tpl/object_currency_amount.tpl.php';
2239
2240 print '<tr>';
2241 // Amount HT
2242 print '<td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
2243 print '<td class="nowrap amountcard right" data-dol-field="total_ht">' . price($object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2244 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2245 // Multicurrency Amount HT
2246 print '<td class="nowrap amountcard right" data-dol-field="multicurrency_total_ht">' . price($object->multicurrency_total_ht, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2247 }
2248 print '</tr>';
2249
2250 print '<tr>';
2251 // Amount VAT
2252 print '<td class="titlefieldmiddle">' . $langs->trans('AmountVAT') . '</td>';
2253 print '<td class="nowrap amountcard right" data-dol-field="total_tva">' . price($object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2254 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2255 // Multicurrency Amount VAT
2256 print '<td class="nowrap amountcard right" data-dol-field="multicurrency_total_tva">' . price($object->multicurrency_total_tva, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2257 }
2258 print '</tr>';
2259
2260 // Amount Local Taxes
2261 if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) {
2262 print '<tr>';
2263 print '<td class="titlefieldmiddle">' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
2264 print '<td class="nowrap amountcard right" data-dol-field="total_localtax1">' . price($object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2265 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2266 print '<td class="nowrap amountcard right" data-dol-field="multicurrency_total_localtax1">' . price($object->total_localtax1, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2267 }
2268 print '</tr>';
2269
2270 if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) {
2271 print '<tr>';
2272 print '<td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
2273 print '<td class="nowrap amountcard right" data-dol-field="total_localtax2">' . price($object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2274 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2275 print '<td class="nowrap amountcard right" data-dol-field="multicurrency_total_localtax2">' . price($object->total_localtax2, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2276 }
2277 print '</tr>';
2278 }
2279 }
2280
2281 print '<tr>';
2282 // Amount TTC
2283 print '<td>' . $langs->trans('AmountTTC') . '</td>';
2284 print '<td class="nowrap amountcard right" data-dol-field="total_ttc">' . price($object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2285 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2286 // Multicurrency Amount TTC
2287 print '<td class="nowrap amountcard right" data-dol-field="multicurrency_total_ttc">' . price($object->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2288 }
2289 print '</tr>';
2290
2291 print '</table>';
2292
2293 // Margin Infos
2294 /*if (isModEnabled('margin')) {
2295 $formmargin->displayMarginInfos($object);
2296 }*/
2297
2298 print '</div>';
2299 print '</div>';
2300
2301 print '<div class="clearboth"></div><br>';
2302
2303 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
2304 $blocname = 'contacts';
2305 $title = $langs->trans('ContactsAddresses');
2306 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2307 }
2308
2309 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
2310 $blocname = 'notes';
2311 $title = $langs->trans('Notes');
2312 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2313 }
2314
2315 /*
2316 * Lines
2317 */
2318
2319 // Show object lines
2320 $result = $object->getLinesArray();
2321
2322 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#add' : '').'" method="POST">
2323 <input type="hidden" name="token" value="' . newToken().'">
2324 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
2325 <input type="hidden" name="mode" value="">
2326 <input type="hidden" name="id" value="' . $object->id.'">
2327 <input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">
2328 ';
2329
2330 if (!empty($conf->use_javascript_ajax) && $object->status == SupplierProposal::STATUS_DRAFT) {
2331 if (isModEnabled('subtotals')) {
2332 include DOL_DOCUMENT_ROOT . '/core/tpl/subtotal_ajaxrow.tpl.php';
2333 } else {
2334 include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
2335 }
2336 }
2337
2338 print '<div class="div-table-responsive-no-min">';
2339 print '<table id="tablelines" class="noborder noshadow centpercent">';
2340
2341 // Add free products/services form
2342 global $forceall, $senderissupplier, $inputalsopricewithtax;
2343 $forceall = 1;
2344 $dateSelector = 0;
2345 $inputalsopricewithtax = 1;
2346 $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty.
2347 if (getDolGlobalInt('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY')) {
2348 $senderissupplier = getDolGlobalInt('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY');
2349 }
2350
2351 if (!empty($object->lines)) {
2352 $object->printObjectLines($action, $soc, $mysoc, $lineid, $dateSelector);
2353 }
2354
2355 // Form to add new line
2356 if ($object->status == SupplierProposal::STATUS_DRAFT && $usercancreate) {
2357 if ($action != 'editline') {
2358 // Add products/services form
2359
2360 $parameters = array('dateSelector' => $dateSelector);
2361 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2362 if ($reshook < 0) {
2363 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2364 }
2365 if (empty($reshook)) {
2366 $object->formAddObjectLine($dateSelector, $soc, $mysoc);
2367 }
2368 }
2369 }
2370
2371 print '</table>';
2372 print '</div>';
2373 print "</form>\n";
2374 }
2375
2376 print dol_get_fiche_end();
2377
2378 if ($action == 'statut') {
2379 // Form to set proposal accepted/refused
2380 $form_close = '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST" id="formacceptrefuse" class="formconsumeproduce paddingbottom paddingleft paddingright">';
2381 $form_close .= '<input type="hidden" name="token" value="'.newToken().'">';
2382 $form_close .= '<input type="hidden" name="action" value="setstatut">';
2383
2384 if (getDolGlobalString('SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL')) {
2385 $form_close .= '<p class="notice">'.$langs->trans('SupplierProposalRefFournNotice').'</p>'; // TODO Suggest a permanent checkbox instead of option
2386 }
2387 $form_close .= '<table class="border centpercent marginleftonly marginrightonly">';
2388 $form_close .= '<tr><td>'.$langs->trans("CloseAs").'</td><td class="left">';
2389 $form_close .= '<select id="statut" name="statut" class="flat">';
2390 $form_close .= '<option value="0">&nbsp;</option>';
2391 $form_close .= '<option value="2">'.$langs->trans('SupplierProposalStatusSigned').'</option>';
2392 $form_close .= '<option value="3">'.$langs->trans('SupplierProposalStatusNotSigned').'</option>';
2393 $form_close .= '</select>';
2394 $form_close .= '</td></tr>';
2395 $form_close .= '<tr><td class="left">'.$langs->trans('Note').'</td><td class="left"><textarea cols="70" rows="'.ROWS_3.'" wrap="soft" name="note">';
2396 $form_close .= $object->note_private;
2397 $form_close .= '</textarea></td></tr>';
2398 $form_close .= '</table>';
2399 $form_close .= $form->buttonsSaveCancel();
2400 $form_close .= '<a id="acceptedrefused">&nbsp;</a>';
2401 $form_close .= '</form>';
2402
2403 print $form_close;
2404 }
2405
2406 /*
2407 * Boutons Actions
2408 */
2409 if ($action != 'presend') {
2410 print '<div class="tabsAction">';
2411
2412 $parameters = array();
2413 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2414 // modified by hook
2415 if (empty($reshook)) {
2416 if ($action != 'statut' && $action != 'editline') {
2417 // Subtotal
2418 if ($object->status == SupplierProposal::STATUS_DRAFT && isModEnabled('subtotals')
2419 && (getDolGlobalString('SUBTOTAL_TITLE_'.strtoupper($object->element)) || getDolGlobalString('SUBTOTAL_'.strtoupper($object->element)) || getDolGlobalString('SUBTOTAL_TEXT_'.strtoupper($object->element)))) {
2420 $langs->load('subtotals');
2421
2422 $url_button = array();
2423
2424 $url_button[] = array(
2425 'lang' => 'subtotals',
2426 'enabled' => $object->status == SupplierProposal::STATUS_DRAFT,
2427 'perm' => (bool) $usercancreate,
2428 'label' => $langs->trans('AddTitleLine'),
2429 'url' => dolBuildUrl($_SERVER['PHP_SELF'], ['id' => $object->id, 'action' => 'add_title_line'], true)
2430 );
2431
2432 $url_button[] = array(
2433 'lang' => 'subtotals',
2434 'enabled' => $object->status == SupplierProposal::STATUS_DRAFT,
2435 'perm' => (bool) $usercancreate,
2436 'label' => $langs->trans('AddSubtotalLine'),
2437 'url' => dolBuildUrl($_SERVER['PHP_SELF'], ['id' => $object->id, 'action' => 'add_subtotal_line'], true)
2438 );
2439
2440 $url_button[] = array(
2441 'lang' => 'subtotals',
2442 'enabled' => $object->status == SupplierProposal::STATUS_DRAFT,
2443 'perm' => (bool) $usercancreate,
2444 'label' => $langs->trans('AddTextLine'),
2445 'url' => dolBuildUrl($_SERVER['PHP_SELF'], ['id' => $object->id, 'action' => 'add_text_line'], true)
2446 );
2447
2448 print dolGetButtonAction('', $langs->trans('SubTotal'), 'default', $url_button, '', true);
2449 }
2450 // Validate
2451 if ($object->status == SupplierProposal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0 && $usercanvalidate) {
2452 if (count($object->lines) > 0) {
2453 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>';
2454 }
2455 // else print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Validate').'</a>';
2456 }
2457
2458 // Edit
2459 if ($object->status == SupplierProposal::STATUS_VALIDATED && $usercancreate) {
2460 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>';
2461 }
2462
2463 // ReOpen
2465 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').'"';
2466 print '>'.$langs->trans('ReOpen').'</a></div>';
2467 }
2468
2469 // Send
2470 if (empty($user->socid)) {
2472 if ($usercansend) {
2473 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'presend', 'mode' => 'init'], true).'#formmailbeforetitle', '');
2474 } else {
2475 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', '#', '', false);
2476 }
2477 }
2478 }
2479
2480 // Create an order
2481 if (isModEnabled("supplier_order") && $object->status == SupplierProposal::STATUS_SIGNED) {
2482 if ($usercancreateorder) {
2483 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>';
2484 }
2485 }
2486
2487 // Set accepted/refused
2488 if ($object->status == SupplierProposal::STATUS_VALIDATED && $usercanclose) {
2489 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').'"';
2490 print '>'.$langs->trans('SetAcceptedRefused').'</a></div>';
2491 }
2492
2493 // Close
2494 if ($object->status == SupplierProposal::STATUS_SIGNED && $usercanclose) {
2495 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').'"';
2496 print '>'.$langs->trans('Close').'</a></div>';
2497 }
2498
2499 // Clone
2500 if ($usercancreate) {
2501 print '<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans("ToClone"), $langs->trans("ToClone"), 'clone', $_SERVER['PHP_SELF'].'?id='.((int) $object->id).'&socid='.((int) $object->socid).'&action=clone&object='.urlencode($object->element).'&token='.newToken(), '', true, array('attr' => array('class' => 'reposition'))).'</div>';
2502 }
2503
2504 // Delete
2505 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', (($object->status == SupplierProposal::STATUS_DRAFT && $usercancreate) || $usercandelete), array('attr' => array('class' => 'reposition')))."\n";
2506 }
2507 }
2508
2509 print '</div>';
2510 }
2511
2512 if ($action != 'presend') {
2513 print '<div class="fichecenter"><div class="fichehalfleft">';
2514
2515 /*
2516 * Generated documents
2517 */
2518 $filename = dol_sanitizeFileName($object->ref);
2519 $filedir = $conf->supplier_proposal->dir_output."/".dol_sanitizeFileName($object->ref);
2520 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2521 $genallowed = $usercanread;
2522 $delallowed = $usercancreate;
2523
2524 print $formfile->showdocuments('supplier_proposal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
2525
2526
2527 // Show links to link elements
2528 $tmparray = $form->showLinkToObjectBlock($object, array(), array('supplier_proposal'), 1);
2529 $linktoelem = $tmparray['linktoelem'];
2530 $htmltoenteralink = $tmparray['htmltoenteralink'];
2531 print $htmltoenteralink;
2532
2533 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2534
2535 $MAXEVENT = 10;
2536
2537 print '</div><div class="fichehalfright">';
2538
2539 // List of actions on element
2540 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2541 $formactions = new FormActions($db);
2542 $somethingshown = $formactions->showactions($object, 'supplier_proposal', $socid, 1, '', $MAXEVENT);
2543
2544 print '</div></div>';
2545 }
2546
2547 // Select mail models is same action as presend
2548 if (GETPOST('modelselected')) {
2549 $action = 'presend';
2550 }
2551
2552 // Presend form
2553 $modelmail = 'supplier_proposal_send';
2554 $defaulttopic = 'SendAskRef';
2555 $diroutput = $conf->supplier_proposal->dir_output;
2556 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
2557 $trackid = 'spro'.$object->id;
2558
2559 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2560}
2561
2562// End of page
2563llxFooter();
2564$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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 to manage "other" html components Only common components are here.
Class to help generate other html components 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 supplier_proposal lines.
Class to manage translations.
global $mysoc
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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
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...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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 rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
supplier_proposal_prepare_head($object)
Prepare array with list of tabs.