mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
213df6451f
* Ensure release build sets correct file and directory permissions * Invoice Cancellation * Invoice Cancellations
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?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\Events\Payment\PaymentWasCreated;
|
|
use App\Factory\CreditFactory;
|
|
use App\Factory\InvoiceItemFactory;
|
|
use App\Factory\PaymentFactory;
|
|
use App\Helpers\Invoice\InvoiceSum;
|
|
use App\Models\Client;
|
|
use App\Models\Invoice;
|
|
use App\Models\Payment;
|
|
use App\Models\Paymentable;
|
|
use App\Services\AbstractService;
|
|
use App\Services\Client\ClientService;
|
|
use App\Services\Payment\PaymentService;
|
|
use App\Utils\Traits\GeneratesCounter;
|
|
|
|
class HandleCancellation extends AbstractService
|
|
{
|
|
use GeneratesCounter;
|
|
|
|
private $invoice;
|
|
|
|
public function __construct(Invoice $invoice)
|
|
{
|
|
$this->invoice = $invoice;
|
|
}
|
|
|
|
public function run()
|
|
{
|
|
/* Check again!! */
|
|
if(!$this->invoice->invoiceCancellable($this->invoice))
|
|
return $this->invoice;
|
|
|
|
$adjustment = $this->invoice->balance*-1;
|
|
//set invoice balance to 0
|
|
$this->invoice->ledger()->updateInvoiceBalance($adjustment, "Invoice cancellation");
|
|
|
|
$this->invoice->balance = 0;
|
|
$this->invoice = $this->invoice->service()->setStatus(Invoice::STATUS_CANCELLED)->save();
|
|
|
|
//adjust client balance
|
|
$this->invoice->client->service()->updateBalance($adjustment)->save();
|
|
|
|
return $this->invoice;
|
|
}
|
|
|
|
}
|
|
|