mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #6189 from turbo124/v5-develop
Constrain recurring / reminders if the client is archived / deleted
This commit is contained in:
commit
850f904b36
@ -426,8 +426,6 @@ class CheckData extends Command
|
|||||||
Client::cursor()->where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->each(function ($client) {
|
Client::cursor()->where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->each(function ($client) {
|
||||||
|
|
||||||
$client->invoices->where('is_deleted', false)->whereIn('status_id', '!=', Invoice::STATUS_DRAFT)->each(function ($invoice) use ($client) {
|
$client->invoices->where('is_deleted', false)->whereIn('status_id', '!=', Invoice::STATUS_DRAFT)->each(function ($invoice) use ($client) {
|
||||||
// $total_amount = $invoice->payments()->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->get()->sum('pivot.amount');
|
|
||||||
// $total_refund = $invoice->payments()->get()->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.refunded');
|
|
||||||
|
|
||||||
$total_paid = $invoice->payments()
|
$total_paid = $invoice->payments()
|
||||||
->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||||
@ -455,6 +453,38 @@ class CheckData extends Command
|
|||||||
$this->logMessage("{$this->wrong_balances} clients with incorrect invoice balances");
|
$this->logMessage("{$this->wrong_balances} clients with incorrect invoice balances");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// $clients = DB::table('clients')
|
||||||
|
// ->leftJoin('invoices', function($join){
|
||||||
|
// $join->on('invoices.client_id', '=', 'clients.id')
|
||||||
|
// ->where('invoices.is_deleted',0)
|
||||||
|
// ->where('invoices.status_id', '>', 1);
|
||||||
|
// })
|
||||||
|
// ->leftJoin('credits', function($join){
|
||||||
|
// $join->on('credits.client_id', '=', 'clients.id')
|
||||||
|
// ->where('credits.is_deleted',0)
|
||||||
|
// ->where('credits.status_id', '>', 1);
|
||||||
|
// })
|
||||||
|
// ->leftJoin('payments', function($join) {
|
||||||
|
// $join->on('payments.client_id', '=', 'clients.id')
|
||||||
|
// ->where('payments.is_deleted', 0)
|
||||||
|
// ->whereIn('payments.status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED]);
|
||||||
|
// })
|
||||||
|
// ->where('clients.is_deleted',0)
|
||||||
|
// //->where('clients.updated_at', '>', now()->subDays(2))
|
||||||
|
// ->groupBy('clients.id')
|
||||||
|
// ->havingRaw('sum(coalesce(invoices.amount - invoices.balance - credits.amount)) != sum(coalesce(payments.amount - payments.refunded, 0))')
|
||||||
|
// ->get(['clients.id', DB::raw('sum(coalesce(invoices.amount - invoices.balance - credits.amount)) as invoice_amount'), DB::raw('sum(coalesce(payments.amount - payments.refunded, 0)) as payment_amount')]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function checkClientBalances()
|
private function checkClientBalances()
|
||||||
{
|
{
|
||||||
$this->wrong_balances = 0;
|
$this->wrong_balances = 0;
|
||||||
|
@ -48,6 +48,10 @@ class RecurringInvoicesCron
|
|||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||||
->where('remaining_cycles', '!=', '0')
|
->where('remaining_cycles', '!=', '0')
|
||||||
|
->whereHas('client', function ($query) {
|
||||||
|
$query->where('is_deleted',0)
|
||||||
|
->where('deleted_at', NULL);
|
||||||
|
})
|
||||||
->with('company')
|
->with('company')
|
||||||
->cursor();
|
->cursor();
|
||||||
|
|
||||||
@ -70,6 +74,10 @@ class RecurringInvoicesCron
|
|||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||||
->where('remaining_cycles', '!=', '0')
|
->where('remaining_cycles', '!=', '0')
|
||||||
|
->whereHas('client', function ($query) {
|
||||||
|
$query->where('is_deleted',0)
|
||||||
|
->where('deleted_at', NULL);
|
||||||
|
})
|
||||||
->with('company')
|
->with('company')
|
||||||
->cursor();
|
->cursor();
|
||||||
|
|
||||||
|
@ -62,6 +62,10 @@ class ReminderJob implements ShouldQueue
|
|||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->where('balance', '>', 0)
|
->where('balance', '>', 0)
|
||||||
|
->whereHas('client', function ($query) {
|
||||||
|
$query->where('is_deleted',0)
|
||||||
|
->where('deleted_at', NULL);
|
||||||
|
})
|
||||||
->with('invitations')->cursor()->each(function ($invoice) {
|
->with('invitations')->cursor()->each(function ($invoice) {
|
||||||
|
|
||||||
if ($invoice->isPayable()) {
|
if ($invoice->isPayable()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user