1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Services/Invoice/UpdateBalance.php

39 lines
928 B
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. 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
{
2023-04-26 14:38:08 +02:00
public function __construct(public Invoice $invoice, public float $balance_adjustment, public bool $is_draft)
{
}
public function run()
{
if ($this->invoice->is_deleted) {
return $this->invoice;
}
2022-03-09 05:45:13 +01:00
$this->invoice->increment('balance', floatval($this->balance_adjustment));
if ($this->invoice->balance == 0 && ! $this->is_draft) {
$this->invoice->status_id = Invoice::STATUS_PAID;
}
return $this->invoice;
}
}