1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

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
$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()

View File

@ -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);

View File

@ -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)) {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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')

View File

@ -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);

View File

@ -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') {