dolibarr 21.0.0-alpha
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
7 * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2011-2023 Philippe Grand <philippe.grand@atoo-net.com>
9 * Copyright (C) 2012-2023 Christophe Battarel <christophe.battarel@altairis.fr>
10 * Copyright (C) 2012-2016 Marcos García <marcosgdf@gmail.com>
11 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
12 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
13 * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
14 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
15 * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
16 * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
17 * Copyright (C) 2023-2024 Benjamin Falière <benjamin.faliere@altairis.fr>
18 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <https://www.gnu.org/licenses/>.
32 */
33
40// Load Dolibarr environment
41require '../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
50
51require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
52require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
53
54if (isModEnabled("propal")) {
55 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
56}
57
58if (isModEnabled('project')) {
59 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
60 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
61}
62
63if (isModEnabled('variants')) {
64 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
65}
66
67
68// Load translation files required by the page
69$langs->loadLangs(array('orders', 'sendings', 'companies', 'bills', 'propal', 'deliveries', 'products', 'other'));
70
71if (isModEnabled('incoterm')) {
72 $langs->load('incoterm');
73}
74if (isModEnabled('margin')) {
75 $langs->load('margins');
76}
77if (isModEnabled('productbatch')) {
78 $langs->load('productbatch');
79}
80
81
82$id = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('orderid'));
83$ref = GETPOST('ref', 'alpha');
84$socid = GETPOSTINT('socid');
85$action = GETPOST('action', 'aZ09');
86$cancel = GETPOST('cancel', 'alpha');
87$confirm = GETPOST('confirm', 'alpha');
88$backtopage = GETPOST('backtopage', 'alpha');
89
90$lineid = GETPOSTINT('lineid');
91$contactid = GETPOSTINT('contactid');
92$projectid = GETPOSTINT('projectid');
93$origin = GETPOST('origin', 'alpha');
94$originid = (GETPOSTINT('originid') ? GETPOSTINT('originid') : GETPOSTINT('origin_id')); // For backward compatibility
95$rank = (GETPOSTINT('rank') > 0) ? GETPOSTINT('rank') : -1;
96
97// PDF
98$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
99$hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
100$hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
101
102// Security check
103if (!empty($user->socid)) {
104 $socid = $user->socid;
105}
106
107// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
108$hookmanager->initHooks(array('ordercard', 'globalcard'));
109
110$result = restrictedArea($user, 'commande', $id);
111
112$object = new Commande($db);
113$extrafields = new ExtraFields($db);
114
115// fetch optionals attributes and labels
116$extrafields->fetch_name_optionals_label($object->table_element);
117
118// Load object
119include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
120
121// Permissions / Rights
122$usercanread = $user->hasRight("commande", "lire");
123$usercancreate = $user->hasRight("commande", "creer");
124$usercandelete = $user->hasRight("commande", "supprimer");
125
126// Advanced permissions
127$usercanclose = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('commande', 'order_advance', 'close')));
128$usercanvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('commande', 'order_advance', 'validate')));
129$usercancancel = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('commande', 'order_advance', 'annuler')));
130$usercansend = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('commande', 'order_advance', 'send'));
131$usercangeneretedoc = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('commande', 'order_advance', 'generetedoc'));
132
133$usermustrespectpricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
134$usercancreatepurchaseorder = ($user->hasRight('fournisseur', 'commande', 'creer') || $user->hasRight('supplier_order', 'creer'));
135
136$permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
137$permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php
138$permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
139
140
141$error = 0;
142
143$date_delivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
144
145
146/*
147 * Actions
148 */
149
150$parameters = array('socid' => $socid);
151// Note that $action and $object may be modified by some hooks
152$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
153if ($reshook < 0) {
154 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
155}
156
157if (empty($reshook)) {
158 $backurlforlist = DOL_URL_ROOT.'/commande/list.php';
159
160 if (empty($backtopage) || ($cancel && empty($id))) {
161 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
162 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
163 $backtopage = $backurlforlist;
164 } else {
165 $backtopage = DOL_URL_ROOT.'/commande/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
166 }
167 }
168 }
169
170 $selectedLines = GETPOST('toselect', 'array');
171
172 if ($cancel) {
173 if (!empty($backtopageforcancel)) {
174 header("Location: ".$backtopageforcancel);
175 exit;
176 } elseif (!empty($backtopage)) {
177 header("Location: ".$backtopage);
178 exit;
179 }
180 $action = '';
181 }
182
183 include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be 'include', not 'include_once'
184
185 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
186
187 include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
188
189 // Action clone object
190 if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
191 if (!($socid > 0)) {
192 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('IdThirdParty')), null, 'errors');
193 } else {
194 if ($object->id > 0) {
195 // Because createFromClone modifies the object, we must clone it so that we can restore it later
196 $orig = clone $object;
197
198 $result = $object->createFromClone($user, $socid);
199 if ($result > 0) {
200 $warningMsgLineList = array();
201 // check all product lines are to sell otherwise add a warning message for each product line is not to sell
202 foreach ($object->lines as $line) {
203 if (!is_object($line->product)) {
204 $line->fetch_product();
205 }
206 if (is_object($line->product) && $line->product->id > 0) {
207 if (empty($line->product->status)) {
208 $warningMsgLineList[$line->id] = $langs->trans('WarningLineProductNotToSell', $line->product->ref);
209 }
210 }
211 }
212 if (!empty($warningMsgLineList)) {
213 setEventMessages('', $warningMsgLineList, 'warnings');
214 }
215
216 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
217 exit;
218 } else {
219 setEventMessages($object->error, $object->errors, 'errors');
220 $object = $orig;
221 $action = '';
222 }
223 }
224 }
225 } elseif ($action == 'reopen' && $usercancreate) {
226 // Reopen a closed order
228 if (getDolGlobalInt('ORDER_REOPEN_TO_DRAFT')) {
229 $result = $object->setDraft($user, $idwarehouse);
230 if ($result < 0) {
231 setEventMessages($object->error, $object->errors, 'errors');
232 }
233 } else {
234 $result = $object->set_reopen($user);
235 if ($result > 0) {
236 setEventMessages($langs->trans('OrderReopened', $object->ref), null);
237 } else {
238 setEventMessages($object->error, $object->errors, 'errors');
239 }
240 }
241 }
242 } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) {
243 // Remove order
244 $result = $object->delete($user);
245 if ($result > 0) {
246 header('Location: list.php?restore_lastsearch_values=1');
247 exit;
248 } else {
249 setEventMessages($object->error, $object->errors, 'errors');
250 }
251 } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
252 // Remove a product line
253 $result = $object->deleteLine($user, $lineid);
254 if ($result > 0) {
255 // reorder lines
256 $object->line_order(true);
257 // Define output language
258 $outputlangs = $langs;
259 $newlang = '';
260 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
261 $newlang = GETPOST('lang_id', 'aZ09');
262 }
263 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
264 $newlang = $object->thirdparty->default_lang;
265 }
266 if (!empty($newlang)) {
267 $outputlangs = new Translate("", $conf);
268 $outputlangs->setDefaultLang($newlang);
269 }
270 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
271 $ret = $object->fetch($object->id); // Reload to get new records
272 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
273 }
274
275 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
276 exit;
277 } else {
278 setEventMessages($object->error, $object->errors, 'errors');
279 }
280 } elseif ($action == 'classin' && $usercancreate) {
281 // Link to a project
282 $object->setProject(GETPOSTINT('projectid'));
283 } elseif ($action == 'add' && $usercancreate) {
284 // Add order
285 $datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
286 $date_delivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
287
288 if ($datecommande == '') {
289 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Date')), null, 'errors');
290 $action = 'create';
291 $error++;
292 }
293
294 if ($socid < 1) {
295 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), null, 'errors');
296 $action = 'create';
297 $error++;
298 }
299
300 if (!$error) {
301 $object->socid = $socid;
302 $object->fetch_thirdparty();
303
304 $db->begin();
305
306 $object->date_commande = $datecommande;
307 $object->note_private = GETPOST('note_private', 'restricthtml');
308 $object->note_public = GETPOST('note_public', 'restricthtml');
309 $object->source = GETPOSTINT('source_id');
310 $object->fk_project = GETPOSTINT('projectid');
311 $object->ref_client = GETPOST('ref_client', 'alpha');
312 $object->model_pdf = GETPOST('model');
313 $object->cond_reglement_id = GETPOSTINT('cond_reglement_id');
314 $object->deposit_percent = GETPOSTFLOAT('cond_reglement_id_deposit_percent');
315 $object->mode_reglement_id = GETPOSTINT('mode_reglement_id');
316 $object->fk_account = GETPOSTINT('fk_account');
317 $object->availability_id = GETPOSTINT('availability_id');
318 $object->demand_reason_id = GETPOSTINT('demand_reason_id');
319 $object->delivery_date = $date_delivery;
320 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
321 $object->warehouse_id = GETPOSTINT('warehouse_id');
322 $object->fk_delivery_address = GETPOSTINT('fk_address');
323 $object->contact_id = GETPOSTINT('contactid');
324 $object->fk_incoterms = GETPOSTINT('incoterm_id');
325 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
326 $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
327 $object->multicurrency_tx = (float) price2num(GETPOST('originmulticurrency_tx'));
328 // Fill array 'array_options' with data from add form
329 if (!$error) {
330 $ret = $extrafields->setOptionalsFromPost(null, $object);
331 if ($ret < 0) {
332 $error++;
333 }
334 }
335
336 // If creation from another object of another module (Example: origin=propal, originid=1)
337 if (!empty($origin) && !empty($originid)) {
338 // Parse element/subelement (ex: project_task)
339 $element = $subelement = $origin;
340 $regs = array();
341 if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
342 $element = $regs [1];
343 $subelement = $regs [2];
344 }
345
346 // For compatibility
347 if ($element == 'order') {
348 $element = $subelement = 'commande';
349 }
350 if ($element == 'propal') {
351 $element = 'comm/propal';
352 $subelement = 'propal';
353 }
354 if ($element == 'contract') {
355 $element = $subelement = 'contrat';
356 }
357
358 $object->origin = $origin;
359 $object->origin_id = $originid;
360
361 // Possibility to add external linked objects with hooks
362 $object->linked_objects [$object->origin] = $object->origin_id;
363 $other_linked_objects = GETPOST('other_linked_objects', 'array');
364 if (!empty($other_linked_objects)) {
365 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
366 }
367
368 if (!$error) {
369 $object_id = $object->create($user);
370
371 if ($object_id > 0) {
372 dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
373
374 $classname = ucfirst($subelement);
375 $srcobject = new $classname($db);
376
377 dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
378 $result = $srcobject->fetch($object->origin_id);
379 if ($result > 0) {
380 $lines = $srcobject->lines;
381 if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
382 $srcobject->fetch_lines();
383 $lines = $srcobject->lines;
384 }
385
386 $fk_parent_line = 0;
387 $num = count($lines);
388
389 for ($i = 0; $i < $num; $i++) {
390 if (!in_array($lines[$i]->id, $selectedLines)) {
391 continue; // Skip unselected lines
392 }
393
394 $label = (!empty($lines[$i]->label) ? $lines[$i]->label : '');
395 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : '');
396 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
397
398 // Dates
399 // TODO mutualiser
400 $date_start = $lines[$i]->date_debut_prevue;
401 if ($lines[$i]->date_debut_reel) {
402 $date_start = $lines[$i]->date_debut_reel;
403 }
404 if ($lines[$i]->date_start) {
405 $date_start = $lines[$i]->date_start;
406 }
407 $date_end = $lines[$i]->date_fin_prevue;
408 if ($lines[$i]->date_fin_reel) {
409 $date_end = $lines[$i]->date_fin_reel;
410 }
411 if ($lines[$i]->date_end) {
412 $date_end = $lines[$i]->date_end;
413 }
414
415 // Reset fk_parent_line for no child products and special product
416 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
417 $fk_parent_line = 0;
418 }
419
420 // Extrafields
421 if (method_exists($lines[$i], 'fetch_optionals')) { // For avoid conflicts if trigger used
422 $lines[$i]->fetch_optionals();
423 $array_options = $lines[$i]->array_options;
424 }
425
426 $tva_tx = $lines[$i]->tva_tx;
427 if (!empty($lines[$i]->vat_src_code) && !preg_match('/\‍(/', $tva_tx)) {
428 $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';
429 }
430
431 $result = $object->addline(
432 $desc,
433 $lines[$i]->subprice,
434 $lines[$i]->qty,
435 $tva_tx,
436 $lines[$i]->localtax1_tx,
437 $lines[$i]->localtax2_tx,
438 $lines[$i]->fk_product,
439 $lines[$i]->remise_percent,
440 $lines[$i]->info_bits,
441 $lines[$i]->fk_remise_except,
442 'HT',
443 0,
444 $date_start,
445 $date_end,
446 $product_type,
447 $lines[$i]->rang,
448 $lines[$i]->special_code,
449 $fk_parent_line,
450 $lines[$i]->fk_fournprice,
451 $lines[$i]->pa_ht,
452 $label,
453 $array_options,
454 $lines[$i]->fk_unit,
455 $object->origin,
456 $lines[$i]->rowid
457 );
458
459 if ($result < 0) {
460 $error++;
461 break;
462 }
463
464 // Defined the new fk_parent_line
465 if ($result > 0 && $lines[$i]->product_type == 9) {
466 $fk_parent_line = $result;
467 }
468 }
469 } else {
470 setEventMessages($srcobject->error, $srcobject->errors, 'errors');
471 $error++;
472 }
473
474 // Now we create same links to contact than the ones found on origin object
475 /* Useless, already into the create
476 if (!empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN))
477 {
478 $originforcontact = $object->origin;
479 $originidforcontact = $object->origin_id;
480 if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order
481 {
482 $originforcontact=$srcobject->origin;
483 $originidforcontact=$srcobject->origin_id;
484 }
485 $sqlcontact = "SELECT code, fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc";
486 $sqlcontact.= " WHERE element_id = ".((int) $originidforcontact)." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$db->escape($originforcontact)."'";
487
488 $resqlcontact = $db->query($sqlcontact);
489 if ($resqlcontact)
490 {
491 while($objcontact = $db->fetch_object($resqlcontact))
492 {
493 //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n";
494 $object->add_contact($objcontact->fk_socpeople, $objcontact->code);
495 }
496 }
497 else dol_print_error($resqlcontact);
498 }*/
499
500 // Hooks
501 $parameters = array('objFrom' => $srcobject);
502 // Note that $action and $object may be modified by hook
503 $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action);
504 if ($reshook < 0) {
505 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
506 $error++;
507 }
508 } else {
509 setEventMessages($object->error, $object->errors, 'errors');
510 $error++;
511 }
512 } else {
513 // Required extrafield left blank, error message already defined by setOptionalsFromPost()
514 $action = 'create';
515 }
516 } else {
517 if (!$error) {
518 $object_id = $object->create($user);
519 }
520 }
521
522 // Insert default contacts if defined
523 if ($object_id > 0) {
524 if (GETPOSTINT('contactid')) {
525 $result = $object->add_contact(GETPOSTINT('contactid'), 'CUSTOMER', 'external');
526 if ($result < 0) {
527 setEventMessages($langs->trans("ErrorFailedToAddContact"), null, 'errors');
528 $error++;
529 }
530 }
531
532 $id = $object_id;
533 $action = '';
534 }
535
536 // End of object creation, we show it
537 if ($object_id > 0 && !$error) {
538 $db->commit();
539 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object_id);
540 exit();
541 } else {
542 $db->rollback();
543 $action = 'create';
544 setEventMessages($object->error, $object->errors, 'errors');
545 }
546 }
547 } elseif ($action == 'classifybilled' && $usercancreate) {
548 $ret = $object->classifyBilled($user);
549
550 if ($ret < 0) {
551 setEventMessages($object->error, $object->errors, 'errors');
552 }
553 } elseif ($action == 'classifyunbilled' && $usercancreate) {
554 $ret = $object->classifyUnBilled($user);
555 if ($ret < 0) {
556 setEventMessages($object->error, $object->errors, 'errors');
557 }
558 } elseif ($action == 'setref_client' && $usercancreate) {
559 // Positionne ref commande client
560 $result = $object->set_ref_client($user, GETPOST('ref_client'));
561 if ($result < 0) {
562 setEventMessages($object->error, $object->errors, 'errors');
563 }
564 } elseif ($action == 'setremise' && $usercancreate) {
565 $result = $object->setDiscount($user, price2num(GETPOST('remise'), 2));
566 if ($result < 0) {
567 setEventMessages($object->error, $object->errors, 'errors');
568 }
569 } elseif ($action == 'setabsolutediscount' && $usercancreate) {
570 if (GETPOST('remise_id')) {
571 if ($object->id > 0) {
572 $object->insert_discount(GETPOST('remise_id'));
573 } else {
574 dol_print_error($db, $object->error);
575 }
576 }
577 } elseif ($action == 'setdate' && $usercancreate) {
578 $date = dol_mktime(0, 0, 0, GETPOSTINT('order_month'), GETPOSTINT('order_day'), GETPOSTINT('order_year'));
579
580 $result = $object->set_date($user, $date);
581 if ($result < 0) {
582 setEventMessages($object->error, $object->errors, 'errors');
583 }
584 } elseif ($action == 'setdate_livraison' && $usercancreate) {
585 $date_delivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
586
587 $object->fetch($id);
588 $result = $object->setDeliveryDate($user, $date_delivery);
589 if ($result < 0) {
590 setEventMessages($object->error, $object->errors, 'errors');
591 }
592 } elseif ($action == 'setmode' && $usercancreate) {
593 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
594 if ($result < 0) {
595 setEventMessages($object->error, $object->errors, 'errors');
596 }
597 } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
598 // Multicurrency Code
599 $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
600 } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
601 // Multicurrency rate
602 $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOSTINT('calculation_mode'));
603 } elseif ($action == 'setavailability' && $usercancreate) {
604 $result = $object->availability(GETPOST('availability_id'));
605 if ($result < 0) {
606 setEventMessages($object->error, $object->errors, 'errors');
607 }
608 } elseif ($action == 'setdemandreason' && $usercancreate) {
609 $result = $object->demand_reason(GETPOST('demand_reason_id'));
610 if ($result < 0) {
611 setEventMessages($object->error, $object->errors, 'errors');
612 }
613 } elseif ($action == 'setconditions' && $usercancreate) {
614 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id'), GETPOSTFLOAT('cond_reglement_id_deposit_percent'));
615 if ($result < 0) {
616 dol_print_error($db, $object->error);
617 } else {
618 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
619 // Define output language
620 $outputlangs = $langs;
621 $newlang = GETPOST('lang_id', 'alpha');
622 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
623 $newlang = $object->thirdparty->default_lang;
624 }
625 if (!empty($newlang)) {
626 $outputlangs = new Translate("", $conf);
627 $outputlangs->setDefaultLang($newlang);
628 }
629
630 $ret = $object->fetch($object->id); // Reload to get new records
631 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
632 }
633 }
634 } elseif ($action == 'set_incoterms' && isModEnabled('incoterm')) {
635 // Set incoterm
636 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOSTFLOAT('location_incoterms'));
637 if ($result < 0) {
638 setEventMessages($object->error, $object->errors, 'errors');
639 }
640 } elseif ($action == 'setbankaccount' && $usercancreate) {
641 // bank account
642 $result = $object->setBankAccount(GETPOSTINT('fk_account'));
643 if ($result < 0) {
644 setEventMessages($object->error, $object->errors, 'errors');
645 }
646 } elseif ($action == 'setshippingmethod' && $usercancreate) {
647 // shipping method
648 $result = $object->setShippingMethod(GETPOSTINT('shipping_method_id'));
649 if ($result < 0) {
650 setEventMessages($object->error, $object->errors, 'errors');
651 }
652 } elseif ($action == 'setwarehouse' && $usercancreate) {
653 // warehouse
654 $result = $object->setWarehouse(GETPOSTINT('warehouse_id'));
655 if ($result < 0) {
656 setEventMessages($object->error, $object->errors, 'errors');
657 }
658 //} elseif ($action == 'setremisepercent' && $usercancreate) {
659 // $result = $object->setDiscount($user, price2num(GETPOST('remise_percent'), '', 2));
660 //} elseif ($action == 'setremiseabsolue' && $usercancreate) {
661 // $result = $object->set_remise_absolue($user, price2num(GETPOST('remise_absolue'), 'MU', 2));
662 } elseif ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && (GETPOST('alldate_start', 'alpha') || GETPOST('alldate_end', 'alpha')) && $usercancreate) {
663 // Define date start and date end for all line
664 $alldate_start = dol_mktime(GETPOST('alldate_starthour'), GETPOST('alldate_startmin'), 0, GETPOST('alldate_startmonth'), GETPOST('alldate_startday'), GETPOST('alldate_startyear'));
665 $alldate_end = dol_mktime(GETPOST('alldate_endhour'), GETPOST('alldate_endmin'), 0, GETPOST('alldate_endmonth'), GETPOST('alldate_endday'), GETPOST('alldate_endyear'));
666 foreach ($object->lines as $line) {
667 if ($line->product_type == 1) { // only service line
668 $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $alldate_start, $alldate_end, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
669 }
670 }
671 } elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('vatforalllines', 'alpha') !== '' && $usercancreate) {
672 // Define vat_rate
673 $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
674 $vat_rate = str_replace('*', '', $vat_rate);
675 $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
676 $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
677 foreach ($object->lines as $line) {
678 $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $line->info_bits, $line->date_start, $line->date_end, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
679 }
680 } elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('remiseforalllines', 'alpha') !== '' && $usercancreate) {
681 // Define remise_percent
682 $remise_percent = (GETPOST('remiseforalllines') ? GETPOST('remiseforalllines') : 0);
683 $remise_percent = str_replace('*', '', $remise_percent);
684 foreach ($object->lines as $line) {
685 $tvatx= $line->tva_tx;
686 if (!empty($line->vat_src_code)) {
687 $tvatx .= ' ('.$line->vat_src_code.')';
688 }
689 $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $remise_percent, $tvatx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
690 }
691 } elseif ($action == 'addline' && !GETPOST('submitforalllines', 'alpha') && $usercancreate) { // Add a new line
692 $langs->load('errors');
693 $error = 0;
694
695 // Set if we used free entry or predefined product
696 $predef = '';
697 $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
698
699 $price_ht = '';
700 $price_ht_devise = '';
701 $price_ttc = '';
702 $price_ttc_devise = '';
703 $pu_ht = '';
704 $pu_ttc = '';
705 $pu_ht_devise = '';
706 $pu_ttc_devise = '';
707
708 if (GETPOST('price_ht') !== '') {
709 $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
710 }
711 if (GETPOST('multicurrency_price_ht') !== '') {
712 $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
713 }
714 if (GETPOST('price_ttc') !== '') {
715 $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
716 }
717 if (GETPOST('multicurrency_price_ttc') !== '') {
718 $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
719 }
720
721 $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
722 if ($prod_entry_mode == 'free') {
723 $idprod = 0;
724 } else {
725 $idprod = GETPOSTINT('idprod');
726
727 if (getDolGlobalString('MAIN_DISABLE_FREE_LINES') && $idprod <= 0) {
728 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors');
729 $error++;
730 }
731 }
732
733 $tva_tx = GETPOST('tva_tx', 'alpha');
734
735 $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
736
737 $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
738 if (empty($remise_percent)) {
739 $remise_percent = 0;
740 }
741
742 // Extrafields
743 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
744 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
745 // Unset extrafield
746 if (is_array($extralabelsline)) {
747 // Get extra fields
748 foreach ($extralabelsline as $key => $value) {
749 unset($_POST["options_".$key]);
750 }
751 }
752
753 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
754 setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
755 $error++;
756 }
757 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
758 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
759 $error++;
760 }
761 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && $price_ht === '' && $price_ht_devise === '' && $price_ttc === '' && $price_ttc_devise === '') { // Unit price can be 0 but not ''. Also price can be negative for order.
762 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
763 $error++;
764 }
765 if ($qty == '') {
766 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
767 $error++;
768 }
769 if ($qty < 0) {
770 setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
771 $error++;
772 }
773 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
774 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
775 $error++;
776 }
777
778 if (!$error && isModEnabled('variants') && $prod_entry_mode != 'free') {
779 if ($combinations = GETPOST('combinations', 'array')) {
780 //Check if there is a product with the given combination
781 $prodcomb = new ProductCombination($db);
782
783 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
784 $idprod = $res->fk_product_child;
785 } else {
786 setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors');
787 $error++;
788 }
789 }
790 }
791
792 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
793 // Clean parameters
794 $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'));
795 $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'));
796 $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
797
798 $price_min = $price_min_ttc = 0;
799 $tva_npr = 0;
800
801 // Ecrase $pu par celui du produit
802 // Ecrase $desc par celui du produit
803 // Ecrase $base_price_type par celui du produit
804 if (!empty($idprod) && $idprod > 0) {
805 $prod = new Product($db);
806 $prod->fetch($idprod);
807
808 $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
809
810 // Update if prices fields are defined
811 /*$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
812 $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
813 if (empty($tva_tx)) {
814 $tva_npr = 0;
815 }*/
816
817 $pu_ht = $prod->price;
818 $pu_ttc = $prod->price_ttc;
819 $price_min = $prod->price_min;
820 $price_min_ttc = $prod->price_min_ttc;
821 $price_base_type = $prod->price_base_type;
822
823 // If price per segment
824 if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
825 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
826 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
827 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
828 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
829 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
830 if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { // using this option is a bug. kept for backward compatibility
831 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
832 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
833 }
834 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
835 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
836 }
837 }
838 } elseif (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
839 // If price per customer
840 require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
841
842 $prodcustprice = new ProductCustomerPrice($db);
843
844 $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
845
846 $result = $prodcustprice->fetchAll('', '', 0, 0, $filter);
847 if ($result >= 0) {
848 if (count($prodcustprice->lines) > 0) {
849 $pu_ht = price($prodcustprice->lines[0]->price);
850 $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
851 $price_min = price($prodcustprice->lines[0]->price_min);
852 $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc);
853 $price_base_type = $prodcustprice->lines[0]->price_base_type;
854 $tva_tx = $prodcustprice->lines[0]->tva_tx;
855 if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\‍(.*\‍)/', $tva_tx)) {
856 $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
857 }
858 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
859 if (empty($tva_tx)) {
860 $tva_npr = 0;
861 }
862 }
863 } else {
864 setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
865 }
866 } elseif (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY')) {
867 // If price per quantity
868 if ($prod->prices_by_qty[0]) { // yes, this product has some prices per quantity
869 // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
870 $pqp = GETPOSTINT('pbq');
871
872 // Search price into product_price_by_qty from $prod->id
873 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
874 if ($priceforthequantityarray['rowid'] != $pqp) {
875 continue;
876 }
877 // We found the price
878 if ($priceforthequantityarray['price_base_type'] == 'HT') {
879 $pu_ht = $priceforthequantityarray['unitprice'];
880 } else {
881 $pu_ttc = $priceforthequantityarray['unitprice'];
882 }
883 // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
884 break;
885 }
886 }
887 } elseif (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
888 // If price per quantity and customer
889 if ($prod->prices_by_qty[$object->thirdparty->price_level]) { // yes, this product has some prices per quantity
890 // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
891 $pqp = GETPOSTINT('pbq');
892 // Search price into product_price_by_qty from $prod->id
893 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
894 if ($priceforthequantityarray['rowid'] != $pqp) {
895 continue;
896 }
897 // We found the price
898 if ($priceforthequantityarray['price_base_type'] == 'HT') {
899 $pu_ht = $priceforthequantityarray['unitprice'];
900 } else {
901 $pu_ttc = $priceforthequantityarray['unitprice'];
902 }
903 // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
904 break;
905 }
906 }
907 }
908
909 $tmpvat = (float) price2num(preg_replace('/\s*\‍(.*\‍)/', '', $tva_tx));
910 $tmpprodvat = (float) price2num(preg_replace('/\s*\‍(.*\‍)/', '', (string) $prod->tva_tx));
911
912 // Set unit price to use
913 if (!empty($price_ht) || $price_ht === '0') {
914 $pu_ht = price2num($price_ht, 'MU');
915 $pu_ttc = price2num((float) $pu_ht * (1 + ($tmpvat / 100)), 'MU');
916 } elseif (!empty($price_ttc) || $price_ttc === '0') {
917 $pu_ttc = price2num($price_ttc, 'MU');
918 $pu_ht = price2num((float) $pu_ttc / (1 + ($tmpvat / 100)), 'MU');
919 } elseif ($tmpvat != $tmpprodvat) {
920 // Is this still used ?
921 if ($price_base_type != 'HT') {
922 $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
923 } else {
924 $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
925 }
926 }
927
928 $desc = '';
929
930 // Define output language
931 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
932 $outputlangs = $langs;
933 $newlang = '';
934 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
935 $newlang = GETPOST('lang_id', 'aZ09');
936 }
937 if (empty($newlang)) {
938 $newlang = $object->thirdparty->default_lang;
939 }
940 if (!empty($newlang)) {
941 $outputlangs = new Translate("", $conf);
942 $outputlangs->setDefaultLang($newlang);
943 }
944
945 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
946 } else {
947 $desc = $prod->description;
948 }
949
950 //If text set in desc is the same as product descpription (as now it's preloaded) we add it only one time
951 if ($product_desc == $desc && getDolGlobalString('PRODUIT_AUTOFILL_DESC')) {
952 $product_desc = '';
953 }
954
955 if (!empty($product_desc) && getDolGlobalString('MAIN_NO_CONCAT_DESCRIPTION')) {
956 $desc = $product_desc;
957 } else {
958 $desc = dol_concatdesc($desc, $product_desc, '', getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION'));
959 }
960
961 // Add custom code and origin country into description
962 if (!getDolGlobalString('MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
963 $tmptxt = '(';
964 // Define output language
965 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
966 $outputlangs = $langs;
967 $newlang = '';
968 if (empty($newlang) && GETPOST('lang_id', 'alpha')) {
969 $newlang = GETPOST('lang_id', 'alpha');
970 }
971 if (empty($newlang)) {
972 $newlang = $object->thirdparty->default_lang;
973 }
974 if (!empty($newlang)) {
975 $outputlangs = new Translate("", $conf);
976 $outputlangs->setDefaultLang($newlang);
977 $outputlangs->load('products');
978 }
979 if (!empty($prod->customcode)) {
980 $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
981 }
982 if (!empty($prod->customcode) && !empty($prod->country_code)) {
983 $tmptxt .= ' - ';
984 }
985 if (!empty($prod->country_code)) {
986 $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, 0, $db, $outputlangs, 0);
987 }
988 } else {
989 if (!empty($prod->customcode)) {
990 $tmptxt .= $langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
991 }
992 if (!empty($prod->customcode) && !empty($prod->country_code)) {
993 $tmptxt .= ' - ';
994 }
995 if (!empty($prod->country_code)) {
996 $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, 0, $db, $langs, 0);
997 }
998 }
999 $tmptxt .= ')';
1000 $desc = dol_concatdesc($desc, $tmptxt);
1001 }
1002
1003 $type = $prod->type;
1004 $fk_unit = $prod->fk_unit;
1005 } else {
1006 $pu_ht = price2num($price_ht, 'MU');
1007 $pu_ttc = price2num($price_ttc, 'MU');
1008 $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
1009 $tva_tx = str_replace('*', '', $tva_tx);
1010 if (empty($tva_tx)) {
1011 $tva_npr = 0;
1012 }
1013 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1014 $desc = $product_desc;
1015 $type = GETPOST('type');
1016 $fk_unit = GETPOST('units', 'alpha');
1017 $pu_ht_devise = price2num($price_ht_devise, 'MU');
1018 $pu_ttc_devise = price2num($price_ttc_devise, 'MU');
1019
1020 if ($pu_ttc && !$pu_ht) {
1021 $price_base_type = 'TTC';
1022 }
1023 }
1024
1025 $info_bits = 0;
1026 if ($tva_npr) {
1027 $info_bits |= 0x01;
1028 }
1029
1030 // Local Taxes
1031 $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty);
1032 $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty);
1033
1034 // Margin
1035 $fournprice = price2num(GETPOST('fournprice'.$predef) ? GETPOST('fournprice'.$predef) : '');
1036 $buyingprice = price2num(GETPOST('buying_price'.$predef) != '' ? GETPOST('buying_price'.$predef) : ''); // If buying_price is '0', we must keep this value
1037
1038 // Prepare a price equivalent for minimum price check
1039 $pu_equivalent = $pu_ht;
1040 $pu_equivalent_ttc = $pu_ttc;
1041
1042 $currency_tx = $object->multicurrency_tx;
1043
1044 // Check if we have a foreign currency
1045 // If so, we update the pu_equiv as the equivalent price in base currency
1046 if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
1047 $pu_equivalent = (float) $pu_ht_devise * (float) $currency_tx;
1048 }
1049 if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') {
1050 $pu_equivalent_ttc = (float) $pu_ttc_devise * (float) $currency_tx;
1051 }
1052
1053 // TODO $pu_equivalent or $pu_equivalent_ttc must be calculated from the one defined
1054 /*
1055 if ($pu_equivalent) {
1056 $tmp = calcul_price_total(1, $pu_equivalent, 0, $tva_tx, -1, -1, 0, 'HT', $info_bits, $type);
1057 $pu_equivalent_ttc = ...
1058 } else {
1059 $tmp = calcul_price_total(1, $pu_equivalent_ttc, 0, $tva_tx, -1, -1, 0, 'TTC', $info_bits, $type);
1060 $pu_equivalent_ht = ...
1061 }
1062 */
1063
1064 $desc = dol_htmlcleanlastbr($desc);
1065
1066 // Check price is not lower than minimum
1067 if ($usermustrespectpricemin) {
1068 if ($pu_equivalent && $price_min && (((float) price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (float) price2num($price_min)) && $price_base_type == 'HT') {
1069 $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1070 setEventMessages($mesg, null, 'errors');
1071 $error++;
1072 } elseif ($pu_equivalent_ttc && $price_min_ttc && (((float) price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < (float) price2num($price_min_ttc)) && $price_base_type == 'TTC') {
1073 $mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1074 setEventMessages($mesg, null, 'errors');
1075 $error++;
1076 }
1077 }
1078
1079 if (!$error) {
1080 // Insert line
1081 $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, min($rank, count($object->lines) + 1), 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $fk_unit, '', 0, $pu_ht_devise);
1082
1083 if ($result > 0) {
1084 $ret = $object->fetch($object->id); // Reload to get new records
1085 $object->fetch_thirdparty();
1086
1087 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1088 // Define output language
1089 $outputlangs = $langs;
1090 $newlang = GETPOST('lang_id', 'alpha');
1091 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1092 $newlang = $object->thirdparty->default_lang;
1093 }
1094 if (!empty($newlang)) {
1095 $outputlangs = new Translate("", $conf);
1096 $outputlangs->setDefaultLang($newlang);
1097 }
1098
1099 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1100 }
1101
1102 unset($_POST['prod_entry_mode']);
1103
1104 unset($_POST['qty']);
1105 unset($_POST['type']);
1106 unset($_POST['remise_percent']);
1107 unset($_POST['price_ht']);
1108 unset($_POST['multicurrency_price_ht']);
1109 unset($_POST['price_ttc']);
1110 unset($_POST['tva_tx']);
1111 unset($_POST['product_ref']);
1112 unset($_POST['product_label']);
1113 unset($_POST['product_desc']);
1114 unset($_POST['fournprice']);
1115 unset($_POST['buying_price']);
1116 unset($_POST['np_marginRate']);
1117 unset($_POST['np_markRate']);
1118 unset($_POST['dp_desc']);
1119 unset($_POST['idprod']);
1120 unset($_POST['units']);
1121
1122 unset($_POST['date_starthour']);
1123 unset($_POST['date_startmin']);
1124 unset($_POST['date_startsec']);
1125 unset($_POST['date_startday']);
1126 unset($_POST['date_startmonth']);
1127 unset($_POST['date_startyear']);
1128 unset($_POST['date_endhour']);
1129 unset($_POST['date_endmin']);
1130 unset($_POST['date_endsec']);
1131 unset($_POST['date_endday']);
1132 unset($_POST['date_endmonth']);
1133 unset($_POST['date_endyear']);
1134 } else {
1135 setEventMessages($object->error, $object->errors, 'errors');
1136 }
1137 }
1138 }
1139 } elseif ($action == 'updateline' && $usercancreate && GETPOST('save')) {
1140 // Update a line
1141 // Clean parameters
1142 $date_start = '';
1143 $date_end = '';
1144 $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
1145 $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
1146
1147 $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
1148
1149 // Define info_bits
1150 $info_bits = 0;
1151 if (preg_match('/\*/', GETPOST('tva_tx'))) {
1152 $info_bits |= 0x01;
1153 }
1154
1155 // Define vat_rate
1156 $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0);
1157 $vat_rate = str_replace('*', '', $vat_rate);
1158 $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1159 $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1160 $pu_ht = price2num(GETPOST('price_ht'), '', 2);
1161 $pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
1162
1163 $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
1164 $pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
1165
1166 $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
1167
1168 // Prepare a price equivalent for minimum price check
1169 $pu_equivalent = $pu_ht;
1170 $pu_equivalent_ttc = $pu_ttc;
1171
1172 $currency_tx = $object->multicurrency_tx;
1173
1174 // Check if we have a foreign currency
1175 // If so, we update the pu_equiv as the equivalent price in base currency
1176 if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
1177 $pu_equivalent = (float) $pu_ht_devise * (float) $currency_tx;
1178 }
1179 if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') {
1180 $pu_equivalent_ttc = (float) $pu_ttc_devise * (float) $currency_tx;
1181 }
1182
1183 // TODO $pu_equivalent or $pu_equivalent_ttc must be calculated from the one not null taking into account all taxes
1184 /*
1185 if ($pu_equivalent) {
1186 $tmp = calcul_price_total(1, $pu_equivalent, 0, $vat_rate, -1, -1, 0, 'HT', $info_bits, $type);
1187 $pu_equivalent_ttc = ...
1188 } else {
1189 $tmp = calcul_price_total(1, $pu_equivalent_ttc, 0, $vat_rate, -1, -1, 0, 'TTC', $info_bits, $type);
1190 $pu_equivalent_ht = ...
1191 }
1192 */
1193
1194 // Add buying price
1195 $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
1196 $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we must keep this value
1197
1198 // Extrafields Lines
1199 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1200 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1201 // Unset extrafield POST Data
1202 if (is_array($extralabelsline)) {
1203 foreach ($extralabelsline as $key => $value) {
1204 unset($_POST["options_".$key]);
1205 }
1206 }
1207
1208 // Define special_code for special lines
1209 $special_code = GETPOST('special_code');
1210 if (!GETPOST('qty')) {
1211 $special_code = 3;
1212 }
1213
1214 $remise_percent = GETPOST('remise_percent') != '' ? price2num(GETPOST('remise_percent'), '', 2) : 0;
1215
1216 // Check minimum price
1217 $productid = GETPOSTINT('productid');
1218 if (!empty($productid)) {
1219 $product = new Product($db);
1220 $product->fetch($productid);
1221
1222 $type = $product->type;
1223
1224 $price_min = $product->price_min;
1225 if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
1226 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1227 }
1228 $price_min_ttc = $product->price_min_ttc;
1229 if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
1230 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1231 }
1232
1233 $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
1234
1235 // Check price is not lower than minimum
1236 if ($usermustrespectpricemin) {
1237 if ($pu_equivalent && $price_min && (((float) price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (float) price2num($price_min)) && $price_base_type == 'HT') {
1238 $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1239 setEventMessages($mesg, null, 'errors');
1240 $error++;
1241 $action = 'editline';
1242 } elseif ($pu_equivalent_ttc && $price_min_ttc && (((float) price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < (float) price2num($price_min_ttc)) && $price_base_type == 'TTC') {
1243 $mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1244 setEventMessages($mesg, null, 'errors');
1245 $error++;
1246 $action = 'editline';
1247 }
1248 }
1249 } else {
1250 $type = GETPOST('type');
1251 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1252
1253 // Check parameters
1254 if (GETPOST('type') < 0) {
1255 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1256 $error++;
1257 $action = 'editline';
1258 }
1259 }
1260
1261 if ($qty < 0) {
1262 setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
1263 $error++;
1264 $action = 'editline';
1265 }
1266
1267 if (!$error) {
1268 if (!$user->hasRight('margins', 'creer')) {
1269 foreach ($object->lines as &$line) {
1270 if ($line->id == GETPOSTINT('lineid')) {
1271 $fournprice = $line->fk_fournprice;
1272 $buyingprice = $line->pa_ht;
1273 break;
1274 }
1275 }
1276 }
1277
1278 $price_base_type = 'HT';
1279 $pu = $pu_ht;
1280 if (empty($pu) && !empty($pu_ttc)) {
1281 $pu = $pu_ttc;
1282 $price_base_type = 'TTC';
1283 }
1284
1285 $result = $object->updateline(GETPOSTINT('lineid'), $description, $pu, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $price_base_type, $info_bits, $date_start, $date_end, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, GETPOST('units'), $pu_ht_devise);
1286
1287 if ($result >= 0) {
1288 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1289 // Define output language
1290 $outputlangs = $langs;
1291 $newlang = '';
1292 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1293 $newlang = GETPOST('lang_id', 'aZ09');
1294 }
1295 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1296 $newlang = $object->thirdparty->default_lang;
1297 }
1298 if (!empty($newlang)) {
1299 $outputlangs = new Translate("", $conf);
1300 $outputlangs->setDefaultLang($newlang);
1301 }
1302
1303 $ret = $object->fetch($object->id); // Reload to get new records
1304 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1305 }
1306
1307 unset($_POST['qty']);
1308 unset($_POST['type']);
1309 unset($_POST['productid']);
1310 unset($_POST['remise_percent']);
1311 unset($_POST['price_ht']);
1312 unset($_POST['multicurrency_price_ht']);
1313 unset($_POST['price_ttc']);
1314 unset($_POST['tva_tx']);
1315 unset($_POST['product_ref']);
1316 unset($_POST['product_label']);
1317 unset($_POST['product_desc']);
1318 unset($_POST['fournprice']);
1319 unset($_POST['buying_price']);
1320
1321 unset($_POST['date_starthour']);
1322 unset($_POST['date_startmin']);
1323 unset($_POST['date_startsec']);
1324 unset($_POST['date_startday']);
1325 unset($_POST['date_startmonth']);
1326 unset($_POST['date_startyear']);
1327 unset($_POST['date_endhour']);
1328 unset($_POST['date_endmin']);
1329 unset($_POST['date_endsec']);
1330 unset($_POST['date_endday']);
1331 unset($_POST['date_endmonth']);
1332 unset($_POST['date_endyear']);
1333 } else {
1334 setEventMessages($object->error, $object->errors, 'errors');
1335 }
1336 }
1337 } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha')) {
1338 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To re-display card in edit mode
1339 exit();
1340 } elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) {
1341 $idwarehouse = GETPOSTINT('idwarehouse');
1342
1343 $qualified_for_stock_change = 0;
1344 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1345 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1346 } else {
1347 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1348 }
1349
1350 // Check parameters
1351 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1352 if (!$idwarehouse || $idwarehouse == -1) {
1353 $error++;
1354 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
1355 $action = '';
1356 }
1357 }
1358
1359 if (!$error) {
1360 $locationTarget = '';
1361
1362 $db->begin();
1363
1364 $result = $object->valid($user, $idwarehouse);
1365 if ($result >= 0) {
1366 $error = 0;
1367 $deposit = null;
1368
1369 $deposit_percent_from_payment_terms = (float) getDictionaryValue('c_payment_term', 'deposit_percent', $object->cond_reglement_id);
1370
1371 if (
1372 GETPOST('generate_deposit', 'alpha') == 'on' && !empty($deposit_percent_from_payment_terms)
1373 && isModEnabled('invoice') && $user->hasRight('facture', 'creer')
1374 ) {
1375 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
1376
1377 $date = dol_mktime(0, 0, 0, GETPOSTINT('datefmonth'), GETPOSTINT('datefday'), GETPOSTINT('datefyear'));
1378 $forceFields = array();
1379
1380 if (GETPOSTISSET('date_pointoftax')) {
1381 $forceFields['date_pointoftax'] = dol_mktime(0, 0, 0, GETPOSTINT('date_pointoftaxmonth'), GETPOSTINT('date_pointoftaxday'), GETPOSTINT('date_pointoftaxyear'));
1382 }
1383
1384 $deposit = Facture::createDepositFromOrigin($object, $date, GETPOSTINT('cond_reglement_id'), $user, 0, GETPOSTINT('validate_generated_deposit') == 'on', $forceFields);
1385
1386 if ($deposit) {
1387 setEventMessage('DepositGenerated');
1388 $locationTarget = DOL_URL_ROOT . '/compta/facture/card.php?id=' . $deposit->id;
1389 } else {
1390 $error++;
1391 setEventMessages($object->error, $object->errors, 'errors');
1392 }
1393 }
1394
1395 // Define output language
1396 if (! $error) {
1397 $db->commit();
1398
1399 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1400 $outputlangs = $langs;
1401 $newlang = '';
1402 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1403 $newlang = GETPOST('lang_id', 'aZ09');
1404 }
1405 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1406 $newlang = $object->thirdparty->default_lang;
1407 }
1408 if (!empty($newlang)) {
1409 $outputlangs = new Translate("", $conf);
1410 $outputlangs->setDefaultLang($newlang);
1411 }
1412 $model = $object->model_pdf;
1413 $ret = $object->fetch($id); // Reload to get new records
1414
1415 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1416
1417 if ($deposit) {
1418 $deposit->fetch($deposit->id); // Reload to get new records
1419 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1420 }
1421 }
1422
1423 if ($locationTarget) {
1424 header('Location: ' . $locationTarget);
1425 exit;
1426 }
1427 } else {
1428 $db->rollback();
1429 }
1430 } else {
1431 $db->rollback();
1432 setEventMessages($object->error, $object->errors, 'errors');
1433 }
1434 }
1435 } elseif ($action == 'confirm_modif' && $usercancreate) {
1436 // Go back to draft status
1437 $idwarehouse = GETPOST('idwarehouse');
1438
1439 $qualified_for_stock_change = 0;
1440 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1441 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1442 } else {
1443 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1444 }
1445
1446 // Check parameters
1447 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1448 if (!$idwarehouse || $idwarehouse == -1) {
1449 $error++;
1450 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
1451 $action = '';
1452 }
1453 }
1454
1455 if (!$error) {
1456 $result = $object->setDraft($user, $idwarehouse);
1457 if ($result >= 0) {
1458 // Define output language
1459 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1460 $outputlangs = $langs;
1461 $newlang = '';
1462 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1463 $newlang = GETPOST('lang_id', 'aZ09');
1464 }
1465 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1466 $newlang = $object->thirdparty->default_lang;
1467 }
1468 if (!empty($newlang)) {
1469 $outputlangs = new Translate("", $conf);
1470 $outputlangs->setDefaultLang($newlang);
1471 }
1472 $model = $object->model_pdf;
1473 $ret = $object->fetch($id); // Reload to get new records
1474
1475 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1476 }
1477 } else {
1478 setEventMessages($object->error, $object->errors, 'errors');
1479 }
1480 }
1481 } elseif ($action == 'confirm_shipped' && $confirm == 'yes' && $usercanclose) {
1482 $result = $object->cloture($user);
1483 if ($result < 0) {
1484 setEventMessages($object->error, $object->errors, 'errors');
1485 }
1486 } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $usercanvalidate) {
1487 $idwarehouse = GETPOSTINT('idwarehouse');
1488
1489 $qualified_for_stock_change = 0;
1490 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1491 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1492 } else {
1493 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1494 }
1495
1496 // Check parameters
1497 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1498 if (!$idwarehouse || $idwarehouse == -1) {
1499 $error++;
1500 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
1501 $action = '';
1502 }
1503 }
1504
1505 if (!$error) {
1506 $result = $object->cancel($idwarehouse);
1507
1508 if ($result < 0) {
1509 setEventMessages($object->error, $object->errors, 'errors');
1510 }
1511 }
1512 }
1513
1514 if ($action == 'update_extras') {
1515 $object->oldcopy = dol_clone($object, 2);
1516 $attribute_name = GETPOST('attribute', 'restricthtml');
1517
1518 // Fill array 'array_options' with data from update form
1519 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
1520 if ($ret < 0) {
1521 $error++;
1522 }
1523
1524 if (!$error) {
1525 // Actions on extra fields
1526 $result = $object->updateExtraField($attribute_name, 'ORDER_MODIFY');
1527 if ($result < 0) {
1528 setEventMessages($object->error, $object->errors, 'errors');
1529 $error++;
1530 }
1531 }
1532
1533 if ($error) {
1534 $action = 'edit_extras';
1535 }
1536 }
1537
1538 // add lines from objectlinked
1539 if ($action == 'import_lines_from_object'
1540 && $usercancreate
1541 && $object->statut == Commande::STATUS_DRAFT
1542 ) {
1543 $fromElement = GETPOST('fromelement');
1544 $fromElementid = GETPOST('fromelementid');
1545 $importLines = GETPOST('line_checkbox');
1546
1547 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1548 if ($fromElement == 'commande') {
1549 dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php');
1550 $lineClassName = 'OrderLine';
1551 } elseif ($fromElement == 'propal') {
1552 dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php');
1553 $lineClassName = 'PropaleLigne';
1554 } elseif ($fromElement == 'facture') {
1555 dol_include_once('/compta/'.$fromElement.'/class/'.$fromElement.'.class.php');
1556 $lineClassName = 'FactureLigne';
1557 }
1558 $nextRang = count($object->lines) + 1;
1559 $importCount = 0;
1560 $error = 0;
1561 foreach ($importLines as $lineId) {
1562 $lineId = intval($lineId);
1563 $originLine = new $lineClassName($db);
1564 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1565 $originLine->fetch_optionals();
1566 $desc = $originLine->desc;
1567 $pu_ht = $originLine->subprice;
1568 $qty = $originLine->qty;
1569 $txtva = $originLine->tva_tx;
1570 $txlocaltax1 = $originLine->localtax1_tx;
1571 $txlocaltax2 = $originLine->localtax2_tx;
1572 $fk_product = $originLine->fk_product;
1573 $remise_percent = $originLine->remise_percent;
1574 $date_start = $originLine->date_start;
1575 $date_end = $originLine->date_end;
1576 $fk_code_ventilation = 0;
1577 $info_bits = $originLine->info_bits;
1578 $fk_remise_except = $originLine->fk_remise_except;
1579 $price_base_type = 'HT';
1580 $pu_ttc = 0;
1581 $type = $originLine->product_type;
1582 $rang = $nextRang++;
1583 $special_code = $originLine->special_code;
1584 $origin = $originLine->element;
1585 $origin_id = $originLine->id;
1586 $fk_parent_line = 0;
1587 $fk_fournprice = $originLine->fk_fournprice;
1588 $pa_ht = $originLine->pa_ht;
1589 $label = $originLine->label;
1590 $array_options = $originLine->array_options;
1591 $situation_percent = 100;
1592 $fk_prev_id = '';
1593 $fk_unit = $originLine->fk_unit;
1594 $pu_ht_devise = $originLine->multicurrency_subprice;
1595
1596 $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc, $date_start, $date_end, $type, $rang, $special_code, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $array_options, $fk_unit, $origin, $origin_id, $pu_ht_devise);
1597
1598 if ($res > 0) {
1599 $importCount++;
1600 } else {
1601 $error++;
1602 }
1603 } else {
1604 $error++;
1605 }
1606 }
1607
1608 if ($error) {
1609 setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors');
1610 }
1611 }
1612 }
1613
1614 // Actions when printing a doc from card
1615 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
1616
1617 // Actions to build doc
1618 $upload_dir = !empty($conf->commande->multidir_output[$object->entity]) ? $conf->commande->multidir_output[$object->entity] : $conf->commande->dir_output;
1619 $permissiontoadd = $usercancreate;
1620 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1621
1622 // Actions to send emails
1623 $triggersendname = 'ORDER_SENTBYMAIL';
1624 $paramname = 'id';
1625 $autocopy = 'MAIN_MAIL_AUTOCOPY_ORDER_TO'; // used to know the automatic BCC to add
1626 $trackid = 'ord'.$object->id;
1627 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1628
1629
1630 if (!$error && getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $usercancreate) {
1631 if ($action == 'addcontact') {
1632 if ($object->id > 0) {
1633 $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
1634 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
1635 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
1636 }
1637
1638 if ($result >= 0) {
1639 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1640 exit();
1641 } else {
1642 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1643 $langs->load("errors");
1644 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
1645 } else {
1646 setEventMessages($object->error, $object->errors, 'errors');
1647 }
1648 }
1649 } elseif ($action == 'swapstatut') {
1650 // bascule du statut d'un contact
1651 if ($object->id > 0) {
1652 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
1653 } else {
1654 dol_print_error($db);
1655 }
1656 } elseif ($action == 'deletecontact') {
1657 // Efface un contact
1658 $result = $object->delete_contact($lineid);
1659
1660 if ($result >= 0) {
1661 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1662 exit();
1663 } else {
1664 dol_print_error($db);
1665 }
1666 }
1667 }
1668}
1669
1670
1671/*
1672 * View
1673 */
1674
1675$title = $object->ref." - ".$langs->trans('Card');
1676if ($action == 'create') {
1677 $title = $langs->trans("NewOrder");
1678}
1679$help_url = 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1680
1681llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-order page-card');
1682
1683$form = new Form($db);
1684$formfile = new FormFile($db);
1685$formorder = new FormOrder($db);
1686$formmargin = new FormMargin($db);
1687if (isModEnabled('project')) {
1688 $formproject = new FormProjets($db);
1689}
1690
1691// Mode creation
1692if ($action == 'create' && $usercancreate) {
1693 print load_fiche_titre($langs->trans('CreateOrder'), '', 'order');
1694
1695 $soc = new Societe($db);
1696 if ($socid > 0) {
1697 $res = $soc->fetch($socid);
1698 }
1699
1700 //$remise_absolue = 0;
1701
1702 $currency_code = $conf->currency;
1703
1704 $cond_reglement_id = GETPOSTINT('cond_reglement_id');
1705 $deposit_percent = GETPOSTFLOAT('cond_reglement_id_deposit_percent');
1706 $mode_reglement_id = GETPOSTINT('mode_reglement_id');
1707 $fk_account = GETPOSTINT('fk_account');
1708
1709 if (!empty($origin) && !empty($originid)) {
1710 // Parse element/subelement (ex: project_task)
1711 $element = $subelement = $origin;
1712 $regs = array();
1713 if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1714 $element = $regs[1];
1715 $subelement = $regs[2];
1716 }
1717
1718 if ($element == 'project') {
1719 $projectid = $originid;
1720
1721 if (!$cond_reglement_id) {
1722 $cond_reglement_id = $soc->cond_reglement_id;
1723 }
1724 if (!$deposit_percent) {
1725 $deposit_percent = $soc->deposit_percent;
1726 }
1727 if (!$mode_reglement_id) {
1728 $mode_reglement_id = $soc->mode_reglement_id;
1729 }
1730 if (!$remise_percent) {
1731 $remise_percent = $soc->remise_percent;
1732 }
1733 /*if (!$dateorder) {
1734 // Do not set 0 here (0 for a date is 1970)
1735 $dateorder = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 : '') : $dateorder);
1736 }*/
1737 } else {
1738 // For compatibility
1739 if ($element == 'order' || $element == 'commande') {
1740 $element = $subelement = 'commande';
1741 } elseif ($element == 'propal') {
1742 $element = 'comm/propal';
1743 $subelement = 'propal';
1744 } elseif ($element == 'contract') {
1745 $element = $subelement = 'contrat';
1746 }
1747
1748 dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1749
1750 $classname = ucfirst($subelement);
1751 $objectsrc = new $classname($db);
1752 $objectsrc->fetch($originid);
1753 if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1754 $objectsrc->fetch_lines();
1755 }
1756 $objectsrc->fetch_thirdparty();
1757
1758 // Replicate extrafields
1759 $objectsrc->fetch_optionals();
1760 $object->array_options = $objectsrc->array_options;
1761
1762 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
1763 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
1764
1765 $soc = $objectsrc->thirdparty;
1766 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1767 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : null));
1768 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1769 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1770 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1771 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1772 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1773 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1774 //$remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1775 //$remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1776 $dateorder = !getDolGlobalString('MAIN_AUTOFILL_DATE_ORDER') ? -1 : '';
1777
1778 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date : '');
1779
1780 if (isModEnabled("multicurrency")) {
1781 if (!empty($objectsrc->multicurrency_code)) {
1782 $currency_code = $objectsrc->multicurrency_code;
1783 }
1784 if (getDolGlobalString('MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1785 $currency_tx = $objectsrc->multicurrency_tx;
1786 }
1787 }
1788
1789 $note_private = $object->getDefaultCreateValueFor('note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1790 $note_public = $object->getDefaultCreateValueFor('note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1791
1792 // Object source contacts list
1793 $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
1794 }
1795 } else {
1796 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
1797 $deposit_percent = empty($soc->deposit_percent) ? $deposit_percent : $soc->deposit_percent;
1798 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
1799 $fk_account = empty($soc->mode_reglement_id) ? $fk_account : $soc->fk_account;
1800 $availability_id = 0;
1801 $shipping_method_id = $soc->shipping_method_id;
1802 $warehouse_id = $soc->fk_warehouse;
1803 $demand_reason_id = $soc->demand_reason_id;
1804 //$remise_percent = $soc->remise_percent;
1805 //$remise_absolue = 0;
1806 $dateorder = !getDolGlobalString('MAIN_AUTOFILL_DATE_ORDER') ? -1 : '';
1807
1808 if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) {
1809 $currency_code = $soc->multicurrency_code;
1810 }
1811
1812 $note_private = $object->getDefaultCreateValueFor('note_private');
1813 $note_public = $object->getDefaultCreateValueFor('note_public');
1814 }
1815
1816 // If form was posted (but error returned), we must reuse the value posted in priority (standard Dolibarr behaviour)
1817 if (!GETPOST('changecompany')) {
1818 if (GETPOSTISSET('cond_reglement_id')) {
1819 $cond_reglement_id = GETPOSTINT('cond_reglement_id');
1820 }
1821 if (GETPOSTISSET('deposit_percent')) {
1822 $deposit_percent = GETPOSTFLOAT('deposit_percent');
1823 }
1824 if (GETPOSTISSET('mode_reglement_id')) {
1825 $mode_reglement_id = GETPOSTINT('mode_reglement_id');
1826 }
1827 if (GETPOSTISSET('cond_reglement_id')) {
1828 $fk_account = GETPOSTINT('fk_account');
1829 }
1830 }
1831
1832 // Warehouse default if null
1833 if ($soc->fk_warehouse > 0) {
1834 $warehouse_id = $soc->fk_warehouse;
1835 }
1836 if (isModEnabled('stock') && empty($warehouse_id) && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1837 if (empty($object->warehouse_id) && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE')) {
1838 $warehouse_id = getDolGlobalString('MAIN_DEFAULT_WAREHOUSE');
1839 }
1840 if (empty($object->warehouse_id) && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE_USER')) {
1841 $warehouse_id = $user->fk_warehouse;
1842 }
1843 }
1844
1845 print '<form name="crea_commande" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1846 print '<input type="hidden" name="token" value="'.newToken().'">';
1847 print '<input type="hidden" name="action" value="add">';
1848 print '<input type="hidden" name="changecompany" value="0">'; // will be set to 1 by javascript so we know post is done after a company change
1849 print '<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.'">';
1850 print '<input type="hidden" name="origin" value="'.$origin.'">';
1851 print '<input type="hidden" name="originid" value="'.$originid.'">';
1852 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1853 if (!empty($currency_tx)) {
1854 print '<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.'">';
1855 }
1856
1857 print dol_get_fiche_head('');
1858
1859 // Call Hook tabContentCreateOrder
1860 $parameters = array();
1861 // Note that $action and $object may be modified by hook
1862 $reshook = $hookmanager->executeHooks('tabContentCreateOrder', $parameters, $object, $action);
1863 if (empty($reshook)) {
1864 print '<table class="border centpercent">';
1865
1866 // Reference
1867 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>';
1868
1869 // Reference client
1870 print '<tr><td>'.$langs->trans('RefCustomer').'</td><td>';
1871 if (getDolGlobalString('MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER') && !empty($origin) && !empty($originid)) {
1872 print '<input type="text" name="ref_client" value="'.$ref_client.'"></td>';
1873 } else {
1874 print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'"></td>';
1875 }
1876 print '</tr>';
1877
1878 // Thirdparty
1879 print '<tr>';
1880 print '<td class="fieldrequired">'.$langs->trans('Customer').'</td>';
1881 if ($socid > 0) {
1882 print '<td>';
1883 print $soc->getNomUrl(1, 'customer');
1884 print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1885 print '</td>';
1886 } else {
1887 print '<td class="valuefieldcreate">';
1888 $filter = '((s.client:IN:1,2,3) AND (s.status:=:1))';
1889 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company('', 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth175 maxwidth500 widthcentpercentminusxx');
1890 // reload page to retrieve customer information
1891 if (!getDolGlobalString('RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED')) {
1892 print '<script>
1893 $(document).ready(function() {
1894 $("#socid").change(function() {
1895 console.log("We have changed the company - Reload page");
1896 var socid = $(this).val();
1897 // reload page
1898 $("input[name=action]").val("create");
1899 $("input[name=changecompany]").val("1");
1900 $("form[name=crea_commande]").submit();
1901 });
1902 });
1903 </script>';
1904 }
1905 print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1906 print '</td>';
1907 }
1908 print '</tr>'."\n";
1909
1910 // Contact of order
1911 if ($socid > 0) {
1912 // Contacts (ask contact only if thirdparty already defined).
1913 print "<tr><td>".$langs->trans("DefaultContact").'</td><td>';
1914 print img_picto('', 'contact', 'class="pictofixedwidth"');
1915 //print $form->selectcontacts($soc->id, $contactid, 'contactid', 1, empty($srccontactslist) ? "" : $srccontactslist, '', 1, 'maxwidth300 widthcentpercentminusx');
1916 print $form->select_contact($soc->id, $contactid, 'contactid', 1, empty($srccontactslist) ? "" : $srccontactslist, '', 1, 'maxwidth300 widthcentpercentminusx', true);
1917 print '</td></tr>';
1918
1919 // Ligne info remises tiers
1920 print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
1921
1922 $absolute_discount = $soc->getAvailableDiscounts();
1923
1924 $thirdparty = $soc;
1925 $discount_type = 0;
1926 $backtopage = $_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.urlencode((string) (GETPOST('origin'))).'&originid='.urlencode((string) (GETPOSTINT('originid')));
1927 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1928
1929 print '</td></tr>';
1930 }
1931
1932 // Date
1933 print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td>';
1934 print img_picto('', 'action', 'class="pictofixedwidth"');
1935 print $form->selectDate('', 're', 0, 0, 0, "crea_commande", 1, 1); // Always autofill date with current date
1936 print '</td></tr>';
1937
1938 // Date delivery planned
1939 print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
1940 print '<td colspan="3">';
1941 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date);
1942 print img_picto('', 'action', 'class="pictofixedwidth"');
1943 print $form->selectDate($date_delivery ? $date_delivery : -1, 'liv_', 1, 1, 1);
1944 print "</td>\n";
1945 print '</tr>';
1946
1947 // Delivery delay
1948 print '<tr class="fielddeliverydelay"><td>'.$langs->trans('AvailabilityPeriod').'</td><td>';
1949 print img_picto('', 'clock', 'class="pictofixedwidth"');
1950 $form->selectAvailabilityDelay((GETPOSTISSET('availability_id') ? GETPOST('availability_id') : $availability_id), 'availability_id', '', 1, 'maxwidth200 widthcentpercentminusx');
1951 print '</td></tr>';
1952
1953 // Terms of payment
1954 print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
1955 print img_picto('', 'payment', 'class="pictofixedwidth"');
1956 print $form->getSelectConditionsPaiements($cond_reglement_id, 'cond_reglement_id', 1, 1, 0, 'maxwidth200 widthcentpercentminusx', $deposit_percent);
1957 print '</td></tr>';
1958
1959 // Payment mode
1960 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>';
1961 print img_picto('', 'bank', 'class="pictofixedwidth"');
1962 print $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1);
1963 print '</td></tr>';
1964
1965 // Bank Account
1966 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled("bank")) {
1967 print '<tr><td>'.$langs->trans('BankAccount').'</td><td>';
1968 print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes($fk_account, 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1);
1969 print '</td></tr>';
1970 }
1971
1972 // Shipping Method
1973 if (isModEnabled('shipping')) {
1974 print '<tr><td>'.$langs->trans('SendingMethod').'</td><td>';
1975 print img_picto('', 'object_dolly', 'class="pictofixedwidth"');
1976 $form->selectShippingMethod(((GETPOSTISSET('shipping_method_id') && GETPOSTINT('shipping_method_id') != 0) ? GETPOST('shipping_method_id') : $shipping_method_id), 'shipping_method_id', '', 1, '', 0, 'maxwidth200 widthcentpercentminusx');
1977 print '</td></tr>';
1978 }
1979
1980 // Warehouse
1981 if (isModEnabled('stock') && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1982 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1983 $formproduct = new FormProduct($db);
1984 print '<tr><td>'.$langs->trans('Warehouse').'</td><td>';
1985 print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses((GETPOSTISSET('warehouse_id') ? GETPOST('warehouse_id') : $warehouse_id), 'warehouse_id', '', 1, 0, 0, '', 0, 0, array(), 'maxwidth500 widthcentpercentminusxx');
1986 print '</td></tr>';
1987 }
1988
1989 // Source / Channel - What trigger creation
1990 print '<tr><td>'.$langs->trans('Channel').'</td><td>';
1991 print img_picto('', 'question', 'class="pictofixedwidth"');
1992 $form->selectInputReason((GETPOSTISSET('demand_reason_id') ? GETPOST('demand_reason_id') : $demand_reason_id), 'demand_reason_id', '', 1, 'maxwidth200 widthcentpercentminusx');
1993 print '</td></tr>';
1994
1995 // TODO How record was recorded OrderMode (llx_c_input_method)
1996
1997 // Project
1998 if (isModEnabled('project')) {
1999 $langs->load("projects");
2000 print '<tr>';
2001 print '<td>'.$langs->trans("Project").'</td><td>';
2002 print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), (GETPOSTISSET('projectid') ? GETPOST('projectid') : $projectid), 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
2003 print ' <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>';
2004 print '</td>';
2005 print '</tr>';
2006 }
2007
2008 // Incoterms
2009 if (isModEnabled('incoterm')) {
2010 print '<tr>';
2011 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).'</label></td>';
2012 print '<td class="maxwidthonsmartphone">';
2013 $incoterm_id = GETPOST('incoterm_id');
2014 $location_incoterms = GETPOST('location_incoterms');
2015 if (empty($incoterm_id)) {
2016 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
2017 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
2018 }
2019 print img_picto('', 'incoterm', 'class="pictofixedwidth"');
2020 print $form->select_incoterms($incoterm_id, $location_incoterms);
2021 print '</td></tr>';
2022 }
2023
2024 // Other attributes
2025 $parameters = array();
2026 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2027 $parameters['objectsrc'] = $objectsrc;
2028 }
2029 $parameters['socid'] = $socid;
2030
2031 // Note that $action and $object may be modified by hook
2032 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
2033 print $hookmanager->resPrint;
2034 if (empty($reshook)) {
2035 if (getDolGlobalString('THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER') && !empty($soc->id)) {
2036 // copy from thirdparty
2037 $tpExtrafields = new ExtraFields($db);
2038 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
2039 if ($soc->fetch_optionals() > 0) {
2040 $object->array_options = array_merge($object->array_options, $soc->array_options);
2041 }
2042 }
2043
2044 print $object->showOptionals($extrafields, 'create', $parameters);
2045 }
2046
2047 // Template to use by default
2048 print '<tr><td>'.$langs->trans('DefaultModel').'</td>';
2049 print '<td>';
2050 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
2052 $preselected = getDolGlobalString('COMMANDE_ADDON_PDF');
2053 print img_picto('', 'pdf', 'class="pictofixedwidth"');
2054 print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1);
2055 print "</td></tr>";
2056
2057 // Multicurrency
2058 if (isModEnabled("multicurrency")) {
2059 print '<tr>';
2060 print '<td>'.$form->editfieldkey("Currency", 'multicurrency_code', '', $object, 0).'</td>';
2061 print '<td class="maxwidthonsmartphone">';
2062 print img_picto('', 'currency', 'class="pictofixedwidth"').$form->selectMultiCurrency(((GETPOSTISSET('multicurrency_code') && !GETPOST('changecompany')) ? GETPOST('multicurrency_code') : $currency_code), 'multicurrency_code', 0, '', false, 'maxwidth200 widthcentpercentminusx');
2063 print '</td></tr>';
2064 }
2065
2066 // Note public
2067 print '<tr>';
2068 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
2069 print '<td>';
2070
2071 $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
2072 print $doleditor->Create(1);
2073 // print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
2074 print '</td></tr>';
2075
2076 // Note private
2077 if (empty($user->socid)) {
2078 print '<tr>';
2079 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
2080 print '<td>';
2081
2082 $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
2083 print $doleditor->Create(1);
2084 // print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
2085 print '</td></tr>';
2086 }
2087
2088 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2089 // TODO for compatibility
2090 if ($origin == 'contrat') {
2091 // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
2092 //$objectsrc->remise_absolue = $remise_absolue;
2093 //$objectsrc->remise_percent = $remise_percent;
2094 $objectsrc->update_price(1);
2095 }
2096
2097 print "\n<!-- ".$classname." info -->";
2098 print "\n";
2099 print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
2100 print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
2101 print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
2102 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
2103 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
2104
2105 switch ($classname) {
2106 case 'Propal':
2107 $newclassname = 'CommercialProposal';
2108 break;
2109 case 'Commande':
2110 $newclassname = 'Order';
2111 break;
2112 case 'Expedition':
2113 $newclassname = 'Sending';
2114 break;
2115 case 'Contrat':
2116 $newclassname = 'Contract';
2117 break;
2118 default:
2119 $newclassname = $classname;
2120 }
2121
2122 print '<tr><td>'.$langs->trans($newclassname).'</td><td>'.$objectsrc->getNomUrl(1).'</td></tr>';
2123
2124 // Amount
2125 print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($objectsrc->total_ht).'</td></tr>';
2126 print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($objectsrc->total_tva)."</td></tr>";
2127 if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1 RE
2128 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax1)."</td></tr>";
2129 }
2130
2131 if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2 IRPF
2132 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax2)."</td></tr>";
2133 }
2134
2135 print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($objectsrc->total_ttc)."</td></tr>";
2136
2137 if (isModEnabled("multicurrency")) {
2138 print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td>'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
2139 print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td>'.price($objectsrc->multicurrency_total_tva)."</td></tr>";
2140 print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td>'.price($objectsrc->multicurrency_total_ttc)."</td></tr>";
2141 }
2142 }
2143
2144 print "\n";
2145
2146 print '</table>';
2147 }
2148
2149 print dol_get_fiche_end();
2150
2151 print $form->buttonsSaveCancel("CreateDraft");
2152
2153 // Show origin lines
2154 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2155 $title = $langs->trans('ProductsAndServices');
2156 print load_fiche_titre($title);
2157
2158 print '<div class="div-table-responsive-no-min">';
2159 print '<table class="noborder centpercent">';
2160
2161 $objectsrc->printOriginLinesList('', $selectedLines);
2162
2163 print '</table>';
2164 print '</div>';
2165 }
2166
2167 print '</form>';
2168} else {
2169 // Mode view
2170 $now = dol_now();
2171
2172 if ($object->id > 0) {
2173 $product_static = new Product($db);
2174
2175 $soc = new Societe($db);
2176 $soc->fetch($object->socid);
2177
2178 $author = new User($db);
2179 $author->fetch($object->user_author_id);
2180
2181 $object->fetch_thirdparty();
2182 $res = $object->fetch_optionals();
2183
2185 print dol_get_fiche_head($head, 'order', $langs->trans("CustomerOrder"), -1, 'order');
2186
2187 $formconfirm = '';
2188
2189 // Confirmation to delete
2190 if ($action == 'delete') {
2191 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
2192 }
2193
2194 // Confirmation of validation
2195 if ($action == 'validate') {
2196 // We check that object has a temporary ref
2197 $ref = substr($object->ref, 1, 4);
2198 if ($ref == 'PROV' || $ref == '') {
2199 $numref = $object->getNextNumRef($soc);
2200 if (empty($numref)) {
2201 $error++;
2202 setEventMessages($object->error, $object->errors, 'errors');
2203 }
2204 } else {
2205 $numref = $object->ref;
2206 }
2207
2208 $text = $langs->trans('ConfirmValidateOrder', $numref);
2209 if (isModEnabled('notification')) {
2210 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
2211 $notify = new Notify($db);
2212 $text .= '<br>';
2213 $text .= $notify->confirmMessage('ORDER_VALIDATE', $object->socid, $object);
2214 }
2215
2216 $qualified_for_stock_change = 0;
2217 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2218 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2219 } else {
2220 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2221 }
2222
2223 $formquestion = array();
2224 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2225 $langs->load("stocks");
2226 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2227 $formproduct = new FormProduct($db);
2228 $forcecombo = 0;
2229 if ($conf->browser->name == 'ie') {
2230 $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
2231 }
2232 $formquestion = array(
2233 // 'text' => $langs->trans("ConfirmClone"),
2234 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
2235 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
2236 array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOSTINT('idwarehouse') ? GETPOSTINT('idwarehouse') : 'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
2237 );
2238 }
2239
2240 // mandatoryPeriod
2241 $nbMandated = 0;
2242 foreach ($object->lines as $line) {
2243 $res = $line->fetch_product();
2244 if ($res > 0) {
2245 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
2246 $nbMandated++;
2247 break;
2248 }
2249 }
2250 }
2251 if ($nbMandated > 0) {
2252 if (getDolGlobalString('SERVICE_STRICT_MANDATORY_PERIOD')) {
2253 setEventMessages($langs->trans("mandatoryPeriodNeedTobeSetMsgValidate"), null, 'errors');
2254 $error++;
2255 } else {
2256 $text .= '<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'</span></div>';
2257 }
2258 }
2259
2260 if (getDolGlobalInt('SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2261 // This is a hidden option:
2262 // Suggestion to create invoice during order validation is not enabled by default.
2263 // Such choice should be managed by the workflow module and trigger. This option generates conflicts with some setup.
2264 // It may also break step of creating an order when invoicing must be done from proposals and not from orders
2265 $deposit_percent_from_payment_terms = (float) getDictionaryValue('c_payment_term', 'deposit_percent', $object->cond_reglement_id);
2266
2267 if (!empty($deposit_percent_from_payment_terms) && isModEnabled('invoice') && $user->hasRight('facture', 'creer')) {
2268 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
2269
2270 $object->fetchObjectLinked();
2271
2272 $eligibleForDepositGeneration = true;
2273
2274 if (array_key_exists('facture', $object->linkedObjects)) {
2275 foreach ($object->linkedObjects['facture'] as $invoice) {
2276 if ($invoice->type == Facture::TYPE_DEPOSIT) {
2277 $eligibleForDepositGeneration = false;
2278 break;
2279 }
2280 }
2281 }
2282
2283 if ($eligibleForDepositGeneration && array_key_exists('propal', $object->linkedObjects)) {
2284 foreach ($object->linkedObjects['propal'] as $proposal) {
2285 $proposal->fetchObjectLinked();
2286
2287 if (array_key_exists('facture', $proposal->linkedObjects)) {
2288 foreach ($proposal->linkedObjects['facture'] as $invoice) {
2289 if ($invoice->type == Facture::TYPE_DEPOSIT) {
2290 $eligibleForDepositGeneration = false;
2291 break 2;
2292 }
2293 }
2294 }
2295 }
2296 }
2297
2298 if ($eligibleForDepositGeneration) {
2299 $formquestion[] = array(
2300 'type' => 'checkbox',
2301 'tdclass' => '',
2302 'name' => 'generate_deposit',
2303 'label' => $form->textwithpicto($langs->trans('GenerateDeposit', $object->deposit_percent), $langs->trans('DepositGenerationPermittedByThePaymentTermsSelected'))
2304 );
2305
2306 $formquestion[] = array(
2307 'type' => 'date',
2308 'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
2309 'name' => 'datef',
2310 'label' => $langs->trans('DateInvoice'),
2311 'value' => dol_now(),
2312 'datenow' => true
2313 );
2314
2315 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2316 $formquestion[] = array(
2317 'type' => 'date',
2318 'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
2319 'name' => 'date_pointoftax',
2320 'label' => $langs->trans('DatePointOfTax'),
2321 'value' => dol_now(),
2322 'datenow' => true
2323 );
2324 }
2325
2326
2327 $paymentTermsSelect = $form->getSelectConditionsPaiements(0, 'cond_reglement_id', -1, 0, 0, 'minwidth200');
2328
2329 $formquestion[] = array(
2330 'type' => 'other',
2331 'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
2332 'name' => 'cond_reglement_id',
2333 'label' => $langs->trans('PaymentTerm'),
2334 'value' => $paymentTermsSelect
2335 );
2336
2337 $formquestion[] = array(
2338 'type' => 'checkbox',
2339 'tdclass' => 'showonlyifgeneratedeposit',
2340 'name' => 'validate_generated_deposit',
2341 'label' => $langs->trans('ValidateGeneratedDeposit')
2342 );
2343
2344 $formquestion[] = array(
2345 'type' => 'onecolumn',
2346 'value' => '
2347 <script>
2348 $(document).ready(function() {
2349 $("[name=generate_deposit]").change(function () {
2350 let $self = $(this);
2351 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2352
2353 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2354 $target.show();
2355 } else {
2356 $target.hide();
2357 }
2358
2359 return true;
2360 });
2361 });
2362 </script>
2363 '
2364 );
2365 }
2366 }
2367 }
2368
2369 if (!$error) {
2370 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 240);
2371 }
2372 }
2373
2374 // Confirm back to draft status
2375 if ($action == 'modif') {
2376 $qualified_for_stock_change = 0;
2377 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2378 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2379 } else {
2380 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2381 }
2382
2383 $text = $langs->trans('ConfirmUnvalidateOrder', $object->ref);
2384 $formquestion = array();
2385 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2386 $langs->load("stocks");
2387 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2388 $formproduct = new FormProduct($db);
2389 $forcecombo = 0;
2390 if ($conf->browser->name == 'ie') {
2391 $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
2392 }
2393 $formquestion = array(
2394 // 'text' => $langs->trans("ConfirmClone"),
2395 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
2396 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
2397 array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse') ? GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
2398 );
2399 }
2400
2401 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnvalidateOrder'), $text, 'confirm_modif', $formquestion, "yes", 1, 220);
2402 }
2403
2404 /*
2405 * Confirmation de la cloture
2406 */
2407 if ($action == 'shipped') {
2408 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_shipped', '', 0, 1);
2409 }
2410
2411 /*
2412 * Confirmation de l'annulation
2413 */
2414 if ($action == 'cancel') {
2415 $qualified_for_stock_change = 0;
2416 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2417 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2418 } else {
2419 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2420 }
2421
2422 $text = $langs->trans('ConfirmCancelOrder', $object->ref);
2423 $formquestion = array();
2424 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2425 $langs->load("stocks");
2426 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2427 $formproduct = new FormProduct($db);
2428 $forcecombo = 0;
2429 if ($conf->browser->name == 'ie') {
2430 $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
2431 }
2432 $formquestion = array(
2433 // 'text' => $langs->trans("ConfirmClone"),
2434 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
2435 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
2436 array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse') ? GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
2437 );
2438 }
2439
2440 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("Cancel"), $text, 'confirm_cancel', $formquestion, 0, 1);
2441 }
2442
2443 // Confirmation to delete line
2444 if ($action == 'ask_deleteline') {
2445 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
2446 }
2447
2448 // Clone confirmation
2449 if ($action == 'clone') {
2450 $filter = '(s.client:IN:1,2,3)';
2451 // Create an array for form
2452 $formquestion = array(
2453 array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOSTINT('socid'), 'socid', $filter, '', 0, 0, null, 0, 'maxwidth300'))
2454 );
2455 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneOrder', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
2456 }
2457
2458 // Call Hook formConfirm
2459 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
2460 // Note that $action and $object may be modified by hook
2461 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action);
2462 if (empty($reshook)) {
2463 $formconfirm .= $hookmanager->resPrint;
2464 } elseif ($reshook > 0) {
2465 $formconfirm = $hookmanager->resPrint;
2466 }
2467
2468 // Print form confirm
2469 print $formconfirm;
2470
2471
2472 // Order card
2473
2474 $linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
2475
2476 $morehtmlref = '<div class="refidno">';
2477 // Ref customer
2478 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1);
2479 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':' . getDolGlobalString('THIRDPARTY_REF_INPUT_SIZE') : ''), '', null, null, '', 1);
2480 // Thirdparty
2481 $morehtmlref .= '<br>'.$soc->getNomUrl(1, 'customer');
2482 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
2483 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
2484 }
2485 // Project
2486 if (isModEnabled('project')) {
2487 $langs->load("projects");
2488 $morehtmlref .= '<br>';
2489 if ($usercancreate) {
2490 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
2491 if ($action != 'classify') {
2492 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
2493 }
2494 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
2495 } else {
2496 if (!empty($object->fk_project)) {
2497 $proj = new Project($db);
2498 $proj->fetch($object->fk_project);
2499 $morehtmlref .= $proj->getNomUrl(1);
2500 if ($proj->title) {
2501 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
2502 }
2503 }
2504 }
2505 }
2506 $morehtmlref .= '</div>';
2507
2508
2509 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
2510
2511 // Call Hook tabContentViewOrder
2512 $parameters = array();
2513 // Note that $action and $object may be modified by hook
2514 $reshook = $hookmanager->executeHooks('tabContentViewOrder', $parameters, $object, $action);
2515 if (empty($reshook)) {
2516 print '<div class="fichecenter">';
2517 print '<div class="fichehalfleft">';
2518 print '<div class="underbanner clearboth"></div>';
2519
2520 print '<table class="border tableforfield centpercent">';
2521
2522 if ($soc->outstanding_limit) {
2523 // Outstanding Bill
2524 print '<tr><td class="titlefield">';
2525 print $langs->trans('OutstandingBill');
2526 print '</td><td class="valuefield">';
2527 $arrayoutstandingbills = $soc->getOutstandingBills();
2528 print price($arrayoutstandingbills['opened']).' / ';
2529 print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency);
2530 print '</td>';
2531 print '</tr>';
2532 }
2533
2534 // Relative and absolute discounts
2535 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
2536 $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
2537 $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
2538 } else {
2539 $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2540 $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2541 }
2542
2543 $addrelativediscount = '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("EditRelativeDiscounts").'</a>';
2544 $addabsolutediscount = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("EditGlobalDiscounts").'</a>';
2545 $addcreditnote = '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&socid='.$soc->id.'&type=2&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("AddCreditNote").'</a>';
2546
2547 print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td class="valuefield">';
2548
2549 $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
2550 $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
2551 $absolute_discount = price2num($absolute_discount, 'MT');
2552 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
2553
2554 $thirdparty = $soc;
2555 $discount_type = 0;
2556 $backtopage = $_SERVER["PHP_SELF"].'?id='.$object->id;
2557 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
2558
2559 print '</td></tr>';
2560
2561 // Date
2562 print '<tr><td>';
2563 $editenable = $usercancreate && $object->statut == Commande::STATUS_DRAFT;
2564 print $form->editfieldkey("Date", 'date', '', $object, $editenable);
2565 print '</td><td class="valuefield">';
2566 if ($action == 'editdate') {
2567 print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2568 print '<input type="hidden" name="token" value="'.newToken().'">';
2569 print '<input type="hidden" name="action" value="setdate">';
2570 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2571 print $form->selectDate($object->date, 'order_', 0, 0, 0, "setdate");
2572 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2573 print '</form>';
2574 } else {
2575 print $object->date ? dol_print_date($object->date, 'day') : '&nbsp;';
2576 if ($object->hasDelay() && empty($object->delivery_date)) { // If there is a delivery date planned, warning should be on this date
2577 print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");
2578 }
2579 }
2580 print '</td>';
2581 print '</tr>';
2582
2583 // Delivery date planned
2584 print '<tr><td>';
2585 $editenable = $usercancreate;
2586 print $form->editfieldkey("DateDeliveryPlanned", 'date_livraison', '', $object, $editenable);
2587 print '</td><td class="valuefield">';
2588 if ($action == 'editdate_livraison') {
2589 print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2590 print '<input type="hidden" name="token" value="'.newToken().'">';
2591 print '<input type="hidden" name="action" value="setdate_livraison">';
2592 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2593 print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 'liv_', 1, 1, 0, "setdate_livraison", 1, 0);
2594 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2595 print '</form>';
2596 } else {
2597 print $object->delivery_date ? dol_print_date($object->delivery_date, 'dayhour') : '&nbsp;';
2598 if ($object->hasDelay() && !empty($object->delivery_date)) {
2599 print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");
2600 }
2601 }
2602 print '</td>';
2603 print '</tr>';
2604
2605 // Delivery delay
2606 print '<tr class="fielddeliverydelay"><td>';
2607 $editenable = $usercancreate;
2608 print $form->editfieldkey("AvailabilityPeriod", 'availability', '', $object, $editenable);
2609 print '</td><td class="valuefield">';
2610 if ($action == 'editavailability') {
2611 $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1);
2612 } else {
2613 $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1);
2614 }
2615 print '</td></tr>';
2616
2617 // Shipping Method
2618 if (isModEnabled('shipping')) {
2619 print '<tr><td>';
2620 $editenable = $usercancreate;
2621 print $form->editfieldkey("SendingMethod", 'shippingmethod', '', $object, $editenable);
2622 print '</td><td class="valuefield">';
2623 if ($action == 'editshippingmethod') {
2624 $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
2625 } else {
2626 $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none');
2627 }
2628 print '</td>';
2629 print '</tr>';
2630 }
2631
2632 // Warehouse
2633 if (isModEnabled('stock') && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
2634 $langs->load('stocks');
2635 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2636 $formproduct = new FormProduct($db);
2637 print '<tr><td>';
2638 $editenable = $usercancreate;
2639 print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $editenable);
2640 print '</td><td class="valuefield">';
2641 if ($action == 'editwarehouse') {
2642 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1);
2643 } else {
2644 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none');
2645 }
2646 print '</td>';
2647 print '</tr>';
2648 }
2649
2650 // Source reason (why we have an order)
2651 print '<tr><td>';
2652 $editenable = $usercancreate;
2653 print $form->editfieldkey("Source", 'demandreason', '', $object, $editenable);
2654 print '</td><td class="valuefield">';
2655 if ($action == 'editdemandreason') {
2656 $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1);
2657 } else {
2658 $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none');
2659 }
2660 print '</td></tr>';
2661
2662 // Terms of payment
2663 print '<tr><td>';
2664 $editenable = $usercancreate;
2665 print $form->editfieldkey("PaymentConditionsShort", 'conditions', '', $object, $editenable);
2666 print '</td><td class="valuefield">';
2667 if ($action == 'editconditions') {
2668 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent);
2669 } else {
2670 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1, '', 1, $object->deposit_percent);
2671 }
2672 print '</td>';
2673
2674 print '</tr>';
2675
2676 // Mode of payment
2677 print '<tr><td>';
2678 $editenable = $usercancreate;
2679 print $form->editfieldkey("PaymentMode", 'mode', '', $object, $editenable);
2680 print '</td><td class="valuefield">';
2681 if ($action == 'editmode') {
2682 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
2683 } else {
2684 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
2685 }
2686 print '</td></tr>';
2687
2688 // Multicurrency
2689 if (isModEnabled("multicurrency")) {
2690 // Multicurrency code
2691 print '<tr>';
2692 print '<td>';
2693 $editenable = $usercancreate && $object->statut == Commande::STATUS_DRAFT;
2694 print $form->editfieldkey("Currency", 'multicurrencycode', '', $object, $editenable);
2695 print '</td><td class="valuefield">';
2696 if ($action == 'editmulticurrencycode') {
2697 $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
2698 } else {
2699 $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
2700 }
2701 print '</td></tr>';
2702
2703 // Multicurrency rate
2704 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2705 print '<tr>';
2706 print '<td>';
2707 $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT;
2708 print $form->editfieldkey("CurrencyRate", 'multicurrencyrate', '', $object, $editenable);
2709 print '</td><td class="valuefield">';
2710 if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
2711 if ($action == 'actualizemulticurrencyrate') {
2712 list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
2713 }
2714 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
2715 } else {
2716 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
2717 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2718 print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
2719 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
2720 print '</div>';
2721 }
2722 }
2723 print '</td></tr>';
2724 }
2725 }
2726
2727 // TODO Order mode (how we receive order). Not yet implemented
2728 /*
2729 print '<tr><td>';
2730 $editenable = $usercancreate;
2731 print $form->editfieldkey("SourceMode", 'inputmode', '', $object, $editenable);
2732 print '</td><td>';
2733 if ($action == 'editinputmode') {
2734 $form->formInputMode($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->source, 'input_mode_id', 1);
2735 } else {
2736 $form->formInputMode($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->source, 'none');
2737 }
2738 print '</td></tr>';
2739 */
2740
2741 $tmparray = $object->getTotalWeightVolume();
2742 $totalWeight = $tmparray['weight'];
2743 $totalVolume = $tmparray['volume'];
2744 if ($totalWeight) {
2745 print '<tr><td>'.$langs->trans("CalculatedWeight").'</td>';
2746 print '<td class="valuefield">';
2747 print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no');
2748 print '</td></tr>';
2749 }
2750 if ($totalVolume) {
2751 print '<tr><td>'.$langs->trans("CalculatedVolume").'</td>';
2752 print '<td class="valuefield">';
2753 print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no');
2754 print '</td></tr>';
2755 }
2756
2757 // TODO How record was recorded OrderMode (llx_c_input_method)
2758
2759 // Incoterms
2760 if (isModEnabled('incoterm')) {
2761 print '<tr><td>';
2762 $editenable = $usercancreate;
2763 print $form->editfieldkey("IncotermLabel", 'incoterm', '', $object, $editenable);
2764 print '</td>';
2765 print '<td class="valuefield">';
2766 if ($action != 'editincoterm') {
2767 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2768 } else {
2769 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
2770 }
2771 print '</td></tr>';
2772 }
2773
2774 // Bank Account
2775 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled("bank")) {
2776 print '<tr><td>';
2777 $editenable = $usercancreate;
2778 print $form->editfieldkey("BankAccount", 'bankaccount', '', $object, $editenable);
2779 print '</td><td class="valuefield">';
2780 if ($action == 'editbankaccount') {
2781 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
2782 } else {
2783 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
2784 }
2785 print '</td>';
2786 print '</tr>';
2787 }
2788
2789 // Other attributes
2790 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2791
2792 print '</table>';
2793
2794 print '</div>';
2795 print '<div class="fichehalfright">';
2796 print '<div class="underbanner clearboth"></div>';
2797
2798 print '<table class="border tableforfield centpercent">';
2799
2800 $alert = '';
2801 if (getDolGlobalString('ORDER_MANAGE_MIN_AMOUNT') && $object->total_ht < $object->thirdparty->order_min_amount) {
2802 $alert = ' ' . img_warning($langs->trans('OrderMinAmount') . ': ' . price($object->thirdparty->order_min_amount));
2803 }
2804
2805 print '<tr>';
2806 print '<td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
2807 print '<td class="nowrap amountcard right">' . price($object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2808 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2809 // Multicurrency Amount HT
2810 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ht, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2811 }
2812 print '</tr>';
2813
2814 print '<tr>';
2815 print '<td class="titlefieldmiddle">' . $langs->trans('AmountVAT') . '</td>';
2816 print '<td class="nowrap amountcard right">' . price($object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2817 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2818 // Multicurrency Amount VAT
2819 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_tva, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2820 }
2821 print '</tr>';
2822
2823 // Amount Local Taxes
2824 if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) {
2825 print '<tr>';
2826 print '<td class="titlefieldmiddle">' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
2827 print '<td class="nowrap amountcard right">' . price($object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2828 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2829 $object->multicurrency_total_localtax1 = price2num($object->total_localtax1 * $object->multicurrency_tx, 'MT');
2830
2831 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2832 }
2833 print '</tr>';
2834 }
2835
2836 // Amount Local Taxes
2837 if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) {
2838 print '<tr>';
2839 print '<td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
2840 print '<td class="nowrap amountcard right">' . price($object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2841 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2842 $object->multicurrency_total_localtax2 = price2num($object->total_localtax2 * $object->multicurrency_tx, 'MT');
2843
2844 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2845 }
2846 print '</tr>';
2847 }
2848
2849 print '<tr>';
2850 print '<td>' . $langs->trans('AmountTTC') . '</td>';
2851 print '<td class="valuefield nowrap right amountcard">' . price($object->total_ttc, 1, '', 1, -1, -1, $conf->currency) . '</td>';
2852 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2853 // Multicurrency Amount TTC
2854 print '<td class="valuefield nowrap right amountcard">' . price($object->multicurrency_total_ttc, 1, '', 1, -1, -1, $object->multicurrency_code) . '</td>';
2855 }
2856 print '</tr>'."\n";
2857
2858 print '</table>';
2859
2860 // Statut
2861 //print '<tr><td>' . $langs->trans('Status') . '</td><td>' . $object->getLibStatut(4) . '</td></tr>';
2862
2863 // Margin Infos
2864 if (isModEnabled('margin')) {
2865 $formmargin->displayMarginInfos($object);
2866 }
2867
2868
2869 print '</div>';
2870 print '</div>'; // Close fichecenter
2871
2872 print '<div class="clearboth"></div><br>';
2873
2874 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
2875 $blocname = 'contacts';
2876 $title = $langs->trans('ContactsAddresses');
2877 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2878 }
2879
2880 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
2881 $blocname = 'notes';
2882 $title = $langs->trans('Notes');
2883 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2884 }
2885
2886 /*
2887 * Lines
2888 */
2889
2890 // Get object lines
2891 $result = $object->getLinesArray();
2892
2893 // Add products/services form
2894 //$forceall = 1;
2895 global $inputalsopricewithtax;
2896 $inputalsopricewithtax = 1;
2897
2898 print '<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">
2899 <input type="hidden" name="token" value="' . newToken().'">
2900 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
2901 <input type="hidden" name="mode" value="">
2902 <input type="hidden" name="page_y" value="">
2903 <input type="hidden" name="id" value="' . $object->id.'">
2904 <input type="hidden" name="backtopage" value="'.$backtopage.'">
2905 ';
2906
2907 if (!empty($conf->use_javascript_ajax) && $object->statut == Commande::STATUS_DRAFT) {
2908 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
2909 }
2910
2911 print '<div class="div-table-responsive-no-min">';
2912 print '<table id="tablelines" class="noborder noshadow" width="100%">';
2913
2914 // Show object lines
2915 if (!empty($object->lines)) {
2916 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2917 }
2918
2919 /*
2920 * Form to add new line
2921 */
2922 if ($object->statut == Commande::STATUS_DRAFT && $usercancreate && $action != 'selectlines') {
2923 if ($action != 'editline') {
2924 // Add free products/services
2925
2926 $parameters = array();
2927 // Note that $action and $object may be modified by hook
2928 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action);
2929 if ($reshook < 0) {
2930 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2931 }
2932 if (empty($reshook)) {
2933 $object->formAddObjectLine(1, $mysoc, $soc);
2934 }
2935 } else {
2936 $parameters = array();
2937 $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action);
2938 }
2939 }
2940 print '</table>';
2941 print '</div>';
2942
2943 print "</form>\n";
2944 }
2945
2946 print dol_get_fiche_end();
2947
2948 /*
2949 * Buttons for actions
2950 */
2951 if ($action != 'presend' && $action != 'editline') {
2952 print '<div class="tabsAction">';
2953
2954 $parameters = array();
2955 // Note that $action and $object may be modified by hook
2956 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
2957 if (empty($reshook)) {
2958 $numlines = count($object->lines);
2959
2960 // Reopen a closed order
2961 if (($object->statut == Commande::STATUS_CLOSED || $object->statut == Commande::STATUS_CANCELED) && $usercancreate && (!$object->billed || !getDolGlobalInt('ORDER_DONT_REOPEN_BILLED'))) {
2962 print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&amp;token='.newToken().'&amp;id='.$object->id, '');
2963 }
2964
2965 // Send
2966 if (empty($user->socid)) {
2967 if ($object->statut > Commande::STATUS_DRAFT || getDolGlobalString('COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS')) {
2968 if ($usercansend) {
2969 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');
2970 } else {
2971 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER['PHP_SELF']. '#', '', false);
2972 }
2973 }
2974 }
2975
2976 // Valid
2977 if ($object->statut == Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || getDolGlobalString('ORDER_ENABLE_NEGATIVE')) && $usercanvalidate) {
2978 if ($numlines > 0) {
2979 print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=validate&amp;token='.newToken().'&amp;id='.$object->id, $object->id, 1);
2980 } else {
2981 print dolGetButtonAction($langs->trans("ErrorObjectMustHaveLinesToBeValidated", $object->ref), $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=validate&amp;token='.newToken().'&amp;id='.$object->id, $object->id, 0);
2982 }
2983 }
2984 // Edit
2985 if ($object->statut == Commande::STATUS_VALIDATED && $usercancreate) {
2986 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=modif&amp;token='.newToken().'&amp;id='.$object->id, '');
2987 }
2988
2989 $arrayforbutaction = array();
2990 // Create a purchase order
2991
2992
2993 if (! getDolGlobalInt('COMMANDE_DISABLE_ADD_PURCHASE_ORDER')) {
2994 $arrayforbutaction[] = array('lang' => 'orders', 'enabled' => (isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT), 'perm' => $usercancreatepurchaseorder, 'label' => 'AddPurchaseOrder', 'url' => '/fourn/commande/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id);
2995 }
2996
2997 /*if (isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0) {
2998 if ($usercancreatepurchaseorder) { isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0
2999 print dolGetButtonAction('', $langs->trans('AddPurchaseOrder'), 'default', DOL_URL_ROOT.'/fourn/commande/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id, '');
3000 }
3001 }*/
3002
3003 // Create intervention
3004 $arrayforbutaction[] = array('lang' => 'interventions', 'enabled' => (isModEnabled("intervention") && $object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && $object->getNbOfServicesLines() > 0), 'perm' => $user->hasRight('ficheinter', 'creer'), 'label' => 'AddIntervention', 'url' => '/fichinter/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid);
3005 /*if (isModEnabled('ficheinter')) {
3006 $langs->load("interventions");
3007
3008 if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && $object->getNbOfServicesLines() > 0) {
3009 if ($user->hasRight('ficheinter', 'creer')) {
3010 print dolGetButtonAction('', $langs->trans('AddIntervention'), 'default', DOL_URL_ROOT.'/fichinter/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid, '');
3011 } else {
3012 print dolGetButtonAction($langs->trans('NotAllowed'), $langs->trans('AddIntervention'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
3013 }
3014 }
3015 }*/
3016
3017 // Create contract
3018 $arrayforbutaction[] = array('lang' => 'contracts', 'enabled' => (isModEnabled("contract") && ($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS || $object->statut == Commande::STATUS_CLOSED)), 'perm' => $user->hasRight('contrat', 'creer'), 'label' => 'AddContract', 'url' => '/contrat/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid);
3019 /*if (isModEnabled('contrat') && ($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS || $object->statut == Commande::STATUS_CLOSED)) {
3020 $langs->load("contracts");
3021
3022 if ($user->hasRight('contrat', 'creer')) {
3023 print dolGetButtonAction('', $langs->trans('AddContract'), 'default', DOL_URL_ROOT.'/contrat/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid, '');
3024 }
3025 }*/
3026
3027 $numshipping = 0;
3028 if (isModEnabled('shipping')) {
3029 $numshipping = $object->countNbOfShipments();
3030 }
3031
3032 // Create shipment
3033 if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && ($object->getNbOfProductsLines() > 0 || getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
3034 if ((getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && $user->hasRight('expedition', 'creer')) || (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && $user->hasRight('expedition', 'delivery', 'creer'))) {
3035 $arrayforbutaction[] = array('lang' => 'sendings', 'enabled' => (isModEnabled("shipping") && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && ($object->getNbOfProductsLines() > 0 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')))), 'perm' => $user->hasRight('expedition', 'creer'), 'label' => 'CreateShipment', 'url' => '/expedition/shipment.php?id='.$object->id);
3036 /*
3037 if ($user->hasRight('expedition', 'creer')) {
3038 print dolGetButtonAction('', $langs->trans('CreateShipment'), 'default', DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id, '');
3039 } else {
3040 print dolGetButtonAction($langs->trans('NotAllowed'), $langs->trans('CreateShipment'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
3041 }*/
3042 } else {
3043 $langs->load("errors");
3044 print dolGetButtonAction($langs->trans('ErrorModuleSetupNotComplete'), $langs->trans('CreateShipment'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
3045 }
3046 }
3047
3048 // Create bill
3049 $arrayforbutaction[] = array(
3050 'lang' => 'bills',
3051 'enabled' => (isModEnabled('invoice') && $object->statut > Commande::STATUS_DRAFT && !$object->billed && $object->total_ttc >= 0),
3052 'perm' => ($user->hasRight('facture', 'creer') && !getDolGlobalInt('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')),
3053 'label' => 'CreateBill',
3054 'url' => '/compta/facture/card.php?action=create&amp;token='.newToken().'&amp;origin='.urlencode($object->element).'&amp;originid='.$object->id.'&amp;socid='.$object->socid
3055 );
3056 /*
3057 if (isModEnabled('facture') && $object->statut > Commande::STATUS_DRAFT && !$object->billed && $object->total_ttc >= 0) {
3058 if (isModEnabled('facture') && $user->hasRight('facture', 'creer') && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
3059 print dolGetButtonAction('', $langs->trans('CreateBill'), 'default', DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;token='.newToken().'&amp;origin='.urlencode($object->element).'&amp;originid='.$object->id.'&amp;socid='.$object->socid, '');
3060 }
3061 }*/
3062
3063 $actionButtonsParameters = [
3064 "areDropdownButtons" => !getDolGlobalInt("MAIN_REMOVE_DROPDOWN_CREATE_BUTTONS_ON_ORDER")
3065 ];
3066
3067 if ($numlines > 0) {
3068 print dolGetButtonAction('', $langs->trans("Create"), 'default', $arrayforbutaction, $object->id, 1, $actionButtonsParameters);
3069 } else {
3070 print dolGetButtonAction($langs->trans("ErrorObjectMustHaveLinesToBeValidated", $object->ref), $langs->trans("Create"), 'default', $arrayforbutaction, $object->id, 0, $actionButtonsParameters);
3071 }
3072
3073 // Set to shipped
3074 if (($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS) && $usercanclose) {
3075 print dolGetButtonAction('', $langs->trans('ClassifyShipped'), 'default', $_SERVER["PHP_SELF"].'?action=shipped&amp;token='.newToken().'&amp;id='.$object->id, '');
3076 }
3077
3078 // Set billed or unbilled
3079 // Note: Even if module invoice is not enabled, we should be able to use button "Classified billed"
3080 if ($object->statut > Commande::STATUS_DRAFT && !$object->billed && $object->total_ttc >= 0) {
3081 if ($usercancreate && $object->statut >= Commande::STATUS_VALIDATED && !getDolGlobalString('ORDER_DISABLE_CLASSIFY_BILLED_FROM_ORDER') && !getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT')) {
3082 print dolGetButtonAction('', $langs->trans('ClassifyBilled'), 'default', $_SERVER["PHP_SELF"].'?action=classifybilled&amp;token='.newToken().'&amp;id='.$object->id, '');
3083 }
3084 }
3085 if ($object->statut > Commande::STATUS_DRAFT && $object->billed) {
3086 if ($usercancreate && $object->statut >= Commande::STATUS_VALIDATED && !getDolGlobalString('ORDER_DISABLE_CLASSIFY_BILLED_FROM_ORDER') && !getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT')) {
3087 print dolGetButtonAction('', $langs->trans('ClassifyUnBilled'), 'delete', $_SERVER["PHP_SELF"].'?action=classifyunbilled&amp;token='.newToken().'&amp;id='.$object->id, '');
3088 }
3089 }
3090
3091 // Clone
3092 if ($usercancreate) {
3093 print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id.'&socid='.$object->socid, '');
3094 }
3095
3096 // Cancel order
3097 if ($object->statut == Commande::STATUS_VALIDATED && !empty($usercancancel)) {
3098 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'">'.$langs->trans("CancelOrder").'</a>';
3099 }
3100
3101 // Delete order
3102 if ($usercandelete) {
3103 if ($numshipping == 0) {
3104 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
3105 } else {
3106 print dolGetButtonAction($langs->trans('ShippingExist'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
3107 }
3108 }
3109 }
3110 print '</div>';
3111 }
3112
3113 // Select mail models is same action as presend
3114 if (GETPOST('modelselected')) {
3115 $action = 'presend';
3116 }
3117
3118 if ($action != 'presend') {
3119 print '<div class="fichecenter"><div class="fichehalfleft">';
3120 print '<a name="builddoc"></a>'; // ancre
3121 // Documents
3122 $objref = dol_sanitizeFileName($object->ref);
3123 $relativepath = $objref.'/'.$objref.'.pdf';
3124 $filedir = $conf->commande->multidir_output[$object->entity].'/'.$objref;
3125 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
3126 $genallowed = $usercanread;
3127 $delallowed = $usercancreate;
3128 print $formfile->showdocuments('commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object);
3129
3130
3131 // Show links to link elements
3132 $linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
3133
3134 $compatibleImportElementsList = false;
3135 if ($usercancreate
3136 && $object->statut == Commande::STATUS_DRAFT) {
3137 $compatibleImportElementsList = array('commande', 'propal', 'facture'); // import from linked elements
3138 }
3139 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
3140
3141 // Show online payment link
3142 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
3143 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
3144 $validpaymentmethod = getValidOnlinePaymentMethods('');
3145 $useonlinepayment = count($validpaymentmethod);
3146
3147 if (getDolGlobalString('ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER')) {
3148 $useonlinepayment = 0;
3149 }
3150 if ($object->statut != Commande::STATUS_DRAFT && $useonlinepayment) {
3151 print '<br><!-- Link to pay -->';
3152 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
3153 print showOnlinePaymentUrl('order', $object->ref).'<br>';
3154 }
3155
3156 print '</div><div class="fichehalfright">';
3157
3158 $MAXEVENT = 10;
3159
3160 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/commande/agenda.php?id='.$object->id);
3161
3162 // List of actions on element
3163 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
3164 $formactions = new FormActions($db);
3165 $somethingshown = $formactions->showactions($object, 'order', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
3166
3167 print '</div></div>';
3168 }
3169
3170 // Presend form
3171 $modelmail = 'order_send';
3172 $defaulttopic = 'SendOrderRef';
3173 $diroutput = getMultidirOutput($object);
3174 $trackid = 'ord'.$object->id;
3175
3176 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3177 }
3178}
3179
3180// End of page
3181llxFooter();
3182$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage customers orders.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_CLOSED
Closed (Sent, billed or not)
const STATUS_CANCELED
Canceled status.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
static createDepositFromOrigin(CommonObject $origin, $date, $payment_terms_id, User $user, $notrigger=0, $autoValidateDeposit=false, $overrideFields=array())
Creates a deposit from a proposal or an order by grouping lines by VAT rates.
const TYPE_DEPOSIT
Deposit invoice.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage HTML output components for orders Before adding component here, check they are not in...
Class with static methods for building HTML components related to products Only components common to ...
Class to manage building of HTML components.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage the table of subscription to notifications.
Class ProductCombination Used to represent the relation between a product and one of its variants.
File of class to manage predefined price products or services by customer.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
llxFooter()
Footer empty.
Definition document.php:107
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
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.
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.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files,...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
commande_prepare_head(Commande $object)
Prepare array with list of tabs.
Definition order.lib.php:34
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.