Fixes for credits

This commit is contained in:
David Bomba 2021-07-04 07:46:25 +10:00
parent 58219ab5f8
commit f6aebc5a8b
9 changed files with 45 additions and 29 deletions

View File

@ -234,38 +234,38 @@ class CheckData extends Command
} }
} }
// check for more than one primary contact // // check for more than one primary contact
$clients = DB::table('clients') // $clients = DB::table('clients')
->leftJoin('client_contacts', function ($join) { // ->leftJoin('client_contacts', function ($join) {
$join->on('client_contacts.client_id', '=', 'clients.id') // $join->on('client_contacts.client_id', '=', 'clients.id')
->where('client_contacts.is_primary', '=', true) // ->where('client_contacts.is_primary', '=', true)
->whereNull('client_contacts.deleted_at'); // ->whereNull('client_contacts.deleted_at');
}) // })
->groupBy('clients.id') // ->groupBy('clients.id')
->havingRaw('count(client_contacts.id) != 1'); // ->havingRaw('count(client_contacts.id) != 1');
if ($this->option('client_id')) { // if ($this->option('client_id')) {
$clients->where('clients.id', '=', $this->option('client_id')); // $clients->where('clients.id', '=', $this->option('client_id'));
} // }
$clients = $clients->get(['clients.id', 'clients.user_id', 'clients.company_id']); // $clients = $clients->get(['clients.id', 'clients.user_id', 'clients.company_id']);
$this->logMessage($clients->count().' clients without a single primary contact'); // // $this->logMessage($clients->count().' clients without a single primary contact');
if ($this->option('fix') == 'true') { // // if ($this->option('fix') == 'true') {
foreach ($clients as $client) { // // foreach ($clients as $client) {
$this->logMessage("Fixing missing primary contacts #{$client->id}"); // // $this->logMessage("Fixing missing primary contacts #{$client->id}");
$new_contact = ClientContactFactory::create($client->company_id, $client->user_id); // // $new_contact = ClientContactFactory::create($client->company_id, $client->user_id);
$new_contact->client_id = $client->id; // // $new_contact->client_id = $client->id;
$new_contact->contact_key = Str::random(40); // // $new_contact->contact_key = Str::random(40);
$new_contact->is_primary = true; // // $new_contact->is_primary = true;
$new_contact->save(); // // $new_contact->save();
} // // }
} // // }
if ($clients->count() > 0) { // if ($clients->count() > 0) {
$this->isValid = false; // $this->isValid = false;
} // }
} }
private function checkFailedJobs() private function checkFailedJobs()

View File

@ -34,11 +34,15 @@ class CreditsTable extends Component
public function render() public function render()
{ {
$query = Credit::query() $query = Credit::query()
->where('client_id', auth('contact')->user()->client->id) ->where('client_id', auth('contact')->user()->client->id)
->where('company_id', $this->company->id)
->where('status_id', '<>', Credit::STATUS_DRAFT) ->where('status_id', '<>', Credit::STATUS_DRAFT)
->whereDate('due_date', '<=', now()) ->where(function ($query){
->orWhere('due_date', NULL) $query->whereDate('due_date', '<=', now())
->orWhereNull('due_date');
})
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->paginate($this->per_page); ->paginate($this->per_page);

View File

@ -44,6 +44,7 @@ class InvoicesTable extends Component
$query = Invoice::query() $query = Invoice::query()
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->where('company_id', $this->company->id)
->where('is_deleted', false); ->where('is_deleted', false);
if (in_array('paid', $this->status)) { if (in_array('paid', $this->status)) {

View File

@ -34,6 +34,7 @@ class PaymentMethodsTable extends Component
{ {
$query = ClientGatewayToken::query() $query = ClientGatewayToken::query()
->with('gateway_type') ->with('gateway_type')
->where('company_id', $this->company->id)
->where('client_id', $this->client->id) ->where('client_id', $this->client->id)
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->paginate($this->per_page); ->paginate($this->per_page);

View File

@ -41,6 +41,7 @@ class PaymentsTable extends Component
{ {
$query = Payment::query() $query = Payment::query()
->with('type', 'client') ->with('type', 'client')
->where('company_id', $this->company->id)
->where('client_id', auth('contact')->user()->client->id) ->where('client_id', auth('contact')->user()->client->id)
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->paginate($this->per_page); ->paginate($this->per_page);

View File

@ -45,6 +45,7 @@ class QuotesTable extends Component
} }
$query = $query $query = $query
->where('company_id', $this->company->id)
->where('client_id', auth('contact')->user()->client->id) ->where('client_id', auth('contact')->user()->client->id)
->where('status_id', '<>', Quote::STATUS_DRAFT) ->where('status_id', '<>', Quote::STATUS_DRAFT)
->paginate($this->per_page); ->paginate($this->per_page);

View File

@ -12,6 +12,7 @@
namespace App\Http\Livewire; namespace App\Http\Livewire;
use App\Libraries\MultiDB;
use App\Models\RecurringInvoice; use App\Models\RecurringInvoice;
use App\Utils\Traits\WithSorting; use App\Utils\Traits\WithSorting;
use Livewire\Component; use Livewire\Component;
@ -23,8 +24,12 @@ class RecurringInvoicesTable extends Component
public $per_page = 10; public $per_page = 10;
public $company;
public function mount() public function mount()
{ {
MultiDB::setDb($this->company->db);
$this->sort_asc = false; $this->sort_asc = false;
$this->sort_field = 'date'; $this->sort_field = 'date';
@ -36,6 +41,7 @@ class RecurringInvoicesTable extends Component
$query = $query $query = $query
->where('client_id', auth('contact')->user()->client->id) ->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]) ->whereIn('status_id', [RecurringInvoice::STATUS_PENDING, RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_PAUSED,RecurringInvoice::STATUS_COMPLETED])
->orderBy('status_id', 'asc') ->orderBy('status_id', 'asc')
->with('client') ->with('client')

View File

@ -36,6 +36,7 @@ class SubscriptionRecurringInvoicesTable extends Component
{ {
$query = RecurringInvoice::query() $query = RecurringInvoice::query()
->where('client_id', auth('contact')->user()->client->id) ->where('client_id', auth('contact')->user()->client->id)
->where('company_id', $this->company->id)
->whereNotNull('subscription_id') ->whereNotNull('subscription_id')
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->paginate($this->per_page); ->paginate($this->per_page);

View File

@ -35,6 +35,7 @@ class TasksTable extends Component
public function render() public function render()
{ {
$query = Task::query() $query = Task::query()
->where('company_id', $this->company->id)
->where('client_id', auth('contact')->user()->client->id); ->where('client_id', auth('contact')->user()->client->id);
if ($this->company->getSetting('show_all_tasks_client_portal') === 'invoiced') { if ($this->company->getSetting('show_all_tasks_client_portal') === 'invoiced') {