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