2020-04-18 22:33:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2021-07-13 04:56:14 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2021-07-13 02:31:56 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2020-04-18 22:33:41 +00:00
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
use App\Models\Service;
|
|
|
|
|
|
|
|
class ServiceController extends Controller
|
|
|
|
{
|
2021-07-13 02:31:56 +00:00
|
|
|
/**
|
|
|
|
* Edit a domain service details
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param Service $o
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function domain_edit(Request $request,Service $o)
|
|
|
|
{
|
|
|
|
session()->flash('service_update',TRUE);
|
|
|
|
|
|
|
|
$validation = $request->validate([
|
2021-07-13 04:56:14 +00:00
|
|
|
'service.domain_name' => ['required',function($attribute,$value,$fail) use ($request,$o) {
|
|
|
|
if (Service\Domain::where('domain_name',$value)
|
|
|
|
->where('domain_tld_id',Arr::get($request,'service.domain_tld_id'))
|
|
|
|
->when($o->type,function($q) use ($o) { return $q->where('id','<>',$o->type->id); })
|
|
|
|
->count() > 0)
|
|
|
|
{
|
|
|
|
$fail('Domain already exists.');
|
|
|
|
}
|
|
|
|
}],
|
2021-07-13 02:31:56 +00:00
|
|
|
'service.domain_expire' => 'required|date',
|
|
|
|
'service.domain_tld_id' => 'required|exists:ab_domain_tld,id',
|
|
|
|
'service.domain_registrar_id' => 'required|exists:ab_domain_registrar,id',
|
|
|
|
'service.registrar_account' => 'required',
|
|
|
|
'service.registrar_username' => 'required|string|min:5',
|
|
|
|
'service.registrar_ns' => 'required|string|min:5',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$o->type->forceFill($validation['service'])->save();
|
|
|
|
|
|
|
|
return redirect()->back()->with('success','Record updated.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List all the domains managed by the user
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function domain_list(): View
|
|
|
|
{
|
|
|
|
$o = Service\Domain::serviceActive()
|
|
|
|
->serviceUserAuthorised(Auth::user())
|
|
|
|
->select('service_domains.*')
|
|
|
|
->join('ab_service',['ab_service.id'=>'service_domains.service_id'])
|
|
|
|
->with(['service.account','registrar'])
|
|
|
|
->get();
|
|
|
|
|
|
|
|
return view('r.service.domain.list')
|
|
|
|
->with('o',$o);
|
|
|
|
}
|
|
|
|
|
2020-04-18 22:33:41 +00:00
|
|
|
/**
|
|
|
|
* Update a service
|
|
|
|
*
|
|
|
|
* @note: Route Middleware protects this path
|
2021-07-13 02:31:56 +00:00
|
|
|
* @param Request $request
|
2020-04-18 22:33:41 +00:00
|
|
|
* @param Service $o
|
2021-07-13 02:31:56 +00:00
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
2020-04-18 22:33:41 +00:00
|
|
|
*/
|
|
|
|
public function update(Request $request,Service $o)
|
|
|
|
{
|
|
|
|
switch ($o->order_status) {
|
2020-04-22 12:54:05 +00:00
|
|
|
case 'CANCEL-REQUEST':
|
|
|
|
if ($request->post()) {
|
|
|
|
if (! $request->post('date_end'))
|
|
|
|
return redirect()->back()->withErrors('Cancellation Date not provided');
|
|
|
|
|
|
|
|
$o->date_end = $request->post('date_end');
|
|
|
|
|
|
|
|
foreach (['cancel_notes'] as $key) {
|
|
|
|
if ($request->post($key))
|
|
|
|
$o->setOrderInfo($key,$request->post($key));
|
|
|
|
}
|
|
|
|
|
|
|
|
$o->order_status='CANCEL-PENDING';
|
|
|
|
$o->save();
|
|
|
|
|
|
|
|
return redirect()->to(url('u/service',$o->id))->with('updated','Service cancellation submitted.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->update_request_cancel($o);
|
|
|
|
|
2020-04-18 22:33:41 +00:00
|
|
|
case 'ORDER-SENT':
|
|
|
|
if ($request->post()) {
|
|
|
|
foreach (['reference','notes'] as $key) {
|
|
|
|
$o->setOrderInfo($key,$request->post($key));
|
|
|
|
}
|
|
|
|
|
|
|
|
$o->save();
|
|
|
|
|
|
|
|
foreach ($request->post($o->stype) as $k=>$v) {
|
|
|
|
$o->type->{$k} = $v;
|
|
|
|
}
|
|
|
|
|
|
|
|
$o->type->save();
|
|
|
|
|
|
|
|
return redirect()->to(url('u/service',$o->id))->with('updated','Order sent notes updated.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->update_order_status($o);
|
|
|
|
|
2020-04-23 07:38:09 +00:00
|
|
|
case 'PROVISION-PLANNED':
|
|
|
|
if ($request->post()) {
|
|
|
|
foreach (['provision_notes'] as $key) {
|
|
|
|
$o->setOrderInfo($key,$request->post($key));
|
|
|
|
}
|
|
|
|
|
|
|
|
$o->date_start = $request->post('date_start');
|
|
|
|
|
|
|
|
$o->save();
|
|
|
|
|
|
|
|
foreach ($request->post($o->stype) as $k=>$v) {
|
|
|
|
$o->type->{$k} = $v;
|
|
|
|
}
|
|
|
|
|
|
|
|
$o->type->save();
|
|
|
|
|
|
|
|
return redirect()->to(url('u/service',$o->id))->with('updated','Order sent notes updated.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->update_provision_planned($o);
|
|
|
|
|
2020-04-18 22:33:41 +00:00
|
|
|
default:
|
|
|
|
abort(499,'Not yet implemented');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 07:38:09 +00:00
|
|
|
private function update_order_status(Service $o)
|
|
|
|
{
|
|
|
|
return View('r.service.order.sent',['o'=>$o]);
|
|
|
|
}
|
|
|
|
|
2020-04-22 12:54:05 +00:00
|
|
|
private function update_request_cancel(Service $o)
|
|
|
|
{
|
|
|
|
return View('u.service.order.cancel',['o'=>$o]);
|
|
|
|
}
|
|
|
|
|
2020-04-23 07:38:09 +00:00
|
|
|
private function update_provision_planned(Service $o)
|
2020-04-18 22:33:41 +00:00
|
|
|
{
|
2020-04-23 07:38:09 +00:00
|
|
|
return View('r.service.order.provision_plan',['o'=>$o]);
|
2020-04-18 22:33:41 +00:00
|
|
|
}
|
|
|
|
}
|