wip
This commit is contained in:
parent
2867288eef
commit
944b968998
|
|
@ -35,6 +35,7 @@ public function __construct(ProjectReport $projectReport, $sendMail = false)
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
// TODO check the changements due to migration
|
||||
$this->projectReport->weeksAgo();
|
||||
|
||||
$projectFolder = base_path('../');
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use function Livewire\off;
|
||||
|
||||
class Project extends Model
|
||||
{
|
||||
|
|
@ -258,6 +259,7 @@ public function startDownload(Carbon $date)
|
|||
|
||||
public function schedule()
|
||||
{
|
||||
//TODO check the ranges.
|
||||
$this->scheduleReport();
|
||||
}
|
||||
|
||||
|
|
@ -269,31 +271,11 @@ public function shouldSchedule(): bool
|
|||
return false;
|
||||
}
|
||||
|
||||
// TODO remove function when it's done
|
||||
// public function hasInvalidMosaicFor($year, $week): bool
|
||||
// {
|
||||
//
|
||||
// $dayOfWeekIso = Carbon::parse($this->mail_day)->dayOfWeekIso;
|
||||
// $min_updated_at_date = now()
|
||||
// ->setISODate($year, $week)
|
||||
// ->startOfWeek()
|
||||
// ->addDays($dayOfWeekIso - 1)
|
||||
// ->format('Y-m-d');
|
||||
//
|
||||
// return $this->mosaics()
|
||||
// ->where('updated_at', '>=', $min_updated_at_date)
|
||||
// ->statusSuccess()
|
||||
// ->where(['year' => $year, 'week' => $week])
|
||||
// ->exists();
|
||||
//
|
||||
// }
|
||||
|
||||
public function hasInvalidMosaicFor(Carbon $endDate,int $offset): bool
|
||||
{
|
||||
// parameters : $
|
||||
// check if the mail day happens the day before mosaic -> good
|
||||
|
||||
//TODO use end_date and offset
|
||||
$dayOfWeekIso = Carbon::parse($this->mail_day)->dayOfWeekIso;
|
||||
$min_updated_at_date = $endDate
|
||||
->startOfWeek()
|
||||
|
|
@ -308,34 +290,32 @@ public function hasInvalidMosaicFor(Carbon $endDate,int $offset): bool
|
|||
|
||||
}
|
||||
|
||||
public function scheduleReport($year = null, $week = null)
|
||||
public function scheduleReport(?Carbon $endDate = null, ?int $offset = null)
|
||||
{
|
||||
// if year, week is in the future set year and week to null;
|
||||
if (now()->year < $year || (now()->year === $year && now()->weekOfYear < $week)) {
|
||||
$year = null;
|
||||
$week = null;
|
||||
logger('year and week is in the future default to now');
|
||||
if($endDate->isFuture() || $endDate->isToday() || $offset <= 0){
|
||||
logger('EndDate is today or in the future.');
|
||||
$endDate = null;
|
||||
$offset = null;
|
||||
}
|
||||
|
||||
$year = $year ?? now()->year;
|
||||
$week = $week ?? now()->weekOfYear;
|
||||
// TODO change to period
|
||||
$endDate = $year ?? Carbon::yesterday();
|
||||
$offset = $week ?? 1;
|
||||
Bus::chain([
|
||||
Bus::batch($this->getFileDownloadsFor($year, $week)),
|
||||
Bus::batch($this->getMosaicsFor($year, $week)),
|
||||
Bus::batch([$this->getReportFor($year, $week,true)]),
|
||||
Bus::batch($this->getFileDownloadsFor($endDate, $offset)),
|
||||
Bus::batch($this->getMosaicsFor($endDate, $offset)),
|
||||
Bus::batch([$this->getReportFor($endDate, $offset,true)]),
|
||||
])
|
||||
->dispatch();
|
||||
return "done";
|
||||
}
|
||||
|
||||
public function getReportFor($year, $week, $sendMail = false)
|
||||
public function getReportFor(Carbon $endDate, $offset, $sendMail = false): ProjectReportGeneratorJob
|
||||
{
|
||||
$report = $this->reports()->create([
|
||||
'name' => 'Report for week '.$week.' of '.$year,
|
||||
'week' => $week,
|
||||
'year' => $year,
|
||||
'path' => 'reports/week_'.$week.'_'.$year.'.docx',
|
||||
'name' => 'Report of the '.$endDate->format('d-m-Y').' from the past '.$offset.' days',
|
||||
'end_date' => $endDate,
|
||||
'offset' => $offset,
|
||||
'path' => 'reports/'.ProjectReport::getFileName($endDate,$offset).'.docx',
|
||||
]);
|
||||
|
||||
return (new ProjectReportGeneratorJob($report, $sendMail));
|
||||
|
|
@ -352,7 +332,7 @@ public function getFileDownloadsFor(Carbon $endDate, $offset):array
|
|||
->toArray();
|
||||
}
|
||||
|
||||
public function getMosaicsFor(Carbon $endDate, $offset= 7)
|
||||
public function getMosaicsFor(Carbon $endDate, $offset= 7): array
|
||||
{
|
||||
logger(sprintf('in Get Mosaics for Period %s with %d offset', $endDate->format('Y-m-d'),$offset));
|
||||
return collect(range(0, 3))
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@
|
|||
use App\Jobs\ProjectDownloadTiffJob;
|
||||
use App\Jobs\ProjectMosiacGeneratorJob;
|
||||
use App\Traits\HasStatus;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class ProjectReport extends Model
|
||||
|
|
@ -26,10 +26,14 @@ public function project()
|
|||
}
|
||||
|
||||
|
||||
public function getFileName()
|
||||
public function getFileNameAttribute()
|
||||
{
|
||||
return 'Period_'.$this->end_date->copy()->subDays($this->offset).'_'.$this->end_date;
|
||||
return static::getFileName($this->end_date,$this->offset);
|
||||
}
|
||||
public static function getFileName(Carbon $endDate, int $offset): string
|
||||
{
|
||||
return 'Period_'.$endDate->copy()->subDays($offset).'_'.$endDate;
|
||||
}
|
||||
|
||||
public function getFullPathName()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue