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()) {
$request->validate([
'date_end'=>'required|date',
'stop_at'=>'required|date',
]);
if (! $o->order_info)
$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_status = 'CANCEL-REQUEST';
$o->save();
@ -298,8 +298,8 @@ class ServiceController extends Controller
$o->type->forceFill($request->post($o->type->type))->save();
}
if ($request->post('date_start'))
$o->date_start = $request->post('date_start');
if ($request->post('start_at'))
$o->date_start = $request->start_at;
$o->save();

View File

@ -36,6 +36,28 @@ class Payment extends Model implements IDs
// Any balance below this we'll assume its all used.
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 */
public function account()
@ -81,6 +103,11 @@ class Payment extends Model implements IDs
/* ATTRIBUTES */
/**
* Work out the remaining amount from this payment that has not been allocated.
*
* @return float
*/
public function getBalanceAttribute(): float
{
$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
{
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 ($this->date_end AND $this->date_end < $date)
$date = $this->date_end;
if ($this->stop_at AND $this->stop_at < $date)
$date = $this->stop_at;
return $date;
}
@ -1211,7 +1211,7 @@ class Service extends Model implements IDs
AND ($this->active OR $this->isPending())
AND (
(($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 {
@ -1231,7 +1231,7 @@ class Service extends Model implements IDs
$o->addTaxes($this->account->country->taxes);
$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

View File

@ -38,7 +38,7 @@
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
</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>