dolibarr  13.0.2
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 <https://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->delivery_note->enabled && $user->rights->expedition->delivery->lire)
51  {
52  // delivery link
53  $object->fetchObjectLinked($object->id, $object->element);
54  if (is_array($object->linkedObjectsIds['delivery']) && 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."/delivery/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 marginleftonlyshort">'.$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->expedition->dir_output."/sending/".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 marginleftonlyshort">'.($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 marginleftonlyshort">'.$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, $db, $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."/delivery/card.php?id=".$object->id;
139  $head[$h][1] = $langs->trans("DeliveryCard");
140  $head[$h][2] = 'delivery';
141  $h++;
142 
143  // Show more tabs from modules
144  // Entries must be declared in modules descriptor with line
145  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
146  // $this->tabs = array('entity:-tabname); to remove a tab
147  // complete_head_from_modules use $object->id for this link so we temporary change it
148 
149  $savObjectId = $object->id;
150 
151  // Get parent object
152  $tmpobject = null;
153  if ($object->origin) {
154  $tmpobject = new Expedition($db);
155  $tmpobject->fetch($object->origin_id);
156  } else {
157  $tmpobject = $object;
158  }
159 
160  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
161  {
162  $objectsrc = $tmpobject;
163  if ($tmpobject->origin == 'commande' && $tmpobject->origin_id > 0)
164  {
165  $objectsrc = new Commande($db);
166  $objectsrc->fetch($tmpobject->origin_id);
167  }
168  $nbContact = count($objectsrc->liste_contact(-1, 'internal')) + count($objectsrc->liste_contact(-1, 'external'));
169  $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$tmpobject->id;
170  $head[$h][1] = $langs->trans("ContactsAddresses");
171  if ($nbContact > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
172  $head[$h][2] = 'contact';
173  $h++;
174  }
175 
176  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
177  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
178  $upload_dir = $conf->commande->dir_output."/".dol_sanitizeFileName($tmpobject->ref);
179  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
180  $nbLinks = Link::count($db, $tmpobject->element, $tmpobject->id);
181  $head[$h][0] = DOL_URL_ROOT.'/expedition/document.php?id='.$tmpobject->id;
182  $head[$h][1] = $langs->trans('Documents');
183  if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
184  $head[$h][2] = 'documents';
185  $h++;
186 
187  $nbNote = 0;
188  if (!empty($tmpobject->note_private)) $nbNote++;
189  if (!empty($tmpobject->note_public)) $nbNote++;
190  $head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$tmpobject->id;
191  $head[$h][1] = $langs->trans("Notes");
192  if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
193  $head[$h][2] = 'note';
194  $h++;
195 
196  $object->id = $tmpobject->id;
197 
198  complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery');
199 
200  complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery', 'remove');
201 
202  $object->id = $savObjectId;
203  return $head;
204 }
205 
214 function show_list_sending_receive($origin, $origin_id, $filter = '')
215 {
216  global $db, $conf, $langs;
217  global $form;
218 
219  $product_static = new Product($db);
220  $expedition = new Expedition($db);
221  $warehousestatic = new Entrepot($db);
222 
223  $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,";
224  $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,";
225  $sql .= " e.rowid as sendingid, e.ref as exp_ref, e.date_creation, e.date_delivery, e.date_expedition,";
226  //if ($conf->delivery_note->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received,";
227  $sql .= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch,';
228  $sql .= ' p.description as product_desc';
229  $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
230  $sql .= ", ".MAIN_DB_PREFIX."expedition as e";
231  $sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj";
232  //if ($conf->delivery_note->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid AND obj.rowid = ld.fk_origin_line";
233  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
234  //TODO Add link to expeditiondet_batch
235  $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
236  $sql .= " AND obj.fk_".$origin." = ".$origin_id;
237  $sql .= " AND obj.rowid = ed.fk_origin_line";
238  $sql .= " AND ed.fk_expedition = e.rowid";
239  if ($filter) $sql .= $filter;
240 
241  $sql .= " ORDER BY obj.fk_product";
242 
243  dol_syslog("show_list_sending_receive", LOG_DEBUG);
244  $resql = $db->query($sql);
245  if ($resql)
246  {
247  $num = $db->num_rows($resql);
248  $i = 0;
249 
250  if ($num)
251  {
252  if ($filter) print load_fiche_titre($langs->trans("OtherSendingsForSameOrder"));
253  else print load_fiche_titre($langs->trans("SendingsAndReceivingForSameOrder"));
254 
255  print '<table class="liste centpercent">';
256  print '<tr class="liste_titre">';
257  //print '<td class="left">'.$langs->trans("QtyOrdered").'</td>';
258  print '<td>'.$langs->trans("SendingSheet").'</td>';
259  print '<td>'.$langs->trans("Description").'</td>';
260  print '<td class="center">'.$langs->trans("DateCreation").'</td>';
261  print '<td class="center">'.$langs->trans("DateDeliveryPlanned").'</td>';
262  print '<td class="center">'.$langs->trans("QtyPreparedOrShipped").'</td>';
263  if (!empty($conf->stock->enabled))
264  {
265  print '<td>'.$langs->trans("Warehouse").'</td>';
266  }
267  /*TODO Add link to expeditiondet_batch
268  if (! empty($conf->productbatch->enabled))
269  {
270  print '<td>';
271  print '</td>';
272  }*/
273  if (!empty($conf->delivery_note->enabled))
274  {
275  print '<td>'.$langs->trans("DeliveryOrder").'</td>';
276  //print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
277  print '<td class="right">'.$langs->trans("DeliveryDate").'</td>';
278  }
279  print "</tr>\n";
280 
281  while ($i < $num)
282  {
283  $objp = $db->fetch_object($resql);
284 
285  print '<tr class="oddeven">';
286 
287  // Sending id
288  print '<td class="nowrap left">';
289  print '<a href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"), 'sending').' '.$objp->exp_ref.'<a>';
290  print '</td>';
291 
292  // Description
293  if ($objp->fk_product > 0)
294  {
295  // Define output language
296  if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
297  {
298  $object = new $origin($db);
299  $object->fetch($origin_id);
300  $object->fetch_thirdparty();
301 
302  $prod = new Product($db);
303  $prod->id = $objp->fk_product;
304  $prod->getMultiLangs();
305 
306  $outputlangs = $langs;
307  $newlang = '';
308  if (empty($newlang) && !empty($_REQUEST['lang_id'])) $newlang = $_REQUEST['lang_id'];
309  if (empty($newlang)) $newlang = $object->thirdparty->default_lang;
310  if (!empty($newlang))
311  {
312  $outputlangs = new Translate("", $conf);
313  $outputlangs->setDefaultLang($newlang);
314  }
315 
316  $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
317  } else {
318  $label = (!empty($objp->label) ? $objp->label : $objp->product_label);
319  }
320 
321  print '<td>';
322 
323  // Show product and description
324  $product_static->type = $objp->fk_product_type;
325  $product_static->id = $objp->fk_product;
326  $product_static->ref = $objp->ref;
327  $product_static->status_batch = $objp->product_tobatch;
328  $text = $product_static->getNomUrl(1);
329  $text .= ' - '.$label;
330  $description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($objp->description));
331  print $form->textwithtooltip($text, $description, 3, '', '', $i);
332 
333  // Show range
334  print_date_range($objp->date_start, $objp->date_end);
335 
336  // Add description in form
337  if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
338  {
339  print (!empty($objp->description) && $objp->description != $objp->product) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
340  }
341 
342  print '</td>';
343  } else {
344  print "<td>";
345  if ($objp->fk_product_type == 1) $text = img_object($langs->trans('Service'), 'service');
346  else $text = img_object($langs->trans('Product'), 'product');
347 
348  if (!empty($objp->label)) {
349  $text .= ' <strong>'.$objp->label.'</strong>';
350  print $form->textwithtooltip($text, $objp->description, 3, '', '', $i);
351  } else {
352  print $text.' '.nl2br($objp->description);
353  }
354 
355  // Show range
356  print_date_range($objp->date_start, $objp->date_end);
357  print "</td>\n";
358  }
359 
360  //print '<td class="center">'.$objp->qty_asked.'</td>';
361 
362  // Date creation
363  print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->date_creation), 'day').'</td>';
364 
365  // Date shipping creation
366  print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->date_delivery), 'day').'</td>';
367 
368  // Qty shipped
369  print '<td class="center">'.$objp->qty_shipped.'</td>';
370 
371  // Warehouse
372  if (!empty($conf->stock->enabled))
373  {
374  print '<td>';
375  if ($objp->warehouse_id > 0)
376  {
377  $warehousestatic->fetch($objp->warehouse_id);
378  print $warehousestatic->getNomUrl(1);
379  }
380  print '</td>';
381  }
382 
383  // Batch number managment
384  /*TODO Add link to expeditiondet_batch
385  if (! empty($conf->productbatch->enabled))
386  {
387  var_dump($objp->edrowid);
388  $lines[$i]->detail_batch
389  if (isset($lines[$i]->detail_batch))
390  {
391  print '<td>';
392  if ($lines[$i]->product_tobatch)
393  {
394  $detail = '';
395  foreach ($lines[$i]->detail_batch as $dbatch)
396  {
397  $detail.= $langs->trans("Batch").': '.$dbatch->batch;
398  $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
399  $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
400  $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
401  $detail.= '<br>';
402  }
403  print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
404  }
405  else
406  {
407  print $langs->trans("NA");
408  }
409  print '</td>';
410  } else {
411  print '<td></td>';
412  }
413  }*/
414 
415  // Informations on receipt
416  if (!empty($conf->delivery_note->enabled))
417  {
418  include_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
419  $expedition->id = $objp->sendingid;
420  $expedition->fetchObjectLinked($expedition->id, $expedition->element);
421  //var_dump($expedition->linkedObjects);
422 
423  $receiving = '';
424  if (!empty($expedition->linkedObjects['delivery'])) $receiving = reset($expedition->linkedObjects['delivery']); // Take first link
425 
426  if (!empty($receiving))
427  {
428  // $expedition->fk_origin_line = id of det line of order
429  // $receiving->fk_origin_line = id of det line of order
430  // $receiving->origin may be 'shipping'
431  // $receiving->origin_id may be id of shipping
432 
433  // Ref
434  print '<td>';
435  print $receiving->getNomUrl($db);
436  //print '<a href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$livraison_id.'">'.img_object($langs->trans("ShowReceiving"),'sending').' '.$objp->livraison_ref.'<a>';
437  print '</td>';
438  // Qty received
439  //print '<td class="center">';
440  // TODO No solution for the moment to link a line det of receipt with a line det of shipping,
441  // so no way to know the qty received for this line of shipping.
442  //print $langs->trans("FeatureNotYetAvailable");
443  //print '</td>';
444  // Date shipping real
445  print '<td class="right">';
446  print dol_print_date($receiving->date_delivery, 'day');
447  print '</td>';
448  } else {
449  //print '<td>&nbsp;</td>';
450  print '<td>&nbsp;</td>';
451  print '<td>&nbsp;</td>';
452  }
453  }
454  print '</tr>';
455  $i++;
456  }
457 
458  print '</table>';
459  }
460  $db->free($resql);
461  } else {
462  dol_print_error($db);
463  }
464 
465  return 1;
466 }
shipping_prepare_head($object)
Prepare array with list of tabs.
Class to manage products or services.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom= 'UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
show_list_sending_receive($origin, $origin_id, $filter= '')
List sendings and receive receipts.
delivery_prepare_head($object)
Prepare array with list of tabs.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage shipments.
Class to manage customers orders.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
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:60
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print_date_range($date_start, $date_end, $format= '', $outputlangs= '')
Format output for start and end date.
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(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
Class to manage warehouses.