osb/app/Http/Controllers/AdminHomeController.php

126 lines
3.3 KiB
PHP
Raw Normal View History

2018-07-31 04:11:00 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
2018-08-07 04:26:33 +00:00
use Illuminate\Support\Facades\Log;
use Illuminate\Http\UploadedFile;
2018-08-23 05:17:26 +00:00
use Illuminate\Support\Facades\Mail;
2018-07-31 04:11:00 +00:00
2019-01-24 03:40:33 +00:00
use App\Mail\{OrderRequestApprove,OrderRequestReject};
2018-08-23 05:17:26 +00:00
use App\Models\{Service,SiteDetails};
2018-07-31 04:11:00 +00:00
class AdminHomeController extends Controller
{
2018-08-23 05:17:26 +00:00
public function service(Service $o)
{
return View('a.service',['o'=>$o]);
}
public function service_update(Request $request, Service $o)
{
2019-01-24 06:16:51 +00:00
if (! $o->validStatus(strtolower($request->input('action'))))
return $this->service($o);
$action = strtolower($request->input('action'));
switch ($action)
2018-08-23 05:17:26 +00:00
{
case 'approve':
// Send an email to the supplier.
// @todo Change to address to suppliers email address.
Mail::to('help@graytech.net.au')
->queue((new OrderRequestApprove($o,$request->input('order_notes') ?: 'NONE'))->onQueue('high'));
// Send an email to the client.
// @todo Your order has been submitted to supplier.
// Update the service to "ORDER-SENT"
2019-01-24 06:16:51 +00:00
$o->nextStatus($action);
2018-08-23 05:17:26 +00:00
break;
2019-01-24 03:40:33 +00:00
case 'reject':
$o->order_info = array_merge($o->order_info ? $o->order_info : [],['reason'=>$request->input('notes')]);
// Send mail to user
Mail::to($o->orderby->email)->queue((new OrderRequestReject($o,$request->input('notes')))->onQueue('email'));
2019-01-24 06:16:51 +00:00
$o->nextStatus($action);
2019-01-24 03:40:33 +00:00
break;
case 'update_reference':
$o->order_info = array_merge($o->order_info ? $o->order_info : [],['order_reference'=>$request->input('notes')]);
$o->save();
2018-08-23 05:17:26 +00:00
// No action specified.
default:
return $this->service($o);
}
2018-08-23 06:31:46 +00:00
return redirect(url('/a/service',[$o->id]));
2018-08-23 05:17:26 +00:00
}
2018-07-31 04:11:00 +00:00
public function setup()
{
return view('a.setup');
}
public function setup_update(Request $request)
{
$request->validate([
'site_name' => 'required|string|max:255',
'site_email' => 'required|string|email|max:255',
'site_address1' => 'required|string|max:255',
'site_address2' => 'nullable|string|max:255',
'site_city' => 'required|string|max:64',
'site_state' => 'required|string|max:32',
'site_postcode' => 'required|string|max:8',
'site_phone' => 'nullable|regex:/[0-9 ]+/|min:6|max:12',
'site_fax' => 'nullable|regex:/[0-9 ]+/|min:6|max:12',
]);
// If we are more input that sample data, reject the update.
if (config('SITE_SETUP')->allowed_keys(array_keys($request->except('_token'))))
return redirect()->back()
->withInput()
->withErrors('Invalid configuration - values not expected.');
foreach ($request->except('_token') as $key => $value)
{
if (! $value) {
SiteDetails::where('site_id',config('SITE_SETUP')->id)->where('key',$key)->delete();
} else {
try {
2018-08-07 04:26:33 +00:00
if ($key == 'site_logo' AND $value instanceof UploadedFile)
{
2018-08-08 23:33:51 +00:00
$path = $value->storeAs('site/'.config('SITE_SETUP')->id,$value->getClientOriginalName(),'public');
2018-08-07 04:26:33 +00:00
SiteDetails::updateOrCreate([
'site_id'=>config('SITE_SETUP')->id,
'key'=>$key,
],[
'value'=>$path,
]);
} else {
// Update or create our config record.
SiteDetails::updateOrCreate([
'site_id'=>config('SITE_SETUP')->id,
'key'=>$key,
],[
'value'=>$value,
]);
}
2018-07-31 04:11:00 +00:00
} catch (\Exception $e) {
2018-08-07 04:26:33 +00:00
Log::debug($e->getMessage(),['k'=>$key,'v'=>$value]);
2018-07-31 04:11:00 +00:00
}
}
}
return redirect()->back()
->with('success','Setup Updated!');;
}
}