akaunting 3.0 (the last dance)
This commit is contained in:
@ -20,7 +20,9 @@ class BulkActions extends Controller
|
||||
*/
|
||||
public function action($group, $type, Request $request)
|
||||
{
|
||||
if ($request->get('handle', '*') == '*') {
|
||||
$handle = $request->get('handle', '*');
|
||||
|
||||
if ($handle == '*') {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'redirect' => true,
|
||||
@ -32,17 +34,20 @@ class BulkActions extends Controller
|
||||
|
||||
// Check is module
|
||||
$module = module($group);
|
||||
$page = ucfirst($type);
|
||||
|
||||
if ($module instanceof \Akaunting\Module\Module) {
|
||||
$tmp = explode('.', $type);
|
||||
$file_name = !empty($tmp[1]) ? Str::studly($tmp[0]) . '\\' . Str::studly($tmp[1]) : Str::studly($tmp[0]);
|
||||
|
||||
$bulk_actions = app('Modules\\' . $module->getStudlyName() . '\BulkActions\\' . $file_name);
|
||||
|
||||
$page = ucfirst($file_name);
|
||||
} else {
|
||||
$bulk_actions = app('App\BulkActions\\' . ucfirst($group) . '\\' . ucfirst($type));
|
||||
}
|
||||
|
||||
if (isset($bulk_actions->actions[$request->get('handle')]['permission']) && !user()->can($bulk_actions->actions[$request->get('handle')]['permission'])) {
|
||||
if (isset($bulk_actions->actions[$handle]['permission']) && !user()->can($bulk_actions->actions[$handle]['permission'])) {
|
||||
flash(trans('errors.message.403'))->error()->important();
|
||||
|
||||
return response()->json([
|
||||
@ -54,11 +59,21 @@ class BulkActions extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
$result = $bulk_actions->{$request->get('handle')}($request);
|
||||
$result = $bulk_actions->{$handle}($request);
|
||||
|
||||
$message = trans($bulk_actions->messages['general'], ['type' => $handle, 'count' => count($request->get('selected'))]);
|
||||
|
||||
if (array_key_exists($handle, $bulk_actions->messages)) {
|
||||
$message = trans($bulk_actions->messages[$handle], ['type' => $page]);
|
||||
}
|
||||
|
||||
if (! empty($result) && ($result instanceof \Symfony\Component\HttpFoundation\BinaryFileResponse)) {
|
||||
flash($message)->success();
|
||||
|
||||
if (!empty($result) && ($result instanceof \Symfony\Component\HttpFoundation\BinaryFileResponse)) {
|
||||
return $result;
|
||||
} elseif (!empty($result) && ($result instanceof RedirectResponse)) {
|
||||
} elseif (! empty($result) && ($result instanceof RedirectResponse)) {
|
||||
flash($message)->success();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'redirect' => $result->getTargetUrl(),
|
||||
@ -67,6 +82,8 @@ class BulkActions extends Controller
|
||||
'message' => ''
|
||||
]);
|
||||
} else {
|
||||
flash($message)->success();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'redirect' => true,
|
||||
|
@ -8,7 +8,6 @@ use App\Jobs\Common\CreateCompany;
|
||||
use App\Jobs\Common\DeleteCompany;
|
||||
use App\Jobs\Common\UpdateCompany;
|
||||
use App\Models\Common\Company;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Traits\Uploads;
|
||||
use App\Traits\Users;
|
||||
|
||||
@ -45,9 +44,7 @@ class Companies extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$currencies = Currency::enabled()->pluck('name', 'code');
|
||||
|
||||
return view('common.companies.create', compact('currencies'));
|
||||
return view('common.companies.create');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,9 +92,7 @@ class Companies extends Controller
|
||||
return redirect()->route('companies.index');
|
||||
}
|
||||
|
||||
$currencies = Currency::enabled()->pluck('name', 'code');
|
||||
|
||||
return view('common.companies.edit', compact('company', 'currencies'));
|
||||
return view('common.companies.edit', compact('company'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,7 +209,7 @@ class Companies extends Controller
|
||||
event(new \App\Events\Common\CompanySwitched($company, $old_company_id));
|
||||
|
||||
// Check wizard
|
||||
if (!setting('wizard.completed', false)) {
|
||||
if (! setting('wizard.completed', false)) {
|
||||
return redirect()->route('wizard.edit', ['company_id' => $company->id]);
|
||||
}
|
||||
}
|
||||
|
@ -71,14 +71,16 @@ class Dashboards extends Controller
|
||||
return Widgets::canShow($widget->class);
|
||||
});
|
||||
|
||||
$user_dashboards = user()->dashboards()->enabled()->get();
|
||||
|
||||
$date_picker_shortcuts = $this->getDatePickerShortcuts();
|
||||
|
||||
if (!request()->has('start_date')) {
|
||||
if (! request()->has('start_date')) {
|
||||
request()->merge(['start_date' => $date_picker_shortcuts[trans('reports.this_year')]['start']]);
|
||||
request()->merge(['end_date' => $date_picker_shortcuts[trans('reports.this_year')]['end']]);
|
||||
}
|
||||
|
||||
return view('common.dashboards.show', compact('dashboard', 'widgets', 'date_picker_shortcuts'));
|
||||
return view('common.dashboards.show', compact('dashboard', 'widgets', 'user_dashboards', 'date_picker_shortcuts'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,7 +90,11 @@ class Dashboards extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$users = company()->users()->get()->sortBy('name');
|
||||
$users = company()->users()->get()->reject(function ($user) {
|
||||
if ($user->cannot('read-admin-panel')) {
|
||||
return true;
|
||||
}
|
||||
})->sortBy('name');
|
||||
|
||||
return view('common.dashboards.create', compact('users'));
|
||||
}
|
||||
@ -133,7 +139,11 @@ class Dashboards extends Controller
|
||||
return redirect()->route('dashboards.index');
|
||||
}
|
||||
|
||||
$users = company()->users()->get()->sortBy('name');
|
||||
$users = company()->users()->get()->reject(function ($user) {
|
||||
if ($user->cannot('read-admin-panel')) {
|
||||
return true;
|
||||
}
|
||||
})->sortBy('name');
|
||||
|
||||
return view('common.dashboards.edit', compact('dashboard', 'users'));
|
||||
}
|
||||
|
@ -38,9 +38,11 @@ class Import extends Controller
|
||||
'role' => 'form',
|
||||
'class' => 'form-loading-button',
|
||||
'novalidate' => true,
|
||||
'route' => '',
|
||||
'url' => '',
|
||||
];
|
||||
|
||||
if (!empty($route)) {
|
||||
if (! empty($route)) {
|
||||
$form_params['route'] = $route;
|
||||
} else {
|
||||
$form_params['url'] = $path . '/import';
|
||||
|
@ -6,14 +6,11 @@ use App\Abstracts\Http\Controller;
|
||||
use App\Exports\Common\Items as Export;
|
||||
use App\Http\Requests\Common\Item as Request;
|
||||
use App\Http\Requests\Common\Import as ImportRequest;
|
||||
use App\Http\Requests\Common\TotalItem as TotalRequest;
|
||||
use App\Imports\Common\Items as Import;
|
||||
use App\Jobs\Common\CreateItem;
|
||||
use App\Jobs\Common\DeleteItem;
|
||||
use App\Jobs\Common\UpdateItem;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Traits\Uploads;
|
||||
|
||||
@ -28,7 +25,7 @@ class Items extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$items = Item::with('category', 'media')->collect();
|
||||
$items = Item::with('category', 'media', 'taxes')->collect();
|
||||
|
||||
return $this->response('common.items.index', compact('items'));
|
||||
}
|
||||
@ -50,11 +47,9 @@ class Items extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$categories = Category::item()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id');
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
|
||||
|
||||
return view('common.items.create', compact('categories', 'taxes'));
|
||||
return view('common.items.create', compact('taxes'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,15 +130,9 @@ class Items extends Controller
|
||||
*/
|
||||
public function edit(Item $item)
|
||||
{
|
||||
$categories = Category::item()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id');
|
||||
|
||||
if ($item->category && !$categories->has($item->category_id)) {
|
||||
$categories->put($item->category->id, $item->category->name);
|
||||
}
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
|
||||
|
||||
return view('common.items.edit', compact('item', 'categories', 'taxes'));
|
||||
return view('common.items.edit', compact('item', 'taxes'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,101 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Common;
|
||||
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Http\Requests\Common\Notification as Request;
|
||||
use App\Traits\Modules;
|
||||
use App\Utilities\Date;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Notifications extends Controller
|
||||
{
|
||||
use Modules;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('common.notifications.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for viewing the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function readAll()
|
||||
{
|
||||
$notifications = user()->unreadNotifications;
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$notification->markAsRead();
|
||||
}
|
||||
|
||||
// Hide New Apps Notifications
|
||||
$module_notifications = $this->getNotifications('new-apps');
|
||||
|
||||
foreach ($module_notifications as $module_notification) {
|
||||
$prefix = 'notifications.' . user()->id . '.' . $module_notification->alias;
|
||||
|
||||
setting()->set([
|
||||
$prefix . '.name' => $module_notification->name,
|
||||
$prefix . '.message' => $module_notification->alias,
|
||||
$prefix . '.date' => Date::now(),
|
||||
$prefix . '.status' => '0',
|
||||
]);
|
||||
}
|
||||
|
||||
setting()->save();
|
||||
|
||||
$message = trans('messages.success.clear_all', ['type' => Str::lower(trans_choice('general.notifications', 2))]);
|
||||
|
||||
flash($message)->success();
|
||||
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource.
|
||||
*
|
||||
* @param Company $company
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function disable(Request $request)
|
||||
{
|
||||
$id = $request['id'];
|
||||
$path = str_replace('#', '/', $request['path']);
|
||||
|
||||
$notifications = $this->getNotifications($path);
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
if ($notification->id == $id) {
|
||||
$prefix = 'notifications.' . $path . '.' . $id;
|
||||
|
||||
setting()->set([
|
||||
$prefix . '.name' => $notification->name,
|
||||
$prefix . '.message' => $notification->message,
|
||||
$prefix . '.date' => Date::now(),
|
||||
$prefix . '.status' => '0',
|
||||
]);
|
||||
|
||||
setting()->save();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => trans('messages.success.disabled', [
|
||||
'type' => Str::lower(trans_choice('general.notifications', 2))
|
||||
]),
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'data' => null,
|
||||
]);
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ use App\Jobs\Common\DeleteReport;
|
||||
use App\Jobs\Common\UpdateReport;
|
||||
use App\Models\Common\Report;
|
||||
use App\Utilities\Reports as Utility;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Reports extends Controller
|
||||
{
|
||||
@ -37,7 +36,7 @@ class Reports extends Controller
|
||||
$reports = Report::orderBy('name')->get();
|
||||
|
||||
foreach ($reports as $report) {
|
||||
if (!Utility::canShow($report->class)) {
|
||||
if (Utility::cannotShow($report->class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -47,17 +46,20 @@ class Reports extends Controller
|
||||
continue;
|
||||
}
|
||||
|
||||
$ttl = 3600 * 6; // 6 hours
|
||||
|
||||
$totals[$report->id] = Cache::remember('reports.totals.' . $report->id, $ttl, function () use ($class) {
|
||||
return $class->getGrandTotal();
|
||||
});
|
||||
|
||||
$icons[$report->id] = $class->getIcon();
|
||||
$categories[$class->getCategory()][] = $report;
|
||||
|
||||
if (empty($categories[$class->getCategory()])) {
|
||||
$categories[$class->getCategory()] = [
|
||||
'name' => $class->getCategory(),
|
||||
'description' => $class->getCategoryDescription(),
|
||||
'reports' => [$report],
|
||||
];
|
||||
} else {
|
||||
$categories[$class->getCategory()]['reports'][] = $report;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response('common.reports.index', compact('categories', 'totals', 'icons'));
|
||||
return $this->response('common.reports.index', compact('categories', 'icons'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,15 +70,12 @@ class Reports extends Controller
|
||||
*/
|
||||
public function show(Report $report)
|
||||
{
|
||||
if (!Utility::canShow($report->class)) {
|
||||
if (Utility::cannotShow($report->class)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$class = Utility::getClassInstance($report);
|
||||
|
||||
// Update cache
|
||||
Cache::put('reports.totals.' . $report->id, $class->getGrandTotal());
|
||||
|
||||
return $class->show();
|
||||
}
|
||||
|
||||
@ -215,7 +214,7 @@ class Reports extends Controller
|
||||
*/
|
||||
public function print(Report $report)
|
||||
{
|
||||
if (!Utility::canShow($report->class)) {
|
||||
if (Utility::cannotShow($report->class)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
@ -230,7 +229,7 @@ class Reports extends Controller
|
||||
*/
|
||||
public function export(Report $report)
|
||||
{
|
||||
if (!Utility::canShow($report->class)) {
|
||||
if (Utility::cannotShow($report->class)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
@ -257,7 +256,7 @@ class Reports extends Controller
|
||||
|
||||
$fields = (new $class())->getFields();
|
||||
|
||||
$html = view('partials.reports.fields', compact('fields'))->render();
|
||||
$html = view('components.reports.fields', compact('fields'))->render();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
@ -266,23 +265,4 @@ class Reports extends Controller
|
||||
'html' => $html,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cache of the resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function clear(Report $report)
|
||||
{
|
||||
$data = Utility::getClassInstance($report)->getGrandTotal();
|
||||
|
||||
Cache::put('reports.totals.' . $report->id, $data);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'data' => $data,
|
||||
'message' => '',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ class Uploads extends Controller
|
||||
|
||||
$file = $media;
|
||||
|
||||
$html = view('partials.media.file', compact('file', 'column_name', 'options'))->render();
|
||||
$html = view('components.media.file', compact('file', 'column_name', 'options'))->render();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
|
Reference in New Issue
Block a user