Skip to content

Commit

Permalink
Merge pull request #512 from wri/TM-1322
Browse files Browse the repository at this point in the history
[TM-1322] Implement Workdays For HBF Reporting
  • Loading branch information
Scriptmatico authored Oct 18, 2024
2 parents efe1560 + 5a892e9 commit 3c52b1d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/Models/Traits/HasWorkdays.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait HasWorkdays
{
public static function bootHasWorkdays()
{
collect([static::WORKDAY_COLLECTIONS['paid'], static::WORKDAY_COLLECTIONS['volunteer']])
collect([static::WORKDAY_COLLECTIONS['paid'], static::WORKDAY_COLLECTIONS['volunteer'], static::WORKDAY_COLLECTIONS['finance']])
->flatten()
->each(function ($collection) {
self::resolveRelationUsing(
Expand Down Expand Up @@ -72,7 +72,7 @@ public function setOtherWorkdaysDescriptionAttribute(?string $value): void

protected function sumTotalWorkdaysAmounts(array $collections): int
{
// Assume that the types are balanced, and just return the value from `gender`
// Gender is considered the canonical total value for all current types of workdays, so just pull and sum gender.
return WorkdayDemographic::whereIn(
'workday_id',
$this->workdays()->visible()->collections($collections)->select('id')
Expand Down
4 changes: 4 additions & 0 deletions app/Models/V2/Projects/ProjectReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ class ProjectReport extends Model implements MediaModel, AuditableContract, Repo
Workday::COLLECTION_PROJECT_PAID_OTHER,
Workday::COLLECTION_PROJECT_VOLUNTEER_OTHER,
],
'finance' => [
Workday::COLLECTION_PROJECT_DIRECT,
Workday::COLLECTION_PROJECT_CONVERGENCE,
],
];

public function registerMediaConversions(Media $media = null): void
Expand Down
4 changes: 4 additions & 0 deletions app/Models/V2/Sites/SiteReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class SiteReport extends Model implements MediaModel, AuditableContract, ReportM
Workday::COLLECTION_SITE_PAID_OTHER,
Workday::COLLECTION_SITE_VOLUNTEER_OTHER,
],
'finance' => [
Workday::COLLECTION_PROJECT_DIRECT,
Workday::COLLECTION_PROJECT_CONVERGENCE,
],
];

public function registerMediaConversions(Media $media = null): void
Expand Down
2 changes: 2 additions & 0 deletions app/Models/V2/Workdays/Workday.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Workday extends Model implements HandlesLinkedFieldSync
public const COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPERATIONS = 'volunteer-nursery-operations';
public const COLLECTION_PROJECT_VOLUNTEER_PROJECT_MANAGEMENT = 'volunteer-project-management';
public const COLLECTION_PROJECT_VOLUNTEER_OTHER = 'volunteer-other-activities';
public const COLLECTION_PROJECT_DIRECT = 'direct';
public const COLLECTION_PROJECT_CONVERGENCE = 'convergence';

public const PROJECT_COLLECTION = [
self::COLLECTION_PROJECT_PAID_NURSERY_OPERATIONS => 'Paid Nursery Operations',
Expand Down
6 changes: 6 additions & 0 deletions app/Models/V2/Workdays/WorkdayDemographic.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WorkdayDemographic extends Model
public const GENDER = 'gender';
public const AGE = 'age';
public const ETHNICITY = 'ethnicity';
public const CASTE = 'caste';

public function workday(): BelongsTo
{
Expand Down Expand Up @@ -60,4 +61,9 @@ public function scopeIsEthnicity(Builder $query, string $ethnicity, string $name
{
return $query->where(['type' => self::ETHNICITY, 'subtype' => $ethnicity, 'name' => $name]);
}

public function scopeCaste(Builder $query): Builder
{
return $query->where('type', self::CASTE);
}
}
28 changes: 28 additions & 0 deletions config/wri/linked-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,20 @@
'collection' => 'volunteer-other-activities',
'option_list_key' => 'workdays-ethnicity',
],
'pro-rep-direct-workdays' => [
'property' => 'workdaysDirect',
'label' => 'Direct Workday',
'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource',
'input_type' => 'workdays',
'collection' => 'direct',
],
'pro-rep-convergence-workdays' => [
'property' => 'workdaysConvergence',
'label' => 'Convergence Workday',
'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource',
'input_type' => 'workdays',
'collection' => 'convergence',
],
],
'file-collections' => [
'pro-rep-col-media' => ['property' => 'media', 'label' => 'Media', 'input_type' => 'file', 'multichoice' => true],
Expand Down Expand Up @@ -745,6 +759,20 @@
'collection' => 'volunteer-other-activities',
'option_list_key' => 'workdays-ethnicity',
],
'site-rep-direct-workdays' => [
'property' => 'workdaysDirect',
'label' => 'Direct Workday',
'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource',
'input_type' => 'workdays',
'collection' => 'direct',
],
'site-rep-convergence-workdays' => [
'property' => 'workdaysConvergence',
'label' => 'Convergence Workday',
'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource',
'input_type' => 'workdays',
'collection' => 'convergence',
],
],
],
'nursery' => [
Expand Down

0 comments on commit 3c52b1d

Please sign in to comment.