Delete invoice when payments are applied

This commit is contained in:
= 2021-04-09 19:51:17 +10:00
parent 045fd56304
commit e7707a919b
2 changed files with 8 additions and 1 deletions

View File

@ -114,6 +114,7 @@ class PaymentRepository extends BaseRepository {
/*Iterate through invoices and apply payments*/
if (array_key_exists('invoices', $data) && is_array($data['invoices']) && count($data['invoices']) > 0) {
$invoice_totals = array_sum(array_column($data['invoices'], 'amount'));
$invoices = Invoice::whereIn('id', array_column($data['invoices'], 'invoice_id'))->get();
@ -125,7 +126,10 @@ class PaymentRepository extends BaseRepository {
$invoice = Invoice::whereId($paid_invoice['invoice_id'])->first();
if ($invoice) {
$invoice = $invoice->service()->markSent()->applyPayment($payment, $paid_invoice['amount'])->save();
$invoice = $invoice->service()
->markSent()
->applyPayment($payment, $paid_invoice['amount'])
->save();
}
}
} else {

View File

@ -101,6 +101,8 @@ class InvoiceService
*/
public function applyPayment(Payment $payment, float $payment_amount)
{
$this->deletePdf();
$this->invoice = (new ApplyPayment($this->invoice, $payment, $payment_amount))->run();
return $this;
@ -295,6 +297,7 @@ class InvoiceService
public function deletePdf()
{
nlog("delete PDF");
//UnlinkFile::dispatchNow(config('filesystems.default'), $this->invoice->client->invoice_filepath() . $this->invoice->numberFormatter().'.pdf');
Storage::disk(config('filesystems.default'))->delete($this->invoice->client->invoice_filepath() . $this->invoice->numberFormatter().'.pdf');