Skip to content

Commit

Permalink
Version 1.51 (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
NomisNostab authored Mar 24, 2024
2 parents 57f6abb + e7fc9af commit 6bc56d3
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 68 deletions.
16 changes: 10 additions & 6 deletions Services/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Topo.Model.Progress;
using Syncfusion.EJ2.Spreadsheet;
using System;
using Syncfusion.EJ2.Linq;

namespace Topo.Services
{
Expand Down Expand Up @@ -844,12 +845,12 @@ public IWorkbook GenerateAttendanceReportWorkbook(AttendanceReportModel attendan
rowNumber++;
// Group attendance by member for youth
var groupedAttendances = attendanceReportData.attendanceReportItems.Where(m => m.IsAdultMember == 0).GroupBy(wa => wa.MemberName).ToList();
var allEvents = attendanceReportData.attendanceReportItems.DistinctBy(i => i.EventNameDisplay).OrderBy(i => i.EventStartDate).ToList();

// Add Event Details
columnNumber = forPdfOutput ? 1 : 2;
rowNumber++;
var firstGroupedAttendance = groupedAttendances.FirstOrDefault();
foreach (var eventAttendance in firstGroupedAttendance)
foreach (var eventAttendance in allEvents)
{
columnNumber++;
if (forPdfOutput)
Expand Down Expand Up @@ -908,6 +909,7 @@ public IWorkbook GenerateAttendanceReportWorkbook(AttendanceReportModel attendan
var sumStartRow = rowNumber + 1;
foreach (var groupedAttendance in groupedAttendances)
{
// Name
rowNumber++;
columnNumber = 1;
if (forPdfOutput)
Expand All @@ -924,17 +926,19 @@ public IWorkbook GenerateAttendanceReportWorkbook(AttendanceReportModel attendan
sheet.Range[rowNumber, columnNumber].Text = groupedAttendance.FirstOrDefault().MemberLastName;
sheet.Range[rowNumber, columnNumber].BorderAround();
}
foreach (var eventAttendance in groupedAttendance)
// Event Attendance
foreach (var events in allEvents)
{
var eventAttendance = groupedAttendance.Where(a => a.EventNameDisplay == events.EventNameDisplay).FirstOrDefault();
columnNumber++;
sheet.Range[rowNumber, columnNumber].Text = eventAttendance.Pal;
sheet.Range[rowNumber, columnNumber].Text = eventAttendance?.Pal;
sheet.Range[rowNumber, columnNumber].BorderAround();
sheet.Range[rowNumber, columnNumber].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
}
// Row total
var sumRange = sheet.Range[rowNumber, forPdfOutput ? 2 : 3, rowNumber, columnNumber].AddressLocal;
columnNumber++;
sheet.Range[rowNumber, columnNumber].Formula = @$"=COUNTIFS({sumRange}, ""P"")+COUNTIFS({sumRange}, ""A"")+COUNTIFS({sumRange}, ""L"")";
sheet.Range[rowNumber, columnNumber].Formula = @$"=COUNTIFS({sumRange}, ""Y"")+COUNTIFS({sumRange}, ""P"")+COUNTIFS({sumRange}, ""A"")+COUNTIFS({sumRange}, ""L"")";
sheet.Range[rowNumber, columnNumber].BorderAround();
sheet.Range[rowNumber, columnNumber].CellStyle.Font.Bold = true;
sheet.Range[rowNumber, columnNumber].CellStyle.ColorIndex = ExcelKnownColors.Grey_25_percent;
Expand All @@ -951,7 +955,7 @@ public IWorkbook GenerateAttendanceReportWorkbook(AttendanceReportModel attendan
for (int i = startCol; i <= columnNumber - 1; i++)
{
var sumRange = sheet.Range[sumStartRow, i, sumEndRow, i].AddressLocal;
sheet.Range[rowNumber, i].Formula = @$"=COUNTIFS({sumRange}, ""P"")+COUNTIFS({sumRange}, ""A"")+COUNTIFS({sumRange}, ""L"")";
sheet.Range[rowNumber, i].Formula = @$"=COUNTIFS({sumRange}, ""Y"")+COUNTIFS({sumRange}, ""P"")+COUNTIFS({sumRange}, ""A"")+COUNTIFS({sumRange}, ""L"")";
sheet.Range[rowNumber, i].BorderAround();
sheet.Range[rowNumber, i].CellStyle.Font.Bold = true;
sheet.Range[rowNumber, i].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
Expand Down
3 changes: 0 additions & 3 deletions Topo/Controller/AdditionalAwardsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ internal async Task UnitChange(string unitId)
{
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
_storageService.UnitName = "";
model.UnitName = _storageService.UnitName;
model.Members = new List<MemberListModel>();
return;
}
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.UnitId).FirstOrDefault().Value;
var allMembers = await _membersService.GetMembersAsync(model.UnitId);
model.Members = allMembers.Where(m => m.isAdultLeader == 0).OrderBy(m => m.first_name).ThenBy(m => m.last_name).ToList();
model.UnitName = _storageService.UnitName;
Expand Down
4 changes: 0 additions & 4 deletions Topo/Controller/ApprovalsBackupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ protected override void OnInitialized()
if (_storageService.UnitId != null)
{
model.SelectedUnitId = _storageService.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.SelectedUnitId).FirstOrDefault().Value;
model.SelectedUnitName = _storageService.UnitName;
}
model.GroupName = _storageService.GroupNameDisplay;
Expand All @@ -51,8 +49,6 @@ internal async Task UnitChange(ChangeEventArgs e)
var unitId = e.Value?.ToString() ?? "";
model.SelectedUnitId = unitId;
_storageService.UnitId = model.SelectedUnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.SelectedUnitId).FirstOrDefault().Value;
model.SelectedUnitName = _storageService.UnitName;
}

Expand Down
4 changes: 0 additions & 4 deletions Topo/Controller/ApprovalsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ protected override void OnInitialized()
if (_storageService.UnitId != null)
{
model.UnitId = _storageService.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.UnitId).FirstOrDefault().Value;
model.UnitName = _storageService.UnitName;
}
}
Expand All @@ -61,8 +59,6 @@ internal async Task UnitChange(ChangeEventArgs e)
var unitId = e.Value?.ToString() ?? "";
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.UnitId).FirstOrDefault().Value;
model.UnitName = _storageService.UnitName;
await RefreshApprovalsClick();
}
Expand Down
3 changes: 0 additions & 3 deletions Topo/Controller/LogbookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@ internal async Task UnitChange(string unitId)
{
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
_storageService.UnitName = "";
model.UnitName = _storageService.UnitName;
model.Members = new List<MemberListModel>();
return;
}
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.UnitId).FirstOrDefault().Value;
model.UnitName = _storageService.UnitName;
await PopulateMembers();
}
Expand Down
3 changes: 0 additions & 3 deletions Topo/Controller/MembersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ internal async Task UnitChange(string unitId)
{
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
_storageService.UnitName = "";
model.UnitName = _storageService.UnitName;
model.Members = new List<MemberListModel>();
return;
}
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.UnitId).FirstOrDefault().Value;
var allMembers = await _membersService.GetMembersAsync(model.UnitId);
model.Members = allMembers.Where(m => m.isAdultLeader == 0).OrderBy(m => m.first_name).ThenBy(m => m.last_name).ToList();
model.UnitName = _storageService.UnitName;
Expand Down
6 changes: 2 additions & 4 deletions Topo/Controller/MilestoneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ protected override void OnInitialized()
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

