mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for check data script
This commit is contained in:
parent
7f13a79623
commit
ad2fcf6b0d
@ -321,10 +321,17 @@ class CheckData extends Command
|
|||||||
|
|
||||||
foreach ($client->invoices()->where('is_deleted', false)->where('status_id', '>', 1)->get() as $invoice) {
|
foreach ($client->invoices()->where('is_deleted', false)->where('status_id', '>', 1)->get() as $invoice) {
|
||||||
|
|
||||||
$total_amount = $invoice->payments()->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->get()->sum('pivot.amount');
|
// $total_amount = $invoice->payments()->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->get()->sum('pivot.amount');
|
||||||
$total_refund = $invoice->payments()->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->get()->sum('pivot.refunded');
|
// $total_refund = $invoice->payments()->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->get()->sum('pivot.refunded');
|
||||||
|
|
||||||
|
// $total_invoice_payments += ($total_amount - $total_refund);
|
||||||
|
|
||||||
|
$total_invoice_payments += $invoice->payments()
|
||||||
|
->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||||
|
->selectRaw('sum(paymentables.amount - paymentables.refunded) as p')
|
||||||
|
->pluck('p')
|
||||||
|
->first();
|
||||||
|
|
||||||
$total_invoice_payments += ($total_amount - $total_refund);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//commented IN 27/06/2021 - sums ALL client payments AND the unapplied amounts to match the client paid to date
|
//commented IN 27/06/2021 - sums ALL client payments AND the unapplied amounts to match the client paid to date
|
||||||
@ -339,7 +346,12 @@ class CheckData extends Command
|
|||||||
|
|
||||||
// 10/02/21
|
// 10/02/21
|
||||||
foreach ($client->payments as $payment) {
|
foreach ($client->payments as $payment) {
|
||||||
$credit_total_applied += $payment->paymentables()->where('paymentable_type', App\Models\Credit::class)->get()->sum(DB::raw('amount'));
|
// $credit_total_applied += $payment->paymentables()->where('paymentable_type', App\Models\Credit::class)->get()->sum(DB::raw('amount'));
|
||||||
|
$credit_total_applied += $payment->paymentables()
|
||||||
|
->where('paymentable_type', App\Models\Credit::class)
|
||||||
|
->selectRaw('sum(paymentables.amount - paymentables.refunded) as p')
|
||||||
|
->pluck('p')
|
||||||
|
->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($credit_total_applied < 0) {
|
if ($credit_total_applied < 0) {
|
||||||
@ -377,6 +389,7 @@ class CheckData extends Command
|
|||||||
$total_credit = $invoice->credits()->get()->sum('amount');
|
$total_credit = $invoice->credits()->get()->sum('amount');
|
||||||
|
|
||||||
$total_paid = $total_amount - $total_refund;
|
$total_paid = $total_amount - $total_refund;
|
||||||
|
|
||||||
$calculated_paid_amount = $invoice->amount - $invoice->balance - $total_credit;
|
$calculated_paid_amount = $invoice->amount - $invoice->balance - $total_credit;
|
||||||
|
|
||||||
if ((string)$total_paid != (string)($invoice->amount - $invoice->balance - $total_credit)) {
|
if ((string)$total_paid != (string)($invoice->amount - $invoice->balance - $total_credit)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user