dolibarr  9.0.0
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@inodbox.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  // Load translation files required by the page
40  $langs->loadLangs(array("sendings","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  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
83  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
84  $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref);
85  $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
86  $nbLinks=Link::count($db, $object->element, $object->id);
87  $head[$h][0] = DOL_URL_ROOT.'/expedition/document.php?id='.$object->id;
88  $head[$h][1] = $langs->trans('Documents');
89  if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
90  $head[$h][2] = 'documents';
91  $h++;
92 
93  $nbNote = 0;
94  if (!empty($object->note_private)) $nbNote++;
95  if (!empty($object->note_public)) $nbNote++;
96  $head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$object->id;
97  $head[$h][1] = $langs->trans("Notes");
98  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
99  $head[$h][2] = 'note';
100  $h++;
101 
102  // Show more tabs from modules
103  // Entries must be declared in modules descriptor with line
104  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
105  // $this->tabs = array('entity:-tabname); to remove a tab
106  complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
107 
108  complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery','remove');
109 
110  return $head;
111 }
112 
113 
120 function delivery_prepare_head($object)
121 {
122  global $langs, $conf, $user;
123 
124  // Load translation files required by the page
125  $langs->loadLangs(array("sendings","deliveries"));
126 
127  $h = 0;
128  $head = array();
129 
130  if ($conf->expedition_bon->enabled && $user->rights->expedition->lire)
131  {
132  $head[$h][0] = DOL_URL_ROOT."/expedition/card.php?id=".$object->origin_id;
133  $head[$h][1] = $langs->trans("SendingCard");
134  $head[$h][2] = 'shipping';
135  $h++;
136  }
137 
138  $head[$h][0] = DOL_URL_ROOT."/livraison/card.php?id=".$object->id;
139  $head[$h][1] = $langs->trans("DeliveryCard");
140  $head[$h][2] = 'delivery';
141  $h++;
142 
143  $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$object->origin_id;
144  $head[$h][1] = $langs->trans("ContactsAddresses");
145  $head[$h][2] = 'contact';
146  $h++;
147 
148  $head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$object->origin_id;
149  $head[$h][1] = $langs->trans("Notes");
150  $head[$h][2] = 'note';
151  $h++;
152 
153  // Show more tabs from modules
154  // Entries must be declared in modules descriptor with line
155  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
156  // $this->tabs = array('entity:-tabname); to remove a tab
157  // complete_head_from_modules use $object->id for this link so we temporary change it
158  $tmpObjectId = $object->id;
159  $object->id = $object->origin_id;
160 
161  complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery');
162 
163  complete_head_from_modules($conf,$langs,$object,$head,$h,'delivery','remove');
164 
165  $object->id = $tmpObjectId;
166  return $head;
167 }
168 
177 function show_list_sending_receive($origin,$origin_id,$filter='')
178 {
179  global $db, $conf, $langs, $bc;
180  global $form;
181 
182  $product_static=new Product($db);
183  $expedition=new Expedition($db);
184  $warehousestatic=new Entrepot($db);
185 
186  $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,";
187  $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,";
188  $sql.= " e.rowid as sendingid, e.ref as exp_ref, e.date_creation, e.date_delivery, e.date_expedition,";
189  //if ($conf->livraison_bon->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received,";
190  $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch,';
191  $sql.= ' p.description as product_desc';
192  $sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
193  $sql.= ", ".MAIN_DB_PREFIX."expedition as e";
194  $sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj";
195  //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";
196  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
197  //TODO Add link to expeditiondet_batch
198  $sql.= " WHERE e.entity IN (".getEntity('expedition').")";
199  $sql.= " AND obj.fk_".$origin." = ".$origin_id;
200  $sql.= " AND obj.rowid = ed.fk_origin_line";
201  $sql.= " AND ed.fk_expedition = e.rowid";
202  if ($filter) $sql.= $filter;
203 
204  $sql.= " ORDER BY obj.fk_product";
205 
206  dol_syslog("show_list_sending_receive", LOG_DEBUG);
207  $resql = $db->query($sql);
208  if ($resql)
209  {
210  $num = $db->num_rows($resql);
211  $i = 0;
212 
213  if ($num)
214  {
215  if ($filter) print load_fiche_titre($langs->trans("OtherSendingsForSameOrder"));
216  else print load_fiche_titre($langs->trans("SendingsAndReceivingForSameOrder"));
217 
218  print '<table class="liste" width="100%">';
219  print '<tr class="liste_titre">';
220  //print '<td align="left">'.$langs->trans("QtyOrdered").'</td>';
221  print '<td align="left">'.$langs->trans("SendingSheet").'</td>';
222  print '<td align="left">'.$langs->trans("Description").'</td>';
223  print '<td align="center">'.$langs->trans("DateCreation").'</td>';
224  print '<td align="center">'.$langs->trans("DateDeliveryPlanned").'</td>';
225  print '<td align="center">'.$langs->trans("QtyPreparedOrShipped").'</td>';
226  if (! empty($conf->stock->enabled))
227  {
228  print '<td>'.$langs->trans("Warehouse").'</td>';
229  }
230  /*TODO Add link to expeditiondet_batch
231  if (! empty($conf->productbatch->enabled))
232  {
233  print '<td>';
234  print '</td>';
235  }*/
236  if (! empty($conf->livraison_bon->enabled))
237  {
238  print '<td>'.$langs->trans("DeliveryOrder").'</td>';
239  //print '<td align="center">'.$langs->trans("QtyReceived").'</td>';
240  print '<td align="right">'.$langs->trans("DeliveryDate").'</td>';
241  }
242  print "</tr>\n";
243 
244  while ($i < $num)
245  {
246  $objp = $db->fetch_object($resql);
247 
248  print '<tr class="oddeven">';
249 
250  // Sending id
251  print '<td align="left" class="nowrap">';
252  print '<a href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->exp_ref.'<a>';
253  print '</td>';
254 
255  // Description
256  if ($objp->fk_product > 0)
257  {
258  // Define output language
259  if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
260  {
261  $object = new $origin($db);
262  $object->fetch($origin_id);
263  $object->fetch_thirdparty();
264 
265  $prod = new Product($db);
266  $prod->id=$objp->fk_product;
267  $prod->getMultiLangs();
268 
269  $outputlangs = $langs;
270  $newlang='';
271  if (empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
272  if (empty($newlang)) $newlang=$object->thirdparty->default_lang;
273  if (! empty($newlang))
274  {
275  $outputlangs = new Translate("",$conf);
276  $outputlangs->setDefaultLang($newlang);
277  }
278 
279  $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
280  }
281  else
282  {
283  $label = (! empty($objp->label)?$objp->label:$objp->product_label);
284  }
285 
286  print '<td>';
287 
288  // Show product and description
289  $product_static->type=$objp->fk_product_type;
290  $product_static->id=$objp->fk_product;
291  $product_static->ref=$objp->ref;
292  $product_static->status_batch=$objp->product_tobatch;
293  $text=$product_static->getNomUrl(1);
294  $text.= ' - '.$label;
295  $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($objp->description));
296  print $form->textwithtooltip($text,$description,3,'','',$i);
297 
298  // Show range
299  print_date_range($objp->date_start,$objp->date_end);
300 
301  // Add description in form
302  if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
303  {
304  print (! empty($objp->description) && $objp->description!=$objp->product)?'<br>'.dol_htmlentitiesbr($objp->description):'';
305  }
306 
307  print '</td>';
308  }
309  else
310  {
311  print "<td>";
312  if ($objp->fk_product_type==1) $text = img_object($langs->trans('Service'),'service');
313  else $text = img_object($langs->trans('Product'),'product');
314 
315  if (! empty($objp->label)) {
316  $text.= ' <strong>'.$objp->label.'</strong>';
317  print $form->textwithtooltip($text,$objp->description,3,'','',$i);
318  } else {
319  print $text.' '.nl2br($objp->description);
320  }
321 
322  // Show range
323  print_date_range($objp->date_start,$objp->date_end);
324  print "</td>\n";
325  }
326 
327  //print '<td align="center">'.$objp->qty_asked.'</td>';
328 
329  // Date creation
330  print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
331 
332  // Date shipping creation
333  print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($objp->date_delivery),'day').'</td>';
334 
335  // Qty shipped
336  print '<td align="center">'.$objp->qty_shipped.'</td>';
337 
338  // Warehouse
339  if (! empty($conf->stock->enabled))
340  {
341  print '<td>';
342  if ($objp->warehouse_id > 0)
343  {
344  $warehousestatic->fetch($objp->warehouse_id);
345  print $warehousestatic->getNomUrl(1);
346  }
347  print '</td>';
348  }
349 
350  // Batch number managment
351  /*TODO Add link to expeditiondet_batch
352  if (! empty($conf->productbatch->enabled))
353  {
354  var_dump($objp->edrowid);
355  $lines[$i]->detail_batch
356  if (isset($lines[$i]->detail_batch))
357  {
358  print '<td>';
359  if ($lines[$i]->product_tobatch)
360  {
361  $detail = '';
362  foreach ($lines[$i]->detail_batch as $dbatch)
363  {
364  $detail.= $langs->trans("Batch").': '.$dbatch->batch;
365  $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
366  $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
367  $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
368  $detail.= '<br>';
369  }
370  print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
371  }
372  else
373  {
374  print $langs->trans("NA");
375  }
376  print '</td>';
377  } else {
378  print '<td></td>';
379  }
380  }*/
381 
382  // Informations on receipt
383  if (! empty($conf->livraison_bon->enabled))
384  {
385  include_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php';
386  $expedition->id=$objp->sendingid;
387  $expedition->fetchObjectLinked($expedition->id,$expedition->element);
388  //var_dump($expedition->linkedObjects);
389 
390  $receiving='';
391  if (count($expedition->linkedObjects['delivery']) > 0) $receiving=reset($expedition->linkedObjects['delivery']); // Take first link
392 
393  if (! empty($receiving))
394  {
395  // $expedition->fk_origin_line = id of det line of order
396  // $receiving->fk_origin_line = id of det line of order
397  // $receiving->origin may be 'shipping'
398  // $receiving->origin_id may be id of shipping
399 
400  // Ref
401  print '<td>';
402  print $receiving->getNomUrl($db);
403  //print '<a href="'.DOL_URL_ROOT.'/livraison/card.php?id='.$livraison_id.'">'.img_object($langs->trans("ShowReceiving"),'sending').' '.$objp->livraison_ref.'<a>';
404  print '</td>';
405  // Qty received
406  //print '<td align="center">';
407  // TODO No solution for the moment to link a line det of receipt with a line det of shipping,
408  // so no way to know the qty received for this line of shipping.
409  //print $langs->trans("FeatureNotYetAvailable");
410  //print '</td>';
411  // Date shipping real
412  print '<td align="right">';
413  print dol_print_date($receiving->date_delivery,'day');
414  print '</td>';
415  }
416  else
417  {
418  //print '<td>&nbsp;</td>';
419  print '<td>&nbsp;</td>';
420  print '<td>&nbsp;</td>';
421  }
422  }
423  print '</tr>';
424  $i++;
425  }
426 
427  print '</table>';
428  }
429  $db->free($resql);
430  }
431  else
432  {
433  dol_print_error($db);
434  }
435 
436  return 1;
437 }
438 
shipping_prepare_head($object)
Prepare array with list of tabs.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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:1053
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
print_date_range($date_start, $date_end, $format='', $outputlangs='')
Format output for start and end date.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage shipments.
Class to manage customers orders.
Class to manage translations.
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:59
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage warehouses.