From 71b252843cf58f9b10ca0026adc4dc08b98895a1 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 19 Aug 2022 20:12:08 +1000 Subject: [PATCH] Show accounting link on accounts that are linked --- app/Jobs/AccountingAccountSync.php | 4 ++-- app/Models/Account.php | 14 +++++------ .../common/account/widget/summary.blade.php | 24 +++++++++++++++---- .../theme/backend/adminlte/home.blade.php | 8 +++---- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/app/Jobs/AccountingAccountSync.php b/app/Jobs/AccountingAccountSync.php index 388844a..e984306 100644 --- a/app/Jobs/AccountingAccountSync.php +++ b/app/Jobs/AccountingAccountSync.php @@ -40,7 +40,7 @@ class AccountingAccountSync implements ShouldQueue public function handle() { $api = $this->to->provider->API($this->to); - $accounts = Account::get(); + $accounts = Account::with(['user'])->get(); foreach ($api->getCustomers() as $customer) { $ao = NULL; @@ -54,7 +54,7 @@ class AccountingAccountSync implements ShouldQueue $ao = $x->pop(); // Look based on Name - } elseif (($x=$accounts->filter(function($item) use ($customer) { return $item->company == $customer->companyname || $item->name == $customer->fullname; }))->count() === 1) { + } elseif (($x=$accounts->filter(function($item) use ($customer) { return $item->company == $customer->companyname || $item->name == $customer->fullname || $item->user->email == $customer->email; }))->count() === 1) { $ao = $x->pop(); } else { diff --git a/app/Models/Account.php b/app/Models/Account.php index c62631d..69c1ff5 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -45,13 +45,6 @@ class Account extends Model implements IDs return $this->hasMany(Charge::class); } - public function providers() - { - return $this->belongsToMany(ProviderOauth::class,'account_provider') - ->where('account_provider.site_id',$this->site_id) - ->withPivot('ref','synctoken','created_at','updated_at'); - } - /** * Return the country the user belongs to */ @@ -85,6 +78,13 @@ class Account extends Model implements IDs return $this->hasMany(Payment::class); } + public function providers() + { + return $this->belongsToMany(ProviderOauth::class,'account_provider') + ->where('account_provider.site_id',$this->site_id) + ->withPivot('ref','synctoken','created_at','updated_at'); + } + public function services($active=FALSE) { $query = $this->hasMany(Service::class); diff --git a/resources/views/theme/backend/adminlte/common/account/widget/summary.blade.php b/resources/views/theme/backend/adminlte/common/account/widget/summary.blade.php index 6dd44f7..3a706ad 100644 --- a/resources/views/theme/backend/adminlte/common/account/widget/summary.blade.php +++ b/resources/views/theme/backend/adminlte/common/account/widget/summary.blade.php @@ -1,5 +1,21 @@ +@if($o->my_accounts->count() <= 2 && $o->my_accounts->pluck('providers')->flatten()->count()) +
+
+ +
+ Accounting + @foreach ($o->my_accounts as $ao) + @foreach($ao->providers as $po) + {{ ucfirst($po->name) }} + @endforeach + @endforeach +
+
+
+@endif + @if ($o->accounts->count() > 1) -
+
@@ -11,7 +27,7 @@
@endif -
+
@@ -23,7 +39,7 @@
-
+
@@ -34,7 +50,7 @@
-
+
diff --git a/resources/views/theme/backend/adminlte/home.blade.php b/resources/views/theme/backend/adminlte/home.blade.php index ffe355d..f781df6 100644 --- a/resources/views/theme/backend/adminlte/home.blade.php +++ b/resources/views/theme/backend/adminlte/home.blade.php @@ -31,13 +31,11 @@ --}} - @if ($o == $user) - @canany('reseller','wholesaler') - - @endcanany - @endif @canany('reseller','wholesaler') + @if ($o == $user) + + @endif @endcanany