dolibarr  7.0.0-beta
sendings.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
24 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
25 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
27 
28 
35 function shipping_prepare_head($object)
36 {
37  global $db, $langs, $conf, $user;
38 
39  $langs->load("sendings");
40  $langs->load("deliveries");
41 
42  $h = 0;
43  $head = array();
44 
45  $head[$h][0] = DOL_URL_ROOT."/expedition/card.php?id=".$object->id;
46  $head[$h][1] = $langs->trans("SendingCard");
47  $head[$h][2] = 'shipping';
48  $h++;
49 
50  if ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire)
51  {
52  // delivery link
53  $object->fetchObjectLinked($object->id,$object->element);
54  if (count($object->linkedObjectsIds['delivery']) > 0) // If there is a delivery
55  {
56  // Take first one element of array
57  $tmp = reset($object->linkedObjectsIds['delivery']);
58 
59  $head[$h][0] = DOL_URL_ROOT."/livraison/card.php?id=".$tmp;
60  $head[$h][1] = $langs->trans("DeliveryCard");
61  $head[$h][2] = 'delivery';
62  $h++;
63  }
64  }
65 
66  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
67  {
68  $objectsrc = $object;
69  if ($object->origin == 'commande' && $object->origin_id > 0)
70  {
71  $objectsrc = new Commande($db);
72  $objectsrc->fetch($object->origin_id);
73  }
74  $nbContact = count($objectsrc->liste_contact(-1,'internal')) + count($objectsrc->liste_contact(-1,'external'));
75  $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$object->id;
76  $head[$h][1] = $langs->trans("ContactsAddresses");
77  if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
78  $head[$h][2] = 'contact';
79  $h++;
80  }
81 
82  $nbNote = 0;
83  if (!empty($object->note_private)) $nbNote++;
84  if (!empty($object->note_public)) $nbNote++;
85  $head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$object->id;
86  $head[$h][1] = $langs->trans("Notes");
87  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
88  $head[$h][2] = 'note';
89  $h++;
90 
91  // Show more tabs from modules
92  // Entries must be declared in modules descriptor with line
93  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
94  // $this->tabs = array('entity:-tabname); to remove a tab
95  complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
96 
97  complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery','remove');
98 
99  return $head;
100 }
101 
102 
109 function delivery_prepare_head($object)
110 {
111  global $langs, $conf, $user;
112 
113  $langs->load("sendings");
114  $langs->load("deliveries");
115 
116  $h = 0;
117  $head = array();
118 
119  if ($conf->expedition_bon->enabled && $user->rights->expedition->lire)
120  {
121  $head[$h][0] = DOL_URL_ROOT."/expedition/card.php?id=".$object->origin_id;
122  $head[$h][1] = $langs->trans("SendingCard");
123  $head[$h][2] = 'shipping';
124  $h++;
125  }
126 
127  $head[$h][0] = DOL_URL_ROOT."/livraison/card.php?id=".$object->id;
128  $head[$h][1] = $langs->trans("DeliveryCard");
129  $head[$h][2] = 'delivery';
130  $h++;
131 
132  $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$object->origin_id;
133  $head[$h][1] = $langs->trans("ContactsAddresses");
134  $head[$h][2] = 'contact';
135  $h++;
136 
137  $head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$object->origin_id;
138  $head[$h][1] = $langs->trans("Notes");
139  $head[$h][2] = 'note';
140  $h++;
141 
142  // Show more tabs from modules
143  // Entries must be declared in modules descriptor with line
144  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
145  // $this->tabs = array('entity:-tabname); to remove a tab
146  // complete_head_from_modules use $object->id for this link so we temporary change it
147  $tmpObjectId = $object->id;
148  $object->id = $object->origin_id;
149 
150  complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
151 
152  complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery','remove');
153 
154  $object->id = $tmpObjectId;
155  return $head;
156 }
157 
166 function show_list_sending_receive($origin,$origin_id,$filter='')
167 {
168  global $db, $conf, $langs, $bc;
169  global $form;
170 
171  $product_static=new Product($db);
172  $expedition=new Expedition($db);
173  $warehousestatic=new Entrepot($db);
174 
175  $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end,";
176  $sql.= " ed.rowid as edrowid, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot as warehouse_id,";
177  $sql.= " e.rowid as sendingid, e.ref as exp_ref, e.date_creation, e.date_delivery, e.date_expedition,";
178  //if ($conf->livraison_bon->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received,";
179  $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch,';
180  $sql.= ' p.description as product_desc';
181  $sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
182  $sql.= ", ".MAIN_DB_PREFIX."expedition as e";
183  $sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj";
184  //if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line";
185  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
186  //TODO Add link to expeditiondet_batch
187  $sql.= " WHERE e.entity IN (".getEntity('expedition').")";
188  $sql.= " AND obj.fk_".$origin." = ".$origin_id;
189  $sql.= " AND obj.rowid = ed.fk_origin_line";
190  $sql.= " AND ed.fk_expedition = e.rowid";
191  if ($filter) $sql.= $filter;
192 
193  $sql.= " ORDER BY obj.fk_product";
194 
195  dol_syslog("show_list_sending_receive", LOG_DEBUG);
196  $resql = $db->query($sql);
197  if ($resql)
198  {
199  $num = $db->num_rows($resql);
200  $i = 0;
201 
202  if ($num)
203  {
204  if ($filter) print load_fiche_titre($langs->trans("OtherSendingsForSameOrder"));
205  else print load_fiche_titre($langs->trans("SendingsAndReceivingForSameOrder"));
206 
207  print '<table class="liste" width="100%">';
208  print '<tr class="liste_titre">';
209  //print '<td align="left">'.$langs->trans("QtyOrdered").'</td>';
210  print '<td align="left">'.$langs->trans("SendingSheet").'</td>';
211  print '<td align="left">'.$langs->trans("Description").'</td>';
212  print '<td align="center">'.$langs->trans("DateCreation").'</td>';
213  print '<td align="center">'.$langs->trans("DateDeliveryPlanned").'</td>';
214  print '<td align="center">'.$langs->trans("QtyPreparedOrShipped").'</td>';
215  if (! empty($conf->stock->enabled))
216  {
217  print '<td>'.$langs->trans("Warehouse").'</td>';
218  }
219  /*TODO Add link to expeditiondet_batch
220  if (! empty($conf->productbatch->enabled))
221  {
222  print '<td>';
223  print '</td>';
224  }*/
225  if (! empty($conf->livraison_bon->enabled))
226  {
227  print '<td>'.$langs->trans("DeliveryOrder").'</td>';
228  //print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
229  print '<td align="right">'.$langs->trans("DeliveryDate").'</td>';
230  }
231  print "</tr>\n";
232 
233  $var=True;
234  while ($i < $num)
235  {
236 
237  $objp = $db->fetch_object($resql);
238  print '<tr class="oddeven">';
239 
240  // Sending id
241  print '<td align="left" class="nowrap">';
242  print '<a href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->exp_ref.'<a>';
243  print '</td>';
244 
245  // Description
246  if ($objp->fk_product > 0)
247  {
248  // Define output language
249  if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
250  {
251  $object = new $origin($db);
252  $object->fetch($origin_id);
253  $object->fetch_thirdparty();
254 
255  $prod = new Product($db);
256  $prod->id=$objp->fk_product;
257  $prod->getMultiLangs();
258 
259  $outputlangs = $langs;
260  $newlang='';
261  if (empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
262  if (empty($newlang)) $newlang=$object->thirdparty->default_lang;
263  if (! empty($newlang))
264  {
265  $outputlangs = new Translate("",$conf);
266  $outputlangs->setDefaultLang($newlang);
267  }
268 
269  $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
270  }
271  else
272  {
273  $label = (! empty($objp->label)?$objp->label:$objp->product_label);
274  }
275 
276  print '<td>';
277 
278  // Show product and description
279  $product_static->type=$objp->fk_product_type;
280  $product_static->id=$objp->fk_product;
281  $product_static->ref=$objp->ref;
282  $product_static->status_batch=$objp->product_tobatch;
283  $text=$product_static->getNomUrl(1);
284  $text.= ' - '.$label;
285  $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($objp->description));
286  print $form->textwithtooltip($text,$description,3,'','',$i);
287 
288  // Show range
289  print_date_range($objp->date_start,$objp->date_end);
290 
291  // Add description in form
292  if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
293  {
294  print (! empty($objp->description) && $objp->description!=$objp->product)?'<br>'.dol_htmlentitiesbr($objp->description):'';
295  }
296 
297  print '</td>';
298  }
299  else
300  {
301  print "<td>";
302  if ($objp->fk_product_type==1) $text = img_object($langs->trans('Service'),'service');
303  else $text = img_object($langs->trans('Product'),'product');
304 
305  if (! empty($objp->label)) {
306  $text.= ' <strong>'.$objp->label.'</strong>';
307  print $form->textwithtooltip($text,$objp->description,3,'','',$i);
308  } else {
309  print $text.' '.nl2br($objp->description);
310  }
311 
312  // Show range
313  print_date_range($objp->date_start,$objp->date_end);
314  print "</td>\n";
315  }
316 
317  //print '<td align="center">'.$objp->qty_asked.'</td>';
318 
319  // Date creation
320  print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
321 
322  // Date shipping creation
323  print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($objp->date_delivery),'day').'</td>';
324 
325  // Qty shipped
326  print '<td align="center">'.$objp->qty_shipped.'</td>';
327 
328  // Warehouse
329  if (! empty($conf->stock->enabled))
330  {
331  print '<td>';
332  if ($objp->warehouse_id > 0)
333  {
334  $warehousestatic->fetch($objp->warehouse_id);
335  print $warehousestatic->getNomUrl(1);
336  }
337  print '</td>';
338  }
339 
340  // Batch number managment
341  /*TODO Add link to expeditiondet_batch
342  if (! empty($conf->productbatch->enabled))
343  {
344  var_dump($objp->edrowid);
345  $lines[$i]->detail_batch
346  if (isset($lines[$i]->detail_batch))
347  {
348  print '<td>';
349  if ($lines[$i]->product_tobatch)
350  {
351  $detail = '';
352  foreach ($lines[$i]->detail_batch as $dbatch)
353  {
354  $detail.= $langs->trans("Batch").': '.$dbatch->batch;
355  $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
356  $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
357  $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->dluo_qty;
358  $detail.= '<br>';
359  }
360  print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
361  }
362  else
363  {
364  print $langs->trans("NA");
365  }
366  print '</td>';
367  } else {
368  print '<td></td>';
369  }
370  }*/
371 
372  // Informations on receipt
373  if (! empty($conf->livraison_bon->enabled))
374  {
375  include_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php';
376  $expedition->id=$objp->sendingid;
377  $expedition->fetchObjectLinked($expedition->id,$expedition->element);
378  //var_dump($expedition->linkedObjects);
379 
380  $receiving='';
381  if (count($expedition->linkedObjects['delivery']) > 0) $receiving=reset($expedition->linkedObjects['delivery']); // Take first link
382 
383  if (! empty($receiving))
384  {
385  // $expedition->fk_origin_line = id of det line of order
386  // $receiving->fk_origin_line = id of det line of order
387  // $receiving->origin may be 'shipping'
388  // $receiving->origin_id may be id of shipping
389 
390  // Ref
391  print '<td>';
392  print $receiving->getNomUrl($db);
393  //print '<a href="'.DOL_URL_ROOT.'/livraison/card.php?id='.$livraison_id.'">'.img_object($langs->trans("ShowReceiving"),'sending').' '.$objp->livraison_ref.'<a>';
394  print '</td>';
395  // Qty received
396  //print '<td align="center">';
397  // TODO No solution for the moment to link a line det of receipt with a line det of shipping,
398  // so no way to know the qty received for this line of shipping.
399  //print $langs->trans("FeatureNotYetAvailable");
400  //print '</td>';
401  // Date shipping real
402  print '<td align="right">';
403  print dol_print_date($receiving->date_delivery,'day');
404  print '</td>';
405  }
406  else
407  {
408  //print '<td>&nbsp;</td>';
409  print '<td>&nbsp;</td>';
410  print '<td>&nbsp;</td>';
411  }
412  }
413  print '</tr>';
414  $i++;
415  }
416 
417  print '</table>';
418  }
419  $db->free($resql);
420  }
421  else
422  {
423  dol_print_error($db);
424  }
425 
426  return 1;
427 }
428 
shipping_prepare_head($object)
Prepare array with list of tabs.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
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.
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...
delivery_prepare_head($object)
Prepare array with list of tabs.
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage shipments.
Class to manage customers orders.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage translations.
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...
print_date_range($date_start, $date_end, $format= '', $outputlangs='')
Format output for start and end date.
Class to manage warehouses.