Work on products, first completed broadband

This commit is contained in:
Deon George
2021-12-24 12:14:01 +11:00
parent 8f5293662e
commit 1e9f15b40f
62 changed files with 2139 additions and 894 deletions

View File

@@ -45,6 +45,46 @@ class Invoice extends Model implements IDs
protected $dates = ['date_orig','due_date'];
public $dateFormat = 'U';
/* Our available billing periods */
public const billing_periods = [
0 => [
'name' => 'Weekly',
'interval' => 0.25,
],
1 => [
'name' => 'Monthly',
'interval' => 1,
],
2 => [
'name' => 'Quarterly',
'interval' => 3,
],
3 => [
'name' => 'Semi-Annually',
'interval' => 6,
],
4 => [
'name' => 'Annually',
'interval' => 12,
],
5 => [
'name' => 'Two years',
'interval' => 24,
],
6 => [
'name' => 'Three Years',
'interval' => 36,
],
7 => [
'name' => 'Four Years',
'interval' => 48,
],
8 => [
'name' => 'Five Years',
'interval' => 60,
],
];
// Array of items that can be updated with PushNew
protected $pushable = ['items'];
@@ -61,6 +101,58 @@ class Invoice extends Model implements IDs
private int $_total = 0;
private int $_total_tax = 0;
/* STATIC */
/**
* This works out what multiplier to use to change billing periods
*
* @param int $source
* @param int $target
* @return float
*/
public static function billing_change(int $source,int $target): float
{
return Arr::get(self::billing_periods,$target.'.interval')/Arr::get(self::billing_periods,$source.'.interval');
}
/**
* Return the name for the billing interval
*
* @param int $interval
* @return string
*/
public static function billing_name(int $interval): string
{
$interval = collect(self::billing_periods)->get($interval);
return Arr::get($interval,'name','Unknown');
}
/**
* Return the number of months in the billing interval
*
* @param int $interval
* @return int
*/
public static function billing_period(int $interval): int
{
$interval = collect(self::billing_periods)->get($interval);
return Arr::get($interval,'interval',0);
}
/**
* Given a contract in months, this will calculate the number of billing intervals required
*
* @param int $contract_term
* @param int $source
* @return int
*/
public static function billing_term(int $contract_term,int $source): int
{
return ceil(($contract_term ?: 1)/(Arr::get(self::billing_periods,$source.'.interval') ?: 1));
}
/* RELATIONS */
public function account()
@@ -312,7 +404,7 @@ class Invoice extends Model implements IDs
$lo = $this->account->user->language;
return $return->sortBy(function ($item) use ($lo) {
return $item->name($lo);
return $item->name;
});
}