Working on the calendar

This commit is contained in:
Hillel Coren 2017-09-12 17:16:18 +03:00
parent c472bf92c8
commit a7dcc30711
10 changed files with 54 additions and 52 deletions

View File

@ -30,7 +30,7 @@ class CalendarController extends BaseController
$events = dispatch(new GenerateCalendarEvents()); $events = dispatch(new GenerateCalendarEvents());
//dd($events); //dd($events);
\Log::info(print_r(request()->input(), true)); \Log::info(print_r(request()->input(), true));
\Log::info(print_r($events, true)); //\Log::info(print_r($events, true));
//echo '[{"title": "Test Event", "start": "2017-09-14T16:00:00", "color": "green"}]'; //echo '[{"title": "Test Event", "start": "2017-09-14T16:00:00", "color": "green"}]';
//exit; //exit;

View File

@ -17,33 +17,25 @@ class GenerateCalendarEvents extends Job
*/ */
public function handle() public function handle()
{ {
$data = []; $events = [];
$filter = request()->filter ?: [];
$invoices = Invoice::scope() $data = [
->where('is_recurring', '=', false) ENTITY_INVOICE => Invoice::scope()->invoices(),
->get(); ENTITY_QUOTE => Invoice::scope()->quotes(),
foreach ($invoices as $invoice) { ENTITY_TASK => Task::scope(),
$data[] = $invoice->present()->calendarEvent; 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) {
$events[] = $entity->present()->calendarEvent;
}
}
} }
$tasks = Task::scope() return $events;
->get();
foreach ($tasks as $task) {
$data[] = $task->present()->calendarEvent;
}
$payments = Payment::scope()
->get();
foreach ($payments as $payment) {
$data[] = $payment->present()->calendarEvent;
}
$expenses = Expense::scope()
->get();
foreach ($expenses as $expense) {
$data[] = $expense->present()->calendarEvent;
}
return $data;
} }
} }

View File

@ -66,7 +66,7 @@ class ExpensePresenter extends EntityPresenter
$data->start = $expense->expense_date; $data->start = $expense->expense_date;
$data->borderColor = $data->backgroundColor = 'gray'; $data->borderColor = $data->backgroundColor = '#F45D01';
return $data; return $data;
} }

View File

@ -332,7 +332,7 @@ class InvoicePresenter extends EntityPresenter
$data->title = trans("texts.{$entityType}") . ' ' . $invoice->invoice_number . ' | ' . $this->amount() . ' | ' . $this->client(); $data->title = trans("texts.{$entityType}") . ' ' . $invoice->invoice_number . ' | ' . $this->amount() . ' | ' . $this->client();
$data->start = $invoice->invoice_date; $data->start = $invoice->invoice_date;
$data->borderColor = $data->backgroundColor = $invoice->isQuote() ? 'orange' : 'blue'; $data->borderColor = $data->backgroundColor = $invoice->isQuote() ? '#2D7DD2' : '#474647';
return $data; return $data;
} }

View File

@ -54,7 +54,7 @@ class PaymentPresenter extends EntityPresenter
$data->title = trans('texts.payment') . ' ' . $invoice->invoice_number . ' | ' . $this->amount() . ' | ' . $this->client(); $data->title = trans('texts.payment') . ' ' . $invoice->invoice_number . ' | ' . $this->amount() . ' | ' . $this->client();
$data->start = $payment->payment_date; $data->start = $payment->payment_date;
$data->borderColor = $data->backgroundColor = 'green'; $data->borderColor = $data->backgroundColor = '#7FB800';
return $data; return $data;
} }

View File

@ -83,7 +83,7 @@ class TaskPresenter extends EntityPresenter
$data->title .= ' | ' . $this->description(); $data->title .= ' | ' . $this->description();
$data->allDay = false; $data->allDay = false;
$data->borderColor = $data->backgroundColor = 'purple'; $data->borderColor = $data->backgroundColor = '#EEB902';
$parts = json_decode($task->time_log) ?: []; $parts = json_decode($task->time_log) ?: [];
if (count($parts)) { if (count($parts)) {

View File

@ -99,7 +99,8 @@ elixir(function(mix) {
], 'public/js/daterangepicker.min.js'); ], 'public/js/daterangepicker.min.js');
mix.scripts([ mix.scripts([
bowerDir + '/fullcalendar/dist/fullcalendar.js' bowerDir + '/fullcalendar/dist/fullcalendar.js',
bowerDir + '/fullcalendar/dist/locale-all.js',
], 'public/js/fullcalendar.min.js'); ], 'public/js/fullcalendar.min.js');
mix.scripts([ mix.scripts([

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,6 +11,18 @@
@stop @stop
@section('head_css')
@parent
<style type="text/css">
.fc-day,
.fc-list-item {
background-color: white;
}
</style>
@stop
@section('top-right') @section('top-right')
<select class="form-control" style="width: 220px" id="entityTypeFilter" multiple="true"> <select class="form-control" style="width: 220px" id="entityTypeFilter" multiple="true">
@foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_PAYMENT, ENTITY_TASK, ENTITY_EXPENSE] as $value) @foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_PAYMENT, ENTITY_TASK, ENTITY_EXPENSE] as $value)
@ -41,34 +53,27 @@
} }
*/ */
}).on('change', function() { }).on('change', function() {
/* $('#calendar').fullCalendar('refetchEvents');
var filter = $('#statuses').val();
if (filter) {
filter = filter.join(',');
} else {
filter = '';
}
*/
}).maximizeSelect2Height(); }).maximizeSelect2Height();
$('#calendar').fullCalendar({ $('#calendar').fullCalendar({
locale: '{{ App::getLocale() }}',
header: { header: {
left: 'prev,next today', left: 'prev,next today',
center: 'title', center: 'title',
right: 'month,basicWeek,basicDay,listWeek' right: 'month,basicWeek,basicDay,listWeek'
}, },
defaultDate: '{{ date('Y-m-d') }}', defaultDate: '{{ date('Y-m-d') }}',
//navLinks: true,
//editable: true,
eventLimit: true, eventLimit: true,
events: { events: {
url: '{{ url('/calendar_events') }}', url: '{{ url('/calendar_events') }}',
type: 'GET', type: 'GET',
data: { data: function() {
custom_param1: 'something', return {
custom_param2: 'somethingelse' filter: $('#entityTypeFilter').val()
}, };
},
error: function() { error: function() {
alert('there was an error while fetching events!'); alert('there was an error while fetching events!');
}, },