From 3d25fdc99fd37f3b5e37f25b7a38804a02130426 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Wed, 17 Aug 2022 11:41:48 +0200 Subject: money calculation working --- README | 3 +++ lib/pages/logbook_page.dart | 5 ++--- lib/shift.dart | 14 ++++++++++++- lib/widgets/agenda_week_item.dart | 44 ++++++++++++++++++++++++++++++++------- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/README b/README index b8d7ea5..0cc93ee 100644 --- a/README +++ b/README @@ -2,6 +2,8 @@ - Laat geld zien op gesloten shifts - gebruiker uurloon laten aanpassen - gebruiker begintijd laten aanpassen per shift +- versie toevoegen aan locale bestanden +- foutmelding geven wanneer een dubbele shift wordt toegevoegd # Features - Aanmelden van werktijden @@ -11,3 +13,4 @@ - data wordt lokaal opgeslagen - gemakkelijk meerdere shifts tegelijk aanmelden - schatting over aantal ingeplande uren en inkomen +- responsive on all screens diff --git a/lib/pages/logbook_page.dart b/lib/pages/logbook_page.dart index 0e81f49..0849cda 100644 --- a/lib/pages/logbook_page.dart +++ b/lib/pages/logbook_page.dart @@ -23,11 +23,10 @@ class MonthData { void calculateData() { totalWorkedTime = Duration(); + expectedSalary = 0; for (var shift in shifts) { totalWorkedTime += shift.getElapsedSessionTime(); - } - if (shifts.isNotEmpty) { - expectedSalary = totalWorkedTime.inMinutes * shifts[0].getMinutePayRate(); + expectedSalary += shift.getEarnedMoney(); } } diff --git a/lib/shift.dart b/lib/shift.dart index fd32cf7..eecf4cc 100644 --- a/lib/shift.dart +++ b/lib/shift.dart @@ -45,7 +45,7 @@ class Shift { case ShiftStatus.Active: return Padding( child: CircularProgressIndicator( - strokeWidth: 1, + strokeWidth: 2, color: Colors.white, ), padding: @@ -111,6 +111,18 @@ class Shift { !DateUtilities.DateUtils.isSameDay(start, DateTime.now()); } + double getEarnedMoney() { + DateTime? endToCalculate = end; + endToCalculate ??= expectedEndTime(); + + if (start.weekday == 6) { + return endToCalculate.difference(start).inMinutes * + getMinutePayRate() * + 1.35; + } + return endToCalculate.difference(start).inMinutes * getMinutePayRate(); + } + double getMoneyForActiveSession() { if (getIsActive()) { Duration elapsed = DateTime.now().difference(start); diff --git a/lib/widgets/agenda_week_item.dart b/lib/widgets/agenda_week_item.dart index 779b42d..b74cabd 100644 --- a/lib/widgets/agenda_week_item.dart +++ b/lib/widgets/agenda_week_item.dart @@ -200,6 +200,12 @@ class _ExerciseEntryState extends State { child: Text('Invullen')); } + Widget createOldShiftInfoText() { + return Text( + '€' + widget.shift.getEarnedMoney().toStringAsFixed(2), + ); + } + Widget createShiftModifyButton() { if (!widget.shift.getIsActive() && widget.shift.canStart()) { return createStartShiftButton(); @@ -207,6 +213,8 @@ class _ExerciseEntryState extends State { return createStopShiftButton(); } else if (widget.shift.shiftIsOpenButBeforeToday()) { return createCompleteOldShiftButton(); + } else if (widget.shift.isDone()) { + return createOldShiftInfoText(); } return Padding(padding: const EdgeInsets.all(0)); @@ -258,6 +266,21 @@ class _ExerciseEntryState extends State { setStartAndEndTime(); + double widthOfItem = MediaQuery.of(context).size.width - 20; + double heightOfItem = 48; + double widthOfIcon = 32; + double widthOfWeekday = 35; + double widthOfDates = 95; + double widthOfAction = 90; + + double remaining = widthOfItem - + widthOfIcon - + widthOfWeekday - + widthOfDates - + widthOfAction - + 20; // padding + double widthOfShiftType = remaining; + return Padding( padding: const EdgeInsets.only(bottom: 8, left: 10, right: 10), child: Container( @@ -270,7 +293,8 @@ class _ExerciseEntryState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( - width: double.infinity, + width: widthOfItem, + height: heightOfItem, decoration: const BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(4))), padding: EdgeInsets.all(0), @@ -288,8 +312,8 @@ class _ExerciseEntryState extends State { borderRadius: BorderRadius.only( topLeft: Radius.circular(8), bottomLeft: Radius.circular(8))), - height: 48.0, - width: 32.0, + height: heightOfItem, + width: widthOfIcon, child: widget.shift.getStatusIcon(), ), ), @@ -299,7 +323,7 @@ class _ExerciseEntryState extends State { DateHelper.getWeekdayName(widget.shift.start.weekday), style: Style.listItemTitletextBold, ), - width: 35, + width: widthOfWeekday, ), Container( child: RichText( @@ -312,15 +336,21 @@ class _ExerciseEntryState extends State { ], ), ), - width: 95, + width: widthOfDates, ), Container( child: Text( '| ' + shiftTypeName, ), - width: 100, + width: widthOfShiftType, + ), + Container( + child: Align( + child: startShiftWidget, + alignment: Alignment.centerRight, + ), + width: widthOfAction, ), - startShiftWidget, ], ), ), -- cgit v1.2.3-70-g09d2