@fabriktor/fx 0.0.195 → 0.0.197
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -39,7 +39,7 @@ export class RouteArrivalCue {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
export function routeHasActiveTransport(actor, route, vehicle_id, state, location_id) {
|
|
42
|
-
// A prior-day start
|
|
42
|
+
// A prior-day start still belongs to the same active transport.
|
|
43
43
|
// Keep the cue tied to stored state; the punch workflow validates its finish.
|
|
44
44
|
return (actor.active_mode === UserTypeEmployee &&
|
|
45
45
|
routeCanTrack(actor, route, vehicle_id, actor.owner_id) &&
|
|
@@ -6,11 +6,11 @@ export declare function timesheetDateChoices(value: InDate): SchemaDate[];
|
|
|
6
6
|
export declare function timesheetDate(value: TimesheetDate): SchemaDate;
|
|
7
7
|
export declare function timesheetDateTime(value: TimesheetDate): number;
|
|
8
8
|
export declare function timesheetPunchDeadline(start: TimesheetDate): number;
|
|
9
|
+
export declare function timesheetPunchExpired(start: TimesheetDate, now: Date): boolean;
|
|
9
10
|
export declare function timesheetPunchWindow(opts: {
|
|
10
11
|
start: TimesheetDate;
|
|
11
12
|
now: Date;
|
|
12
13
|
minimum?: TimesheetDate;
|
|
13
|
-
allow_equal?: boolean;
|
|
14
14
|
}): {
|
|
15
15
|
minimum: number;
|
|
16
16
|
maximum: number;
|
|
@@ -40,10 +40,13 @@ export function timesheetDateTime(value) {
|
|
|
40
40
|
export function timesheetPunchDeadline(start) {
|
|
41
41
|
return timesheetDateTime(start) + TimesheetMaxPunchHours * hourMS;
|
|
42
42
|
}
|
|
43
|
+
export function timesheetPunchExpired(start, now) {
|
|
44
|
+
return now.getTime() > timesheetPunchDeadline(start);
|
|
45
|
+
}
|
|
43
46
|
export function timesheetPunchWindow(opts) {
|
|
44
47
|
const start = timesheetDateTime(opts.start);
|
|
45
48
|
return {
|
|
46
|
-
minimum: Math.max(start
|
|
49
|
+
minimum: Math.max(start, opts.minimum ? timesheetDateTime(opts.minimum) : start),
|
|
47
50
|
maximum: Math.min(opts.now.getTime(), timesheetPunchDeadline(opts.start)),
|
|
48
51
|
};
|
|
49
52
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mergeQueryOptions, queryNestedParam, queryParams, } from "@fabriktor/client";
|
|
2
2
|
import { PunchStatusApproved, PunchStatusPending, PunchStatusWorking, PunchTypeIn, PunchTypeOut, PunchTypeRideIn, PunchTypeRideOut, } from "@fabriktor/schema";
|
|
3
3
|
import { inDateAtTimestamp } from "../core/date.js";
|
|
4
|
-
import { timesheetDate, timesheetDateTime, timesheetPunchDeadline, } from "./time.js";
|
|
4
|
+
import { timesheetDate, timesheetDateTime, timesheetPunchDeadline, timesheetPunchExpired, } from "./time.js";
|
|
5
5
|
import { errRequired } from "../core/err.js";
|
|
6
6
|
import { PreActionBlocked } from "../core/pre-action.js";
|
|
7
7
|
import { queryRecordParams, runOwnerScopeQuery, } from "../core/query.js";
|
|
@@ -222,7 +222,9 @@ export class TimesheetsWorkspace {
|
|
|
222
222
|
: undefined,
|
|
223
223
|
});
|
|
224
224
|
requireState(timesheetStateKey(current) === timesheetStateKey(opts.expected), TimesheetsBlock.Changed);
|
|
225
|
-
requireState(
|
|
225
|
+
requireState(!!opts.date ||
|
|
226
|
+
!current.punch ||
|
|
227
|
+
!timesheetPunchExpired(current.punch.punch_in_time, await this.now()), TimesheetsBlock.FinishRequired);
|
|
226
228
|
requireState(opts.action === PunchTypeOut || (current.open_punches?.length ?? 0) <= 1, TimesheetsBlock.Active);
|
|
227
229
|
requireState(!current.week_sheet || timesheetIsMutable(current.week_sheet), TimesheetsBlock.Locked);
|
|
228
230
|
const controls = this.actions.punchControls(current);
|
|
@@ -239,11 +241,8 @@ export class TimesheetsWorkspace {
|
|
|
239
241
|
current.punch.timezone === opts.timezone, TimesheetsBlock.Changed);
|
|
240
242
|
}
|
|
241
243
|
if (opts.date && current.punch && opts.action !== PunchTypeIn) {
|
|
242
|
-
requireState(opts.
|
|
243
|
-
|
|
244
|
-
timesheetDateTime(current.punch.punch_in_time)
|
|
245
|
-
: timesheetDateTime(opts.date) >=
|
|
246
|
-
timesheetDateTime(current.punch.punch_in_time), TimesheetsBlock.InvalidDay);
|
|
244
|
+
requireState(timesheetDateTime(opts.date) >=
|
|
245
|
+
timesheetDateTime(current.punch.punch_in_time), TimesheetsBlock.InvalidDay);
|
|
247
246
|
requireState(timesheetDateTime(opts.date) <=
|
|
248
247
|
timesheetPunchDeadline(current.punch.punch_in_time), TimesheetsBlock.Duration);
|
|
249
248
|
}
|
|
@@ -278,8 +277,10 @@ export class TimesheetsWorkspace {
|
|
|
278
277
|
: !!current.punch &&
|
|
279
278
|
timesheetDateTime(p.punch_in_time) ===
|
|
280
279
|
timesheetDateTime(current.punch.punch_in_time)));
|
|
281
|
-
const last = matches.
|
|
280
|
+
const last = matches.at(-1);
|
|
282
281
|
requireState(!!last &&
|
|
282
|
+
matches.filter((p) => p.punch_status === PunchStatusWorking).length ===
|
|
283
|
+
(opts.action === PunchTypeOut ? 0 : 1) &&
|
|
283
284
|
last.location_id === opts.location_id &&
|
|
284
285
|
!sheet.is_archived &&
|
|
285
286
|
(opts.action === PunchTypeOut
|
|
@@ -294,7 +295,7 @@ export class TimesheetsWorkspace {
|
|
|
294
295
|
async saveDay(opts) {
|
|
295
296
|
await this.validateDay(opts.start, opts.timezone);
|
|
296
297
|
await this.validateDay(opts.end, opts.timezone);
|
|
297
|
-
requireState(timesheetDateTime(opts.end)
|
|
298
|
+
requireState(timesheetDateTime(opts.end) >= timesheetDateTime(opts.start), TimesheetsBlock.InvalidDay);
|
|
298
299
|
requireState(timesheetDateTime(opts.end) <= timesheetPunchDeadline(opts.start), TimesheetsBlock.Duration);
|
|
299
300
|
const matches = opts.replace
|
|
300
301
|
? [await this.week(opts.replace.id)]
|