diff --git a/VERSION.txt b/VERSION.txt index 0a9e374797..b4e08793d5 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.2.7 \ No newline at end of file +5.2.10 \ No newline at end of file diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index fdc0886113..712393644b 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -234,38 +234,38 @@ class CheckData extends Command } } - // check for more than one primary contact - $clients = DB::table('clients') - ->leftJoin('client_contacts', function ($join) { - $join->on('client_contacts.client_id', '=', 'clients.id') - ->where('client_contacts.is_primary', '=', true) - ->whereNull('client_contacts.deleted_at'); - }) - ->groupBy('clients.id') - ->havingRaw('count(client_contacts.id) != 1'); + // // check for more than one primary contact + // $clients = DB::table('clients') + // ->leftJoin('client_contacts', function ($join) { + // $join->on('client_contacts.client_id', '=', 'clients.id') + // ->where('client_contacts.is_primary', '=', true) + // ->whereNull('client_contacts.deleted_at'); + // }) + // ->groupBy('clients.id') + // ->havingRaw('count(client_contacts.id) != 1'); - if ($this->option('client_id')) { - $clients->where('clients.id', '=', $this->option('client_id')); - } + // if ($this->option('client_id')) { + // $clients->where('clients.id', '=', $this->option('client_id')); + // } - $clients = $clients->get(['clients.id', 'clients.user_id', 'clients.company_id']); - $this->logMessage($clients->count().' clients without a single primary contact'); + // $clients = $clients->get(['clients.id', 'clients.user_id', 'clients.company_id']); + // // $this->logMessage($clients->count().' clients without a single primary contact'); - if ($this->option('fix') == 'true') { - foreach ($clients as $client) { - $this->logMessage("Fixing missing primary contacts #{$client->id}"); + // // if ($this->option('fix') == 'true') { + // // foreach ($clients as $client) { + // // $this->logMessage("Fixing missing primary contacts #{$client->id}"); - $new_contact = ClientContactFactory::create($client->company_id, $client->user_id); - $new_contact->client_id = $client->id; - $new_contact->contact_key = Str::random(40); - $new_contact->is_primary = true; - $new_contact->save(); - } - } + // // $new_contact = ClientContactFactory::create($client->company_id, $client->user_id); + // // $new_contact->client_id = $client->id; + // // $new_contact->contact_key = Str::random(40); + // // $new_contact->is_primary = true; + // // $new_contact->save(); + // // } + // // } - if ($clients->count() > 0) { - $this->isValid = false; - } + // if ($clients->count() > 0) { + // $this->isValid = false; + // } } private function checkFailedJobs() diff --git a/app/Http/Livewire/CreditsTable.php b/app/Http/Livewire/CreditsTable.php index 7b69eb33c9..056d72469d 100644 --- a/app/Http/Livewire/CreditsTable.php +++ b/app/Http/Livewire/CreditsTable.php @@ -34,11 +34,15 @@ class CreditsTable extends Component public function render() { + $query = Credit::query() ->where('client_id', auth('contact')->user()->client->id) + ->where('company_id', $this->company->id) ->where('status_id', '<>', Credit::STATUS_DRAFT) - ->whereDate('due_date', '<=', now()) - ->orWhere('due_date', NULL) + ->where(function ($query){ + $query->whereDate('due_date', '<=', now()) + ->orWhereNull('due_date'); + }) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/app/Http/Livewire/InvoicesTable.php b/app/Http/Livewire/InvoicesTable.php index 28029f54ac..deefd93b39 100644 --- a/app/Http/Livewire/InvoicesTable.php +++ b/app/Http/Livewire/InvoicesTable.php @@ -44,6 +44,7 @@ class InvoicesTable extends Component $query = Invoice::query() ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') + ->where('company_id', $this->company->id) ->where('is_deleted', false); if (in_array('paid', $this->status)) { diff --git a/app/Http/Livewire/PaymentMethodsTable.php b/app/Http/Livewire/PaymentMethodsTable.php index 8a37e71537..b4906176fd 100644 --- a/app/Http/Livewire/PaymentMethodsTable.php +++ b/app/Http/Livewire/PaymentMethodsTable.php @@ -34,6 +34,7 @@ class PaymentMethodsTable extends Component { $query = ClientGatewayToken::query() ->with('gateway_type') + ->where('company_id', $this->company->id) ->where('client_id', $this->client->id) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/app/Http/Livewire/PaymentsTable.php b/app/Http/Livewire/PaymentsTable.php index 0702ec170d..42111fbcb7 100644 --- a/app/Http/Livewire/PaymentsTable.php +++ b/app/Http/Livewire/PaymentsTable.php @@ -41,6 +41,7 @@ class PaymentsTable extends Component { $query = Payment::query() ->with('type', 'client') + ->where('company_id', $this->company->id) ->where('client_id', auth('contact')->user()->client->id) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/app/Http/Livewire/QuotesTable.php b/app/Http/Livewire/QuotesTable.php index 4fc21065b9..2e1c4dc92f 100644 --- a/app/Http/Livewire/QuotesTable.php +++ b/app/Http/Livewire/QuotesTable.php @@ -45,6 +45,7 @@ class QuotesTable extends Component } $query = $query + ->where('company_id', $this->company->id) ->where('client_id', auth('contact')->user()->client->id) ->where('status_id', '<>', Quote::STATUS_DRAFT) ->paginate($this->per_page); diff --git a/app/Http/Livewire/RecurringInvoicesTable.php b/app/Http/Livewire/RecurringInvoicesTable.php index 5b68c1dc63..a99f387086 100644 --- a/app/Http/Livewire/RecurringInvoicesTable.php +++ b/app/Http/Livewire/RecurringInvoicesTable.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Libraries\MultiDB; use App\Models\RecurringInvoice; use App\Utils\Traits\WithSorting; use Livewire\Component; @@ -23,8 +24,12 @@ class RecurringInvoicesTable extends Component public $per_page = 10; + public $company; + public function mount() { + MultiDB::setDb($this->company->db); + $this->sort_asc = false; $this->sort_field = 'date'; @@ -36,6 +41,7 @@ class RecurringInvoicesTable extends Component $query = $query ->where('client_id', auth('contact')->user()->client->id) + ->where('company_id', $this->company->id) ->whereIn('status_id', [RecurringInvoice::STATUS_PENDING, RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_PAUSED,RecurringInvoice::STATUS_COMPLETED]) ->orderBy('status_id', 'asc') ->with('client') diff --git a/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php b/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php index a529863ea4..a18bdb1b77 100644 --- a/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php +++ b/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php @@ -36,6 +36,7 @@ class SubscriptionRecurringInvoicesTable extends Component { $query = RecurringInvoice::query() ->where('client_id', auth('contact')->user()->client->id) + ->where('company_id', $this->company->id) ->whereNotNull('subscription_id') ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/app/Http/Livewire/TasksTable.php b/app/Http/Livewire/TasksTable.php index f477af99b5..679c02d572 100644 --- a/app/Http/Livewire/TasksTable.php +++ b/app/Http/Livewire/TasksTable.php @@ -35,6 +35,7 @@ class TasksTable extends Component public function render() { $query = Task::query() + ->where('company_id', $this->company->id) ->where('client_id', auth('contact')->user()->client->id); if ($this->company->getSetting('show_all_tasks_client_portal') === 'invoiced') { diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index a1cf2b316e..a7f1021bb3 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -51,8 +51,10 @@ class ClientService $credits = $this->client->credits() ->where('is_deleted', false) ->where('balance', '>', 0) - ->whereDate('due_date', '<=', now()->format('Y-m-d')) - ->orWhere('due_date', NULL) + ->where(function ($query){ + $query->whereDate('due_date', '<=', now()->format('Y-m-d')) + ->orWhereNull('due_date'); + }) ->orderBy('created_at','ASC'); return Number::roundValue($credits->sum('balance'), $this->client->currency()->precision); diff --git a/config/ninja.php b/config/ninja.php index 61be55d47b..12e9acec68 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.2.9', - 'app_tag' => '5.2.9', + 'app_version' => '5.2.10', + 'app_tag' => '5.2.10', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),