1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Services/Invoice/UpdateBalance.php
David Bomba c25de936ed
Refactor - moving away from jobs. (#3279)
* Implement Services

* implement service pattern

* Service patterns

* Refactoring invoice paid

* refactoring invoice

* Refactor jobs

* Refactor - remove jobs

* Refactor jobs

* Refactoring jobs

* Refactoring away from jobs

* Refactoring jobs

* Add Credits to test data
2020-02-03 21:33:07 +11:00

47 lines
950 B
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\Models\Invoice;
class UpdateBalance
{
private $invoice;
public function __construct($invoice)
{
$this->invoice = $invoice;
}
public function __invoke($balance_adjustment)
{
if ($this->invoice->is_deleted) {
return;
}
$balance_adjustment = floatval($balance_adjustment);
$this->invoice->balance += $balance_adjustment;
if ($this->invoice->balance == 0) {
$this->status_id = Invoice::STATUS_PAID;
// $this->save();
// event(new InvoiceWasPaid($this, $this->company));
}
return $this->invoice;
}
}