Refactor invoice delete/restore

This commit is contained in:
David Bomba 2020-12-03 15:20:39 +11:00
parent 73c9474912
commit f96bde6fca
3 changed files with 62 additions and 1 deletions

View File

@ -70,13 +70,25 @@ class InvoiceRepository extends BaseRepository
}
// $invoice->service()->markDeleted()->handleCancellation()->save();
$invoice->service()->markDeleted()->save();
$invoice = $invoice->service()->markDeleted()->save();
parent::delete($invoice);
return $invoice;
}
public function restore() :Invoice
{
if(!$invoice->is_deleted)
return $invoice
$invoice = $invoice->service()->handeRestore()->save()
parent::restore($invoice);
return $invoice;
}
public function reverse()
{
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Invoice;
use App\Models\Invoice;
use App\Services\AbstractService;
use Illuminate\Support\Facades\DB;
class HandleInvoiceRestore extends AbstractService
{
private $invoice;
public function __construct(Invoice $invoice)
{
$this->invoice = $invoice;
}
public function run()
{
//determine whether we need to un-delete payments OR just modify the payment amount /applied balances.
//adjust ledger balance
//adjust paid to dates
//restore paymentables
}
}

View File

@ -164,6 +164,13 @@ class InvoiceService
return $this;
}
public function handeRestore()
{
$this->invoice = (new HandleInvoiceRestore($this->invoice))->run();
return $this;
}
public function reverseCancellation()
{
$this->invoice = (new HandleCancellation($this->invoice))->reverse();