Merge branch 'master' of github.com:akaunting/akaunting
# Conflicts: # resources/views/banking/reconciliations/create.blade.php
This commit is contained in:
commit
41e7aee498
@ -123,8 +123,6 @@ abstract class BulkAction
|
||||
foreach ($items as $item) {
|
||||
$item->delete();
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
}
|
||||
|
||||
public function disableContacts($request)
|
||||
|
@ -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')->pluck('amount')->first();
|
||||
|
||||
if ($discount) {
|
||||
$sub_total = $this->totals()->where('code', 'sub_total')->value('amount');
|
||||
$sub_total = $this->totals->where('code', 'sub_total')->pluck('amount')->first();
|
||||
|
||||
$percent = number_format((($discount * 100) / $sub_total), 0);
|
||||
}
|
||||
@ -171,7 +171,7 @@ abstract class DocumentModel extends Model
|
||||
{
|
||||
$amount = $this->amount;
|
||||
|
||||
$this->totals()->where('code', 'tax')->each(function ($tax) use(&$amount) {
|
||||
$this->totals->where('code', 'tax')->each(function ($tax) use(&$amount) {
|
||||
$amount -= $tax->amount;
|
||||
});
|
||||
|
||||
|
@ -35,6 +35,8 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W
|
||||
|
||||
$date_fields = ['paid_at', 'invoiced_at', 'billed_at', 'due_at', 'issued_at', 'created_at'];
|
||||
|
||||
$evil_chars = ['=', '+', '-', '@'];
|
||||
|
||||
foreach ($this->fields() as $field) {
|
||||
$value = $model->$field;
|
||||
|
||||
@ -42,6 +44,11 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W
|
||||
$value = Date::parse($value)->format('Y-m-d');
|
||||
}
|
||||
|
||||
// Prevent CSV injection https://security.stackexchange.com/a/190848
|
||||
if (Str::startsWith($value, $evil_chars)) {
|
||||
$value = "'" . $value;
|
||||
}
|
||||
|
||||
$map[] = $value;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Abstracts;
|
||||
|
||||
use App\Scopes\Company;
|
||||
use App\Traits\Tenants;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@ -11,7 +12,9 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
abstract class Model extends Eloquent
|
||||
{
|
||||
use Cachable, SearchString, SoftDeletes, Sortable;
|
||||
use Cachable, SearchString, SoftDeletes, Sortable, Tenants;
|
||||
|
||||
protected $tenantable = true;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
|
@ -47,11 +47,6 @@ abstract class Report
|
||||
|
||||
public $loaded = false;
|
||||
|
||||
public $indents = [
|
||||
'table_header' => '0px',
|
||||
'table_rows' => '24px',
|
||||
];
|
||||
|
||||
public $chart = [
|
||||
'line' => [
|
||||
'width' => '0',
|
||||
@ -329,7 +324,7 @@ abstract class Report
|
||||
event(new RowsShowing($this));
|
||||
}
|
||||
|
||||
public function setTotals($items, $date_field, $check_type = false, $table = 'default')
|
||||
public function setTotals($items, $date_field, $check_type = false, $table = 'default', $with_tax = true)
|
||||
{
|
||||
foreach ($items as $item) {
|
||||
// Make groups extensible
|
||||
@ -347,7 +342,7 @@ abstract class Report
|
||||
continue;
|
||||
}
|
||||
|
||||
$amount = $item->getAmountConvertedToDefault();
|
||||
$amount = $item->getAmountConvertedToDefault(false, $with_tax);
|
||||
|
||||
$type = (($item instanceof Invoice) || (($item instanceof Transaction) && ($item->type == 'income'))) ? 'income' : 'expense';
|
||||
|
||||
|
@ -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]));
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,11 @@ class Kernel extends ConsoleKernel
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// Not installed yet
|
||||
if (!env('APP_INSTALLED')) {
|
||||
if (!config('app.installed')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$schedule_time = env('APP_SCHEDULE_TIME', '09:00');
|
||||
$schedule_time = config('app.schedule_time');
|
||||
|
||||
$schedule->command('reminder:invoice')->dailyAt($schedule_time);
|
||||
$schedule->command('reminder:bill')->dailyAt($schedule_time);
|
||||
|
@ -1,25 +1,16 @@
|
||||
{
|
||||
"name": "$VENDOR$/$LOWER_NAME$",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "$AUTHOR_NAME$",
|
||||
"email": "$AUTHOR_EMAIL$"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\": ""
|
||||
}
|
||||
"require": {
|
||||
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\Main"
|
||||
],
|
||||
"aliases": {
|
||||
|
||||
}
|
||||
}
|
||||
"replace": {
|
||||
"guzzlehttp/guzzle": "*",
|
||||
"guzzlehttp/psr7": "*",
|
||||
"laravel/framework": "*",
|
||||
"symfony/http-foundation": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"test": [
|
||||
"composer install --prefer-dist --no-interaction --no-scripts --no-suggest --no-progress --no-ansi"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners;
|
||||
use App\Events\Module\Installed as Event;
|
||||
use App\Traits\Permissions;
|
||||
|
||||
class InstallModule
|
||||
class FinishInstallation
|
||||
{
|
||||
use Permissions;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider;
|
||||
use $MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners\InstallModule;
|
||||
use $MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners\FinishInstallation;
|
||||
|
||||
class Event extends Provider
|
||||
{
|
||||
@ -14,7 +14,7 @@ class Event extends Provider
|
||||
*/
|
||||
protected $listen = [
|
||||
\App\Events\Module\Installed::class => [
|
||||
InstallModule::class,
|
||||
FinishInstallation::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
22
app/Events/Common/GlobalSearched.php
Normal file
22
app/Events/Common/GlobalSearched.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class GlobalSearched
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $search;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $search
|
||||
*/
|
||||
public function __construct($search)
|
||||
{
|
||||
$this->search = $search;
|
||||
}
|
||||
}
|
@ -54,7 +54,7 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
if (env('APP_DEBUG') === false) {
|
||||
if (config('app.debug') === false) {
|
||||
return $this->handleExceptions($request, $exception);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -9,7 +9,7 @@ class Payments extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with(['account', 'bill', 'category', 'contact'])->type('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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -9,7 +9,7 @@ class BillTransactions extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with(['account', 'category', 'contact', 'bill'])->type('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);
|
||||
|
@ -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);
|
||||
|
@ -9,7 +9,7 @@ class Revenues extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with(['account', 'category', 'contact', 'invoice'])->type('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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -9,7 +9,7 @@ class InvoiceTransactions extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with(['account', 'category', 'contact', 'invoice'])->type('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);
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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',
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class Login extends Controller
|
||||
auth()->logout();
|
||||
|
||||
// Session destroy is required if stored in database
|
||||
if (env('SESSION_DRIVER') == 'database') {
|
||||
if (config('session.driver') == 'database') {
|
||||
$request = app('Illuminate\Http\Request');
|
||||
$request->session()->getHandler()->destroy($request->session()->getId());
|
||||
}
|
||||
|
@ -23,7 +23,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'));
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use App\Jobs\Banking\UpdateReconciliation;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Banking\Reconciliation;
|
||||
use App\Models\Banking\Transaction;
|
||||
use Date;
|
||||
|
||||
class Reconciliations extends Controller
|
||||
{
|
||||
@ -48,8 +49,8 @@ class Reconciliations extends Controller
|
||||
$accounts = Account::enabled()->pluck('name', 'id');
|
||||
|
||||
$account_id = request('account_id', setting('default.account'));
|
||||
$started_at = request('started_at', '0000-00-00');
|
||||
$ended_at = request('ended_at', '0000-00-00');
|
||||
$started_at = request('started_at', Date::now()->firstOfMonth()->toDateString());
|
||||
$ended_at = request('ended_at', Date::now()->endOfMonth()->toDateString());
|
||||
|
||||
$account = Account::find($account_id);
|
||||
|
||||
|
@ -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'));
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -47,38 +47,33 @@ class Dashboards extends Controller
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function show(Dashboard $dashboard)
|
||||
public function show($dashboard_id = null)
|
||||
{
|
||||
$dashboard_id = session('dashboard_id', 0);
|
||||
$dashboard_id = $dashboard_id ?? session('dashboard_id');
|
||||
|
||||
if ($dashboard) {
|
||||
$dashboard_id = $dashboard->id;
|
||||
if (empty($dashboard_id)) {
|
||||
$dashboard_id = user()->dashboards()->enabled()->pluck('id')->first();
|
||||
}
|
||||
|
||||
// Change Dashboard
|
||||
if (request()->get('dashboard_id', 0)) {
|
||||
$dashboard_id = request()->get('dashboard_id');
|
||||
|
||||
session(['dashboard_id' => $dashboard_id]);
|
||||
if (!empty($dashboard_id)) {
|
||||
$dashboard = Dashboard::find($dashboard_id);
|
||||
}
|
||||
|
||||
$dashboards = user()->dashboards()->enabled()->get();
|
||||
|
||||
if (!$dashboard_id) {
|
||||
$dashboard_id = $dashboards->pluck('id')->first();
|
||||
if (empty($dashboard)) {
|
||||
$dashboard = $this->dispatch(new CreateDashboard([
|
||||
'company_id' => session('company_id'),
|
||||
'name' => trans_choice('general.dashboards', 1),
|
||||
'with_widgets' => true,
|
||||
]));
|
||||
}
|
||||
|
||||
// Dashboard
|
||||
$dashboard = Dashboard::find($dashboard_id);
|
||||
|
||||
// Widgets
|
||||
$widgets = Widget::where('dashboard_id', $dashboard->id)->orderBy('sort', 'asc')->get()->filter(function ($widget) {
|
||||
return Widgets::canRead($widget->class);
|
||||
});
|
||||
|
||||
$financial_start = $this->getFinancialStart()->format('Y-m-d');
|
||||
|
||||
return view('common.dashboards.show', compact('dashboards', 'dashboard', 'widgets', 'financial_start'));
|
||||
return view('common.dashboards.show', compact('dashboard', 'widgets', 'financial_start'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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'));
|
||||
}
|
||||
@ -50,7 +50,7 @@ class Items extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::item()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
|
||||
|
||||
@ -131,7 +131,7 @@ class Items extends Controller
|
||||
*/
|
||||
public function edit(Item $item)
|
||||
{
|
||||
$categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::item()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Common;
|
||||
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Events\Common\GlobalSearched;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Common\Contact;
|
||||
@ -19,53 +20,53 @@ class Search extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$results = array();
|
||||
$search = new \stdClass();
|
||||
$search->results = [];
|
||||
$search->keyword = request('keyword');
|
||||
|
||||
$keyword = request('keyword');
|
||||
|
||||
$accounts = Account::enabled()->usingSearchString($keyword)->get();
|
||||
$accounts = Account::enabled()->usingSearchString($search->keyword)->get();
|
||||
|
||||
if ($accounts->count()) {
|
||||
foreach ($accounts as $account) {
|
||||
$results[] = (object)[
|
||||
$search->results[] = (object) [
|
||||
'id' => $account->id,
|
||||
'name' => $account->name,
|
||||
'type' => trans_choice('general.accounts', 1),
|
||||
'color' => '#55588b',
|
||||
'href' => url('banking/accounts/' . $account->id . '/edit'),
|
||||
'href' => route('accounts.edit', $account->id),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$items = Item::enabled()->usingSearchString($keyword)->get();
|
||||
$items = Item::enabled()->usingSearchString($search->keyword)->get();
|
||||
|
||||
if ($items->count()) {
|
||||
foreach ($items as $item) {
|
||||
$results[] = (object)[
|
||||
$search->results[] = (object) [
|
||||
'id' => $item->id,
|
||||
'name' => $item->name,
|
||||
'type' => trans_choice('general.items', 1),
|
||||
'color' => '#efad32',
|
||||
'href' => url('common/items/' . $item->id . '/edit'),
|
||||
'href' => route('items.edit', $item->id),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$invoices = Invoice::usingSearchString($keyword)->get();
|
||||
$invoices = Invoice::usingSearchString($search->keyword)->get();
|
||||
|
||||
if ($invoices->count()) {
|
||||
foreach ($invoices as $invoice) {
|
||||
$results[] = (object)[
|
||||
$search->results[] = (object) [
|
||||
'id' => $invoice->id,
|
||||
'name' => $invoice->invoice_number . ' - ' . $invoice->contact_name,
|
||||
'type' => trans_choice('general.invoices', 1),
|
||||
'color' => '#6da252',
|
||||
'href' => url('sales/invoices/' . $invoice->id),
|
||||
'href' => route('invoices.show', $invoice->id),
|
||||
];
|
||||
}
|
||||
}/*
|
||||
|
||||
$income_transactions = Transaction::type('income')->usingSearchString($keyword)->get();
|
||||
$income_transactions = Transaction::income()->usingSearchString($keyword)->get();
|
||||
|
||||
if ($income_transactions->count()) {
|
||||
foreach ($income_transactions as $transaction) {
|
||||
@ -79,35 +80,35 @@ class Search extends Controller
|
||||
}
|
||||
}*/
|
||||
|
||||
$customers = Contact::customer()->enabled()->usingSearchString($keyword)->get();
|
||||
$customers = Contact::customer()->enabled()->usingSearchString($search->keyword)->get();
|
||||
|
||||
if ($customers->count()) {
|
||||
foreach ($customers as $customer) {
|
||||
$results[] = (object)[
|
||||
$search->results[] = (object) [
|
||||
'id' => $customer->id,
|
||||
'name' => $customer->name,
|
||||
'type' => trans_choice('general.customers', 1),
|
||||
'color' => '#328aef',
|
||||
'href' => url('sales/customers/' . $customer->id),
|
||||
'href' => route('customers.show', $customer->id),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$bills = Bill::usingSearchString($keyword)->get();
|
||||
$bills = Bill::usingSearchString($search->keyword)->get();
|
||||
|
||||
if ($bills->count()) {
|
||||
foreach ($bills as $bill) {
|
||||
$results[] = (object)[
|
||||
$search->results[] = (object) [
|
||||
'id' => $bill->id,
|
||||
'name' => $bill->bill_number . ' - ' . $bill->contact_name,
|
||||
'type' => trans_choice('general.bills', 1),
|
||||
'color' => '#ef3232',
|
||||
'href' => url('purchases/bills/' . $bill->id),
|
||||
'href' => route('bills.show', $bill->id),
|
||||
];
|
||||
}
|
||||
}
|
||||
/*
|
||||
$payments = Transaction::type('expense')->usingSearchString($keyword)->get();
|
||||
$payments = Transaction::expense()->usingSearchString($keyword)->get();
|
||||
|
||||
if ($revenues->count()) {
|
||||
foreach ($revenues as $revenue) {
|
||||
@ -121,20 +122,22 @@ class Search extends Controller
|
||||
}
|
||||
}*/
|
||||
|
||||
$vendors = Contact::vendor()->enabled()->usingSearchString($keyword)->get();
|
||||
$vendors = Contact::vendor()->enabled()->usingSearchString($search->keyword)->get();
|
||||
|
||||
if ($vendors->count()) {
|
||||
foreach ($vendors as $vendor) {
|
||||
$results[] = (object)[
|
||||
$search->results[] = (object) [
|
||||
'id' => $vendor->id,
|
||||
'name' => $vendor->name,
|
||||
'type' => trans_choice('general.vendors', 1),
|
||||
'color' => '#efef32',
|
||||
'href' => url('purchases/vendors/' . $vendor->id),
|
||||
'href' => route('vendors.show', $vendor->id),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json((object) $results);
|
||||
event(new GlobalSearched($search));
|
||||
|
||||
return response()->json((object) $search->results);
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,10 @@ class Database extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$connection = config('database.default','mysql');
|
||||
|
||||
$host = $request['hostname'];
|
||||
$port = env('DB_PORT', '3306');
|
||||
$port = config("database.connections.$connection.port", '3306');
|
||||
$database = $request['database'];
|
||||
$username = $request['username'];
|
||||
$password = $request['password'];
|
||||
|
@ -30,7 +30,7 @@ class Items extends Controller
|
||||
*/
|
||||
public function create(IRequest $request)
|
||||
{
|
||||
$categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::item()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
|
||||
|
||||
|
@ -84,19 +84,19 @@ class Item extends Controller
|
||||
// Download
|
||||
$steps[] = [
|
||||
'text' => trans('modules.installation.download', ['module' => $name]),
|
||||
'url' => url('apps/download')
|
||||
'url' => route('apps.download')
|
||||
];
|
||||
|
||||
// Unzip
|
||||
$steps[] = [
|
||||
'text' => trans('modules.installation.unzip', ['module' => $name]),
|
||||
'url' => url('apps/unzip')
|
||||
'url' => route('apps.unzip')
|
||||
];
|
||||
|
||||
// Download
|
||||
$steps[] = [
|
||||
'text' => trans('modules.installation.install', ['module' => $name]),
|
||||
'url' => url('apps/install')
|
||||
'url' => route('apps.install')
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
@ -269,11 +269,9 @@ class Item extends Controller
|
||||
|
||||
public function reviews($alias, Request $request)
|
||||
{
|
||||
$page = $request['page'];
|
||||
|
||||
$data = [
|
||||
'query' => [
|
||||
'page' => ($page) ? $page : 1,
|
||||
'page' => $request->get('page', 1),
|
||||
]
|
||||
];
|
||||
|
||||
@ -284,7 +282,7 @@ class Item extends Controller
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'data' => null,
|
||||
'data' => $reviews,
|
||||
'message' => null,
|
||||
'html' => $html,
|
||||
]);
|
||||
|
@ -146,7 +146,7 @@ class Tiles extends Controller
|
||||
]
|
||||
];
|
||||
|
||||
$title = trans('modules.search');
|
||||
$title = trans('general.search');
|
||||
$modules = $this->getSearchModules($data);
|
||||
$installed = Module::all()->pluck('enabled', 'alias')->toArray();
|
||||
|
||||
|
@ -23,11 +23,11 @@ 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']);
|
||||
|
||||
$categories = collect(Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'));
|
||||
$categories = collect(Category::income()->enabled()->orderBy('name')->pluck('name', 'id'));
|
||||
|
||||
$statuses = $this->getInvoiceStatuses();
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Payments extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$payments = Transaction::type('income')->where('contact_id', '=', user()->contact->id)->paginate();
|
||||
$payments = Transaction::income()->where('contact_id', '=', user()->contact->id)->paginate();
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods('all');
|
||||
|
||||
|
@ -37,11 +37,11 @@ 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');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$statuses = $this->getBillStatuses();
|
||||
|
||||
@ -67,7 +67,7 @@ class Bills extends Controller
|
||||
|
||||
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
@ -106,7 +106,7 @@ class Bills extends Controller
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get();
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$number = $this->getNextBillNumber();
|
||||
|
||||
@ -202,7 +202,7 @@ class Bills extends Controller
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get();
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
return view('purchases.bills.edit', compact('bill', 'vendors', 'currencies', 'currency', 'items', 'taxes', 'categories'));
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ class Payments extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$payments = Transaction::type('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');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
@ -68,7 +68,7 @@ class Payments extends Controller
|
||||
|
||||
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
@ -156,7 +156,7 @@ class Payments extends Controller
|
||||
|
||||
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
|
@ -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)->type('expense')->get();
|
||||
$transactions = Transaction::with('category')->where('contact_id', $vendor->id)->expense()->get();
|
||||
|
||||
$counts['transactions'] = $transactions->count();
|
||||
|
||||
|
@ -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)->type('income')->get();
|
||||
$transactions = Transaction::with('category')->where('contact_id', $customer->id)->income()->get();
|
||||
|
||||
$counts['transactions'] = $transactions->count();
|
||||
|
||||
|
@ -38,11 +38,11 @@ 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');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$statuses = $this->getInvoiceStatuses();
|
||||
|
||||
@ -68,7 +68,7 @@ class Invoices extends Controller
|
||||
|
||||
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
@ -109,7 +109,7 @@ class Invoices extends Controller
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get();
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$number = $this->getNextInvoiceNumber();
|
||||
|
||||
@ -205,7 +205,7 @@ class Invoices extends Controller
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get();
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
return view('sales.invoices.edit', compact('invoice', 'customers', 'currencies', 'currency', 'items', 'taxes', 'categories'));
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ class Revenues extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$revenues = Transaction::type('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');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
@ -68,7 +68,7 @@ class Revenues extends Controller
|
||||
|
||||
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
@ -156,7 +156,7 @@ class Revenues extends Controller
|
||||
|
||||
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
|
@ -4,8 +4,10 @@ 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
|
||||
@ -58,6 +60,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 +76,10 @@ class Email extends Controller
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($total_companies == 1) {
|
||||
$this->oneCompany($real_key, $value);
|
||||
}
|
||||
|
||||
setting()->set($real_key, $value);
|
||||
}
|
||||
|
||||
@ -114,4 +122,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Settings;
|
||||
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Models\Setting\Setting;
|
||||
use App\Utilities\Modules as Utility;
|
||||
use App\Http\Requests\Setting\Module as Request;
|
||||
|
||||
class Modules extends Controller
|
||||
@ -54,9 +55,10 @@ class Modules extends Controller
|
||||
setting()->set($alias . '.' . $key, $value);
|
||||
}
|
||||
|
||||
// Save all settings
|
||||
setting()->save();
|
||||
|
||||
Utility::clearPaymentMethodsCache();
|
||||
|
||||
$message = trans('messages.success.updated', ['type' => trans_choice('general.settings', 2)]);
|
||||
|
||||
$response = [
|
||||
|
@ -102,6 +102,7 @@ class Kernel extends HttpKernel
|
||||
'session.errors',
|
||||
'csrf',
|
||||
'signature',
|
||||
'signed.redirect',
|
||||
'company.signed',
|
||||
'bindings',
|
||||
'header.x',
|
||||
@ -139,6 +140,7 @@ class Kernel extends HttpKernel
|
||||
|
||||
// Akaunting
|
||||
'api.company' => \App\Http\Middleware\ApiCompany::class,
|
||||
'api.key' => \App\Http\Middleware\CanApiKey::class,
|
||||
'auth.disabled' => \App\Http\Middleware\LogoutIfUserDisabled::class,
|
||||
'auth.redirect' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'company.currencies' => \App\Http\Middleware\LoadCurrencies::class,
|
||||
@ -151,8 +153,8 @@ class Kernel extends HttpKernel
|
||||
'install.can' => \App\Http\Middleware\CanInstall::class,
|
||||
'install.redirect' => \App\Http\Middleware\RedirectIfNotInstalled::class,
|
||||
'money' => \App\Http\Middleware\Money::class,
|
||||
'signed.redirect' => \App\Http\Middleware\RedirectSignedIfAuthenticated::class,
|
||||
'wizard.redirect' => \App\Http\Middleware\RedirectIfWizardNotCompleted::class,
|
||||
'api.key' => \App\Http\Middleware\CanApiKey::class,
|
||||
|
||||
// Vendor
|
||||
'ability' => \Laratrust\Middleware\LaratrustAbility::class,
|
||||
|
37
app/Http/Middleware/RedirectSignedIfAuthenticated.php
Normal file
37
app/Http/Middleware/RedirectSignedIfAuthenticated.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Sale\Invoice;
|
||||
use Closure;
|
||||
|
||||
class RedirectSignedIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (!$user = user()) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$prefix = $user->contact ? 'portal.' : '';
|
||||
$page = 'dashboard';
|
||||
$params = [];
|
||||
|
||||
if ($request->segment(2) == 'invoices') {
|
||||
$page = 'invoices.show';
|
||||
|
||||
$invoice = Invoice::find($request->segment(3));
|
||||
|
||||
$params = [$invoice->id];
|
||||
}
|
||||
|
||||
redirect()->route($prefix . $page, $params)->send();
|
||||
}
|
||||
}
|
@ -22,11 +22,11 @@ class Modules
|
||||
if (setting('apps.api_key')) {
|
||||
$categories = Cache::remember('modules.categories.' . language()->getShortCode(), Date::now()->addHour(6), function () {
|
||||
return collect($this->getCategories())->pluck('name', 'slug')
|
||||
->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), '');
|
||||
->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), '*');
|
||||
});
|
||||
} else {
|
||||
$categories = collect([
|
||||
'' => trans('general.all_type', ['type' => trans_choice('general.categories', 2)]),
|
||||
'*' => trans('general.all_type', ['type' => trans_choice('general.categories', 2)]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Notifications
|
||||
public function compose(View $view)
|
||||
{
|
||||
// No need to add suggestions in console
|
||||
if (app()->runningInConsole() || !env('APP_INSTALLED') || !user()) {
|
||||
if (app()->runningInConsole() || !config('app.installed') || !user()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ class Suggestions
|
||||
public function compose(View $view)
|
||||
{
|
||||
// No need to add suggestions in console
|
||||
if (app()->runningInConsole() || !env('APP_INSTALLED')) {
|
||||
if (app()->runningInConsole() || !config('app.installed')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -31,22 +31,18 @@ class Suggestions
|
||||
|
||||
if ($path) {
|
||||
$suggestions = $this->getSuggestions($path);
|
||||
|
||||
|
||||
if ($suggestions) {
|
||||
$suggestion_modules = $suggestions->modules;
|
||||
|
||||
|
||||
foreach ($suggestion_modules as $key => $module) {
|
||||
$installed = Module::where('company_id', session('company_id'))->where('alias', $module->alias)->first();
|
||||
|
||||
if ($installed) {
|
||||
unset($suggestion_modules[$key]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($suggestion_modules) {
|
||||
shuffle($suggestion_modules);
|
||||
|
||||
$modules[] = $suggestion_modules[0];
|
||||
$modules[] = $module;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\Permission;
|
||||
use Artisan;
|
||||
|
||||
class CreatePermission extends Job
|
||||
{
|
||||
@ -29,8 +28,6 @@ class CreatePermission extends Job
|
||||
{
|
||||
$permission = Permission::create($this->request->all());
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $permission;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\Role;
|
||||
use Artisan;
|
||||
|
||||
class CreateRole extends Job
|
||||
{
|
||||
@ -33,8 +32,6 @@ class CreateRole extends Job
|
||||
$role->permissions()->attach($this->request->get('permissions'));
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $role;
|
||||
}
|
||||
}
|
||||
|
@ -44,21 +44,23 @@ class CreateUser extends Job
|
||||
$user->permissions()->attach($this->request->get('permissions'));
|
||||
}
|
||||
|
||||
$user->roles()->attach($this->request->get('roles'));
|
||||
|
||||
$user->companies()->attach($this->request->get('companies'));
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
// Add User Dashboard
|
||||
foreach ($user->companies as $company) {
|
||||
Artisan::call('user:seed', [
|
||||
'user' => $user->id,
|
||||
'company' => $company->id,
|
||||
]);
|
||||
if ($this->request->has('roles')) {
|
||||
$user->roles()->attach($this->request->get('roles'));
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
if ($this->request->has('companies')) {
|
||||
$user->companies()->attach($this->request->get('companies'));
|
||||
}
|
||||
|
||||
// Add User Dashboard
|
||||
if (!empty($user->companies)) {
|
||||
foreach ($user->companies as $company) {
|
||||
Artisan::call('user:seed', [
|
||||
'user' => $user->id,
|
||||
'company' => $company->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use Artisan;
|
||||
|
||||
class DeletePermission extends Job
|
||||
{
|
||||
@ -28,8 +27,6 @@ class DeletePermission extends Job
|
||||
{
|
||||
$this->permission->delete();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use Artisan;
|
||||
|
||||
class DeleteRole extends Job
|
||||
{
|
||||
@ -28,7 +27,7 @@ class DeleteRole extends Job
|
||||
{
|
||||
$this->role->delete();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
$this->role->flushCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use Artisan;
|
||||
|
||||
class DeleteUser extends Job
|
||||
{
|
||||
@ -30,7 +29,7 @@ class DeleteUser extends Job
|
||||
|
||||
$this->user->delete();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
$this->user->flushCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\Permission;
|
||||
use Artisan;
|
||||
|
||||
class UpdatePermission extends Job
|
||||
{
|
||||
@ -33,8 +32,6 @@ class UpdatePermission extends Job
|
||||
{
|
||||
$this->permission->update($this->request->all());
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $this->permission;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\Role;
|
||||
use Artisan;
|
||||
|
||||
class UpdateRole extends Job
|
||||
{
|
||||
@ -37,8 +36,6 @@ class UpdateRole extends Job
|
||||
$this->role->permissions()->sync($this->request->get('permissions'));
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $this->role;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\User;
|
||||
use Artisan;
|
||||
|
||||
class UpdateUser extends Job
|
||||
{
|
||||
@ -58,8 +57,6 @@ class UpdateUser extends Job
|
||||
$this->user->companies()->sync($this->request->get('companies'));
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,6 @@ class CreateDocumentTransaction extends Job
|
||||
{
|
||||
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
|
||||
$total_amount = $this->model->amount;
|
||||
|
||||
$default_amount = (double) $this->request['amount'];
|
||||
|
||||
if ($this->model->currency_code == $this->request['currency_code']) {
|
||||
@ -103,7 +101,7 @@ class CreateDocumentTransaction extends Job
|
||||
$amount = (double) $convert_amount_model->getAmountConvertedFromDefault();
|
||||
}
|
||||
|
||||
$total_amount -= $this->model->paid;
|
||||
$total_amount = $this->model->amount - $this->model->paid;
|
||||
unset($this->model->reconciled);
|
||||
|
||||
// For amount cover integer
|
||||
@ -114,7 +112,7 @@ class CreateDocumentTransaction extends Job
|
||||
}
|
||||
|
||||
$amount_check = (int) ($amount * $multiplier);
|
||||
$total_amount_check = (int) (round($total_amount, $this->currency->precision) * $multiplier);
|
||||
$total_amount_check = (int) ($total_amount * $multiplier);
|
||||
|
||||
if ($amount_check > $total_amount_check) {
|
||||
$error_amount = $total_amount;
|
||||
|
@ -4,6 +4,7 @@ namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\Auth\Role;
|
||||
use App\Models\Common\Contact;
|
||||
|
||||
class CreateContact extends Job
|
||||
@ -48,11 +49,14 @@ class CreateContact extends Job
|
||||
$data = $this->request->all();
|
||||
$data['locale'] = setting('default.locale', 'en-GB');
|
||||
|
||||
$user = User::create($data);
|
||||
$user->roles()->attach(['3']);
|
||||
$user->companies()->attach([session('company_id')]);
|
||||
$customer_role = Role::all()->filter(function ($role) {
|
||||
return $role->hasPermission('read-client-portal');
|
||||
})->first();
|
||||
|
||||
$user = User::create($data);
|
||||
$user->roles()->attach($customer_role);
|
||||
$user->companies()->attach(session('company_id'));
|
||||
|
||||
// St user id to request
|
||||
$this->request['user_id'] = $user->id;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Common\Dashboard;
|
||||
use App\Models\Common\Widget;
|
||||
use App\Utilities\Widgets;
|
||||
|
||||
class CreateDashboard extends Job
|
||||
{
|
||||
@ -28,10 +30,14 @@ class CreateDashboard extends Job
|
||||
{
|
||||
$this->request['enabled'] = $this->request['enabled'] ?? 1;
|
||||
|
||||
$this->dashboard = Dashboard::create($this->request->all());
|
||||
$this->dashboard = Dashboard::create($this->request->only(['company_id', 'name', 'enabled']));
|
||||
|
||||
$this->attachToUser();
|
||||
|
||||
if ($this->request->has('with_widgets')) {
|
||||
$this->createWidgets();
|
||||
}
|
||||
|
||||
return $this->dashboard;
|
||||
}
|
||||
|
||||
@ -49,4 +55,24 @@ class CreateDashboard extends Job
|
||||
|
||||
$this->dashboard->users()->attach($user);
|
||||
}
|
||||
|
||||
protected function createWidgets()
|
||||
{
|
||||
$widgets = Widgets::getClasses(false);
|
||||
|
||||
$sort = 1;
|
||||
|
||||
foreach ($widgets as $class => $name) {
|
||||
Widget::create([
|
||||
'company_id' => $this->dashboard->company_id,
|
||||
'dashboard_id' => $this->dashboard->id,
|
||||
'class' => $class,
|
||||
'name' => $name,
|
||||
'sort' => $sort,
|
||||
'settings' => (new $class())->getDefaultSettings(),
|
||||
]);
|
||||
|
||||
$sort++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Jobs\Auth\DeleteUser;
|
||||
use App\Traits\Contacts;
|
||||
|
||||
class DeleteContact extends Job
|
||||
@ -30,6 +31,10 @@ class DeleteContact extends Job
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
if ($user = $this->contact->user) {
|
||||
$this->dispatch(new DeleteUser($user));
|
||||
}
|
||||
|
||||
$this->contact->delete();
|
||||
|
||||
return true;
|
||||
@ -55,7 +60,7 @@ class DeleteContact extends Job
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
if (in_array($this->contact->type, $this->getCustomerTypes())) {
|
||||
if ($this->isCustomer()) {
|
||||
$rels['invoices'] = 'invoices';
|
||||
} else {
|
||||
$rels['bills'] = 'bills';
|
||||
|
@ -4,7 +4,6 @@ namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Traits\Users;
|
||||
use Artisan;
|
||||
|
||||
class DeleteDashboard extends Job
|
||||
{
|
||||
@ -35,8 +34,6 @@ class DeleteDashboard extends Job
|
||||
|
||||
$this->dashboard->delete();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,11 @@ class AddAdminItems
|
||||
if ($dashboards->count() > 1) {
|
||||
$menu->dropdown(trim(trans_choice('general.dashboards', 2)), function ($sub) use ($user, $attr, $dashboards) {
|
||||
foreach ($dashboards as $key => $dashboard) {
|
||||
$path = (session('dashboard_id') == $dashboard->id) ? '/' : '/?dashboard_id=' . $dashboard->id;
|
||||
|
||||
$sub->url($path, $dashboard->name, $key, $attr);
|
||||
if (session('dashboard_id') != $dashboard->id) {
|
||||
$sub->route('dashboards.switch', $dashboard->name, ['dashboard' => $dashboard->id], $key, $attr);
|
||||
} else {
|
||||
$sub->url('/', $dashboard->name, $key, $attr);
|
||||
}
|
||||
}
|
||||
}, 1, [
|
||||
'url' => '/',
|
||||
|
@ -26,7 +26,7 @@ class Version207 extends Listener
|
||||
|
||||
// Update .env file
|
||||
Installer::updateEnv([
|
||||
'MAIL_MAILER' => env('MAIL_DRIVER'),
|
||||
'MAIL_MAILER' => env('MAIL_DRIVER', config('mail.default')),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use App\Traits\Tenants;
|
||||
use Laratrust\Models\LaratrustPermission;
|
||||
use Laratrust\Traits\LaratrustPermissionTrait;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
@ -9,10 +10,12 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
class Permission extends LaratrustPermission
|
||||
{
|
||||
use LaratrustPermissionTrait, SearchString, Sortable;
|
||||
use LaratrustPermissionTrait, SearchString, Sortable, Tenants;
|
||||
|
||||
protected $table = 'permissions';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use App\Traits\Tenants;
|
||||
use Laratrust\Models\LaratrustRole;
|
||||
use Laratrust\Traits\LaratrustRoleTrait;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
@ -9,10 +10,12 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
class Role extends LaratrustRole
|
||||
{
|
||||
use LaratrustRoleTrait, SearchString, Sortable;
|
||||
use LaratrustRoleTrait, SearchString, Sortable, Tenants;
|
||||
|
||||
protected $table = 'roles';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use App\Traits\Tenants;
|
||||
use App\Notifications\Auth\Reset;
|
||||
use App\Traits\Media;
|
||||
use Date;
|
||||
@ -15,10 +16,12 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use LaratrustUserTrait, Notifiable, SearchString, SoftDeletes, Sortable, Media;
|
||||
use LaratrustUserTrait, Notifiable, SearchString, SoftDeletes, Sortable, Media, Tenants;
|
||||
|
||||
protected $table = 'users';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Models\Common;
|
||||
|
||||
use App\Traits\Media;
|
||||
use App\Traits\Tenants;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
@ -10,10 +11,12 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
class Company extends Eloquent
|
||||
{
|
||||
use Media, SearchString, SoftDeletes, Sortable;
|
||||
use Media, SearchString, SoftDeletes, Sortable, Tenants;
|
||||
|
||||
protected $table = 'companies';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
protected $fillable = ['domain', 'enabled'];
|
||||
|
@ -133,9 +133,9 @@ class Contact extends Model
|
||||
{
|
||||
$amount = 0;
|
||||
|
||||
$collection = in_array($this->type, $this->getCustomerTypes()) ? 'invoices' : 'bills';
|
||||
$collection = $this->isCustomer() ? 'invoices' : 'bills';
|
||||
|
||||
$this->$collection()->accrued()->notPaid()->each(function ($item) use (&$amount) {
|
||||
$this->$collection->whereNotIn('status', ['draft', 'cancelled', 'paid'])->each(function ($item) use (&$amount) {
|
||||
$unpaid = $item->amount - $item->paid;
|
||||
|
||||
$amount += $this->convertToDefault($unpaid, $item->currency_code, $item->currency_rate);
|
||||
|
@ -9,5 +9,7 @@ class Media extends BaseMedia
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
}
|
||||
|
@ -68,6 +68,50 @@ class Category extends Model
|
||||
return $query->whereIn($this->table . '.type', (array) $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only income.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeIncome($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'income');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only expense.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeExpense($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'expense');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only item.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeItem($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'item');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only other.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeOther($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'other');
|
||||
}
|
||||
|
||||
public function scopeName($query, $name)
|
||||
{
|
||||
return $query->where('name', '=', $name);
|
||||
@ -81,6 +125,6 @@ class Category extends Model
|
||||
*/
|
||||
public function scopeTransfer($query)
|
||||
{
|
||||
return $query->where('type', 'other')->pluck('id')->first();
|
||||
return $query->where($this->table . '.type', '=', 'other')->pluck('id')->first();
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,17 @@
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Scopes\Company;
|
||||
use App\Traits\Tenants;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
|
||||
class Setting extends Eloquent
|
||||
{
|
||||
use Tenants;
|
||||
|
||||
protected $table = 'settings';
|
||||
|
||||
protected $tenantable = true;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
|
@ -31,11 +31,11 @@ class App extends Provider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
if (env('APP_INSTALLED') && env('APP_DEBUG')) {
|
||||
if (config('app.installed') && config('app.debug')) {
|
||||
$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
|
||||
}
|
||||
|
||||
if (env('APP_ENV') !== 'production') {
|
||||
if (config('app.env') !== 'production') {
|
||||
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class ExpenseSummary extends Report
|
||||
|
||||
public function setData()
|
||||
{
|
||||
$transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
@ -41,7 +41,7 @@ class ExpenseSummary extends Report
|
||||
break;
|
||||
default:
|
||||
// Bills
|
||||
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
|
||||
$bills = $this->applyFilters(Bill::with('recurring', 'transactions')->accrued(), ['date_field' => 'billed_at'])->get();
|
||||
Recurring::reflect($bills, 'billed_at');
|
||||
$this->setTotals($bills, 'billed_at');
|
||||
|
||||
|
@ -16,8 +16,8 @@ class IncomeExpenseSummary extends Report
|
||||
|
||||
public function setData()
|
||||
{
|
||||
$income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$income_transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$expense_transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
@ -32,7 +32,7 @@ class IncomeExpenseSummary extends Report
|
||||
break;
|
||||
default:
|
||||
// Invoices
|
||||
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
$invoices = $this->applyFilters(Invoice::with('recurring', 'transactions')->accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
Recurring::reflect($invoices, 'invoiced_at');
|
||||
$this->setTotals($invoices, 'invoiced_at', true);
|
||||
|
||||
@ -42,7 +42,7 @@ class IncomeExpenseSummary extends Report
|
||||
$this->setTotals($revenues, 'paid_at', true);
|
||||
|
||||
// Bills
|
||||
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
|
||||
$bills = $this->applyFilters(Bill::with('recurring', 'transactions')->accrued(), ['date_field' => 'billed_at'])->get();
|
||||
Recurring::reflect($bills, 'bill', 'billed_at');
|
||||
$this->setTotals($bills, 'billed_at', true);
|
||||
|
||||
|
@ -30,7 +30,7 @@ class IncomeSummary extends Report
|
||||
|
||||
public function setData()
|
||||
{
|
||||
$transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
@ -41,7 +41,7 @@ class IncomeSummary extends Report
|
||||
break;
|
||||
default:
|
||||
// Invoices
|
||||
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
$invoices = $this->applyFilters(Invoice::with('recurring', 'transactions')->accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
Recurring::reflect($invoices, 'invoiced_at');
|
||||
$this->setTotals($invoices, 'invoiced_at');
|
||||
|
||||
|
@ -16,11 +16,6 @@ class ProfitLoss extends Report
|
||||
|
||||
public $icon = 'fa fa-heart';
|
||||
|
||||
public $indents = [
|
||||
'table_header' => '0px',
|
||||
'table_rows' => '48px',
|
||||
];
|
||||
|
||||
public function setViews()
|
||||
{
|
||||
parent::setViews();
|
||||
@ -40,40 +35,40 @@ class ProfitLoss extends Report
|
||||
|
||||
public function setData()
|
||||
{
|
||||
$income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$income_transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$expense_transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
// Revenues
|
||||
$revenues = $income_transactions->get();
|
||||
$this->setTotals($revenues, 'paid_at', true, $this->tables['income']);
|
||||
$this->setTotals($revenues, 'paid_at', true, $this->tables['income'], false);
|
||||
|
||||
// Payments
|
||||
$payments = $expense_transactions->get();
|
||||
$this->setTotals($payments, 'paid_at', true, $this->tables['expense']);
|
||||
$this->setTotals($payments, 'paid_at', true, $this->tables['expense'], false);
|
||||
|
||||
break;
|
||||
default:
|
||||
// Invoices
|
||||
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
$invoices = $this->applyFilters(Invoice::with('recurring', 'totals', 'transactions')->accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
Recurring::reflect($invoices, 'invoiced_at');
|
||||
$this->setTotals($invoices, 'invoiced_at', true, $this->tables['income']);
|
||||
$this->setTotals($invoices, 'invoiced_at', true, $this->tables['income'], false);
|
||||
|
||||
// Revenues
|
||||
$revenues = $income_transactions->isNotDocument()->get();
|
||||
Recurring::reflect($revenues, 'paid_at');
|
||||
$this->setTotals($revenues, 'paid_at', true, $this->tables['income']);
|
||||
$this->setTotals($revenues, 'paid_at', true, $this->tables['income'], false);
|
||||
|
||||
// Bills
|
||||
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
|
||||
$bills = $this->applyFilters(Bill::with('recurring', 'totals', 'transactions')->accrued(), ['date_field' => 'billed_at'])->get();
|
||||
Recurring::reflect($bills, 'bill', 'billed_at');
|
||||
$this->setTotals($bills, 'billed_at', true, $this->tables['expense']);
|
||||
$this->setTotals($bills, 'billed_at', true, $this->tables['expense'], false);
|
||||
|
||||
// Payments
|
||||
$payments = $expense_transactions->isNotDocument()->get();
|
||||
Recurring::reflect($payments, 'paid_at');
|
||||
$this->setTotals($payments, 'paid_at', true, $this->tables['expense']);
|
||||
$this->setTotals($payments, 'paid_at', true, $this->tables['expense'], false);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -21,11 +21,6 @@ class TaxSummary extends Report
|
||||
|
||||
public $icon = 'fa fa-percent';
|
||||
|
||||
public $indents = [
|
||||
'table_header' => '0px',
|
||||
'table_rows' => '48px',
|
||||
];
|
||||
|
||||
public function setViews()
|
||||
{
|
||||
parent::setViews();
|
||||
@ -47,22 +42,22 @@ class TaxSummary extends Report
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
// Invoice Payments
|
||||
$invoices = $this->applyFilters(Transaction::with(['invoice', 'invoice.totals'])->type('income')->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
||||
$invoices = $this->applyFilters(Transaction::with('recurring', 'invoice', 'invoice.totals')->income()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
||||
$this->setTotals($invoices, 'paid_at');
|
||||
|
||||
// Bill Payments
|
||||
$bills = $this->applyFilters(Transaction::with(['bill', 'bill.totals'])->type('expense')->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
||||
$bills = $this->applyFilters(Transaction::with('recurring', 'bill', 'bill.totals')->expense()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
||||
$this->setTotals($bills, 'paid_at');
|
||||
|
||||
break;
|
||||
default:
|
||||
// Invoices
|
||||
$invoices = $this->applyFilters(Invoice::accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
$invoices = $this->applyFilters(Invoice::with('recurring', 'totals', 'transactions')->accrued(), ['date_field' => 'invoiced_at'])->get();
|
||||
Recurring::reflect($invoices, 'invoiced_at');
|
||||
$this->setTotals($invoices, 'invoiced_at');
|
||||
|
||||
// Bills
|
||||
$bills = $this->applyFilters(Bill::accrued(), ['date_field' => 'billed_at'])->get();
|
||||
$bills = $this->applyFilters(Bill::with('recurring', 'totals', 'transactions')->accrued(), ['date_field' => 'billed_at'])->get();
|
||||
Recurring::reflect($bills, 'billed_at');
|
||||
$this->setTotals($bills, 'billed_at');
|
||||
|
||||
@ -70,7 +65,7 @@ class TaxSummary extends Report
|
||||
}
|
||||
}
|
||||
|
||||
public function setTotals($items, $date_field, $check_type = false, $table = 'default')
|
||||
public function setTotals($items, $date_field, $check_type = false, $table = 'default', $with_tax = true)
|
||||
{
|
||||
foreach ($items as $item) {
|
||||
// Make groups extensible
|
||||
|
@ -17,13 +17,16 @@ class Company implements Scope
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model)
|
||||
{
|
||||
if (method_exists($model, 'isNotTenantable') && $model->isNotTenantable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$table = $model->getTable();
|
||||
|
||||
// Skip for specific tables
|
||||
$skip_tables = [
|
||||
'companies', 'jobs', 'firewall_ips', 'firewall_logs', 'media', 'mediables', 'migrations', 'notifications',
|
||||
'permissions', 'roles', 'role_companies', 'role_permissions', 'sessions', 'users', 'user_companies',
|
||||
'user_dashboards', 'user_permissions', 'user_roles',
|
||||
'jobs', 'firewall_ips', 'firewall_logs', 'media', 'mediables', 'migrations', 'notifications', 'role_companies',
|
||||
'role_permissions', 'sessions', 'user_companies', 'user_dashboards', 'user_permissions', 'user_roles',
|
||||
];
|
||||
|
||||
if (in_array($table, $skip_tables)) {
|
||||
|
@ -4,31 +4,44 @@ namespace App\Traits;
|
||||
|
||||
trait Contacts
|
||||
{
|
||||
public function isCustomer()
|
||||
{
|
||||
return in_array($this->type, $this->getCustomerTypes());
|
||||
}
|
||||
|
||||
public function isVendor()
|
||||
{
|
||||
return in_array($this->type, $this->getVendorTypes());
|
||||
}
|
||||
|
||||
public function getCustomerTypes($return = 'array')
|
||||
{
|
||||
$types = (string) setting('contact.type.customer', 'customer');
|
||||
|
||||
return ($return == 'array') ? explode(',', $types) : $types;
|
||||
return $this->getContactTypes('customer', $return);
|
||||
}
|
||||
|
||||
public function getVendorTypes($return = 'array')
|
||||
{
|
||||
$types = (string) setting('contact.type.vendor', 'vendor');
|
||||
return $this->getContactTypes('vendor', $return);
|
||||
}
|
||||
|
||||
public function getContactTypes($index, $return = 'array')
|
||||
{
|
||||
$types = (string) setting('contact.type.' . $index, $index);
|
||||
|
||||
return ($return == 'array') ? explode(',', $types) : $types;
|
||||
}
|
||||
|
||||
public function addCustomerType($new_type)
|
||||
{
|
||||
$this->addType($new_type, 'customer');
|
||||
$this->addContactType($new_type, 'customer');
|
||||
}
|
||||
|
||||
public function addVendorType($new_type)
|
||||
{
|
||||
$this->addType($new_type, 'vendor');
|
||||
$this->addContactType($new_type, 'vendor');
|
||||
}
|
||||
|
||||
public function addType($new_type, $index)
|
||||
public function addContactType($new_type, $index)
|
||||
{
|
||||
$types = explode(',', setting('contact.type.' . $index, $index));
|
||||
|
||||
|
@ -17,7 +17,7 @@ trait DateTime
|
||||
$default = 'd M Y';
|
||||
|
||||
// Make sure it's installed
|
||||
if (!env('APP_INSTALLED') && (env('APP_ENV') !== 'testing')) {
|
||||
if (!config('app.installed') && (config('app.env') !== 'testing')) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,10 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\Module\Module as Model;
|
||||
use App\Models\Module\Module;
|
||||
use App\Traits\SiteApi;
|
||||
use App\Utilities\Console;
|
||||
use App\Utilities\Info;
|
||||
use Artisan;
|
||||
use Cache;
|
||||
use Date;
|
||||
use File;
|
||||
@ -36,10 +34,11 @@ trait Modules
|
||||
}
|
||||
|
||||
// Get All Modules
|
||||
public function getModules()
|
||||
public function getModules($data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$items = Cache::get('apps.items');
|
||||
$key = 'apps.items.page.' . $this->getPageNumber($data);
|
||||
|
||||
$items = Cache::get($key);
|
||||
|
||||
if (!empty($items)) {
|
||||
return $items;
|
||||
@ -47,7 +46,7 @@ trait Modules
|
||||
|
||||
$items = static::getResponseData('GET', 'apps/items');
|
||||
|
||||
Cache::put('apps.items', $items, Date::now()->addHour());
|
||||
Cache::put($key, $items, Date::now()->addHour());
|
||||
|
||||
return $items;
|
||||
}
|
||||
@ -62,8 +61,9 @@ trait Modules
|
||||
|
||||
public function getDocumentation($alias)
|
||||
{
|
||||
// Get data from cache
|
||||
$documentation = Cache::get('apps.docs.' . $alias);
|
||||
$key = 'apps.docs.' . $alias;
|
||||
|
||||
$documentation = Cache::get($key);
|
||||
|
||||
if (!empty($documentation)) {
|
||||
return $documentation;
|
||||
@ -71,15 +71,16 @@ trait Modules
|
||||
|
||||
$documentation = static::getResponseData('GET', 'apps/docs/' . $alias);
|
||||
|
||||
Cache::put('apps.docs.' . $alias, $documentation, Date::now()->addHour());
|
||||
Cache::put($key, $documentation, Date::now()->addHour());
|
||||
|
||||
return $documentation;
|
||||
}
|
||||
|
||||
public function getModuleReviews($alias, $data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$reviews = Cache::get('apps.' . $alias . '.reviews');
|
||||
$key = 'apps.' . $alias . '.reviews.page.'. $this->getPageNumber($data);
|
||||
|
||||
$reviews = Cache::get($key);
|
||||
|
||||
if (!empty($reviews)) {
|
||||
return $reviews;
|
||||
@ -87,15 +88,16 @@ trait Modules
|
||||
|
||||
$reviews = static::getResponseData('GET', 'apps/' . $alias . '/reviews', $data);
|
||||
|
||||
Cache::put('apps.' . $alias . '.reviews', $reviews, Date::now()->addHour());
|
||||
Cache::put($key, $reviews, Date::now()->addHour());
|
||||
|
||||
return $reviews;
|
||||
}
|
||||
|
||||
public function getCategories()
|
||||
public function getCategories($data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$categories = Cache::get('apps.categories');
|
||||
$key = 'apps.categories.page.' . $this->getPageNumber($data);
|
||||
|
||||
$categories = Cache::get($key);
|
||||
|
||||
if (!empty($categories)) {
|
||||
return $categories;
|
||||
@ -103,15 +105,16 @@ trait Modules
|
||||
|
||||
$categories = static::getResponseData('GET', 'apps/categories');
|
||||
|
||||
Cache::put('apps.categories', $categories, Date::now()->addHour());
|
||||
Cache::put($key, $categories, Date::now()->addHour());
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public function getModulesByCategory($alias, $data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$category = Cache::get('apps.categories.' . $alias);
|
||||
$key = 'apps.categories.' . $alias . '.page.' . $this->getPageNumber($data);
|
||||
|
||||
$category = Cache::get($key);
|
||||
|
||||
if (!empty($category)) {
|
||||
return $category;
|
||||
@ -119,15 +122,16 @@ trait Modules
|
||||
|
||||
$category = static::getResponseData('GET', 'apps/categories/' . $alias, $data);
|
||||
|
||||
Cache::put('apps.categories.' . $alias, $category, Date::now()->addHour());
|
||||
Cache::put($key, $category, Date::now()->addHour());
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
public function getVendors()
|
||||
public function getVendors($data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$vendors = Cache::get('apps.vendors');
|
||||
$key = 'apps.vendors.page.' . $this->getPageNumber($data);
|
||||
|
||||
$vendors = Cache::get($key);
|
||||
|
||||
if (!empty($vendors)) {
|
||||
return $vendors;
|
||||
@ -135,15 +139,16 @@ trait Modules
|
||||
|
||||
$vendors = static::getResponseData('GET', 'apps/vendors');
|
||||
|
||||
Cache::put('apps.vendors', $vendors, Date::now()->addHour());
|
||||
Cache::put($key, $vendors, Date::now()->addHour());
|
||||
|
||||
return $vendors;
|
||||
}
|
||||
|
||||
public function getModulesByVendor($alias, $data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$vendor = Cache::get('apps.vendors.' . $alias);
|
||||
$key = 'apps.vendors.' . $alias . '.page.' . $this->getPageNumber($data);
|
||||
|
||||
$vendor = Cache::get($key);
|
||||
|
||||
if (!empty($vendor)) {
|
||||
return $vendor;
|
||||
@ -151,7 +156,7 @@ trait Modules
|
||||
|
||||
$vendor = static::getResponseData('GET', 'apps/vendors/' . $alias, $data);
|
||||
|
||||
Cache::put('apps.vendors.' . $alias, $vendor, Date::now()->addHour());
|
||||
Cache::put($key, $vendor, Date::now()->addHour());
|
||||
|
||||
return $vendor;
|
||||
}
|
||||
@ -161,44 +166,38 @@ trait Modules
|
||||
return static::getResponseData('GET', 'apps/my', $data);
|
||||
}
|
||||
|
||||
public function getInstalledModules($data = [])
|
||||
public function getInstalledModules()
|
||||
{
|
||||
$company_id = session('company_id');
|
||||
$key = 'apps.installed.' . session('company_id');
|
||||
|
||||
$cache = 'installed.' . $company_id . '.module';
|
||||
|
||||
$installed = Cache::get($cache);
|
||||
|
||||
if ($installed) {
|
||||
if ($installed = Cache::get($key)) {
|
||||
return $installed;
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$modules = Module::all();
|
||||
$installed_modules = Model::where('company_id', '=', session('company_id'))->pluck('enabled', 'alias')->toArray();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if (!array_key_exists($module->alias, $installed_modules)) {
|
||||
continue;
|
||||
Module::all()->each(function($module) use (&$installed) {
|
||||
if (!$this->moduleExists($module->alias)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->getModule($module->alias);
|
||||
|
||||
if ($result) {
|
||||
$installed[] = $result;
|
||||
if (!$result = $this->getModule($module->alias)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Cache::put($cache, $installed, Date::now()->addHour(6));
|
||||
$installed[] = $result;
|
||||
});
|
||||
|
||||
Cache::put($key, $installed, Date::now()->addHour(6));
|
||||
|
||||
return $installed;
|
||||
}
|
||||
|
||||
public function getPreSaleModules($data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$pre_sale = Cache::get('apps.pre_sale');
|
||||
$key = 'apps.pre_sale.page.' . $this->getPageNumber($data);
|
||||
|
||||
$pre_sale = Cache::get($key);
|
||||
|
||||
if (!empty($pre_sale)) {
|
||||
return $pre_sale;
|
||||
@ -206,15 +205,16 @@ trait Modules
|
||||
|
||||
$pre_sale = static::getResponseData('GET', 'apps/pre_sale', $data);
|
||||
|
||||
Cache::put('apps.pre_sale', $pre_sale, Date::now()->addHour());
|
||||
Cache::put($key, $pre_sale, Date::now()->addHour());
|
||||
|
||||
return $pre_sale;
|
||||
}
|
||||
|
||||
public function getPaidModules($data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$paid = Cache::get('apps.paid');
|
||||
$key = 'apps.paid.page.' . $this->getPageNumber($data);
|
||||
|
||||
$paid = Cache::get($key);
|
||||
|
||||
if (!empty($paid)) {
|
||||
return $paid;
|
||||
@ -222,15 +222,16 @@ trait Modules
|
||||
|
||||
$paid = static::getResponseData('GET', 'apps/paid', $data);
|
||||
|
||||
Cache::put('apps.paid', $paid, Date::now()->addHour());
|
||||
Cache::put($key, $paid, Date::now()->addHour());
|
||||
|
||||
return $paid;
|
||||
}
|
||||
|
||||
public function getNewModules($data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$new = Cache::get('apps.new');
|
||||
$key = 'apps.new.page.' . $this->getPageNumber($data);
|
||||
|
||||
$new = Cache::get($key);
|
||||
|
||||
if (!empty($new)) {
|
||||
return $new;
|
||||
@ -238,15 +239,16 @@ trait Modules
|
||||
|
||||
$new = static::getResponseData('GET', 'apps/new', $data);
|
||||
|
||||
Cache::put('apps.new', $new, Date::now()->addHour());
|
||||
Cache::put($key, $new, Date::now()->addHour());
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function getFreeModules($data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$free = Cache::get('apps.free');
|
||||
$key = 'apps.free.page.' . $this->getPageNumber($data);
|
||||
|
||||
$free = Cache::get($key);
|
||||
|
||||
if (!empty($free)) {
|
||||
return $free;
|
||||
@ -254,15 +256,16 @@ trait Modules
|
||||
|
||||
$free = static::getResponseData('GET', 'apps/free', $data);
|
||||
|
||||
Cache::put('apps.free', $free, Date::now()->addHour());
|
||||
Cache::put($key, $free, Date::now()->addHour());
|
||||
|
||||
return $free;
|
||||
}
|
||||
|
||||
public function getFeaturedModules($data = [])
|
||||
{
|
||||
// Get data from cache
|
||||
$featured = Cache::get('apps.featured');
|
||||
$key = 'apps.featured.page.' . $this->getPageNumber($data);
|
||||
|
||||
$featured = Cache::get($key);
|
||||
|
||||
if (!empty($featured)) {
|
||||
return $featured;
|
||||
@ -270,7 +273,7 @@ trait Modules
|
||||
|
||||
$featured = static::getResponseData('GET', 'apps/featured', $data);
|
||||
|
||||
Cache::put('apps.featured', $featured, Date::now()->addHour());
|
||||
Cache::put($key, $featured, Date::now()->addHour());
|
||||
|
||||
return $featured;
|
||||
}
|
||||
@ -293,11 +296,20 @@ trait Modules
|
||||
|
||||
public function downloadModule($path)
|
||||
{
|
||||
if (empty($path)) {
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'message' => trans('modules.errors.download', ['module' => '']),
|
||||
'data' => null,
|
||||
];
|
||||
}
|
||||
|
||||
if (!$response = static::getResponse('GET', $path)) {
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'message' => null,
|
||||
'message' => trans('modules.errors.download', ['module' => '']),
|
||||
'data' => null,
|
||||
];
|
||||
}
|
||||
@ -321,7 +333,7 @@ trait Modules
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'message' => null,
|
||||
'message' => trans('modules.errors.download', ['module' => '']),
|
||||
'data' => null,
|
||||
];
|
||||
}
|
||||
@ -338,6 +350,15 @@ trait Modules
|
||||
|
||||
public function unzipModule($path)
|
||||
{
|
||||
if (empty($path)) {
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'message' => trans('modules.errors.unzip', ['module' => '']),
|
||||
'data' => null,
|
||||
];
|
||||
}
|
||||
|
||||
$temp_path = storage_path('app/temp') . '/' . $path;
|
||||
|
||||
$file = $temp_path . '/upload.zip';
|
||||
@ -349,7 +370,7 @@ trait Modules
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'message' => null,
|
||||
'message' => trans('modules.errors.unzip', ['module' => '']),
|
||||
'data' => null,
|
||||
];
|
||||
}
|
||||
@ -373,9 +394,18 @@ trait Modules
|
||||
|
||||
public function installModule($path)
|
||||
{
|
||||
if (empty($path)) {
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'message' => trans('modules.errors.finish', ['module' => '']),
|
||||
'data' => null,
|
||||
];
|
||||
}
|
||||
|
||||
$temp_path = storage_path('app/temp') . '/' . $path;
|
||||
|
||||
$modules_path = base_path() . '/modules';
|
||||
$modules_path = config('module.paths.modules');
|
||||
|
||||
// Create modules directory
|
||||
if (!File::isDirectory($modules_path)) {
|
||||
@ -404,13 +434,24 @@ trait Modules
|
||||
$company_id = session('company_id');
|
||||
$locale = app()->getLocale();
|
||||
|
||||
Cache::forget('installed.' . $company_id . '.module');
|
||||
$this->clearModulesCache();
|
||||
|
||||
Console::run("module:install {$module->alias} {$company_id} {$locale}");
|
||||
$command = "module:install {$module->alias} {$company_id} {$locale}";
|
||||
|
||||
if (true !== $result = Console::run($command)) {
|
||||
$message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $module->alias]);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => true,
|
||||
'message' => $message,
|
||||
'data' => null,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'redirect' => url('apps/' . $module->alias),
|
||||
'redirect' => route('apps.app.show', $module->alias),
|
||||
'error' => false,
|
||||
'message' => null,
|
||||
'data' => $data,
|
||||
@ -427,12 +468,9 @@ trait Modules
|
||||
'version' => $module->get('version'),
|
||||
];
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
$module->delete();
|
||||
|
||||
// Cache Data clear
|
||||
File::deleteDirectory(storage_path('framework/cache/data'));
|
||||
$this->clearModulesCache();
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
@ -454,7 +492,7 @@ trait Modules
|
||||
|
||||
$module->enable();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
$this->clearModulesCache();
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
@ -476,7 +514,7 @@ trait Modules
|
||||
|
||||
$module->disable();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
$this->clearModulesCache($alias);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
@ -488,19 +526,31 @@ trait Modules
|
||||
|
||||
public function moduleExists($alias)
|
||||
{
|
||||
$status = false;
|
||||
|
||||
if (module($alias) instanceof \Akaunting\Module\Module) {
|
||||
$status = true;
|
||||
if (!module($alias) instanceof \Akaunting\Module\Module) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $status;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function moduleEnabled($alias)
|
||||
{
|
||||
if (!$this->moduleExists($alias)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Module::alias($alias)->enabled()->first()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function loadSuggestions()
|
||||
{
|
||||
// Get data from cache
|
||||
$data = Cache::get('suggestions');
|
||||
$key = 'apps.suggestions';
|
||||
|
||||
$data = Cache::get($key);
|
||||
|
||||
if (!empty($data)) {
|
||||
return $data;
|
||||
@ -516,15 +566,16 @@ trait Modules
|
||||
$data[$suggestion->path] = $suggestion;
|
||||
}
|
||||
|
||||
Cache::put('suggestions', $data, Date::now()->addHour(6));
|
||||
Cache::put($key, $data, Date::now()->addHour(6));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function loadNotifications()
|
||||
{
|
||||
// Get data from cache
|
||||
$data = Cache::get('notifications');
|
||||
$key = 'apps.notifications';
|
||||
|
||||
$data = Cache::get($key);
|
||||
|
||||
if (!empty($data)) {
|
||||
return $data;
|
||||
@ -540,15 +591,16 @@ trait Modules
|
||||
$data[$notification->path][] = $notification;
|
||||
}
|
||||
|
||||
Cache::put('notifications', $data, Date::now()->addHour(6));
|
||||
Cache::put($key, $data, Date::now()->addHour(6));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getSuggestions($path)
|
||||
{
|
||||
// Get data from cache
|
||||
$data = Cache::get('suggestions');
|
||||
$key = 'apps.suggestions';
|
||||
|
||||
$data = Cache::get($key);
|
||||
|
||||
if (empty($data)) {
|
||||
$data = $this->loadSuggestions();
|
||||
@ -563,8 +615,9 @@ trait Modules
|
||||
|
||||
public function getNotifications($path)
|
||||
{
|
||||
// Get data from cache
|
||||
$data = Cache::get('notifications');
|
||||
$key = 'apps.notifications';
|
||||
|
||||
$data = Cache::get($key);
|
||||
|
||||
if (empty($data)) {
|
||||
$data = $this->loadNotifications();
|
||||
@ -576,4 +629,24 @@ trait Modules
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getPageNumber($data = [])
|
||||
{
|
||||
if (empty($data['query']) || empty($data['query']['page'])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return $data['query']['page'];
|
||||
}
|
||||
|
||||
public function clearModulesCache()
|
||||
{
|
||||
if (config('module.cache.enabled')) {
|
||||
Cache::forget(config('module.cache.key'));
|
||||
}
|
||||
|
||||
Cache::forget('apps.notifications');
|
||||
Cache::forget('apps.suggestions');
|
||||
Cache::forget('apps.installed.' . session('company_id'));
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ trait Omnipay
|
||||
public function purchase($invoice, $request, $extra_options = [])
|
||||
{
|
||||
$default_options = [
|
||||
'amount' => $invoice->amount,
|
||||
'amount' => $invoice->amount - $invoice->paid,
|
||||
'currency' => $invoice->currency_code,
|
||||
'transactionId' => $invoice->id,
|
||||
'returnUrl' => $this->getReturnUrl($invoice),
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Utilities\Info;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
@ -21,6 +22,7 @@ trait SiteApi
|
||||
'Referer' => app()->runningInConsole() ? config('app.url') : url('/'),
|
||||
'Akaunting' => version('short'),
|
||||
'Language' => language()->getShortCode(),
|
||||
'Information' => json_encode(Info::all()),
|
||||
];
|
||||
|
||||
$data = array_merge([
|
||||
|
16
app/Traits/Tenants.php
Normal file
16
app/Traits/Tenants.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait Tenants
|
||||
{
|
||||
public function isTenantable()
|
||||
{
|
||||
return (isset($this->tenantable) && ($this->tenantable === true));
|
||||
}
|
||||
|
||||
public function isNotTenantable()
|
||||
{
|
||||
return !$this->isTenantable();
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
use Illuminate\Support\ProcessUtils;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
@ -11,6 +12,8 @@ class Console
|
||||
{
|
||||
$command = static::formatCommandString($string);
|
||||
|
||||
logger('Console command:: ' . $command);
|
||||
|
||||
$process = Process::fromShellCommandline($command, base_path());
|
||||
$process->setTimeout($timeout);
|
||||
|
||||
@ -22,19 +25,21 @@ class Console
|
||||
|
||||
$output = $all_output ? $process->getOutput() : $process->getErrorOutput();
|
||||
|
||||
logger($output);
|
||||
logger('Console output:: ' . $output);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function getPhpBinary()
|
||||
{
|
||||
return (new PhpExecutableFinder)->find(false) ?? 'php';
|
||||
$bin = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
|
||||
|
||||
return !empty($bin) ? $bin : 'php';
|
||||
}
|
||||
|
||||
public static function getArtisanBinary()
|
||||
{
|
||||
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
|
||||
return defined('ARTISAN_BINARY') ? ProcessUtils::escapeArgument(ARTISAN_BINARY) : 'artisan';
|
||||
}
|
||||
|
||||
public static function formatCommandString($string)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user