Merge pull request #2109 from cuneytsenturk/master
Report page per widget clear own cache
This commit is contained in:
commit
70e374ac86
@ -142,7 +142,7 @@ abstract class Report
|
|||||||
$sum += is_array($total) ? array_sum($total) : $total;
|
$sum += is_array($total) ? array_sum($total) : $total;
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = money($sum, setting('default.currency'), true);
|
$total = money($sum, setting('default.currency'), true)->format();
|
||||||
} else {
|
} else {
|
||||||
$total = trans('general.na');
|
$total = trans('general.na');
|
||||||
}
|
}
|
||||||
|
77
app/Console/Commands/ReportReminder.php
Normal file
77
app/Console/Commands/ReportReminder.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Common\Company;
|
||||||
|
use App\Models\Common\Report;
|
||||||
|
use App\Utilities\Reports as Utility;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
class ReportReminder extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'reminder:report';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Calculate reminders for reports';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
// Disable model cache
|
||||||
|
config(['laravel-model-caching.enabled' => false]);
|
||||||
|
|
||||||
|
// Get all companies
|
||||||
|
$companies = Company::enabled()->withCount('reports')->cursor();
|
||||||
|
|
||||||
|
foreach ($companies as $company) {
|
||||||
|
// Has company reports
|
||||||
|
if (!$company->reports_count) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Calculate report reminders for ' . $company->name . ' company.');
|
||||||
|
|
||||||
|
// Set company
|
||||||
|
$company->makeCurrent();
|
||||||
|
|
||||||
|
$this->remind();
|
||||||
|
}
|
||||||
|
|
||||||
|
Company::forgetCurrent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function remind()
|
||||||
|
{
|
||||||
|
$reports = Report::orderBy('name')->get();
|
||||||
|
|
||||||
|
foreach ($reports as $report) {
|
||||||
|
$class = Utility::getClassInstance($report, false);
|
||||||
|
|
||||||
|
if (empty($class)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ttl = 3600 * 6; // 6 hours
|
||||||
|
|
||||||
|
Cache::forget('reports.totals.' . $report->id);
|
||||||
|
|
||||||
|
Cache::remember('reports.totals.' . $report->id, $ttl, function () use ($class) {
|
||||||
|
return $class->getGrandTotal();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,6 +29,7 @@ class Kernel extends ConsoleKernel
|
|||||||
|
|
||||||
$schedule_time = config('app.schedule_time');
|
$schedule_time = config('app.schedule_time');
|
||||||
|
|
||||||
|
$schedule->command('reminder:report')->everySixHours();
|
||||||
$schedule->command('reminder:invoice')->dailyAt($schedule_time);
|
$schedule->command('reminder:invoice')->dailyAt($schedule_time);
|
||||||
$schedule->command('reminder:bill')->dailyAt($schedule_time);
|
$schedule->command('reminder:bill')->dailyAt($schedule_time);
|
||||||
$schedule->command('recurring:check')->dailyAt($schedule_time);
|
$schedule->command('recurring:check')->dailyAt($schedule_time);
|
||||||
|
@ -24,6 +24,7 @@ class Reports extends Controller
|
|||||||
$this->middleware('permission:update-common-reports')->only('edit', 'update', 'enable', 'disable');
|
$this->middleware('permission:update-common-reports')->only('edit', 'update', 'enable', 'disable');
|
||||||
$this->middleware('permission:delete-common-reports')->only('destroy');
|
$this->middleware('permission:delete-common-reports')->only('destroy');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
@ -271,16 +272,17 @@ class Reports extends Controller
|
|||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function clear()
|
public function clear(Report $report)
|
||||||
{
|
{
|
||||||
Report::all()->each(function ($report) {
|
$data = Utility::getClassInstance($report)->getGrandTotal();
|
||||||
if (!Utility::canShow($report->class)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cache::put('reports.totals.' . $report->id, Utility::getClassInstance($report)->getGrandTotal());
|
Cache::put('reports.totals.' . $report->id, $data);
|
||||||
});
|
|
||||||
|
|
||||||
return redirect()->back();
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'error' => false,
|
||||||
|
'data' => $data,
|
||||||
|
'message' => '',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
resources/assets/js/views/common/reports.js
vendored
16
resources/assets/js/views/common/reports.js
vendored
@ -30,9 +30,14 @@ const app = new Vue({
|
|||||||
form: new Form('report'),
|
form: new Form('report'),
|
||||||
bulk_action: new BulkAction('reports'),
|
bulk_action: new BulkAction('reports'),
|
||||||
report_fields: '',
|
report_fields: '',
|
||||||
|
reports_total: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
created() {
|
||||||
|
this.reports_total = reports_total;
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onChangeClass(class_name) {
|
onChangeClass(class_name) {
|
||||||
axios.get(url + '/common/reports/fields', {
|
axios.get(url + '/common/reports/fields', {
|
||||||
@ -76,6 +81,15 @@ const app = new Vue({
|
|||||||
|
|
||||||
onChangeReportFields(event) {
|
onChangeReportFields(event) {
|
||||||
this.form = event;
|
this.form = event;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
onRefreshTotal(report_id) {
|
||||||
|
axios.get(url + '/common/reports/' + report_id + '/clear')
|
||||||
|
.then(response => {
|
||||||
|
this.reports_total[report_id] = response.data.data;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
});
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
@can('create-common-reports')
|
@can('create-common-reports')
|
||||||
<a href="{{ route('reports.create') }}" class="btn btn-success btn-sm">{{ trans('general.add_new') }}</a>
|
<a href="{{ route('reports.create') }}" class="btn btn-success btn-sm">{{ trans('general.add_new') }}</a>
|
||||||
@endcan
|
@endcan
|
||||||
<a href="{{ route('reports.clear') }}" class="btn btn-warning btn-sm">{{ trans('general.clear_cache') }}</a>
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
@ -25,14 +24,17 @@
|
|||||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
<i class="fa fa-ellipsis-v text-primary"></i>
|
<i class="fa fa-ellipsis-v text-primary"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||||
@can('update-common-reports')
|
@can('update-common-reports')
|
||||||
<a class="dropdown-item" href="{{ route('reports.edit', $report->id) }}">{{ trans('general.edit') }}</a>
|
<a class="dropdown-item" href="{{ route('reports.edit', $report->id) }}">{{ trans('general.edit') }}</a>
|
||||||
@endcan
|
@endcan
|
||||||
|
|
||||||
@can('create-common-reports')
|
@can('create-common-reports')
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
<a class="dropdown-item" href="{{ route('reports.duplicate', $report->id) }}">{{ trans('general.duplicate') }}</a>
|
<a class="dropdown-item" href="{{ route('reports.duplicate', $report->id) }}">{{ trans('general.duplicate') }}</a>
|
||||||
@endcan
|
@endcan
|
||||||
|
|
||||||
@can('delete-common-reports')
|
@can('delete-common-reports')
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
{!! Form::deleteLink($report, 'reports.destroy') !!}
|
{!! Form::deleteLink($report, 'reports.destroy') !!}
|
||||||
@ -47,9 +49,20 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<a href="{{ route('reports.show', $report->id) }}">
|
<a href="{{ route('reports.show', $report->id) }}">
|
||||||
<h5 class="card-title text-uppercase text-muted mb-0">{{ $report->name }}</h5>
|
<h5 class="card-title text-uppercase text-muted mb-0">{{ $report->name }}</h5>
|
||||||
<h2 class="font-weight-bold mb-0">{{ $totals[$report->id] }}</h2>
|
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<a href="{{ route('reports.show', $report->id) }}">
|
||||||
|
<h2 class="font-weight-bold mb-0" v-if="reports_total[{{ $report->id }}]" v-html="reports_total[{{ $report->id }}]"></h2>
|
||||||
|
<h2 class="font-weight-bold mb-0" v-else>{{ $totals[$report->id] }}</h2>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<button type="button" @click="onRefreshTotal('{{ $report->id }}')" class="btn btn-otline-primary btn-sm ml-2">
|
||||||
|
<i class="fas fa-redo"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<a href="{{ route('reports.show', $report->id) }}">
|
<a href="{{ route('reports.show', $report->id) }}">
|
||||||
<div class="icon icon-shape bg-orange text-white rounded-circle shadow">
|
<div class="icon icon-shape bg-orange text-white rounded-circle shadow">
|
||||||
@ -58,6 +71,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="mt-3 mb-0 text-sm">
|
<p class="mt-3 mb-0 text-sm">
|
||||||
<a class="text-default" href="{{ route('reports.show', $report->id) }}">
|
<a class="text-default" href="{{ route('reports.show', $report->id) }}">
|
||||||
<span class="pre">{{ $report->description }}</span>
|
<span class="pre">{{ $report->description }}</span>
|
||||||
@ -73,6 +87,9 @@
|
|||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@push('scripts_start')
|
@push('scripts_start')
|
||||||
|
<script type="text/javascript">
|
||||||
|
var reports_total = {!! json_encode($totals) !!};
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="{{ asset('public/js/common/reports.js?v=' . version('short')) }}"></script>
|
<script src="{{ asset('public/js/common/reports.js?v=' . version('short')) }}"></script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ Route::group(['prefix' => 'common'], function () {
|
|||||||
Route::get('reports/{report}/print', 'Common\Reports@print')->name('reports.print');
|
Route::get('reports/{report}/print', 'Common\Reports@print')->name('reports.print');
|
||||||
Route::get('reports/{report}/export', 'Common\Reports@export')->name('reports.export');
|
Route::get('reports/{report}/export', 'Common\Reports@export')->name('reports.export');
|
||||||
Route::get('reports/{report}/duplicate', 'Common\Reports@duplicate')->name('reports.duplicate');
|
Route::get('reports/{report}/duplicate', 'Common\Reports@duplicate')->name('reports.duplicate');
|
||||||
Route::get('reports/clear', 'Common\Reports@clear')->name('reports.clear');
|
Route::get('reports/{report}/clear', 'Common\Reports@clear')->name('reports.clear');
|
||||||
Route::get('reports/fields', 'Common\Reports@fields')->name('reports.fields');
|
Route::get('reports/fields', 'Common\Reports@fields')->name('reports.fields');
|
||||||
Route::resource('reports', 'Common\Reports');
|
Route::resource('reports', 'Common\Reports');
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user