[Done] Set minimum date from harvest data file.
This commit is contained in:
parent
66b58ced54
commit
9d744a95a2
|
|
@ -24,7 +24,7 @@ class ProjectDownloadTiffJob implements ShouldQueue
|
|||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(ProjectDownload $download, Carbon $date,)
|
||||
public function __construct(ProjectDownload $download, Carbon $date)
|
||||
{
|
||||
$this->date = $date;
|
||||
$this->download = $download;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ class Project extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
'min_harvest_date' => 'date'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'mail_template',
|
||||
|
|
@ -30,12 +34,16 @@ class Project extends Model
|
|||
'download_path',
|
||||
'pivot_json_path',
|
||||
'span_json_path',
|
||||
'harvest_json_path'
|
||||
'harvest_json_path',
|
||||
'min_harvest_date'
|
||||
];
|
||||
|
||||
public static function saveWithFormData(mixed $formData)
|
||||
{
|
||||
$uniqueIdentifier = ['id' => $formData['id'] ?? null];
|
||||
/**
|
||||
* @var Project $project
|
||||
*/
|
||||
$project = Project::updateOrCreate($uniqueIdentifier, $formData);
|
||||
$baseFrom = 'livewire-tmp/';
|
||||
$baseTo = $project->download_path.'/Data/';
|
||||
|
|
@ -49,7 +57,9 @@ public static function saveWithFormData(mixed $formData)
|
|||
}
|
||||
if ($formData['harvest_file']) {
|
||||
Storage::copy($baseFrom.$formData['harvest_file']['tmpFilename'],$baseTo.'harvest.'.$formData['harvest_file']['extension']);
|
||||
$project->update(['harvest_json_path' => $baseTo.'harvest.'.$formData['harvest_file']['extension']]);
|
||||
if($project->update(['harvest_json_path' => $baseTo.'harvest.'.$formData['harvest_file']['extension']])) {
|
||||
$project->setMinHarvestDate();
|
||||
}
|
||||
}
|
||||
}
|
||||
private function upsertMailRecipients($formData)
|
||||
|
|
@ -333,14 +343,14 @@ public function getMosaicsFor(Carbon $endDate, int $offset= 7): array
|
|||
->toArray();
|
||||
}
|
||||
|
||||
public function missingDownloadsInHarvestFile()
|
||||
public function setMinHarvestDate():bool
|
||||
{
|
||||
if(!$this->harvest_json_path){
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
$dates = $this->downloads->map(fn($d)=>$d->date)->sort();
|
||||
return $this->update(['min_harvest_date'=> $this->getMinimumDateFromHarvestExcelFile()->format('Y-m-d')]);
|
||||
}
|
||||
private function getMinimumDateFromHarvestExcelFile()
|
||||
private function getMinimumDateFromHarvestExcelFile():Carbon
|
||||
{
|
||||
$value = Storage::disk('local')->path($this->harvest_json_path);
|
||||
$data = Excel::toCollection(new \App\Imports\ExcelFileImport(),$value);
|
||||
|
|
|
|||
Loading…
Reference in a new issue