<?php

namespace App\Http\Controllers;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	// GET /care_months/view/{uid}/SUB_dashboard
	public function SUB_dashboard(Request $request, $uid) {
		$record = DB::table('care_month')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('care_month')->where('id', $uid)->first();
			if($record) return redirect('/care_months/view/' . $record->uid . '/SUB_dashboard');
		}
		$result_clients = DB::select("select id, concat(name_first, ' ', name_last) as name_display from client");
		$result_pros = DB::select("SELECT id, name_display FROM pro");
		return response()->view('pro/care_months_SINGLE/SUB_dashboard', compact('record', 'result_clients', 'result_pros'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /care_months/view/{uid}/SUB_cm_time_entries
	public function SUB_cm_time_entries(Request $request, $uid) {
		$record = DB::table('care_month')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('care_month')->where('id', $uid)->first();
			if($record) return redirect('/care_months/view/' . $record->uid . '/SUB_cm_time_entries');
		}
		$subRecords = DB::table('care_month_entry')->where('care_month_id', $record->id)->where('cm_or_rm', 'CM')->get();
		return response()->view('pro/care_months_SINGLE/SUB_cm_time_entries', compact('record', 'subRecords'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /care_months/view/{uid}/SUB_rm_time_entries
	public function SUB_rm_time_entries(Request $request, $uid) {
		$record = DB::table('care_month')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('care_month')->where('id', $uid)->first();
			if($record) return redirect('/care_months/view/' . $record->uid . '/SUB_rm_time_entries');
		}
		$subRecords = DB::table('care_month_entry')->where('care_month_id', $record->id)->where('cm_or_rm', 'RM')->get();
		return response()->view('pro/care_months_SINGLE/SUB_rm_time_entries', compact('record', 'subRecords'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

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

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

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

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