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