Add account next invoice

This commit is contained in:
2024-07-31 22:36:28 +10:00
parent 0b5bc9e012
commit f43748e20a
9 changed files with 109 additions and 96 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use Carbon\Carbon;
use Exception;
use Illuminate\Database\Eloquent\Casts\AsCollection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -11,7 +12,6 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Leenooks\Carbon;
use Leenooks\Casts\LeenooksCarbon;
use App\Models\Product\Type;
@@ -33,8 +33,6 @@ use App\Traits\{ScopeServiceActive,ScopeServiceUserAuthorised};
* + billing_interval : The period that this service is billed for by default
* + billing_interval_string : The period that this service is billed for by default as a name
* + invoiced_to : When this service has been billed to
* + category : The type of service this is, eg: broadband, phone
* + category_name : The type of service this is, eg: Broadband, Telephone (in human friendly)
* + contract_term : The term that this service must be active
* + contract_end : The date that the contract ends for this service
* + name : Service short name with service address
@@ -615,10 +613,13 @@ class Service extends Model implements IDs
*
* @return Carbon
*/
public function getInvoiceNextAttribute(): Carbon
public function getInvoiceNextAttribute(): ?Carbon
{
$last = $this->getInvoicedToAttribute();
if ($this->stop_at && $last->greaterThan($this->stop_at))
return NULL;
return $last
? $last->addDay()
: (min($this->start_at,$this->invoice_next_at) ?: Carbon::now());
@@ -1074,9 +1075,9 @@ class Service extends Model implements IDs
if (is_null($billdate))
$billdate = $invoiced_to->clone()->addDays(config('osb.invoice_days'));
while ($invoiced_to < ($this->stop_at ?: $billdate)) {
while ($invoiced_to <= ($this->stop_at ?: $billdate)) {
$ii = new InvoiceItem;
$period = Invoice::invoice_period($invoiced_to,$this->getBillingIntervalAttribute(),$this->product->price_recur_strict);
$period = Invoice::invoice_period($invoiced_to,$this->getBillingIntervalAttribute(),(bool)$this->product->price_recur_strict);
$ii->active = TRUE;
$ii->service_id = $this->id;