2020-04-18 22:33:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2020-04-18 22:33:41 +00:00
|
|
|
use Illuminate\Http\Request;
|
2021-07-13 04:56:14 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2022-06-12 08:32:54 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2021-07-13 02:31:56 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2021-09-29 04:57:25 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
2022-08-03 05:28:27 +00:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2022-08-01 10:34:10 +00:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2024-07-24 04:14:11 +00:00
|
|
|
use Illuminate\Validation\Rule;
|
2022-09-29 01:22:16 +00:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2020-04-18 22:33:41 +00:00
|
|
|
use Illuminate\View\View;
|
2021-09-29 04:57:25 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
2020-04-18 22:33:41 +00:00
|
|
|
|
2024-08-17 00:33:56 +00:00
|
|
|
use App\Http\Requests\{ServiceCancel,ServiceChangeRequest};
|
2021-09-29 04:57:25 +00:00
|
|
|
use App\Mail\{CancelRequest,ChangeRequest};
|
2024-07-24 04:14:11 +00:00
|
|
|
use App\Models\{Charge,Invoice,Product,Service};
|
2020-04-18 22:33:41 +00:00
|
|
|
|
|
|
|
class ServiceController extends Controller
|
|
|
|
{
|
2021-09-29 04:57:25 +00:00
|
|
|
/* SERVICE WORKFLOW METHODS */
|
|
|
|
|
2021-07-13 02:31:56 +00:00
|
|
|
/**
|
2021-09-29 04:57:25 +00:00
|
|
|
* Cancel a request to cancel a service
|
2021-07-13 02:31:56 +00:00
|
|
|
*
|
|
|
|
* @param Service $o
|
2021-09-29 04:57:25 +00:00
|
|
|
* @return bool
|
2021-07-13 02:31:56 +00:00
|
|
|
*/
|
2021-09-29 04:57:25 +00:00
|
|
|
private function action_cancel_cancel(Service $o): bool
|
2021-07-13 02:31:56 +00:00
|
|
|
{
|
2021-09-29 04:57:25 +00:00
|
|
|
if (! $o->order_info)
|
|
|
|
$o->order_info = collect();
|
2021-07-13 02:31:56 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
$o->order_info->put('cancel_cancel',Carbon::now()->format('Y-m-d H:i:s'));
|
|
|
|
$o->order_status = 'ACTIVE';
|
2024-08-17 03:17:07 +00:00
|
|
|
$o->stop_at = NULL;
|
2021-07-13 02:31:56 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
return $o->save();
|
2021-07-13 02:31:56 +00:00
|
|
|
}
|
|
|
|
|
2022-08-03 05:47:09 +00:00
|
|
|
private function action_cancel_pending_enter(Service $o): bool
|
|
|
|
{
|
|
|
|
$o->order_status = 'CANCEL-PENDING';
|
|
|
|
|
|
|
|
return $o->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function action_cancelled(Service $o): bool
|
|
|
|
{
|
|
|
|
$o->order_status = 'CANCELLED';
|
|
|
|
$o->active = FALSE;
|
|
|
|
|
|
|
|
return $o->save();
|
|
|
|
}
|
|
|
|
|
2021-07-13 02:31:56 +00:00
|
|
|
/**
|
2021-09-29 04:57:25 +00:00
|
|
|
* Cancel a request to change a service
|
2021-07-13 02:31:56 +00:00
|
|
|
*
|
2021-09-29 04:57:25 +00:00
|
|
|
* @param Service $o
|
|
|
|
* @return bool
|
2021-07-13 02:31:56 +00:00
|
|
|
*/
|
2021-09-29 04:57:25 +00:00
|
|
|
private function action_change_cancel(Service $o): bool
|
2021-07-13 02:31:56 +00:00
|
|
|
{
|
2021-09-29 04:57:25 +00:00
|
|
|
if (! $o->order_info)
|
|
|
|
$o->order_info = collect();
|
2021-07-13 02:31:56 +00:00
|
|
|
|
2023-05-06 03:53:14 +00:00
|
|
|
// @todo add some validation if this doesnt return a result
|
|
|
|
$np = $o->changes()->where('service__change.active',TRUE)->where('complete',FALSE)->get()->pop();
|
|
|
|
$np->pivot->active = FALSE;
|
|
|
|
$np->pivot->save();
|
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
$o->order_status = 'ACTIVE';
|
|
|
|
|
|
|
|
return $o->save();
|
2021-07-13 02:31:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-18 22:33:41 +00:00
|
|
|
/**
|
2021-09-29 04:57:25 +00:00
|
|
|
* Action to change a service order_status to another stage
|
|
|
|
* This is a generic function that can redirect the user to a page that is required to completed to enter
|
|
|
|
* the new stage
|
|
|
|
*
|
|
|
|
* @param Service $o
|
|
|
|
* @param string $stage
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
private function action_request_enter_redirect(Service $o,string $stage)
|
|
|
|
{
|
|
|
|
return redirect(sprintf('u/service/%d/%s',$o->id,strtolower($stage)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OTHER METHODS */
|
|
|
|
|
2022-06-12 08:32:54 +00:00
|
|
|
public function change_pending(ServiceChangeRequest $request,Service $o)
|
|
|
|
{
|
2023-05-06 03:53:14 +00:00
|
|
|
// @todo add some validation if this doesnt return a result
|
|
|
|
$np = $o->changes()->where('service__change.active',TRUE)->where('complete',FALSE)->get()->pop();
|
|
|
|
|
2022-06-12 08:32:54 +00:00
|
|
|
if ($request->post()) {
|
|
|
|
foreach ($this->service_change_charges($request,$o) as $co)
|
|
|
|
$co->save();
|
|
|
|
|
|
|
|
$o->product_id = Arr::get($request->broadband,'product_id');
|
2023-05-03 08:09:29 +00:00
|
|
|
$o->price = Arr::get($request->broadband,'price');
|
2022-06-12 08:32:54 +00:00
|
|
|
$o->order_status = 'ACTIVE';
|
|
|
|
$o->save();
|
|
|
|
|
2023-05-06 03:53:14 +00:00
|
|
|
$np->pivot->complete = TRUE;
|
|
|
|
$np->pivot->effective_at = Carbon::now();
|
|
|
|
$np->pivot->save();
|
|
|
|
|
2022-06-12 08:32:54 +00:00
|
|
|
return redirect()->to(url('u/service',[$o->id]));
|
|
|
|
}
|
|
|
|
|
2024-07-04 05:03:11 +00:00
|
|
|
return view('theme.backend.adminlte.service.change_pending')
|
2022-07-29 07:45:17 +00:00
|
|
|
->with('breadcrumb',collect()->merge($o->account->breadcrumb))
|
2023-05-06 03:53:14 +00:00
|
|
|
->with('o',$o)
|
|
|
|
->with('np',$np);
|
2022-06-12 08:32:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
/**
|
|
|
|
* Process a request to cancel a service
|
2020-04-18 22:33:41 +00:00
|
|
|
*
|
2024-08-17 00:33:56 +00:00
|
|
|
* @param ServiceCancel $request
|
2020-04-18 22:33:41 +00:00
|
|
|
* @param Service $o
|
2021-09-29 04:57:25 +00:00
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|RedirectResponse|\Illuminate\Routing\Redirector
|
2020-04-18 22:33:41 +00:00
|
|
|
*/
|
2024-08-17 00:33:56 +00:00
|
|
|
public function cancel_request(ServiceCancel $request,Service $o)
|
2020-04-18 22:33:41 +00:00
|
|
|
{
|
2024-08-17 00:33:56 +00:00
|
|
|
if (! $o->order_info)
|
|
|
|
$o->order_info = collect();
|
2020-04-22 12:54:05 +00:00
|
|
|
|
2024-08-17 00:33:56 +00:00
|
|
|
$o->stop_at = $request->stop_at;
|
|
|
|
$o->order_info->put('cancel_note',$request->validated('notes'));
|
2020-04-22 12:54:05 +00:00
|
|
|
|
2024-08-17 00:33:56 +00:00
|
|
|
if ($request->validated('extra_charges'))
|
|
|
|
$o->order_info->put('cancel_extra_charges_accepted',$request->extra_charges_amount);
|
2020-04-22 12:54:05 +00:00
|
|
|
|
2024-08-17 00:33:56 +00:00
|
|
|
$o->order_status = 'CANCEL-REQUEST';
|
|
|
|
$o->save();
|
2020-04-22 12:54:05 +00:00
|
|
|
|
2024-08-17 00:33:56 +00:00
|
|
|
Mail::to(config('osb.ticket_admin'))
|
|
|
|
->queue((new CancelRequest($o,$request->notes))->onQueue('email'));
|
2021-09-29 04:57:25 +00:00
|
|
|
|
2024-08-17 00:33:56 +00:00
|
|
|
return redirect('u/service/'.$o->id)
|
|
|
|
->with('success','Cancellation lodged');
|
2021-09-29 04:57:25 +00:00
|
|
|
}
|
2020-04-22 12:54:05 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
/**
|
|
|
|
* Change the status of a service
|
2022-07-25 13:50:46 +00:00
|
|
|
* @todo This needs to be optimized
|
2021-09-29 04:57:25 +00:00
|
|
|
*
|
|
|
|
* @note This route is protected by middleware @see ServicePolicy::progress()
|
|
|
|
* It is assumed that the next stage is valid for the services current stage - validated in ServicePolicy::progress()
|
|
|
|
* @param Service $o
|
|
|
|
* @param string $stage
|
|
|
|
* @return RedirectResponse
|
|
|
|
*/
|
|
|
|
public function change(Service $o,string $stage): RedirectResponse
|
|
|
|
{
|
|
|
|
// While stage has a string value, that indicates the next stage we want to go to
|
|
|
|
// If stage is NULL, the current stage hasnt been completed
|
|
|
|
// If stage is FALSE, then the current stage failed, and may optionally be directed to another stage.
|
|
|
|
|
|
|
|
while ($stage) {
|
|
|
|
// Check that stage is a valid next action for the user currently performing it
|
|
|
|
//$current = $this->getStageParameters($this->order_status);
|
|
|
|
$next = $o->getStageParameters($stage);
|
2020-04-22 12:54:05 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
// If valid, call the method to confirm that the current stage is complete
|
|
|
|
if ($x=$next->get('enter_method')) {
|
|
|
|
if (! method_exists($this,$x))
|
|
|
|
abort(500,sprintf('ENTER_METHOD [%s]defined doesnt exist',$x));
|
2020-04-18 22:33:41 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
Log::debug(sprintf('Running ENTER_METHOD [%s] on Service [%d] to go to stage [%s]',$x,$o->id,$stage));
|
2020-04-18 22:33:41 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
// @todo Should call exit_method of the current stage first, to be sure we can change
|
2020-04-18 22:33:41 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
try {
|
|
|
|
$result = $this->{$x}($o,$stage);
|
2020-04-18 22:33:41 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
// If we have a form to complete, we need to return with a URL, so we can catch that with an Exception
|
|
|
|
} catch (HttpException $e) {
|
|
|
|
if ($e->getStatusCode() == 301)
|
|
|
|
return ($e->getMessage());
|
2020-04-18 22:33:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
// An Error Condition
|
|
|
|
if (is_null($result))
|
|
|
|
return redirect()->to('u/service/'.$o->id);
|
|
|
|
|
|
|
|
elseif ($result instanceof RedirectResponse)
|
|
|
|
return $result;
|
2020-04-18 22:33:41 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
// The service cannot enter the next stage
|
|
|
|
elseif (! $result)
|
|
|
|
abort(500,'Current Method FAILED: '.$result);
|
2020-04-23 07:38:09 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
} else {
|
|
|
|
$o->order_status = $stage;
|
2022-07-25 13:50:46 +00:00
|
|
|
|
|
|
|
if ($stage == 'ACTIVE')
|
|
|
|
$o->active = TRUE;
|
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
$o->save();
|
|
|
|
}
|
2020-04-23 07:38:09 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
// If valid, call the method to start the next stage
|
|
|
|
$stage = ''; // @todo this is temporary, we havent written the code to automatically jump to the next stage if wecan
|
|
|
|
}
|
2020-04-23 07:38:09 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
return redirect()->to('u/service/'.$o->id);
|
|
|
|
}
|
2020-04-23 07:38:09 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
/**
|
|
|
|
* Process a request to cancel a service
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param Service $o
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function change_request(Request $request,Service $o)
|
|
|
|
{
|
|
|
|
if ($request->post()) {
|
|
|
|
$request->validate([
|
2023-05-06 03:53:14 +00:00
|
|
|
'product_id'=>'required|exists:products,id',
|
2021-09-29 04:57:25 +00:00
|
|
|
'change_date'=>'required|date',
|
2023-05-06 03:53:14 +00:00
|
|
|
'notes'=>'nullable|min:10',
|
2021-09-29 04:57:25 +00:00
|
|
|
]);
|
2020-04-23 07:38:09 +00:00
|
|
|
|
2023-05-06 03:53:14 +00:00
|
|
|
$o->changes()->attach([$o->id=>[
|
|
|
|
'site_id'=> $o->site_id,
|
|
|
|
'ordered_by' => Auth::id(),
|
|
|
|
'ordered_at' => Carbon::now(),
|
|
|
|
'effective_at' => $request->change_date,
|
|
|
|
'product_id' => $request->product_id,
|
|
|
|
'notes' => $request->notes,
|
|
|
|
'active' => TRUE,
|
|
|
|
'complete' => FALSE,
|
|
|
|
]]);
|
2021-09-29 04:57:25 +00:00
|
|
|
|
|
|
|
$o->order_status = 'CHANGE-REQUEST';
|
|
|
|
$o->save();
|
2020-04-23 07:38:09 +00:00
|
|
|
|
2024-08-17 00:47:33 +00:00
|
|
|
Mail::to(config('osb.ticket_admin'))
|
2021-09-29 04:57:25 +00:00
|
|
|
->queue((new ChangeRequest($o,$request->notes))->onQueue('email'));
|
|
|
|
|
|
|
|
return redirect('u/service/'.$o->id)->with('success','Upgrade requested');
|
|
|
|
}
|
2020-04-23 07:38:09 +00:00
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
switch (get_class($o->type)) {
|
2020-04-18 22:33:41 +00:00
|
|
|
default:
|
2024-07-04 05:03:11 +00:00
|
|
|
return view('theme.backend.adminlte.service.change_request')
|
2022-07-29 07:45:17 +00:00
|
|
|
->with('breadcrumb',collect()->merge($o->account->breadcrumb))
|
2021-09-29 04:57:25 +00:00
|
|
|
->with('o',$o);
|
2020-04-18 22:33:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 04:57:25 +00:00
|
|
|
/**
|
|
|
|
* List all the domains managed by the user
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
* @todo revalidate
|
|
|
|
*/
|
|
|
|
public function domain_list(): View
|
2020-04-18 22:33:41 +00:00
|
|
|
{
|
2024-08-01 07:34:31 +00:00
|
|
|
$o = Service\Domain::ServiceActive()
|
2024-08-10 13:53:13 +00:00
|
|
|
->AccountUserAuthorised('services')
|
2022-04-19 07:07:39 +00:00
|
|
|
->select('service_domain.*')
|
|
|
|
->join('services',['services.id'=>'service_domain.service_id'])
|
2021-09-29 04:57:25 +00:00
|
|
|
->with(['service.account','registrar'])
|
|
|
|
->get();
|
|
|
|
|
2024-07-04 05:03:11 +00:00
|
|
|
return view('theme.backend.adminlte.service.domain.list')
|
2021-09-29 04:57:25 +00:00
|
|
|
->with('o',$o);
|
2020-04-18 22:33:41 +00:00
|
|
|
}
|
2022-02-01 05:40:46 +00:00
|
|
|
|
2022-04-02 07:06:34 +00:00
|
|
|
public function email_list(): View
|
|
|
|
{
|
2024-08-01 07:34:31 +00:00
|
|
|
$o = Service\Email::ServiceActive()
|
2024-08-10 13:53:13 +00:00
|
|
|
->AccountUserAuthorised('services')
|
2022-04-19 07:07:39 +00:00
|
|
|
->select('service_email.*')
|
|
|
|
->join('services',['services.id'=>'service_email.service_id'])
|
2022-04-02 07:06:34 +00:00
|
|
|
->with(['service.account','service.product.type.supplied.supplier_detail.supplier','tld'])
|
|
|
|
->get();
|
|
|
|
|
2024-07-04 05:03:11 +00:00
|
|
|
return view('theme.backend.adminlte.service.email.list')
|
2022-07-29 07:45:17 +00:00
|
|
|
->with('o',$o);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return details on the users service
|
|
|
|
*
|
|
|
|
* @param Service $o
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function home(Service $o): View
|
|
|
|
{
|
2024-07-04 05:03:11 +00:00
|
|
|
return view('theme.backend.adminlte.service.home')
|
2022-07-29 07:45:17 +00:00
|
|
|
->with('breadcrumb',collect()->merge($o->account->breadcrumb))
|
2022-04-02 07:06:34 +00:00
|
|
|
->with('o',$o);
|
|
|
|
}
|
|
|
|
|
2022-04-02 09:26:59 +00:00
|
|
|
public function hosting_list(): View
|
|
|
|
{
|
2024-08-01 07:34:31 +00:00
|
|
|
$o = Service\Host::ServiceActive()
|
2024-08-10 13:53:13 +00:00
|
|
|
->AccountUserAuthorised('services')
|
2022-04-19 07:07:39 +00:00
|
|
|
->select('service_host.*')
|
|
|
|
->join('services',['services.id'=>'service_host.service_id'])
|
2022-04-02 09:26:59 +00:00
|
|
|
->with(['service.account','service.product.type.supplied.supplier_detail.supplier','tld'])
|
|
|
|
->get();
|
|
|
|
|
2024-08-01 07:34:31 +00:00
|
|
|
return view('theme.backend.adminlte.service.hosting.list')
|
2022-04-02 09:26:59 +00:00
|
|
|
->with('o',$o);
|
|
|
|
}
|
|
|
|
|
2022-06-12 08:32:54 +00:00
|
|
|
private function service_change_charges(Request $request,Service $o): Collection
|
|
|
|
{
|
|
|
|
$charges = collect();
|
|
|
|
$po = Product::findOrFail(Arr::get($request->broadband,'product_id'));
|
|
|
|
$start_at = Carbon::create(Arr::get($request->broadband,'start_at'));
|
|
|
|
|
|
|
|
// Get the invoiced items covering the start_at date
|
2024-08-15 22:20:58 +00:00
|
|
|
foreach ($o->invoiced_items
|
|
|
|
->filter(fn($item)=>($item->start_at < $start_at) && ($item->stop_at > $start_at) && ($item->item_type === 0)) as $iio)
|
2022-06-12 08:32:54 +00:00
|
|
|
{
|
|
|
|
// Reverse the original charge
|
|
|
|
$co = new Charge;
|
|
|
|
$co->active = TRUE;
|
|
|
|
$co->service_id = $o->id;
|
|
|
|
$co->account_id = $o->account_id;
|
|
|
|
$co->sweep_type = 6;
|
|
|
|
$co->product_id = $iio->product_id;
|
|
|
|
$co->description = 'Plan Upgrade Adjustment';
|
|
|
|
$co->user_id = Auth::id();
|
|
|
|
$co->type = $iio->item_type;
|
|
|
|
$co->start_at = $start_at;
|
|
|
|
$co->stop_at = $iio->stop_at;
|
|
|
|
$co->amount = $iio->price_base;
|
|
|
|
$co->taxable = TRUE; // @todo this should be determined
|
2024-07-29 13:12:53 +00:00
|
|
|
$co->quantity = -1*$start_at->diffInDays($iio->stop_at)/$iio->start_at->diffInDays($iio->stop_at);
|
2022-06-12 08:32:54 +00:00
|
|
|
$charges->push($co);
|
|
|
|
|
|
|
|
// Add the new charge
|
|
|
|
$co = new Charge;
|
|
|
|
$co->active = TRUE;
|
|
|
|
$co->service_id = $o->id;
|
|
|
|
$co->account_id = $o->account_id;
|
|
|
|
$co->sweep_type = 6;
|
|
|
|
$co->product_id = $po->id;
|
|
|
|
$co->description = 'Plan Upgrade Adjustment';
|
|
|
|
$co->user_id = Auth::id();
|
|
|
|
$co->type = $iio->item_type;
|
|
|
|
$co->start_at = $start_at;
|
|
|
|
$co->stop_at = $iio->stop_at;
|
2023-05-03 08:09:29 +00:00
|
|
|
$co->amount = Arr::get($request->broadband,'price') ?: $po->base_charge;
|
2022-06-12 08:32:54 +00:00
|
|
|
$co->taxable = TRUE; // @todo this should be determined
|
2024-07-29 13:12:53 +00:00
|
|
|
$co->quantity = $start_at->diffInDays($iio->stop_at)/$iio->start_at->diffInDays($iio->stop_at);
|
2022-06-12 08:32:54 +00:00
|
|
|
$charges->push($co);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add any fee
|
|
|
|
if (Arr::get($request->broadband,'change_fee')) {
|
|
|
|
$co = new Charge;
|
|
|
|
$co->active = TRUE;
|
|
|
|
$co->service_id = $o->id;
|
|
|
|
$co->account_id = $o->account_id;
|
|
|
|
$co->sweep_type = 6;
|
|
|
|
$co->product_id = $po->id;
|
|
|
|
$co->description = 'Plan Upgrade Fee';
|
|
|
|
$co->user_id = Auth::id();
|
|
|
|
$co->type = 3;
|
|
|
|
$co->start_at = $start_at;
|
|
|
|
$co->stop_at = $start_at;
|
|
|
|
$co->amount = Arr::get($request->broadband,'change_fee');
|
|
|
|
$co->taxable = TRUE; // @todo this should be determined
|
|
|
|
$co->quantity = 1;
|
|
|
|
$charges->push($co);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $charges;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is an API method, that works with service change - to return the new charges as a result of changing a service
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param Service $o
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function service_change_charges_display(Request $request,Service $o)
|
|
|
|
{
|
2024-08-15 22:20:58 +00:00
|
|
|
return view('theme.backend.adminlte.service.change_charge')
|
2022-06-12 08:32:54 +00:00
|
|
|
->with('charges',$this->service_change_charges($request,$o));
|
|
|
|
}
|
|
|
|
|
2022-02-01 05:40:46 +00:00
|
|
|
/**
|
|
|
|
* Update details about a service
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param Service $o
|
|
|
|
* @return RedirectResponse
|
2022-09-29 01:22:16 +00:00
|
|
|
* @throws ValidationException
|
2022-02-01 05:40:46 +00:00
|
|
|
*/
|
|
|
|
public function update(Request $request,Service $o)
|
|
|
|
{
|
2024-07-24 04:14:11 +00:00
|
|
|
Session::put('service_update',true);
|
|
|
|
|
|
|
|
// We dynamically create our validation
|
|
|
|
$validator = Validator::make(
|
|
|
|
$request->post(),
|
|
|
|
$x=collect($o->type->validation())
|
|
|
|
->keys()
|
2024-07-29 13:12:53 +00:00
|
|
|
->transform(fn($item)=>sprintf('%s.%s',$o->product->category,$item))
|
2024-07-24 04:14:11 +00:00
|
|
|
->combine(array_values($o->type->validation()))
|
|
|
|
->transform(fn($item)=>is_string($item)
|
2024-07-29 13:12:53 +00:00
|
|
|
? preg_replace('/^exclude_without:/',sprintf('exclude_without:%s.',$o->product->category),$item)
|
2024-07-24 04:14:11 +00:00
|
|
|
: $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',
|
2024-07-29 13:12:53 +00:00
|
|
|
$o->product->category => 'array|min:1',
|
2024-07-24 04:14:11 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
->toArray()
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withErrors($validator)
|
|
|
|
->withInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
$validated = collect($validator->validated());
|
|
|
|
|
|
|
|
// Store our service type values
|
2024-07-29 13:12:53 +00:00
|
|
|
$o->type->forceFill($validated->get($o->product->category));
|
2022-08-01 10:34:10 +00:00
|
|
|
|
2024-07-24 04:14:11 +00:00
|
|
|
// Some special handling
|
2024-07-29 13:12:53 +00:00
|
|
|
switch ($o->product->category) {
|
2024-07-24 04:14:11 +00:00
|
|
|
case 'broadband':
|
|
|
|
// If pppoe is not set, then we dont need username/password
|
2024-07-29 13:12:53 +00:00
|
|
|
$o->type->pppoe = ($x=data_get($validated,$o->product->category.'.pppoe',FALSE));
|
2022-08-01 10:34:10 +00:00
|
|
|
|
2024-07-24 04:14:11 +00:00
|
|
|
if (! $x) {
|
|
|
|
$o->type->service_username = NULL;
|
|
|
|
$o->type->service_password = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2022-02-01 05:40:46 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 10:34:10 +00:00
|
|
|
$o->type->save();
|
|
|
|
|
2024-07-24 04:14:11 +00:00
|
|
|
if ($validated->has('invoice_next_at'))
|
2024-08-01 07:34:31 +00:00
|
|
|
$o->invoice_next_at = $validated?->get('invoice_next_at');
|
2022-09-07 05:15:02 +00:00
|
|
|
|
2024-07-24 04:14:11 +00:00
|
|
|
if ($validated->has('recur_schedule'))
|
|
|
|
$o->recur_schedule = $validated->get('recur_schedule');
|
2022-10-18 03:17:50 +00:00
|
|
|
|
2024-07-24 04:14:11 +00:00
|
|
|
$o->suspend_billing = ($validated->get('suspend_billing') == 'on');
|
|
|
|
$o->external_billing = ($validated->get('external_billing') == 'on');
|
|
|
|
$o->price = $validated->get('price');
|
2022-10-18 06:24:53 +00:00
|
|
|
|
2022-08-01 10:34:10 +00:00
|
|
|
// Also update our service start_at date.
|
2022-09-29 01:22:16 +00:00
|
|
|
// @todo We may want to make start_at/stop_at dynamic values calculated by the type records
|
2024-07-24 04:14:11 +00:00
|
|
|
if ($validated->has('start_at'))
|
|
|
|
$o->start_at = $validated->get('start_at');
|
|
|
|
|
2022-09-29 01:22:16 +00:00
|
|
|
else {
|
|
|
|
// For broadband, start_at is connect_at in the type record
|
2024-07-29 13:12:53 +00:00
|
|
|
switch ($o->product->category) {
|
2022-09-29 01:22:16 +00:00
|
|
|
case 'broadband':
|
|
|
|
$o->start_at = $o->type->connect_at;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-02-01 05:40:46 +00:00
|
|
|
|
|
|
|
$o->save();
|
|
|
|
|
2024-07-24 04:14:11 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('success','Record Updated');
|
2022-02-01 05:40:46 +00:00
|
|
|
}
|
2020-04-18 22:33:41 +00:00
|
|
|
}
|