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