dolibarr 21.0.3
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
26require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
27require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
28
29
37{
38 global $db, $langs, $conf, $user;
39
40 // Load translation files required by the page
41 $langs->loadLangs(array("sendings", "deliveries"));
42
43 $h = 0;
44 $head = array();
45
46 $head[$h][0] = DOL_URL_ROOT."/expedition/card.php?id=".$object->id;
47 $head[$h][1] = $langs->trans("SendingCard");
48 $head[$h][2] = 'shipping';
49 $h++;
50
51 if ($object->statut == Expedition::STATUS_DRAFT) {
52 $head[$h][0] = DOL_URL_ROOT."/expedition/dispatch.php?id=".$object->id;
53 $head[$h][1] = $langs->trans("ShipmentDistribution");
54 $head[$h][2] = 'dispatch';
55 $h++;
56 }
57
58 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && $user->hasRight('expedition', 'delivery', 'lire')) {
59 // delivery link
60 $object->fetchObjectLinked($object->id, $object->element);
61 if (isset($object->linkedObjectsIds['delivery']) && is_array($object->linkedObjectsIds['delivery']) && count($object->linkedObjectsIds['delivery']) > 0) { // If there is a delivery
62 // Take first element of array
63 $tmp = reset($object->linkedObjectsIds['delivery']);
64
65 $head[$h][0] = DOL_URL_ROOT."/delivery/card.php?id=".((int) $tmp);
66 $head[$h][1] = $langs->trans("DeliveryCard");
67 $head[$h][2] = 'delivery';
68 $h++;
69 }
70 }
71
72 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
73 $objectsrc = $object;
74 if ($object->origin == 'commande' && $object->origin_id > 0) {
75 $objectsrc = new Commande($db);
76 $objectsrc->fetch($object->origin_id);
77 }
78 $nbContact = count($objectsrc->liste_contact(-1, 'internal')) + count($objectsrc->liste_contact(-1, 'external'));
79 $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".((int) $object->id);
80 $head[$h][1] = $langs->trans("ContactsAddresses");
81 if ($nbContact > 0) {
82 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
83 }
84 $head[$h][2] = 'contact';
85 $h++;
86 }
87
88 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
89 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
90 $upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($object->ref);
91 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
92 $nbLinks = Link::count($db, $object->element, $object->id);
93 $head[$h][0] = DOL_URL_ROOT.'/expedition/document.php?id='.$object->id;
94 $head[$h][1] = $langs->trans('Documents');
95 if (($nbFiles + $nbLinks) > 0) {
96 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
97 }
98 $head[$h][2] = 'documents';
99 $h++;
100
101 $nbNote = 0;
102 if (!empty($object->note_private)) {
103 $nbNote++;
104 }
105 if (!empty($object->note_public)) {
106 $nbNote++;
107 }
108 $head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$object->id;
109 $head[$h][1] = $langs->trans("Notes");
110 if ($nbNote > 0) {
111 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
112 }
113 $head[$h][2] = 'note';
114 $h++;
115
116 // Show more tabs from modules
117 // Entries must be declared in modules descriptor with line
118 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
119 // $this->tabs = array('entity:-tabname); to remove a tab
120 complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery');
121
122 complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery', 'remove');
123
124 return $head;
125}
126
127
135{
136 global $langs, $db, $conf, $user;
137
138 // Load translation files required by the page
139 $langs->loadLangs(array("sendings", "deliveries"));
140
141 $h = 0;
142 $head = array();
143
144 if (getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && $user->hasRight('expedition', 'lire')) {
145 $head[$h][0] = DOL_URL_ROOT."/expedition/card.php?id=".$object->origin_id;
146 $head[$h][1] = $langs->trans("SendingCard");
147 $head[$h][2] = 'shipping';
148 $h++;
149 }
150
151 $head[$h][0] = DOL_URL_ROOT."/delivery/card.php?id=".$object->id;
152 $head[$h][1] = $langs->trans("DeliveryCard");
153 $head[$h][2] = 'delivery';
154 $h++;
155
156 // Show more tabs from modules
157 // Entries must be declared in modules descriptor with line
158 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
159 // $this->tabs = array('entity:-tabname); to remove a tab
160 // complete_head_from_modules use $object->id for this link so we temporary change it
161
162 $savObjectId = $object->id;
163
164 // Get parent object
165 $tmpobject = null;
166 if ($object->origin) {
167 $tmpobject = new Expedition($db);
168 $tmpobject->fetch($object->origin_id);
169 } else {
170 $tmpobject = $object;
171 }
172
173 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
174 $objectsrc = $tmpobject;
175 if ($tmpobject->origin == 'commande' && $tmpobject->origin_id > 0) {
176 $objectsrc = new Commande($db);
177 $objectsrc->fetch($tmpobject->origin_id);
178 }
179 $nbContact = count($objectsrc->liste_contact(-1, 'internal')) + count($objectsrc->liste_contact(-1, 'external'));
180 $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$tmpobject->id;
181 $head[$h][1] = $langs->trans("ContactsAddresses");
182 if ($nbContact > 0) {
183 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
184 }
185 $head[$h][2] = 'contact';
186 $h++;
187 }
188
189 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
190 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
191 $upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($tmpobject->ref);
192 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
193 $nbLinks = Link::count($db, $tmpobject->element, $tmpobject->id);
194 $head[$h][0] = DOL_URL_ROOT.'/expedition/document.php?id='.$tmpobject->id;
195 $head[$h][1] = $langs->trans('Documents');
196 if (($nbFiles + $nbLinks) > 0) {
197 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
198 }
199 $head[$h][2] = 'documents';
200 $h++;
201
202 $nbNote = 0;
203 if (!empty($tmpobject->note_private)) {
204 $nbNote++;
205 }
206 if (!empty($tmpobject->note_public)) {
207 $nbNote++;
208 }
209 $head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$tmpobject->id;
210 $head[$h][1] = $langs->trans("Notes");
211 if ($nbNote > 0) {
212 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
213 }
214 $head[$h][2] = 'note';
215 $h++;
216
217 $object->id = $tmpobject->id;
218
219 complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery');
220
221 complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery', 'remove');
222
223 $object->id = $savObjectId;
224 return $head;
225}
226
235function show_list_sending_receive($origin, $origin_id, $filter = '')
236{
237 global $db, $conf, $langs;
238 global $form;
239
240 $product_static = new Product($db);
241 $expedition = new Expedition($db);
242 $warehousestatic = new Entrepot($db);
243
244 $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,";
245 $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,";
246 $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, e.signed_status,";
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"; // for example llx_commandedet
252 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
253 //TODO Add link to expeditiondet_batch
254 $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
255 $sql .= " AND obj.fk_".$origin." = ".((int) $origin_id);
256 $sql .= " AND obj.rowid = ed.fk_elementdet";
257 $sql .= " AND ed.fk_expedition = e.rowid";
258 if ($filter) {
259 $sql .= $filter;
260 }
261 $sql .= " ORDER BY obj.rowid, obj.fk_product";
262
263 dol_syslog("show_list_sending_receive", LOG_DEBUG);
264 $resql = $db->query($sql);
265 if ($resql) {
266 $num = $db->num_rows($resql);
267 $i = 0;
268
269 if ($num) {
270 if ($filter) {
271 print load_fiche_titre($langs->trans("OtherSendingsForSameOrder"));
272 } else {
273 print load_fiche_titre($langs->trans("SendingsAndReceivingForSameOrder"));
274 }
275
276 print '<div class="div-table-responsive-no-min">';
277 print '<table class="liste centpercent">';
278 print '<tr class="liste_titre">';
279 //print '<td class="left">'.$langs->trans("QtyOrdered").'</td>';
280 print '<td>'.$langs->trans("SendingSheet").'</td>';
281 print '<td>'.$langs->trans("Description").'</td>';
282 print '<td class="center">'.$langs->trans("DateCreation").'</td>';
283 print '<td class="center">'.$langs->trans("DateDeliveryPlanned").'</td>';
284 print '<td class="center">'.$langs->trans("QtyPreparedOrShipped").'</td>';
285 if (isModEnabled('stock')) {
286 print '<td>'.$langs->trans("Warehouse").'</td>';
287 }
288 /*TODO Add link to expeditiondet_batch
289 if (isModEnabled('productbatch'))
290 {
291 print '<td>';
292 print '</td>';
293 }*/
294 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
295 print '<td>'.$langs->trans("DeliveryOrder").'</td>';
296 //print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
297 print '<td class="right">'.$langs->trans("DeliveryDate").'</td>';
298 }
299 print "</tr>\n";
300
301 while ($i < $num) {
302 $objp = $db->fetch_object($resql);
303
304 $expedition->id = $objp->expedition_id;
305 $expedition->ref = $objp->exp_ref;
306 $expedition->billed = $objp->billed;
307 $expedition->statut = $objp->status;
308 $expedition->status = $objp->status;
309 $expedition->signed_status = $objp->signed_status;
310
311 print '<tr class="oddeven">';
312
313 // Sending id
314 print '<td class="tdoverflowmax125">';
315 print $expedition->getNomUrl(1);
316 //print '<a href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"), 'sending').' '.$objp->exp_ref.'<a>';
317 print '</td>';
318
319 // Description
320 if ($objp->fk_product > 0) {
321 // Define output language
322 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
323 $object = new $origin($db);
324 '@phan-var-force CommonObject $object';
325 $object->fetch($origin_id);
326 $object->fetch_thirdparty();
327
328 $prod = new Product($db);
329 $prod->id = $objp->fk_product;
330 $prod->getMultiLangs();
331
332 $outputlangs = $langs;
333 $newlang = '';
334 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
335 $newlang = GETPOST('lang_id', 'aZ09');
336 }
337 if (empty($newlang)) {
338 $newlang = $object->thirdparty->default_lang;
339 }
340 if (!empty($newlang)) {
341 $outputlangs = new Translate("", $conf);
342 $outputlangs->setDefaultLang($newlang);
343 }
344
345 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
346 } else {
347 $label = (!empty($objp->label) ? $objp->label : $objp->product_label);
348 }
349
350 print '<td>';
351
352 // Show product and description
353 $product_static->type = $objp->fk_product_type;
354 $product_static->id = $objp->fk_product;
355 $product_static->ref = $objp->ref;
356 $product_static->status_batch = $objp->product_tobatch;
357
358 $text = $product_static->getNomUrl(1);
359 $text .= ' - '.$label;
360 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
361 print $form->textwithtooltip($text, $description, 3, 0, '', $i);
362
363 // Show range
364 print_date_range($objp->date_start, $objp->date_end);
365
366 // Add description in form
367 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
368 print(!empty($objp->description) ? ((empty($objp->product) || $objp->description != $objp->product) ? '<br>'.dol_htmlentitiesbr($objp->description) : '') : '');
369 }
370
371 print '</td>';
372 } else {
373 print "<td>";
374 if ($objp->fk_product_type == 1) {
375 $text = img_object($langs->trans('Service'), 'service');
376 } else {
377 $text = img_object($langs->trans('Product'), 'product');
378 }
379
380 if (!empty($objp->label)) {
381 $text .= ' <strong>'.$objp->label.'</strong>';
382 print $form->textwithtooltip($text, $objp->description, 3, 0, '', $i);
383 } else {
384 print $text.' '.nl2br($objp->description);
385 }
386
387 // Show range
388 print_date_range($objp->date_start, $objp->date_end);
389 print "</td>\n";
390 }
391
392 //print '<td class="center">'.$objp->qty_asked.'</td>';
393
394 // Date creation
395 print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->date_creation), 'day').'</td>';
396
397 // Date shipping creation
398 print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->date_delivery), 'day').'</td>';
399
400 // Qty shipped
401 print '<td class="center">'.$objp->qty_shipped.'</td>';
402
403 // Warehouse
404 if (isModEnabled('stock')) {
405 print '<td class="tdoverflowmax125">';
406 if ($objp->warehouse_id > 0) {
407 $warehousestatic->fetch($objp->warehouse_id);
408 print $warehousestatic->getNomUrl(1);
409 }
410 print '</td>';
411 }
412
413 // Batch number management
414 /*TODO Add link to expeditiondet_batch
415 if (isModEnabled('productbatch'))
416 {
417 //var_dump($objp->edrowid);
418 $lines[$i]->detail_batch
419 if (isset($lines[$i]->detail_batch))
420 {
421 print '<td>';
422 if ($lines[$i]->product_tobatch)
423 {
424 $detail = '';
425 foreach ($lines[$i]->detail_batch as $dbatch)
426 {
427 $detail.= $langs->trans("Batch").': '.$dbatch->batch;
428 $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
429 $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
430 $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
431 $detail.= '<br>';
432 }
433 print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
434 }
435 else
436 {
437 print $langs->trans("NA");
438 }
439 print '</td>';
440 } else {
441 print '<td></td>';
442 }
443 }*/
444
445 // Information on receipt
446 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
447 include_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
448 $expedition->fetchObjectLinked($expedition->id, $expedition->element, null, 'delivery');
449 //var_dump($expedition->linkedObjects);
450
451 $receiving = '';
452 if (!empty($expedition->linkedObjects['delivery'])) {
453 $receiving = reset($expedition->linkedObjects['delivery']); // Take first link
454 }
455
456 if (!empty($receiving)) {
457 '@phan-var-force Delivery $receiving';
458 // $expedition->fk_elementdet = id of det line of order
459 // $receiving->fk_origin_line = id of det line of order
460 // $receiving->origin may be 'shipping'
461 // $receiving->origin_id may be id of shipping
462
463 // Ref
464 print '<td>';
465 print $receiving->getNomUrl($db);
466 //print '<a href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$livraison_id.'">'.img_object($langs->trans("ShowReceiving"),'sending').' '.$objp->livraison_ref.'<a>';
467 print '</td>';
468 // Qty received
469 //print '<td class="center">';
470 // TODO No solution for the moment to link a line det of receipt with a line det of shipping,
471 // so no way to know the qty received for this line of shipping.
472 //print $langs->trans("FeatureNotYetAvailable");
473 //print '</td>';
474 // Date shipping real
475 print '<td class="right">';
476 print dol_print_date($receiving->date_delivery, 'day');
477 print '</td>';
478 } else {
479 //print '<td>&nbsp;</td>';
480 print '<td>&nbsp;</td>';
481 print '<td>&nbsp;</td>';
482 }
483 }
484 print '</tr>';
485 $i++;
486 }
487
488 print '</table>';
489 print '</div>';
490 }
491 $db->free($resql);
492 } else {
493 dol_print_error($db);
494 }
495
496 return 1;
497}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class to manage customers orders.
Class to manage warehouses.
const STATUS_DRAFT
Draft status.
Class to manage products or services.
Class to manage translations.
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, $allowothertags=array())
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_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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.