Update service update to use components, enhanced form handling and submission. Added pppoe to broadband and changed validation to allow for longer service number.
This commit is contained in:
@@ -12,13 +12,14 @@ use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
use App\Http\Requests\ServiceChangeRequest;
|
||||
use App\Mail\{CancelRequest,ChangeRequest};
|
||||
use App\Models\{Charge,Product,Service};
|
||||
use App\Models\{Charge,Invoice,Product,Service};
|
||||
|
||||
class ServiceController extends Controller
|
||||
{
|
||||
@@ -415,39 +416,74 @@ class ServiceController extends Controller
|
||||
*/
|
||||
public function update(Request $request,Service $o)
|
||||
{
|
||||
if ($o->type->validation()) {
|
||||
Session::put('service_update',true);
|
||||
$validator = Validator::make($x=$request->post($o->category),$o->type->validation());
|
||||
Session::put('service_update',true);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect()
|
||||
->back()
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
// We dynamically create our validation
|
||||
$validator = Validator::make(
|
||||
$request->post(),
|
||||
$x=collect($o->type->validation())
|
||||
->keys()
|
||||
->transform(fn($item)=>sprintf('%s.%s',$o->category,$item))
|
||||
->combine(array_values($o->type->validation()))
|
||||
->transform(fn($item)=>is_string($item)
|
||||
? preg_replace('/^exclude_without:/',sprintf('exclude_without:%s.',$o->category),$item)
|
||||
: $item)
|
||||
->merge(
|
||||
[
|
||||
'external_billing' => 'nullable|in:on',
|
||||
'suspend_billing' => 'nullable|in:on',
|
||||
'recur_schedule' => ['required',Rule::in(collect(Invoice::billing_periods)->keys())],
|
||||
'invoice_next_at' => 'nullable|date',
|
||||
'price' => 'nullable|numeric',
|
||||
$o->category => 'array|min:1',
|
||||
]
|
||||
)
|
||||
->toArray()
|
||||
);
|
||||
|
||||
$o->type->forceFill($validator->validated());
|
||||
if ($validator->fails()) {
|
||||
return redirect()
|
||||
->back()
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
} elseif ($request->post($o->product->category)) {
|
||||
$o->type->forceFill($request->post($o->product->category));
|
||||
$validated = collect($validator->validated());
|
||||
|
||||
// Store our service type values
|
||||
$o->type->forceFill($validated->get($o->category));
|
||||
|
||||
// Some special handling
|
||||
switch ($o->category) {
|
||||
case 'broadband':
|
||||
// If pppoe is not set, then we dont need username/password
|
||||
$o->type->pppoe = ($x=data_get($validated,$o->category.'.pppoe',FALSE));
|
||||
|
||||
if (! $x) {
|
||||
$o->type->service_username = NULL;
|
||||
$o->type->service_password = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$o->type->save();
|
||||
|
||||
if ($request->post('invoice_next_at'))
|
||||
$o->invoice_next_at = $request->invoice_next_at;
|
||||
if ($validated->has('invoice_next_at'))
|
||||
$o->invoice_next_at = $validated->get('invoice_next_at');
|
||||
|
||||
if ($request->post('recur_schedule'))
|
||||
$o->recur_schedule = $request->recur_schedule;
|
||||
if ($validated->has('recur_schedule'))
|
||||
$o->recur_schedule = $validated->get('recur_schedule');
|
||||
|
||||
$o->suspend_billing = ($request->suspend_billing == 'on');
|
||||
$o->external_billing = ($request->external_billing == 'on');
|
||||
$o->price = $request->price ?: NULL;
|
||||
$o->suspend_billing = ($validated->get('suspend_billing') == 'on');
|
||||
$o->external_billing = ($validated->get('external_billing') == 'on');
|
||||
$o->price = $validated->get('price');
|
||||
|
||||
// Also update our service start_at date.
|
||||
// @todo We may want to make start_at/stop_at dynamic values calculated by the type records
|
||||
if ($request->post('start_at'))
|
||||
$o->start_at = $request->start_at;
|
||||
if ($validated->has('start_at'))
|
||||
$o->start_at = $validated->get('start_at');
|
||||
|
||||
else {
|
||||
// For broadband, start_at is connect_at in the type record
|
||||
switch ($o->category) {
|
||||
@@ -459,6 +495,8 @@ class ServiceController extends Controller
|
||||
|
||||
$o->save();
|
||||
|
||||
return redirect()->back()->with('success','Record Updated');
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success','Record Updated');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user