You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.0 KiB
Dart

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;
int weekday = -1;
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);
weekday = bookingDay.weekday;
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: 'code', value: e.code),
DataGridCell<int>(columnName: 'weekday', value: e.weekday),
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) {
Color colBG = Colors.white;
String code = row.getCells().toList()[0].value;
int weekday = row.getCells().toList()[1].value;
String holiday = row.getCells().toList()[3].value;
if (code == 'U') {
colBG = Color.fromARGB(255, 127, 127, 255);
}
if (weekday == 6 || weekday == 7) {
colBG = Color.fromARGB(255, 255, 165, 0);
}
if (holiday != '') {
colBG = Color.fromARGB(255, 255, 165, 0);
}
if (code == 'T') {
colBG = Color.fromARGB(255, 127, 127, 255);
}
if (code == 'SU') {
colBG = Color.fromARGB(255, 127, 127, 255);
}
if (code == 'K') {
colBG = Colors.yellow;
}
if (code == 'G') {
colBG = Color.fromARGB(255, 191, 191, 255);
}
if (code == 'T') {
colBG = Colors.red;
}
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((e) {
if (e.columnName == 'dayRight' ||
e.columnName == 'holiday' ||
e.columnName == 'information') {
return Container(
alignment: Alignment.centerLeft,
color: colBG,
padding: const EdgeInsets.all(8.0),
child: Text(e.value.toString() == '99:99' ? '' : e.value.toString()),
);
}
return Container(
alignment: Alignment.centerRight,
color: colBG,
padding: const EdgeInsets.all(8.0),
child: Text(e.value.toString() == '99:99' ? '' : e.value.toString()),
);
}).toList());
}
void updateDataGrid() {
notifyListeners();
}
}