2017-09-12 12:43:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Jobs\Job;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\Expense;
|
|
|
|
use App\Models\Task;
|
|
|
|
|
|
|
|
class GenerateCalendarEvents extends Job
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2017-09-12 16:16:18 +02:00
|
|
|
$events = [];
|
|
|
|
$filter = request()->filter ?: [];
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
ENTITY_INVOICE => Invoice::scope()->invoices(),
|
|
|
|
ENTITY_QUOTE => Invoice::scope()->quotes(),
|
|
|
|
ENTITY_TASK => Task::scope(),
|
|
|
|
ENTITY_PAYMENT => Payment::scope(),
|
|
|
|
ENTITY_EXPENSE => Expense::scope(),
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($data as $type => $source) {
|
|
|
|
if (! count($filter) || in_array($type, $filter)) {
|
|
|
|
foreach ($source->get() as $entity) {
|
2017-09-12 23:20:18 +02:00
|
|
|
$subColors = count($filter) == 1;
|
|
|
|
$events[] = $entity->present()->calendarEvent($subColors);
|
2017-09-12 16:16:18 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-12 12:43:59 +02:00
|
|
|
}
|
|
|
|
|
2017-09-12 16:16:18 +02:00
|
|
|
return $events;
|
2017-09-12 12:43:59 +02:00
|
|
|
}
|
|
|
|
}
|