dolibarr  21.0.0-alpha
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 
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->hasRight('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 element of array
62  $tmp = reset($object->linkedObjectsIds['delivery']);
63 
64  $head[$h][0] = DOL_URL_ROOT."/delivery/card.php?id=".((int) $tmp);
65  $head[$h][1] = $langs->trans("DeliveryCard");
66  $head[$h][2] = 'delivery';
67  $h++;
68  }
69  }
70 
71  if (!getDolGlobalString('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=".((int) $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 
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->hasRight('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 (!getDolGlobalString('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_elementdet, 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, e.billed, e.fk_statut as status,";
246  $sql .= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch,';
247  $sql .= ' p.description as product_desc';
248  $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed,";
249  $sql .= " ".MAIN_DB_PREFIX."expedition as e,";
250  $sql .= " ".MAIN_DB_PREFIX.$origin."det as obj"; // for example llx_commandedet
251  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
252  //TODO Add link to expeditiondet_batch
253  $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
254  $sql .= " AND obj.fk_".$origin." = ".((int) $origin_id);
255  $sql .= " AND obj.rowid = ed.fk_elementdet";
256  $sql .= " AND ed.fk_expedition = e.rowid";
257  if ($filter) {
258  $sql .= $filter;
259  }
260  $sql .= " ORDER BY obj.rowid, obj.fk_product";
261 
262  dol_syslog("show_list_sending_receive", LOG_DEBUG);
263  $resql = $db->query($sql);
264  if ($resql) {
265  $num = $db->num_rows($resql);
266  $i = 0;
267 
268  if ($num) {
269  if ($filter) {
270  print load_fiche_titre($langs->trans("OtherSendingsForSameOrder"));
271  } else {
272  print load_fiche_titre($langs->trans("SendingsAndReceivingForSameOrder"));
273  }
274 
275  print '<table class="liste centpercent">';
276  print '<tr class="liste_titre">';
277  //print '<td class="left">'.$langs->trans("QtyOrdered").'</td>';
278  print '<td>'.$langs->trans("SendingSheet").'</td>';
279  print '<td>'.$langs->trans("Description").'</td>';
280  print '<td class="center">'.$langs->trans("DateCreation").'</td>';
281  print '<td class="center">'.$langs->trans("DateDeliveryPlanned").'</td>';
282  print '<td class="center">'.$langs->trans("QtyPreparedOrShipped").'</td>';
283  if (isModEnabled('stock')) {
284  print '<td>'.$langs->trans("Warehouse").'</td>';
285  }
286  /*TODO Add link to expeditiondet_batch
287  if (!empty($conf->productbatch->enabled))
288  {
289  print '<td>';
290  print '</td>';
291  }*/
292  if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
293  print '<td>'.$langs->trans("DeliveryOrder").'</td>';
294  //print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
295  print '<td class="right">'.$langs->trans("DeliveryDate").'</td>';
296  }
297  print "</tr>\n";
298 
299  while ($i < $num) {
300  $objp = $db->fetch_object($resql);
301 
302  $expedition->id = $objp->expedition_id;
303  $expedition->ref = $objp->exp_ref;
304  $expedition->billed = $objp->billed;
305  $expedition->statut = $objp->status;
306  $expedition->status = $objp->status;
307 
308  print '<tr class="oddeven">';
309 
310  // Sending id
311  print '<td class="nowrap left">';
312  print $expedition->getNomUrl(1);
313  //print '<a href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"), 'sending').' '.$objp->exp_ref.'<a>';
314  print '</td>';
315 
316  // Description
317  if ($objp->fk_product > 0) {
318  // Define output language
319  if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
320  $object = new $origin($db);
321  $object->fetch($origin_id);
322  $object->fetch_thirdparty();
323 
324  $prod = new Product($db);
325  $prod->id = $objp->fk_product;
326  $prod->getMultiLangs();
327 
328  $outputlangs = $langs;
329  $newlang = '';
330  if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
331  $newlang = GETPOST('lang_id', 'aZ09');
332  }
333  if (empty($newlang)) {
334  $newlang = $object->thirdparty->default_lang;
335  }
336  if (!empty($newlang)) {
337  $outputlangs = new Translate("", $conf);
338  $outputlangs->setDefaultLang($newlang);
339  }
340 
341  $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
342  } else {
343  $label = (!empty($objp->label) ? $objp->label : $objp->product_label);
344  }
345 
346  print '<td>';
347 
348  // Show product and description
349  $product_static->type = $objp->fk_product_type;
350  $product_static->id = $objp->fk_product;
351  $product_static->ref = $objp->ref;
352  $product_static->status_batch = $objp->product_tobatch;
353 
354  $text = $product_static->getNomUrl(1);
355  $text .= ' - '.$label;
356  $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
357  print $form->textwithtooltip($text, $description, 3, '', '', $i);
358 
359  // Show range
360  print_date_range($objp->date_start, $objp->date_end);
361 
362  // Add description in form
363  if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
364  print (!empty($objp->description) ? ((empty($objp->product) || $objp->description != $objp->product) ? '<br>'.dol_htmlentitiesbr($objp->description) : '') : '');
365  }
366 
367  print '</td>';
368  } else {
369  print "<td>";
370  if ($objp->fk_product_type == 1) {
371  $text = img_object($langs->trans('Service'), 'service');
372  } else {
373  $text = img_object($langs->trans('Product'), 'product');
374  }
375 
376  if (!empty($objp->label)) {
377  $text .= ' <strong>'.$objp->label.'</strong>';
378  print $form->textwithtooltip($text, $objp->description, 3, '', '', $i);
379  } else {
380  print $text.' '.nl2br($objp->description);
381  }
382 
383  // Show range
384  print_date_range($objp->date_start, $objp->date_end);
385  print "</td>\n";
386  }
387 
388  //print '<td class="center">'.$objp->qty_asked.'</td>';
389 
390  // Date creation
391  print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->date_creation), 'day').'</td>';
392 
393  // Date shipping creation
394  print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->date_delivery), 'day').'</td>';
395 
396  // Qty shipped
397  print '<td class="center">'.$objp->qty_shipped.'</td>';
398 
399  // Warehouse
400  if (isModEnabled('stock')) {
401  print '<td>';
402  if ($objp->warehouse_id > 0) {
403  $warehousestatic->fetch($objp->warehouse_id);
404  print $warehousestatic->getNomUrl(1);
405  }
406  print '</td>';
407  }
408 
409  // Batch number management
410  /*TODO Add link to expeditiondet_batch
411  if (!empty($conf->productbatch->enabled))
412  {
413  //var_dump($objp->edrowid);
414  $lines[$i]->detail_batch
415  if (isset($lines[$i]->detail_batch))
416  {
417  print '<td>';
418  if ($lines[$i]->product_tobatch)
419  {
420  $detail = '';
421  foreach ($lines[$i]->detail_batch as $dbatch)
422  {
423  $detail.= $langs->trans("Batch").': '.$dbatch->batch;
424  $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
425  $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
426  $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
427  $detail.= '<br>';
428  }
429  print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
430  }
431  else
432  {
433  print $langs->trans("NA");
434  }
435  print '</td>';
436  } else {
437  print '<td></td>';
438  }
439  }*/
440 
441  // Information on receipt
442  if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
443  include_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
444  $expedition->fetchObjectLinked($expedition->id, $expedition->element);
445  //var_dump($expedition->linkedObjects);
446 
447  $receiving = '';
448  if (!empty($expedition->linkedObjects['delivery'])) {
449  $receiving = reset($expedition->linkedObjects['delivery']); // Take first link
450  }
451 
452  if (!empty($receiving)) {
453  // $expedition->fk_elementdet = id of det line of order
454  // $receiving->fk_origin_line = id of det line of order
455  // $receiving->origin may be 'shipping'
456  // $receiving->origin_id may be id of shipping
457 
458  // Ref
459  print '<td>';
460  print $receiving->getNomUrl($db);
461  //print '<a href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$livraison_id.'">'.img_object($langs->trans("ShowReceiving"),'sending').' '.$objp->livraison_ref.'<a>';
462  print '</td>';
463  // Qty received
464  //print '<td class="center">';
465  // TODO No solution for the moment to link a line det of receipt with a line det of shipping,
466  // so no way to know the qty received for this line of shipping.
467  //print $langs->trans("FeatureNotYetAvailable");
468  //print '</td>';
469  // Date shipping real
470  print '<td class="right">';
471  print dol_print_date($receiving->date_delivery, 'day');
472  print '</td>';
473  } else {
474  //print '<td>&nbsp;</td>';
475  print '<td>&nbsp;</td>';
476  print '<td>&nbsp;</td>';
477  }
478  }
479  print '</tr>';
480  $i++;
481  }
482 
483  print '</table>';
484  }
485  $db->free($resql);
486  } else {
487  dol_print_error($db);
488  }
489 
490  return 1;
491 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('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') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
dol_dir_list($utf8_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:63
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_date_range($date_start, $date_end, $format='', $outputlangs=null)
Format output for start and end date.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.