mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fixes for multiple deletes on a single invoice
This commit is contained in:
parent
4d1555b46e
commit
9e69488254
@ -266,7 +266,7 @@ class MatchBankTransactions implements ShouldQueue
|
||||
/* Create Payment */
|
||||
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
||||
|
||||
$payment->amount = $amount;
|
||||
$payment->amount = $this->bt->amount;
|
||||
$payment->applied = $this->applied_amount;
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
$payment->client_id = $this->invoice->client_id;
|
||||
|
@ -56,8 +56,7 @@ class HandleRestore extends AbstractService
|
||||
|
||||
$this->invoice->client
|
||||
->service()
|
||||
->updateBalance($this->invoice->balance)
|
||||
->updatePaidToDate($this->invoice->paid_to_date)
|
||||
->updateBalanceAndPaidToDate($this->invoice->balance,$this->invoice->paid_to_date)
|
||||
->save();
|
||||
|
||||
$this->windBackInvoiceNumber();
|
||||
@ -120,11 +119,11 @@ class HandleRestore extends AbstractService
|
||||
|
||||
if ($this->adjustment_amount == $this->total_payments) {
|
||||
$this->invoice->payments()->update(['payments.deleted_at' => null, 'payments.is_deleted' => false]);
|
||||
} else {
|
||||
}
|
||||
|
||||
//adjust payments down by the amount applied to the invoice payment.
|
||||
|
||||
$this->invoice->payments->each(function ($payment) {
|
||||
$this->invoice->payments->fresh()->each(function ($payment) {
|
||||
$payment_adjustment = $payment->paymentables
|
||||
->where('paymentable_type', '=', 'invoices')
|
||||
->where('paymentable_id', $this->invoice->id)
|
||||
@ -141,8 +140,7 @@ class HandleRestore extends AbstractService
|
||||
$payment->restore();
|
||||
$payment->save();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -77,26 +77,17 @@ class MarkInvoiceDeleted extends AbstractService
|
||||
return $this;
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
private function adjustBalance()
|
||||
{
|
||||
// $client = $this->invoice->client->fresh();
|
||||
// $client->balance += $this->balance_adjustment * -1;
|
||||
// $client->save();
|
||||
|
||||
// $this->invoice->client->service()->updateBalance($this->balance_adjustment * -1)->save(); //reduces the client balance by the invoice amount.
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/* Adjust the payment amounts */
|
||||
private function adjustPayments()
|
||||
{
|
||||
//if total payments = adjustment amount - that means we need to delete the payments as well.
|
||||
|
||||
if ($this->adjustment_amount == $this->total_payments) {
|
||||
nlog($this->adjustment_amount);
|
||||
nlog($this->total_payments);
|
||||
|
||||
if ($this->adjustment_amount == $this->total_payments)
|
||||
$this->invoice->payments()->update(['payments.deleted_at' => now(), 'payments.is_deleted' => true]);
|
||||
} else {
|
||||
|
||||
|
||||
//adjust payments down by the amount applied to the invoice payment.
|
||||
|
||||
@ -115,7 +106,7 @@ class MarkInvoiceDeleted extends AbstractService
|
||||
$payment->applied -= $payment_adjustment;
|
||||
$payment->save();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -116,8 +116,6 @@ class ClientApiTest extends TestCase
|
||||
|
||||
Client::reguard();
|
||||
|
||||
nlog($c->toArray());
|
||||
|
||||
$c->refresh();
|
||||
|
||||
$this->assertEquals("3", $c->settings->currency_id);
|
||||
|
@ -162,6 +162,7 @@ class DeleteInvoiceTest extends TestCase
|
||||
$payment = $payment->fresh();
|
||||
|
||||
$this->assertTrue($payment->is_deleted);
|
||||
$this->assertEquals(0, $payment->amount);
|
||||
$this->assertEquals(4, $payment->status_id);
|
||||
|
||||
$client->fresh();
|
||||
|
Loading…
Reference in New Issue
Block a user