Created
October 1, 2021 08:14
-
-
Save bingogg14/9d703c58e344df2267d96952baf04fc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @return HasOne | |
*/ | |
public function statusReviews(): HasOne | |
{ | |
return $this->hasOne(DailyReview::class, 'weekly_review_id', 'id') | |
->select('weekly_review_id', | |
DB::raw('daily_reviews.approved_by IS NOT NULL as daily_reviews_is_approved') | |
) | |
->groupBy('weekly_review_id'); | |
} | |
/** | |
* @return mixed | |
*/ | |
protected function getStatusReviewsRelation() | |
{ | |
if ( ! $this->relationLoaded('statusReviews')) | |
$this->load('statusReviews'); | |
return $this->getRelation('statusReviews'); | |
} | |
/** | |
* @return string|null | |
*/ | |
public function getStatusWeekReviewAttribute(): ?string | |
{ | |
$relation = $this->getStatusReviewsRelation(); | |
if ($relation) { | |
$DailyReviewIsApproved = $relation->daily_reviews_is_approved; | |
$WeeklyReviewIsApproved = $this->approved_by ? true : false; | |
if ($DailyReviewIsApproved) { | |
if ($WeeklyReviewIsApproved) { | |
return self::WEEKLY_REVIEW_STATUSES[1]['value']; //Approved | |
} | |
return self::WEEKLY_REVIEW_STATUSES[0]['value']; //PendingWeekly | |
} | |
return self::WEEKLY_REVIEW_STATUSES[2]['value']; //PendingDaily | |
} | |
return null; | |
} | |
/** Get Weekly Totals */ | |
public function weekTotals(): HasOne | |
{ | |
return $this->hasOne(DailyReportJobTier::class, 'weekly_review_id', 'id') | |
->select('weekly_review_id', | |
DB::raw('SUM(daily_report_job_tier.regular_time) as rt_total'), | |
DB::raw('SUM(daily_report_job_tier.overtime) as ot_total'), | |
DB::raw('SUM(daily_report_job_tier.double_time) as dt_total'), | |
DB::raw('(SUM(daily_report_job_tier.regular_time) + SUM(daily_report_job_tier.overtime) + SUM(daily_report_job_tier.double_time)) as week_total') | |
) | |
->groupBy('weekly_review_id'); | |
} | |
/** | |
* @return mixed | |
*/ | |
protected function getWeekTotalRelation() | |
{ | |
if ( ! $this->relationLoaded('weekTotals')) | |
$this->load('weekTotals'); | |
return $this->getRelation('weekTotals'); | |
} | |
/** | |
* @return string|null | |
*/ | |
public function getWeekTotalAttribute(): ?string | |
{ | |
return $this->getWeekTotalRelation() ? (string) $this->getWeekTotalRelation()->week_total : null; | |
} | |
/** | |
* @return string|null | |
*/ | |
public function getWeekTotalRegularTimeAttribute(): ?string | |
{ | |
return $this->getWeekTotalRelation() ? (string) $this->getWeekTotalRelation()->rt_total : null; | |
} | |
/** | |
* @return string|null | |
*/ | |
public function getWeekTotalDoubleTimeAttribute(): ?string | |
{ | |
return $this->getWeekTotalRelation() ? (string) $this->getWeekTotalRelation()->dt_total : null; | |
} | |
/** | |
* @return string|null | |
*/ | |
public function getWeekTotalOverTimeAttribute(): ?string | |
{ | |
return $this->getWeekTotalRelation() ? (string) $this->getWeekTotalRelation()->ot_total : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment