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