dolibarr 24.0.3
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 // Keep the extra parameters of the source line (for example the options of subtotal lines)
506 if ($result > 0 && !empty($lines[$i]->extraparams)) {
507 $newline = new SupplierProposalLine($db);
508 $newline->id = $result;
509 $newline->extraparams = $lines[$i]->extraparams;
510 $newline->setExtraParameters();
511 }
512
513 // Defined the new fk_parent_line
514 if ($result > 0 && $lines[$i]->product_type == 9) {
515 $fk_parent_line = $result;
516 }
517 }
518
519 // Hooks
520 $parameters = array('objFrom' => $srcobject);
521 $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
522 // modified by hook
523 if ($reshook < 0) {
524 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
525 $error++;
526 }
527 } else {
528 setEventMessages($srcobject->error, $srcobject->errors, 'errors');
529 $error++;
530 }
531 } else {
532 setEventMessages($object->error, $object->errors, 'errors');
533 $error++;
534 }
535 } else {
536 // Standard creation
537 $id = $object->create($user);
538 }
539
540 if ($id > 0) {
541 if (isModEnabled('category')) {
542 $categories = GETPOST('categories', 'array');
543 $object->setCategories($categories);
544 }
545 if (!$error) {
546 $db->commit();
547
548 // Define output language
549 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
550 $outputlangs = $langs;
551 $newlang = '';
552 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
553 $newlang = GETPOST('lang_id', 'aZ09');
554 }
555 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
556 $newlang = $object->thirdparty->default_lang;
557 }
558 if (!empty($newlang)) {
559 $outputlangs = new Translate("", $conf);
560 $outputlangs->setDefaultLang($newlang);
561 }
562 $model = $object->model_pdf;
563
564 if (!empty($model)) {
565 $ret = $object->fetch($id); // Reload to get new records
566 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
567 if ($result < 0) {
568 dol_print_error($db, $object->error, $object->errors);
569 }
570 }
571 }
572
573 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
574 exit();
575 } else {
576 $db->rollback();
577 $action = 'create';
578 }
579 } else {
580 setEventMessages($object->error, $object->errors, 'errors');
581 $db->rollback();
582 $action = 'create';
583 }
584 }
585 }
586 } elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) {
587 // Reopen proposal
588 // prevent browser refresh from reopening proposal several times
591 }
592 } elseif ($action == 'close' && $usercanclose && !GETPOST('cancel', 'alpha')) {
593 // Close proposal
594 // prevent browser refresh from reopening proposal several times
597 }
598 } elseif ($action == 'setstatut' && $usercanclose && !GETPOST('cancel', 'alpha')) {
599 // Set accepted/refused
600 // Only the 2 values of the form are accepted (like for a customer proposal), not any status
602 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("CloseAs")), null, 'errors');
603 $action = 'statut';
604 } else {
605 // prevent browser refresh from closing proposal several times
607 $object->cloture($user, GETPOSTINT('statut'), GETPOST('note', 'restricthtml'));
608 }
609 }
610 } elseif ($action == 'addline' && GETPOST('updateallvatlinesblock', 'alpha') && GETPOST('vatforblocklines', 'alpha') !== '' && $usercancreate) {
611 $tx_tva = GETPOST('vatforblocklines') ? GETPOST('vatforblocklines') : 0;
612 $object->updateSubtotalLineBlockLines($langs, $object->getRangOfLine($lineid), 'tva', $tx_tva);
613 } elseif ($action == 'addline' && GETPOST('updatealldiscountlinesblock', 'alpha') && GETPOST('discountforblocklines', 'alpha') !== '' && $usercancreate) {
614 $discount = GETPOST('discountforblocklines') ? GETPOST('discountforblocklines') : 0;
615 $object->updateSubtotalLineBlockLines($langs, $object->getRangOfLine($lineid), 'discount', $discount);
616 } elseif ($action == 'settags' && isModEnabled('category') && $usercancreate) { // Set tags
617 $result = $object->setCategories(GETPOST('categories', 'array'));
618 }
619
620 // Actions when printing a doc from card
621 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
622
623 // Actions to send emails
624 $triggersendname = 'PROPOSAL_SUPPLIER_SENTBYMAIL';
625 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
626 $trackid = 'spro'.$object->id;
627 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
628
629 // Actions to build doc
630 $upload_dir = $conf->supplier_proposal->dir_output;
631 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
632
633 // Go back to draft
634 if ($action == 'modif' && $usercancreate) {
635 $object->setDraft($user);
636
637 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
638 // Define output language
639 $outputlangs = $langs;
640 if (getDolGlobalInt('MAIN_MULTILANGS')) {
641 $outputlangs = new Translate("", $conf);
642 $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
643 $outputlangs->setDefaultLang($newlang);
644 }
645 $ret = $object->fetch($id); // Reload to get new records
646 if ($ret > 0) {
647 $object->fetch_thirdparty();
648 }
649 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
650 }
651 } elseif ($action == "setabsolutediscount" && $usercancreate) {
652 if (GETPOSTINT("remise_id")) {
653 if ($object->id > 0) {
654 $result = $object->insert_discount(GETPOSTINT("remise_id"));
655 if ($result < 0) {
656 setEventMessages($object->error, $object->errors, 'errors');
657 }
658 }
659 }
660 }
661
662 // Add a product line
663 if ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && GETPOST('vatforalllines', 'alpha') && $usercancreate) {
664 // Define vat_rate
665 $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
666 $vat_rate = str_replace('*', '', $vat_rate);
667 $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
668 $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
669 foreach ($object->lines as $line) {
670 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
671 continue;
672 }
673 $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);
674 }
675 } elseif ($action == 'confirm_addtitleline' && $usercancreate) {
676 // Handling adding a new title line for subtotals module
677
678 $langs->load('subtotals');
679
680 $desc = GETPOST('subtotallinedesc', 'alphanohtml');
681 $depth = GETPOSTINT('subtotallinelevel') ?? 1;
682
683 $subtotal_options = array();
684
685 foreach (SupplierProposal::$TITLE_OPTIONS as $option) {
686 $value = GETPOST($option, 'alphanohtml');
687 if ($value) {
688 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
689 }
690 }
691
692 // Insert line
693 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
694
695 if ($result >= 0) {
696 if ($result == 0) {
697 setEventMessages($object->error, $object->errors, 'warnings');
698 }
699 $ret = $object->fetch($object->id); // Reload to get new records
700 $object->fetch_thirdparty();
701
702 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
703 // Define output language
704 $outputlangs = $langs;
705 $newlang = GETPOST('lang_id', 'alpha');
706 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
707 $newlang = $object->thirdparty->default_lang;
708 }
709 if (!empty($newlang)) {
710 $outputlangs = new Translate("", $conf);
711 $outputlangs->setDefaultLang($newlang);
712 }
713
714 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
715 }
716 } else {
717 setEventMessages($object->error, $object->errors, 'errors');
718 }
719 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
720 exit();
721 } elseif ($action == 'confirm_addsubtotalline' && $usercancreate) {
722 // Handling adding a new subtotal line for subtotals module
723
724 $langs->load('subtotals');
725
726 $choosen_line = GETPOST('subtotaltitleline', 'alphanohtml');
727 foreach ($object->lines as $line) {
728 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
729 $desc = $line->desc;
730 $depth = -$line->qty;
731 }
732 }
733
734 $subtotal_options = array();
735
736 foreach (SupplierProposal::$SUBTOTAL_OPTIONS as $option) {
737 $value = GETPOST($option, 'alphanohtml');
738 if ($value) {
739 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
740 }
741 }
742
743 // Insert line
744 if (isset($desc) && isset($depth)) {
745 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
746 } else {
747 $result = -1;
748 $object->errors[] = $langs->trans("CorrespondingTitleNotFound");
749 }
750
751 if ($result >= 0) {
752 $ret = $object->fetch($object->id); // Reload to get new records
753 $object->fetch_thirdparty();
754
755 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
756 // Define output language
757 $outputlangs = $langs;
758 $newlang = GETPOST('lang_id', 'alpha');
759 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
760 $newlang = $object->thirdparty->default_lang;
761 }
762 if (!empty($newlang)) {
763 $outputlangs = new Translate("", $conf);
764 $outputlangs->setDefaultLang($newlang);
765 }
766
767 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
768 }
769 } else {
770 setEventMessages($object->error, $object->errors, 'errors');
771 }
772 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
773 exit();
774 } elseif ($action == 'addline' && $usercancreate) {
775 $langs->load('errors');
776 $error = 0;
777
778 // Set if we used free entry or predefined product
779 $predef = '';
780 $line_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
781 $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'));
782 $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'));
783
784 $ref_supplier = GETPOST('fourn_ref', 'alpha');
785
786 $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
787 if ($prod_entry_mode == 'free') {
788 $idprod = 0;
789 } else {
790 $idprod = GETPOSTINT('idprod');
791 }
792
793 $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)'
794
795 $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
796 $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
797 $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
798 $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
799
800 $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
801
802 $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
803 if (empty($remise_percent)) {
804 $remise_percent = 0;
805 }
806
807 // Extrafields
808 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
809 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
810 // Unset extrafield
811 if (is_array($extralabelsline)) {
812 // Get extra fields
813 foreach ($extralabelsline as $key => $value) {
814 unset($_POST["options_".$key]);
815 }
816 }
817
818 if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) {
819 setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
820 $error++;
821 }
822 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
823 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
824 $error++;
825 }
826
827 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.
828 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPrice")), null, 'errors');
829 $error++;
830 }
831 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
832 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
833 $error++;
834 }
835 if (!$error && ($qty >= 0)) {
836 $pu_ht = price2num($price_ht, 'MU');
837 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
838 $price_min = 0;
839 $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
840
841 $db->begin();
842
843 if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
844 $productsupplier = new ProductFournisseur($db);
845
846 $idprod = 0;
847 if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') {
848 $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, ...)
849 }
850
851 $reg = array();
852 if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) {
853 $idprod = (int) $reg[1];
854 $res = $productsupplier->fetch($idprod); // Load product from its id
855 // Call to init some price properties of $productsupplier
856 // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
857 if (getDolGlobalString('SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
858 $fksoctosearch = 0;
859 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
860 if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price
861 $productsupplier->ref_supplier = '';
862 }
863 } else {
864 $fksoctosearch = $object->thirdparty->id;
865 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
866 }
867 } elseif (GETPOSTINT('idprodfournprice') > 0) { // id here.
868 //$qtytosearch=$qty; // Just to see if a price exists for the quantity. Not used to found vat.
869 $qtytosearch = -1; // We force qty to -1 to be sure to find if the supplier price that exists
870 $idprod = $productsupplier->get_buyprice(GETPOSTINT('idprodfournprice'), $qtytosearch);
871 $res = $productsupplier->fetch($idprod);
872 }
873
874 if ($idprod > 0) {
875 $label = $productsupplier->label;
876
877 // Define output language
878 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
879 $outputlangs = $langs;
880 $newlang = '';
881 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
882 $newlang = GETPOST('lang_id', 'aZ09');
883 }
884 if (empty($newlang)) {
885 $newlang = $object->thirdparty->default_lang;
886 }
887 if (!empty($newlang)) {
888 $outputlangs = new Translate("", $conf);
889 $outputlangs->setDefaultLang($newlang);
890 }
891 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description;
892 } else {
893 $desc = $productsupplier->description;
894 }
895 // if we use supplier description of the products
896 if (!empty($productsupplier->desc_supplier) && getDolGlobalString('PRODUIT_FOURN_TEXTS')) {
897 $desc = $productsupplier->desc_supplier;
898 }
899
900 if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 0) {
901 // 'DoNotAutofillButAutoConcat'
902 $desc = dol_concatdesc($desc, $line_desc, false, getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION') ? true : false);
903 } else {
904 //'AutoFillFormFieldBeforeSubmit' or 'DoNotUseDescriptionOfProdut' => User has already done the modification they want
905 $desc = $line_desc;
906 }
907
908 $ref_supplier = $productsupplier->ref_supplier;
909
910 // Get vat rate
911 $tva_npr = 0;
912 if (!GETPOSTISSET('tva_tx')) { // If vat rate not provided from the form (the form has the priority)
913 $tmpidprodfournprice = GETPOST('idprodfournprice', 'alpha'); // can be an id of price, or -1, -2, -99 or 'idprod_...'
914 if (is_numeric($tmpidprodfournprice) && (int) $tmpidprodfournprice > 0) {
915 $tmpidprodfournprice = (int) $tmpidprodfournprice;
916 } else {
917 $tmpidprodfournprice = 0;
918 }
919
920 $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, $tmpidprodfournprice);
921 $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, $tmpidprodfournprice);
922 }
923 if (empty($tva_tx)) {
924 $tva_npr = 0;
925 }
926 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
927 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
928
929 $type = $productsupplier->type;
930 if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
931 $price_base_type = 'HT';
932 $pu = price2num($price_ht, 'MU');
933 $pu_devise = price2num($price_ht_devise, 'CU');
934 } elseif (GETPOST('price_ttc') != '' || GETPOST('multicurrency_price_ttc') != '') {
935 $price_base_type = 'TTC';
936 $pu = price2num($price_ttc, 'MU');
937 $pu_devise = price2num($price_ttc_devise, 'CU');
938 } else {
939 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
940 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
941 $pu = $productsupplier->fourn_pu;
942 $pu_devise = 0;
943 } else {
944 $pu = $productsupplier->fourn_pu;
945 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
946 }
947 }
948
949 if (empty($pu)) {
950 $pu = 0; // If pu is '' or null, we force to have a numeric value
951 }
952
953 // 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)
954 $fournprice = (is_numeric(GETPOST('idprodfournprice', 'alpha')) ? GETPOST('idprodfournprice', 'alpha') : -1);
955 $buyingprice = 0;
956
957 $result = $object->addline(
958 $desc,
959 ($price_base_type == 'HT' ? $pu : 0),
960 (float) $qty,
961 $tva_tx,
962 $localtax1_tx,
963 $localtax2_tx,
964 $productsupplier->id,
965 $remise_percent,
966 $price_base_type,
967 ($price_base_type == 'TTC' ? $pu : 0),
968 $tva_npr,
969 $type,
970 min($rank, count($object->lines) + 1),
971 0,
972 GETPOSTINT('fk_parent_line'),
973 (int) $fournprice,
974 $buyingprice,
975 $label,
976 $array_options,
977 $ref_supplier,
978 $productsupplier->fk_unit,
979 '',
980 0,
981 $pu_devise,
983 $date_end
984 );
985
986 //var_dump($tva_tx);
987 //var_dump($productsupplier->fourn_pu);
988 //var_dump($price_base_type);exit;
989 if ($result < 0) {
990 $error++;
991 setEventMessages($object->error, $object->errors, 'errors');
992 }
993 }
994 if ($idprod == -99 || $idprod == 0) {
995 // Product not selected
996 $error++;
997 $langs->load("errors");
998 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")).' '.$langs->trans("or").' '.$langs->trans("NoPriceDefinedForThisSupplier"), null, 'errors');
999 }
1000 if ($idprod == -1) {
1001 // Quantity too low
1002 $error++;
1003 $langs->load("errors");
1004 setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors');
1005 }
1006 } elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '' || GETPOST('multicurrency_price_ht') != '') && empty($error)) { // Free product. // $price_ht is already set
1007 $pu_ht = price2num($price_ht, 'MU');
1008 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
1009
1010 $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
1011 $tva_tx = str_replace('*', '', $tva_tx);
1012 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1013 $desc = $line_desc;
1014 $type = GETPOSTINT('type');
1015
1016 $fk_unit = GETPOSTINT('units');
1017
1018 if (!preg_match('/\‍((.*)\‍)/', $tva_tx)) {
1019 $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'
1020 }
1021
1022 // Local Taxes
1023 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1024 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1025
1026 if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
1027 $pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
1028 } else {
1029 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
1030 $pu_ht = price2num((float) $pu_ttc / (1 + ((float) $tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
1031 }
1032 $price_base_type = 'HT';
1033 $pu_ht_devise = price2num($price_ht_devise, 'CU');
1034 $info_bits = 0;
1035
1036 $result = $object->addline(
1037 $desc,
1038 (float) $pu_ht,
1039 (float) $qty,
1040 $tva_tx, // don't cast to float
1041 $localtax1_tx,
1042 $localtax2_tx,
1043 $idprod,
1044 $remise_percent,
1045 $price_base_type,
1046 (float) $pu_ttc,
1047 $info_bits,
1048 $type,
1049 -1, // rang
1050 0, // special_code
1051 GETPOSTINT('fk_parent_line'),
1052 (int) $fournprice,
1053 $buyingprice,
1054 $label,
1055 $array_options,
1056 $ref_supplier,
1057 $fk_unit,
1058 '', // origin
1059 0, // origin_id
1060 (float) $pu_ht_devise
1061 );
1062 }
1063
1064
1065 if (!$error && $result > 0) {
1066 $db->commit();
1067
1068 $ret = $object->fetch($object->id); // Reload to get new records
1069
1070 // Define output language
1071 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1072 $outputlangs = $langs;
1073 $newlang = '';
1074 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1075 $newlang = GETPOST('lang_id', 'aZ09');
1076 }
1077 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1078 $newlang = $object->thirdparty->default_lang;
1079 }
1080 if (!empty($newlang)) {
1081 $outputlangs = new Translate("", $conf);
1082 $outputlangs->setDefaultLang($newlang);
1083 }
1084 $model = $object->model_pdf;
1085 $ret = $object->fetch($id); // Reload to get new records
1086 if ($ret > 0) {
1087 $object->fetch_thirdparty();
1088 }
1089
1090 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1091 if ($result < 0) {
1092 dol_print_error($db, $object->error, $object->errors);
1093 }
1094 }
1095
1096 unset($_POST['prod_entry_mode']);
1097
1098 unset($_POST['qty']);
1099 unset($_POST['type']);
1100 unset($_POST['remise_percent']);
1101 unset($_POST['pu']);
1102 unset($_POST['price_ht']);
1103 unset($_POST['multicurrency_price_ht']);
1104 unset($_POST['price_ttc']);
1105 unset($_POST['fourn_ref']);
1106 unset($_POST['tva_tx']);
1107 unset($_POST['label']);
1108 unset($_POST['product_ref']);
1109 unset($_POST['product_label']);
1110 unset($_POST['product_desc']);
1111 unset($_POST['fournprice']);
1112 unset($_POST['buying_price']);
1113 unset($localtax1_tx);
1114 unset($localtax2_tx);
1115 unset($_POST['np_marginRate']);
1116 unset($_POST['np_markRate']);
1117 unset($_POST['dp_desc']);
1118 unset($_POST['idprodfournprice']);
1119 unset($_POST['units']);
1120
1121 unset($_POST['idprod']);
1122
1123 unset($_POST['date_starthour']);
1124 unset($_POST['date_startmin']);
1125 unset($_POST['date_startsec']);
1126 unset($_POST['date_startday']);
1127 unset($_POST['date_startmonth']);
1128 unset($_POST['date_startyear']);
1129 unset($_POST['date_endhour']);
1130 unset($_POST['date_endmin']);
1131 unset($_POST['date_endsec']);
1132 unset($_POST['date_endday']);
1133 unset($_POST['date_endmonth']);
1134 unset($_POST['date_endyear']);
1135 } else {
1136 $db->rollback();
1137
1138 setEventMessages($object->error, $object->errors, 'errors');
1139 }
1140 }
1141 } elseif ($action == 'updatetitleline' && GETPOSTISSET("save") && $usercancreate && !GETPOST('cancel', 'alpha')) {
1142 // Handling updating a title line for subtotals module
1143
1144 $langs->load('subtotals');
1145
1146 $desc = GETPOST('line_desc', 'alphanohtml') ?? $langs->trans("Title");
1147 $depth = GETPOSTINT('line_depth') ?? 1;
1148
1149 $subtotal_options = array();
1150
1151 foreach (SupplierProposal::$TITLE_OPTIONS as $option) {
1152 $value = GETPOST($option, 'alphanohtml');
1153 if ($value) {
1154 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
1155 }
1156 }
1157
1158 // Update line
1159 $result = $object->updateSubtotalLine($langs, GETPOSTINT('lineid'), $desc, $depth, $subtotal_options);
1160
1161 if ($result >= 0) {
1162 if ($result == 0) {
1163 setEventMessages($object->error, $object->errors, 'warnings');
1164 }
1165 $ret = $object->fetch($object->id); // Reload to get new records
1166 $object->fetch_thirdparty();
1167
1168 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1169 // Define output language
1170 $outputlangs = $langs;
1171 $newlang = GETPOST('lang_id', 'alpha');
1172 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1173 $newlang = $object->thirdparty->default_lang;
1174 }
1175 if (!empty($newlang)) {
1176 $outputlangs = new Translate("", $conf);
1177 $outputlangs->setDefaultLang($newlang);
1178 }
1179
1180 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1181 }
1182 } else {
1183 setEventMessages($object->error, $object->errors, 'errors');
1184 }
1185 } elseif ($action == 'updatesubtotalline' && GETPOSTISSET("save") && $usercancreate && !GETPOST('cancel', 'alpha')) {
1186 // Handling updating a subtotal line for subtotals module
1187
1188 $langs->load('subtotals');
1189
1190 $desc = GETPOST('line_desc', 'alphanohtml');
1191 $depth = GETPOSTINT('line_depth');
1192
1193 $subtotal_options = array();
1194
1195 foreach (SupplierProposal::$SUBTOTAL_OPTIONS as $option) {
1196 $value = GETPOST($option, 'alphanohtml');
1197 if ($value) {
1198 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
1199 }
1200 }
1201
1202 // Update line
1203 $result = $object->updateSubtotalLine($langs, GETPOSTINT('lineid'), $desc, $depth, $subtotal_options);
1204
1205 if ($result > 0) {
1206 $ret = $object->fetch($object->id); // Reload to get new records
1207 $object->fetch_thirdparty();
1208
1209 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1210 // Define output language
1211 $outputlangs = $langs;
1212 $newlang = GETPOST('lang_id', 'alpha');
1213 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1214 $newlang = $object->thirdparty->default_lang;
1215 }
1216 if (!empty($newlang)) {
1217 $outputlangs = new Translate("", $conf);
1218 $outputlangs->setDefaultLang($newlang);
1219 }
1220
1221 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1222 }
1223 } else {
1224 setEventMessages($object->error, $object->errors, 'errors');
1225 }
1226 } elseif ($action == 'updateline' && $usercancreate && GETPOST('save') == $langs->trans("Save")) {
1227 // Update a line within proposal
1228 $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
1229
1230 // Define info_bits
1231 $info_bits = 0;
1232 if (preg_match('/\*/', $vat_rate)) {
1233 $info_bits |= 0x01;
1234 }
1235
1236 // Clean parameters
1237 $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
1238
1239 // Define vat_rate
1240 $vat_rate = str_replace('*', '', $vat_rate);
1241 $localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
1242 $localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
1243
1244 if (GETPOST('price_ht') != '') {
1245 $price_base_type = 'HT';
1246 $ht = price2num(GETPOST('price_ht'), '', 2);
1247 } else {
1248 $reg = array();
1249 $vatratecleaned = $vat_rate;
1250 if (preg_match('/^(.*)\s*\‍((.*)\‍)$/', $vat_rate, $reg)) { // If vat is "xx (yy)"
1251 $vatratecleaned = trim($reg[1]);
1252 $vatratecode = $reg[2];
1253 }
1254
1255 $ttc = price2num(GETPOST('price_ttc'), '', 2);
1256 $ht = (float) $ttc / (1 + ((float) $vatratecleaned / 100));
1257 $price_base_type = 'HT';
1258 }
1259
1260 $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), 'CU', 2);
1261
1262 // Add buying price
1263 $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
1264 $buyingprice = price2num((GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''), '', 2); // If buying_price is '0', we must keep this value
1265
1266 // Extrafields Lines
1267 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1268 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1269 // Unset extrafield POST Data
1270 if (is_array($extralabelsline)) {
1271 foreach ($extralabelsline as $key => $value) {
1272 unset($_POST["options_".$key]);
1273 }
1274 }
1275
1276 // Define special_code for special lines
1277 $special_code = GETPOST('special_code');
1278 if (!GETPOST('qty')) {
1279 $special_code = 3;
1280 }
1281
1282 // Check minimum price
1283 $productid = GETPOSTINT('productid');
1284 if (!empty($productid)) {
1285 $productsupplier = new ProductFournisseur($db);
1286 if (getDolGlobalInt('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY') == 1) { // Not the common case
1287 if ($productid > 0 && $productsupplier->get_buyprice(0, (float) price2num(GETPOST('qty')), $productid, 'none', GETPOSTINT('socid')) < 0) {
1288 setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'warnings');
1289 }
1290 }
1291
1292 $product = new Product($db);
1293 $res = $product->fetch($productid);
1294
1295 $type = $product->type;
1296
1297 $price_min = $product->price_min;
1298 if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
1299 $price_min = $product->multiprices_min [$object->thirdparty->price_level];
1300 }
1301
1302 $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
1303 } else {
1304 $type = GETPOST('type');
1305 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1306
1307 // Check parameters
1308 if (GETPOST('type') < 0) {
1309 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1310 $error++;
1311 }
1312 }
1313
1314 if (!$error) {
1315 $db->begin();
1316
1317 $ref_supplier = GETPOST('fourn_ref', 'alpha');
1318 $fk_unit = GETPOSTINT('units');
1319
1320 $result = $object->updateline(
1321 GETPOSTINT('lineid'),
1322 $ht,
1323 (float) price2num(GETPOST('qty'), 'MS', 2),
1324 (float) price2num(GETPOST('remise_percent'), '', 2),
1325 $vat_rate,
1326 $localtax1_rate,
1327 $localtax2_rate,
1328 $description,
1329 $price_base_type,
1330 $info_bits,
1331 $special_code,
1332 GETPOSTINT('fk_parent_line'),
1333 0,
1334 (int) $fournprice,
1335 $buyingprice,
1336 $label,
1337 $type,
1338 $array_options,
1339 $ref_supplier,
1340 $fk_unit,
1341 (float) $pu_ht_devise
1342 );
1343
1344 if ($result >= 0) {
1345 $db->commit();
1346
1347 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1348 // Define output language
1349 $outputlangs = $langs;
1350 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1351 $outputlangs = new Translate("", $conf);
1352 $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
1353 $outputlangs->setDefaultLang($newlang);
1354 }
1355 $ret = $object->fetch($id); // Reload to get new records
1356 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1357 }
1358
1359 unset($_POST['qty']);
1360 unset($_POST['type']);
1361 unset($_POST['productid']);
1362 unset($_POST['remise_percent']);
1363 unset($_POST['price_ht']);
1364 unset($_POST['multicurrency_price_ht']);
1365 unset($_POST['price_ttc']);
1366 unset($_POST['tva_tx']);
1367 unset($_POST['product_ref']);
1368 unset($_POST['product_label']);
1369 unset($_POST['product_desc']);
1370 unset($_POST['fournprice']);
1371 unset($_POST['buying_price']);
1372
1373 unset($_POST['date_starthour']);
1374 unset($_POST['date_startmin']);
1375 unset($_POST['date_startsec']);
1376 unset($_POST['date_startday']);
1377 unset($_POST['date_startmonth']);
1378 unset($_POST['date_startyear']);
1379 unset($_POST['date_endhour']);
1380 unset($_POST['date_endmin']);
1381 unset($_POST['date_endsec']);
1382 unset($_POST['date_endday']);
1383 unset($_POST['date_endmonth']);
1384 unset($_POST['date_endyear']);
1385 } else {
1386 $db->rollback();
1387
1388 setEventMessages($object->error, $object->errors, 'errors');
1389 }
1390 }
1391 } elseif ($action == 'updateline' && $usercancreate && $cancel) {
1392 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To re-display card in edit mode
1393 exit();
1394 } elseif ($action == 'classin' && $usercancreate) {
1395 // Set project
1396 $object->setProject(GETPOSTINT('projectid'));
1397 } elseif ($action == 'setavailability' && $usercancreate) {
1398 // Delivery delay
1399 $result = $object->availability(GETPOST('availability_id'));
1400 } elseif ($action == 'setconditions' && $usercancreate) {
1401 // Terms of payments
1402 $sql = "SELECT code ";
1403 $sql .= "FROM " . $db->prefix() . "c_payment_term";
1404 $sql .= " WHERE rowid = " . GETPOSTINT('cond_reglement_id');
1405 $result = $db->query($sql);
1406 if ($result) {
1407 $obj = $db->fetch_object($result);
1408 if ($obj->code == 'DEP30PCTDEL') {
1409 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id'), GETPOSTFLOAT('cond_reglement_id_deposit_percent'));
1410 } else {
1411 $object->deposit_percent = 0;
1412 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id'), $object->deposit_percent);
1413 }
1414 }
1415 } elseif ($action == 'setmode' && $usercancreate) {
1416 // Payment mode
1417 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
1418 } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
1419 // Multicurrency Code
1420 $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
1421 } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
1422 // Multicurrency rate
1423 $result = $object->setMulticurrencyRate(GETPOSTFLOAT('multicurrency_tx'), GETPOSTINT('calculation_mode'));
1424 } elseif ($action == 'update_extras' && $permissiontoeditextra) {
1425 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
1426
1427 $attribute_name = GETPOST('attribute', 'aZ09');
1428
1429 // Fill array 'array_options' with data from update form
1430 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
1431 if ($ret < 0) {
1432 $error++;
1433 }
1434
1435 if (!$error) {
1436 $result = $object->updateExtraField($attribute_name, 'PROPOSAL_SUPPLIER_MODIFY');
1437 if ($result < 0) {
1438 setEventMessages($object->error, $object->errors, 'errors');
1439 $error++;
1440 }
1441 }
1442
1443 if ($error) {
1444 $action = 'edit_extras';
1445 }
1446 }
1447}
1448
1449
1450/*
1451 * View
1452 */
1453
1454$title = $object->ref." - ".$langs->trans('Card');
1455if ($action == 'create') {
1456 $title = $langs->trans("SupplierProposalNew");
1457}
1458$help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
1459
1460llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-supplierproposal page-card');
1461
1462$form = new Form($db);
1463$formother = new FormOther($db);
1464$formfile = new FormFile($db);
1465$formmargin = new FormMargin($db);
1466$companystatic = new Societe($db);
1467if (isModEnabled('project')) {
1468 $formproject = new FormProjets($db);
1469}
1470
1471$now = dol_now();
1472
1473// Add new askprice
1474if ($action == 'create') {
1475 $currency_code = $conf->currency;
1476
1477 print load_fiche_titre($langs->trans("SupplierProposalNew"), '', 'supplier_proposal');
1478
1479 $soc = new Societe($db);
1480 if ($socid > 0) {
1481 $res = $soc->fetch($socid);
1482 }
1483
1484 // Load objectsrc
1485 if (!empty($origin) && !empty($originid)) {
1486 $element = $subelement = GETPOST('origin');
1487 $regs = array();
1488 if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs)) {
1489 $element = $regs[1];
1490 $subelement = $regs[2];
1491 }
1492
1493 // For compatibility
1494 if ($element == 'order' || $element == 'commande') {
1495 $element = $subelement = 'commande';
1496 }
1497 if ($element == 'propal') {
1498 $element = 'comm/propal';
1499 $subelement = 'propal';
1500 }
1501
1502 dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1503
1504 $classname = ucfirst($subelement);
1505 $objectsrc = new $classname($db);
1506 '@phan-var-force Commande|Propal|CommandeFournisseur|SupplierProposal $objectsrc'; // Could be other classes, but CommonObject is too generic
1508 $objectsrc->fetch($originid);
1509 if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1510 $objectsrc->fetch_lines();
1511 }
1512 $objectsrc->fetch_thirdparty();
1513
1514 $projectid = (int) $objectsrc->fk_project;
1515 $soc = $objectsrc->thirdparty;
1516
1517 $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
1518 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : 0));
1519 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1520 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1521
1522 // Replicate extrafields
1523 $objectsrc->fetch_optionals();
1524 $object->array_options = $objectsrc->array_options;
1525
1526 if (isModEnabled("multicurrency")) {
1527 if (!empty($objectsrc->multicurrency_code)) {
1528 $currency_code = $objectsrc->multicurrency_code;
1529 }
1530 if (getDolGlobalString('MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1531 $currency_tx = $objectsrc->multicurrency_tx;
1532 }
1533 }
1534 } else {
1535 $cond_reglement_id = $soc->cond_reglement_supplier_id;
1536 $deposit_percent = !empty($soc->deposit_percent) ? $soc->deposit_percent : 0;
1537 $mode_reglement_id = $soc->mode_reglement_supplier_id;
1538 $fk_account = !empty($soc->fk_account) ? $soc->fk_account : 0;
1539 if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) {
1540 $currency_code = $soc->multicurrency_code;
1541 }
1542 }
1543 if (GETPOSTISSET('cond_reglement_id_deposit_percent')) {
1544 $deposit_percent = GETPOSTFLOAT('cond_reglement_id_deposit_percent');
1545 }
1546
1548
1549 print '<form name="addprop" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1550 print '<input type="hidden" name="token" value="'.newToken().'">';
1551 print '<input type="hidden" name="action" value="add">';
1552 if ($origin != 'project' && $originid) {
1553 print '<input type="hidden" name="origin" value="'.$origin.'">';
1554 print '<input type="hidden" name="originid" value="'.$originid.'">';
1555 }
1556 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1557
1558 print dol_get_fiche_head();
1559
1560 // Call Hook tabContentCreateSupplierProposal
1561 $parameters = array();
1562 // Note that $action and $object may be modified by hook
1563 $reshook = $hookmanager->executeHooks('tabContentCreateSupplierProposal', $parameters, $object, $action);
1564 if (empty($reshook)) {
1565 print '<table class="border centpercent">';
1566
1567 // Reference
1568 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
1569
1570 // Third party
1571 print '<tr>';
1572 print '<td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
1573 if ($socid > 0) {
1574 print '<td colspan="2">';
1575 print $soc->getNomUrl(1, 'supplier');
1576 print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1577 print '</td>';
1578 } else {
1579 print '<td colspan="2">';
1580 $filter = '((s.fournisseur:=:1) AND (s.status:=:1))';
1581 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company((empty($socid) ? '' : $socid), 'socid', $filter, 'SelectThirdParty', 1, 0, array(), 0, 'minwidth175 maxwidth500 widthcentpercentminusxx');
1582 // reload page to retrieve customer information
1583 if (!getDolGlobalString('RELOAD_PAGE_ON_SUPPLIER_CHANGE_DISABLED')) {
1584 print '<script>
1585 $(document).ready(function() {
1586 $("#socid").change(function() {
1587 console.log("We have changed the company - Reload page");
1588 // reload page
1589 $("input[name=action]").val("create");
1590 $("form[name=addprop]").submit();
1591 });
1592 });
1593 </script>';
1594 }
1595 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>';
1596 print '</td>';
1597 }
1598 print '</tr>'."\n";
1599
1600 if ($soc->id > 0) {
1601 // Discounts for third party
1602 print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
1603
1604 $absolute_discount = $soc->getAvailableDiscounts(null, '', 0, 1);
1605
1606 $thirdparty = $soc;
1607 $discount_type = 1;
1608 $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
1609 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1610
1611 print '</td></tr>';
1612 }
1613
1614 // Terms of payment
1615 print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
1616 print img_picto('', 'payment', 'class="pictofixedwidth"');
1617 print $form->getSelectConditionsPaiements(GETPOSTISSET('cond_reglement_id') ? GETPOSTINT('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id', -1, 1, 0, '', $deposit_percent);
1618 print '</td></tr>';
1619
1620 // Mode of payment
1621 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
1622 print img_picto('', 'bank', 'class="pictofixedwidth"');
1623 $form->select_types_paiements(GETPOST('mode_reglement_id') > 0 ? GETPOST('mode_reglement_id') : $mode_reglement_id, 'mode_reglement_id');
1624 print '</td></tr>';
1625
1626 // Bank Account
1627 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL') && isModEnabled("bank")) {
1628 print '<tr><td>'.$langs->trans('BankAccount').'</td><td colspan="2">';
1629 print img_picto('', 'bank', 'class="pictofixedwidth"');
1630 $form->select_comptes(GETPOST('fk_account') > 0 ? GETPOSTINT('fk_account') : $fk_account, 'fk_account', 0, '', 1);
1631 print '</td></tr>';
1632 }
1633
1634 // Shipping Method
1635 if (isModEnabled("shipping")) {
1636 print '<tr><td>'.$langs->trans('SendingMethod').'</td><td colspan="2">';
1637 print img_picto('', 'dolly', 'class="pictofixedwidth"');
1638 $form->selectShippingMethod(GETPOST('shipping_method_id') > 0 ? GETPOSTINT('shipping_method_id') : "", 'shipping_method_id', '', 1);
1639 print '</td></tr>';
1640 }
1641
1642 // Delivery date (or manufacturing)
1643 print '<tr><td>'.$langs->trans("DeliveryDate").'</td>';
1644 print '<td colspan="2">';
1645 print img_picto('', 'action', 'class="pictofixedwidth"');
1646 $datedelivery = dol_mktime(0, 0, 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
1647 if (is_numeric(getDolGlobalString('DATE_LIVRAISON_WEEK_DELAY'))) { // If value set to 0 or a num, not empty
1648 $tmpdte = time() + (7 * getDolGlobalInt('DATE_LIVRAISON_WEEK_DELAY') * 24 * 60 * 60);
1649 $syear = date("Y", $tmpdte);
1650 $smonth = date("m", $tmpdte);
1651 $sday = date("d", $tmpdte);
1652 print $form->selectDate($syear."-".$smonth."-".$sday, 'liv_', 0, 0, 0, "addask");
1653 } else {
1654 print $form->selectDate($datedelivery ? $datedelivery : -1, 'liv_', 0, 0, 0, "addask", 1, 1);
1655 }
1656 print '</td></tr>';
1657
1658
1659 // Model
1661 if (count($list) > 0) {
1662 print '<tr>';
1663 print '<td>'.$langs->trans("DefaultModel").'</td>';
1664 print '<td colspan="2">';
1665 print img_picto('', 'pdf', 'class="pictofixedwidth"');
1666 $preselected = getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT', getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF'));
1667 print $form->selectarray('model', $list, $preselected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
1668 print "</td></tr>";
1669 }
1670
1671 // Project
1672 if (isModEnabled('project')) {
1673 $langs->load("projects");
1674
1675 $formproject = new FormProjets($db);
1676
1677 if ($origin == 'project') {
1678 $projectid = ($originid ? $originid : 0);
1679 }
1680
1681 print '<tr>';
1682 print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
1683 if (!empty($user->socid)) { // external user: restrict to their own third party
1684 $projSocFilter = $user->socid;
1685 } elseif (getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') || $socid == 0) {
1686 // Give priority to the constant (as on supplier invoice), so a supplier document created from a
1687 // customer project keeps that project selected after the supplier is chosen.
1688 $projSocFilter = -1;
1689 } else {
1690 $projSocFilter = $socid;
1691 }
1692 print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects($projSocFilter, $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
1693 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>';
1694 print '</td>';
1695 print '</tr>';
1696 }
1697
1698 // Multicurrency
1699 if (isModEnabled("multicurrency")) {
1700 print '<tr>';
1701 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1702 print '<td colspan="3" class="maxwidthonsmartphone">';
1703 print img_picto('', 'currency', 'class="pictofixedwidth"');
1704 print $form->selectMultiCurrency($currency_code, 'multicurrency_code');
1705 print '</td></tr>';
1706 }
1707 // Categories
1708 if (isModEnabled('category')) {
1709 print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
1710 print $form->selectCategories(Categorie::TYPE_SUPPLIER_PROPOSAL, 'categories', $object);
1711 print "</td></tr>";
1712 }
1713
1714 // Other attributes
1715 $parameters = array('colspan' => ' colspan="3"', 'cols' => 3);
1716 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1717 print $hookmanager->resPrint;
1718 if (empty($reshook)) {
1719 print $object->showOptionals($extrafields, 'create', $parameters);
1720 }
1721
1722
1723 // Lines from source
1724 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && $classname !== null) {
1725 // TODO for compatibility
1726 if ($origin == 'contrat') {
1727 // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
1728 $objectsrc->update_price(1, 'auto', 1);
1729 }
1730
1731 print "\n<!-- ".$classname." info -->";
1732 print "\n";
1733 print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
1734 print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
1735 print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
1736 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1737 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1738
1739 print '<tr><td>'.$langs->trans('CommRequest').'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
1740 print '<tr><td>'.$langs->trans('AmountHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
1741 print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
1742 if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1
1743 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
1744 }
1745
1746 if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2
1747 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
1748 }
1749 print '<tr><td>'.$langs->trans('AmountTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
1750
1751 if (isModEnabled("multicurrency")) {
1752 print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).'</td></tr>';
1753 print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code)."</td></tr>";
1754 print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code)."</td></tr>";
1755 }
1756 }
1757
1758 print "</table>\n";
1759
1760
1761 /*
1762 * Combobox for copy function
1763 */
1764
1765 if (!getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
1766 print '<input type="hidden" name="createmode" value="empty">';
1767 }
1768
1769 if (getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
1770 print '<br><table>';
1771
1772 // For backward compatibility
1773 print '<tr>';
1774 print '<td><input type="radio" name="createmode" value="copy"></td>';
1775 print '<td>'.$langs->trans("CopyAskFrom").' </td>';
1776 print '<td>';
1777 $liste_ask = array();
1778 $liste_ask [0] = '';
1779
1780 $sql = "SELECT p.rowid as id, p.ref, s.nom";
1781 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal p";
1782 $sql .= ", ".MAIN_DB_PREFIX."societe s";
1783 $sql .= " WHERE s.rowid = p.fk_soc";
1784 $sql .= " AND p.entityy IN (".getEntity('supplier_proposal').")";
1785 $sql .= " AND p.fk_statut <> ".SupplierProposal::STATUS_DRAFT;
1786 $sql .= " ORDER BY Id";
1787
1788 $resql = $db->query($sql);
1789 if ($resql) {
1790 $num = $db->num_rows($resql);
1791 $i = 0;
1792 while ($i < $num) {
1793 $row = $db->fetch_row($resql);
1794 $askPriceSupplierRefAndSocName = $row[1]." - ".$row[2];
1795 $liste_ask[$row[0]] = $askPriceSupplierRefAndSocName;
1796 $i++;
1797 }
1798 print $form->selectarray("copie_supplier_proposal", $liste_ask, 0);
1799 } else {
1801 }
1802 print '</td></tr>';
1803
1804 print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
1805 print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyAsk").'</td></tr>';
1806 }
1807
1808 if (getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
1809 print '</table>';
1810 }
1811 }
1812
1813 print dol_get_fiche_end();
1814
1815 print $form->buttonsSaveCancel("CreateDraft");
1816
1817 print "</form>";
1818
1819
1820 // Show origin lines
1821 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1822 print '<br>';
1823
1824 $title = $langs->trans('ProductsAndServices');
1825 print load_fiche_titre($title);
1826
1827 print '<div class="div-table-responsive-no-min">';
1828 print '<table class="noborder centpercent">';
1829
1830 $objectsrc->printOriginLinesList();
1831
1832 print '</table>';
1833 print '</div>';
1834 }
1835} else {
1836 /*
1837 * Show object in view mode
1838 */
1839
1840 $soc = new Societe($db);
1841 $soc->fetch($object->socid);
1842
1843 $head = supplier_proposal_prepare_head($object);
1844 print dol_get_fiche_head($head, 'comm', $langs->trans('CommRequest'), -1, 'supplier_proposal', 0, '', '', 0, '', 1);
1845
1846 $formconfirm = '';
1847
1848 // Clone confirmation
1849 if ($action == 'clone') {
1850 $filter = '(s.fournisseur:=:1)';
1851 // Create an array for form
1852 $formquestion = array(
1853 // 'text' => $langs->trans("ConfirmClone"),
1854 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
1855 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' =>
1856 // 1),
1857 array(
1858 'type' => 'other',
1859 'name' => 'socid',
1860 'label' => $langs->trans("SelectThirdParty"),
1861 'value' => $form->select_company(GETPOSTINT('socid'), 'socid', $filter))
1862 );
1863 // Paiement incomplet. On demande si motif = escompte ou autre
1864 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1865 } elseif ($action == 'delete') {
1866 // Confirm delete
1867 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAsk'), $langs->trans('ConfirmDeleteAsk', $object->ref), 'confirm_delete', '', 0, 1);
1868 } elseif ($action == 'reopen') {
1869 // Confirm reopen
1870 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenAsk', $object->ref), 'confirm_reopen', '', 0, 1);
1871 } elseif ($action == 'ask_deleteline') {
1872 // Confirmation delete product/service line
1873 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
1874 } elseif ($action == 'ask_subtotal_deleteline') {
1875 // Generate form to ask confirmation to delete a subtotal line
1876 $langs->load("subtotals");
1877 $title = "DeleteSubtotalLine";
1878 $question = "ConfirmDeleteSubtotalLine";
1879 if (GETPOST('type') == 'title') {
1880 $formconfirm = [
1881 [
1882 'type' => 'checkbox',
1883 'name' => 'deletecorrespondingsubtotalline',
1884 'label' => $langs->trans("DeleteCorrespondingSubtotalLine"),
1885 'value' => 0,
1886 ],
1887 ];
1888 $title = "DeleteTitleLine";
1889 $question = "ConfirmDeleteTitleLine";
1890 }
1891 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans($title), $langs->trans($question), 'confirm_delete_subtotalline', $formconfirm, 'no', 1);
1892 } elseif ($action == 'validate') {
1893 // Confirm validate askprice
1894 $error = 0;
1895
1896 // Verify if the object has a temporary number
1897 $ref = substr($object->ref, 1, 4);
1898 if ($ref == 'PROV') {
1899 $numref = $object->getNextNumRef($soc);
1900 if (empty($numref)) {
1901 $error++;
1902 setEventMessages($object->error, $object->errors, 'errors');
1903 }
1904 } else {
1905 $numref = (string) $object->ref;
1906 }
1907
1908 $text = $langs->trans('ConfirmValidateAsk', $numref);
1909 if (isModEnabled('notification')) {
1910 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1911 $notify = new Notify($db);
1912 $text .= '<br>';
1913 $text .= $notify->confirmMessage('PROPOSAL_SUPPLIER_VALIDATE', $object->socid, $object);
1914 }
1915
1916 if (!$error) {
1917 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateAsk'), $text, 'confirm_validate', '', 0, 1);
1918 }
1919 }
1920 // Subtotal line form
1921 if ($action == 'add_title_line') {
1922 $langs->load('subtotals');
1923 $type = 'title';
1924 $depth_array = $object->getPossibleLevels($langs);
1925 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1926 } elseif ($action == 'add_subtotal_line') {
1927 $langs->load('subtotals');
1928 $type = 'subtotal';
1929 $titles = $object->getPossibleTitles();
1930 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1931 }
1932
1933 // Call Hook formConfirm
1934 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
1935 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1936 if (empty($reshook)) {
1937 $formconfirm .= $hookmanager->resPrint;
1938 } elseif ($reshook > 0) {
1939 $formconfirm = $hookmanager->resPrint;
1940 }
1941
1942 // Print form confirm
1943 print $formconfirm;
1944
1945
1946 // Supplier proposal card
1947 $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1948
1949
1950 $morehtmlref = '<div class="refidno">';
1951 // Ref supplier
1952 //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', 0, 1);
1953 //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', null, null, '', 1);
1954 // Thirdparty
1955 $morehtmlref .= $object->thirdparty->getNomUrl(1, 'supplier');
1956 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
1957 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherProposals").'</a>)';
1958 }
1959 // Project
1960 if (isModEnabled('project')) {
1961 $langs->load("projects");
1962 $morehtmlref .= '<br>';
1963 if ($usercancreate) {
1964 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1965 if ($action != 'classify') {
1966 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1967 }
1968 $canLinkAll = getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS');
1969 $canLinkAll = ($canLinkAll === '' || $canLinkAll === false) ? 0 : $canLinkAll;
1970 $currentSocId = ($object->id > 0) ? $object->socid : $socid;
1971 $projectSocId = ((int) $canLinkAll == 1) ? -1 : $currentSocId;
1972 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $projectSocId, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
1973 } else {
1974 if (!empty($object->fk_project)) {
1975 $proj = new Project($db);
1976 $proj->fetch($object->fk_project);
1977 $morehtmlref .= $proj->getNomUrl(1);
1978 if ($proj->title) {
1979 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
1980 }
1981 }
1982 }
1983 }
1984 $morehtmlref .= '</div>';
1985
1986
1987 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1988
1989 // Call Hook tabContentViewSupplierProposal
1990 $parameters = array();
1991 // Note that $action and $object may be modified by hook
1992 $reshook = $hookmanager->executeHooks('tabContentViewSupplierProposal', $parameters, $object, $action);
1993 if (empty($reshook)) {
1994 print '<div class="fichecenter">';
1995 print '<div class="fichehalfleft">';
1996 print '<div class="underbanner clearboth"></div>';
1997
1998 print '<table class="border tableforfield centpercent">';
1999
2000 // Relative and absolute discounts
2001 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
2002 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
2003 $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
2004 } else {
2005 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2006 $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2007 }
2008
2009 print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td>';
2010
2011 $absolute_discount = $soc->getAvailableDiscounts(null, $filterabsolutediscount, 0, 1);
2012 $absolute_creditnote = $soc->getAvailableDiscounts(null, $filtercreditnote, 0, 1);
2013 $absolute_discount = price2num($absolute_discount, 'MT');
2014 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
2015
2016 $thirdparty = $soc;
2017 $discount_type = 1;
2018 $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
2019 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
2020
2021 print '</td></tr>';
2022
2023 // Payment term
2024 print '<tr><td class="titlefield">';
2025 print '<table class="nobordernopadding" width="100%"><tr><td>';
2026 print $langs->trans('PaymentConditionsShort');
2027 print '</td>';
2028 if ($action != 'editconditions' && $object->status != SupplierProposal::STATUS_NOTSIGNED) {
2029 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>';
2030 }
2031 print '</tr></table>';
2032 print '</td><td class="valuefield">';
2033 if ($action == 'editconditions') {
2034 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent);
2035 } else {
2036 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->cond_reglement_id, 'none', 1, '', 1, $object->deposit_percent);
2037 }
2038 print '</td>';
2039 print '</tr>';
2040
2041 // Delivery date
2042 print '<tr><td>';
2043 print '<table class="nobordernopadding" width="100%"><tr><td>';
2044 print $langs->trans('DeliveryDate');
2045 print '</td>';
2046 if ($action != 'editdate_livraison' && $object->status != SupplierProposal::STATUS_NOTSIGNED) {
2047 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>';
2048 }
2049 print '</tr></table>';
2050 print '</td><td class="valuefield">';
2051 if ($action == 'editdate_livraison') {
2052 print '<form name="editdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2053 print '<input type="hidden" name="token" value="'.newToken().'">';
2054 print '<input type="hidden" name="action" value="setdate_livraison">';
2055 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2056 print $form->selectDate($object->delivery_date, 'liv_', 0, 0, 0, "editdate_livraison");
2057 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2058 print '</form>';
2059 } else {
2060 print dol_print_date($object->delivery_date, 'daytext');
2061 }
2062 print '</td>';
2063 print '</tr>';
2064
2065 // Payment mode
2066 print '<tr>';
2067 print '<td>';
2068 print '<table class="nobordernopadding" width="100%"><tr><td>';
2069 print $langs->trans('PaymentMode');
2070 print '</td>';
2071 if ($action != 'editmode' && $object->status != SupplierProposal::STATUS_NOTSIGNED) {
2072 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>';
2073 }
2074 print '</tr></table>';
2075 print '</td><td class="valuefield">';
2076 if ($action == 'editmode') {
2077 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1);
2078 } else {
2079 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->mode_reglement_id, 'none');
2080 }
2081 print '</td></tr>';
2082
2083 /* Not for supplier proposals
2084 if ($soc->outstanding_limit) {
2085 // Outstanding Bill
2086 print '<tr><td>';
2087 print $langs->trans('OutstandingBill');
2088 print '</td><td class="valuefield">';
2089 $arrayoutstandingbills = $soc->getOutstandingBills('supplier');
2090 $outstandingBills = $arrayoutstandingbills['opened'];
2091 print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency);
2092 print '</td>';
2093 print '</tr>';
2094 }*/
2095
2096 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL') && isModEnabled("bank")) {
2097 // Bank Account
2098 print '<tr><td>';
2099 print '<table width="100%" class="nobordernopadding"><tr><td>';
2100 print $langs->trans('BankAccount');
2101 print '</td>';
2102 if ($action != 'editbankaccount' && $usercancreate) {
2103 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>';
2104 }
2105 print '</tr></table>';
2106 print '</td><td class="valuefield">';
2107 if ($action == 'editbankaccount') {
2108 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'fk_account', 1);
2109 } else {
2110 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'none');
2111 }
2112 print '</td>';
2113 print '</tr>';
2114 }
2115 // Categories
2116 if (isModEnabled('category')) {
2117 print '<tr><td>';
2118 print '<table class="nobordernopadding centpercent"><tr><td>';
2119 print $langs->trans("Categories");
2120 print '<td><td class="right">';
2121 if ($usercancreate) {
2122 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$object->id.'&action=edittags&token='.newToken().'">'.img_edit().'</a>';
2123 } else {
2124 print '&nbsp;';
2125 }
2126 print '</td></tr></table>';
2127 print '</td>';
2128 print '<td>';
2129 if ($action == 'edittags') {
2130 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
2131 print '<input type="hidden" name="action" value="settags">';
2132 print '<input type="hidden" name="token" value="'.newToken().'">';
2133 print $form->selectCategories(Categorie::TYPE_SUPPLIER_PROPOSAL, 'categories', $object);
2134 print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
2135 print '</form>';
2136 } else {
2137 print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER_PROPOSAL, 1);
2138 }
2139 print "</td></tr>";
2140 }
2141 // Other attributes
2142 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2143
2144 print '</table>';
2145
2146 print '</div>';
2147 print '<div class="fichehalfright">';
2148 print '<div class="underbanner clearboth"></div>';
2149
2150 print '<table class="border tableforfield centpercent">';
2151
2152 include DOL_DOCUMENT_ROOT.'/core/tpl/object_currency_amount.tpl.php';
2153
2154 print '<tr>';
2155 // Amount HT
2156 print '<td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
2157 print '<td class="nowrap amountcard right">' . price($object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2158 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2159 // Multicurrency Amount HT
2160 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ht, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2161 }
2162 print '</tr>';
2163
2164 print '<tr>';
2165 // Amount VAT
2166 print '<td class="titlefieldmiddle">' . $langs->trans('AmountVAT') . '</td>';
2167 print '<td class="nowrap amountcard right">' . price($object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2168 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2169 // Multicurrency Amount VAT
2170 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_tva, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2171 }
2172 print '</tr>';
2173
2174 // Amount Local Taxes
2175 if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) {
2176 print '<tr>';
2177 print '<td class="titlefieldmiddle">' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
2178 print '<td class="nowrap amountcard right">' . price($object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2179 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2180 print '<td class="nowrap amountcard right">' . price($object->total_localtax1, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2181 }
2182 print '</tr>';
2183
2184 if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) {
2185 print '<tr>';
2186 print '<td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
2187 print '<td class="nowrap amountcard right">' . price($object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2188 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2189 print '<td class="nowrap amountcard right">' . price($object->total_localtax2, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2190 }
2191 print '</tr>';
2192 }
2193 }
2194
2195 print '<tr>';
2196 // Amount TTC
2197 print '<td>' . $langs->trans('AmountTTC') . '</td>';
2198 print '<td class="nowrap amountcard right">' . price($object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2199 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2200 // Multicurrency Amount TTC
2201 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2202 }
2203 print '</tr>';
2204
2205 print '</table>';
2206
2207 // Margin Infos
2208 /*if (isModEnabled('margin')) {
2209 $formmargin->displayMarginInfos($object);
2210 }*/
2211
2212 print '</div>';
2213 print '</div>';
2214
2215 print '<div class="clearboth"></div><br>';
2216
2217 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
2218 $blocname = 'contacts';
2219 $title = $langs->trans('ContactsAddresses');
2220 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2221 }
2222
2223 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
2224 $blocname = 'notes';
2225 $title = $langs->trans('Notes');
2226 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2227 }
2228
2229 /*
2230 * Lines
2231 */
2232
2233 // Show object lines
2234 $result = $object->getLinesArray();
2235
2236 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#add' : '').'" method="POST">
2237 <input type="hidden" name="token" value="' . newToken().'">
2238 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
2239 <input type="hidden" name="mode" value="">
2240 <input type="hidden" name="id" value="' . $object->id.'">
2241 <input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">
2242 ';
2243
2244 if (!empty($conf->use_javascript_ajax) && $object->status == SupplierProposal::STATUS_DRAFT) {
2245 if (isModEnabled('subtotals')) {
2246 include DOL_DOCUMENT_ROOT . '/core/tpl/subtotal_ajaxrow.tpl.php';
2247 } else {
2248 include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
2249 }
2250 }
2251
2252 print '<div class="div-table-responsive-no-min">';
2253 print '<table id="tablelines" class="noborder noshadow centpercent">';
2254
2255 // Add free products/services form
2256 global $forceall, $senderissupplier, $inputalsopricewithtax;
2257 $forceall = 1;
2258 $dateSelector = 0;
2259 $inputalsopricewithtax = 1;
2260 $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty.
2261 if (getDolGlobalInt('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY')) {
2262 $senderissupplier = getDolGlobalInt('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY');
2263 }
2264
2265 if (!empty($object->lines)) {
2266 $object->printObjectLines($action, $soc, $mysoc, $lineid, $dateSelector);
2267 }
2268
2269 // Form to add new line
2270 if ($object->status == SupplierProposal::STATUS_DRAFT && $usercancreate) {
2271 if ($action != 'editline') {
2272 // Add products/services form
2273
2274 $parameters = array('dateSelector' => $dateSelector);
2275 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2276 if ($reshook < 0) {
2277 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2278 }
2279 if (empty($reshook)) {
2280 $object->formAddObjectLine($dateSelector, $soc, $mysoc);
2281 }
2282 }
2283 }
2284
2285 print '</table>';
2286 print '</div>';
2287 print "</form>\n";
2288 }
2289
2290 print dol_get_fiche_end();
2291
2292 if ($action == 'statut') {
2293 // Form to set proposal accepted/refused
2294 $form_close = '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST" id="formacceptrefuse" class="formconsumeproduce paddingbottom paddingleft paddingright">';
2295 $form_close .= '<input type="hidden" name="token" value="'.newToken().'">';
2296 $form_close .= '<input type="hidden" name="action" value="setstatut">';
2297
2298 if (getDolGlobalString('SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL')) {
2299 $form_close .= '<p class="notice">'.$langs->trans('SupplierProposalRefFournNotice').'</p>'; // TODO Suggest a permanent checkbox instead of option
2300 }
2301 $form_close .= '<table class="border centpercent marginleftonly marginrightonly">';
2302 $form_close .= '<tr><td>'.$langs->trans("CloseAs").'</td><td class="left">';
2303 $form_close .= '<select id="statut" name="statut" class="flat">';
2304 $form_close .= '<option value="0">&nbsp;</option>';
2305 $form_close .= '<option value="2">'.$langs->trans('SupplierProposalStatusSigned').'</option>';
2306 $form_close .= '<option value="3">'.$langs->trans('SupplierProposalStatusNotSigned').'</option>';
2307 $form_close .= '</select>';
2308 $form_close .= '</td></tr>';
2309 $form_close .= '<tr><td class="left">'.$langs->trans('Note').'</td><td class="left"><textarea cols="70" rows="'.ROWS_3.'" wrap="soft" name="note">';
2310 $form_close .= $object->note_private;
2311 $form_close .= '</textarea></td></tr>';
2312 $form_close .= '</table>';
2313 $form_close .= $form->buttonsSaveCancel();
2314 $form_close .= '<a id="acceptedrefused">&nbsp;</a>';
2315 $form_close .= '</form>';
2316
2317 print $form_close;
2318 }
2319
2320 /*
2321 * Boutons Actions
2322 */
2323 if ($action != 'presend') {
2324 print '<div class="tabsAction">';
2325
2326 $parameters = array();
2327 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2328 // modified by hook
2329 if (empty($reshook)) {
2330 if ($action != 'statut' && $action != 'editline') {
2331 // Subtotal
2332 if ($object->status == SupplierProposal::STATUS_DRAFT && isModEnabled('subtotals') && getDolGlobalString('SUBTOTAL_TITLE_'.strtoupper($object->element))) {
2333 $langs->load('subtotals');
2334
2335 $url_button = array();
2336
2337 $url_button[] = array(
2338 'lang' => 'subtotals',
2339 'enabled' => $object->status == SupplierProposal::STATUS_DRAFT,
2340 'perm' => (bool) $usercancreate,
2341 'label' => $langs->trans('AddTitleLine'),
2342 'url' => dolBuildUrl($_SERVER['PHP_SELF'], ['id' => $object->id, 'action' => 'add_title_line'], true)
2343 );
2344
2345 $url_button[] = array(
2346 'lang' => 'subtotals',
2347 'enabled' => $object->status == SupplierProposal::STATUS_DRAFT,
2348 'perm' => (bool) $usercancreate,
2349 'label' => $langs->trans('AddSubtotalLine'),
2350 'url' => dolBuildUrl($_SERVER['PHP_SELF'], ['id' => $object->id, 'action' => 'add_subtotal_line'], true)
2351 );
2352
2353 print dolGetButtonAction('', $langs->trans('SubTotal'), 'default', $url_button, '', true);
2354 }
2355 // Validate
2356 if ($object->status == SupplierProposal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0 && $usercanvalidate) {
2357 if (count($object->lines) > 0) {
2358 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>';
2359 }
2360 // else print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Validate').'</a>';
2361 }
2362
2363 // Edit
2364 if ($object->status == SupplierProposal::STATUS_VALIDATED && $usercancreate) {
2365 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>';
2366 }
2367
2368 // ReOpen
2370 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').'"';
2371 print '>'.$langs->trans('ReOpen').'</a></div>';
2372 }
2373
2374 // Send
2375 if (empty($user->socid)) {
2377 if ($usercansend) {
2378 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'presend', 'mode' => 'init'], true).'#formmailbeforetitle', '');
2379 } else {
2380 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', '#', '', false);
2381 }
2382 }
2383 }
2384
2385 // Create an order
2386 if (isModEnabled("supplier_order") && $object->status == SupplierProposal::STATUS_SIGNED) {
2387 if ($usercancreateorder) {
2388 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>';
2389 }
2390 }
2391
2392 // Set accepted/refused
2393 if ($object->status == SupplierProposal::STATUS_VALIDATED && $usercanclose) {
2394 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').'"';
2395 print '>'.$langs->trans('SetAcceptedRefused').'</a></div>';
2396 }
2397
2398 // Close
2399 if ($object->status == SupplierProposal::STATUS_SIGNED && $usercanclose) {
2400 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').'"';
2401 print '>'.$langs->trans('Close').'</a></div>';
2402 }
2403
2404 // Clone
2405 if ($usercancreate) {
2406 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>';
2407 }
2408
2409 // Delete
2410 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', (($object->status == SupplierProposal::STATUS_DRAFT && $usercancreate) || $usercandelete));
2411 }
2412 }
2413
2414 print '</div>';
2415 }
2416
2417 if ($action != 'presend') {
2418 print '<div class="fichecenter"><div class="fichehalfleft">';
2419
2420 /*
2421 * Generated documents
2422 */
2423 $filename = dol_sanitizeFileName($object->ref);
2424 $filedir = $conf->supplier_proposal->dir_output."/".dol_sanitizeFileName($object->ref);
2425 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2426 $genallowed = $usercanread;
2427 $delallowed = $usercancreate;
2428
2429 print $formfile->showdocuments('supplier_proposal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
2430
2431
2432 // Show links to link elements
2433 $tmparray = $form->showLinkToObjectBlock($object, array(), array('supplier_proposal'), 1);
2434 $linktoelem = $tmparray['linktoelem'];
2435 $htmltoenteralink = $tmparray['htmltoenteralink'];
2436 print $htmltoenteralink;
2437
2438 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2439
2440 $MAXEVENT = 10;
2441
2442 print '</div><div class="fichehalfright">';
2443
2444 // List of actions on element
2445 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2446 $formactions = new FormActions($db);
2447 $somethingshown = $formactions->showactions($object, 'supplier_proposal', $socid, 1, '', $MAXEVENT);
2448
2449 print '</div></div>';
2450 }
2451
2452 // Select mail models is same action as presend
2453 if (GETPOST('modelselected')) {
2454 $action = 'presend';
2455 }
2456
2457 // Presend form
2458 $modelmail = 'supplier_proposal_send';
2459 $defaulttopic = 'SendAskRef';
2460 $diroutput = $conf->supplier_proposal->dir_output;
2461 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
2462 $trackid = 'spro'.$object->id;
2463
2464 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2465}
2466
2467// End of page
2468llxFooter();
2469$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 supplier_proposal lines.
Class to manage translations.
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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:492
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
supplier_proposal_prepare_head($object)
Prepare array with list of tabs.