footer
This commit is contained in:
+58
-53
@@ -1,81 +1,86 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../models/work_day.dart';
|
||||
import '../models/work_interval.dart';
|
||||
import '../models/month_start.dart';
|
||||
import '../utils/helpers.dart';
|
||||
|
||||
class BookingApi {
|
||||
final String host;
|
||||
final String path;
|
||||
final http.Client client;
|
||||
BookingApi({required this.client});
|
||||
|
||||
const BookingApi({
|
||||
required this.client,
|
||||
this.host = 'api.windesign.at',
|
||||
this.path = '/workinghours.php',
|
||||
});
|
||||
|
||||
/// Monatliche Buchungen holen (für YYYY-MM)
|
||||
Future<List<WorkDay>> getBookingList(DateTime monthStart) async {
|
||||
final y = monthStart.year.toString().padLeft(4, '0');
|
||||
final m = monthStart.month.toString().padLeft(2, '0');
|
||||
final uri = Uri.https(host, path, {
|
||||
'module': 'booking',
|
||||
'function': 'getList',
|
||||
'date': '$y-$m',
|
||||
});
|
||||
|
||||
http.Response res;
|
||||
try {
|
||||
res = await client
|
||||
.get(uri, headers: {'Accept': 'application/json'})
|
||||
.timeout(const Duration(seconds: 15));
|
||||
} on http.ClientException catch (e) {
|
||||
throw Exception('ClientException: ${e.message} (uri=$uri)');
|
||||
} on Object catch (e) {
|
||||
throw Exception('Network error: $e (uri=$uri)');
|
||||
}
|
||||
final uri = Uri.parse(
|
||||
'https://api.windesign.at/workinghours.php?module=booking&function=getList&date=$y-$m',
|
||||
);
|
||||
|
||||
final res = await client.get(uri);
|
||||
if (res.statusCode != 200) {
|
||||
throw Exception('HTTP ${res.statusCode}: ${res.body}');
|
||||
throw Exception('booking/getList failed: ${res.statusCode} ${res.body}');
|
||||
}
|
||||
|
||||
final map = jsonDecode(res.body) as Map<String, dynamic>;
|
||||
final List items = map['bookings'] ?? [];
|
||||
final out = <WorkDay>[];
|
||||
if (map['error'] == true) {
|
||||
throw Exception('booking/getList error: ${map['errmsg']}');
|
||||
}
|
||||
final list = (map['bookings'] as List?) ?? const [];
|
||||
final items = <WorkDay>[];
|
||||
|
||||
for (final row in items) {
|
||||
final d = DateTime.parse(row['bookingDay'] as String);
|
||||
final isWeekend = d.weekday == DateTime.saturday || d.weekday == DateTime.sunday;
|
||||
final target = isWeekend ? 0 : 8 * 60;
|
||||
for (final e in list) {
|
||||
final row = e as Map<String, dynamic>;
|
||||
final dayStr = (row['bookingDay'] as String?) ?? '';
|
||||
final date = DateTime.tryParse(dayStr);
|
||||
if (date == null) continue;
|
||||
|
||||
String? code = (row['code'] as String?)?.trim();
|
||||
if (code != null && code.isEmpty) code = null;
|
||||
|
||||
final starts = <String?>[
|
||||
row['come1'] as String?, row['come2'] as String?,
|
||||
row['come3'] as String?, row['come4'] as String?, row['come5'] as String?,
|
||||
];
|
||||
final ends = <String?>[
|
||||
row['leave1'] as String?, row['leave2'] as String?,
|
||||
row['leave3'] as String?, row['leave4'] as String?, row['leave5'] as String?,
|
||||
];
|
||||
final intervals = <WorkInterval>[];
|
||||
TimeOfDay? p(dynamic v) => parseHHMM(v);
|
||||
void addPair(String a, String b) {
|
||||
final s = p(row[a]);
|
||||
final e = p(row[b]);
|
||||
if (s != null && e != null) intervals.add(WorkInterval(s, e));
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final s = parseDbTime(starts[i]);
|
||||
final e2 = parseDbTime(ends[i]);
|
||||
if (s != null && e2 != null) {
|
||||
intervals.add(WorkInterval(s, e2));
|
||||
}
|
||||
}
|
||||
addPair('come1', 'leave1');
|
||||
addPair('come2', 'leave2');
|
||||
addPair('come3', 'leave3');
|
||||
addPair('come4', 'leave4');
|
||||
addPair('come5', 'leave5');
|
||||
|
||||
final code = (row['code']?.toString().trim().isEmpty ?? true)
|
||||
? null
|
||||
: row['code'].toString().trim();
|
||||
|
||||
out.add(WorkDay(
|
||||
date: d,
|
||||
items.add(WorkDay(
|
||||
date: DateTime(date.year, date.month, date.day),
|
||||
intervals: intervals,
|
||||
targetMinutes: target,
|
||||
targetMinutes: 0, // wird im UI mit dem Tagesplan ersetzt
|
||||
code: code,
|
||||
));
|
||||
}
|
||||
|
||||
out.sort((a, b) => a.date.compareTo(b.date));
|
||||
return out;
|
||||
return items;
|
||||
}
|
||||
|
||||
/// Monatliche Startdaten (Startsaldo, Vacation, Overtime, Correction)
|
||||
Future<MonthStart> getMonthStart(DateTime monthStart) async {
|
||||
final y = monthStart.year.toString().padLeft(4, '0');
|
||||
final m = monthStart.month.toString().padLeft(2, '0');
|
||||
final uri = Uri.parse(
|
||||
'https://api.windesign.at/workinghours.php'
|
||||
'?module=monthlybooking&function=getList&date=$y-$m-01',
|
||||
);
|
||||
final res = await client.get(uri);
|
||||
if (res.statusCode != 200) {
|
||||
throw Exception('monthlybooking/getList failed: ${res.statusCode} ${res.body}');
|
||||
}
|
||||
final map = jsonDecode(res.body) as Map<String, dynamic>;
|
||||
if (map['error'] == true) {
|
||||
throw Exception('monthlybooking/getList error: ${map['errmsg']}');
|
||||
}
|
||||
return MonthStart.fromJson(map);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +1,47 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
/// Lädt die tägliche Sollzeit (HH:MM:SS pro Wochentag) aus der API.
|
||||
/// Gibt eine Map<int,int> zurück: key = DateTime.weekday (1..7), value = Minuten.
|
||||
class DailyWorkingApi {
|
||||
final String host;
|
||||
final String path;
|
||||
final http.Client client;
|
||||
DailyWorkingApi({required this.client});
|
||||
|
||||
const DailyWorkingApi({
|
||||
required this.client,
|
||||
this.host = 'api.windesign.at',
|
||||
this.path = '/workinghours.php',
|
||||
});
|
||||
|
||||
/// Liefert Map weekday(1..7) -> Minuten (int)
|
||||
Future<Map<int, int>> getDailyMinutes() async {
|
||||
final uri = Uri.https(host, path, {
|
||||
'module': 'dailyworking',
|
||||
'function': 'getList',
|
||||
});
|
||||
|
||||
final res = await client
|
||||
.get(uri, headers: {'Accept': 'application/json'})
|
||||
.timeout(const Duration(seconds: 15));
|
||||
|
||||
final uri = Uri.parse(
|
||||
'https://api.windesign.at/workinghours.php?module=dailyworking&function=getList',
|
||||
);
|
||||
final res = await client.get(uri);
|
||||
if (res.statusCode != 200) {
|
||||
throw Exception('HTTP ${res.statusCode}: ${res.body}');
|
||||
throw Exception('dailyworking/getList failed: ${res.statusCode} ${res.body}');
|
||||
}
|
||||
|
||||
final map = jsonDecode(res.body) as Map<String, dynamic>;
|
||||
final list = (map['entries'] as List?) ?? const [];
|
||||
if (list.isEmpty) return _defaultPlan();
|
||||
|
||||
final row = (list.first as Map).cast<String, dynamic>();
|
||||
|
||||
int parseHMS(String? s) {
|
||||
if (s == null) return 0;
|
||||
if (map['error'] == true) {
|
||||
throw Exception('dailyworking/getList error: ${map['errmsg']}');
|
||||
}
|
||||
final entries = (map['entries'] as List?) ?? const [];
|
||||
if (entries.isEmpty) {
|
||||
return {
|
||||
1: 8 * 60, 2: 8 * 60, 3: 8 * 60, 4: 8 * 60, 5: 8 * 60, 6: 0, 7: 0,
|
||||
};
|
||||
}
|
||||
final row = entries.first as Map<String, dynamic>;
|
||||
int parseHHMMSS(String? s) {
|
||||
if (s == null || s.isEmpty) return 0;
|
||||
final parts = s.split(':');
|
||||
if (parts.length != 3) return 0;
|
||||
if (parts.length < 2) return 0;
|
||||
final h = int.tryParse(parts[0]) ?? 0;
|
||||
final m = int.tryParse(parts[1]) ?? 0;
|
||||
return h * 60 + m; // Sekunden ignoriert
|
||||
return h * 60 + m;
|
||||
}
|
||||
|
||||
return {
|
||||
DateTime.monday: parseHMS(row['monday'] as String?),
|
||||
DateTime.tuesday: parseHMS(row['tuesday'] as String?),
|
||||
DateTime.wednesday: parseHMS(row['wednesday'] as String?),
|
||||
DateTime.thursday: parseHMS(row['thursday'] as String?),
|
||||
DateTime.friday: parseHMS(row['friday'] as String?),
|
||||
DateTime.saturday: parseHMS(row['saturday'] as String?),
|
||||
DateTime.sunday: parseHMS(row['sunday'] as String?),
|
||||
1: parseHHMMSS(row['monday'] as String?),
|
||||
2: parseHHMMSS(row['tuesday'] as String?),
|
||||
3: parseHHMMSS(row['wednesday'] as String?),
|
||||
4: parseHHMMSS(row['thursday'] as String?),
|
||||
5: parseHHMMSS(row['friday'] as String?),
|
||||
6: parseHHMMSS(row['saturday'] as String?),
|
||||
7: parseHHMMSS(row['sunday'] as String?),
|
||||
};
|
||||
}
|
||||
|
||||
Map<int, int> _defaultPlan() => {
|
||||
DateTime.monday: 8 * 60,
|
||||
DateTime.tuesday: 8 * 60,
|
||||
DateTime.wednesday: 8 * 60,
|
||||
DateTime.thursday: 8 * 60,
|
||||
DateTime.friday: 8 * 60,
|
||||
DateTime.saturday: 0,
|
||||
DateTime.sunday: 0,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user