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