From e8730904c4cd5a4800640b333346ea92a9b6c4a2 Mon Sep 17 00:00:00 2001 From: mikeburg Date: Thu, 14 Nov 2024 11:40:51 -0800 Subject: [PATCH] New timesheet back fill buton. (#2135) --- app/components/person/timesheet-backfill.hbs | 31 ++++++ app/components/person/timesheet-backfill.js | 106 +++++++++++++++++++ app/templates/person/timesheet.hbs | 22 ++-- 3 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 app/components/person/timesheet-backfill.hbs create mode 100644 app/components/person/timesheet-backfill.js diff --git a/app/components/person/timesheet-backfill.hbs b/app/components/person/timesheet-backfill.hbs new file mode 100644 index 00000000..45073357 --- /dev/null +++ b/app/components/person/timesheet-backfill.hbs @@ -0,0 +1,31 @@ +{{#if this.session.isAdmin}} + + Back Fill Service Years + +{{/if}} + +{{#if this.yearsForm}} + + + Select Years To Back Fill + +

+ For each selected year, a single Dirt timesheet entry will be created with an on-duty time of Jan 1st at + 12:00:00 and an off-duty time of Jan 1st at 12:01:00. Any year that already has any timesheet entries, + regardless of position, will be skipped. +

+ + + +
+ + + + +
+
+{{/if}} + +{{#if this.isSubmitting}} + +{{/if}} \ No newline at end of file diff --git a/app/components/person/timesheet-backfill.js b/app/components/person/timesheet-backfill.js new file mode 100644 index 00000000..b76b43af --- /dev/null +++ b/app/components/person/timesheet-backfill.js @@ -0,0 +1,106 @@ +import Component from '@glimmer/component'; +import {service} from '@ember/service'; +import EmberObject, {action} from '@ember/object'; +import {tracked} from '@glimmer/tracking'; +import {DIRT} from "clubhouse/constants/positions"; +import {STATUS_VERIFIED} from "clubhouse/models/timesheet"; + +export default class PersonTimesheetBackfillComponent extends Component { + @service ajax; + @service house; + @service modal; + @service session; + @service store; + @service toast; + + @tracked isSubmitting = false; + @tracked yearsForm; + @tracked isAdmin; + + constructor() { + super(...arguments); + + this.yearOptions = []; + for (let i = 1996; i <= 2010; i++) { + this.yearOptions.push(i); + } + } + + @action + openDialog() { + this.yearsForm = EmberObject.create({years: []}); + } + + @action + cancelDialog() { + this.yearsForm = null; + } + + @action + async submitYears(model) { + if (!model.years.length) { + this.modal.info('No Years Selected', 'Select one or more years to back fill.'); + return; + } + + this.isSubmitting = true; + const {person} = this.args; + const exists = []; + const backFill = []; + + for (let year of model.years) { + try { + const {timesheet} = await this.ajax.request('timesheet', { + data: { + person_id: person.id, + year + } + }); + if (timesheet.length) { + exists.push(year); + } else { + backFill.push(year); + } + } catch (response) { + this.house.handleErrorResponse(response); + this.isSubmitting = false; + return; + } + } + + if (!backFill.length) { + this.modal.info('Already back filled', + 'The year(s) selected to back fill already have one or more timesheet entries to represent the year(s). No new entries have been created.'); + this.isSubmitting = false; + return; + } + + try { + for (let year of backFill) { + const entry = this.store.createRecord('timesheet', { + person_id: person.id, + position_id: DIRT, + on_duty: `${year}-01-01 12:00:00`, + off_duty: `${year}-01-01 12:01:00`, + review_status: STATUS_VERIFIED, + additional_admin_notes: `Back fill entry created to represent year ${year}`, + suppress_duration_warning: true, + }); + + await entry.save(); + } + + await person.reload(); // Pick up new timesheet entry years + let message = `

The following year(s) were back filled: ${backFill.join(',')}

`; + if (exists.length) { + message += `

The following year(s) were NOT back filled because timesheet entries already exists for the given year(s): ${exists.join(',')}

`; + } + this.modal.info('Year(s) Back Filled', message); + this.yearsForm = null; + } catch (response) { + this.house.handleErrorResponse(response); + } finally { + this.isSubmitting = false; + } + } +} diff --git a/app/templates/person/timesheet.hbs b/app/templates/person/timesheet.hbs index ee2c83d7..1f5a2227 100644 --- a/app/templates/person/timesheet.hbs +++ b/app/templates/person/timesheet.hbs @@ -14,7 +14,7 @@ {{#if this.missingRequestPendingCount}} {{pluralize this.missingRequestPendingCount "Missing Timesheet Entry Request"}} requires attention. - Jump to Missing Timesheet Entry Requests + Jump to Missing Timesheet Entry Requests {{/if}} @@ -30,14 +30,18 @@ {{this.person.callsign}} has not yet confirmed the {{this.year}} timesheet is correct. {{/if}} - {{#if this.canForceConfirmation}} -

- As a Tech Ninja, you may {{if this.timesheetInfo.timesheet_confirmed "un-confirm" "confirm"}} the timesheet. - - {{if this.timesheetInfo.timesheet_confirmed "Un-Confirm" "Confirm"}} Timesheet - -

- {{/if}} + {{/if}} + {{#if this.session.isAdmin}} +
+
+ + + {{if this.timesheetInfo.timesheet_confirmed "Un-Confirm" "Confirm"}} Timesheet + + + +
+
{{/if}} {{#if (lt this.year 2008)}}