dolibarr  13.0.2
shipment.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012-2015 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
7  * Copyright (C) 2018 Philippe Grand <philippe.grand@atoo-net.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
36 if (!empty($conf->projet->enabled)) {
37  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
38  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
39 }
40 if (!empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
41 if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
42 if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
43 
44 // Load translation files required by the page
45 $langs->loadLangs(array('orders', "companies", "bills", 'propal', 'deliveries', 'stocks', "productbatch", 'incoterm', 'other'));
46 
47 $id = GETPOST('id', 'int'); // id of order
48 $ref = GETPOST('ref', 'alpha');
49 $action = GETPOST('action', 'aZ09');
50 
51 $hookmanager->initHooks(array('ordershipmentcard'));
52 
53 
54 // Security check
55 $socid = 0;
56 if (!empty($user->socid)) $socid = $user->socid;
57 $result = restrictedArea($user, 'commande', $id);
58 
59 $object = new Commande($db);
60 $extrafields = new ExtraFields($db);
61 
62 // fetch optionals attributes and labels
63 $extrafields->fetch_name_optionals_label($object->table_element);
64 
65 // Load object
66 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
67 
68 
69 
70 
71 /*
72  * Actions
73  */
74 
75 $parameters = array('socid' => $socid);
76 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
77 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
78 
79 if (empty($reshook))
80 {
81  // Categorisation dans projet
82  if ($action == 'classin')
83  {
84  $object = new Commande($db);
85  $object->fetch($id);
86  $object->setProject(GETPOST('projectid', 'int'));
87  }
88 
89  if ($action == 'confirm_cloture' && GETPOST('confirm', 'alpha') == 'yes')
90  {
91  $object = new Commande($db);
92  $object->fetch($id);
93  $result = $object->cloture($user);
94  }
95 
96  // Positionne ref commande client
97  elseif ($action == 'setref_client' && $user->rights->commande->creer) {
98  $result = $object->set_ref_client($user, GETPOST('ref_client'));
99  if ($result < 0)
100  {
101  setEventMessages($object->error, $object->errors, 'errors');
102  }
103  }
104 
105  if ($action == 'setdatedelivery' && $user->rights->commande->creer)
106  {
107  //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
108  $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));
109 
110  $object->fetch($id);
111  $result = $object->setDeliveryDate($user, $datedelivery);
112  if ($result < 0)
113  {
114  setEventMessages($object->error, $object->errors, 'errors');
115  }
116  }
117  /*
118  if ($action == 'setdeliveryaddress' && $user->rights->commande->creer)
119  {
120  $object = new Commande($db);
121  $object->fetch($id);
122  $object->setDeliveryAddress(GETPOST('delivery_address_id','int'));
123  if ($result < 0)
124  setEventMessages($object->error, $object->errors, 'errors');
125  }
126  */
127  if ($action == 'setmode' && $user->rights->commande->creer)
128  {
129  $object = new Commande($db);
130  $object->fetch($id);
131  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
132  if ($result < 0)
133  setEventMessages($object->error, $object->errors, 'errors');
134  }
135 
136  if ($action == 'setavailability' && $user->rights->commande->creer) {
137  $object = new Commande($db);
138  $object->fetch($id);
139  $result = $object->availability(GETPOST('availability_id'));
140  if ($result < 0)
141  setEventMessages($object->error, $object->errors, 'errors');
142  }
143 
144  if ($action == 'setdemandreason' && $user->rights->commande->creer) {
145  $object = new Commande($db);
146  $object->fetch($id);
147  $result = $object->demand_reason(GETPOST('demand_reason_id'));
148  if ($result < 0)
149  setEventMessages($object->error, $object->errors, 'errors');
150  }
151 
152  if ($action == 'setconditions' && $user->rights->commande->creer)
153  {
154  $object = new Commande($db);
155  $object->fetch($id);
156  $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
157  if ($result < 0)
158  setEventMessages($object->error, $object->errors, 'errors');
159  }
160 
161  // Set incoterm
162  elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
163  {
164  $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
165  if ($result < 0) {
166  setEventMessages($object->error, $object->errors, 'errors');
167  }
168  }
169 
170  // shipping method
171  if ($action == 'setshippingmethod' && $user->rights->commande->creer) {
172  $object = new Commande($db);
173  $object->fetch($id);
174  $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int'));
175  if ($result < 0)
176  setEventMessages($object->error, $object->errors, 'errors');
177  }
178 
179  // warehouse
180  if ($action == 'setwarehouse' && $user->rights->commande->creer) {
181  $object = new Commande($db);
182  $object->fetch($id);
183  $result = $object->setWarehouse(GETPOST('warehouse_id', 'int'));
184  if ($result < 0)
185  setEventMessages($object->error, $object->errors, 'errors');
186  }
187 
188  if ($action == 'update_extras')
189  {
190  $object->oldcopy = dol_clone($object);
191 
192  // Fill array 'array_options' with data from update form
193  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
194  if ($ret < 0) $error++;
195 
196  if (!$error)
197  {
198  // Actions on extra fields
199  $result = $object->insertExtraFields('SHIPMENT_MODIFY');
200  if ($result < 0)
201  {
202  setEventMessages($object->error, $object->errors, 'errors');
203  $error++;
204  }
205  }
206 
207  if ($error)
208  $action = 'edit_extras';
209  }
210 
211  if ($action == 'set_thirdparty' && $user->rights->commande->creer)
212  {
213  $object->fetch($id);
214  $object->setValueFrom('fk_soc', $socid, '', '', 'date', '', $user, 'ORDER_MODIFY');
215 
216  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
217  exit();
218  }
219 
220  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
221 }
222 
223 /*
224  * View
225  */
226 
227 $form = new Form($db);
228 $formfile = new FormFile($db);
229 $formproduct = new FormProduct($db);
230 if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
231 
232 llxHeader('', $langs->trans('OrderCard'), '');
233 
234 
235 if ($id > 0 || !empty($ref))
236 {
237  $object = new Commande($db);
238  if ($object->fetch($id, $ref) > 0)
239  {
240  $object->loadExpeditions(1);
241 
242  $product_static = new Product($db);
243 
244  $soc = new Societe($db);
245  $soc->fetch($object->socid);
246 
247  $author = new User($db);
248  $author->fetch($object->user_author_id);
249 
250  $res = $object->fetch_optionals();
251 
252  $head = commande_prepare_head($object);
253  print dol_get_fiche_head($head, 'shipping', $langs->trans("CustomerOrder"), -1, 'order');
254 
255 
256  $formconfirm = '';
257 
258  // Confirm validation
259  if ($action == 'cloture')
260  {
261  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id, $langs->trans("CloseShipment"), $langs->trans("ConfirmCloseShipment"), "confirm_cloture");
262  }
263 
264  // Call Hook formConfirm
265  $parameters = array('formConfirm' => $formconfirm);
266  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
267  if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
268  elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
269 
270  // Print form confirm
271  print $formconfirm;
272 
273 
274  // Order card
275 
276  $linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
277 
278 
279  $morehtmlref = '<div class="refidno">';
280  // Ref customer
281  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', 0, 1);
282  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', null, null, '', 1);
283  // Thirdparty
284  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$soc->getNomUrl(1);
285  // Project
286  if (!empty($conf->projet->enabled))
287  {
288  $langs->load("projects");
289  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
290  if ($user->rights->commande->creer)
291  {
292  if ($action != 'classify') {
293  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
294  }
295  if ($action == 'classify') {
296  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
297  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
298  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
299  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
300  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
301  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
302  $morehtmlref .= '</form>';
303  } else {
304  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
305  }
306  } else {
307  if (!empty($object->fk_project)) {
308  $proj = new Project($db);
309  $proj->fetch($object->fk_project);
310  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
311  $morehtmlref .= $proj->ref;
312  $morehtmlref .= '</a>';
313  } else {
314  $morehtmlref .= '';
315  }
316  }
317  }
318  $morehtmlref .= '</div>';
319 
320 
321  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
322 
323 
324  print '<div class="fichecenter">';
325  print '<div class="fichehalfleft">';
326  print '<div class="underbanner clearboth"></div>';
327 
328  print '<table class="border centpercent tableforfield">';
329 
330  // Discounts for third party
331  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
332  $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
333  $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
334  } else {
335  $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
336  $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
337  }
338 
339  print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td colspan="3">';
340 
341  $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
342  $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
343  $absolute_discount = price2num($absolute_discount, 'MT');
344  $absolute_creditnote = price2num($absolute_creditnote, 'MT');
345 
346  $thirdparty = $soc;
347  $discount_type = 0;
348  $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
349  $cannotApplyDiscount = 1;
350  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
351  print '</td></tr>';
352 
353  // Date
354  print '<tr><td>'.$langs->trans('Date').'</td>';
355  print '<td colspan="2">';
356  print dol_print_date($object->date, 'day');
357  if ($object->hasDelay() && empty($object->delivery_date)) {
358  print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");
359  }
360  print '</td>';
361  print '</tr>';
362 
363  // Delivery date planned
364  print '<tr><td height="10">';
365  print '<table class="nobordernopadding" width="100%"><tr><td>';
366  print $langs->trans('DateDeliveryPlanned');
367  print '</td>';
368 
369  if ($action != 'editdate_livraison') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
370  print '</tr></table>';
371  print '</td><td colspan="2">';
372  if ($action == 'editdate_livraison')
373  {
374  print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
375  print '<input type="hidden" name="token" value="'.newToken().'">';
376  print '<input type="hidden" name="action" value="setdatedelivery">';
377  print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);
378  print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
379  print '</form>';
380  } else {
381  print dol_print_date($object->delivery_date, 'dayhour');
382  if ($object->hasDelay() && !empty($object->delivery_date)) {
383  print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");
384  }
385  }
386  print '</td>';
387  // Note on several rows
388  //print '<td rowspan="'.$nbrow.'" valign="top">'.$langs->trans('NotePublic').' :<br>';
389  //print nl2br($object->note_public);
390  //print '</td>';
391  print '</tr>';
392 
393  // Shipping Method
394  print '<tr><td>';
395  print '<table width="100%" class="nobordernopadding"><tr><td>';
396  print $langs->trans('SendingMethod');
397  print '</td>';
398  if ($action != 'editshippingmethod' && $user->rights->expedition->creer)
399  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshippingmethod&amp;id='.$object->id.'">'.img_edit($langs->trans('SetShippingMode'), 1).'</a></td>';
400  print '</tr></table>';
401  print '</td><td colspan="2">';
402  if ($action == 'editshippingmethod') {
403  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
404  } else {
405  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none');
406  }
407  print '</td>';
408  print '</tr>';
409 
410  // Warehouse
411  if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
412  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
413  $formproduct = new FormProduct($db);
414  print '<tr><td>';
415  print '<table width="100%" class="nobordernopadding"><tr><td>';
416  print $langs->trans('Warehouse');
417  print '</td>';
418  if ($action != 'editwarehouse' && $user->rights->commande->creer)
419  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editwarehouse&amp;id='.$object->id.'">'.img_edit($langs->trans('SetWarehouse'), 1).'</a></td>';
420  print '</tr></table>';
421  print '</td><td colspan="2">';
422  if ($action == 'editwarehouse') {
423  $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1);
424  } else {
425  $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none');
426  }
427  print '</td>';
428  print '</tr>';
429  }
430 
431  // Terms of payment
432  /*
433  print '<tr><td height="10">';
434  print '<table class="nobordernopadding" width="100%"><tr><td>';
435  print $langs->trans('PaymentConditionsShort');
436  print '</td>';
437 
438  if ($action != 'editconditions' && $object->statut == Expedition::STATUS_VALIDATED) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
439  print '</tr></table>';
440  print '</td><td colspan="2">';
441  if ($action == 'editconditions')
442  {
443  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id');
444  }
445  else
446  {
447  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none');
448  }
449  print '</td></tr>';
450 
451  // Mode of payment
452  print '<tr><td>';
453  print '<table class="nobordernopadding" width="100%"><tr><td>';
454  print $langs->trans('PaymentMode');
455  print '</td>';
456  if ($action != 'editmode' && $object->statut == Expedition::STATUS_VALIDATED) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
457  print '</tr></table>';
458  print '</td><td colspan="2">';
459  if ($action == 'editmode')
460  {
461  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
462  }
463  else
464  {
465  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none');
466  }
467  print '</td></tr>';*/
468 
469  // Availability
470  print '<tr><td height="10">';
471  print '<table class="nobordernopadding" width="100%"><tr><td>';
472  print $langs->trans('AvailabilityPeriod');
473  print '</td>';
474  if ($action != 'editavailability')
475  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editavailability&amp;id='.$object->id.'">'.img_edit($langs->trans('SetAvailability'), 1).'</a></td>';
476  print '</tr></table>';
477  print '</td><td colspan="3">';
478  if ($action == 'editavailability') {
479  $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1);
480  } else {
481  $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1);
482  }
483  print '</td></tr>';
484 
485  // Source
486  print '<tr><td height="10">';
487  print '<table class="nobordernopadding" width="100%"><tr><td>';
488  print $langs->trans('Source');
489  print '</td>';
490  if ($action != 'editdemandreason')
491  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDemandReason'), 1).'</a></td>';
492  print '</tr></table>';
493  print '</td><td colspan="3">';
494  if ($action == 'editdemandreason') {
495  $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1);
496  } else {
497  $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none');
498  }
499 
500  $tmparray = $object->getTotalWeightVolume();
501  $totalWeight = $tmparray['weight'];
502  $totalVolume = $tmparray['volume'];
503  if ($totalWeight || $totalVolume)
504  {
505  print '<tr><td>'.$langs->trans("CalculatedWeight").'</td>';
506  print '<td>';
507  print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no');
508  print '</td></tr>';
509  print '<tr><td>'.$langs->trans("CalculatedVolume").'</td>';
510  print '<td>';
511  print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no');
512  print '</td></tr>';
513  }
514 
515  // TODO How record was recorded OrderMode (llx_c_input_method)
516 
517  // Incoterms
518  if (!empty($conf->incoterm->enabled))
519  {
520  print '<tr><td>';
521  print '<table width="100%" class="nobordernopadding"><tr><td>';
522  print $langs->trans('IncotermLabel');
523  print '<td><td class="right">';
524  if ($user->rights->commande->creer) print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'/expedition/shipment.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
525  else print '&nbsp;';
526  print '</td></tr></table>';
527  print '</td>';
528  print '<td colspan="3">';
529  if ($action != 'editincoterm')
530  {
531  print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
532  } else {
533  print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
534  }
535  print '</td></tr>';
536  }
537 
538  $expe = new Expedition($db);
539  $extrafields->fetch_name_optionals_label($expe->table_element);
540 
541  // Other attributes
542  $cols = 2;
543  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
544 
545  print '</table>';
546 
547  print '</div>';
548  print '<div class="fichehalfright">';
549  print '<div class="ficheaddleft">';
550  print '<div class="underbanner clearboth"></div>';
551 
552  print '<table class="border centpercent tableforfield">';
553 
554  if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
555  {
556  // Multicurrency Amount HT
557  print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';
558  print '<td class="nowrap">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
559  print '</tr>';
560 
561  // Multicurrency Amount VAT
562  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';
563  print '<td class="nowrap">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
564  print '</tr>';
565 
566  // Multicurrency Amount TTC
567  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';
568  print '<td class="nowrap">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
569  print '</tr>';
570  }
571 
572  // Total HT
573  print '<tr><td class="titlefieldmiddle">'.$langs->trans('AmountHT').'</td>';
574  print '<td>'.price($object->total_ht, 0, '', 1, -1, -1, $conf->currency).'</td>';
575  print '</tr>';
576 
577  // Total VAT
578  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 0, '', 1, -1, -1, $conf->currency).'</td>';
579  print '</tr>';
580 
581  // Amount Local Taxes
582  if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1
583  {
584  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
585  print '<td>'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
586  }
587  if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) // Localtax2 IRPF
588  {
589  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
590  print '<td>'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
591  }
592 
593  // Total TTC
594  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 0, '', 1, -1, -1, $conf->currency).'</td>';
595  print '</tr>';
596 
597  print '</table>';
598 
599  print '</div>';
600  print '</div>';
601  print '</div>';
602 
603  print '<div class="clearboth"></div><br>';
604 
605 
606 
611  print '<table class="noborder noshadow" width="100%">';
612 
613  $sql = "SELECT cd.rowid, cd.fk_product, cd.product_type as type, cd.label, cd.description,";
614  $sql .= " cd.price, cd.tva_tx, cd.subprice,";
615  $sql .= " cd.qty,";
616  $sql .= ' cd.date_start,';
617  $sql .= ' cd.date_end,';
618  $sql .= ' cd.special_code,';
619  $sql .= ' p.rowid as prodid, p.label as product_label, p.entity, p.ref, p.fk_product_type as product_type, p.description as product_desc,';
620  $sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units,';
621  $sql .= ' p.surface, p.surface_units, p.volume, p.volume_units';
622  $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
623  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
624  $sql .= " WHERE cd.fk_commande = ".$object->id;
625  $sql .= " ORDER BY cd.rang, cd.rowid";
626 
627  //print $sql;
628  dol_syslog("shipment.php", LOG_DEBUG);
629  $resql = $db->query($sql);
630  if ($resql)
631  {
632  $num = $db->num_rows($resql);
633  $i = 0;
634 
635  print '<tr class="liste_titre">';
636  print '<td>'.$langs->trans("Description").'</td>';
637  print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
638  print '<td class="center">'.$langs->trans("QtyShipped").'</td>';
639  print '<td class="center">'.$langs->trans("KeepToShip").'</td>';
640  if (!empty($conf->stock->enabled))
641  {
642  print '<td class="center">'.$langs->trans("RealStock").'</td>';
643  } else {
644  print '<td>&nbsp;</td>';
645  }
646  print "</tr>\n";
647 
648  $toBeShipped = array();
649  $toBeShippedTotal = 0;
650  while ($i < $num)
651  {
652  $objp = $db->fetch_object($resql);
653 
654  $parameters = array('i' => $i, 'line' => $objp, 'num' => $num);
655  $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);
656  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
657 
658  if (empty($reshook))
659  {
660  // Show product and description
661  $type = isset($objp->type) ? $objp->type : $objp->product_type;
662 
663  // Try to enhance type detection using date_start and date_end for free lines where type
664  // was not saved.
665  if (!empty($objp->date_start)) $type = 1;
666  if (!empty($objp->date_end)) $type = 1;
667 
668  print '<tr class="oddeven">';
669 
670  // Product label
671  if ($objp->fk_product > 0)
672  {
673  // Define output language
674  if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
675  {
676  $object->fetch_thirdparty();
677 
678  $prod = new Product($db);
679  $prod->id = $objp->fk_product;
680  $prod->entity = $objp->entity;
681  $prod->getMultiLangs();
682 
683  $outputlangs = $langs;
684  $newlang = '';
685  if (empty($newlang) && !empty($_REQUEST['lang_id'])) $newlang = $_REQUEST['lang_id'];
686  if (empty($newlang)) $newlang = $object->thirdparty->default_lang;
687  if (!empty($newlang))
688  {
689  $outputlangs = new Translate("", $conf);
690  $outputlangs->setDefaultLang($newlang);
691  }
692 
693  $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
694  } else $label = (!empty($objp->label) ? $objp->label : $objp->product_label);
695 
696  print '<td>';
697  print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
698 
699  // Show product and description
700  $product_static->type = $type;
701  $product_static->id = $objp->fk_product;
702  $product_static->ref = $objp->ref;
703  $product_static->entity = $objp->entity;
704 
705  $product_static->weight = $objp->weight;
706  $product_static->weight_units = $objp->weight_units;
707  $product_static->length = $objp->length;
708  $product_static->length_units = $objp->length_units;
709  $product_static->width = $objp->width;
710  $product_static->width_units = $objp->width_units;
711  $product_static->height = $objp->height;
712  $product_static->height_units = $objp->height_units;
713  $product_static->surface = $objp->surface;
714  $product_static->surface_units = $objp->surface_units;
715  $product_static->volume = $objp->volume;
716  $product_static->volume_units = $objp->volume_units;
717 
718  $text = $product_static->getNomUrl(1);
719  $text .= ' - '.$label;
720  $description = ($conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($objp->description)).'<br>';
721  $description .= $product_static->show_photos('product', $conf->product->multidir_output[$product_static->entity], 1, 1, 0, 0, 0, 80);
722  print $form->textwithtooltip($text, $description, 3, '', '', $i);
723 
724  // Show range
725  print_date_range($db->jdate($objp->date_start), $db->jdate($objp->date_end));
726 
727  // Add description in form
728  if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
729  {
730  print ($objp->description && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
731  }
732 
733  print '</td>';
734  } else {
735  print "<td>";
736  if ($type == 1) $text = img_object($langs->trans('Service'), 'service');
737  else $text = img_object($langs->trans('Product'), 'product');
738 
739  if (!empty($objp->label)) {
740  $text .= ' <strong>'.$objp->label.'</strong>';
741  print $form->textwithtooltip($text, $objp->description, 3, '', '', $i);
742  } else {
743  print $text.' '.nl2br($objp->description);
744  }
745 
746  // Show range
747  print_date_range($db->jdate($objp->date_start), $db->jdate($objp->date_end));
748  print "</td>\n";
749  }
750 
751  // Qty ordered
752  print '<td class="center">'.$objp->qty.'</td>';
753 
754  // Qty already shipped
755  $qtyProdCom = $objp->qty;
756  print '<td class="center">';
757  // Nb of sending products for this line of order
758  $qtyAlreadyShipped = (!empty($object->expeditions[$objp->rowid]) ? $object->expeditions[$objp->rowid] : 0);
759  print $qtyAlreadyShipped;
760  print '</td>';
761 
762  // Qty remains to ship
763  print '<td class="center">';
764  if ($type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES))
765  {
766  $toBeShipped[$objp->fk_product] = $objp->qty - $qtyAlreadyShipped;
767  $toBeShippedTotal += $toBeShipped[$objp->fk_product];
768  print $toBeShipped[$objp->fk_product];
769  } else {
770  print '0 ('.$langs->trans("Service").')';
771  }
772  print '</td>';
773 
774  if ($objp->fk_product > 0)
775  {
776  $product = new Product($db);
777  $product->fetch($objp->fk_product);
778  $product->load_stock('warehouseopen');
779  }
780 
781  if ($objp->fk_product > 0 && ($type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && !empty($conf->stock->enabled))
782  {
783  print '<td class="center">';
784  print $product->stock_reel;
785  if ($product->stock_reel < $toBeShipped[$objp->fk_product])
786  {
787  print ' '.img_warning($langs->trans("StockTooLow"));
788  }
789  print '</td>';
790  } else {
791  print '<td>&nbsp;</td>';
792  }
793  print "</tr>\n";
794 
795  // Show subproducts lines
796  if ($objp->fk_product > 0 && !empty($conf->global->PRODUIT_SOUSPRODUITS))
797  {
798  // Set tree of subproducts in product->sousprods
799  $product->get_sousproduits_arbo();
800  //var_dump($product->sousprods);exit;
801 
802  // Define a new tree with quantiies recalculated
803  $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
804  //var_dump($prods_arbo);
805  if (count($prods_arbo) > 0)
806  {
807  foreach ($prods_arbo as $key => $value)
808  {
809  $img = '';
810  if ($value['stock'] < $value['stock_alert'])
811  {
812  $img = img_warning($langs->trans("StockTooLow"));
813  }
814  print '<tr class="oddeven"><td>&nbsp; &nbsp; &nbsp; -> <a href="'.DOL_URL_ROOT."/product/card.php?id=".$value['id'].'">'.$value['fullpath'].'</a> ('.$value['nb'].')</td>';
815  print '<td class="center"> '.$value['nb_total'].'</td>';
816  print '<td>&nbsp</td>';
817  print '<td>&nbsp</td>';
818  print '<td class="center">'.$value['stock'].' '.$img.'</td></tr>'."\n";
819  }
820  }
821  }
822  }
823  $i++;
824  }
825  $db->free($resql);
826 
827  if (!$num)
828  {
829  print '<tr '.$bc[false].'><td colspan="5">'.$langs->trans("NoArticleOfTypeProduct").'<br>';
830  }
831 
832  print "</table>";
833  } else {
834  dol_print_error($db);
835  }
836 
837  print '</div>';
838 
839 
840  /*
841  * Boutons Actions
842  */
843 
844  if (empty($user->socid))
845  {
846  print '<div class="tabsAction">';
847 
848  // Bouton expedier sans gestion des stocks
849  if (empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED))
850  {
851  if ($user->rights->expedition->creer)
852  {
853  print '<a class="butAction" href="'.DOL_URL_ROOT.'/expedition/card.php?action=create&amp;origin=commande&amp;object_id='.$id.'">'.$langs->trans("CreateShipment").'</a>';
854  if ($toBeShippedTotal <= 0)
855  {
856  print ' '.img_warning($langs->trans("WarningNoQtyLeftToSend"));
857  }
858  } else {
859  print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("CreateShipment").'</a>';
860  }
861  }
862  print "</div>";
863  }
864 
865 
866  // Bouton expedier avec gestion des stocks
867 
868  if (!empty($conf->stock->enabled) && $object->statut == Commande::STATUS_DRAFT)
869  {
870  print $langs->trans("ValidateOrderFirstBeforeShipment");
871  }
872 
873  if (!empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED))
874  {
875  if ($user->rights->expedition->creer)
876  {
877  //print load_fiche_titre($langs->trans("CreateShipment"));
878  print '<div class="tabsAction">';
879 
880  print '<form method="GET" action="'.DOL_URL_ROOT.'/expedition/card.php">';
881  print '<input type="hidden" name="action" value="create">';
882  //print '<input type="hidden" name="id" value="'.$object->id.'">';
883  print '<input type="hidden" name="shipping_method_id" value="'.$object->shipping_method_id.'">';
884  print '<input type="hidden" name="origin" value="commande">';
885  print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
886  print '<input type="hidden" name="projectid" value="'.$object->fk_project.'">';
887  //print '<table class="border centpercent">';
888 
889  $langs->load("stocks");
890 
891  //print '<tr>';
892 
893  if (!empty($conf->stock->enabled))
894  {
895  //print '<td>';
896  print $langs->trans("WarehouseSource");
897  //print '</td>';
898  //print '<td>';
899  print $formproduct->selectWarehouses(!empty($object->warehouse_id) ? $object->warehouse_id : 'ifone', 'entrepot_id', '', 1, 0, 0, '', 0, 0, array(), 'minwidth200');
900  if (count($formproduct->cache_warehouses) <= 0)
901  {
902  print ' &nbsp; '.$langs->trans("WarehouseSourceNotDefined").' <a href="'.DOL_URL_ROOT.'/product/stock/card.php?action=create">'.$langs->trans("AddOne").'</a>';
903  }
904  //print '</td>';
905  }
906  //print '<td class="center">';
907  print '<input type="submit" class="butAction" named="save" value="'.$langs->trans("CreateShipment").'">';
908  if ($toBeShippedTotal <= 0)
909  {
910  print ' '.img_warning($langs->trans("WarningNoQtyLeftToSend"));
911  }
912  //print '</td></tr>';
913 
914  //print "</table>";
915  print "</form>\n";
916 
917  print '</div>';
918 
919  $somethingshown = 1;
920  } else {
921  print '<div class="tabsAction">';
922  print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("CreateShipment").'</a>';
923  print '</div>';
924  }
925  }
926 
927  show_list_sending_receive('commande', $object->id);
928  } else {
929  /* Order not found */
930  setEventMessages($langs->trans("NonExistentOrder"), null, 'errors');
931  }
932 }
933 
934 // End of page
935 llxFooter();
936 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
const STATUS_CLOSED
Closed (Sent, billed or not)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage products or services.
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom= 'UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
show_list_sending_receive($origin, $origin_id, $filter= '')
List sendings and receive receipts.
const TYPE_PRODUCT
Regular product.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
Class with static methods for building HTML components related to products Only components common to ...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage building of HTML components.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput= 'no')
Output a dimension with best unit.
Class to manage shipments.
Class to manage customers orders.
const STATUS_DRAFT
Draft status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage translations.
Class to offer components to list and upload files.
commande_prepare_head(Commande $object)
Prepare array with list of tabs.
Definition: order.lib.php:34
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print_date_range($date_start, $date_end, $format= '', $outputlangs= '')
Format output for start and end date.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.