dolibarr 19.0.3
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') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
79$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
80$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (getDolGlobalString('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 = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->supplier_proposal->validate_advance)));
113$usercansend = (!getDolGlobalString('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 (!getDolGlobalString('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 (!getDolGlobalString('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->delivery_date = $date_delivery;
285 $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
286 $object->cond_reglement_id = GETPOST('cond_reglement_id');
287 $object->mode_reglement_id = GETPOST('mode_reglement_id');
288 $object->fk_account = GETPOST('fk_account', 'int');
289 $object->socid = GETPOST('socid');
290 $object->fk_project = GETPOST('projectid', 'int');
291 $object->model_pdf = GETPOST('model');
292 $object->author = $user->id; // deprecated
293 $object->note = GETPOST('note', 'restricthtml');
294 $object->note_private = GETPOST('note', 'restricthtml');
295 $object->statut = SupplierProposal::STATUS_DRAFT;
296 } else {
297 setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_supplier_proposal')), null, 'errors');
298 }
299 } else {
300 $object->ref = GETPOST('ref');
301 $object->delivery_date = $date_delivery;
302 $object->demand_reason_id = GETPOST('demand_reason_id');
303 $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
304 $object->cond_reglement_id = GETPOST('cond_reglement_id');
305 $object->mode_reglement_id = GETPOST('mode_reglement_id');
306 $object->fk_account = GETPOST('fk_account', 'int');
307 $object->fk_project = GETPOST('projectid', 'int');
308 $object->model_pdf = GETPOST('model');
309 $object->author = $user->id; // deprecated
310 $object->note = GETPOST('note', 'restricthtml');
311 $object->note_private = GETPOST('note', 'restricthtml');
312
313 $object->origin = GETPOST('origin');
314 $object->origin_id = GETPOST('originid');
315
316 // Multicurrency
317 if (isModEnabled("multicurrency")) {
318 $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
319 }
320
321 // Fill array 'array_options' with data from add form
322 $ret = $extrafields->setOptionalsFromPost(null, $object);
323 if ($ret < 0) {
324 $error++;
325 $action = 'create';
326 }
327 }
328
329 if (!$error) {
330 if ($origin && $originid) {
331 // Parse element/subelement (ex: project_task)
332 $element = $subelement = $origin;
333 if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
334 $element = $regs[1];
335 $subelement = $regs[2];
336 }
337
338 // For compatibility
339 if ($element == 'order') {
340 $element = $subelement = 'commande';
341 }
342 if ($element == 'propal') {
343 $element = 'comm/propal';
344 $subelement = 'propal';
345 }
346 if ($element == 'contract') {
347 $element = $subelement = 'contrat';
348 }
349 if ($element == 'inter') {
350 $element = $subelement = 'ficheinter';
351 }
352 if ($element == 'shipping') {
353 $element = $subelement = 'expedition';
354 }
355
356 $object->origin = $origin;
357 $object->origin_id = $originid;
358
359 // Possibility to add external linked objects with hooks
360 $object->linked_objects [$object->origin] = $object->origin_id;
361 if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
362 $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
363 }
364
365 $id = $object->create($user);
366 if ($id > 0) {
367 dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
368
369 $classname = ucfirst($subelement);
370 $srcobject = new $classname($db);
371
372 dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
373 $result = $srcobject->fetch($object->origin_id);
374
375 if ($result > 0) {
376 $lines = $srcobject->lines;
377 if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
378 $srcobject->fetch_lines();
379 $lines = $srcobject->lines;
380 }
381
382 $fk_parent_line = 0;
383 $num = count($lines);
384 for ($i = 0; $i < $num; $i++) {
385 $label = (!empty($lines[$i]->label) ? $lines[$i]->label : '');
386 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
387
388 // Positive line
389 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
390
391 // Reset fk_parent_line for no child products and special product
392 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
393 $fk_parent_line = 0;
394 }
395
396 // Extrafields
397 if (method_exists($lines[$i], 'fetch_optionals')) {
398 $lines[$i]->fetch_optionals();
399 $array_options = $lines[$i]->array_options;
400 }
401
402 $result = $object->addline(
403 $desc,
404 $lines[$i]->subprice,
405 $lines[$i]->qty,
406 $lines[$i]->tva_tx,
407 $lines[$i]->localtax1_tx,
408 $lines[$i]->localtax2_tx,
409 $lines[$i]->fk_product,
410 $lines[$i]->remise_percent,
411 'HT',
412 0,
413 $lines[$i]->info_bits,
414 $product_type,
415 $lines[$i]->rang,
416 $lines[$i]->special_code,
417 $fk_parent_line,
418 $lines[$i]->fk_fournprice,
419 $lines[$i]->pa_ht,
420 $label,
421 $array_options,
422 $lines[$i]->ref_supplier,
423 $lines[$i]->fk_unit
424 );
425
426 if ($result > 0) {
427 $lineid = $result;
428 } else {
429 $lineid = 0;
430 $error++;
431 break;
432 }
433
434 // Defined the new fk_parent_line
435 if ($result > 0 && $lines[$i]->product_type == 9) {
436 $fk_parent_line = $result;
437 }
438 }
439
440 // Hooks
441 $parameters = array('objFrom' => $srcobject);
442 $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
443 // modified by hook
444 if ($reshook < 0) {
445 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
446 $error++;
447 }
448 } else {
449 setEventMessages($srcobject->error, $srcobject->errors, 'errors');
450 $error++;
451 }
452 } else {
453 setEventMessages($object->error, $object->errors, 'errors');
454 $error++;
455 }
456 } else {
457 // Standard creation
458 $id = $object->create($user);
459 }
460
461 if ($id > 0) {
462 if (!$error) {
463 $db->commit();
464
465 // Define output language
466 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
467 $outputlangs = $langs;
468 $newlang = '';
469 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
470 $newlang = GETPOST('lang_id', 'aZ09');
471 }
472 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
473 $newlang = $object->thirdparty->default_lang;
474 }
475 if (!empty($newlang)) {
476 $outputlangs = new Translate("", $conf);
477 $outputlangs->setDefaultLang($newlang);
478 }
479 $model = $object->model_pdf;
480
481 $ret = $object->fetch($id); // Reload to get new records
482 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
483 if ($result < 0) {
484 dol_print_error($db, $result);
485 }
486 }
487
488 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
489 exit();
490 } else {
491 $db->rollback();
492 $action = 'create';
493 }
494 } else {
495 setEventMessages($object->error, $object->errors, 'errors');
496 $db->rollback();
497 $action = 'create';
498 }
499 }
500 }
501 } elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) {
502 // Reopen proposal
503 // prevent browser refresh from reopening proposal several times
504 if ($object->statut == SupplierProposal::STATUS_SIGNED || $object->statut == SupplierProposal::STATUS_NOTSIGNED || $object->statut == SupplierProposal::STATUS_CLOSE) {
505 $object->reopen($user, SupplierProposal::STATUS_VALIDATED);
506 }
507 } elseif ($action == 'close' && $usercanclose && !GETPOST('cancel', 'alpha')) {
508 // Close proposal
509 // prevent browser refresh from reopening proposal several times
510 if ($object->statut == SupplierProposal::STATUS_SIGNED) {
511 $object->setStatut(SupplierProposal::STATUS_CLOSE);
512 }
513 } elseif ($action == 'setstatut' && $usercanclose && !GETPOST('cancel', 'alpha')) {
514 // Set accepted/refused
515 if (!GETPOST('statut')) {
516 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("CloseAs")), null, 'errors');
517 $action = 'statut';
518 } else {
519 // prevent browser refresh from closing proposal several times
520 if ($object->statut == SupplierProposal::STATUS_VALIDATED) {
521 $object->cloture($user, GETPOST('statut'), GETPOST('note', 'restricthtml'));
522 }
523 }
524 }
525
526 // Actions when printing a doc from card
527 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
528
529 // Actions to send emails
530 $triggersendname = 'PROPOSAL_SUPPLIER_SENTBYMAIL';
531 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
532 $trackid = 'spro'.$object->id;
533 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
534
535 // Actions to build doc
536 $upload_dir = $conf->supplier_proposal->dir_output;
537 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
538
539
540 // Go back to draft
541 if ($action == 'modif' && $usercancreate) {
542 $object->setDraft($user);
543
544 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
545 // Define output language
546 $outputlangs = $langs;
547 if (getDolGlobalInt('MAIN_MULTILANGS')) {
548 $outputlangs = new Translate("", $conf);
549 $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
550 $outputlangs->setDefaultLang($newlang);
551 }
552 $ret = $object->fetch($id); // Reload to get new records
553 if ($ret > 0) {
554 $object->fetch_thirdparty();
555 }
556 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
557 }
558 } elseif ($action == "setabsolutediscount" && $usercancreate) {
559 if (GETPOST("remise_id", 'int')) {
560 if ($object->id > 0) {
561 $result = $object->insert_discount(GETPOST("remise_id", 'int'));
562 if ($result < 0) {
563 setEventMessages($object->error, $object->errors, 'errors');
564 }
565 }
566 }
567 }
568
569 // Add a product line
570 if ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && GETPOST('vatforalllines', 'alpha') && $usercancreate) {
571 // Define vat_rate
572 $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
573 $vat_rate = str_replace('*', '', $vat_rate);
574 $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
575 $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
576 foreach ($object->lines as $line) {
577 $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);
578 }
579 } elseif ($action == 'addline' && $usercancreate) {
580 $langs->load('errors');
581 $error = 0;
582
583 // Set if we used free entry or predefined product
584 $predef = '';
585 $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
586 $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'));
587 $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'));
588
589 $ref_supplier = GETPOST('fourn_ref', 'alpha');
590
591 $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
592 if ($prod_entry_mode == 'free') {
593 $idprod = 0;
594 } else {
595 $idprod = GETPOST('idprod', 'int');
596 }
597
598 $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)'
599
600 $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
601 $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
602 $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
603 $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
604
605 $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
606
607 $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
608 if (empty($remise_percent)) {
609 $remise_percent = 0;
610 }
611
612 // Extrafields
613 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
614 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
615 // Unset extrafield
616 if (is_array($extralabelsline)) {
617 // Get extra fields
618 foreach ($extralabelsline as $key => $value) {
619 unset($_POST["options_".$key]);
620 }
621 }
622
623 if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) {
624 setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
625 $error++;
626 }
627 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
628 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
629 $error++;
630 }
631
632 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.
633 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPrice")), null, 'errors');
634 $error++;
635 }
636 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
637 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
638 $error++;
639 }
640 if (!$error && ($qty >= 0)) {
641 $pu_ht = price2num($price_ht, 'MU');
642 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
643 $price_min = 0;
644 $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
645
646 $db->begin();
647
648 if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
649 $productsupplier = new ProductFournisseur($db);
650
651 $idprod = 0;
652 if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') {
653 $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, ...)
654 }
655
656 $reg = array();
657 if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) {
658 $idprod = $reg[1];
659 $res = $productsupplier->fetch($idprod); // Load product from its id
660 // Call to init some price properties of $productsupplier
661 // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
662 if (getDolGlobalString('SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
663 $fksoctosearch = 0;
664 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
665 if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price
666 $productsupplier->ref_supplier = '';
667 }
668 } else {
669 $fksoctosearch = $object->thirdparty->id;
670 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
671 }
672 } elseif (GETPOST('idprodfournprice', 'alpha') > 0) {
673 //$qtytosearch=$qty; // Just to see if a price exists for the quantity. Not used to found vat.
674 $qtytosearch = -1; // We force qty to -1 to be sure to find if the supplier price that exists
675 $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch);
676 $res = $productsupplier->fetch($idprod);
677 }
678
679 if ($idprod > 0) {
680 $label = $productsupplier->label;
681
682 // Define output language
683 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
684 $outputlangs = $langs;
685 $newlang = '';
686 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
687 $newlang = GETPOST('lang_id', 'aZ09');
688 }
689 if (empty($newlang)) {
690 $newlang = $object->thirdparty->default_lang;
691 }
692 if (!empty($newlang)) {
693 $outputlangs = new Translate("", $conf);
694 $outputlangs->setDefaultLang($newlang);
695 }
696 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description;
697 } else {
698 $desc = $productsupplier->description;
699 }
700 // if we use supplier description of the products
701 if (!empty($productsupplier->desc_supplier) && getDolGlobalString('PRODUIT_FOURN_TEXTS')) {
702 $desc = $productsupplier->desc_supplier;
703 }
704
705 //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time
706 if (trim($product_desc) == trim($desc) && getDolGlobalString('PRODUIT_AUTOFILL_DESC')) {
707 $product_desc='';
708 }
709
710 if (!empty($product_desc) && getDolGlobalString('MAIN_NO_CONCAT_DESCRIPTION')) {
711 $desc = $product_desc;
712 }
713 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
714 $desc = dol_concatdesc($desc, $product_desc, '', getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION'));
715 }
716
717 $ref_supplier = $productsupplier->ref_supplier;
718
719 // Get vat rate
720 $tva_npr = 0;
721 if (!GETPOSTISSET('tva_tx')) { // If vat rate not provided from the form (the form has the priority)
722 $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
723 $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
724 }
725 if (empty($tva_tx)) {
726 $tva_npr = 0;
727 }
728 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
729 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
730
731 $type = $productsupplier->type;
732 if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
733 $price_base_type = 'HT';
734 $pu = price2num($price_ht, 'MU');
735 $pu_devise = price2num($price_ht_devise, 'CU');
736 } elseif (GETPOST('price_ttc') != '' || GETPOST('multicurrency_price_ttc') != '') {
737 $price_base_type = 'TTC';
738 $pu = price2num($price_ttc, 'MU');
739 $pu_devise = price2num($price_ttc_devise, 'CU');
740 } else {
741 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
742 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
743 $pu = $productsupplier->fourn_pu;
744 $pu_devise = 0;
745 } else {
746 $pu = $productsupplier->fourn_pu;
747 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
748 }
749 }
750
751 if (empty($pu)) {
752 $pu = 0; // If pu is '' or null, we force to have a numeric value
753 }
754
755 // 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)
756 $fournprice = (is_numeric(GETPOST('idprodfournprice', 'alpha')) ? GETPOST('idprodfournprice', 'alpha') : -1);
757 $buyingprice = 0;
758
759 $result = $object->addline(
760 $desc,
761 ($price_base_type == 'HT' ? $pu : 0),
762 $qty,
763 $tva_tx,
764 $localtax1_tx,
765 $localtax2_tx,
766 $productsupplier->id,
767 $remise_percent,
768 $price_base_type,
769 ($price_base_type == 'TTC' ? $pu : 0),
770 $tva_npr,
771 $type,
772 min($rank, count($object->lines) + 1),
773 0,
774 GETPOST('fk_parent_line'),
775 $fournprice,
776 $buyingprice,
777 $label,
778 $array_options,
779 $ref_supplier,
780 $productsupplier->fk_unit,
781 '',
782 0,
783 $pu_devise,
784 $date_start,
785 $date_end
786 );
787
788 //var_dump($tva_tx);
789 //var_dump($productsupplier->fourn_pu);
790 //var_dump($price_base_type);exit;
791 if ($result < 0) {
792 $error++;
793 setEventMessages($object->error, $object->errors, 'errors');
794 }
795 }
796 if ($idprod == -99 || $idprod == 0) {
797 // Product not selected
798 $error++;
799 $langs->load("errors");
800 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")).' '.$langs->trans("or").' '.$langs->trans("NoPriceDefinedForThisSupplier"), null, 'errors');
801 }
802 if ($idprod == -1) {
803 // Quantity too low
804 $error++;
805 $langs->load("errors");
806 setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors');
807 }
808 } elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '' || GETPOST('multicurrency_price_ht') != '') && empty($error)) { // Free product. // $price_ht is already set
809 $pu_ht = price2num($price_ht, 'MU');
810 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
811
812 $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
813 $tva_tx = str_replace('*', '', $tva_tx);
814 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
815 $desc = $product_desc;
816 $type = GETPOST('type');
817
818 $fk_unit = GETPOST('units', 'alpha');
819
820 if (!preg_match('/\‍((.*)\‍)/', $tva_tx)) {
821 $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'
822 }
823
824 // Local Taxes
825 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
826 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
827
828 if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
829 $pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
830 } else {
831 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
832 $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
833 }
834 $price_base_type = 'HT';
835 $pu_ht_devise = price2num($price_ht_devise, 'CU');
836 $info_bits = 0;
837
838 $result = $object->addline(
839 $desc,
840 $pu_ht,
841 $qty,
842 $tva_tx,
843 $localtax1_tx,
844 $localtax2_tx,
845 $idprod,
846 $remise_percent,
847 $price_base_type,
848 $pu_ttc,
849 $info_bits,
850 $type,
851 -1, // rang
852 0, // special_code
853 GETPOST('fk_parent_line'),
854 $fournprice,
855 $buyingprice,
856 $label,
857 $array_options,
858 $ref_supplier,
859 $fk_unit,
860 '', // origin
861 0, // origin_id
862 $pu_ht_devise
863 );
864 }
865
866
867 if (!$error && $result > 0) {
868 $db->commit();
869
870 $ret = $object->fetch($object->id); // Reload to get new records
871
872 // Define output language
873 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
874 $outputlangs = $langs;
875 $newlang = '';
876 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
877 $newlang = GETPOST('lang_id', 'aZ09');
878 }
879 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
880 $newlang = $object->thirdparty->default_lang;
881 }
882 if (!empty($newlang)) {
883 $outputlangs = new Translate("", $conf);
884 $outputlangs->setDefaultLang($newlang);
885 }
886 $model = $object->model_pdf;
887 $ret = $object->fetch($id); // Reload to get new records
888 if ($ret > 0) {
889 $object->fetch_thirdparty();
890 }
891
892 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
893 if ($result < 0) {
894 dol_print_error($db, $result);
895 }
896 }
897
898 unset($_POST['prod_entry_mode']);
899
900 unset($_POST['qty']);
901 unset($_POST['type']);
902 unset($_POST['remise_percent']);
903 unset($_POST['pu']);
904 unset($_POST['price_ht']);
905 unset($_POST['multicurrency_price_ht']);
906 unset($_POST['price_ttc']);
907 unset($_POST['fourn_ref']);
908 unset($_POST['tva_tx']);
909 unset($_POST['label']);
910 unset($_POST['product_ref']);
911 unset($_POST['product_label']);
912 unset($_POST['product_desc']);
913 unset($_POST['fournprice']);
914 unset($_POST['buying_price']);
915 unset($localtax1_tx);
916 unset($localtax2_tx);
917 unset($_POST['np_marginRate']);
918 unset($_POST['np_markRate']);
919 unset($_POST['dp_desc']);
920 unset($_POST['idprodfournprice']);
921 unset($_POST['units']);
922
923 unset($_POST['idprod']);
924
925 unset($_POST['date_starthour']);
926 unset($_POST['date_startmin']);
927 unset($_POST['date_startsec']);
928 unset($_POST['date_startday']);
929 unset($_POST['date_startmonth']);
930 unset($_POST['date_startyear']);
931 unset($_POST['date_endhour']);
932 unset($_POST['date_endmin']);
933 unset($_POST['date_endsec']);
934 unset($_POST['date_endday']);
935 unset($_POST['date_endmonth']);
936 unset($_POST['date_endyear']);
937 } else {
938 $db->rollback();
939
940 setEventMessages($object->error, $object->errors, 'errors');
941 }
942 }
943 } elseif ($action == 'updateline' && $usercancreate && GETPOST('save') == $langs->trans("Save")) {
944 // Update a line within proposal
945 $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
946
947 // Define info_bits
948 $info_bits = 0;
949 if (preg_match('/\*/', $vat_rate)) {
950 $info_bits |= 0x01;
951 }
952
953 // Clean parameters
954 $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
955
956 // Define vat_rate
957 $vat_rate = str_replace('*', '', $vat_rate);
958 $localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
959 $localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
960
961 if (GETPOST('price_ht') != '') {
962 $price_base_type = 'HT';
963 $ht = price2num(GETPOST('price_ht'), '', 2);
964 } else {
965 $reg = array();
966 $vatratecleaned = $vat_rate;
967 if (preg_match('/^(.*)\s*\‍((.*)\‍)$/', $vat_rate, $reg)) { // If vat is "xx (yy)"
968 $vatratecleaned = trim($reg[1]);
969 $vatratecode = $reg[2];
970 }
971
972 $ttc = price2num(GETPOST('price_ttc'), '', 2);
973 $ht = (float) $ttc / (1 + ((float) $vatratecleaned / 100));
974 $price_base_type = 'HT';
975 }
976
977 $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), 'CU', 2);
978
979 // Add buying price
980 $fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
981 $buyingprice = (GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
982
983 // Extrafields Lines
984 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
985 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
986 // Unset extrafield POST Data
987 if (is_array($extralabelsline)) {
988 foreach ($extralabelsline as $key => $value) {
989 unset($_POST["options_".$key]);
990 }
991 }
992
993 // Define special_code for special lines
994 $special_code = GETPOST('special_code');
995 if (!GETPOST('qty')) {
996 $special_code = 3;
997 }
998
999 // Check minimum price
1000 $productid = GETPOST('productid', 'int');
1001 if (!empty($productid)) {
1002 $productsupplier = new ProductFournisseur($db);
1003 if (getDolGlobalString('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY')) {
1004 if ($productid > 0 && $productsupplier->get_buyprice(0, price2num(GETPOST('qty')), $productid, 'none', GETPOST('socid', 'int')) < 0) {
1005 setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'warnings');
1006 }
1007 }
1008
1009 $product = new Product($db);
1010 $res = $product->fetch($productid);
1011
1012 $type = $product->type;
1013
1014 $price_min = $product->price_min;
1015 if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
1016 $price_min = $product->multiprices_min [$object->thirdparty->price_level];
1017 }
1018
1019 $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
1020 } else {
1021 $type = GETPOST('type');
1022 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1023
1024 // Check parameters
1025 if (GETPOST('type') < 0) {
1026 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1027 $error++;
1028 }
1029 }
1030
1031 if (!$error) {
1032 $db->begin();
1033
1034 $ref_supplier = GETPOST('fourn_ref', 'alpha');
1035 $fk_unit = GETPOST('units');
1036
1037 $result = $object->updateline(
1038 GETPOST('lineid', 'int'),
1039 $ht,
1040 price2num(GETPOST('qty'), 'MS', 2),
1041 price2num(GETPOST('remise_percent'), '', 2),
1042 $vat_rate,
1043 $localtax1_rate,
1044 $localtax2_rate,
1045 $description,
1046 $price_base_type,
1047 $info_bits,
1048 $special_code,
1049 GETPOST('fk_parent_line', 'int'),
1050 0,
1051 $fournprice,
1052 $buyingprice,
1053 $label,
1054 $type,
1055 $array_options,
1056 $ref_supplier,
1057 $fk_unit,
1058 $pu_ht_devise
1059 );
1060
1061 if ($result >= 0) {
1062 $db->commit();
1063
1064 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1065 // Define output language
1066 $outputlangs = $langs;
1067 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1068 $outputlangs = new Translate("", $conf);
1069 $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
1070 $outputlangs->setDefaultLang($newlang);
1071 }
1072 $ret = $object->fetch($id); // Reload to get new records
1073 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1074 }
1075
1076 unset($_POST['qty']);
1077 unset($_POST['type']);
1078 unset($_POST['productid']);
1079 unset($_POST['remise_percent']);
1080 unset($_POST['price_ht']);
1081 unset($_POST['multicurrency_price_ht']);
1082 unset($_POST['price_ttc']);
1083 unset($_POST['tva_tx']);
1084 unset($_POST['product_ref']);
1085 unset($_POST['product_label']);
1086 unset($_POST['product_desc']);
1087 unset($_POST['fournprice']);
1088 unset($_POST['buying_price']);
1089
1090 unset($_POST['date_starthour']);
1091 unset($_POST['date_startmin']);
1092 unset($_POST['date_startsec']);
1093 unset($_POST['date_startday']);
1094 unset($_POST['date_startmonth']);
1095 unset($_POST['date_startyear']);
1096 unset($_POST['date_endhour']);
1097 unset($_POST['date_endmin']);
1098 unset($_POST['date_endsec']);
1099 unset($_POST['date_endday']);
1100 unset($_POST['date_endmonth']);
1101 unset($_POST['date_endyear']);
1102 } else {
1103 $db->rollback();
1104
1105 setEventMessages($object->error, $object->errors, 'errors');
1106 }
1107 }
1108 } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
1109 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
1110 exit();
1111 } elseif ($action == 'classin' && $usercancreate) {
1112 // Set project
1113 $object->setProject(GETPOST('projectid'), 'int');
1114 } elseif ($action == 'setavailability' && $usercancreate) {
1115 // Delivery delay
1116 $result = $object->availability(GETPOST('availability_id'));
1117 } elseif ($action == 'setconditions' && $usercancreate) {
1118 // Terms of payments
1119 $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
1120 //} elseif ($action == 'setremisepercent' && $usercancreate) {
1121 // $result = $object->set_remise_percent($user, price2num(GETPOST('remise_percent'), '', 2));
1122 //} elseif ($action == 'setremiseabsolue' && $usercancreate) {
1123 // $result = $object->set_remise_absolue($user, price2num(GETPOST('remise_absolue'), 'MU', 2));
1124 } elseif ($action == 'setmode' && $usercancreate) {
1125 // Payment mode
1126 $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
1127 } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
1128 // Multicurrency Code
1129 $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
1130 } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
1131 // Multicurrency rate
1132 $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int'));
1133 } elseif ($action == 'update_extras') {
1134 $object->oldcopy = dol_clone($object, 2);
1135
1136 // Fill array 'array_options' with data from update form
1137 $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
1138 if ($ret < 0) {
1139 $error++;
1140 }
1141
1142 if (!$error) {
1143 $result = $object->insertExtraFields('PROPOSAL_SUPPLIER_MODIFY');
1144 if ($result < 0) {
1145 setEventMessages($object->error, $object->errors, 'errors');
1146 $error++;
1147 }
1148 }
1149
1150 if ($error) {
1151 $action = 'edit_extras';
1152 }
1153 }
1154}
1155
1156
1157/*
1158 * View
1159 */
1160
1161$title = $object->ref." - ".$langs->trans('Card');
1162if ($action == 'create') {
1163 $title = $langs->trans("SupplierProposalNew");
1164}
1165$help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
1166
1167llxHeader('', $title, $help_url);
1168
1169$form = new Form($db);
1170$formother = new FormOther($db);
1171$formfile = new FormFile($db);
1172$formmargin = new FormMargin($db);
1173$companystatic = new Societe($db);
1174if (isModEnabled('project')) {
1175 $formproject = new FormProjets($db);
1176}
1177
1178$now = dol_now();
1179
1180// Add new askprice
1181if ($action == 'create') {
1182 $currency_code = $conf->currency;
1183
1184 print load_fiche_titre($langs->trans("SupplierProposalNew"), '', 'supplier_proposal');
1185
1186 $soc = new Societe($db);
1187 if ($socid > 0) {
1188 $res = $soc->fetch($socid);
1189 }
1190
1191 // Load objectsrc
1192 if (!empty($origin) && !empty($originid)) {
1193 $element = $subelement = GETPOST('origin');
1194 if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs)) {
1195 $element = $regs[1];
1196 $subelement = $regs[2];
1197 }
1198
1199 // For compatibility
1200 if ($element == 'order' || $element == 'commande') {
1201 $element = $subelement = 'commande';
1202 }
1203 if ($element == 'propal') {
1204 $element = 'comm/propal';
1205 $subelement = 'propal';
1206 }
1207
1208 dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1209
1210 $classname = ucfirst($subelement);
1211 $objectsrc = new $classname($db);
1212 $objectsrc->fetch($originid);
1213 if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1214 $objectsrc->fetch_lines();
1215 }
1216 $objectsrc->fetch_thirdparty();
1217
1218 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
1219 $soc = $objectsrc->thirdparty;
1220
1221 $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
1222 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1223
1224 // Replicate extrafields
1225 $objectsrc->fetch_optionals();
1226 $object->array_options = $objectsrc->array_options;
1227
1228 if (isModEnabled("multicurrency")) {
1229 if (!empty($objectsrc->multicurrency_code)) {
1230 $currency_code = $objectsrc->multicurrency_code;
1231 }
1232 if (getDolGlobalString('MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1233 $currency_tx = $objectsrc->multicurrency_tx;
1234 }
1235 }
1236 } else {
1237 $cond_reglement_id = $soc->cond_reglement_supplier_id;
1238 $mode_reglement_id = $soc->mode_reglement_supplier_id;
1239 if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) {
1240 $currency_code = $soc->multicurrency_code;
1241 }
1242 }
1243
1244 $object = new SupplierProposal($db);
1245
1246 print '<form name="addprop" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1247 print '<input type="hidden" name="token" value="'.newToken().'">';
1248 print '<input type="hidden" name="action" value="add">';
1249 if ($origin != 'project' && $originid) {
1250 print '<input type="hidden" name="origin" value="'.$origin.'">';
1251 print '<input type="hidden" name="originid" value="'.$originid.'">';
1252 }
1253 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1254
1255 print dol_get_fiche_head();
1256
1257 // Call Hook tabContentCreateSupplierProposal
1258 $parameters = array();
1259 // Note that $action and $object may be modified by hook
1260 $reshook = $hookmanager->executeHooks('tabContentCreateSupplierProposal', $parameters, $object, $action);
1261 if (empty($reshook)) {
1262 print '<table class="border centpercent">';
1263
1264 // Reference
1265 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
1266
1267 // Third party
1268 print '<tr>';
1269 print '<td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
1270 if ($socid > 0) {
1271 print '<td colspan="2">';
1272 print $soc->getNomUrl(1, 'supplier');
1273 print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1274 print '</td>';
1275 } else {
1276 print '<td colspan="2">';
1277 $filter = '((s.fournisseur:=:1) AND (s.status:=:1))';
1278 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company((empty($socid) ? '' : $socid), 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth175 maxwidth500 widthcentpercentminusxx');
1279 // reload page to retrieve customer informations
1280 if (getDolGlobalString('RELOAD_PAGE_ON_SUPPLIER_CHANGE')) {
1281 print '<script>
1282 $(document).ready(function() {
1283 $("#socid").change(function() {
1284 console.log("We have changed the company - Reload page");
1285 // reload page
1286 $("input[name=action]").val("create");
1287 $("form[name=add]").submit();
1288 });
1289 });
1290 </script>';
1291 }
1292 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>';
1293 print '</td>';
1294 }
1295 print '</tr>'."\n";
1296
1297 if ($soc->id > 0) {
1298 // Discounts for third party
1299 print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
1300
1301 $absolute_discount = $soc->getAvailableDiscounts('', '', 0, 1);
1302
1303 $thirdparty = $soc;
1304 $discount_type = 1;
1305 $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
1306 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1307
1308 print '</td></tr>';
1309 }
1310
1311 // Terms of payment
1312 print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
1313 print img_picto('', 'payment', 'class="pictofixedwidth"');
1314 print $form->getSelectConditionsPaiements(GETPOST('cond_reglement_id') > 0 ? GETPOST('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id', -1, 1);
1315 print '</td></tr>';
1316
1317 // Mode of payment
1318 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
1319 print img_picto('', 'bank', 'class="pictofixedwidth"');
1320 $form->select_types_paiements(GETPOST('mode_reglement_id') > 0 ? GETPOST('mode_reglement_id') : $mode_reglement_id, 'mode_reglement_id');
1321 print '</td></tr>';
1322
1323 // Bank Account
1324 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL') && isModEnabled("banque")) {
1325 print '<tr><td>'.$langs->trans('BankAccount').'</td><td colspan="2">';
1326 $form->select_comptes(GETPOST('fk_account') > 0 ? GETPOST('fk_account', 'int') : $fk_account, 'fk_account', 0, '', 1);
1327 print '</td></tr>';
1328 }
1329
1330 // Shipping Method
1331 if (isModEnabled("expedition")) {
1332 print '<tr><td>'.$langs->trans('SendingMethod').'</td><td colspan="2">';
1333 print img_picto('', 'dolly', 'class="pictofixedwidth"');
1334 $form->selectShippingMethod(GETPOST('shipping_method_id') > 0 ? GETPOST('shipping_method_id', 'int') : "", 'shipping_method_id', '', 1);
1335 print '</td></tr>';
1336 }
1337
1338 // Delivery date (or manufacturing)
1339 print '<tr><td>'.$langs->trans("DeliveryDate").'</td>';
1340 print '<td colspan="2">';
1341 print img_picto('', 'action', 'class="pictofixedwidth"');
1342 $datedelivery = dol_mktime(0, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
1343 if (is_numeric(getDolGlobalString('DATE_LIVRAISON_WEEK_DELAY'))) { // If value set to 0 or a num, not empty
1344 $tmpdte = time() + (7 * getDolGlobalInt('DATE_LIVRAISON_WEEK_DELAY') * 24 * 60 * 60);
1345 $syear = date("Y", $tmpdte);
1346 $smonth = date("m", $tmpdte);
1347 $sday = date("d", $tmpdte);
1348 print $form->selectDate($syear."-".$smonth."-".$sday, 'liv_', '', '', '', "addask");
1349 } else {
1350 print $form->selectDate($datedelivery ? $datedelivery : -1, 'liv_', '', '', '', "addask", 1, 1);
1351 }
1352 print '</td></tr>';
1353
1354
1355 // Model
1356 print '<tr>';
1357 print '<td>'.$langs->trans("DefaultModel").'</td>';
1358 print '<td colspan="2">';
1359 print img_picto('', 'pdf', 'class="pictofixedwidth"');
1361 $preselected = (getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT') ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT : $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF);
1362 print $form->selectarray('model', $list, $preselected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
1363 print "</td></tr>";
1364
1365 // Project
1366 if (isModEnabled('project')) {
1367 $langs->load("projects");
1368
1369 $formproject = new FormProjets($db);
1370
1371 if ($origin == 'project') {
1372 $projectid = ($originid ? $originid : 0);
1373 }
1374
1375 print '<tr>';
1376 print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
1377 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');
1378 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>';
1379
1380 print '</td>';
1381 print '</tr>';
1382 }
1383
1384 // Multicurrency
1385 if (isModEnabled("multicurrency")) {
1386 print '<tr>';
1387 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1388 print '<td colspan="3" class="maxwidthonsmartphone">';
1389 print img_picto('', 'currency', 'class="pictofixedwidth"');
1390 print $form->selectMultiCurrency($currency_code, 'multicurrency_code');
1391 print '</td></tr>';
1392 }
1393
1394 // Other attributes
1395 $parameters = array('colspan' => ' colspan="3"', 'cols' => 3);
1396 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1397 print $hookmanager->resPrint;
1398 if (empty($reshook)) {
1399 print $object->showOptionals($extrafields, 'create', $parameters);
1400 }
1401
1402
1403 // Lines from source
1404 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1405 // TODO for compatibility
1406 if ($origin == 'contrat') {
1407 // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
1408 //$objectsrc->remise_absolue = $remise_absolue;
1409 //$objectsrc->remise_percent = $remise_percent;
1410 $objectsrc->update_price(1, 'auto', 1);
1411 }
1412
1413 print "\n<!-- ".$classname." info -->";
1414 print "\n";
1415 print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
1416 print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
1417 print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
1418 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1419 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1420
1421 print '<tr><td>'.$langs->trans('CommRequest').'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
1422 print '<tr><td>'.$langs->trans('AmountHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
1423 print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
1424 if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1
1425 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
1426 }
1427
1428 if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2
1429 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
1430 }
1431 print '<tr><td>'.$langs->trans('AmountTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
1432
1433 if (isModEnabled("multicurrency")) {
1434 print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
1435 print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_tva)."</td></tr>";
1436 print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ttc)."</td></tr>";
1437 }
1438 }
1439
1440 print "</table>\n";
1441
1442
1443 /*
1444 * Combobox for copy function
1445 */
1446
1447 if (!getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
1448 print '<input type="hidden" name="createmode" value="empty">';
1449 }
1450
1451 if (getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
1452 print '<br><table>';
1453
1454 // For backward compatibility
1455 print '<tr>';
1456 print '<td><input type="radio" name="createmode" value="copy"></td>';
1457 print '<td>'.$langs->trans("CopyAskFrom").' </td>';
1458 print '<td>';
1459 $liste_ask = array();
1460 $liste_ask [0] = '';
1461
1462 $sql = "SELECT p.rowid as id, p.ref, s.nom";
1463 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal p";
1464 $sql .= ", ".MAIN_DB_PREFIX."societe s";
1465 $sql .= " WHERE s.rowid = p.fk_soc";
1466 $sql .= " AND p.entityy IN (".getEntity('supplier_proposal').")";
1467 $sql .= " AND p.fk_statut <> ".SupplierProposal::STATUS_DRAFT;
1468 $sql .= " ORDER BY Id";
1469
1470 $resql = $db->query($sql);
1471 if ($resql) {
1472 $num = $db->num_rows($resql);
1473 $i = 0;
1474 while ($i < $num) {
1475 $row = $db->fetch_row($resql);
1476 $askPriceSupplierRefAndSocName = $row[1]." - ".$row[2];
1477 $liste_ask[$row[0]] = $askPriceSupplierRefAndSocName;
1478 $i++;
1479 }
1480 print $form->selectarray("copie_supplier_proposal", $liste_ask, 0);
1481 } else {
1482 dol_print_error($db);
1483 }
1484 print '</td></tr>';
1485
1486 print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
1487 print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyAsk").'</td></tr>';
1488 }
1489
1490 if (getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
1491 print '</table>';
1492 }
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 (!getDolGlobalString('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 // Call Hook tabContentViewSupplierProposal
1638 $parameters = array();
1639 // Note that $action and $object may be modified by hook
1640 $reshook = $hookmanager->executeHooks('tabContentViewSupplierProposal', $parameters, $object, $action);
1641 if (empty($reshook)) {
1642 print '<div class="fichecenter">';
1643 print '<div class="fichehalfleft">';
1644 print '<div class="underbanner clearboth"></div>';
1645
1646 print '<table class="border tableforfield centpercent">';
1647
1648 // Relative and absolute discounts
1649 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
1650 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
1651 $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
1652 } else {
1653 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
1654 $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
1655 }
1656
1657 print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td>';
1658
1659 $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
1660 $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote, 0, 1);
1661 $absolute_discount = price2num($absolute_discount, 'MT');
1662 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
1663
1664 $thirdparty = $soc;
1665 $discount_type = 1;
1666 $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
1667 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1668
1669 print '</td></tr>';
1670
1671 // Payment term
1672 print '<tr><td class="titlefield">';
1673 print '<table class="nobordernopadding" width="100%"><tr><td>';
1674 print $langs->trans('PaymentConditionsShort');
1675 print '</td>';
1676 if ($action != 'editconditions' && $object->statut != SupplierProposal::STATUS_NOTSIGNED) {
1677 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>';
1678 }
1679 print '</tr></table>';
1680 print '</td><td class="valuefield">';
1681 if ($action == 'editconditions') {
1682 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
1683 } else {
1684 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1);
1685 }
1686 print '</td>';
1687 print '</tr>';
1688
1689 // Delivery date
1690 $langs->load('deliveries');
1691 print '<tr><td>';
1692 print '<table class="nobordernopadding" width="100%"><tr><td>';
1693 print $langs->trans('DeliveryDate');
1694 print '</td>';
1695 if ($action != 'editdate_livraison' && $object->statut != SupplierProposal::STATUS_NOTSIGNED) {
1696 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>';
1697 }
1698 print '</tr></table>';
1699 print '</td><td class="valuefield">';
1700 if ($action == 'editdate_livraison') {
1701 print '<form name="editdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post" class="formconsumeproduce">';
1702 print '<input type="hidden" name="token" value="'.newToken().'">';
1703 print '<input type="hidden" name="action" value="setdate_livraison">';
1704 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1705 print $form->selectDate($object->delivery_date, 'liv_', '', '', '', "editdate_livraison");
1706 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
1707 print '</form>';
1708 } else {
1709 print dol_print_date($object->delivery_date, 'daytext');
1710 }
1711 print '</td>';
1712 print '</tr>';
1713
1714 // Payment mode
1715 print '<tr>';
1716 print '<td>';
1717 print '<table class="nobordernopadding" width="100%"><tr><td>';
1718 print $langs->trans('PaymentMode');
1719 print '</td>';
1720 if ($action != 'editmode' && $object->statut != SupplierProposal::STATUS_NOTSIGNED) {
1721 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>';
1722 }
1723 print '</tr></table>';
1724 print '</td><td class="valuefield">';
1725 if ($action == 'editmode') {
1726 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1);
1727 } else {
1728 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
1729 }
1730 print '</td></tr>';
1731
1732 // Multicurrency
1733 if (isModEnabled("multicurrency")) {
1734 // Multicurrency code
1735 print '<tr>';
1736 print '<td>';
1737 print '<table class="nobordernopadding" width="100%"><tr><td>';
1738 print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
1739 print '</td>';
1740 if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_VALIDATED) {
1741 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>';
1742 }
1743 print '</tr></table>';
1744 print '</td><td class="valuefield">';
1745 if ($action == 'editmulticurrencycode') {
1746 $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
1747 } else {
1748 $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
1749 }
1750 print '</td></tr>';
1751
1752 // Multicurrency rate
1753 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1754 print '<tr>';
1755 print '<td>';
1756 print '<table class="nobordernopadding" width="100%"><tr><td>';
1757 print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
1758 print '</td>';
1759 if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_VALIDATED && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1760 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>';
1761 }
1762 print '</tr></table>';
1763 print '</td><td class="valuefield">';
1764 if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
1765 if ($action == 'actualizemulticurrencyrate') {
1766 list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
1767 }
1768 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
1769 } else {
1770 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
1771 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
1772 print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
1773 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
1774 print '</div>';
1775 }
1776 }
1777 print '</td></tr>';
1778 }
1779 }
1780
1781 /* Not for supplier proposals
1782 if ($soc->outstanding_limit) {
1783 // Outstanding Bill
1784 print '<tr><td>';
1785 print $langs->trans('OutstandingBill');
1786 print '</td><td class="valuefield">';
1787 $arrayoutstandingbills = $soc->getOutstandingBills('supplier');
1788 $outstandingBills = $arrayoutstandingbills['opened'];
1789 print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency);
1790 print '</td>';
1791 print '</tr>';
1792 }*/
1793
1794 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL') && isModEnabled("banque")) {
1795 // Bank Account
1796 print '<tr><td>';
1797 print '<table width="100%" class="nobordernopadding"><tr><td>';
1798 print $langs->trans('BankAccount');
1799 print '</td>';
1800 if ($action != 'editbankaccount' && $usercancreate) {
1801 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>';
1802 }
1803 print '</tr></table>';
1804 print '</td><td class="valuefield">';
1805 if ($action == 'editbankaccount') {
1806 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
1807 } else {
1808 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
1809 }
1810 print '</td>';
1811 print '</tr>';
1812 }
1813
1814 // Other attributes
1815 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1816
1817 print '</table>';
1818
1819 print '</div>';
1820 print '<div class="fichehalfright">';
1821 print '<div class="underbanner clearboth"></div>';
1822
1823 print '<table class="border tableforfield centpercent">';
1824
1825 print '<tr>';
1826 // Amount HT
1827 print '<td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
1828 print '<td class="nowrap amountcard right">' . price($object->total_ht, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
1829 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1830 // Multicurrency Amount HT
1831 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ht, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1832 }
1833 print '</tr>';
1834
1835 print '<tr>';
1836 // Amount VAT
1837 print '<td class="titlefieldmiddle">' . $langs->trans('AmountVAT') . '</td>';
1838 print '<td class="nowrap amountcard right">' . price($object->total_tva, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
1839 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1840 // Multicurrency Amount VAT
1841 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_tva, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1842 }
1843 print '</tr>';
1844
1845 // Amount Local Taxes
1846 if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) {
1847 print '<tr>';
1848 print '<td class="titlefieldmiddle">' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
1849 print '<td class="nowrap amountcard right">' . price($object->total_localtax1, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
1850 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1851 print '<td class="nowrap amountcard right">' . price($object->total_localtax1, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1852 }
1853 print '</tr>';
1854
1855 if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) {
1856 print '<tr>';
1857 print '<td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
1858 print '<td class="nowrap amountcard right">' . price($object->total_localtax2, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
1859 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1860 print '<td class="nowrap amountcard right">' . price($object->total_localtax2, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1861 }
1862 print '</tr>';
1863 }
1864 }
1865
1866 print '<tr>';
1867 // Amount TTC
1868 print '<td>' . $langs->trans('AmountTTC') . '</td>';
1869 print '<td class="nowrap amountcard right">' . price($object->total_ttc, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
1870 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1871 // Multicurrency Amount TTC
1872 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ttc, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1873 }
1874 print '</tr>';
1875
1876 print '</table>';
1877
1878 // Margin Infos
1879 /*if (isModEnabled('margin')) {
1880 $formmargin->displayMarginInfos($object);
1881 }*/
1882
1883 print '</div>';
1884 print '</div>';
1885
1886 print '<div class="clearboth"></div><br>';
1887
1888 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
1889 $blocname = 'contacts';
1890 $title = $langs->trans('ContactsAddresses');
1891 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1892 }
1893
1894 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
1895 $blocname = 'notes';
1896 $title = $langs->trans('Notes');
1897 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1898 }
1899
1900 /*
1901 * Lines
1902 */
1903
1904 // Show object lines
1905 $result = $object->getLinesArray();
1906
1907 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#add' : '').'" method="POST">
1908 <input type="hidden" name="token" value="' . newToken().'">
1909 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
1910 <input type="hidden" name="mode" value="">
1911 <input type="hidden" name="id" value="' . $object->id.'">
1912 <input type="hidden" name="backtopage" value="'.$backtopage.'">
1913 ';
1914
1915 if (!empty($conf->use_javascript_ajax) && $object->statut == SupplierProposal::STATUS_DRAFT) {
1916 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
1917 }
1918
1919 print '<div class="div-table-responsive-no-min">';
1920 print '<table id="tablelines" class="noborder noshadow" width="100%">';
1921
1922 // Add free products/services form
1923 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
1924 $forceall = 1;
1925 $dateSelector = 0;
1926 $inputalsopricewithtax = 1;
1927 $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty.
1928 if (getDolGlobalString('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY')) {
1929 $senderissupplier = 1;
1930 }
1931
1932 if (!empty($object->lines)) {
1933 $object->printObjectLines($action, $soc, $mysoc, $lineid, $dateSelector);
1934 }
1935
1936 // Form to add new line
1937 if ($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) {
1938 if ($action != 'editline') {
1939 // Add products/services form
1940
1941 $parameters = array();
1942 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1943 if ($reshook < 0) {
1944 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1945 }
1946 if (empty($reshook)) {
1947 $object->formAddObjectLine($dateSelector, $soc, $mysoc);
1948 }
1949 }
1950 }
1951
1952 print '</table>';
1953 print '</div>';
1954 print "</form>\n";
1955 }
1956
1957 print dol_get_fiche_end();
1958
1959 if ($action == 'statut') {
1960 // Form to set proposal accepted/refused
1961 $form_close = '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST" id="formacceptrefuse" class="formconsumeproduce paddingbottom paddingleft paddingright">';
1962 $form_close .= '<input type="hidden" name="token" value="'.newToken().'">';
1963 $form_close .= '<input type="hidden" name="action" value="setstatut">';
1964
1965 if (getDolGlobalString('SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL')) {
1966 $form_close .= '<p class="notice">'.$langs->trans('SupplierProposalRefFournNotice').'</p>'; // TODO Suggest a permanent checkbox instead of option
1967 }
1968 $form_close .= '<table class="border centpercent marginleftonly marginrightonly">';
1969 $form_close .= '<tr><td>'.$langs->trans("CloseAs").'</td><td class="left">';
1970 $form_close .= '<select id="statut" name="statut" class="flat">';
1971 $form_close .= '<option value="0">&nbsp;</option>';
1972 $form_close .= '<option value="2">'.$langs->trans('SupplierProposalStatusSigned').'</option>';
1973 $form_close .= '<option value="3">'.$langs->trans('SupplierProposalStatusNotSigned').'</option>';
1974 $form_close .= '</select>';
1975 $form_close .= '</td></tr>';
1976 $form_close .= '<tr><td class="left">'.$langs->trans('Note').'</td><td class="left"><textarea cols="70" rows="'.ROWS_3.'" wrap="soft" name="note">';
1977 $form_close .= $object->note_private;
1978 $form_close .= '</textarea></td></tr>';
1979 $form_close .= '</table>';
1980 $form_close .= $form->buttonsSaveCancel();
1981 $form_close .= '<a id="acceptedrefused">&nbsp;</a>';
1982 $form_close .= '</form>';
1983
1984 print $form_close;
1985 }
1986
1987 /*
1988 * Boutons Actions
1989 */
1990 if ($action != 'presend') {
1991 print '<div class="tabsAction">';
1992
1993 $parameters = array();
1994 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1995 // modified by hook
1996 if (empty($reshook)) {
1997 if ($action != 'statut' && $action != 'editline') {
1998 // Validate
1999 if ($object->statut == SupplierProposal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0 && $usercanvalidate) {
2000 if (count($object->lines) > 0) {
2001 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a></div>';
2002 }
2003 // else print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Validate').'</a>';
2004 }
2005
2006 // Edit
2007 if ($object->statut == SupplierProposal::STATUS_VALIDATED && $usercancreate) {
2008 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>';
2009 }
2010
2011 // ReOpen
2012 if (($object->statut == SupplierProposal::STATUS_SIGNED || $object->statut == SupplierProposal::STATUS_NOTSIGNED || $object->statut == SupplierProposal::STATUS_CLOSE) && $usercanclose) {
2013 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().(!getDolGlobalString('MAIN_JUMP_TAG') ? '' : '#reopen').'"';
2014 print '>'.$langs->trans('ReOpen').'</a></div>';
2015 }
2016
2017 // Send
2018 if (empty($user->socid)) {
2019 if ($object->statut == SupplierProposal::STATUS_VALIDATED || $object->statut == SupplierProposal::STATUS_SIGNED) {
2020 if ($usercansend) {
2021 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>';
2022 } else {
2023 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
2024 }
2025 }
2026 }
2027
2028 // Create an order
2029 if (isModEnabled("supplier_order") && $object->statut == SupplierProposal::STATUS_SIGNED) {
2030 if ($usercancreateorder) {
2031 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>';
2032 }
2033 }
2034
2035 // Set accepted/refused
2036 if ($object->statut == SupplierProposal::STATUS_VALIDATED && $usercanclose) {
2037 print '<div class="inline-block divButAction"><a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;token='.newToken().'&amp;action=statut'.(!getDolGlobalString('MAIN_JUMP_TAG') ? '' : '#acceptedrefused').'"';
2038 print '>'.$langs->trans('SetAcceptedRefused').'</a></div>';
2039 }
2040
2041 // Close
2042 if ($object->statut == SupplierProposal::STATUS_SIGNED && $usercanclose) {
2043 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;token='.newToken().'&amp;action=close'.(!getDolGlobalString('MAIN_JUMP_TAG') ? '' : '#close').'"';
2044 print '>'.$langs->trans('Close').'</a></div>';
2045 }
2046
2047 // Clone
2048 if ($usercancreate) {
2049 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>';
2050 }
2051
2052 // Delete
2053 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', (($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) || $usercandelete));
2054 }
2055 }
2056
2057 print '</div>';
2058 }
2059
2060 if ($action != 'presend') {
2061 print '<div class="fichecenter"><div class="fichehalfleft">';
2062
2063 /*
2064 * Generated documents
2065 */
2066 $filename = dol_sanitizeFileName($object->ref);
2067 $filedir = $conf->supplier_proposal->dir_output."/".dol_sanitizeFileName($object->ref);
2068 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2069 $genallowed = $usercanread;
2070 $delallowed = $usercancreate;
2071
2072 print $formfile->showdocuments('supplier_proposal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang);
2073
2074
2075 // Show links to link elements
2076 $linktoelem = $form->showLinkToObjectBlock($object, null, array('supplier_proposal'));
2077 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2078
2079
2080 print '</div><div class="fichehalfright">';
2081
2082 // List of actions on element
2083 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2084 $formactions = new FormActions($db);
2085 $somethingshown = $formactions->showactions($object, 'supplier_proposal', $socid, 1);
2086
2087 print '</div></div>';
2088 }
2089
2090 // Select mail models is same action as presend
2091 if (GETPOST('modelselected')) {
2092 $action = 'presend';
2093 }
2094
2095 // Presend form
2096 $modelmail = 'supplier_proposal_send';
2097 $defaulttopic = 'SendAskRef';
2098 $diroutput = $conf->supplier_proposal->dir_output;
2099 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
2100 $trackid = 'spro'.$object->id;
2101
2102 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2103}
2104
2105// End of page
2106llxFooter();
2107$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
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 a 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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.