-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pickup_soc_reports.php
511 lines (450 loc) · 18.1 KB
/
pickup_soc_reports.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<?php
/* Copyright (C) 2021-2022 John Livingston <license@john-livingston.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file pickup/pickupindex.php
* \ingroup pickup
* \brief Home page of pickup top menu
*/
// Load Dolibarr environment
$res=0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
$tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1;
while($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; }
if (! $res && $i > 0 && file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include substr($tmp, 0, ($i+1))."/main.inc.php";
if (! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include dirname(substr($tmp, 0, ($i+1)))."/main.inc.php";
// Try main.inc.php using relative path
if (! $res && file_exists("../main.inc.php")) $res=@include "../main.inc.php";
if (! $res && file_exists("../../main.inc.php")) $res=@include "../../main.inc.php";
if (! $res && file_exists("../../../main.inc.php")) $res=@include "../../../main.inc.php";
if (! $res) die("Include of main fails");
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
dol_include_once('societe/class/societe.class.php');
dol_include_once('/pickup/class/pickup.class.php');
dol_include_once('/product/class/product.class.php');
dol_include_once('/product/stock/class/mouvementstock.class.php');
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; // for measuringUnitString
// Load translation files required by the page
$langs->loadLangs(array("stocks", "pickup@pickup"));
// Securite acces client
if (! $user->rights->pickup->reports) accessforbidden();
$socid=GETPOST('socid', 'int');
if (isset($user->societe_id) && $user->societe_id > 0)
{
$socid = $user->societe_id;
}
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label('product');
$status_filter = GETPOST('status', 'int');
$pickup_type_filter = GETPOST('pickup_type', 'int');
$soc_filter = GETPOST('soc', 'int');
$date_startmonth = GETPOST('date_startmonth', 'int');
$date_startday = GETPOST('date_startday', 'int');
$date_startyear = GETPOST('date_startyear', 'int');
$date_endmonth = GETPOST('date_endmonth', 'int');
$date_endday = GETPOST('date_endday', 'int');
$date_endyear = GETPOST('date_endyear', 'int');
$nbofyear = 1;
// Date range
$year = GETPOST('year', 'int');
if (empty($year))
{
$year_current = strftime("%Y", dol_now());
$month_current = strftime("%m", dol_now());
$year_start = $year_current - ($nbofyear - 1);
} else {
$year_current = $year;
$month_current = strftime("%m", dol_now());
$year_start = $year - ($nbofyear - 1);
}
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
// We define date_start and date_end
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
$q = GETPOST("q") ?GETPOST("q") : 0;
if ($q == 0)
{
// We define date_start and date_end
$year_end = $year_start + ($nbofyear - 1);
$month_start = GETPOST("month") ?GETPOST("month") : 1; // january by default
if (!GETPOST('month'))
{
if (!GETPOST("year") && $month_start > $month_current)
{
$year_start--;
$year_end--;
}
$month_end = $month_start - 1;
if ($month_end < 1) $month_end = 12;
else $year_end++;
}
else $month_end = $month_start;
$date_start = dol_get_first_day($year_start, $month_start, false);
$date_end = dol_get_last_day($year_end, $month_end, false);
}
if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
}
// $date_start and $date_end are defined. We force $year_start and $nbofyear
$tmps = dol_getdate($date_start);
$year_start = $tmps['year'];
$tmpe = dol_getdate($date_end);
$year_end = $tmpe['year'];
$nbofyear = ($year_end - $year_start) + 1;
//var_dump("year_start=".$year_start." year_end=".$year_end." nbofyear=".$nbofyear." date_start=".dol_print_date($date_start, 'dayhour')." date_end=".dol_print_date($date_end, 'dayhour'));
$form = new Form($db);
llxHeader("", $langs->trans("ModulePickupName"));
function get_soc_list() {
global $db;
$sql = 'SELECT distinct(fk_soc) as soc FROM '.MAIN_DB_PREFIX.'pickup_pickup';
$result = array();
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$row = $db->fetch_object($resql);
$soc = new Societe($db);
$soc->fetch($row->soc);
$result[strval($row->soc)] = $soc->name;
$i++;
}
$db->free($resql);
} else {
dol_print_error($db);
}
asort($result);
return $result;
}
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
$periodlink = $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear - 2)."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear)."'>".img_next()."</a>" : "");
$builddate = dol_now();
/**
* Show header of a pickup report.
* Code inspired by core/lib/report.lib.php
*
* @param string $reportname Name of report
* @param string $period Period of report
* @param string $periodlink Link to switch period
* @param integer $builddate Date generation
* @return void
*/
function pickup_report_header($reportname, $period, $periodlink, $builddate, $soc_filter, $status_filter, $pickup_type_filter)
{
global $langs, $db, $conf;
print "\n\n<!-- start banner of report -->\n";
$head = array();
$h = 0;
$head[$h][0] = $_SERVER["PHP_SELF"].$varlink;
$head[$h][1] = $langs->trans("Report");
$head[$h][2] = 'report';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
dol_fiche_head($head, 'report');
print '<table class="border tableforfield centpercent">'."\n";
// Title line
print '<tr>';
print '<td width="110">'.$langs->trans("ReportName").'</td>';
print '<td>';
print $reportname;
print '</td>';
if ($periodlink) print '<td></td>';
print '</tr>'."\n";
// Period line
print '<tr>';
print '<td>'.$langs->trans("ReportPeriod").'</td>';
print '<td>';
if ($period) print $period;
if ($periodlink) print '<td class="nowraponall">'.$periodlink.'</td>';
print '</td>';
print '</tr>'."\n";
// Thirdparty
print '<tr>';
print '<td>'.$langs->trans('ThirdParty').'</td>';
print '<td>';
print '<select name="soc"><option value=""></option>';
$soc_list = get_soc_list();
foreach ($soc_list as $id => $label) {
print '<option value="'.$id.'"'.($soc_filter == $id ? ' selected="selected"' : '').'>';
print $label;
print '</option>';
}
print '</select>';
print '</td>';
// Pickup type
if (!empty($conf->global->PICKUP_USE_PICKUP_TYPE)) {
print '<tr>';
print '<td>'.$langs->trans('PickupType').'</td>';
print '<td>';
$pickup_type_options = Pickup::getPickupTypeOptions();
print '<select name="pickup_type">';
print '<option value=""></option>';
foreach ($pickup_type_options as $pickup_type_option) {
print '<option ';
print ' value="'.htmlspecialchars($pickup_type_option['value']).'"';
if ($pickup_type_filter !== '' && intval($pickup_type_filter) === intval($pickup_type_option['value'])) {
print ' selected="selected" ';
}
print '>'.htmlspecialchars($pickup_type_option['label']).'</option>';
}
print '</select>';
print '</td>';
if ($periodlink) print '<td></td>';
print '</tr>'."\n";
}
// Status
print '<tr>';
print '<td>'.$langs->trans('Status').'</td>';
print '<td>';
$tmp_pickup = new Pickup($db);
$status_options = array();
foreach (array($tmp_pickup::STATUS_DRAFT, $tmp_pickup::STATUS_PROCESSING, $tmp_pickup::STATUS_STOCK, $tmp_pickup::STATUS_SIGNED, $tmp_pickup::STATUS_DISABLED) as $status) {
$status_options[$status] = $tmp_pickup->LibStatut($status);
}
print '<select name="status">';
print '<option value=""></option>';
foreach ($status_options as $status => $label) {
print '<option value="'.$status.'"'.($status_filter !== '' && intval($status_filter) === $status ? ' selected="selected"' : '').'>'.$label.'</option>';
}
print '</select>';
print '</td>';
if ($periodlink) print '<td></td>';
print '</tr>'."\n";
// Export line
print '<tr>';
print '<td>'.$langs->trans("GeneratedOn").'</td>';
print '<td>';
print dol_print_date($builddate, 'dayhour');
print '</td>';
if ($periodlink) print '<td></td>';
print '</tr>'."\n";
print '</table>'."\n";
dol_fiche_end();
print '<div class="center"><input type="submit" class="button" name="submit" value="'.$langs->trans("Refresh").'"></div>';
print '</form>';
print '<br>';
print "\n<!-- end banner of report -->\n\n";
}
pickup_report_header($langs->trans("PickupMenuSocReports"), $period, $periodlink, $builddate, $soc_filter, $status_filter, $pickup_type_filter);
/*
* Retrieve data
*/
function retrieve_data() {
// TODO: add indexes in DB?
global $db, $conf;
global $date_start, $date_end, $soc_filter, $status_filter, $pickup_type_filter;
if (empty($soc_filter)) {
return array();
}
$sql = 'SELECT p.rowid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'pickup_pickup as p';
$sql.= ' WHERE';
$sql.= " p.date_pickup >= '".$db->escape(dol_print_date($date_start, "%Y-%m-%d"))."'";
$sql.= " AND p.date_pickup <= '".$db->escape(dol_print_date($date_end, "%Y-%m-%d"))."'";
$sql.= " AND p.fk_soc = '".$db->escape($soc_filter)."'";
if ($status_filter !== '') {
$sql.= " AND p.status = '".$db->escape($status_filter)."'";
}
if (!empty($conf->global->PICKUP_USE_PICKUP_TYPE) && !empty($pickup_type_filter)) {
$sql.= " AND p.fk_pickup_type = '".$db->escape($pickup_type_filter)."'";
}
$sql.= " ORDER BY p.ref";
$data = array();
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$row = $db->fetch_object($resql);
$pickup_id = $row->rowid;
$pickup = new Pickup($db);
$pickup->fetch($pickup_id);
$pickup->getLinesArray();
foreach ($pickup->lines as $pickupline) {
array_push($data, array(
'pickup' => $pickup,
'pickupline' => $pickupline
));
}
$i++;
}
$db->free($resql);
} else {
dol_print_error($db);
}
return $data;
}
$data = retrieve_data();
/*
* Show result array
*/
print '<div class="div-table-responsive">';
print '<table class="tagtable liste">'."\n";
print '<thead>';
print '<tr class="liste_titre">';
print '<td rowspan="2" align="" class="liste_titre">' . $langs->trans('Ref') . '</td>';
print '<td rowspan="2" align="" class="liste_titre">' . $langs->trans('Date') . '</td>';
if (!empty($conf->global->PICKUP_USE_PICKUP_TYPE)) {
print '<td rowspan="2" align="" class="liste_titre">' . $langs->trans('PickupType') . '</td>';
}
print '<td rowspan="2" align="" class="liste_titre">' . $langs->trans('Status') . '</td>';
print '<td rowspan="2" align="" class="liste_titre">' . $langs->trans('Description') . '</td>';
print '<td rowspan="2" align="" class="liste_titre">' . $langs->trans('Qty') . '</td>';
if (!empty($conf->global->PICKUP_UNITS_WEIGHT)) {
print '<td colspan="2" align="" class="liste_titre center">' . $langs->trans('Weight') . '</td>';
}
if (!empty($conf->global->PICKUP_UNITS_LENGTH)) {
print '<td colspan="2" align="" class="liste_titre center">' . $langs->trans('Length') . '</td>';
}
if (!empty($conf->global->PICKUP_UNITS_SURFACE)) {
print '<td colspan="2" align="" class="liste_titre center">' . $langs->trans('Surface') . '</td>';
}
if (!empty($conf->global->PICKUP_UNITS_VOLUME)) {
print '<td colspan="2" align="" class="liste_titre center">' . $langs->trans('Volume') . '</td>';
}
if (!empty($conf->global->PICKUP_USE_DEEE)) {
print '<td rowspan="2" align="" class="liste_titre">' . $langs->trans('DEEE') . '</td>';
}
print '<td rowspan="2" align="" class="liste_titre">' . $langs->trans('StockMovement') . '</td>';
print '</tr>';
print '<tr class="liste_titre">';
if (!empty($conf->global->PICKUP_UNITS_WEIGHT)) {
?><td class="right"><?php print $langs->trans('PickupUnitValue'); ?></td>
<td class="right"><?php print $langs->trans('Total'); ?></td><?php
}
if (!empty($conf->global->PICKUP_UNITS_LENGTH)) {
?><td class="right"><?php print $langs->trans('PickupUnitValue'); ?></td>
<td class="right"><?php print $langs->trans('Total'); ?></td><?php
}
if (!empty($conf->global->PICKUP_UNITS_SURFACE)) {
?><td class="right"><?php print $langs->trans('PickupUnitValue'); ?></td>
<td class="right"><?php print $langs->trans('Total'); ?></td><?php
}
if (!empty($conf->global->PICKUP_UNITS_VOLUME)) {
?><td class="right"><?php print $langs->trans('PickupUnitValue'); ?></td>
<td class="right"><?php print $langs->trans('Total'); ?></td><?php
}
print '</tr>';
print '</thead>';
foreach ($data as $line) {
$pickup = $line['pickup'];
$pickupline = $line['pickupline'];
$stock_movement = 0;
if ($pickupline->fk_stock_movement) {
$stock_movement = new MouvementStock($db);
$stock_movement->fetch($pickupline->fk_stock_movement);
}
$line_product = 0;
if ($pickupline->fk_product > 0) {
$line_product = new Product($db);
$line_product->fetch($pickupline->fk_product);
}
$cats = $pickupline->getProductCategoriesLabels();
print '<tr class="oddeven">';
print '<td class="nowrap">'.$pickup->getNomUrl(1).'</td>';
print '<td class="nowrap">'.$pickup->showOutputField($pickup->fields['date_pickup'], 'date_pickup', $pickup->date_pickup).'</td>';
if (!empty($conf->global->PICKUP_USE_PICKUP_TYPE)) {
print '<td class="nowrap">'.$pickup->showOutputField($pickup->fields['fk_pickup_type'], 'fk_pickup_type', $pickup->fk_pickup_type).'</td>';
}
print '<td>'.$pickup->showOutputField($pickup->fields['status'], 'status', $pickup->status).'</td>';
print '<td class="nowrap">';
if (count($cats) > 0) {
print join(', ', $cats);
print ('<br>');
}
if (!empty($line_product)) {
print $form->textwithtooltip($line_product->getNomUrl(1), '');
}
print '</td>';
print '<td class="nowrap right">';
print price($pickupline->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price
print '</td>';
if (!empty($conf->global->PICKUP_UNITS_WEIGHT)) {
print '<td class="nowrap right">';
if (!empty($pickupline->weight)) {
print $pickupline->weight . ' ' . measuringUnitString(0, "weight", $pickupline->weight_units);
}
print '</td>';
print '<td class="nowrap right">';
if (!empty($pickupline->weight)) {
print ($pickupline->qty * $pickupline->weight) . ' ' . measuringUnitString(0, "weight", $pickupline->weight_units);
}
print '</td>';
}
if (!empty($conf->global->PICKUP_UNITS_LENGTH)) {
print '<td class="nowrap right">';
if (!empty($pickupline->length)) {
print $pickupline->length . ' ' . measuringUnitString(0, "size", $pickupline->length_units);
}
print '</td>';
print '<td class="nowrap right">';
if (!empty($pickupline->length)) {
print ($pickupline->qty * $pickupline->length) . ' ' . measuringUnitString(0, "size", $pickupline->length_units);
}
print '</td>';
}
if (!empty($conf->global->PICKUP_UNITS_SURFACE)) {
print '<td class="nowrap right">';
if (!empty($pickupline->surface)) {
print $pickupline->surface . ' ' . measuringUnitString(0, "surface", $pickupline->surface_units);
}
print '</td>';
print '<td class="nowrap right">';
if (!empty($pickupline->surface)) {
print ($pickupline->qty * $pickupline->surface) . ' ' . measuringUnitString(0, "surface", $pickupline->surface_units);
}
print '</td>';
}
if (!empty($conf->global->PICKUP_UNITS_VOLUME)) {
print '<td class="nowrap right">';
if (!empty($pickupline->volume)) {
print $pickupline->volume . ' ' . measuringUnitString(0, "volume", $pickupline->volume_units);
}
print '</td>';
print '<td class="nowrap right">';
if (!empty($pickupline->volume)) {
print ($pickupline->qty * $pickupline->volume) . ' ' . measuringUnitString(0, "volume", $pickupline->volume_units);
}
print '</td>';
}
if (!empty($conf->global->PICKUP_USE_DEEE)) {
print '<td class="nowrap">';
if ($pickupline->deee) {
// this field is defined as en extrafield on the product table.
print $extrafields->showOutputField('pickup_deee_type', $pickupline->deee_type, '', 'product');
} else {
print '-';
}
print '</td>';
}
print '<td>';
if (! empty($stock_movement)) { print $stock_movement->getNomUrl(1); }
print '</td>';
print '</tr>';
}
// TODO: total line?
print "</table>";
print '</div>';
// End of page
llxFooter();
$db->close();