Skip to content

Commit

Permalink
Merge pull request #218 from marzmehr/SS-773
Browse files Browse the repository at this point in the history
SS-776: Adding functionality to accommodate DateRange on training reports
  • Loading branch information
marzmehr committed Feb 17, 2024
2 parents 98e5aff + 14a8edc commit 957858e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 23 deletions.
66 changes: 56 additions & 10 deletions api/services/usermanagement/TrainingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,24 @@ public async Task<List<TrainingReportDto>> GetSheriffsTrainingReports(TrainingRe
}
else
{
var takenTraining = sheriff.Training.Find(t => t.TrainingTypeId == training.Id);
var timezone = takenTraining.Timezone == null? "America/Vancouver" : takenTraining.Timezone;
var trainingStatus = GetTrainingStatus(takenTraining.TrainingCertificationExpiry, timezone, training.AdvanceNotice, training, takenTraining.FirstNotice);
var takenTrainings = sheriff.Training.FindAll(t => t.TrainingTypeId == training.Id).OrderByDescending(t => t.EndDate).ToList();
var takenTraining = new SheriffTraining();
var timezone = "";

TrainingStatus trainingStatus = new TrainingStatus();
if(trainingReportSearch.startDate != null && trainingReportSearch.endDate != null)
{
var takenTrainingInRange = takenTrainings.Find(t => t.EndDate < trainingReportSearch.endDate);
takenTraining = takenTrainingInRange !=null ? takenTrainingInRange : takenTrainings.LastOrDefault();
timezone = takenTraining.Timezone == null? "America/Vancouver" : takenTraining.Timezone;
trainingStatus = GetTrainingStatusOnDateRange(trainingReportSearch, takenTraining.TrainingCertificationExpiry, timezone, training, takenTraining.EndDate);
}
else
{
takenTraining = takenTrainings[0];
timezone = takenTraining.Timezone == null? "America/Vancouver" : takenTraining.Timezone;
trainingStatus = GetTrainingStatus(takenTraining.TrainingCertificationExpiry, timezone, training.AdvanceNotice, training, takenTraining.FirstNotice);
}

sheriffTrainings.Add(new TrainingReportDto()
{
Expand All @@ -134,13 +149,13 @@ public async Task<List<TrainingReportDto>> GetSheriffsTrainingReports(TrainingRe

Logger.LogInformation("__________End_Creating_Reports____________");

if(trainingReportSearch.startDate != null && trainingReportSearch.endDate != null)
return sheriffTrainings.FindAll(t =>
t.end>=trainingReportSearch.startDate &&
t.end<=trainingReportSearch.endDate
);
else
return sheriffTrainings;
// if(trainingReportSearch.startDate != null && trainingReportSearch.endDate != null)
// return sheriffTrainings.FindAll(t =>
// t.end>=trainingReportSearch.startDate &&
// t.end<=trainingReportSearch.endDate
// );
// else
return sheriffTrainings;
}

#endregion Training Reports
Expand Down Expand Up @@ -223,6 +238,37 @@ private TrainingStatus GetTrainingStatus(DateTimeOffset? requalificationDate, s
return trainingStatus;
}

private TrainingStatus GetTrainingStatusOnDateRange(TrainingReportSearchDto trainingReportSearch, DateTimeOffset? requalificationDate, string timezone, LookupCode trainingType, DateTimeOffset trainingCompletionDate)
{
TrainingStatus trainingStatus = new TrainingStatus();

var reportEndDate = ((DateTimeOffset)trainingReportSearch.endDate).ConvertToTimezone(timezone);
var expiryDate = IsRotatingTraining(trainingType)? requalificationDate : requalificationDate?.AddYears(1);

if(reportEndDate > expiryDate)
{
trainingStatus.rowType = "alert";
trainingStatus.status = TrainingStatusTypes.alert;
}
else if(reportEndDate > requalificationDate)
{
trainingStatus.rowType = "warning";
trainingStatus.status = TrainingStatusTypes.warning;
}
else if(reportEndDate >= trainingCompletionDate && (reportEndDate <= requalificationDate || requalificationDate == null) )
{
trainingStatus.rowType = "white";
trainingStatus.status = "";
}
else
{
trainingStatus.rowType = "danger";
trainingStatus.status = TrainingStatusTypes.danger;
}

return trainingStatus;
}

public bool IsRotatingTraining(LookupCode trainingType){
return trainingType.Rotating || !YearsInDays.Contains(trainingType.ValidityPeriod);
}
Expand Down
19 changes: 18 additions & 1 deletion web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<link
rel="icon"
href="<%= BASE_URL %>images/bcid-favicon-32x32.png"
sizes="32x32"
type="image/png"
/>
<link
rel="icon"
href="<%= BASE_URL %>images/bcid-favicon-16x16.png"
sizes="16x16"
type="image/png"
/>
<link
rel="mask-icon"
href="<%= BASE_URL %>images/bcid-apple-icon.svg"
color="#036"
/>
<link rel="icon" href="<%= BASE_URL %>images/bcid-favicon-32x32.png" />
<title>Sheriff Scheduling</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class Home extends Vue {
location = {} as locationInfoType;
trainingTypeOptions: leaveTrainingTypeInfoType[] = [];
statusOptions: trainingStatusInfoType = { danger:'Not Taken', alert:'Expired', warning:'Requalification <br> Requierd', notify:'Requalify Soon' };
statusOptions: trainingStatusInfoType = { danger:'Not Taken', alert:'Expired', warning:'Requalification <br> Required', notify:'Requalify Soon' };
training: trainingStatusCardInfoType = { danger: [], alert: [], warning: [], notify: [] };
trainingAlert=false;
Expand Down
19 changes: 11 additions & 8 deletions web/src/components/MyTeam/Components/DateRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import moment from 'moment-timezone';
import * as _ from 'underscore';
import Spinner from "@components/Spinner.vue";
// import moment from 'moment-timezone';
// import * as _ from 'underscore';
// import Spinner from "@components/Spinner.vue";
import { dateRangeInfoType } from '@/types/common';
Expand All @@ -74,17 +74,20 @@
}
public onContextStart(ctx) {
console.log(ctx)
// console.log(ctx)
if(this.dateRange.endDate && ctx>this.dateRange.endDate)
this.dateRange.startDate=""
if(!this.dateRange.endDate) this.dateRange.endDate = this.dateRange.startDate
this.dateRange.endDate = "";
// else if(!this.dateRange.endDate)
// this.dateRange.endDate = this.dateRange.startDate;
this.validateDates()
}
public onContextEnd(ctx) {
console.log(ctx)
// console.log(ctx)
if(this.dateRange.startDate && ctx<this.dateRange.startDate)
this.dateRange.endDate=""
this.dateRange.endDate = "";
// else if(!this.dateRange.startDate)
// this.dateRange.startDate = this.dateRange.endDate;
this.validateDates()
}
Expand Down
16 changes: 13 additions & 3 deletions web/src/components/MyTeam/ViewReports.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<b-col cols="4">
<date-range :dateRange="reportDateRange" @rangeChanged="clearReports()"/>
</b-col>
<b-col cols="5" class="text-left">
<b-col cols="6" class="text-left">
<label class="h4 mb-2 p-0 ml-4" >Filter By</label>
<b-form-checkbox-group
class="ml-4"
Expand All @@ -125,7 +125,6 @@
:options="Object.values(statusOptions)"
/>
</b-col>
<b-col cols="1"/>
<b-col cols="2">
<b-button
style="float:right; padding: 0.25rem 1rem; margin-top:1.5rem;"
Expand Down Expand Up @@ -181,7 +180,13 @@
variant="primary"
@click="downloadReport()"
><spinner color="#FFF" v-if="generatingReport" style="margin:0; padding: 0; height:2rem; transform:translate(0px,-24px);"/>
<span style="font-size: 18px;" v-else><b-icon-download class="mr-2"/>Download SCV File</span>
<b-row class="mx-1" style="font-size: 18px;" v-else>
<b-icon-download class="mr-2"/>
Download CSV File
<div style="line-height:1rem; transform:translate(5px,6px)">
<i style="font-size:20pt;" class="mdi mdi-file-excel"></i>
</div>
</b-row>
</b-button>
</b-row>
</div>
Expand Down Expand Up @@ -319,6 +324,11 @@
this.reportTypeState = true;
this.reportSubTypeState = true;
if(!this.reportDateRange.valid){
this.reportDateRange.startDate = ''
this.reportDateRange.endDate = ''
}
if (!this.reportParameters.reportType){
this.reportTypeState = false;
}
Expand Down

0 comments on commit 957858e

Please sign in to comment.