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