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