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