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