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

Fixes for model freshness

This commit is contained in:
David Bomba 2022-03-05 09:21:17 +11:00
parent dad1b17f29
commit 3ee38d54b4
4 changed files with 18 additions and 13 deletions

View File

@ -38,7 +38,7 @@ class PaymentHash extends Model
public function fee_invoice()
{
return $this->belongsTo(Invoice::class, 'fee_invoice_id', 'id');
return $this->belongsTo(Invoice::class, 'fee_invoice_id', 'id')->withTrashed();
}
public function withData(string $property, $value): self

View File

@ -148,6 +148,7 @@ class ApplyPayment
if ((int)$this->invoice->balance == 0) {
$this->invoice->service()->deletePdf();
$this->invoice = $this->invoice->fresh();
event(new InvoiceWasPaid($this->invoice, $this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
}
}

View File

@ -47,7 +47,7 @@ class AutoBillInvoice extends AbstractService
MultiDB::setDb($this->db);
$this->client = $this->invoice->client;
$this->client = $this->invoice->client->fresh();
$is_partial = false;
@ -178,14 +178,16 @@ class AutoBillInvoice extends AbstractService
}
$payment->ledger()
->updatePaymentBalance($amount * -1)
->save();
->updatePaymentBalance($amount * -1)
->save();
$this->invoice->client->service()
->updateBalance($amount * -1)
->updatePaidToDate($amount)
->adjustCreditBalance($amount * -1)
->save();
$client = $this->invoice->client->fresh();
$client->service()
->updateBalance($amount * -1)
->updatePaidToDate($amount)
->adjustCreditBalance($amount * -1)
->save();
$this->invoice->ledger()
->updateInvoiceBalance($amount * -1, "Invoice {$this->invoice->number} payment using Credit {$current_credit->number}")

View File

@ -41,6 +41,8 @@ class UpdateInvoicePayment
collect($paid_invoices)->each(function ($paid_invoice) use ($invoices) {
$client = $this->payment->client->fresh();
$invoice = $invoices->first(function ($inv) use ($paid_invoice) {
return $paid_invoice->invoice_id == $inv->hashed_id;
});
@ -70,8 +72,7 @@ class UpdateInvoicePayment
->ledger()
->updatePaymentBalance($paid_amount * -1);
$this->payment
->client
$client
->service()
->updateBalance($paid_amount * -1)
->updatePaidToDate($paid_amount)
@ -94,11 +95,12 @@ class UpdateInvoicePayment
$this->payment->saveQuietly();
$invoices->each(function ($invoice) {
$invoice = $invoice->fresh();
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
});
return $this->payment;
return $this->payment->fresh();
}
}