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
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
private $invoice;
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
private $balance_adjustment;
|
|
|
|
|
|
|
|
public function __construct($invoice, $balance_adjustment)
|
2020-02-03 11:33:07 +01:00
|
|
|
{
|
|
|
|
$this->invoice = $invoice;
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->balance_adjustment = $balance_adjustment;
|
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) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->invoice->balance += floatval($this->balance_adjustment);
|
2020-02-03 11:33:07 +01:00
|
|
|
|
|
|
|
if ($this->invoice->balance == 0) {
|
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
|
|
|
}
|