osb/app/Http/Controllers/UserHomeController.php

92 lines
1.8 KiB
PHP
Raw Normal View History

2018-05-20 12:53:14 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Contracts\View\Factory;
2018-07-13 04:53:44 +00:00
use Illuminate\Support\Facades\Auth;
2020-02-05 04:47:24 +00:00
use Illuminate\View\View;
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
2019-07-02 05:28:27 +00:00
2018-08-23 05:17:26 +00:00
use App\Models\{Invoice,Service};
2018-08-01 07:09:38 +00:00
use App\User;
2018-07-13 04:53:44 +00:00
2018-05-20 12:53:14 +00:00
class UserHomeController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
2020-02-05 04:47:24 +00:00
/**
* Logged in users home page
*
* @return Factory|View
2020-02-05 04:47:24 +00:00
*/
public function home(User $o=NULL): View
2018-05-20 12:53:14 +00:00
{
2020-02-08 11:51:50 +00:00
if ($o)
return View('u.home',['o'=>$o]);
// If User was null, then test and see what type of logged on user we have
$o = Auth::user();
2018-07-13 04:53:44 +00:00
switch (Auth::user()->role()) {
2018-07-31 04:11:00 +00:00
case 'customer':
return View('u.home',['o'=>$o]);
2018-07-13 04:53:44 +00:00
2018-07-31 04:11:00 +00:00
case 'reseller':
case 'wholesaler':
return View('r.home',['o'=>$o]);
2018-07-13 04:53:44 +00:00
default:
abort(500,'Unknown role: '.$o->role());
2018-07-13 04:53:44 +00:00
}
2018-05-20 12:53:14 +00:00
}
2018-07-16 05:06:43 +00:00
2020-02-05 04:47:24 +00:00
/**
* Render a specific invoice for the user
*
* @param Invoice $o
* @return View
*/
public function invoice(Invoice $o): View
2018-08-23 05:17:26 +00:00
{
return View('u.invoice',['o'=>$o]);
}
2020-02-05 04:47:24 +00:00
/**
* Return the invoice in PDF format, ready to download
*
* @param Invoice $o
* @return mixed
*/
2018-08-23 05:17:26 +00:00
public function invoice_pdf(Invoice $o)
{
return PDF::loadView('u.invoice', ['o'=>$o])->stream(sprintf('%s.pdf',$o->invoice_account_id));
}
2018-07-16 05:06:43 +00:00
/**
* Helper to redirect to the old site, when functions are not available in this one.
*
* @param $type
* @param $action
* @param $id
* @return void
* @deprecated @todo Remove once all functions added
*/
public function oldsite($type,$action,$id)
{
abort(307,sprintf('http://www.graytech.net.au/u/%s/%s/%s',$type,$action,$id));
}
2018-08-01 07:09:38 +00:00
2020-02-05 04:47:24 +00:00
/**
* Return details on the users service
*
* @param Service $o
* @return View
*/
public function service(Service $o): View
2018-08-23 05:17:26 +00:00
{
2020-02-05 04:47:24 +00:00
return View('u.service',['o'=>$o]);
2018-08-01 07:09:38 +00:00
}
2018-05-20 12:53:14 +00:00
}