initial commit

This commit is contained in:
2024-04-23 10:01:29 +02:00
parent e18472e116
commit 18bbdce261
9 changed files with 980 additions and 116 deletions
+172
View File
@@ -0,0 +1,172 @@
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
import 'package:workinghours/data/publicHolidays.dart';
class Booking {
DateTime bookingDay;
DateTime come1;
DateTime leave1;
DateTime come2;
DateTime leave2;
DateTime come3;
DateTime leave3;
DateTime come4;
DateTime leave4;
DateTime come5;
DateTime leave5;
String code;
String information;
String holiday = '';
String dayLeft = '';
String dayRight = '';
String pause = '';
String durationIs = '';
String durationShould = '';
String diff = '';
String currentDiff = '';
String decimal = '';
Booking({
required this.bookingDay,
required this.come1,
required this.leave1,
required this.come2,
required this.leave2,
required this.come3,
required this.leave3,
required this.come4,
required this.leave4,
required this.come5,
required this.leave5,
required this.code,
required this.information,
}) {
PublicHolidays h = PublicHolidays(year: bookingDay.year);
holiday = h.holiday(bookingDay);
dayLeft = DateFormat('EEEE - dd').format(bookingDay);
dayRight = DateFormat('dd - EEEE').format(bookingDay);
pause = '';
durationIs = '';
durationShould = '';
diff = '';
currentDiff = '';
decimal = '';
}
// factory Booking.fromJson(Map<String, dynamic> json) {
// return Movie(
// movieID: int.parse(json['movieID']),
// movieTitle: json['movieTitle'] as String,
// overview: json['overview'] as String,
// releaseDate: DateTime.parse(json['releaseDate']),
// state: int.parse(json['state']),
// resolution: json['resolution'] as String,
// );
// }
}
class BookingDataSource extends DataGridSource {
/// Creates the employee data source class with required details.
BookingDataSource(this.booking) {
buildDataGridRow();
}
void buildDataGridRow() {
_bookingDataGridRows = booking
.map<DataGridRow>((e) => DataGridRow(cells: [
DataGridCell<String>(columnName: 'dayLeft', value: e.dayLeft),
DataGridCell<String>(columnName: 'holiday', value: e.holiday),
DataGridCell<String>(
columnName: 'come1',
value: e.come1.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.come1)),
DataGridCell<String>(
columnName: 'leave1',
value: e.leave1.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.leave1)),
DataGridCell<String>(
columnName: 'come2',
value: e.come2.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.come2)),
DataGridCell<String>(
columnName: 'leave2',
value: e.leave2.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.leave2)),
DataGridCell<String>(
columnName: 'come3',
value: e.come3.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.come3)),
DataGridCell<String>(
columnName: 'leave3',
value: e.leave3.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.leave3)),
DataGridCell<String>(
columnName: 'come4',
value: e.come4.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.come4)),
DataGridCell<String>(
columnName: 'leave4',
value: e.leave4.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.leave4)),
DataGridCell<String>(
columnName: 'come5',
value: e.come5.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.come5)),
DataGridCell<String>(
columnName: 'leave5',
value: e.leave5.year == 1900
? '99:99'
: DateFormat('hh:mm').format(e.leave5)),
DataGridCell<String>(columnName: 'pause', value: e.pause),
DataGridCell<String>(columnName: 'code', value: e.code),
DataGridCell<String>(
columnName: 'durationIs', value: e.durationIs),
DataGridCell<String>(
columnName: 'durationShould', value: e.durationShould),
DataGridCell<String>(columnName: 'diff', value: e.diff),
DataGridCell<String>(
columnName: 'information', value: e.information),
DataGridCell<String>(
columnName: 'currentDiff', value: e.currentDiff),
DataGridCell<String>(columnName: 'decimal', value: e.decimal),
DataGridCell<String>(columnName: 'dayRight', value: e.dayRight),
]))
.toList();
}
List<Booking> booking = [];
List<DataGridRow> _bookingDataGridRows = [];
@override
List<DataGridRow> get rows => _bookingDataGridRows;
@override
DataGridRowAdapter buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((e) {
return Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(8.0),
child: Text(e.value.toString() == '99:99' ? '' : e.value.toString()),
);
}).toList());
}
void updateDataGrid() {
notifyListeners();
}
}
+135
View File
@@ -0,0 +1,135 @@
import 'package:jiffy/jiffy.dart';
class PublicHolidays {
PublicHolidays({
required this.year,
}) {
holidayList[neujahr()] = 'Neujahr';
holidayList[heilige3koenige()] = 'Heilige 3 Könige';
holidayList[karfreitag()] = 'Karfreitag';
holidayList[ostersonntag()] = 'Ostersonntag';
holidayList[ostermontag()] = 'OsterMontag';
holidayList[staatsfeiertag1()] = 'Staatsfeiertag';
holidayList[christihimmelfahrt()] = 'Christi Himmelfahrt';
holidayList[pfingstsonntag()] = 'Pfingstsonntag';
holidayList[pfingstmontag()] = 'Pfingstmontag';
holidayList[fronleichnam()] = 'Fronleichnam';
holidayList[mariahimmelfahrt()] = 'Maria Himmelfahrt';
holidayList[staatsfeiertag()] = 'Staatsfeiertag';
holidayList[allerheiligen()] = 'Allerheiligen';
holidayList[ersteradvent()] = '1. Advent';
holidayList[mariaempfaengnis()] = 'Maria Emphängnis';
holidayList[ersterweihnachtstag()] = '1. Weihnachtstag';
holidayList[zweiterweihnachtstag()] = '2. Weihnachtstag';
holidayList[silvester()] = 'Silvester';
}
Map<DateTime, String> holidayList = {};
int year = 0;
Map<DateTime, String> entries() {
return holidayList;
}
String holiday(DateTime bookingDate) {
if (holidayList.containsKey(bookingDate)) {
return holidayList[bookingDate]!;
}
return '';
}
DateTime neujahr() {
return DateTime(year, 1, 1);
}
DateTime heilige3koenige() {
return DateTime(year, 1, 6);
}
DateTime karfreitag() {
DateTime d =
Jiffy.parseFromDateTime(ostersonntag()).subtract(days: 2).dateTime;
return DateTime(d.year, d.month, d.day);
}
DateTime ostersonntag() {
int a = year % 19;
int b = (year ~/ 100).toInt();
int c = year % 100;
int e = b % 4;
int f = ((b + 8) ~/ 25).toInt();
int g = ((b - f + 1) ~/ 3).toInt();
int h = (19 * a + b - (b ~/ 4) - g + 15) % 30;
int k = c % 4;
int l = (32 + 2 * e + 2 * (c ~/ 4) - h - k) % 7;
int m = (a + 11 * h + 22 * l) ~/ 451;
int month = (h + l - 7 * m + 114) ~/ 31;
int day = (h + l - 7 * m + 114) % 31 + 1;
return DateTime(year, month, day);
}
DateTime ostermontag() {
DateTime d = Jiffy.parseFromDateTime(ostersonntag()).add(days: 1).dateTime;
return DateTime(d.year, d.month, d.day);
}
DateTime staatsfeiertag1() {
return DateTime(year, 5, 1);
}
DateTime christihimmelfahrt() {
DateTime d = Jiffy.parseFromDateTime(ostersonntag()).add(days: 39).dateTime;
return DateTime(d.year, d.month, d.day);
}
DateTime pfingstsonntag() {
DateTime d = Jiffy.parseFromDateTime(ostersonntag()).add(days: 49).dateTime;
return DateTime(d.year, d.month, d.day);
}
DateTime pfingstmontag() {
DateTime d = Jiffy.parseFromDateTime(ostersonntag()).add(days: 50).dateTime;
return DateTime(d.year, d.month, d.day);
}
DateTime fronleichnam() {
DateTime d = Jiffy.parseFromDateTime(ostersonntag()).add(days: 60).dateTime;
return DateTime(d.year, d.month, d.day);
}
DateTime mariahimmelfahrt() {
return DateTime(year, 8, 15);
}
DateTime staatsfeiertag() {
return DateTime(year, 10, 26);
}
DateTime allerheiligen() {
return DateTime(year, 11, 1);
}
DateTime ersteradvent() {
DateTime d = DateTime(year, 11, 27);
DateTime d1 = Jiffy.parseFromDateTime(d).add(days: 7 - d.weekday).dateTime;
return DateTime(d1.year, d1.month, d1.day);
}
DateTime mariaempfaengnis() {
return DateTime(year, 12, 8);
}
DateTime ersterweihnachtstag() {
return DateTime(year, 12, 25);
}
DateTime zweiterweihnachtstag() {
return DateTime(year, 12, 26);
}
DateTime silvester() {
return DateTime(year, 12, 31);
}
}