mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
fixes for tests
This commit is contained in:
parent
656bf13510
commit
b0740b46dd
@ -22,6 +22,7 @@ use App\Models\Credit;
|
||||
use App\Models\Invitation;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\Payment;
|
||||
use App\Utils\Ninja;
|
||||
use Carbon;
|
||||
use DB;
|
||||
@ -325,8 +326,11 @@ class CheckData extends Command
|
||||
$total_invoice_payments = 0;
|
||||
|
||||
foreach ($client->invoices->where('is_deleted', false)->where('status_id', '>', 1) as $invoice) {
|
||||
$total_amount = $invoice->payments->whereNull('deleted_at')->sum('pivot.amount');
|
||||
$total_refund = $invoice->payments->whereNull('deleted_at')->sum('pivot.refunded');
|
||||
// $total_amount = $invoice->payments->whereNull('deleted_at')->sum('pivot.amount');
|
||||
// $total_refund = $invoice->payments->whereNull('deleted_at')->sum('pivot.refunded');
|
||||
|
||||
$total_amount = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.amount');
|
||||
$total_refund = $invoice->payments->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.refunded');
|
||||
|
||||
$total_invoice_payments += ($total_amount - $total_refund);
|
||||
}
|
||||
@ -360,8 +364,8 @@ class CheckData extends Command
|
||||
|
||||
Client::cursor()->each(function ($client) use ($wrong_balances) {
|
||||
$client->invoices->where('is_deleted', false)->whereIn('status_id', '!=', Invoice::STATUS_DRAFT)->each(function ($invoice) use ($wrong_balances, $client) {
|
||||
$total_amount = $invoice->payments->sum('pivot.amount');
|
||||
$total_refund = $invoice->payments->sum('pivot.refunded');
|
||||
$total_amount = $invoice->payments->whereIn('status_id', [Payment::STATUS_PAID, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.amount');
|
||||
$total_refund = $invoice->payments->whereIn('status_id', [Payment::STATUS_PAID, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.refunded');
|
||||
$total_credit = $invoice->credits->sum('amount');
|
||||
|
||||
$total_paid = $total_amount - $total_refund;
|
||||
|
@ -186,7 +186,7 @@ class Invoice extends BaseModel
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->morphToMany(Payment::class, 'paymentable')->withPivot('amount', 'refunded')->withTimestamps()->withTrashed();
|
||||
return $this->morphToMany(Payment::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded')->withTimestamps();
|
||||
}
|
||||
|
||||
public function company_ledger()
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Events\Payment\PaymentWasDeleted;
|
||||
use App\Factory\CreditFactory;
|
||||
use App\Jobs\Credit\ApplyCreditPayment;
|
||||
use App\Libraries\Currency\Conversion\CurrencyApi;
|
||||
@ -146,7 +147,7 @@ class PaymentRepository extends BaseRepository
|
||||
|
||||
//todo optimize into a single query
|
||||
foreach ($data['credits'] as $paid_credit) {
|
||||
$credit = Credit::find($this->decodePrimaryKey($paid_credit['credit_id']))->withTrashed();
|
||||
$credit = Credit::withTrashed()->find($this->decodePrimaryKey($paid_credit['credit_id']));
|
||||
|
||||
if ($credit) {
|
||||
ApplyCreditPayment::dispatchNow($credit, $payment, $paid_credit['amount'], $credit->company);
|
||||
@ -198,9 +199,12 @@ class PaymentRepository extends BaseRepository
|
||||
return;
|
||||
}
|
||||
|
||||
$payment->service()->deletePayment();
|
||||
$payment = $payment->service()->deletePayment();
|
||||
|
||||
return parent::delete($payment);
|
||||
event(new PaymentWasDeleted($payment, $payment->company, Ninja::eventVars()));
|
||||
|
||||
return $payment;
|
||||
//return parent::delete($payment);
|
||||
}
|
||||
|
||||
public function restore($payment)
|
||||
|
Loading…
x
Reference in New Issue
Block a user