dolibarr 20.0.0
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 technical object to manage hooks of page. Note that conf->hooks_modules contains 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') && $usercancreate) {
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' && $usercancreate) {
1515 $object->oldcopy = dol_clone($object, 2);
1516
1517 // Fill array 'array_options' with data from update form
1518 $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
1519 if ($ret < 0) {
1520 $error++;
1521 }
1522
1523 if (!$error) {
1524 // Actions on extra fields
1525 $result = $object->insertExtraFields('ORDER_MODIFY');
1526 if ($result < 0) {
1527 setEventMessages($object->error, $object->errors, 'errors');
1528 $error++;
1529 }
1530 }
1531
1532 if ($error) {
1533 $action = 'edit_extras';
1534 }
1535 }
1536
1537 // add lines from objectlinked
1538 if ($action == 'import_lines_from_object'
1539 && $usercancreate
1540 && $object->statut == Commande::STATUS_DRAFT
1541 ) {
1542 $fromElement = GETPOST('fromelement');
1543 $fromElementid = GETPOST('fromelementid');
1544 $importLines = GETPOST('line_checkbox');
1545
1546 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1547 if ($fromElement == 'commande') {
1548 dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php');
1549 $lineClassName = 'OrderLine';
1550 } elseif ($fromElement == 'propal') {
1551 dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php');
1552 $lineClassName = 'PropaleLigne';
1553 } elseif ($fromElement == 'facture') {
1554 dol_include_once('/compta/'.$fromElement.'/class/'.$fromElement.'.class.php');
1555 $lineClassName = 'FactureLigne';
1556 }
1557 $nextRang = count($object->lines) + 1;
1558 $importCount = 0;
1559 $error = 0;
1560 foreach ($importLines as $lineId) {
1561 $lineId = intval($lineId);
1562 $originLine = new $lineClassName($db);
1563 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1564 $originLine->fetch_optionals();
1565 $desc = $originLine->desc;
1566 $pu_ht = $originLine->subprice;
1567 $qty = $originLine->qty;
1568 $txtva = $originLine->tva_tx;
1569 $txlocaltax1 = $originLine->localtax1_tx;
1570 $txlocaltax2 = $originLine->localtax2_tx;
1571 $fk_product = $originLine->fk_product;
1572 $remise_percent = $originLine->remise_percent;
1573 $date_start = $originLine->date_start;
1574 $date_end = $originLine->date_end;
1575 $fk_code_ventilation = 0;
1576 $info_bits = $originLine->info_bits;
1577 $fk_remise_except = $originLine->fk_remise_except;
1578 $price_base_type = 'HT';
1579 $pu_ttc = 0;
1580 $type = $originLine->product_type;
1581 $rang = $nextRang++;
1582 $special_code = $originLine->special_code;
1583 $origin = $originLine->element;
1584 $origin_id = $originLine->id;
1585 $fk_parent_line = 0;
1586 $fk_fournprice = $originLine->fk_fournprice;
1587 $pa_ht = $originLine->pa_ht;
1588 $label = $originLine->label;
1589 $array_options = $originLine->array_options;
1590 $situation_percent = 100;
1591 $fk_prev_id = '';
1592 $fk_unit = $originLine->fk_unit;
1593 $pu_ht_devise = $originLine->multicurrency_subprice;
1594
1595 $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);
1596
1597 if ($res > 0) {
1598 $importCount++;
1599 } else {
1600 $error++;
1601 }
1602 } else {
1603 $error++;
1604 }
1605 }
1606
1607 if ($error) {
1608 setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors');
1609 }
1610 }
1611 }
1612
1613 // Actions when printing a doc from card
1614 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
1615
1616 // Actions to build doc
1617 $upload_dir = !empty($conf->commande->multidir_output[$object->entity]) ? $conf->commande->multidir_output[$object->entity] : $conf->commande->dir_output;
1618 $permissiontoadd = $usercancreate;
1619 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1620
1621 // Actions to send emails
1622 $triggersendname = 'ORDER_SENTBYMAIL';
1623 $paramname = 'id';
1624 $autocopy = 'MAIN_MAIL_AUTOCOPY_ORDER_TO'; // used to know the automatic BCC to add
1625 $trackid = 'ord'.$object->id;
1626 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1627
1628
1629 if (!$error && getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $usercancreate) {
1630 if ($action == 'addcontact' && $usercancreate) {
1631 if ($object->id > 0) {
1632 $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
1633 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
1634 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
1635 }
1636
1637 if ($result >= 0) {
1638 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1639 exit();
1640 } else {
1641 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1642 $langs->load("errors");
1643 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
1644 } else {
1645 setEventMessages($object->error, $object->errors, 'errors');
1646 }
1647 }
1648 } elseif ($action == 'swapstatut' && $usercancreate) {
1649 // bascule du statut d'un contact
1650 if ($object->id > 0) {
1651 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
1652 } else {
1653 dol_print_error($db);
1654 }
1655 } elseif ($action == 'deletecontact' && $usercancreate) {
1656 // Efface un contact
1657 $result = $object->delete_contact($lineid);
1658
1659 if ($result >= 0) {
1660 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1661 exit();
1662 } else {
1663 dol_print_error($db);
1664 }
1665 }
1666 }
1667}
1668
1669
1670/*
1671 * View
1672 */
1673
1674$title = $object->ref." - ".$langs->trans('Card');
1675if ($action == 'create') {
1676 $title = $langs->trans("NewOrder");
1677}
1678$help_url = 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1679
1680llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-order page-card');
1681
1682$form = new Form($db);
1683$formfile = new FormFile($db);
1684$formorder = new FormOrder($db);
1685$formmargin = new FormMargin($db);
1686if (isModEnabled('project')) {
1687 $formproject = new FormProjets($db);
1688}
1689
1690// Mode creation
1691if ($action == 'create' && $usercancreate) {
1692 print load_fiche_titre($langs->trans('CreateOrder'), '', 'order');
1693
1694 $soc = new Societe($db);
1695 if ($socid > 0) {
1696 $res = $soc->fetch($socid);
1697 }
1698
1699 //$remise_absolue = 0;
1700
1701 $currency_code = $conf->currency;
1702
1703 $cond_reglement_id = GETPOSTINT('cond_reglement_id');
1704 $deposit_percent = GETPOSTFLOAT('cond_reglement_id_deposit_percent');
1705 $mode_reglement_id = GETPOSTINT('mode_reglement_id');
1706 $fk_account = GETPOSTINT('fk_account');
1707
1708 if (!empty($origin) && !empty($originid)) {
1709 // Parse element/subelement (ex: project_task)
1710 $element = $subelement = $origin;
1711 $regs = array();
1712 if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1713 $element = $regs[1];
1714 $subelement = $regs[2];
1715 }
1716
1717 if ($element == 'project') {
1718 $projectid = $originid;
1719
1720 if (!$cond_reglement_id) {
1721 $cond_reglement_id = $soc->cond_reglement_id;
1722 }
1723 if (!$deposit_percent) {
1724 $deposit_percent = $soc->deposit_percent;
1725 }
1726 if (!$mode_reglement_id) {
1727 $mode_reglement_id = $soc->mode_reglement_id;
1728 }
1729 if (!$remise_percent) {
1730 $remise_percent = $soc->remise_percent;
1731 }
1732 /*if (!$dateorder) {
1733 // Do not set 0 here (0 for a date is 1970)
1734 $dateorder = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 : '') : $dateorder);
1735 }*/
1736 } else {
1737 // For compatibility
1738 if ($element == 'order' || $element == 'commande') {
1739 $element = $subelement = 'commande';
1740 } elseif ($element == 'propal') {
1741 $element = 'comm/propal';
1742 $subelement = 'propal';
1743 } elseif ($element == 'contract') {
1744 $element = $subelement = 'contrat';
1745 }
1746
1747 dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1748
1749 $classname = ucfirst($subelement);
1750 $objectsrc = new $classname($db);
1751 $objectsrc->fetch($originid);
1752 if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1753 $objectsrc->fetch_lines();
1754 }
1755 $objectsrc->fetch_thirdparty();
1756
1757 // Replicate extrafields
1758 $objectsrc->fetch_optionals();
1759 $object->array_options = $objectsrc->array_options;
1760
1761 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
1762 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
1763
1764 $soc = $objectsrc->thirdparty;
1765 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1766 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : null));
1767 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1768 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1769 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1770 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1771 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1772 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1773 //$remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1774 //$remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1775 $dateorder = !getDolGlobalString('MAIN_AUTOFILL_DATE_ORDER') ? -1 : '';
1776
1777 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date : '');
1778
1779 if (isModEnabled("multicurrency")) {
1780 if (!empty($objectsrc->multicurrency_code)) {
1781 $currency_code = $objectsrc->multicurrency_code;
1782 }
1783 if (getDolGlobalString('MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1784 $currency_tx = $objectsrc->multicurrency_tx;
1785 }
1786 }
1787
1788 $note_private = $object->getDefaultCreateValueFor('note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1789 $note_public = $object->getDefaultCreateValueFor('note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1790
1791 // Object source contacts list
1792 $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
1793 }
1794 } else {
1795 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
1796 $deposit_percent = empty($soc->deposit_percent) ? $deposit_percent : $soc->deposit_percent;
1797 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
1798 $fk_account = empty($soc->mode_reglement_id) ? $fk_account : $soc->fk_account;
1799 $availability_id = 0;
1800 $shipping_method_id = $soc->shipping_method_id;
1801 $warehouse_id = $soc->fk_warehouse;
1802 $demand_reason_id = $soc->demand_reason_id;
1803 //$remise_percent = $soc->remise_percent;
1804 //$remise_absolue = 0;
1805 $dateorder = !getDolGlobalString('MAIN_AUTOFILL_DATE_ORDER') ? -1 : '';
1806
1807 if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) {
1808 $currency_code = $soc->multicurrency_code;
1809 }
1810
1811 $note_private = $object->getDefaultCreateValueFor('note_private');
1812 $note_public = $object->getDefaultCreateValueFor('note_public');
1813 }
1814
1815 // If form was posted (but error returned), we must reuse the value posted in priority (standard Dolibarr behaviour)
1816 if (!GETPOST('changecompany')) {
1817 if (GETPOSTISSET('cond_reglement_id')) {
1818 $cond_reglement_id = GETPOSTINT('cond_reglement_id');
1819 }
1820 if (GETPOSTISSET('deposit_percent')) {
1821 $deposit_percent = GETPOSTFLOAT('deposit_percent');
1822 }
1823 if (GETPOSTISSET('mode_reglement_id')) {
1824 $mode_reglement_id = GETPOSTINT('mode_reglement_id');
1825 }
1826 if (GETPOSTISSET('cond_reglement_id')) {
1827 $fk_account = GETPOSTINT('fk_account');
1828 }
1829 }
1830
1831 // Warehouse default if null
1832 if ($soc->fk_warehouse > 0) {
1833 $warehouse_id = $soc->fk_warehouse;
1834 }
1835 if (isModEnabled('stock') && empty($warehouse_id) && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1836 if (empty($object->warehouse_id) && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE')) {
1837 $warehouse_id = getDolGlobalString('MAIN_DEFAULT_WAREHOUSE');
1838 }
1839 if (empty($object->warehouse_id) && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE_USER') && !empty($user->warehouse_id)) {
1840 $warehouse_id = $user->fk_warehouse;
1841 }
1842 }
1843
1844 print '<form name="crea_commande" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1845 print '<input type="hidden" name="token" value="'.newToken().'">';
1846 print '<input type="hidden" name="action" value="add">';
1847 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
1848 print '<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.'">';
1849 print '<input type="hidden" name="origin" value="'.$origin.'">';
1850 print '<input type="hidden" name="originid" value="'.$originid.'">';
1851 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1852 if (!empty($currency_tx)) {
1853 print '<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.'">';
1854 }
1855
1856 print dol_get_fiche_head('');
1857
1858 // Call Hook tabContentCreateOrder
1859 $parameters = array();
1860 // Note that $action and $object may be modified by hook
1861 $reshook = $hookmanager->executeHooks('tabContentCreateOrder', $parameters, $object, $action);
1862 if (empty($reshook)) {
1863 print '<table class="border centpercent">';
1864
1865 // Reference
1866 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>';
1867
1868 // Reference client
1869 print '<tr><td>'.$langs->trans('RefCustomer').'</td><td>';
1870 if (getDolGlobalString('MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER') && !empty($origin) && !empty($originid)) {
1871 print '<input type="text" name="ref_client" value="'.$ref_client.'"></td>';
1872 } else {
1873 print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'"></td>';
1874 }
1875 print '</tr>';
1876
1877 // Thirdparty
1878 print '<tr>';
1879 print '<td class="fieldrequired">'.$langs->trans('Customer').'</td>';
1880 if ($socid > 0) {
1881 print '<td>';
1882 print $soc->getNomUrl(1, 'customer');
1883 print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1884 print '</td>';
1885 } else {
1886 print '<td class="valuefieldcreate">';
1887 $filter = '((s.client:IN:1,2,3) AND (s.status:=:1))';
1888 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company('', 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth175 maxwidth500 widthcentpercentminusxx');
1889 // reload page to retrieve customer information
1890 if (!getDolGlobalString('RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED')) {
1891 print '<script>
1892 $(document).ready(function() {
1893 $("#socid").change(function() {
1894 console.log("We have changed the company - Reload page");
1895 var socid = $(this).val();
1896 // reload page
1897 $("input[name=action]").val("create");
1898 $("input[name=changecompany]").val("1");
1899 $("form[name=crea_commande]").submit();
1900 });
1901 });
1902 </script>';
1903 }
1904 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>';
1905 print '</td>';
1906 }
1907 print '</tr>'."\n";
1908
1909 // Contact of order
1910 if ($socid > 0) {
1911 // Contacts (ask contact only if thirdparty already defined).
1912 print "<tr><td>".$langs->trans("DefaultContact").'</td><td>';
1913 print img_picto('', 'contact', 'class="pictofixedwidth"');
1914 //print $form->selectcontacts($soc->id, $contactid, 'contactid', 1, empty($srccontactslist) ? "" : $srccontactslist, '', 1, 'maxwidth300 widthcentpercentminusx');
1915 print $form->select_contact($soc->id, $contactid, 'contactid', 1, empty($srccontactslist) ? "" : $srccontactslist, '', 1, 'maxwidth300 widthcentpercentminusx', true);
1916 print '</td></tr>';
1917
1918 // Ligne info remises tiers
1919 print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
1920
1921 $absolute_discount = $soc->getAvailableDiscounts();
1922
1923 $thirdparty = $soc;
1924 $discount_type = 0;
1925 $backtopage = $_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.urlencode((string) (GETPOST('origin'))).'&originid='.urlencode((string) (GETPOSTINT('originid')));
1926 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1927
1928 print '</td></tr>';
1929 }
1930
1931 // Date
1932 print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td>';
1933 print img_picto('', 'action', 'class="pictofixedwidth"');
1934 print $form->selectDate('', 're', 0, 0, 0, "crea_commande", 1, 1); // Always autofill date with current date
1935 print '</td></tr>';
1936
1937 // Date delivery planned
1938 print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
1939 print '<td colspan="3">';
1940 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date);
1941 print img_picto('', 'action', 'class="pictofixedwidth"');
1942 print $form->selectDate($date_delivery ? $date_delivery : -1, 'liv_', 1, 1, 1);
1943 print "</td>\n";
1944 print '</tr>';
1945
1946 // Delivery delay
1947 print '<tr class="fielddeliverydelay"><td>'.$langs->trans('AvailabilityPeriod').'</td><td>';
1948 print img_picto('', 'clock', 'class="pictofixedwidth"');
1949 $form->selectAvailabilityDelay((GETPOSTISSET('availability_id') ? GETPOST('availability_id') : $availability_id), 'availability_id', '', 1, 'maxwidth200 widthcentpercentminusx');
1950 print '</td></tr>';
1951
1952 // Terms of payment
1953 print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
1954 print img_picto('', 'payment', 'class="pictofixedwidth"');
1955 print $form->getSelectConditionsPaiements($cond_reglement_id, 'cond_reglement_id', 1, 1, 0, 'maxwidth200 widthcentpercentminusx', $deposit_percent);
1956 print '</td></tr>';
1957
1958 // Payment mode
1959 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>';
1960 print img_picto('', 'bank', 'class="pictofixedwidth"');
1961 print $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1);
1962 print '</td></tr>';
1963
1964 // Bank Account
1965 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled("bank")) {
1966 print '<tr><td>'.$langs->trans('BankAccount').'</td><td>';
1967 print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes($fk_account, 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1);
1968 print '</td></tr>';
1969 }
1970
1971 // Shipping Method
1972 if (isModEnabled('shipping')) {
1973 print '<tr><td>'.$langs->trans('SendingMethod').'</td><td>';
1974 print img_picto('', 'object_dolly', 'class="pictofixedwidth"');
1975 $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');
1976 print '</td></tr>';
1977 }
1978
1979 // Warehouse
1980 if (isModEnabled('stock') && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1981 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1982 $formproduct = new FormProduct($db);
1983 print '<tr><td>'.$langs->trans('Warehouse').'</td><td>';
1984 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');
1985 print '</td></tr>';
1986 }
1987
1988 // Source / Channel - What trigger creation
1989 print '<tr><td>'.$langs->trans('Source').'</td><td>';
1990 print img_picto('', 'question', 'class="pictofixedwidth"');
1991 $form->selectInputReason((GETPOSTISSET('demand_reason_id') ? GETPOST('demand_reason_id') : $demand_reason_id), 'demand_reason_id', '', 1, 'maxwidth200 widthcentpercentminusx');
1992 print '</td></tr>';
1993
1994 // TODO How record was recorded OrderMode (llx_c_input_method)
1995
1996 // Project
1997 if (isModEnabled('project')) {
1998 $langs->load("projects");
1999 print '<tr>';
2000 print '<td>'.$langs->trans("Project").'</td><td>';
2001 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');
2002 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>';
2003 print '</td>';
2004 print '</tr>';
2005 }
2006
2007 // Incoterms
2008 if (isModEnabled('incoterm')) {
2009 print '<tr>';
2010 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).'</label></td>';
2011 print '<td class="maxwidthonsmartphone">';
2012 $incoterm_id = GETPOST('incoterm_id');
2013 $location_incoterms = GETPOST('location_incoterms');
2014 if (empty($incoterm_id)) {
2015 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
2016 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
2017 }
2018 print img_picto('', 'incoterm', 'class="pictofixedwidth"');
2019 print $form->select_incoterms($incoterm_id, $location_incoterms);
2020 print '</td></tr>';
2021 }
2022
2023 // Other attributes
2024 $parameters = array();
2025 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2026 $parameters['objectsrc'] = $objectsrc;
2027 }
2028 $parameters['socid'] = $socid;
2029
2030 // Note that $action and $object may be modified by hook
2031 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
2032 print $hookmanager->resPrint;
2033 if (empty($reshook)) {
2034 if (getDolGlobalString('THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER') && !empty($soc->id)) {
2035 // copy from thirdparty
2036 $tpExtrafields = new ExtraFields($db);
2037 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
2038 if ($soc->fetch_optionals() > 0) {
2039 $object->array_options = array_merge($object->array_options, $soc->array_options);
2040 }
2041 }
2042
2043 print $object->showOptionals($extrafields, 'create', $parameters);
2044 }
2045
2046 // Template to use by default
2047 print '<tr><td>'.$langs->trans('DefaultModel').'</td>';
2048 print '<td>';
2049 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
2051 $preselected = getDolGlobalString('COMMANDE_ADDON_PDF');
2052 print img_picto('', 'pdf', 'class="pictofixedwidth"');
2053 print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1);
2054 print "</td></tr>";
2055
2056 // Multicurrency
2057 if (isModEnabled("multicurrency")) {
2058 print '<tr>';
2059 print '<td>'.$form->editfieldkey("Currency", 'multicurrency_code', '', $object, 0).'</td>';
2060 print '<td class="maxwidthonsmartphone">';
2061 print img_picto('', 'currency', 'class="pictofixedwidth"').$form->selectMultiCurrency(((GETPOSTISSET('multicurrency_code') && !GETPOST('changecompany')) ? GETPOST('multicurrency_code') : $currency_code), 'multicurrency_code', 0, '', false, 'maxwidth200 widthcentpercentminusx');
2062 print '</td></tr>';
2063 }
2064
2065 // Note public
2066 print '<tr>';
2067 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
2068 print '<td>';
2069
2070 $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
2071 print $doleditor->Create(1);
2072 // print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
2073 print '</td></tr>';
2074
2075 // Note private
2076 if (empty($user->socid)) {
2077 print '<tr>';
2078 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
2079 print '<td>';
2080
2081 $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
2082 print $doleditor->Create(1);
2083 // print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
2084 print '</td></tr>';
2085 }
2086
2087 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2088 // TODO for compatibility
2089 if ($origin == 'contrat') {
2090 // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
2091 //$objectsrc->remise_absolue = $remise_absolue;
2092 //$objectsrc->remise_percent = $remise_percent;
2093 $objectsrc->update_price(1);
2094 }
2095
2096 print "\n<!-- ".$classname." info -->";
2097 print "\n";
2098 print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
2099 print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
2100 print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
2101 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
2102 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
2103
2104 switch ($classname) {
2105 case 'Propal':
2106 $newclassname = 'CommercialProposal';
2107 break;
2108 case 'Commande':
2109 $newclassname = 'Order';
2110 break;
2111 case 'Expedition':
2112 $newclassname = 'Sending';
2113 break;
2114 case 'Contrat':
2115 $newclassname = 'Contract';
2116 break;
2117 default:
2118 $newclassname = $classname;
2119 }
2120
2121 print '<tr><td>'.$langs->trans($newclassname).'</td><td>'.$objectsrc->getNomUrl(1).'</td></tr>';
2122
2123 // Amount
2124 print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($objectsrc->total_ht).'</td></tr>';
2125 print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($objectsrc->total_tva)."</td></tr>";
2126 if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1 RE
2127 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax1)."</td></tr>";
2128 }
2129
2130 if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2 IRPF
2131 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax2)."</td></tr>";
2132 }
2133
2134 print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($objectsrc->total_ttc)."</td></tr>";
2135
2136 if (isModEnabled("multicurrency")) {
2137 print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td>'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
2138 print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td>'.price($objectsrc->multicurrency_total_tva)."</td></tr>";
2139 print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td>'.price($objectsrc->multicurrency_total_ttc)."</td></tr>";
2140 }
2141 }
2142
2143 print "\n";
2144
2145 print '</table>';
2146 }
2147
2148 print dol_get_fiche_end();
2149
2150 print $form->buttonsSaveCancel("CreateDraft");
2151
2152 // Show origin lines
2153 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2154 $title = $langs->trans('ProductsAndServices');
2155 print load_fiche_titre($title);
2156
2157 print '<div class="div-table-responsive-no-min">';
2158 print '<table class="noborder centpercent">';
2159
2160 $objectsrc->printOriginLinesList('', $selectedLines);
2161
2162 print '</table>';
2163 print '</div>';
2164 }
2165
2166 print '</form>';
2167} else {
2168 // Mode view
2169 $now = dol_now();
2170
2171 if ($object->id > 0) {
2172 $product_static = new Product($db);
2173
2174 $soc = new Societe($db);
2175 $soc->fetch($object->socid);
2176
2177 $author = new User($db);
2178 $author->fetch($object->user_author_id);
2179
2180 $object->fetch_thirdparty();
2181 $res = $object->fetch_optionals();
2182
2184 print dol_get_fiche_head($head, 'order', $langs->trans("CustomerOrder"), -1, 'order');
2185
2186 $formconfirm = '';
2187
2188 // Confirmation to delete
2189 if ($action == 'delete') {
2190 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
2191 }
2192
2193 // Confirmation of validation
2194 if ($action == 'validate') {
2195 // We check that object has a temporary ref
2196 $ref = substr($object->ref, 1, 4);
2197 if ($ref == 'PROV' || $ref == '') {
2198 $numref = $object->getNextNumRef($soc);
2199 if (empty($numref)) {
2200 $error++;
2201 setEventMessages($object->error, $object->errors, 'errors');
2202 }
2203 } else {
2204 $numref = $object->ref;
2205 }
2206
2207 $text = $langs->trans('ConfirmValidateOrder', $numref);
2208 if (isModEnabled('notification')) {
2209 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
2210 $notify = new Notify($db);
2211 $text .= '<br>';
2212 $text .= $notify->confirmMessage('ORDER_VALIDATE', $object->socid, $object);
2213 }
2214
2215 $qualified_for_stock_change = 0;
2216 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2217 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2218 } else {
2219 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2220 }
2221
2222 $formquestion = array();
2223 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2224 $langs->load("stocks");
2225 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2226 $formproduct = new FormProduct($db);
2227 $forcecombo = 0;
2228 if ($conf->browser->name == 'ie') {
2229 $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
2230 }
2231 $formquestion = array(
2232 // 'text' => $langs->trans("ConfirmClone"),
2233 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
2234 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
2235 array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOSTINT('idwarehouse') ? GETPOSTINT('idwarehouse') : 'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
2236 );
2237 }
2238
2239 // mandatoryPeriod
2240 $nbMandated = 0;
2241 foreach ($object->lines as $line) {
2242 $res = $line->fetch_product();
2243 if ($res > 0) {
2244 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
2245 $nbMandated++;
2246 break;
2247 }
2248 }
2249 }
2250 if ($nbMandated > 0) {
2251 if (getDolGlobalString('SERVICE_STRICT_MANDATORY_PERIOD')) {
2252 setEventMessages($langs->trans("mandatoryPeriodNeedTobeSetMsgValidate"), null, 'errors');
2253 $error++;
2254 } else {
2255 $text .= '<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'</span></div>';
2256 }
2257 }
2258
2259 if (getDolGlobalInt('SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2260 // This is a hidden option:
2261 // Suggestion to create invoice during order validation is not enabled by default.
2262 // Such choice should be managed by the workflow module and trigger. This option generates conflicts with some setup.
2263 // It may also break step of creating an order when invoicing must be done from proposals and not from orders
2264 $deposit_percent_from_payment_terms = (float) getDictionaryValue('c_payment_term', 'deposit_percent', $object->cond_reglement_id);
2265
2266 if (!empty($deposit_percent_from_payment_terms) && isModEnabled('invoice') && $user->hasRight('facture', 'creer')) {
2267 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
2268
2269 $object->fetchObjectLinked();
2270
2271 $eligibleForDepositGeneration = true;
2272
2273 if (array_key_exists('facture', $object->linkedObjects)) {
2274 foreach ($object->linkedObjects['facture'] as $invoice) {
2275 if ($invoice->type == Facture::TYPE_DEPOSIT) {
2276 $eligibleForDepositGeneration = false;
2277 break;
2278 }
2279 }
2280 }
2281
2282 if ($eligibleForDepositGeneration && array_key_exists('propal', $object->linkedObjects)) {
2283 foreach ($object->linkedObjects['propal'] as $proposal) {
2284 $proposal->fetchObjectLinked();
2285
2286 if (array_key_exists('facture', $proposal->linkedObjects)) {
2287 foreach ($proposal->linkedObjects['facture'] as $invoice) {
2288 if ($invoice->type == Facture::TYPE_DEPOSIT) {
2289 $eligibleForDepositGeneration = false;
2290 break 2;
2291 }
2292 }
2293 }
2294 }
2295 }
2296
2297 if ($eligibleForDepositGeneration) {
2298 $formquestion[] = array(
2299 'type' => 'checkbox',
2300 'tdclass' => '',
2301 'name' => 'generate_deposit',
2302 'label' => $form->textwithpicto($langs->trans('GenerateDeposit', $object->deposit_percent), $langs->trans('DepositGenerationPermittedByThePaymentTermsSelected'))
2303 );
2304
2305 $formquestion[] = array(
2306 'type' => 'date',
2307 'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
2308 'name' => 'datef',
2309 'label' => $langs->trans('DateInvoice'),
2310 'value' => dol_now(),
2311 'datenow' => true
2312 );
2313
2314 if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
2315 $formquestion[] = array(
2316 'type' => 'date',
2317 'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
2318 'name' => 'date_pointoftax',
2319 'label' => $langs->trans('DatePointOfTax'),
2320 'value' => dol_now(),
2321 'datenow' => true
2322 );
2323 }
2324
2325
2326 $paymentTermsSelect = $form->getSelectConditionsPaiements(0, 'cond_reglement_id', -1, 0, 0, 'minwidth200');
2327
2328 $formquestion[] = array(
2329 'type' => 'other',
2330 'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
2331 'name' => 'cond_reglement_id',
2332 'label' => $langs->trans('PaymentTerm'),
2333 'value' => $paymentTermsSelect
2334 );
2335
2336 $formquestion[] = array(
2337 'type' => 'checkbox',
2338 'tdclass' => 'showonlyifgeneratedeposit',
2339 'name' => 'validate_generated_deposit',
2340 'label' => $langs->trans('ValidateGeneratedDeposit')
2341 );
2342
2343 $formquestion[] = array(
2344 'type' => 'onecolumn',
2345 'value' => '
2346 <script>
2347 $(document).ready(function() {
2348 $("[name=generate_deposit]").change(function () {
2349 let $self = $(this);
2350 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2351
2352 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2353 $target.show();
2354 } else {
2355 $target.hide();
2356 }
2357
2358 return true;
2359 });
2360 });
2361 </script>
2362 '
2363 );
2364 }
2365 }
2366 }
2367
2368 if (!$error) {
2369 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 240);
2370 }
2371 }
2372
2373 // Confirm back to draft status
2374 if ($action == 'modif') {
2375 $qualified_for_stock_change = 0;
2376 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2377 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2378 } else {
2379 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2380 }
2381
2382 $text = $langs->trans('ConfirmUnvalidateOrder', $object->ref);
2383 $formquestion = array();
2384 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2385 $langs->load("stocks");
2386 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2387 $formproduct = new FormProduct($db);
2388 $forcecombo = 0;
2389 if ($conf->browser->name == 'ie') {
2390 $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
2391 }
2392 $formquestion = array(
2393 // 'text' => $langs->trans("ConfirmClone"),
2394 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
2395 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
2396 array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse') ? GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
2397 );
2398 }
2399
2400 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnvalidateOrder'), $text, 'confirm_modif', $formquestion, "yes", 1, 220);
2401 }
2402
2403 /*
2404 * Confirmation de la cloture
2405 */
2406 if ($action == 'shipped') {
2407 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_shipped', '', 0, 1);
2408 }
2409
2410 /*
2411 * Confirmation de l'annulation
2412 */
2413 if ($action == 'cancel') {
2414 $qualified_for_stock_change = 0;
2415 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2416 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2417 } else {
2418 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2419 }
2420
2421 $text = $langs->trans('ConfirmCancelOrder', $object->ref);
2422 $formquestion = array();
2423 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2424 $langs->load("stocks");
2425 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2426 $formproduct = new FormProduct($db);
2427 $forcecombo = 0;
2428 if ($conf->browser->name == 'ie') {
2429 $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
2430 }
2431 $formquestion = array(
2432 // 'text' => $langs->trans("ConfirmClone"),
2433 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
2434 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
2435 array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse') ? GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
2436 );
2437 }
2438
2439 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("Cancel"), $text, 'confirm_cancel', $formquestion, 0, 1);
2440 }
2441
2442 // Confirmation to delete line
2443 if ($action == 'ask_deleteline') {
2444 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
2445 }
2446
2447 // Clone confirmation
2448 if ($action == 'clone') {
2449 $filter = '(s.client:IN:1,2,3)';
2450 // Create an array for form
2451 $formquestion = array(
2452 array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOSTINT('socid'), 'socid', $filter, '', 0, 0, null, 0, 'maxwidth300'))
2453 );
2454 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneOrder', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
2455 }
2456
2457 // Call Hook formConfirm
2458 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
2459 // Note that $action and $object may be modified by hook
2460 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action);
2461 if (empty($reshook)) {
2462 $formconfirm .= $hookmanager->resPrint;
2463 } elseif ($reshook > 0) {
2464 $formconfirm = $hookmanager->resPrint;
2465 }
2466
2467 // Print form confirm
2468 print $formconfirm;
2469
2470
2471 // Order card
2472
2473 $linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
2474
2475 $morehtmlref = '<div class="refidno">';
2476 // Ref customer
2477 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1);
2478 $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);
2479 // Thirdparty
2480 $morehtmlref .= '<br>'.$soc->getNomUrl(1, 'customer');
2481 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
2482 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
2483 }
2484 // Project
2485 if (isModEnabled('project')) {
2486 $langs->load("projects");
2487 $morehtmlref .= '<br>';
2488 if ($usercancreate) {
2489 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
2490 if ($action != 'classify') {
2491 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
2492 }
2493 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
2494 } else {
2495 if (!empty($object->fk_project)) {
2496 $proj = new Project($db);
2497 $proj->fetch($object->fk_project);
2498 $morehtmlref .= $proj->getNomUrl(1);
2499 if ($proj->title) {
2500 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
2501 }
2502 }
2503 }
2504 }
2505 $morehtmlref .= '</div>';
2506
2507
2508 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
2509
2510 // Call Hook tabContentViewOrder
2511 $parameters = array();
2512 // Note that $action and $object may be modified by hook
2513 $reshook = $hookmanager->executeHooks('tabContentViewOrder', $parameters, $object, $action);
2514 if (empty($reshook)) {
2515 print '<div class="fichecenter">';
2516 print '<div class="fichehalfleft">';
2517 print '<div class="underbanner clearboth"></div>';
2518
2519 print '<table class="border tableforfield centpercent">';
2520
2521 if ($soc->outstanding_limit) {
2522 // Outstanding Bill
2523 print '<tr><td class="titlefield">';
2524 print $langs->trans('OutstandingBill');
2525 print '</td><td class="valuefield">';
2526 $arrayoutstandingbills = $soc->getOutstandingBills();
2527 print price($arrayoutstandingbills['opened']).' / ';
2528 print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency);
2529 print '</td>';
2530 print '</tr>';
2531 }
2532
2533 // Relative and absolute discounts
2534 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
2535 $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
2536 $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
2537 } else {
2538 $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2539 $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2540 }
2541
2542 $addrelativediscount = '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("EditRelativeDiscounts").'</a>';
2543 $addabsolutediscount = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("EditGlobalDiscounts").'</a>';
2544 $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>';
2545
2546 print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td class="valuefield">';
2547
2548 $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
2549 $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
2550 $absolute_discount = price2num($absolute_discount, 'MT');
2551 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
2552
2553 $thirdparty = $soc;
2554 $discount_type = 0;
2555 $backtopage = $_SERVER["PHP_SELF"].'?id='.$object->id;
2556 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
2557
2558 print '</td></tr>';
2559
2560 // Date
2561 print '<tr><td>';
2562 $editenable = $usercancreate && $object->statut == Commande::STATUS_DRAFT;
2563 print $form->editfieldkey("Date", 'date', '', $object, $editenable);
2564 print '</td><td class="valuefield">';
2565 if ($action == 'editdate') {
2566 print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2567 print '<input type="hidden" name="token" value="'.newToken().'">';
2568 print '<input type="hidden" name="action" value="setdate">';
2569 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2570 print $form->selectDate($object->date, 'order_', 0, 0, 0, "setdate");
2571 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2572 print '</form>';
2573 } else {
2574 print $object->date ? dol_print_date($object->date, 'day') : '&nbsp;';
2575 if ($object->hasDelay() && empty($object->delivery_date)) { // If there is a delivery date planned, warning should be on this date
2576 print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");
2577 }
2578 }
2579 print '</td>';
2580 print '</tr>';
2581
2582 // Delivery date planned
2583 print '<tr><td>';
2584 $editenable = $usercancreate;
2585 print $form->editfieldkey("DateDeliveryPlanned", 'date_livraison', '', $object, $editenable);
2586 print '</td><td class="valuefield">';
2587 if ($action == 'editdate_livraison') {
2588 print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2589 print '<input type="hidden" name="token" value="'.newToken().'">';
2590 print '<input type="hidden" name="action" value="setdate_livraison">';
2591 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2592 print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 'liv_', 1, 1, 0, "setdate_livraison", 1, 0);
2593 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2594 print '</form>';
2595 } else {
2596 print $object->delivery_date ? dol_print_date($object->delivery_date, 'dayhour') : '&nbsp;';
2597 if ($object->hasDelay() && !empty($object->delivery_date)) {
2598 print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");
2599 }
2600 }
2601 print '</td>';
2602 print '</tr>';
2603
2604 // Delivery delay
2605 print '<tr class="fielddeliverydelay"><td>';
2606 $editenable = $usercancreate;
2607 print $form->editfieldkey("AvailabilityPeriod", 'availability', '', $object, $editenable);
2608 print '</td><td class="valuefield">';
2609 if ($action == 'editavailability') {
2610 $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1);
2611 } else {
2612 $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1);
2613 }
2614 print '</td></tr>';
2615
2616 // Shipping Method
2617 if (isModEnabled('shipping')) {
2618 print '<tr><td>';
2619 $editenable = $usercancreate;
2620 print $form->editfieldkey("SendingMethod", 'shippingmethod', '', $object, $editenable);
2621 print '</td><td class="valuefield">';
2622 if ($action == 'editshippingmethod') {
2623 $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
2624 } else {
2625 $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none');
2626 }
2627 print '</td>';
2628 print '</tr>';
2629 }
2630
2631 // Warehouse
2632 if (isModEnabled('stock') && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
2633 $langs->load('stocks');
2634 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2635 $formproduct = new FormProduct($db);
2636 print '<tr><td>';
2637 $editenable = $usercancreate;
2638 print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $editenable);
2639 print '</td><td class="valuefield">';
2640 if ($action == 'editwarehouse') {
2641 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1);
2642 } else {
2643 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none');
2644 }
2645 print '</td>';
2646 print '</tr>';
2647 }
2648
2649 // Source reason (why we have an order)
2650 print '<tr><td>';
2651 $editenable = $usercancreate;
2652 print $form->editfieldkey("Source", 'demandreason', '', $object, $editenable);
2653 print '</td><td class="valuefield">';
2654 if ($action == 'editdemandreason') {
2655 $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1);
2656 } else {
2657 $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none');
2658 }
2659 print '</td></tr>';
2660
2661 // Terms of payment
2662 print '<tr><td>';
2663 $editenable = $usercancreate;
2664 print $form->editfieldkey("PaymentConditionsShort", 'conditions', '', $object, $editenable);
2665 print '</td><td class="valuefield">';
2666 if ($action == 'editconditions') {
2667 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent);
2668 } else {
2669 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1, '', 1, $object->deposit_percent);
2670 }
2671 print '</td>';
2672
2673 print '</tr>';
2674
2675 // Mode of payment
2676 print '<tr><td>';
2677 $editenable = $usercancreate;
2678 print $form->editfieldkey("PaymentMode", 'mode', '', $object, $editenable);
2679 print '</td><td class="valuefield">';
2680 if ($action == 'editmode') {
2681 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
2682 } else {
2683 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
2684 }
2685 print '</td></tr>';
2686
2687 // Multicurrency
2688 if (isModEnabled("multicurrency")) {
2689 // Multicurrency code
2690 print '<tr>';
2691 print '<td>';
2692 $editenable = $usercancreate && $object->statut == Commande::STATUS_DRAFT;
2693 print $form->editfieldkey("Currency", 'multicurrencycode', '', $object, $editenable);
2694 print '</td><td class="valuefield">';
2695 if ($action == 'editmulticurrencycode') {
2696 $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
2697 } else {
2698 $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
2699 }
2700 print '</td></tr>';
2701
2702 // Multicurrency rate
2703 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2704 print '<tr>';
2705 print '<td>';
2706 $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT;
2707 print $form->editfieldkey("CurrencyRate", 'multicurrencyrate', '', $object, $editenable);
2708 print '</td><td class="valuefield">';
2709 if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
2710 if ($action == 'actualizemulticurrencyrate') {
2711 list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
2712 }
2713 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
2714 } else {
2715 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
2716 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2717 print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
2718 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
2719 print '</div>';
2720 }
2721 }
2722 print '</td></tr>';
2723 }
2724 }
2725
2726 // TODO Order mode (how we receive order). Not yet implemented
2727 /*
2728 print '<tr><td>';
2729 $editenable = $usercancreate;
2730 print $form->editfieldkey("SourceMode", 'inputmode', '', $object, $editenable);
2731 print '</td><td>';
2732 if ($action == 'editinputmode') {
2733 $form->formInputMode($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->source, 'input_mode_id', 1);
2734 } else {
2735 $form->formInputMode($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->source, 'none');
2736 }
2737 print '</td></tr>';
2738 */
2739
2740 $tmparray = $object->getTotalWeightVolume();
2741 $totalWeight = $tmparray['weight'];
2742 $totalVolume = $tmparray['volume'];
2743 if ($totalWeight) {
2744 print '<tr><td>'.$langs->trans("CalculatedWeight").'</td>';
2745 print '<td class="valuefield">';
2746 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');
2747 print '</td></tr>';
2748 }
2749 if ($totalVolume) {
2750 print '<tr><td>'.$langs->trans("CalculatedVolume").'</td>';
2751 print '<td class="valuefield">';
2752 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');
2753 print '</td></tr>';
2754 }
2755
2756 // TODO How record was recorded OrderMode (llx_c_input_method)
2757
2758 // Incoterms
2759 if (isModEnabled('incoterm')) {
2760 print '<tr><td>';
2761 $editenable = $usercancreate;
2762 print $form->editfieldkey("IncotermLabel", 'incoterm', '', $object, $editenable);
2763 print '</td>';
2764 print '<td class="valuefield">';
2765 if ($action != 'editincoterm') {
2766 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2767 } else {
2768 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
2769 }
2770 print '</td></tr>';
2771 }
2772
2773 // Bank Account
2774 if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled("bank")) {
2775 print '<tr><td>';
2776 $editenable = $usercancreate;
2777 print $form->editfieldkey("BankAccount", 'bankaccount', '', $object, $editenable);
2778 print '</td><td class="valuefield">';
2779 if ($action == 'editbankaccount') {
2780 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
2781 } else {
2782 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
2783 }
2784 print '</td>';
2785 print '</tr>';
2786 }
2787
2788 // Other attributes
2789 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2790
2791 print '</table>';
2792
2793 print '</div>';
2794 print '<div class="fichehalfright">';
2795 print '<div class="underbanner clearboth"></div>';
2796
2797 print '<table class="border tableforfield centpercent">';
2798
2799 $alert = '';
2800 if (getDolGlobalString('ORDER_MANAGE_MIN_AMOUNT') && $object->total_ht < $object->thirdparty->order_min_amount) {
2801 $alert = ' ' . img_warning($langs->trans('OrderMinAmount') . ': ' . price($object->thirdparty->order_min_amount));
2802 }
2803
2804 print '<tr>';
2805 print '<td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
2806 print '<td class="nowrap amountcard right">' . price($object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2807 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2808 // Multicurrency Amount HT
2809 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ht, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2810 }
2811 print '</tr>';
2812
2813 print '<tr>';
2814 print '<td class="titlefieldmiddle">' . $langs->trans('AmountVAT') . '</td>';
2815 print '<td class="nowrap amountcard right">' . price($object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2816 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2817 // Multicurrency Amount VAT
2818 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_tva, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2819 }
2820 print '</tr>';
2821
2822 // Amount Local Taxes
2823 if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) {
2824 print '<tr>';
2825 print '<td class="titlefieldmiddle">' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
2826 print '<td class="nowrap amountcard right">' . price($object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2827 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2828 $object->multicurrency_total_localtax1 = price2num($object->total_localtax1 * $object->multicurrency_tx, 'MT');
2829
2830 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2831 }
2832 print '</tr>';
2833 }
2834
2835 // Amount Local Taxes
2836 if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) {
2837 print '<tr>';
2838 print '<td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
2839 print '<td class="nowrap amountcard right">' . price($object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
2840 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2841 $object->multicurrency_total_localtax2 = price2num($object->total_localtax2 * $object->multicurrency_tx, 'MT');
2842
2843 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
2844 }
2845 print '</tr>';
2846 }
2847
2848 print '<tr>';
2849 print '<td>' . $langs->trans('AmountTTC') . '</td>';
2850 print '<td class="valuefield nowrap right amountcard">' . price($object->total_ttc, 1, '', 1, -1, -1, $conf->currency) . '</td>';
2851 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2852 // Multicurrency Amount TTC
2853 print '<td class="valuefield nowrap right amountcard">' . price($object->multicurrency_total_ttc, 1, '', 1, -1, -1, $object->multicurrency_code) . '</td>';
2854 }
2855 print '</tr>'."\n";
2856
2857 print '</table>';
2858
2859 // Statut
2860 //print '<tr><td>' . $langs->trans('Status') . '</td><td>' . $object->getLibStatut(4) . '</td></tr>';
2861
2862 // Margin Infos
2863 if (isModEnabled('margin')) {
2864 $formmargin->displayMarginInfos($object);
2865 }
2866
2867
2868 print '</div>';
2869 print '</div>'; // Close fichecenter
2870
2871 print '<div class="clearboth"></div><br>';
2872
2873 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
2874 $blocname = 'contacts';
2875 $title = $langs->trans('ContactsAddresses');
2876 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2877 }
2878
2879 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
2880 $blocname = 'notes';
2881 $title = $langs->trans('Notes');
2882 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2883 }
2884
2885 /*
2886 * Lines
2887 */
2888
2889 // Get object lines
2890 $result = $object->getLinesArray();
2891
2892 // Add products/services form
2893 //$forceall = 1;
2894 global $inputalsopricewithtax;
2895 $inputalsopricewithtax = 1;
2896
2897 print '<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">
2898 <input type="hidden" name="token" value="' . newToken().'">
2899 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
2900 <input type="hidden" name="mode" value="">
2901 <input type="hidden" name="page_y" value="">
2902 <input type="hidden" name="id" value="' . $object->id.'">
2903 <input type="hidden" name="backtopage" value="'.$backtopage.'">
2904 ';
2905
2906 if (!empty($conf->use_javascript_ajax) && $object->statut == Commande::STATUS_DRAFT) {
2907 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
2908 }
2909
2910 print '<div class="div-table-responsive-no-min">';
2911 print '<table id="tablelines" class="noborder noshadow" width="100%">';
2912
2913 // Show object lines
2914 if (!empty($object->lines)) {
2915 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2916 }
2917
2918 /*
2919 * Form to add new line
2920 */
2921 if ($object->statut == Commande::STATUS_DRAFT && $usercancreate && $action != 'selectlines') {
2922 if ($action != 'editline') {
2923 // Add free products/services
2924
2925 $parameters = array();
2926 // Note that $action and $object may be modified by hook
2927 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action);
2928 if ($reshook < 0) {
2929 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2930 }
2931 if (empty($reshook)) {
2932 $object->formAddObjectLine(1, $mysoc, $soc);
2933 }
2934 } else {
2935 $parameters = array();
2936 $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action);
2937 }
2938 }
2939 print '</table>';
2940 print '</div>';
2941
2942 print "</form>\n";
2943 }
2944
2945 print dol_get_fiche_end();
2946
2947 /*
2948 * Buttons for actions
2949 */
2950 if ($action != 'presend' && $action != 'editline') {
2951 print '<div class="tabsAction">';
2952
2953 $parameters = array();
2954 // Note that $action and $object may be modified by hook
2955 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
2956 if (empty($reshook)) {
2957 $numlines = count($object->lines);
2958
2959 // Reopen a closed order
2960 if (($object->statut == Commande::STATUS_CLOSED || $object->statut == Commande::STATUS_CANCELED) && $usercancreate && (!$object->billed || !getDolGlobalInt('ORDER_DONT_REOPEN_BILLED'))) {
2961 print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&amp;token='.newToken().'&amp;id='.$object->id, '');
2962 }
2963
2964 // Send
2965 if (empty($user->socid)) {
2966 if ($object->statut > Commande::STATUS_DRAFT || getDolGlobalString('COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS')) {
2967 if ($usercansend) {
2968 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');
2969 } else {
2970 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER['PHP_SELF']. '#', '', false);
2971 }
2972 }
2973 }
2974
2975 // Valid
2976 if ($object->statut == Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || getDolGlobalString('ORDER_ENABLE_NEGATIVE')) && $usercanvalidate) {
2977 if ($numlines > 0) {
2978 print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=validate&amp;token='.newToken().'&amp;id='.$object->id, $object->id, 1);
2979 } else {
2980 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);
2981 }
2982 }
2983 // Edit
2984 if ($object->statut == Commande::STATUS_VALIDATED && $usercancreate) {
2985 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=modif&amp;token='.newToken().'&amp;id='.$object->id, '');
2986 }
2987
2988 $arrayforbutaction = array();
2989 // Create a purchase order
2990
2991 if (!getDolGlobalInt('COMMANDE_DISABLE_ADD_PURCHASE_ORDER')) {
2992 $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='.urlencode($object->element).'&amp;originid='.((int) $object->id));
2993 }
2994
2995 /*if (isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0) {
2996 if ($usercancreatepurchaseorder) { isModEnabled("supplier_order") && $object->statut > Commande::STATUS_DRAFT && $object->getNbOfServicesLines() > 0
2997 print dolGetButtonAction('', $langs->trans('AddPurchaseOrder'), 'default', DOL_URL_ROOT.'/fourn/commande/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id, '');
2998 }
2999 }*/
3000
3001 // Create intervention
3002 $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);
3003 /*if (isModEnabled('ficheinter')) {
3004 $langs->load("interventions");
3005
3006 if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && $object->getNbOfServicesLines() > 0) {
3007 if ($user->hasRight('ficheinter', 'creer')) {
3008 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, '');
3009 } else {
3010 print dolGetButtonAction($langs->trans('NotAllowed'), $langs->trans('AddIntervention'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
3011 }
3012 }
3013 }*/
3014
3015 // Create contract
3016 $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);
3017 /*if (isModEnabled('contrat') && ($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS || $object->statut == Commande::STATUS_CLOSED)) {
3018 $langs->load("contracts");
3019
3020 if ($user->hasRight('contrat', 'creer')) {
3021 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, '');
3022 }
3023 }*/
3024
3025 $numshipping = 0;
3026 if (isModEnabled('shipping')) {
3027 $numshipping = $object->countNbOfShipments();
3028 }
3029
3030 // Create shipment
3031 if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && ($object->getNbOfProductsLines() > 0 || getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
3032 if ((getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && $user->hasRight('expedition', 'creer')) || (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && $user->hasRight('expedition', 'delivery', 'creer'))) {
3033 $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);
3034 /*
3035 if ($user->hasRight('expedition', 'creer')) {
3036 print dolGetButtonAction('', $langs->trans('CreateShipment'), 'default', DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id, '');
3037 } else {
3038 print dolGetButtonAction($langs->trans('NotAllowed'), $langs->trans('CreateShipment'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
3039 }*/
3040 } else {
3041 $langs->load("errors");
3042 print dolGetButtonAction($langs->trans('ErrorModuleSetupNotComplete'), $langs->trans('CreateShipment'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
3043 }
3044 }
3045
3046 // Create bill
3047 $arrayforbutaction[] = array(
3048 'lang' => 'bills',
3049 'enabled' => (isModEnabled('invoice') && $object->statut > Commande::STATUS_DRAFT && !$object->billed && $object->total_ttc >= 0),
3050 'perm' => ($user->hasRight('facture', 'creer') && !getDolGlobalInt('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')),
3051 'label' => 'CreateBill',
3052 'url' => '/compta/facture/card.php?action=create&amp;token='.newToken().'&amp;origin='.urlencode($object->element).'&amp;originid='.$object->id.'&amp;socid='.$object->socid
3053 );
3054 /*
3055 if (isModEnabled('facture') && $object->statut > Commande::STATUS_DRAFT && !$object->billed && $object->total_ttc >= 0) {
3056 if (isModEnabled('facture') && $user->hasRight('facture', 'creer') && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
3057 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, '');
3058 }
3059 }*/
3060
3061 $actionButtonsParameters = [
3062 "areDropdownButtons" => !getDolGlobalInt("MAIN_REMOVE_DROPDOWN_CREATE_BUTTONS_ON_ORDER")
3063 ];
3064
3065 if ($numlines > 0) {
3066 print dolGetButtonAction('', $langs->trans("Create"), 'default', $arrayforbutaction, $object->id, 1, $actionButtonsParameters);
3067 } else {
3068 print dolGetButtonAction($langs->trans("ErrorObjectMustHaveLinesToBeValidated", $object->ref), $langs->trans("Create"), 'default', $arrayforbutaction, $object->id, 0, $actionButtonsParameters);
3069 }
3070
3071 // Set to shipped
3072 if (($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS) && $usercanclose) {
3073 print dolGetButtonAction('', $langs->trans('ClassifyShipped'), 'default', $_SERVER["PHP_SELF"].'?action=shipped&amp;token='.newToken().'&amp;id='.$object->id, '');
3074 }
3075
3076 // Set billed or unbilled
3077 // Note: Even if module invoice is not enabled, we should be able to use button "Classified billed"
3078 if ($object->statut > Commande::STATUS_DRAFT && !$object->billed && $object->total_ttc >= 0) {
3079 if ($usercancreate && $object->statut >= Commande::STATUS_VALIDATED && !getDolGlobalString('ORDER_DISABLE_CLASSIFY_BILLED_FROM_ORDER') && !getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT')) {
3080 print dolGetButtonAction('', $langs->trans('ClassifyBilled'), 'default', $_SERVER["PHP_SELF"].'?action=classifybilled&amp;token='.newToken().'&amp;id='.$object->id, '');
3081 }
3082 }
3083 if ($object->statut > Commande::STATUS_DRAFT && $object->billed) {
3084 if ($usercancreate && $object->statut >= Commande::STATUS_VALIDATED && !getDolGlobalString('ORDER_DISABLE_CLASSIFY_BILLED_FROM_ORDER') && !getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT')) {
3085 print dolGetButtonAction('', $langs->trans('ClassifyUnBilled'), 'delete', $_SERVER["PHP_SELF"].'?action=classifyunbilled&amp;token='.newToken().'&amp;id='.$object->id, '');
3086 }
3087 }
3088
3089 // Clone
3090 if ($usercancreate) {
3091 print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id.'&socid='.$object->socid, '');
3092 }
3093
3094 // Cancel order
3095 if ($object->statut == Commande::STATUS_VALIDATED && !empty($usercancancel)) {
3096 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'">'.$langs->trans("CancelOrder").'</a>';
3097 }
3098
3099 // Delete order
3100 if ($usercandelete) {
3101 if ($numshipping == 0) {
3102 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
3103 } else {
3104 print dolGetButtonAction($langs->trans('ShippingExist'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
3105 }
3106 }
3107 }
3108 print '</div>';
3109 }
3110
3111 // Select mail models is same action as presend
3112 if (GETPOST('modelselected')) {
3113 $action = 'presend';
3114 }
3115
3116 if ($action != 'presend') {
3117 print '<div class="fichecenter"><div class="fichehalfleft">';
3118 print '<a name="builddoc"></a>'; // ancre
3119 // Documents
3120 $objref = dol_sanitizeFileName($object->ref);
3121 $relativepath = $objref.'/'.$objref.'.pdf';
3122 $filedir = $conf->commande->multidir_output[$object->entity].'/'.$objref;
3123 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
3124 $genallowed = $usercanread;
3125 $delallowed = $usercancreate;
3126 print $formfile->showdocuments('commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object);
3127
3128
3129 // Show links to link elements
3130 $linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
3131
3132 $compatibleImportElementsList = false;
3133 if ($usercancreate
3134 && $object->statut == Commande::STATUS_DRAFT) {
3135 $compatibleImportElementsList = array('commande', 'propal', 'facture'); // import from linked elements
3136 }
3137 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
3138
3139 // Show online payment link
3140 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
3141 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
3142 $validpaymentmethod = getValidOnlinePaymentMethods('');
3143 $useonlinepayment = count($validpaymentmethod);
3144
3145 if (getDolGlobalString('ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER')) {
3146 $useonlinepayment = 0;
3147 }
3148 if ($object->statut != Commande::STATUS_DRAFT && $useonlinepayment) {
3149 print '<br><!-- Link to pay -->';
3150 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
3151 print showOnlinePaymentUrl('order', $object->ref).'<br>';
3152 }
3153
3154 print '</div><div class="fichehalfright">';
3155
3156 $MAXEVENT = 10;
3157
3158 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/commande/agenda.php?id='.$object->id);
3159
3160 // List of actions on element
3161 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
3162 $formactions = new FormActions($db);
3163 $somethingshown = $formactions->showactions($object, 'order', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
3164
3165 print '</div></div>';
3166 }
3167
3168 // Presend form
3169 $modelmail = 'order_send';
3170 $defaulttopic = 'SendOrderRef';
3171 $diroutput = getMultidirOutput($object);
3172 $trackid = 'ord'.$object->id;
3173
3174 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3175 }
3176}
3177
3178// End of page
3179llxFooter();
3180$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage 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.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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.