<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;

class notes_SINGLE_Controller extends Controller
{
    public $selfName = 'notes_SINGLE_Controller';
    public $dashboardName = 'dashboard';

	// GET /notes/view/{uid}/ACTION_signAsHcp
	public function ACTION_signAsHcp(Request $request, $uid) {
		$record = DB::table('note')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('note')->where('id', $uid)->first();
			if($record) return redirect('/notes/view/' . $record->uid . '/ACTION_signAsHcp');
		}
		return response()->view('pro/notes_SINGLE/ACTION_signAsHcp', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /notes/view/{uid}/SUB_dashboard
	public function SUB_dashboard(Request $request, $uid) {
		$record = DB::table('note')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('note')->where('id', $uid)->first();
			if($record) return redirect('/notes/view/' . $record->uid . '/SUB_dashboard');
		}
		return response()->view('pro/notes_SINGLE/SUB_dashboard', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /notes/view/{uid}/SUB_bills
	public function SUB_bills(Request $request, $uid) {
		$record = DB::table('note')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('note')->where('id', $uid)->first();
			if($record) return redirect('/notes/view/' . $record->uid . '/SUB_bills');
		}
		$subRecords = DB::table('bill')->where('note_id', $record->id)->get();
		return response()->view('pro/notes_SINGLE/SUB_bills', compact('record', 'subRecords'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /notes/view/{uid}/SUB_sections
	public function SUB_sections(Request $request, $uid) {
		$record = DB::table('note')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('note')->where('id', $uid)->first();
			if($record) return redirect('/notes/view/' . $record->uid . '/SUB_sections');
		}
		$subRecords = DB::table('section')->where('note_id', $record->id)->get();
		return response()->view('pro/notes_SINGLE/SUB_sections', compact('record', 'subRecords'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /notes/view/{uid}/ACTION_add_new_bill
	public function ACTION_add_new_bill(Request $request, $uid) {
		$record = DB::table('note')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('note')->where('id', $uid)->first();
			if($record) return redirect('/notes/view/' . $record->uid . '/ACTION_add_new_bill');
		}
		return response()->view('pro/notes_SINGLE/ACTION_add_new_bill', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}
}
