dbXapp
2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Toggle main menu visibility
Loading...
Searching...
No Matches
myLKW.class.php
Go to the documentation of this file.
1
<?php
2
namespace
dbx\myLKW;
3
use DateTime;
4
use Throwable;
5
6
7
function
dbx_get_datum
(
8
string
$format =
'day,dd.mm.yyyy'
,
9
int
$offset = 0,
10
?DateTime
$base
=
null
11
): string {
12
13
// -----------------------------------------
14
// BASISDATUM
15
// -----------------------------------------
16
17
if
(!
$base
) {
18
$base
=
new
DateTime(
'today'
);
19
}
else
{
20
$base
= clone
$base
;
21
}
22
23
// -----------------------------------------
24
// WORKDAY CHECK (CFG gesteuert)
25
// -----------------------------------------
26
27
$is_workday =
function
(DateTime $d): bool {
28
29
$w = (int)$d->format(
'N'
);
// 1=Mo ... 7=So
30
31
$maxWorkday = (int)
dbx
()->get_config(
'myLKW'
,
'workdays'
);
32
if
(!$maxWorkday) {
33
$maxWorkday = 5;
34
}
35
36
if
($w > $maxWorkday) {
37
return
false
;
38
}
39
40
return
true
;
41
};
42
43
// -----------------------------------------
44
// NEXT / PREV WORKDAY
45
// -----------------------------------------
46
47
$next_workday =
function
(DateTime $d) use ($is_workday): DateTime {
48
$d = clone $d;
49
do
{
50
$d->modify(
'+1 day'
);
51
}
while
(!$is_workday($d));
52
return
$d;
53
};
54
55
$prev_workday =
function
(DateTime $d) use ($is_workday): DateTime {
56
$d = clone $d;
57
do
{
58
$d->modify(
'-1 day'
);
59
}
while
(!$is_workday($d));
60
return
$d;
61
};
62
63
// -----------------------------------------
64
// OFFSET (d0/d1/d2 ...)
65
// -----------------------------------------
66
67
if
($offset > 0) {
68
for
($i = 0; $i < $offset; $i++) {
69
$base
= $next_workday(
$base
);
70
}
71
}
72
73
if
($offset < 0) {
74
for
($i = 0; $i < abs($offset); $i++) {
75
$base
= $prev_workday(
$base
);
76
}
77
}
78
79
// -----------------------------------------
80
// SPANISCH
81
// -----------------------------------------
82
83
$dias_full = [
'domingo'
,
'lunes'
,
'martes'
,
'miércoles'
,
'jueves'
,
'viernes'
,
'sábado'
];
84
$dias_short = [
'Dom'
,
'Lun'
,
'Mar'
,
'Mié'
,
'Jue'
,
'Vie'
,
'Sáb'
];
85
86
$meses_full = [
87
1=>
'enero'
,
'febrero'
,
'marzo'
,
'abril'
,
'mayo'
,
'junio'
,
88
'julio'
,
'agosto'
,
'septiembre'
,
'octubre'
,
'noviembre'
,
'diciembre'
89
];
90
91
// -----------------------------------------
92
// RANGE (~~ FIX)
93
// -----------------------------------------
94
95
if
(strpos($format,
'~~'
) !==
false
) {
96
97
$fmt = str_replace(
'~~'
,
''
,$format);
98
99
$format_date =
function
(DateTime $d) use ($fmt, $dias_full, $dias_short, $meses_full):
string
{
100
101
$out = $fmt;
102
103
$out = str_replace(
'day'
, $dias_full[(
int
)$d->format(
'w'
)], $out);
104
$out = str_replace(
'dy'
, $dias_short[(
int
)$d->format(
'w'
)], $out);
105
106
$out = str_replace(
'dd'
, $d->format(
'd'
), $out);
107
$out = str_replace(
'mm'
, $d->format(
'm'
), $out);
108
$out = str_replace(
'yyyy'
, $d->format(
'Y'
), $out);
109
110
$out = str_replace(
'month'
, $meses_full[(
int
)$d->format(
'n'
)], $out);
111
112
return
trim($out);
113
};
114
115
$start = clone
$base
;
116
$end = $next_workday($start);
117
118
return
$format_date($start) .
' ~~ '
. $format_date($end);
119
}
120
121
// -----------------------------------------
122
// NORMAL FORMAT
123
// -----------------------------------------
124
125
$format_date =
function
(DateTime $d) use ($format, $dias_full, $dias_short, $meses_full):
string
{
126
127
$out = $format;
128
129
$out = str_replace(
'day'
, $dias_full[(
int
)$d->format(
'w'
)], $out);
130
$out = str_replace(
'dy'
, $dias_short[(
int
)$d->format(
'w'
)], $out);
131
132
$out = str_replace(
'dd'
, $d->format(
'd'
), $out);
133
$out = str_replace(
'mm'
, $d->format(
'm'
), $out);
134
$out = str_replace(
'yyyy'
, $d->format(
'Y'
), $out);
135
136
$out = str_replace(
'month'
, $meses_full[(
int
)$d->format(
'n'
)], $out);
137
138
return
$out;
139
};
140
141
return
$format_date(
$base
);
142
}
143
144
145
class
myLKW
{
146
private
function
shift_plus() {
147
148
$dd =
'lkw'
;
149
$oDB =
dbx
()->get_system_obj(
'dbxDB'
);
150
151
$table
= $oDB->get_dd_table($dd);
152
if
(!
$table
)
return
0;
153
154
$uid =
dbx
()->user();
155
$now = date(
'Y-m-d H:i:s'
);
156
157
try
{
158
159
if
(!$oDB->begin($dd))
return
0;
160
161
$sql =
"UPDATE $table SET
162
163
/* ===== d5 ← d4 ===== */
164
d5_origen_region = d4_origen_region,
165
d5_origen_lugar = d4_origen_lugar,
166
d5_carga_region = d4_carga_region,
167
d5_carga_lugar = d4_carga_lugar,
168
d5_observaciones = d4_observaciones,
169
170
/* ===== d4 ← d3 ===== */
171
d4_origen_region = d3_origen_region,
172
d4_origen_lugar = d3_origen_lugar,
173
d4_carga_region = d3_carga_region,
174
d4_carga_lugar = d3_carga_lugar,
175
d4_observaciones = d3_observaciones,
176
177
/* ===== d3 ← d2 ===== */
178
d3_origen_region = d2_origen_region,
179
d3_origen_lugar = d2_origen_lugar,
180
d3_carga_region = d2_carga_region,
181
d3_carga_lugar = d2_carga_lugar,
182
d3_observaciones = d2_observaciones,
183
184
/* ===== d2 ← d1 ===== */
185
d2_origen_region = d1_origen_region,
186
d2_origen_lugar = d1_origen_lugar,
187
d2_carga_region = d1_carga_region,
188
d2_carga_lugar = d1_carga_lugar,
189
d2_observaciones = d1_observaciones,
190
191
/* ===== d1 ← d0 ===== */
192
d1_origen_region = d0_origen_region,
193
d1_origen_lugar = d0_origen_lugar,
194
d1_carga_region = d0_carga_region,
195
d1_carga_lugar = d0_carga_lugar,
196
d1_observaciones = d0_observaciones,
197
198
/* ===== d0 leer ===== */
199
d0_origen_region = '',
200
d0_origen_lugar = '',
201
d0_carga_region = '',
202
d0_carga_lugar = '',
203
d0_observaciones = '',
204
205
update_date = '$now',
206
update_uid = '$uid'"
;
207
208
if
(!$oDB->rawQuery($oDB->get_dd_server($dd),$sql)) {
209
210
$oDB->rollback($dd);
211
return
0;
212
}
213
214
if
(!$oDB->commit($dd)) {
215
216
$oDB->rollback($dd);
217
return
0;
218
}
219
220
return
1;
221
222
}
223
catch
(Throwable $e) {
224
225
$oDB->rollback($dd);
226
return
0;
227
}
228
}
229
230
private
function
sync_grid() {
231
232
$oDB =
dbx
()->get_system_obj(
'dbxDB'
);
233
$dd =
'lkw'
;
234
235
$last_update =
dbx
()->get_modul_var(
'last_update'
,
''
,
'datetime'
);
236
237
//dbx_debug("Sync=$last_update");
238
239
if
(!$last_update) {
240
$last_update =
'1970-01-01 00:00:00'
;
241
}
242
243
/* ---------------------------------------------
244
SERVER TIME
245
--------------------------------------------- */
246
247
$server_time = (
new
DateTime())->format(
'Y-m-d H:i:s.v'
);
248
249
/* ---------------------------------------------
250
WHERE
251
--------------------------------------------- */
252
253
$where =
"update_date > '$last_update'"
;
254
dbx
()->debug(
"where=($where)"
);
255
256
/* ---------------------------------------------
257
SELECT
258
--------------------------------------------- */
259
260
$rows = $oDB->select(
261
$dd,
262
$where,
263
'*'
,
264
'update_date'
,
265
'ASC'
266
);
267
268
if
(!is_array($rows)){
269
$rows = [];
270
}
271
272
/* ---------------------------------------------
273
COUNT
274
--------------------------------------------- */
275
276
$count
= count($rows);
277
278
dbx
()->debug(
"Update=($count)"
,$rows);
279
280
/* ---------------------------------------------
281
JSON OUTPUT
282
--------------------------------------------- */
283
284
header(
'Content-Type: application/json; charset=utf-8'
);
285
286
echo json_encode([
287
'ok'
=> 1,
288
'count'
=>
$count
,
289
'rows'
=> $rows,
290
'server_time'
=> $server_time
291
]);
292
293
exit
;
294
}
295
296
297
public
function
run
() {
298
299
$modul =
dbx
()->get_system_var(
'dbx_activ_modul'
);
300
$action=
dbx
()->get_modul_var(
'dbx_run1'
);
301
dbx
()->set_system_var(
'dbx_page'
,
'default'
);
302
303
$today = date(
'Y-m-d'
);
304
$is_shift=
dbx
()->get_remember_var(
'ist_shift'
,
''
,
'myLKW'
);
305
dbx
()->debug(
"Auto-shift=($today)($is_shift)"
);
306
307
if
($is_shift != $today) {
308
$obj=
dbx
()->get_include_obj(
'myLKW_dayshift'
);
309
$silent=$obj->run();
310
dbx
()->debug(
"DAyshift="
,$silent);
311
dbx
()->set_remember_var(
'ist_shift'
,$today,
'myLKW'
);
312
}
313
314
switch
($action) {
315
316
case
'sync_grid'
:
317
$this->sync_grid();
318
break
;
319
320
case
'shift_plus'
:
321
$this->shift_plus();
322
break
;
323
324
325
case
'summary'
:
326
$obj=
dbx
()->get_include_obj(
'mySummary'
);
327
$content=$obj->run();
328
break
;
329
330
case
'list_lkw'
:
331
$obj=
dbx
()->get_include_obj(
'myLKW_list'
);
332
$content=$obj->run();
333
break
;
334
335
case
'list_dispo'
:
336
$obj=
dbx
()->get_include_obj(
'myLKW_dispo'
);
337
$content=$obj->run();
338
break
;
339
340
case
'dayshift'
:
341
$obj=
dbx
()->get_include_obj(
'myLKW_dayshift'
);
342
$content=$obj->run();
343
break
;
344
345
case
'dayset'
:
346
$obj=
dbx
()->get_include_obj(
'myLKW_dayset'
);
347
$content=$obj->run();
348
break
;
349
350
case
'add_lkw'
:
351
$obj=
dbx
()->get_include_obj(
'myLKW_add'
);
352
$content=$obj->run();
353
break
;
354
355
356
357
case
'report_lkw'
:
358
$obj=
dbx
()->get_include_obj(
'myLKW_report'
);
359
$content=$obj->run();
360
break
;
361
362
case
'import_lkw'
:
363
$obj=
dbx
()->get_include_obj(
'myLKW_import'
);
364
$content=$obj->run();
365
break
;
366
367
default
:
368
$oTPL=
dbx
()->get_system_obj(
'dbxTPL'
);
369
$msg[
'msg'
]=
"Modul=($modul) Action=($action) is undef."
;
370
$content=$oTPL->get_tpl(
'dbx'
,
'alert-warning'
,$msg);
371
372
}
// switch()
373
374
return
$content;
375
}
376
377
378
}
// class
$table
$table['server']
Definition
.dd.php:6
dbx\myLKW\myLKW
Definition
myLKW.class.php:145
dbx\myLKW\myLKW\run
run()
Definition
myLKW.class.php:297
$count
$count
Definition
generate_dbxapp_merch_mockups.php:270
exit
exit
Definition
index.php:532
if
if( $syncRequest)
Definition
index.php:520
dbx\myLKW\dbx_get_datum
dbx_get_datum(string $format='day, dd.mm.yyyy', int $offset=0, ?DateTime $base=null)
Definition
myLKW.class.php:7
dbx
DBX schema administration.
$base
$base
Definition
run_context_help_provision.php:2
dbx
modules
myLKW
myLKW.class.php
Generated by
1.17.0