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