Fix some missing date_* attributes for Service that have been missed

This commit is contained in:
Deon George 2022-05-12 09:09:49 +10:00
parent 03f37f33ff
commit 2d7437fc0d
4 changed files with 39 additions and 26 deletions

View File

@ -80,13 +80,13 @@ class ServiceController extends Controller
{ {
if ($request->post()) { if ($request->post()) {
$request->validate([ $request->validate([
'date_end'=>'required|date', 'stop_at'=>'required|date',
]); ]);
if (! $o->order_info) if (! $o->order_info)
$o->order_info = collect(); $o->order_info = collect();
$o->date_end = $request->date_end; $o->stop_at = $request->stop_at;
$o->order_info->put('cancel_note',$request->notes); $o->order_info->put('cancel_note',$request->notes);
$o->order_status = 'CANCEL-REQUEST'; $o->order_status = 'CANCEL-REQUEST';
$o->save(); $o->save();
@ -298,8 +298,8 @@ class ServiceController extends Controller
$o->type->forceFill($request->post($o->type->type))->save(); $o->type->forceFill($request->post($o->type->type))->save();
} }
if ($request->post('date_start')) if ($request->post('start_at'))
$o->date_start = $request->post('date_start'); $o->date_start = $request->start_at;
$o->save(); $o->save();

View File

@ -36,6 +36,28 @@ class Payment extends Model implements IDs
// Any balance below this we'll assume its all used. // Any balance below this we'll assume its all used.
private const threshold = 0.05; private const threshold = 0.05;
/* INTERFACES */
/**
* Payment Local ID
*
* @return string
*/
public function getLIDattribute(): string
{
return sprintf('%06s',$this->id);
}
/**
* Payment System ID
*
* @return string
*/
public function getSIDAttribute(): string
{
return sprintf('%02s-%04s#%s',$this->site_id,$this->account_id,$this->getLIDattribute());
}
/* RELATIONS */ /* RELATIONS */
public function account() public function account()
@ -81,6 +103,11 @@ class Payment extends Model implements IDs
/* ATTRIBUTES */ /* ATTRIBUTES */
/**
* Work out the remaining amount from this payment that has not been allocated.
*
* @return float
*/
public function getBalanceAttribute(): float public function getBalanceAttribute(): float
{ {
$balance = $this->getTotalAttribute()-$this->items->sum('amount'); $balance = $this->getTotalAttribute()-$this->items->sum('amount');
@ -89,25 +116,11 @@ class Payment extends Model implements IDs
} }
/** /**
* Payment Local ID * The total of the payment.
* *
* @return string * @return float
* @todo Change the DB column to total
*/ */
public function getLIDattribute(): string
{
return sprintf('%06s',$this->id);
}
/**
* Payment System ID
*
* @return string
*/
public function getSIDAttribute(): string
{
return sprintf('%02s-%04s#%s',$this->site_id,$this->account_id,$this->getLIDattribute());
}
public function getTotalAttribute(): float public function getTotalAttribute(): float
{ {
return sprintf('%3.2f',$this->total_amt); return sprintf('%3.2f',$this->total_amt);

View File

@ -636,8 +636,8 @@ class Service extends Model implements IDs
} }
// If the invoice has an end date, our invoice period shouldnt be greater than that. // If the invoice has an end date, our invoice period shouldnt be greater than that.
if ($this->date_end AND $this->date_end < $date) if ($this->stop_at AND $this->stop_at < $date)
$date = $this->date_end; $date = $this->stop_at;
return $date; return $date;
} }
@ -1211,7 +1211,7 @@ class Service extends Model implements IDs
AND ($this->active OR $this->isPending()) AND ($this->active OR $this->isPending())
AND ( AND (
(($future == TRUE) AND $this->invoice_next < $this->invoice_next_end) OR (($future == TRUE) AND $this->invoice_next < $this->invoice_next_end) OR
(($future == FALSE) AND ($this->invoice_to < ($this->date_end ?: $billdate))) (($future == FALSE) AND ($this->invoice_to < ($this->stop_at ?: $billdate)))
)) ))
{ {
do { do {
@ -1231,7 +1231,7 @@ class Service extends Model implements IDs
$o->addTaxes($this->account->country->taxes); $o->addTaxes($this->account->country->taxes);
$this->invoice_items->push($o); $this->invoice_items->push($o);
} while ($future == FALSE AND ($this->invoice_to < ($this->date_end ?: $billdate))); } while ($future == FALSE AND ($this->invoice_to < ($this->stop_at ?: $billdate)));
} }
// Add additional charges // Add additional charges

View File

@ -38,7 +38,7 @@
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span> <span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
</div> </div>
<input type="text" class="form-control" id="datestop" name="date_end" value="{{ ($x=$o->date_end) ? $x->format('Y-m-d') : '' }}"> <input type="text" class="form-control" id="datestop" name="stop_at" value="{{ ($x=$o->stop_at) ? $x->format('Y-m-d') : '' }}">
</div> </div>
</div> </div>
</div> </div>