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

38 lines
927 B
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. 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;
}
}