diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 80d85501fa3f..557dee23d998 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -125,17 +125,19 @@ class CreateTestData extends Command $this->info('Client: ' . $client->name); $this->createInvoices($client); + $this->createInvoices($client, true); } } /** * @param $client */ - private function createInvoices($client) + private function createInvoices($client, $isQuote = false) { for ($i = 0; $i < $this->count; $i++) { $data = [ 'is_public' => true, + 'is_quote' => $isQuote, 'client_id' => $client->id, 'invoice_date_sql' => date_create()->modify(rand(-100, 100) . ' days')->format('Y-m-d'), 'due_date_sql' => date_create()->modify(rand(-100, 100) . ' days')->format('Y-m-d'), @@ -206,7 +208,7 @@ class CreateTestData extends Command $data = [ 'vendor_id' => $vendor->id, 'amount' => $this->faker->randomFloat(2, 1, 10), - 'expense_date' => null, + 'expense_date' => date_create()->modify(rand(-100, 100) . ' days')->format('Y-m-d'), 'public_notes' => '', ]; diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index 82b4ff2470f5..80abe6b2cd20 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -14,12 +14,8 @@ class CalendarController extends BaseController */ public function showCalendar() { - if (! auth()->user()->hasPermission('view_all')) { - return redirect('/'); - } - $data = [ - //'showBreadcrumbs' => false, + 'account' => auth()->user()->account, ]; return view('calendar', $data); @@ -27,12 +23,11 @@ class CalendarController extends BaseController public function loadEvents() { - $events = dispatch(new GenerateCalendarEvents()); - //dd($events); - \Log::info(print_r(request()->input(), true)); - //\Log::info(print_r($events, true)); - //echo '[{"title": "Test Event", "start": "2017-09-14T16:00:00", "color": "green"}]'; - //exit; + if (auth()->user()->account->hasFeature(FEATURE_REPORTS)) { + $events = dispatch(new GenerateCalendarEvents()); + } else { + $events = []; + } return response()->json($events); } diff --git a/app/Jobs/GenerateCalendarEvents.php b/app/Jobs/GenerateCalendarEvents.php index 044a5aa61899..27a91a8db23b 100644 --- a/app/Jobs/GenerateCalendarEvents.php +++ b/app/Jobs/GenerateCalendarEvents.php @@ -23,14 +23,18 @@ class GenerateCalendarEvents extends Job $data = [ ENTITY_INVOICE => Invoice::scope()->invoices(), ENTITY_QUOTE => Invoice::scope()->quotes(), - ENTITY_TASK => Task::scope(), - ENTITY_PAYMENT => Payment::scope(), - ENTITY_EXPENSE => Expense::scope(), + ENTITY_TASK => Task::scope()->with(['project']), + ENTITY_PAYMENT => Payment::scope()->with(['invoice']), + ENTITY_EXPENSE => Expense::scope()->with(['expense_category']), ]; foreach ($data as $type => $source) { if (! count($filter) || in_array($type, $filter)) { - foreach ($source->get() as $entity) { + foreach ($source->with(['account', 'client.contacts'])->get() as $entity) { + if ($entity->client && $entity->client->trashed()) { + continue; + } + $subColors = count($filter) == 1; $events[] = $entity->present()->calendarEvent($subColors); } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 05943da77a29..3dbf3f623332 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2446,6 +2446,7 @@ $LANG = array( 'stripe_alipay_help' => 'These gateways also need to be activated in :link.', 'gocardless_webhook_help_link_text' => 'add this URL as an endpoint in GoCardless', 'calendar' => 'Calendar', + 'pro_plan_calendar' => ':link to enable the calendar by joining the Pro Plan', ); diff --git a/resources/views/calendar.blade.php b/resources/views/calendar.blade.php index e1622602faa0..c0e525d51211 100644 --- a/resources/views/calendar.blade.php +++ b/resources/views/calendar.blade.php @@ -33,6 +33,14 @@ @section('content') + @if (!Utils::isPro()) +