model.GroupName = _storageService.GroupNameDisplay;
model.Units = _storageService.Units;
model.UnitId = _storageService.UnitId;
model.UnitName = _storageService.UnitName;
model.GroupName = _storageService.GroupNameDisplay;
model.Units = _storageService.Units;
}

internal async Task UnitChange(ChangeEventArgs e)
{
var unitId = e.Value?.ToString() ?? "";
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.UnitId).FirstOrDefault().Value;
model.UnitName = _storageService.UnitName;
}

Expand Down
2 changes: 0 additions & 2 deletions Topo/Controller/OasController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ internal async Task UnitChange(string unitId)
{
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.UnitId).FirstOrDefault().Value;
model.UnitName = _storageService.UnitName;
}

Expand Down
1 change: 0 additions & 1 deletion Topo/Controller/ProgramController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ internal async Task ShowUnitCalendarClick()
}
if (!string.IsNullOrEmpty(model.CalendarId))
{
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.CalendarId)?.FirstOrDefault().Value ?? "";
_storageService.UnitId = model.CalendarId;
await _programService.SetCalendar(model.CalendarId);
var events = await _programService.GetEventsForDates(model.CalendarSearchFromDate, model.CalendarSearchToDate);
Expand Down
3 changes: 0 additions & 3 deletions Topo/Controller/ProgressController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ internal async Task UnitChange(ChangeEventArgs e)
{
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
_storageService.UnitName = "";
model.UnitName = _storageService.UnitName;
model.Members = new List<MemberListModel>();
return;
Expand All @@ -61,8 +60,6 @@ internal async Task UnitChange(ChangeEventArgs e)

async Task populateMembers()
{
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == _storageService.UnitId).FirstOrDefault().Value;
var allMembers = await _membersService.GetMembersAsync(_storageService.UnitId);
model.Members = allMembers.Where(m => m.isAdultLeader == 0).OrderBy(m => m.first_name).ThenBy(m => m.last_name).ToList();
model.UnitName = _storageService.UnitName;
Expand Down
3 changes: 0 additions & 3 deletions Topo/Controller/SIAController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ internal async Task UnitChange(string unitId)
{
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
_storageService.UnitName = "";
model.UnitName = _storageService.UnitName;
model.Members = new List<MemberListModel>();
return;
}
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.UnitId).FirstOrDefault().Value;
var allMembers = await _membersService.GetMembersAsync(model.UnitId);
model.Members = allMembers.Where(m => m.isAdultLeader == 0).OrderBy(m => m.first_name).ThenBy(m => m.last_name).ToList();
model.UnitName = _storageService.UnitName;
Expand Down
12 changes: 7 additions & 5 deletions Topo/Controller/WallchartController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ protected override void OnInitialized()
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

