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