2020-02-03 11:33:07 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-02-03 11:33:07 +01:00
|
|
|
*
|
|
|
|
* @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)
|
2020-02-03 11:33:07 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-02-03 11:33:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Services\Invoice;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Services\AbstractService;
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
class UpdateBalance extends AbstractService
|
2020-02-03 11:33:07 +01:00
|
|
|
{
|
2023-04-26 14:38:08 +02:00
|
|
|
public function __construct(public Invoice $invoice, public float $balance_adjustment, public bool $is_draft)
|
2020-02-03 11:33:07 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function run()
|
|
|
|
{
|
2020-02-03 11:33:07 +01:00
|
|
|
if ($this->invoice->is_deleted) {
|
2021-02-07 14:03:59 +01:00
|
|
|
return $this->invoice;
|
2020-02-03 11:33:07 +01:00
|
|
|
}
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-03-09 05:45:13 +01:00
|
|
|
$this->invoice->increment('balance', floatval($this->balance_adjustment));
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($this->invoice->balance == 0 && ! $this->is_draft) {
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->invoice->status_id = Invoice::STATUS_PAID;
|
2020-02-03 11:33:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->invoice;
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-02-14 04:32:22 +01:00
|
|
|
}
|