if (_storageService.UnitId != null)
{
model.UnitId = _storageService.UnitId;
model.UnitName = _storageService.UnitName;
}

model.GroupName = _storageService.GroupNameDisplay;
model.Units = _storageService.Units;
model.UnitId = _storageService.UnitId;
model.UnitName = _storageService.UnitName;
}

internal async Task UnitChange(ChangeEventArgs e)

Check warning on line 48 in Topo/Controller/WallchartController.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-pages

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var unitId = e.Value?.ToString() ?? "";
_storageService.UnitId = unitId;
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
if (_storageService.Units != null)
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.UnitId).FirstOrDefault().Value;
model.UnitName = _storageService.UnitName;
}

Expand Down
27 changes: 13 additions & 14 deletions Topo/Services/ProgramService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public async Task<EventListModel> GetAttendanceForEvent(string eventId)
{
eventAttendance.Add(new EventAttendance
{
id = member.id,
first_name = member.first_name,
last_name = member.last_name,
member_number = member.member_number,
Expand All @@ -149,19 +150,21 @@ public async Task<EventListModel> GetAttendanceForEvent(string eventId)
if (eventAttendance.Any(a => a.member_number == attended.member_number))
{
eventAttendance.Where(a => a.member_number == attended.member_number).Single().attended = true;
eventAttendance.Where(a => a.member_number == attended.member_number).Single().pal = "Y";
}
else
{
// Load out of unit members
eventAttendance.Add(new EventAttendance
{
id = attended.id,
first_name = attended.first_name,
last_name = attended.last_name,
member_number = attended.member_number,
patrol_name = "",
isAdultMember = false,
attended = true,
pal = ""
pal = "Y"
});
}
}
Expand Down Expand Up @@ -213,7 +216,6 @@ public async Task<AttendanceReportModel> GenerateAttendanceReportData(DateTime f
var attendanceReport = new AttendanceReportModel();
var attendanceReportItems = new List<AttendanceReportItemModel>();
await SetCalendar(selectedCalendar);
var members = await _memberService.GetMembersAsync(_storageService.UnitId);

var programEvents = await GetEventsForDates(fromDate, toDate);
await ResetCalendar();
Expand All @@ -228,35 +230,33 @@ public async Task<AttendanceReportModel> GenerateAttendanceReportData(DateTime f
{
var eventListModel = await GetAttendanceForEvent(programEvent.Id);
programEvent.attendees = eventListModel.attendees;
foreach (var member in members)
foreach (var attendee in programEvent.attendees)
{
var attended = programEvent.attendees.Where(a => a.member_number == member.member_number).SingleOrDefault()?.attended ?? false;
var pal = programEvent.attendees.Where(a => a.member_number == member.member_number).SingleOrDefault()?.pal ?? "";
attendanceReportItems.Add(new AttendanceReportItemModel
{
MemberId = member.id,
MemberName = $"{member.first_name} {member.last_name}",
MemberFirstName = member.first_name,
MemberLastName = member.last_name,
MemberId = attendee.id,
MemberName = $"{attendee.first_name} {attendee.last_name}",
MemberFirstName = attendee.first_name,
MemberLastName = attendee.last_name,
EventName = programEvent.EventName,
EventChallengeArea = programEvent.ChallengeArea,
EventStartDate = programEvent.StartDateTime,
EventNameDisplay = $"{programEvent.EventName} {programEvent.EventDate}",
Attended = attended ? 1 : 0,
IsAdultMember = member.isAdultLeader,
Attended = attendee.attended ? 1 : 0,
IsAdultMember = attendee.isAdultMember ? 1 : 0,
EventStatus = programEvent.EventStatus,
Pal = pal
Pal = attendee.pal
});
}
}
attendanceReport.attendanceReportItems = attendanceReportItems;

var memberSummaries = new List<AttendanceReportMemberSummaryModel>();
var attendanceReportItemsGroupedByMember = attendanceReportItems.GroupBy(a => a.MemberId);
var totalEvents = attendanceReportItems.DistinctBy(i => i.EventNameDisplay).Where(ma => ma.EventStartDate <= DateTime.Now).Count();
foreach (var memberAttendance in attendanceReportItemsGroupedByMember)
{
var attendedCount = memberAttendance.Where(ma => ma.EventStartDate <= DateTime.Now).Sum(ma => ma.Attended);
var totalEvents = memberAttendance.Where(ma => ma.EventStartDate <= DateTime.Now).Count();
memberSummaries.Add(new AttendanceReportMemberSummaryModel
{
MemberId = memberAttendance.Key,
Expand All @@ -270,7 +270,6 @@ public async Task<AttendanceReportModel> GenerateAttendanceReportData(DateTime f
foreach (var attendanceItem in attendanceReportItems)
{
var attendanceCount = memberSummaries.Where(ms => ms.MemberId == attendanceItem.MemberId).FirstOrDefault()?.AttendanceCount ?? 0;
var totalEvents = memberSummaries.Where(ms => ms.MemberId == attendanceItem.MemberId).FirstOrDefault()?.TotalEvents ?? 0;
var attendanceRate = totalEvents == 0 ? 0 : (decimal)attendanceCount / totalEvents * 100m;
attendanceItem.MemberNameAndRate = $"{attendanceItem.MemberName} ({Math.Round(attendanceRate, 0)}%)";
}
Expand Down
Loading

0 comments on commit 6bc56d3

Please sign in to comment.