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