Working on scheduled reports

This commit is contained in:
Hillel Coren 2017-11-23 13:15:50 +02:00
parent ace4985d24
commit 5a17953c76
6 changed files with 69 additions and 46 deletions

View File

@ -76,11 +76,6 @@ class SendReminders extends Command
$this->info('Done'); $this->info('Done');
if (\Utils::isNinjaDev()) {
$this->info('Stopping early on ninja dev');
exit;
}
if ($errorEmail = env('ERROR_EMAIL')) { if ($errorEmail = env('ERROR_EMAIL')) {
\Mail::raw('EOM', function ($message) use ($errorEmail, $database) { \Mail::raw('EOM', function ($message) use ($errorEmail, $database) {
$message->to($errorEmail) $message->to($errorEmail)

View File

@ -11,6 +11,7 @@ use Input;
use Utils; use Utils;
use View; use View;
use Carbon; use Carbon;
use Validator;
/** /**
* Class ReportController. * Class ReportController.
@ -133,6 +134,14 @@ class ReportController extends BaseController
private function schedule($params, $options) private function schedule($params, $options)
{ {
$validator = Validator::make(request()->all(), [
'frequency' => 'required|in:daily,weekly,biweekly,monthly',
'send_date' => 'required',
]);
if ($validator->fails()) {
session()->now('message', trans('texts.scheduled_report_error'));
} else {
$options['report_type'] = $params['reportType']; $options['report_type'] = $params['reportType'];
$options['range'] = request('range'); $options['range'] = request('range');
$options['start_date_offset'] = $options['range'] ? '' : Carbon::parse($params['startDate'])->diffInDays(null, false); // null,false to get the relative/non-absolute diff $options['start_date_offset'] = $options['range'] ? '' : Carbon::parse($params['startDate'])->diffInDays(null, false); // null,false to get the relative/non-absolute diff
@ -150,6 +159,7 @@ class ReportController extends BaseController
session()->now('message', trans('texts.created_scheduled_report')); session()->now('message', trans('texts.created_scheduled_report'));
} }
}
private function cancelSchdule() private function cancelSchdule()
{ {

View File

@ -99,6 +99,7 @@ class ExportReportResults extends Job
$sheet->setAutoSize(true); $sheet->setAutoSize(true);
}); });
if (count($summary)) {
$excel->sheet(trans("texts.totals"), function($sheet) use($report, $summary, $format) { $excel->sheet(trans("texts.totals"), function($sheet) use($report, $summary, $format) {
$sheet->setOrientation('landscape'); $sheet->setOrientation('landscape');
$sheet->freezeFirstRow(); $sheet->freezeFirstRow();
@ -118,6 +119,7 @@ class ExportReportResults extends Job
}); });
$sheet->setAutoSize(true); $sheet->setAutoSize(true);
}); });
}
}); });
} }

View File

@ -18,8 +18,8 @@ class ActivityReport extends AbstractReport
{ {
$account = Auth::user()->account; $account = Auth::user()->account;
$startDate = $this->startDate->format('Y-m-d'); $startDate = $this->startDate;;
$endDate = $this->endDate->format('Y-m-d'); $endDate = $this->endDate;
$activities = Activity::scope() $activities = Activity::scope()
->with('client.contacts', 'user', 'invoice', 'payment', 'credit', 'task', 'expense', 'account') ->with('client.contacts', 'user', 'invoice', 'payment', 'credit', 'task', 'expense', 'account')
@ -32,7 +32,7 @@ class ActivityReport extends AbstractReport
$activity->present()->createdAt, $activity->present()->createdAt,
$client ? ($this->isExport ? $client->getDisplayName() : $client->present()->link) : '', $client ? ($this->isExport ? $client->getDisplayName() : $client->present()->link) : '',
$activity->present()->user, $activity->present()->user,
$activity->getMessage(), $this->isExport ? strip_tags($activity->getMessage()) : $activity->getMessage(),
]; ];
} }

View File

@ -2553,7 +2553,7 @@ $LANG = array(
'created_scheduled_report' => 'Successfully scheduled report', 'created_scheduled_report' => 'Successfully scheduled report',
'deleted_scheduled_report' => 'Successfully canceled scheduled report', 'deleted_scheduled_report' => 'Successfully canceled scheduled report',
'scheduled_report_attached' => 'Your scheduled :type report is attached.', 'scheduled_report_attached' => 'Your scheduled :type report is attached.',
'scheduled_report_error' => 'Failed to create schedule report',
); );
return $LANG; return $LANG;

View File

@ -101,10 +101,11 @@
{!! Former::open()->addClass('report-form')->rules(['start_date' => 'required', 'end_date' => 'required']) !!} {!! Former::open()->addClass('report-form')->rules(['start_date' => 'required', 'end_date' => 'required']) !!}
<div style="display:none"> <div style="display:none">
{!! Former::text('action') !!} {!! Former::text('action')->forceValue('') !!}
{!! Former::text('range') !!} {!! Former::text('range')->forceValue('') !!}
{!! Former::text('scheduled_report_id') !!} {!! Former::text('scheduled_report_id')->forceValue('') !!}
</div> </div>
{!! Former::populateField('start_date', $startDate) !!} {!! Former::populateField('start_date', $startDate) !!}
@ -212,7 +213,7 @@
->appendIcon(Icon::create('remove')) !!} ->appendIcon(Icon::create('remove')) !!}
{!! Button::primary(trans('texts.schedule')) {!! Button::primary(trans('texts.schedule'))
->withAttributes(['id'=>'scheduleButton', 'onclick' => 'showScheduleModal()']) ->withAttributes(['id'=>'scheduleButton', 'onclick' => 'showScheduleModal()', 'style' => 'display:none'])
->appendIcon(Icon::create('time')) !!} ->appendIcon(Icon::create('time')) !!}
</span> &nbsp;&nbsp; </span> &nbsp;&nbsp;
@ -433,6 +434,13 @@
} }
}); });
$('#format').change(function() {
var val = $('#format').val();
if (isStorageSupported() && val != 'zip') {
localStorage.setItem('last:report_format', val);
}
});
$('#report_type').change(function() { $('#report_type').change(function() {
var val = $('#report_type').val(); var val = $('#report_type').val();
setFiltersShown(); setFiltersShown();
@ -498,6 +506,12 @@
widgets: ['zebra', 'uitheme'], widgets: ['zebra', 'uitheme'],
}).show(); }).show();
setFiltersShown();
setDocumentZipShown();
setTimeout(function() {
setScheduleButton();
}, 1);
if (isStorageSupported()) { if (isStorageSupported()) {
var lastReportType = localStorage.getItem('last:report_type'); var lastReportType = localStorage.getItem('last:report_type');
if (lastReportType) { if (lastReportType) {
@ -507,11 +521,13 @@
if (lastDocumentFilter) { if (lastDocumentFilter) {
$('#document_filter').val(lastDocumentFilter); $('#document_filter').val(lastDocumentFilter);
} }
var lastFormat = localStorage.getItem('last:report_format');
if (lastFormat) {
setTimeout(function() {
$('#format').val(lastFormat);
}, 1);
}
} }
setFiltersShown();
setDocumentZipShown();
setScheduleButton();
}); });
}) })