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