mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 02:54:35 -04:00
Fixes for model freshness
This commit is contained in:
parent
dad1b17f29
commit
3ee38d54b4
@ -38,7 +38,7 @@ class PaymentHash extends Model
|
|||||||
|
|
||||||
public function fee_invoice()
|
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
|
public function withData(string $property, $value): self
|
||||||
|
@ -148,6 +148,7 @@ class ApplyPayment
|
|||||||
|
|
||||||
if ((int)$this->invoice->balance == 0) {
|
if ((int)$this->invoice->balance == 0) {
|
||||||
$this->invoice->service()->deletePdf();
|
$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)));
|
event(new InvoiceWasPaid($this->invoice, $this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class AutoBillInvoice extends AbstractService
|
|||||||
|
|
||||||
MultiDB::setDb($this->db);
|
MultiDB::setDb($this->db);
|
||||||
|
|
||||||
$this->client = $this->invoice->client;
|
$this->client = $this->invoice->client->fresh();
|
||||||
|
|
||||||
$is_partial = false;
|
$is_partial = false;
|
||||||
|
|
||||||
@ -178,14 +178,16 @@ class AutoBillInvoice extends AbstractService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$payment->ledger()
|
$payment->ledger()
|
||||||
->updatePaymentBalance($amount * -1)
|
->updatePaymentBalance($amount * -1)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
$this->invoice->client->service()
|
$client = $this->invoice->client->fresh();
|
||||||
->updateBalance($amount * -1)
|
|
||||||
->updatePaidToDate($amount)
|
$client->service()
|
||||||
->adjustCreditBalance($amount * -1)
|
->updateBalance($amount * -1)
|
||||||
->save();
|
->updatePaidToDate($amount)
|
||||||
|
->adjustCreditBalance($amount * -1)
|
||||||
|
->save();
|
||||||
|
|
||||||
$this->invoice->ledger()
|
$this->invoice->ledger()
|
||||||
->updateInvoiceBalance($amount * -1, "Invoice {$this->invoice->number} payment using Credit {$current_credit->number}")
|
->updateInvoiceBalance($amount * -1, "Invoice {$this->invoice->number} payment using Credit {$current_credit->number}")
|
||||||
|
@ -41,6 +41,8 @@ class UpdateInvoicePayment
|
|||||||
|
|
||||||
collect($paid_invoices)->each(function ($paid_invoice) use ($invoices) {
|
collect($paid_invoices)->each(function ($paid_invoice) use ($invoices) {
|
||||||
|
|
||||||
|
$client = $this->payment->client->fresh();
|
||||||
|
|
||||||
$invoice = $invoices->first(function ($inv) use ($paid_invoice) {
|
$invoice = $invoices->first(function ($inv) use ($paid_invoice) {
|
||||||
return $paid_invoice->invoice_id == $inv->hashed_id;
|
return $paid_invoice->invoice_id == $inv->hashed_id;
|
||||||
});
|
});
|
||||||
@ -70,8 +72,7 @@ class UpdateInvoicePayment
|
|||||||
->ledger()
|
->ledger()
|
||||||
->updatePaymentBalance($paid_amount * -1);
|
->updatePaymentBalance($paid_amount * -1);
|
||||||
|
|
||||||
$this->payment
|
$client
|
||||||
->client
|
|
||||||
->service()
|
->service()
|
||||||
->updateBalance($paid_amount * -1)
|
->updateBalance($paid_amount * -1)
|
||||||
->updatePaidToDate($paid_amount)
|
->updatePaidToDate($paid_amount)
|
||||||
@ -94,11 +95,12 @@ class UpdateInvoicePayment
|
|||||||
$this->payment->saveQuietly();
|
$this->payment->saveQuietly();
|
||||||
|
|
||||||
$invoices->each(function ($invoice) {
|
$invoices->each(function ($invoice) {
|
||||||
|
|
||||||
|
$invoice = $invoice->fresh();
|
||||||
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->payment;
|
return $this->payment->fresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user