improved tenant identification
This commit is contained in:
@@ -116,9 +116,9 @@ trait Import
|
||||
public function getAccountIdFromCurrency($row)
|
||||
{
|
||||
return Account::firstOrCreate([
|
||||
'company_id' => company_id(),
|
||||
'currency_code' => $row['currency_code'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'name' => !empty($row['account_name']) ? $row['account_name'] : $row['currency_code'],
|
||||
'number' => !empty($row['account_number']) ? $row['account_number'] : rand(1, 10000),
|
||||
'opening_balance' => !empty($row['opening_balance']) ? $row['opening_balance'] : 0,
|
||||
@@ -129,9 +129,9 @@ trait Import
|
||||
public function getAccountIdFromName($row)
|
||||
{
|
||||
return Account::firstOrCreate([
|
||||
'company_id' => company_id(),
|
||||
'name' => $row['account_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'number' => !empty($row['account_number']) ? $row['account_number'] : rand(1, 10000),
|
||||
'currency_code' => !empty($row['currency_code']) ? $row['currency_code'] : setting('default.currency'),
|
||||
'opening_balance' => !empty($row['opening_balance']) ? $row['opening_balance'] : 0,
|
||||
@@ -142,9 +142,9 @@ trait Import
|
||||
public function getAccountIdFromNumber($row)
|
||||
{
|
||||
return Account::firstOrCreate([
|
||||
'company_id' => company_id(),
|
||||
'number' => $row['account_number'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'name' => !empty($row['account_name']) ? $row['account_name'] : $row['account_number'],
|
||||
'currency_code' => !empty($row['currency_code']) ? $row['currency_code'] : setting('default.currency'),
|
||||
'opening_balance' => !empty($row['opening_balance']) ? $row['opening_balance'] : 0,
|
||||
@@ -155,9 +155,9 @@ trait Import
|
||||
public function getCategoryIdFromName($row, $type)
|
||||
{
|
||||
return Category::firstOrCreate([
|
||||
'company_id' => company_id(),
|
||||
'name' => $row['category_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'color' => !empty($row['category_color']) ? $row['category_color'] : '#' . dechex(rand(0x000000, 0xFFFFFF)),
|
||||
'enabled' => 1,
|
||||
@@ -167,9 +167,9 @@ trait Import
|
||||
public function getContactIdFromEmail($row, $type)
|
||||
{
|
||||
return Contact::firstOrCreate([
|
||||
'company_id' => company_id(),
|
||||
'email' => $row['contact_email'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'name' => !empty($row['contact_name']) ? $row['contact_name'] : $row['contact_email'],
|
||||
'currency_code' => !empty($row['contact_currency']) ? $row['contact_currency'] : setting('default.currency'),
|
||||
@@ -180,9 +180,9 @@ trait Import
|
||||
public function getContactIdFromName($row, $type)
|
||||
{
|
||||
return Contact::firstOrCreate([
|
||||
'company_id' => company_id(),
|
||||
'name' => $row['contact_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'currency_code' => !empty($row['contact_currency']) ? $row['contact_currency'] : setting('default.currency'),
|
||||
'enabled' => 1,
|
||||
@@ -192,9 +192,9 @@ trait Import
|
||||
public function getItemIdFromName($row)
|
||||
{
|
||||
return Item::firstOrCreate([
|
||||
'company_id' => company_id(),
|
||||
'name' => $row['item_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'sale_price' => !empty($row['sale_price']) ? $row['sale_price'] : (!empty($row['price']) ? $row['price'] : 0),
|
||||
'purchase_price' => !empty($row['purchase_price']) ? $row['purchase_price'] : (!empty($row['price']) ? $row['price'] : 0),
|
||||
'enabled' => 1,
|
||||
@@ -204,9 +204,9 @@ trait Import
|
||||
public function getTaxIdFromRate($row, $type = 'normal')
|
||||
{
|
||||
return Tax::firstOrCreate([
|
||||
'company_id' => company_id(),
|
||||
'rate' => $row['tax_rate'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'name' => !empty($row['tax_name']) ? $row['tax_name'] : $row['tax_rate'],
|
||||
'enabled' => 1,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Traits;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Bus\Dispatcher;
|
||||
use Throwable;
|
||||
|
||||
trait Jobs
|
||||
@@ -17,7 +18,32 @@ trait Jobs
|
||||
{
|
||||
$function = $this->getDispatchFunction();
|
||||
|
||||
return $function($job);
|
||||
return $this->$function($job);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a job to its appropriate handler.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatchQueue($job)
|
||||
{
|
||||
return app(Dispatcher::class)->dispatch($job);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a command to its appropriate handler in the current process.
|
||||
*
|
||||
* Queuable jobs will be dispatched to the "sync" queue.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $handler
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatchSync($job, $handler = null)
|
||||
{
|
||||
return app(Dispatcher::class)->dispatchSync($job, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,12 +52,12 @@ trait Jobs
|
||||
* @param mixed $job
|
||||
* @param mixed $handler
|
||||
* @return mixed
|
||||
*
|
||||
* @deprecated Will be removed in a future Laravel version.
|
||||
*/
|
||||
public function dispatchNow($job, $handler = null)
|
||||
{
|
||||
$result = dispatch_now($job, $handler);
|
||||
|
||||
return $result;
|
||||
return app(Dispatcher::class)->dispatchNow($job, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,8 +91,6 @@ trait Jobs
|
||||
|
||||
public function getDispatchFunction()
|
||||
{
|
||||
$config = config('queue.default');
|
||||
|
||||
return ($config == 'sync') ? 'dispatch_now' : 'dispatch';
|
||||
return should_queue() ? 'dispatchQueue' : 'dispatchSync';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ trait Modules
|
||||
|
||||
public function getInstalledModules()
|
||||
{
|
||||
$key = 'apps.installed.' . session('company_id');
|
||||
$key = 'apps.installed.' . company_id();
|
||||
|
||||
if ($installed = Cache::get($key)) {
|
||||
return $installed;
|
||||
|
||||
@@ -83,7 +83,7 @@ trait Scopes
|
||||
return $type;
|
||||
}
|
||||
|
||||
$type = $request->get('type') ?: Str::singular((string) $request->segment(2));
|
||||
$type = $request->get('type') ?: Str::singular((string) $request->segment(3));
|
||||
|
||||
if ($type == 'revenue') {
|
||||
$type = 'income';
|
||||
|
||||
@@ -19,7 +19,7 @@ trait SiteApi
|
||||
$headers['headers'] = [
|
||||
'Authorization' => 'Bearer ' . setting('apps.api_key'),
|
||||
'Accept' => 'application/json',
|
||||
'Referer' => app()->runningInConsole() ? config('app.url') : route('dashboard'),
|
||||
'Referer' => app()->runningInConsole() ? config('app.url') : url('/'),
|
||||
'Akaunting' => version('short'),
|
||||
'Language' => language()->getShortCode(),
|
||||
'Information' => json_encode(Info::all()),
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use MediaUploader;
|
||||
use App\Models\Common\Media as MediaModel;
|
||||
use MediaUploader;
|
||||
|
||||
trait Uploads
|
||||
{
|
||||
@@ -16,7 +16,7 @@ trait Uploads
|
||||
}
|
||||
|
||||
if (!$company_id) {
|
||||
$company_id = session('company_id');
|
||||
$company_id = company_id();
|
||||
}
|
||||
|
||||
$file_name = $file->getClientOriginalName();
|
||||
@@ -39,7 +39,7 @@ trait Uploads
|
||||
}
|
||||
|
||||
if (!$company_id) {
|
||||
$company_id = session('company_id');
|
||||
$company_id = company_id();
|
||||
}
|
||||
|
||||
$path = $company_id . '/' . $folder;
|
||||
@@ -56,7 +56,7 @@ trait Uploads
|
||||
}
|
||||
|
||||
if (!$company_id) {
|
||||
$company_id = session('company_id');
|
||||
$company_id = company_id();
|
||||
}
|
||||
|
||||
$path = $company_id . '/' . $folder . '/' . basename($file);
|
||||
|
||||
@@ -29,11 +29,18 @@ trait Users
|
||||
return false;
|
||||
}
|
||||
|
||||
$company = $user->companies()->where('id', $id)->first();
|
||||
$company = $user->withoutEvents(function () use ($user, $id) {
|
||||
return $user->companies()->where('id', $id)->first();
|
||||
});
|
||||
|
||||
return !empty($company);
|
||||
}
|
||||
|
||||
public function isNotUserCompany($id)
|
||||
{
|
||||
return !$this->isUserCompany($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user dashboard assignment
|
||||
*
|
||||
@@ -49,8 +56,54 @@ trait Users
|
||||
return app()->runningInConsole() ? true : false;
|
||||
}
|
||||
|
||||
$dashboard = $user->dashboards()->where('id', $id)->first();
|
||||
$dashboard = $user->withoutEvents(function () use ($user, $id) {
|
||||
return $user->dashboards()->where('id', $id)->first();
|
||||
});
|
||||
|
||||
return !empty($dashboard);
|
||||
}
|
||||
|
||||
public function isNotUserDashboard($id)
|
||||
{
|
||||
return !$this->isUserDashboard($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fist company of active user
|
||||
*
|
||||
* @return null|\App\Models\Common\Company
|
||||
*/
|
||||
public function getFirstCompanyOfUser()
|
||||
{
|
||||
$user = user();
|
||||
|
||||
if (empty($user)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$company = $user->withoutEvents(function () use ($user) {
|
||||
return $user->companies()->enabled()->first();
|
||||
});
|
||||
|
||||
if (empty($company)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $company;
|
||||
}
|
||||
|
||||
public function getLandingPageOfUser()
|
||||
{
|
||||
$user = user();
|
||||
|
||||
if (empty($user)) {
|
||||
return route('login');
|
||||
}
|
||||
|
||||
$route_name = $user->contact ? 'portal.dashboard' : $user->landing_page;
|
||||
|
||||
$company_id = company_id() ?: optional($this->getFirstCompanyOfUser())->id;
|
||||
|
||||
return route($route_name, ['company_id' => $company_id]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user