Merge branch 'master' of github.com:akaunting/akaunting into 2.1-dev

# Conflicts:
#	app/Http/Controllers/Common/Items.php
#	resources/views/modules/item/documentation.blade.php
#	resources/views/modules/item/show.blade.php
#	resources/views/partials/admin/header.blade.php
#	resources/views/purchases/bills/show.blade.php
#	resources/views/purchases/vendors/show.blade.php
#	resources/views/sales/customers/show.blade.php
#	resources/views/sales/invoices/show.blade.php
#	resources/views/wizard/companies/edit.blade.php
#	resources/views/wizard/currencies/index.blade.php
#	resources/views/wizard/finish/index.blade.php
#	resources/views/wizard/taxes/index.blade.php
This commit is contained in:
Cüneyt Şentürk 2020-08-28 19:24:26 +03:00
commit a3b5cc7ddd
824 changed files with 14086 additions and 5612 deletions

39
.github/workflows/translations.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: Translations
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
sync:
name: Sync
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Sync with Crowdin
uses: crowdin/github-action@master
with:
upload_sources: true
upload_translations: true
download_translations: true
skip_untranslated_files: true
source: 'resources/lang/en-GB/*.php'
translation: 'resources/lang/%locale%/%original_file_name%'
localization_branch_name: 'translations'
commit_message: 'new crowdin translations'
pull_request_title: 'New Crowdin translations'
pull_request_body: 'https://crowdin.com/project/akaunting'
pull_request_labels: 'Translation'
project_id: ${{ secrets.CROWDIN_CORE_ID }}
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2
.gitignore vendored
View File

