1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Services/Invoice/UpdateBalance.php

44 lines
999 B
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Invoice;
use App\Models\Invoice;
use App\Services\AbstractService;
class UpdateBalance extends AbstractService
{
public $invoice;
public $balance_adjustment;
public function __construct($invoice, $balance_adjustment)
{
$this->invoice = $invoice;
$this->balance_adjustment = $balance_adjustment;
}
public function run()
{
if ($this->invoice->is_deleted) {
return $this->invoice;
}
$this->invoice->balance += floatval($this->balance_adjustment);
if ($this->invoice->balance == 0) {
$this->invoice->status_id = Invoice::STATUS_PAID;
}
return $this->invoice;
}
}