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