@ -78,6 +78,7 @@ fabric.properties
/storage/*.key
/vendor
/.idea
/.history
/.vscode
/.vagrant
Homestead.json
@ -87,6 +88,7 @@ npm-debug.log
.env.example
robots.txt
_ide_helper.php
_ide_helper_models.php
.phpstorm.meta.php
/storage/debugbar/*
.phpunit.result.cache

View File

@ -13,8 +13,15 @@
# Prevent Direct Access to Protected Files
<FilesMatch "(?i)(^artisan$|\.env|\.log)">
Order deny,allow
Deny from all
# Apache 2.2 syntax
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
# Apache 2.4 syntax
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
</FilesMatch>
# Prevent Direct Access To Protected Folders

View File

@ -0,0 +1,76 @@
<?php
namespace App\Abstracts\Commands;
use App\Models\Module\Module as Model;
use App\Models\Module\ModuleHistory as ModelHistory;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputArgument;
abstract class Module extends Command
{
protected function prepare()
{
$this->alias = Str::kebab($this->argument('alias'));
$this->company_id = $this->argument('company');
$this->locale = $this->argument('locale');
$this->module = module($this->alias);
}
protected function changeRuntime()
{
$this->old_company_id = session('company_id');
session(['company_id' => $this->company_id]);
app()->setLocale($this->locale);
// Disable model cache
config(['laravel-model-caching.enabled' => false]);
}
protected function revertRuntime()
{
session()->forget('company_id');
if (!empty($this->old_company_id)) {
session(['company_id' => $this->old_company_id]);
}
}
protected function getModel()
{
$this->model = Model::companyId($this->company_id)->alias($this->alias)->first();
return $this->model;
}
protected function createHistory($action)
{
if (empty($this->model)) {
return;
}
ModelHistory::create([
'company_id' => $this->company_id,
'module_id' => $this->model->id,
'version' => $this->module->get('version'),
'description' => trans('modules.' . $action, ['module' => $this->alias]),
]);
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['alias', InputArgument::REQUIRED, 'Module alias.'],
['company', InputArgument::REQUIRED, 'Company ID.'],
];
}
}

View File

@ -3,8 +3,8 @@
namespace App\Abstracts;
use App\Abstracts\Model;
use App\Models\Banking\Transaction;
use App\Models\Setting\Currency;
use App\Events\Sale\InvoicePaidCalculated;
use App\Models\Setting\Tax;
use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Media;
@ -65,10 +65,10 @@ abstract class DocumentModel extends Model
{
$percent = 0;
$discount = $this->totals()->where('code', 'discount')->value('amount');
$discount = $this->totals->where('code', 'discount')->makeHidden('title')->pluck('amount')->first();
if ($discount) {
$sub_total = $this->totals()->where('code', 'sub_total')->value('amount');
$sub_total = $this->totals->where('code', 'sub_total')->makeHidden('title')->pluck('amount')->first();
$percent = number_format((($discount * 100) / $sub_total), 0);
}
@ -90,28 +90,16 @@ abstract class DocumentModel extends Model
$paid = 0;
$reconciled = $reconciled_amount = 0;
$code = $this->currency_code;
$rate = config('money.' . $code . '.rate');
$precision = config('money.' . $code . '.precision');
if ($this->transactions->count()) {
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
foreach ($this->transactions as $item) {
if ($this->currency_code == $item->currency_code) {
$amount = (double) $item->amount;
} else {
$default_model = new Transaction();
$default_model->default_currency_code = $this->currency_code;
$default_model->amount = $item->amount;
$default_model->currency_code = $item->currency_code;
$default_model->currency_rate = $currencies[$item->currency_code];
$amount = $item->amount;
$default_amount = (double) $default_model->getAmountConvertedToDefault();
$convert_model = new Transaction();
$convert_model->default_currency_code = $item->currency_code;
$convert_model->amount = $default_amount;
$convert_model->currency_code = $this->currency_code;
$convert_model->currency_rate = $currencies[$this->currency_code];
$amount = (double) $convert_model->getAmountConvertedFromDefault();
if ($code != $item->currency_code) {
$amount = $this->convertBetween($amount, $item->currency_code, $item->currency_rate, $code, $rate);
}
$paid += $amount;
@ -122,13 +110,19 @@ abstract class DocumentModel extends Model
}
}
if ($this->amount == $reconciled_amount) {
if (bccomp(round($this->amount, $precision), round($reconciled_amount, $precision), $precision) === 0) {
$reconciled = 1;
}
$this->setAttribute('reconciled', $reconciled);
return $paid;
// TODO: find a cleaner way compatible with observer pattern
$invoice = clone $this;
$invoice->paid_amount = $paid;
event(new InvoicePaidCalculated($invoice));
return round($invoice->paid_amount, $precision);
}
/**
* Get the status label.
@ -171,8 +165,14 @@ abstract class DocumentModel extends Model
{
$amount = $this->amount;
$this->totals()->where('code', 'tax')->each(function ($tax) use(&$amount) {
$amount -= $tax->amount;
$this->totals->where('code', 'tax')->each(function ($total) use(&$amount) {
$tax = Tax::name($total->name)->first();
if (!empty($tax) && ($tax->type == 'withholding')) {
return;
}
$amount -= $total->amount;
});
return $amount;

View File

@ -44,16 +44,20 @@ abstract class Controller extends BaseController
$controller = '';
// Add module
if (isset($arr[3]) && isset($arr[4])) {
if (strtolower($arr[4]) == 'modules') {
$controller .= Str::kebab($arr[3]) . '-';
} elseif (isset($arr[5]) && (strtolower($arr[5]) == 'modules')) {
$controller .= Str::kebab($arr[4]) . '-';
}
}
// Add folder
if (strtolower($arr[1]) != 'controllers') {
$controller .= Str::kebab($arr[1]) . '-';
}
// Add module
if (isset($arr[3]) && isset($arr[4]) && (strtolower($arr[4]) == 'modules')) {
$controller .= Str::kebab($arr[3]) . '-';
}
// Add file
$controller .= Str::kebab($arr[0]);
@ -63,10 +67,15 @@ abstract class Controller extends BaseController
return;
}
// App\Http\Controllers\FooBar -->> foo-bar
// App\Http\Controllers\FooBar\Main -->> foo-bar-main
// Modules\Blog\Http\Controllers\Posts -->> blog-posts
// Modules\Blog\Http\Controllers\Portal\Posts -->> blog-portal-posts
// Add CRUD permission check
$this->middleware('permission:create-' . $controller)->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-' . $controller)->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-' . $controller)->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-' . $controller)->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-' . $controller)->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-' . $controller)->only('update', 'enable', 'disable');
$this->middleware('permission:delete-' . $controller)->only('destroy');
}

View File

@ -34,7 +34,7 @@ abstract class PaymentController extends BaseController
$this->logger = $this->getLogger();
$this->user = user();
$this->module = module($this->alias);
return $next($request);
@ -160,6 +160,7 @@ abstract class PaymentController extends BaseController
public function dispatchPaidEvent($invoice, $request)
{
$request['company_id'] = $invoice->company_id;
$request['account_id'] = setting($this->alias . '.account_id', setting('default.account'));
$request['amount'] = $invoice->amount;
$request['payment_method'] = $this->alias;
$request['reference'] = $this->getReference($invoice);

View File

@ -18,6 +18,10 @@ abstract class Model extends Eloquent
protected $dates = ['deleted_at'];
protected $casts = [
'enabled' => 'boolean',
];
/**
* The "booting" method of the model.
*

View File

@ -2,6 +2,8 @@
namespace App\Abstracts;
use App\Events\Report\DataLoaded;
use App\Events\Report\DataLoading;
use App\Events\Report\FilterApplying;
use App\Events\Report\FilterShowing;
use App\Events\Report\GroupApplying;
@ -47,11 +49,6 @@ abstract class Report
public $loaded = false;
public $indents = [
'table_header' => '0px',
'table_rows' => '24px',
];
public $chart = [
'line' => [
'width' => '0',
@ -97,12 +94,21 @@ abstract class Report
$this->setDates();
$this->setFilters();
$this->setRows();
$this->setData();
$this->loadData();
$this->setColumnWidth();
$this->loaded = true;
}
public function loadData()
{
event(new DataLoading($this));
$this->setData();
event(new DataLoaded($this));
}
public function getDefaultName()
{
if (!empty($this->default_name)) {
@ -147,17 +153,17 @@ abstract class Report
{
$chart = new Chartjs();
if (empty($this->model->settings->chart)) {
if (!$type = $this->getSetting('chart')) {
return $chart;
}
$config = $this->chart[$this->model->settings->chart];
$config = $this->chart[$type];
$default_options = $this->getLineChartOptions();
$options = array_merge($default_options, (array) $config['options']);
$chart->type($this->model->settings->chart)
$chart->type($type)
->width((int) $config['width'])
->height((int) $config['height'])
->options($options)
@ -204,13 +210,13 @@ abstract class Report
public function setColumnWidth()
{
if (empty($this->model->settings->period)) {
if (!$period = $this->getSetting('period')) {
return;
}
$width = '';
switch ($this->model->settings->period) {
switch ($period) {
case 'quarterly':
$width = 'col-sm-2';
break;
@ -258,16 +264,16 @@ abstract class Report
public function setDates()
{
if (empty($this->model->settings->period)) {
if (!$period = $this->getSetting('period')) {
return;
}
$function = 'sub' . ucfirst(str_replace('ly', '', $this->model->settings->period));
$function = 'sub' . ucfirst(str_replace('ly', '', $period));
$start = $this->getFinancialStart()->copy()->$function();
for ($j = 1; $j <= 12; $j++) {
switch ($this->model->settings->period) {
switch ($period) {
case 'yearly':
$start->addYear();
@ -337,7 +343,7 @@ abstract class Report
$date = $this->getFormattedDate(Date::parse($item->$date_field));
$id_field = $this->model->settings->group . '_id';
$id_field = $this->getSetting('group') . '_id';
if (
!isset($this->row_values[$table][$item->$id_field])
@ -379,7 +385,7 @@ abstract class Report
public function getFormattedDate($date)
{
switch ($this->model->settings->period) {
switch ($this->getSetting('period')) {
case 'yearly':
$i = $date->copy()->format($this->getYearlyDateFormat());
break;
@ -416,6 +422,11 @@ abstract class Report
return $print_url;
}
public function getSetting($name, $default = '')
{
return $this->model->settings->$name ?? $default;
}
public function getFields()
{
return [

View File

@ -11,14 +11,14 @@ class Reconciliations extends BulkAction
public $model = Reconciliation::class;
public $actions = [
'enable' => [
'name' => 'general.enable',
'message' => 'bulk_actions.message.enable',
'reconcile' => [
'name' => 'reconciliations.reconcile',
'message' => 'bulk_actions.message.reconcile',
'permission' => 'update-banking-reconciliations',
],
'disable' => [
'name' => 'general.disable',
'message' => 'bulk_actions.message.disable',
'unreconcile' => [
'name' => 'reconciliations.unreconcile',
'message' => 'bulk_actions.message.unreconcile',
'permission' => 'update-banking-reconciliations',
],
'delete' => [
@ -28,37 +28,41 @@ class Reconciliations extends BulkAction
],
];
public function enable($request)
public function reconcile($request)
{
$reconciliations = $this->getSelectedRecords($request);
foreach ($reconciliations as $reconciliation) {
$reconciliation->enabled = 1;
$reconciliation->save();
\DB::transaction(function () use ($reconciliation) {
$reconciliation->reconciled = 1;
$reconciliation->save();
Transaction::where('account_id', $reconciliation->account_id)
->reconciled()
->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) {
$item->reconciled = 1;
$item->save();
});
Transaction::where('account_id', $reconciliation->account_id)
->isNotReconciled()
->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) {
$item->reconciled = 1;
$item->save();
});
});
}
}
public function disable($request)
public function unreconcile($request)
{
$reconciliations = $this->getSelectedRecords($request);
foreach ($reconciliations as $reconciliation) {
$reconciliation->enabled = 0;
$reconciliation->save();
\DB::transaction(function () use ($reconciliation) {
$reconciliation->reconciled = 0;
$reconciliation->save();
Transaction::where('account_id', $reconciliation->account_id)
->reconciled()
->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) {
$item->reconciled = 0;
$item->save();
});
Transaction::where('account_id', $reconciliation->account_id)
->isReconciled()
->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) {
$item->reconciled = 0;
$item->save();
});
});
}
}
@ -67,14 +71,16 @@ class Reconciliations extends BulkAction
$reconciliations = $this->getSelectedRecords($request);
foreach ($reconciliations as $reconciliation) {
$reconciliation->delete();
\DB::transaction(function () use ($reconciliation) {
$reconciliation->delete();
Transaction::where('account_id', $reconciliation->account_id)
->reconciled()
->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) {
$item->reconciled = 0;
$item->save();
});
Transaction::where('account_id', $reconciliation->account_id)
->isReconciled()
->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) {
$item->reconciled = 0;
$item->save();
});
});
}
}
}

View File

@ -78,8 +78,13 @@ class BillReminder extends Command
$bills = Bill::with('contact')->accrued()->notPaid()->due($date)->cursor();
foreach ($bills as $bill) {
event(new BillReminded($bill));
try {
event(new BillReminded($bill));
} catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) {
$this->error($e->getMessage());
logger('Bill reminder:: ' . $e->getMessage());
}
}
}
}

View File

@ -43,6 +43,8 @@ class FinishUpdate extends Command
// Check if file mirror was successful
$version = ($alias == 'core') ? version('short') : module($alias)->get('version');
if ($version != $new) {
logger($alias . ' update failed:: file version > ' . $version . ' -vs- ' . 'request version > ' . $new);
throw new \Exception(trans('modules.errors.finish', ['module' => $alias]));
}

View File

@ -15,6 +15,7 @@ class Install extends Command
const OPT_DB_NAME = 'db-name';
const OPT_DB_USERNAME = 'db-username';
const OPT_DB_PASSWORD = 'db-password';
const OPT_DB_PREFIX = 'db-prefix';
const OPT_COMPANY_NAME = 'company-name';
const OPT_COMPANY_EMAIL = 'company-email';
const OPT_ADMIN_EMAIL = 'admin-email';
@ -33,6 +34,7 @@ class Install extends Command
{--db-name= : Name of the database}
{--db-username=root : Username to use to access the database}
{--db-password= : Password to use to access the database}
{--db-prefix= : Table name prefix}
{--company-name=My Company : Name of the company}
{--company-email=my@company.com : Email of the company}
{--admin-email= : Admin user email}
@ -55,7 +57,7 @@ class Install extends Command
public function handle()
{
if (($missing_options = $this->getMissingOptions()) && $this->option(self::OPT_NO_INTERACTION)) {
$this->line('❌ Some options are missing and --no-interaction is present. Please run the following command for more informations :');
$this->line('❌ Some options are missing and --no-interaction is present. Please run the following command for more information :');
$this->line('❌ php artisan help install');
$this->line('❌ Missing options are : ' . implode(', ', $missing_options));
@ -102,12 +104,15 @@ class Install extends Command
'OPT_DB_NAME',
'OPT_DB_USERNAME',
'OPT_DB_PASSWORD',
'OPT_DB_PREFIX',
'OPT_COMPANY_NAME',
'OPT_COMPANY_EMAIL',
'OPT_ADMIN_EMAIL',
'OPT_ADMIN_PASSWORD',
'OPT_ADMIN_PASSWORD'
];
$allowed_empty = ['db_password', 'db_prefix'];
foreach ($contants as $const) {
$option = constant("self::$const");
@ -115,14 +120,15 @@ class Install extends Command
$this->$property = $this->option($option);
if (empty($this->$property)) {
// Allow empty password
if ($property == 'db_password') {
continue;
}
$missing_options[] = $option;
if (!empty($this->$property)) {
continue;
}
if (in_array($property, $allowed_empty)) {
continue;
}
$missing_options[] = $option;
}
return $missing_options;
@ -177,10 +183,11 @@ class Install extends Command
$this->db_name = $this->option(self::OPT_DB_NAME);
$this->db_username = $this->option(self::OPT_DB_USERNAME);
$this->db_password = $this->option(self::OPT_DB_PASSWORD);
$this->db_prefix = $this->option(self::OPT_DB_PREFIX);
$this->line('Connecting to database ' . $this->db_name . '@' . $this->db_host . ':' . $this->db_port);
if (!Installer::createDbTables($this->db_host, $this->db_port, $this->db_name, $this->db_username, $this->db_password)) {
if (!Installer::createDbTables($this->db_host, $this->db_port, $this->db_name, $this->db_username, $this->db_password, $this->db_prefix)) {
$this->error('Error: Could not connect to the database! Please, make sure the details are correct.');
return false;

View File

@ -0,0 +1,58 @@
<?php
namespace App\Console\Commands;
use App\Models\Auth\User;
use App\Models\Common\Company;
use Illuminate\Console\Command;
class InstallRefresh extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'install:refresh {--admin-password=123456}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Allows to refresh Akaunting installation directly through CLI';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$user = User::first();
$company = Company::first();
$this->info('Resetting migrations');
$this->callSilent('migrate:reset', [
'--force' => true,
]);
$this->info('Installing Akaunting');
$this->callSilent('install', [
'--db-host' => env('DB_HOST'),
'--db-port' => env('DB_PORT'),
'--db-name' => env('DB_DATABASE'),
'--db-username' => env('DB_USERNAME'),
'--db-password' => env('DB_PASSWORD'),
'--db-prefix' => env('DB_PREFIX'),
'--company-name' => $company->name,
'--company-email' => $company->email,
'--admin-email' => $user->email,
'--admin-password' => $this->option('admin-password'),
'--locale' => $company->locale,
'--no-interaction' => true,
]);
$this->info('Installation refreshed');
}
}

View File

@ -78,7 +78,13 @@ class InvoiceReminder extends Command
$invoices = Invoice::with('contact')->accrued()->notPaid()->due($date)->cursor();
foreach ($invoices as $invoice) {
event(new InvoiceReminded($invoice));
try {
event(new InvoiceReminded($invoice));
} catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) {
$this->error($e->getMessage());
logger('Invoice reminder:: ' . $e->getMessage());
}
}
}
}

View File

@ -145,8 +145,15 @@ class RecurringCheck extends Command
$model->cloneable_relations = ['items', 'totals'];
// Create new record
$clone = $model->duplicate();
try {
$clone = $model->duplicate();
} catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) {
$this->error($e->getMessage());
logger('Recurring check:: ' . $e->getMessage());
return false;
}
// Set original model id
$clone->parent_id = $model->id;

View File

@ -0,0 +1,54 @@
<?php
namespace App\Console\Commands;
use App\Abstracts\Commands\Module as Command;
use App\Events\Module\Uninstalled;
class UninstallModule extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:uninstall {alias} {company} {locale=en-GB}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Uninstall the specified module.';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->prepare();
if (!$this->getModel()) {
$this->info("Module [{$this->alias}] not found.");
return;
}
$this->changeRuntime();
// Delete db
$this->model->delete();
$this->createHistory('uninstalled');
event(new Uninstalled($this->alias, $this->company_id));
// Delete files
$this->module->delete();
$this->revertRuntime();
$this->info("Module [{$this->alias}] uninstalled.");
}
}

View File

@ -61,7 +61,7 @@ class UpdateAll extends Command
$command = "update {$alias} {$company_id}";
if (true !== $result = Console::run($command, true)) {
if (true !== $result = Console::run($command)) {
$message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $alias]);
$this->error($message);

View File

@ -2,7 +2,6 @@
"alias": "$ALIAS$",
"icon": "fa fa-cog",
"version": "1.0.0",
"category": "accounting",
"active": 1,
"providers": [
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\Event",

View File

@ -4,6 +4,7 @@ namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners;
use App\Events\Module\Installed as Event;
use App\Traits\Permissions;
use Artisan;
class FinishInstallation
{
@ -24,6 +25,8 @@ class FinishInstallation
}
$this->updatePermissions();
//$this->callSeeds();
}
protected function updatePermissions()
@ -33,4 +36,12 @@ class FinishInstallation
$this->alias . '-main' => 'c,r,u,d',
]);
}
protected function callSeeds()
{
Artisan::call('company:seed', [
'company' => session('company_id'),
'--class' => 'Modules\$STUDLY_NAME$\Database\Seeds\$STUDLY_NAME$DatabaseSeeder',
]);
}
}

View File

@ -10,8 +10,8 @@
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"cross-env": "^5.1.4",
"laravel-mix": "^4.0.7",
"cross-env": "^5.2.1",
"laravel-mix": "^4.1.4",
"laravel-mix-merge-manifest": "^0.1.2"
}
}

View File

@ -3,18 +3,28 @@
namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider;
use $MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners\FinishInstallation;
class Event extends Provider
{
/**
* The event listener mappings for the module.
* Determine if events and listeners should be automatically discovered.
*
* @var array
* @return bool
*/
protected $listen = [
\App\Events\Module\Installed::class => [
FinishInstallation::class,
],
];
public function shouldDiscoverEvents()
{
return true;
}
/**
* Get the listener directories that should be used to discover events.
*
* @return array
*/
protected function discoverEventsWithin()
{
return [
__DIR__ . '/../Listeners',
];
}
}

