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