View File

@ -2,9 +2,9 @@
namespace $NAMESPACE$;
use Illuminate\Http\Resources\Json\Resource;
use Illuminate\Http\Resources\Json\JsonResource;
class $CLASS$ extends Resource
class $CLASS$ extends JsonResource
{
/**
* Transform the resource into an array.

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Auth;
use Illuminate\Queue\SerializesModels;
class LandingPageShowing
{
use SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @param $user
*/
public function __construct($user)
{
$this->user = $user;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Install;
use Illuminate\Queue\SerializesModels;
class UpdateCacheCleared
{
use SerializesModels;
public $company_id;
/**
* Create a new event instance.
*
* @param $company_id
*/
public function __construct($company_id)
{
$this->company_id = $company_id;
}
}

View File

@ -4,7 +4,7 @@ namespace App\Events\Module;
use Illuminate\Queue\SerializesModels;
class Deleted
class Copied
{
use SerializesModels;

View File

@ -0,0 +1,26 @@
<?php
namespace App\Events\Module;
use Illuminate\Queue\SerializesModels;
class Uninstalled
{
use SerializesModels;
public $alias;
public $company_id;
/**
* Create a new event instance.
*
* @param $alias
* @param $company_id
*/
public function __construct($alias, $company_id)
{
$this->alias = $alias;
$this->company_id = $company_id;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Report;
use Illuminate\Queue\SerializesModels;
class DataLoaded
{
use SerializesModels;
public $class;
/**
* Create a new event instance.
*
* @param $class
*/
public function __construct($class)
{
$this->class = $class;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Report;
use Illuminate\Queue\SerializesModels;
class DataLoading
{
use SerializesModels;
public $class;
/**
* Create a new event instance.
*
* @param $class
*/
public function __construct($class)
{
$this->class = $class;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Sale;
use Illuminate\Queue\SerializesModels;
class InvoicePaidCalculated
{
use SerializesModels;
public $invoice;
/**
* Create a new event instance.
*
* @param $invoice
*/
public function __construct($invoice)
{
$this->invoice = $invoice;
}
}

View File

@ -9,7 +9,7 @@ class Transactions extends Export
{
public function collection()
{
$model = Model::with(['account', 'bill', 'category', 'contact', 'invoice'])->usingSearchString(request('search'));
$model = Model::with('account', 'bill', 'category', 'contact', 'invoice')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class Items extends Export
{
public function collection()
{
$model = Model::with(['category', 'tax'])->usingSearchString(request('search'));
$model = Model::with('category', 'tax')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class Payments extends Export
{
public function collection()
{
$model = Model::with(['account', 'bill', 'category', 'contact'])->expense()->usingSearchString(request('search'));
$model = Model::with('account', 'bill', 'category', 'contact')->expense()->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class BillHistories extends Export
{
public function collection()
{
$model = Model::with(['bill'])->usingSearchString(request('search'));
$model = Model::with('bill')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('bill_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class BillItemTaxes extends Export
{
public function collection()
{
$model = Model::with(['bill', 'item', 'tax'])->usingSearchString(request('search'));
$model = Model::with('bill', 'item', 'tax')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('bill_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class BillItems extends Export
{
public function collection()
{
$model = Model::with(['bill', 'item'])->usingSearchString(request('search'));
$model = Model::with('bill', 'item')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('bill_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class BillTotals extends Export
{
public function collection()
{
$model = Model::with(['bill'])->usingSearchString(request('search'));
$model = Model::with('bill')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('bill_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class BillTransactions extends Export
{
public function collection()
{
$model = Model::with(['account', 'category', 'contact', 'bill'])->expense()->isDocument()->usingSearchString(request('search'));
$model = Model::with('account', 'category', 'contact', 'bill')->expense()->isDocument()->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('document_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class Bills extends Export
{
public function collection()
{
$model = Model::with(['category'])->usingSearchString(request('search'));
$model = Model::with('category')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class Revenues extends Export
{
public function collection()
{
$model = Model::with(['account', 'category', 'contact', 'invoice'])->income()->usingSearchString(request('search'));
$model = Model::with('account', 'category', 'contact', 'invoice')->income()->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class InvoiceHistories extends Export
{
public function collection()
{
$model = Model::with(['invoice'])->usingSearchString(request('search'));
$model = Model::with('invoice')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('invoice_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class InvoiceItemTaxes extends Export
{
public function collection()
{
$model = Model::with(['invoice', 'item', 'tax'])->usingSearchString(request('search'));
$model = Model::with('invoice', 'item', 'tax')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('invoice_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class InvoiceItems extends Export
{
public function collection()
{
$model = Model::with(['invoice', 'item'])->usingSearchString(request('search'));
$model = Model::with('invoice', 'item')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('invoice_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class InvoiceTotals extends Export
{
public function collection()
{
$model = Model::with(['invoice'])->usingSearchString(request('search'));
$model = Model::with('invoice')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('invoice_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class InvoiceTransactions extends Export
{
public function collection()
{
$model = Model::with(['account', 'category', 'contact', 'invoice'])->income()->isDocument()->usingSearchString(request('search'));
$model = Model::with('account', 'category', 'contact', 'invoice')->income()->isDocument()->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('document_id', (array) $this->ids);

View File

@ -9,7 +9,7 @@ class Invoices extends Export
{
public function collection()
{
$model = Model::with(['category'])->usingSearchString(request('search'));
$model = Model::with('category')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('id', (array) $this->ids);

View File

@ -45,7 +45,7 @@ class Permissions extends ApiController
{
$permission = $this->dispatch(new CreatePermission($request));
return $this->response->created(url('api/permissions/' . $permission->id));
return $this->response->created(route('api.permissions.show', $permission->id));
}
/**

View File

@ -45,7 +45,7 @@ class Roles extends ApiController
{
$role = $this->dispatch(new CreateRole($request));
return $this->response->created(url('api/roles/' . $role->id));
return $this->response->created(route('api.roles.show', $role->id));
}
/**

View File

@ -19,7 +19,7 @@ class Users extends ApiController
*/
public function index()
{
$users = User::with(['companies', 'roles', 'permissions'])->collect();
$users = User::with('companies', 'permissions', 'roles')->collect();
return $this->response->paginator($users, new Transformer());
}
@ -34,9 +34,9 @@ class Users extends ApiController
{
// Check if we're querying by id or email
if (is_numeric($id)) {
$user = User::with(['companies', 'roles', 'permissions'])->find($id);
$user = User::with('companies', 'permissions', 'roles')->find($id);
} else {
$user = User::with(['companies', 'roles', 'permissions'])->where('email', $id)->first();
$user = User::with('companies', 'permissions', 'roles')->where('email', $id)->first();
}
return $this->response->item($user, new Transformer());
@ -52,7 +52,7 @@ class Users extends ApiController
{
$user = $this->dispatch(new CreateUser($request));
return $this->response->created(url('api/users/' . $user->id));
return $this->response->created(route('api.users.show', $user->id));
}
/**

View File

@ -52,7 +52,7 @@ class Accounts extends ApiController
{
$account = $this->dispatch(new CreateAccount($request));
return $this->response->created(url('api/accounts/' . $account->id));
return $this->response->created(route('api.accounts.show', $account->id));
}
/**

View File

@ -19,7 +19,7 @@ class Reconciliations extends ApiController
*/
public function index()
{
$items = Reconciliation::with(['account'])->collect();
$items = Reconciliation::with('account')->collect();
return $this->response->paginator($items, new Transformer());
}
@ -45,7 +45,7 @@ class Reconciliations extends ApiController
{
$reconciliation = $this->dispatch(new CreateReconciliation($request));
return $this->response->created(url('api/reconciliations/' . $reconciliation->id));
return $this->response->created(route('api.reconciliations.show', $reconciliation->id));
}
/**

View File

@ -19,7 +19,7 @@ class Transactions extends ApiController
*/
public function index()
{
$transactions = Transaction::with(['account', 'category', 'contact'])->collect(['paid_at'=> 'desc']);
$transactions = Transaction::with('account', 'category', 'contact')->collect(['paid_at'=> 'desc']);
return $this->response->paginator($transactions, new Transformer());
}
@ -45,7 +45,7 @@ class Transactions extends ApiController
{
$transaction = $this->dispatch(new CreateTransaction($request));
return $this->response->created(url('api/transactions/' . $transaction->id));
return $this->response->created(route('api.transactions.show', $transaction->id));
}
/**

View File

@ -19,9 +19,9 @@ class Transfers extends ApiController
*/
public function index()
{
$transfers = Transfer::with([
$transfers = Transfer::with(
'expense_transaction', 'expense_transaction.account', 'income_transaction', 'income_transaction.account'
])->collect('expense_transaction.paid_at');
)->collect('expense_transaction.paid_at');
$special_key = [
'expense_transaction.name' => 'from_account',
@ -75,7 +75,7 @@ class Transfers extends ApiController
{
$transfer = $this->dispatch(new CreateTransfer($request));
return $this->response->created(url('api/transfers/' . $transfer->id));
return $this->response->created(route('api.transfers.show', $transfer->id));
}
/**

View File

@ -56,7 +56,7 @@ class Companies extends ApiController
{
$company = $this->dispatch(new CreateCompany($request));
return $this->response->created(url('api/companies/' . $company->id));
return $this->response->created(route('api.companies.show', $company->id));
}
/**

View File

@ -21,9 +21,9 @@ class Contacts extends ApiController
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-sales-customers')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-sales-customers')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-sales-customers')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-sales-customers')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-sales-customers')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-sales-customers')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-sales-customers')->only('destroy');
}
@ -67,7 +67,7 @@ class Contacts extends ApiController
{
$contact = $this->dispatch(new CreateContact($request));
return $this->response->created(url('api/contacts/' . $contact->id));
return $this->response->created(route('api.contacts.show', $contact->id));
}
/**

View File

@ -22,7 +22,7 @@ class Items extends ApiController
*/
public function index()
{
$items = Item::with(['category', 'tax'])->collect();
$items = Item::with('category', 'tax')->collect();
return $this->response->paginator($items, new Transformer());
}
@ -35,7 +35,7 @@ class Items extends ApiController
*/
public function show($id)
{
$item = Item::with(['category', 'tax'])->find($id);
$item = Item::with('category', 'tax')->find($id);
return $this->response->item($item, new Transformer());
}
@ -50,7 +50,7 @@ class Items extends ApiController
{
$item = $this->dispatch(new CreateItem($request));
return $this->response->created(url('api/items/' . $item->id));
return $this->response->created(route('api.items.show', $item->id));
}
/**

View File

@ -45,7 +45,7 @@ class Reports extends ApiController
{
$report = $this->dispatch(new CreateReport($request));
return $this->response->created(url('api/reports/' . $report->id));
return $this->response->created(route('api.reports.show', $report->id));
}
/**

View File

@ -19,7 +19,7 @@ class Bills extends ApiController
*/
public function index()
{
$bills = Bill::with(['contact', 'items', 'transactions', 'histories'])->collect(['billed_at'=> 'desc']);
$bills = Bill::with('contact', 'histories', 'items', 'transactions')->collect(['billed_at'=> 'desc']);
return $this->response->paginator($bills, new Transformer());
}
@ -45,7 +45,7 @@ class Bills extends ApiController
{
$bill = $this->dispatch(new CreateBill($request));
return $this->response->created(url('api/bills/' . $bill->id));
return $this->response->created(route('api.bills.show', $bill->id));
}
/**

View File

@ -19,7 +19,7 @@ class Invoices extends ApiController
*/
public function index()
{
$invoices = Invoice::with(['contact', 'items', 'transactions', 'histories'])->collect(['invoiced_at'=> 'desc']);
$invoices = Invoice::with('contact', 'histories', 'items', 'transactions')->collect(['invoiced_at'=> 'desc']);
return $this->response->paginator($invoices, new Transformer());
}
@ -52,7 +52,7 @@ class Invoices extends ApiController
{
$invoice = $this->dispatch(new CreateInvoice($request));
return $this->response->created(url('api/invoices/' . $invoice->id));
return $this->response->created(route('api.invoices.show', $invoice->id));
}
/**

View File

@ -45,7 +45,7 @@ class Categories extends ApiController
{
$category = $this->dispatch(new CreateCategory($request));
return $this->response->created(url('api/categories/' . $category->id));
return $this->response->created(route('api.categories.show', $category->id));
}
/**

View File

@ -52,7 +52,7 @@ class Currencies extends ApiController
{
$currency = $this->dispatch(new CreateCurrency($request));
return $this->response->created(url('api/currencies/' . $currency->id));
return $this->response->created(route('api.currencies.show', $currency->id));
}
/**

View File

@ -52,7 +52,7 @@ class Settings extends ApiController
{
$setting = Setting::create($request->all());
return $this->response->created(url('api/settings/'.$setting->id));
return $this->response->created(route('api.settings.show', $setting->id));
}
/**

View File

@ -45,7 +45,7 @@ class Taxes extends ApiController
{
$tax = $this->dispatch(new CreateTax($request));
return $this->response->created(url('api/taxes/' . $tax->id));
return $this->response->created(route('api.taxes.show', $tax->id));
}
/**

View File

@ -89,8 +89,6 @@ class Login extends Controller
return response()->json($response);
}
session(['dashboard_id' => $user->dashboards()->enabled()->pluck('id')->first()]);
$response = [
'status' => null,
'success' => true,

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;
use App\Abstracts\Http\Controller;
use App\Events\Auth\LandingPageShowing;
use App\Http\Requests\Auth\User as Request;
use App\Jobs\Auth\CreateUser;
use App\Jobs\Auth\DeleteUser;
@ -16,6 +17,17 @@ class Users extends Controller
{
use Uploads;
public function __construct()
{
$this->middleware('permission:create-auth-users')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-auth-users')->only('index', 'show', 'export');
$this->middleware('permission:update-auth-users')->only('enable', 'disable');
$this->middleware('permission:delete-auth-users')->only('destroy');
$this->middleware('permission:read-auth-users|read-auth-profile')->only('edit');
$this->middleware('permission:update-auth-users|update-auth-profile')->only('update');
}
/**
* Display a listing of the resource.
*
@ -23,7 +35,7 @@ class Users extends Controller
*/
public function index()
{
$users = User::with('roles')->collect();
$users = User::with('media', 'roles')->collect();
return view('auth.users.index', compact('users'));
}
@ -35,33 +47,20 @@ class Users extends Controller
*/
public function create()
{
$routes = [
'dashboard' => trans_choice('general.dashboards', 1),
'items.index' => trans_choice('general.items', 2),
'invoices.index' => trans_choice('general.invoices', 2),
'revenues.index' => trans_choice('general.revenues', 2),
'customers.index' => trans_choice('general.customers', 2),
'bills.index' => trans_choice('general.bills', 2),
'payments.index' => trans_choice('general.payments', 2),
'vendors.index' => trans_choice('general.vendors', 2),
'accounts.index' => trans_choice('general.accounts', 2),
'transfers.index' => trans_choice('general.transfers', 2),
'transactions.index' => trans_choice('general.transactions', 2),
'reconciliations.index' => trans_choice('general.reconciliations', 2),
'reports.index' => trans_choice('general.reports', 2),
'settings.index' => trans_choice('general.settings', 2),
'categories.index' => trans_choice('general.categories', 2),
'currencies.index' => trans_choice('general.currencies', 2),
'taxes.index' => trans_choice('general.taxes', 2),
];
$u = new \stdClass();
$u->landing_pages = [];
event(new LandingPageShowing($u));
$landing_pages = $u->landing_pages;
$roles = Role::all()->reject(function ($r) {
return $r->hasPermission('read-client-portal');
});
$companies = user()->companies()->get()->sortBy('name');
$companies = user()->companies()->take(10)->get()->sortBy('name')->pluck('name', 'id');
return view('auth.users.create', compact('roles', 'companies', 'routes'));
return view('auth.users.create', compact('roles', 'companies', 'landing_pages'));
}
/**
@ -101,25 +100,16 @@ class Users extends Controller
*/
public function edit(User $user)
{
$routes = [
'dashboard' => trans_choice('general.dashboards', 1),
'items.index' => trans_choice('general.items', 2),
'invoices.index' => trans_choice('general.invoices', 2),
'revenues.index' => trans_choice('general.revenues', 2),
'customers.index' => trans_choice('general.customers', 2),
'bills.index' => trans_choice('general.bills', 2),
'payments.index' => trans_choice('general.payments', 2),
'vendors.index' => trans_choice('general.vendors', 2),
'accounts.index' => trans_choice('general.accounts', 2),
'transfers.index' => trans_choice('general.transfers', 2),
'transactions.index' => trans_choice('general.transactions', 2),
'reconciliations.index' => trans_choice('general.reconciliations', 2),
'reports.index' => trans_choice('general.reports', 2),
'settings.index' => trans_choice('general.settings', 2),
'categories.index' => trans_choice('general.categories', 2),
'currencies.index' => trans_choice('general.currencies', 2),
'taxes.index' => trans_choice('general.taxes', 2),
];
if (user()->cannot('read-auth-users') && ($user->id != user()->id)) {
abort(403);
}
$u = new \stdClass();
$u->landing_pages = [];
event(new LandingPageShowing($u));
$landing_pages = $u->landing_pages;
if ($user->can('read-client-portal')) {
// Show only roles with customer permission
@ -133,9 +123,9 @@ class Users extends Controller
});
}
$companies = user()->companies()->get()->sortBy('name');
$companies = user()->companies()->take(10)->get()->sortBy('name')->pluck('name', 'id');
return view('auth.users.edit', compact('user', 'companies', 'roles', 'routes'));
return view('auth.users.edit', compact('user', 'companies', 'roles', 'landing_pages'));
}
/**
@ -148,6 +138,10 @@ class Users extends Controller
*/
public function update(User $user, Request $request)
{
if (user()->cannot('update-auth-users') && ($user->id != user()->id)) {
abort(403);
}
$response = $this->ajaxDispatch(new UpdateUser($user, $request));
if ($response['success']) {

View File

@ -28,7 +28,7 @@ class Transactions extends Controller
$request_type = !request()->has('type') ? ['income', 'expense'] : request('type');
$categories = Category::enabled()->type($request_type)->orderBy('name')->pluck('name', 'id');
$transactions = Transaction::with(['account', 'category', 'contact'])->collect(['paid_at'=> 'desc']);
$transactions = Transaction::with('account', 'category', 'contact')->collect(['paid_at'=> 'desc']);
return view('banking.transactions.index', compact('transactions', 'accounts', 'types', 'categories'));
}

View File

@ -24,9 +24,9 @@ class Transfers extends Controller
{
$data = [];
$items = Transfer::with([
$items = Transfer::with(
'expense_transaction', 'expense_transaction.account', 'income_transaction', 'income_transaction.account'
])->collect(['expense_transaction.paid_at' => 'desc']);
)->collect(['expense_transaction.paid_at' => 'desc']);
foreach ($items as $item) {
$income_transaction = $item->income_transaction;

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Common;
use App\Abstracts\Http\Controller;
use App\Http\Requests\Common\BulkAction as Request;
use Illuminate\Support\Str;
class
@ -34,7 +35,10 @@ BulkActions extends Controller
$module = module($group);
if ($module instanceof \Akaunting\Module\Module) {
$bulk_actions = app('Modules\\' . $module->getStudlyName() . '\BulkActions\\' . ucfirst($type));
$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);
} else {
$bulk_actions = app('App\BulkActions\\' . ucfirst($group) . '\\' . ucfirst($type));
}

View File

@ -213,7 +213,7 @@ class Companies extends Controller
$old_company_id = session('company_id');
session(['company_id' => $company->id]);
session(['dashboard_id' => $company->dashboards()->pluck('id')->first()]);
session(['dashboard_id' => user()->dashboards()->enabled()->pluck('id')->first()]);
Overrider::load('settings');
@ -227,4 +227,23 @@ class Companies extends Controller
return redirect()->route('dashboard');
}
public function autocomplete()
{
$query = request('query');
$autocomplete = Company::autocomplete([
'name' => $query
]);
$companies = $autocomplete->get()->sortBy('name')->pluck('name', 'id');
return response()->json([
'success' => true,
'message' => 'Get all companies.',
'errors' => [],
'count' => $companies->count(),
'data' => ($companies->count()) ? $companies : null,
]);
}
}

View File

@ -24,9 +24,9 @@ class Dashboards extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-common-dashboards')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-common-dashboards')->only(['show']);
$this->middleware('permission:update-common-dashboards')->only(['index', 'edit', 'export', 'update', 'enable', 'disable', 'share']);
$this->middleware('permission:create-common-dashboards')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-common-dashboards')->only('show');
$this->middleware('permission:update-common-dashboards')->only('index', 'edit', 'export', 'update', 'enable', 'disable', 'share');
$this->middleware('permission:delete-common-dashboards')->only('destroy');
}
@ -51,12 +51,10 @@ class Dashboards extends Controller
{
$dashboard_id = $dashboard_id ?? session('dashboard_id');
if (empty($dashboard_id)) {
$dashboard_id = user()->dashboards()->enabled()->pluck('id')->first();
}
if (!empty($dashboard_id)) {
$dashboard = Dashboard::find($dashboard_id);
} else {
$dashboard = user()->dashboards()->enabled()->first();
}
if (empty($dashboard)) {
@ -67,8 +65,10 @@ class Dashboards extends Controller
]));
}
session(['dashboard_id' => $dashboard->id]);
$widgets = Widget::where('dashboard_id', $dashboard->id)->orderBy('sort', 'asc')->get()->filter(function ($widget) {
return Widgets::canRead($widget->class);
return Widgets::canShow($widget->class);
});
$financial_start = $this->getFinancialStart()->format('Y-m-d');
@ -215,7 +215,7 @@ class Dashboards extends Controller
flash($message)->success();
session(['dashboard_id' => user()->dashboards()->pluck('id')->first()]);
session(['dashboard_id' => user()->dashboards()->enabled()->pluck('id')->first()]);
} else {
$message = $response['message'];

View File

@ -28,7 +28,7 @@ class Items extends Controller
*/
public function index()
{
$items = Item::with(['category', 'tax'])->collect();
$items = Item::with('category', 'media')->collect();
return view('common.items.index', compact('items'));
}

View File

@ -25,7 +25,7 @@ class Reports extends Controller
$reports = Report::orderBy('name')->get();
foreach ($reports as $report) {
if (!Utility::canRead($report->class)) {
if (!Utility::canShow($report->class)) {
continue;
}
@ -56,7 +56,7 @@ class Reports extends Controller
*/
public function show(Report $report)
{
if (!Utility::canRead($report->class)) {
if (!Utility::canShow($report->class)) {
abort(403);
}
@ -203,7 +203,7 @@ class Reports extends Controller
*/
public function print(Report $report)
{
if (!Utility::canRead($report->class)) {
if (!Utility::canShow($report->class)) {
abort(403);
}
@ -218,7 +218,7 @@ class Reports extends Controller
*/
public function export(Report $report)
{
if (!Utility::canRead($report->class)) {
if (!Utility::canShow($report->class)) {
abort(403);
}
@ -263,7 +263,7 @@ class Reports extends Controller
public function clear()
{
Report::all()->each(function ($report) {
if (!Utility::canRead($report->class)) {
if (!Utility::canShow($report->class)) {
return;
}

View File

@ -64,8 +64,9 @@ class Search extends Controller
'href' => route('invoices.show', $invoice->id),
];
}
}/*
}
/*
$income_transactions = Transaction::income()->usingSearchString($keyword)->get();
if ($income_transactions->count()) {
@ -78,7 +79,8 @@ class Search extends Controller
'href' => url('sales/revenues/' . $transaction->id),
];
}
}*/
}
*/
$customers = Contact::customer()->enabled()->usingSearchString($search->keyword)->get();
@ -107,7 +109,8 @@ class Search extends Controller
];
}
}
/*
/*
$payments = Transaction::expense()->usingSearchString($keyword)->get();
if ($revenues->count()) {
@ -120,7 +123,8 @@ class Search extends Controller
'href' => url('sales/revenues/' . $revenue->id),
];
}
}*/
}
*/
$vendors = Contact::vendor()->enabled()->usingSearchString($search->keyword)->get();

View File

@ -121,10 +121,21 @@ class Uploads extends Controller
*/
public function destroy($id, Request $request)
{
$return = back();
if ($request->has('ajax') && $request->get('ajax')) {
$return = [
'success' => true,
'errors' => false,
'message' => '',
'redirect' => $request->get('redirect')
];
}
try {
$media = Media::find($id);
} catch (\Exception $e) {
return back();
return $return;
}
// Get file path
@ -133,7 +144,7 @@ class Uploads extends Controller
flash($message)->warning();
return back();
return $return;
}
$media->delete(); //will not delete files
@ -150,7 +161,7 @@ class Uploads extends Controller
}
}
return back();
return $return;
}
/**

View File

@ -39,7 +39,6 @@ class Updates extends Controller
$m = new \stdClass();
$m->name = $row->getName();
$m->alias = $row->get('alias');
$m->category = $row->get('category');
$m->installed = $row->get('version');
$m->latest = $updates[$alias];

View File

@ -16,9 +16,9 @@ class Accounts extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-banking-accounts')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-banking-accounts')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-banking-accounts')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-banking-accounts')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-banking-accounts')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-banking-accounts')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-banking-accounts')->only('destroy');
}

View File

@ -22,9 +22,9 @@ class BillTransactions extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-purchases-bills')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-purchases-bills')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-purchases-bills')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-purchases-bills')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-purchases-bills')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-purchases-bills')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-purchases-bills')->only('destroy');
}
@ -67,6 +67,19 @@ class BillTransactions extends Controller
'error' => false,
'message' => 'null',
'html' => $html,
'data' => [
'title' => trans('general.title.new', ['type' => trans_choice('general.payments', 1)]),
'buttons' => [
'cancel' => [
'text' => trans('general.cancel'),
'class' => 'btn-outline-secondary'
],
'confirm' => [
'text' => trans('general.save'),
'class' => 'btn-success'
]
]
]
]);
}

View File

@ -15,9 +15,9 @@ class Categories extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-settings-categories')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-settings-categories')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-settings-categories')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-settings-categories')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-settings-categories')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-settings-categories')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-settings-categories')->only('destroy');
}

View File

@ -16,9 +16,9 @@ class Currencies extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-settings-currencies')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-settings-currencies')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-settings-currencies')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-settings-currencies')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-settings-currencies')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-settings-currencies')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-settings-currencies')->only('destroy');
}

View File

@ -15,9 +15,9 @@ class Customers extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-sales-customers')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-sales-customers')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-sales-customers')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-sales-customers')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-sales-customers')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-sales-customers')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-sales-customers')->only('destroy');
}

View File

@ -12,9 +12,9 @@ class InvoiceTemplates extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-settings-settings')->only(['create', 'store']);
$this->middleware('permission:read-settings-settings')->only(['index', 'edit']);
$this->middleware('permission:update-settings-settings')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-settings-settings')->only('create', 'store');
$this->middleware('permission:read-settings-settings')->only('index', 'edit');
$this->middleware('permission:update-settings-settings')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-settings-settings')->only('destroy');
}

View File

@ -22,9 +22,9 @@ class InvoiceTransactions extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-sales-invoices')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-sales-invoices')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-sales-invoices')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-sales-invoices')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-sales-invoices')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-sales-invoices')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-sales-invoices')->only('destroy');
}
@ -67,6 +67,24 @@ class InvoiceTransactions extends Controller
'error' => false,
'message' => 'null',
'html' => $html,
'data' => [
'title' => trans('general.title.new', ['type' => trans_choice('general.payments', 1)]),
'buttons' => [
'cancel' => [
'text' => trans('general.cancel'),
'class' => 'btn-outline-secondary'
],
'payment' => [
'text' => trans('invoices.accept_payments'),
'class' => 'long-texts',
'url' => route('apps.categories.show', 'payment-method')
],
'confirm' => [
'text' => trans('general.save'),
'class' => 'btn-success'
]
]
]
]);
}

View File

@ -17,9 +17,9 @@ class Items extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-common-items')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-common-items')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-common-items')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-common-items')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-common-items')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-common-items')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-common-items')->only('destroy');
}
@ -34,7 +34,7 @@ class Items extends Controller
$taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
$currency = Currency::where('code', setting('default.currency', 'USD'))->first();
$currency = Currency::where('code', setting('default.currency'))->first();
$html = view('modals.items.create', compact('categories', 'taxes', 'currency'))->render();

View File

@ -14,9 +14,9 @@ class Taxes extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-settings-taxes')->only(['create', 'store']);
$this->middleware('permission:read-settings-taxes')->only(['index', 'edit']);
$this->middleware('permission:update-settings-taxes')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-settings-taxes')->only('create', 'store');
$this->middleware('permission:read-settings-taxes')->only('index', 'edit');
$this->middleware('permission:update-settings-taxes')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-settings-taxes')->only('destroy');
}
@ -28,8 +28,10 @@ class Taxes extends Controller
public function create()
{
$types = [
'fixed' => trans('taxes.fixed'),
'normal' => trans('taxes.normal'),
'inclusive' => trans('taxes.inclusive'),
'withholding' => trans('taxes.withholding'),
'compound' => trans('taxes.compound'),
];

View File

@ -15,9 +15,9 @@ class Vendors extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-purchases-vendors')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-purchases-vendors')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-purchases-vendors')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-purchases-vendors')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-purchases-vendors')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-purchases-vendors')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-purchases-vendors')->only('destroy');
}

View File

@ -4,7 +4,6 @@ namespace App\Http\Controllers\Modules;
use App\Abstracts\Http\Controller;
use App\Models\Module\Module;
use App\Models\Module\ModuleHistory;
use App\Traits\Modules;
use Illuminate\Http\Request;
@ -18,9 +17,9 @@ class Item extends Controller
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-modules-item')->only(['install']);
$this->middleware('permission:update-modules-item')->only(['update', 'enable', 'disable']);
$this->middleware('permission:delete-modules-item')->only(['uninstall']);
$this->middleware('permission:create-modules-item')->only('install');
$this->middleware('permission:update-modules-item')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-modules-item')->only('uninstall');
}
/**
@ -38,7 +37,7 @@ class Item extends Controller
$module = $this->getModule($alias);
if (empty($module)) {
return redirect('apps/home')->send();
return redirect()->route('apps.home.index')->send();
}
if ($this->moduleExists($alias) && ($model = Module::alias($alias)->first())) {
@ -160,6 +159,8 @@ class Item extends Controller
$message = trans('modules.installed', ['module' => $json['data']['name']]);
flash($message)->success();
} else {
flash($json['message'])->error();
}
return response()->json($json);
@ -169,102 +170,45 @@ class Item extends Controller
{
$json = $this->uninstallModule($alias);
$module = Module::alias($alias)->first();
if ($json['success']) {
$message = trans('modules.uninstalled', ['module' => $json['data']['name']]);
$data = [
'company_id' => session('company_id'),
'module_id' => $module->id,
'category' => $json['data']['category'],
'version' => $json['data']['version'],
'description' => trans('modules.uninstalled', ['module' => $json['data']['name']]),
];
flash($message)->success();
} else {
flash($json['message'])->error();
}
ModuleHistory::create($data);
$module->delete();
$message = trans('modules.uninstalled', ['module' => $json['data']['name']]);
flash($message)->success();
return redirect('apps/' . $alias)->send();
}
public function update($alias)
{
$json = $this->updateModule($alias);
$module = Module::alias($alias)->first();
$data = [
'company_id' => session('company_id'),
'module_id' => $module->id,
'category' => $json['data']['category'],
'version' => $json['data']['version'],
'description' => trans_choice('modules.updated', $json['data']['name']),
];
ModuleHistory::create($data);
$message = trans('modules.updated', ['module' => $json['data']['name']]);
flash($message)->success();
return redirect('apps/' . $alias)->send();
return redirect()->route('apps.app.show', $alias)->send();
}
public function enable($alias)
{
$json = $this->enableModule($alias);
$module = Module::alias($alias)->first();
if ($json['success']) {
$message = trans('modules.enabled', ['module' => $json['data']['name']]);
$data = [
'company_id' => session('company_id'),
'module_id' => $module->id,
'category' => $json['data']['category'],
'version' => $json['data']['version'],
'description' => trans('modules.enabled', ['module' => $json['data']['name']]),
];
flash($message)->success();
} else {
flash($json['message'])->error();
}
$module->enabled = 1;
$module->save();
ModuleHistory::create($data);
$message = trans('modules.enabled', ['module' => $json['data']['name']]);
flash($message)->success();
return redirect('apps/' . $alias)->send();
return redirect()->route('apps.app.show', $alias)->send();
}
public function disable($alias)
{
$json = $this->disableModule($alias);
$module = Module::alias($alias)->first();
if ($json['success']) {
$message = trans('modules.disabled', ['module' => $json['data']['name']]);
$data = [
'company_id' => session('company_id'),
'module_id' => $module->id,
'category' => $json['data']['category'],
'version' => $json['data']['version'],
'description' => trans('modules.disabled', ['module' => $json['data']['name']]),
];
flash($message)->success();
} else {
flash($json['message'])->error();
}
$module->enabled = 0;
$module->save();
ModuleHistory::create($data);
$message = trans('modules.disabled', ['module' => $json['data']['name']]);
flash($message)->success();
return redirect('apps/' . $alias)->send();
return redirect()->route('apps.app.show', $alias)->send();
}
public function reviews($alias, Request $request)
@ -292,11 +236,11 @@ class Item extends Controller
{
$documentation = $this->getDocumentation($alias);
if (empty($documentation)) {
return redirect('apps/' . $alias)->send();
}
$back = route('apps.app.show', $alias);
$back = 'apps/' . $alias;
if (empty($documentation)) {
return redirect()->route($back)->send();
}
return view('modules.item.documentation', compact('documentation', 'back'));
}

View File

@ -23,7 +23,7 @@ class Invoices extends Controller
*/
public function index()
{
$invoices = Invoice::with(['contact', 'items', 'payments', 'histories'])
$invoices = Invoice::with('contact', 'histories', 'items', 'payments')
->accrued()->where('contact_id', user()->contact->id)
->collect(['invoice_number'=> 'desc']);

View File

@ -37,7 +37,7 @@ class Bills extends Controller
*/
public function index()
{
$bills = Bill::with(['contact', 'items', 'histories', 'transactions'])->collect(['billed_at'=> 'desc']);
$bills = Bill::with('contact', 'transactions')->collect(['billed_at'=> 'desc']);
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');
@ -83,7 +83,7 @@ class Bills extends Controller
$bill->grand_total = money($total, $currency->code)->getAmount();
if (!empty($bill->paid)) {
$bill->grand_total = round($bill->total - $bill->paid, $currency->precision) ;
$bill->grand_total = round($bill->total - $bill->paid, $currency->precision);
}
return view('purchases.bills.show', compact('bill', 'accounts', 'currencies', 'currency', 'account_currency_code', 'vendors', 'categories', 'payment_methods', 'date_format'));

View File

@ -30,7 +30,7 @@ class Payments extends Controller
*/
public function index()
{
$payments = Transaction::expense()->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']);
$payments = Transaction::with('account', 'bill', 'category', 'contact')->expense()->isNotTransfer()->collect(['paid_at'=> 'desc']);
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');

View File

@ -28,7 +28,7 @@ class Vendors extends Controller
*/
public function index()
{
$vendors = Contact::vendor()->collect();
$vendors = Contact::with('bills.transactions')->vendor()->collect();
return view('purchases.vendors.index', compact('vendors'));
}
@ -51,7 +51,7 @@ class Vendors extends Controller
$counts = [];
// Handle bills
$bills = Bill::where('contact_id', $vendor->id)->get();
$bills = Bill::with('transactions')->where('contact_id', $vendor->id)->get();
$counts['bills'] = $bills->count();
@ -78,7 +78,7 @@ class Vendors extends Controller
}
// Handle payments
$transactions = Transaction::where('contact_id', $vendor->id)->expense()->get();
$transactions = Transaction::with('category')->where('contact_id', $vendor->id)->expense()->get();
$counts['transactions'] = $transactions->count();

View File

@ -26,7 +26,7 @@ class Customers extends Controller
*/
public function index()
{
$customers = Contact::customer()->collect();
$customers = Contact::with('invoices.transactions')->customer()->collect();
return view('sales.customers.index', compact('customers'));
}
@ -49,7 +49,7 @@ class Customers extends Controller
$counts = [];
// Handle invoices
$invoices = Invoice::where('contact_id', $customer->id)->get();
$invoices = Invoice::with('transactions')->where('contact_id', $customer->id)->get();
$counts['invoices'] = $invoices->count();
@ -76,7 +76,7 @@ class Customers extends Controller
}
// Handle transactions
$transactions = Transaction::where('contact_id', $customer->id)->income()->get();
$transactions = Transaction::with('category')->where('contact_id', $customer->id)->income()->get();
$counts['transactions'] = $transactions->count();

View File

@ -38,7 +38,7 @@ class Invoices extends Controller
*/
public function index()
{
$invoices = Invoice::with(['contact', 'items', 'histories', 'transactions'])->collect(['invoice_number'=> 'desc']);
$invoices = Invoice::with('contact', 'transactions')->collect(['invoice_number'=> 'desc']);
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
@ -435,7 +435,7 @@ class Invoices extends Controller
$currency = Currency::where('code', $currency_code)->first();
if (empty($currency)) {
$currency = Currency::where('code', setting('default.currency', 'USD'))->first();
$currency = Currency::where('code', setting('default.currency'))->first();
}
if ($currency) {

View File

@ -30,7 +30,7 @@ class Revenues extends Controller
*/
public function index()
{
$revenues = Transaction::income()->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']);
$revenues = Transaction::with('account', 'category', 'contact', 'invoice')->income()->isNotTransfer()->collect(['paid_at'=> 'desc']);
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');

View File

@ -3,20 +3,11 @@
namespace App\Http\Controllers\Settings;
use App\Abstracts\Http\Controller;
use App\Models\Setting\Setting;
class Company extends Controller
{
public function edit()
{
$setting = Setting::prefix('company')->get()->transform(function ($s) {
$s->key = str_replace('company.', '', $s->key);
return $s;
})->pluck('value', 'key');
return view('settings.company.edit', compact(
'setting'
));
return view('settings.company.edit');
}
}

View File

@ -56,7 +56,15 @@ class Currencies extends Controller
$codes[$key] = $key;
}
return view('settings.currencies.create', compact('codes'));
$precisions = (object) [
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
];
return view('settings.currencies.create', compact('codes', 'precisions'));
}
/**
@ -114,7 +122,15 @@ class Currencies extends Controller
// Set default currency
$currency->default_currency = ($currency->code == setting('default.currency')) ? 1 : 0;
return view('settings.currencies.edit', compact('currency', 'codes'));
$precisions = (object) [
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
];
return view('settings.currencies.edit', compact('currency', 'codes', 'precisions'));
}
/**

View File

@ -5,7 +5,6 @@ namespace App\Http\Controllers\Settings;
use App\Abstracts\Http\Controller;
use App\Models\Banking\Account;
use App\Models\Setting\Currency;
use App\Models\Setting\Setting;
use App\Models\Setting\Tax;
use App\Utilities\Modules;
@ -13,12 +12,6 @@ class Defaults extends Controller
{
public function edit()
{
$setting = Setting::prefix('default')->get()->transform(function ($s) {
$s->key = str_replace('default.', '', $s->key);
return $s;
})->pluck('value', 'key');
$accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
$currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code');
@ -28,7 +21,6 @@ class Defaults extends Controller
$payment_methods = Modules::getPaymentMethods();
return view('settings.default.edit', compact(
'setting',
'accounts',
'currencies',
'taxes',

View File

@ -4,8 +4,9 @@ namespace App\Http\Controllers\Settings;
use App\Abstracts\Http\Controller;
use App\Http\Requests\Setting\Setting as Request;
use App\Models\Common\Company;
use App\Models\Common\EmailTemplate;
use App\Models\Setting\Setting;
use App\Utilities\Installer;
use Illuminate\Support\Str;
class Email extends Controller
@ -23,20 +24,14 @@ class Email extends Controller
}
// Add CRUD permission check
$this->middleware('permission:create-settings-settings')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-settings-email')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-settings-settings')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-settings-settings')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-settings-email')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-settings-settings')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-settings-settings')->only('destroy');
}
public function edit()
{
$setting = Setting::prefix('email')->get()->transform(function ($s) {
$s->key = str_replace('email.', '', $s->key);
return $s;
})->pluck('value', 'key');
$templates = EmailTemplate::all();
$email_protocols = [
@ -47,7 +42,6 @@ class Email extends Controller
];
return view('settings.email.edit', compact(
'setting',
'templates',
'email_protocols'
));
@ -58,6 +52,8 @@ class Email extends Controller
$fields = $request->all();
$prefix = $request->get('_prefix', 'email');
$total_companies = Company::count();
foreach ($fields as $key => $value) {
$real_key = $prefix . '.' . $key;
@ -72,6 +68,10 @@ class Email extends Controller
continue;
}
if ($total_companies == 1) {
$this->oneCompany($real_key, $value);
}
setting()->set($real_key, $value);
}
@ -114,4 +114,32 @@ class Email extends Controller
unset($fields[$subject_key]);
unset($fields[$body_key]);
}
protected function oneCompany($real_key, $value)
{
if (empty($value)) {
return;
}
switch ($real_key) {
case 'email.protocol':
Installer::updateEnv(['MAIL_MAILER' => '"' . $value . '"']);
break;
case 'email.smtp_host':
Installer::updateEnv(['MAIL_HOST' => '"' . $value . '"']);
break;
case 'email.smtp_port':
Installer::updateEnv(['MAIL_PORT' => '"' . $value . '"']);
break;
case 'email.smtp_username':
Installer::updateEnv(['MAIL_USERNAME' => '"' . $value . '"']);
break;
case 'email.smtp_password':
Installer::updateEnv(['MAIL_PASSWORD' => '"' . $value . '"']);
break;
case 'email.smtp_encryption':
Installer::updateEnv(['MAIL_ENCRYPTION' => '"' . $value . '"']);
break;
}
}
}

View File

@ -3,18 +3,11 @@
namespace App\Http\Controllers\Settings;
use App\Abstracts\Http\Controller;
use App\Models\Setting\Setting;
class Invoice extends Controller
{
public function edit()
{
$setting = Setting::prefix('invoice')->get()->transform(function ($s) {
$s->key = str_replace('invoice.', '', $s->key);
return $s;
})->pluck('value', 'key');
$item_names = [
'settings.invoice.item' => trans('settings.invoice.item'),
'settings.invoice.product' => trans('settings.invoice.product'),
@ -43,7 +36,6 @@ class Invoice extends Controller
];
return view('settings.invoice.edit', compact(
'setting',
'item_names',
'price_names',
'quantity_names',

View File

@ -3,7 +3,6 @@
namespace App\Http\Controllers\Settings;
use App\Abstracts\Http\Controller;
use App\Models\Setting\Setting;
use App\Traits\DateTime;
class Localisation extends Controller
@ -12,12 +11,6 @@ class Localisation extends Controller
public function edit()
{
$setting = Setting::prefix('localisation')->get()->transform(function ($s) {
$s->key = str_replace('localisation.', '', $s->key);
return $s;
})->pluck('value', 'key');
$timezones = $this->getTimezones();
$date_formats = [
@ -49,7 +42,6 @@ class Localisation extends Controller
];
return view('settings.localisation.edit', compact(
'setting',
'timezones',
'date_formats',
'date_separators',

View File

@ -3,6 +3,8 @@
namespace App\Http\Controllers\Settings;
use App\Abstracts\Http\Controller;
use App\Models\Banking\Account;
use App\Models\Setting\Category;
use App\Models\Setting\Setting;
use App\Utilities\Modules as Utility;
use App\Http\Requests\Setting\Module as Request;
@ -17,9 +19,9 @@ class Modules extends Controller
$alias = request()->segment(1);
// Add CRUD permission check
$this->middleware('permission:create-' . $alias . '-settings')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-' . $alias . '-settings')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-' . $alias . '-settings')->only(['update', 'enable', 'disable']);
$this->middleware('permission:create-' . $alias . '-settings')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-' . $alias . '-settings')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-' . $alias . '-settings')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-' . $alias . '-settings')->only('destroy');
}
@ -30,6 +32,9 @@ class Modules extends Controller
*/
public function edit($alias)
{
$accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
$setting = Setting::prefix($alias)->get()->transform(function ($s) use ($alias) {
$s->key = str_replace($alias . '.', '', $s->key);
return $s;
@ -37,7 +42,7 @@ class Modules extends Controller
$module = module($alias);
return view('settings.modules.edit', compact('setting', 'module'));
return view('settings.modules.edit', compact('setting', 'module', 'accounts', 'categories'));
}
/**

Some files were not shown because too many files have changed in this diff Show More