Merge branch 'main' of https://github.com/WDI-Ideas/cheerstothe_season_laravel11 into sayli
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\APIs\RestaurantApi;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\APIs\RestaurantService\RestAuthApiService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class RestAuthApiController extends Controller
|
||||
{
|
||||
protected $RestAuthApiService;
|
||||
|
||||
public function __construct(RestAuthApiService $RestAuthApiService)
|
||||
{
|
||||
$this->RestAuthApiService = $RestAuthApiService;
|
||||
}
|
||||
|
||||
public function viewresyaurant()
|
||||
{
|
||||
try {
|
||||
$response = $this->RestAuthApiService->viewresyaurant();
|
||||
return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('FAW get data controller function failed: ' . $e->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function restRegister(Request $request)
|
||||
{
|
||||
try {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'first_name' => 'required|string|min:2|max:100',
|
||||
'last_name' => 'required|string|min:2|max:100',
|
||||
'role' => 'required|string|min:2|max:100',
|
||||
'restaurant_xid' => 'required',
|
||||
'date_of_birth' => 'required|date',
|
||||
'email_address' => [
|
||||
'required',
|
||||
'string',
|
||||
'email',
|
||||
'max:100',
|
||||
Rule::unique('iam_principal')->where(function ($query) {
|
||||
return $query->where('principal_type_xid', 4)->whereNull('deleted_at');
|
||||
}),
|
||||
],
|
||||
'phone_number' => 'required|min:10',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$validationErrors = $validator->errors()->all();
|
||||
Log::error("Registration validation error: " . implode(", ", $validationErrors));
|
||||
return jsonResponseWithErrorMessageApi($validationErrors, 403);
|
||||
}
|
||||
return $this->RestAuthApiService->restRegister($request);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error("Registration API Failed: " . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,12 +4,151 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\IamPrincipal;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\ManageRestaurant;
|
||||
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
// public function showDashboard(){
|
||||
|
||||
|
||||
return view('Admin.dashboard');
|
||||
// return view('Admin.dashboard');
|
||||
// }
|
||||
public function showDashboard()
|
||||
{
|
||||
|
||||
|
||||
// Fetching data for sorting by day
|
||||
// $dailyData = OrderedPassport::select(DB::raw("COUNT(*) as count"), DB::raw("DATE(created_at) as date"))
|
||||
// ->whereBetween('created_at', [now()->subDays(7), now()]) // Fetch data for the last 7 days
|
||||
// ->groupBy(DB::raw("DATE(created_at)"))
|
||||
// ->orderBy(DB::raw("DATE(created_at)"))
|
||||
// ->pluck('count', 'date')
|
||||
// ->toArray();
|
||||
|
||||
// Ensure that $dailyData contains zeros for days with no data
|
||||
$start_date = now()->subDays(7)->startOfDay();
|
||||
$end_date = now()->endOfDay();
|
||||
$formattedDailyData = [];
|
||||
while ($start_date <= $end_date) {
|
||||
$formattedDailyData[$start_date->format('Y-m-d')] = isset($dailyData[$start_date->format('Y-m-d')]) ? $dailyData[$start_date->format('Y-m-d')] : 0;
|
||||
$start_date->addDay();
|
||||
}
|
||||
|
||||
// Default sales chart data (monthly)
|
||||
// $defaultData = OrderedPassport::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
|
||||
// ->whereYear('created_at', date('Y'))
|
||||
// ->groupBy(DB::raw("MONTH(created_at)"))
|
||||
// ->orderBy(DB::raw("MONTH(created_at)"))
|
||||
// ->pluck('count', 'month')
|
||||
// ->toArray();
|
||||
|
||||
// Ensure that $defaultData contains zeros for months with no data
|
||||
$months = range(1, 12);
|
||||
$formattedDefaultData = [];
|
||||
foreach ($months as $month) {
|
||||
$formattedDefaultData[$month] = isset($defaultData[$month]) ? $defaultData[$month] : 0;
|
||||
}
|
||||
|
||||
// $quarterlyData = OrderedPassport::select(
|
||||
// DB::raw("COUNT(*) as count"),
|
||||
// DB::raw("QUARTER(created_at) as quarter")
|
||||
// )
|
||||
// ->whereYear('created_at', date('Y'))
|
||||
// ->groupBy(DB::raw("QUARTER(created_at)"))
|
||||
// ->orderBy(DB::raw("QUARTER(created_at)"))
|
||||
// ->pluck('count', 'quarter')
|
||||
// ->toArray();
|
||||
|
||||
// Ensure that $quarterlyData contains zeros for quarters with no data
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!isset($quarterlyData[$i])) {
|
||||
$quarterlyData[$i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Fetching data for yearly option
|
||||
// $yearlyData = OrderedPassport::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
|
||||
// ->groupBy(DB::raw("YEAR(created_at)"))
|
||||
// ->pluck('count', 'year')
|
||||
// ->toArray();
|
||||
//
|
||||
// Monthly data
|
||||
$dataMonthlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
|
||||
->whereIn('principal_type_xid', [3])
|
||||
->whereYear('created_at', date('Y'))
|
||||
->groupBy(DB::raw("MONTH(created_at)"))
|
||||
->orderBy(DB::raw("MONTH(created_at)"))
|
||||
->pluck('count', 'month')
|
||||
->toArray();
|
||||
|
||||
$dataMonthlyWithType4 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
|
||||
->whereIn('principal_type_xid', [4])
|
||||
->whereYear('created_at', date('Y'))
|
||||
->groupBy(DB::raw("MONTH(created_at)"))
|
||||
->orderBy(DB::raw("MONTH(created_at)"))
|
||||
->pluck('count', 'month')
|
||||
->toArray();
|
||||
|
||||
// Quarterly data
|
||||
$dataQuarterlyWithType3 = IamPrincipal::select(
|
||||
DB::raw("COUNT(*) as count"),
|
||||
DB::raw("QUARTER(created_at) as quarter")
|
||||
)
|
||||
->whereIn('principal_type_xid', [3])
|
||||
->groupBy(DB::raw("QUARTER(created_at)"))
|
||||
->orderBy(DB::raw("QUARTER(created_at)"))
|
||||
->pluck('count', 'quarter')
|
||||
->toArray();
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!isset($dataQuarterlyWithType3[$i])) {
|
||||
$dataQuarterlyWithType3[$i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$dataQuarterlyWithType4 = IamPrincipal::select(
|
||||
DB::raw("COUNT(*) as count"),
|
||||
DB::raw("QUARTER(created_at) as quarter")
|
||||
)
|
||||
->whereIn('principal_type_xid', [4])
|
||||
->groupBy(DB::raw("QUARTER(created_at)"))
|
||||
->orderBy(DB::raw("QUARTER(created_at)"))
|
||||
->pluck('count', 'quarter')
|
||||
->toArray();
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
if (!isset($dataQuarterlyWithType4[$i])) {
|
||||
$dataQuarterlyWithType4[$i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Yearly data
|
||||
$dataYearlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
|
||||
->whereIn('principal_type_xid', [3])
|
||||
->groupBy(DB::raw("YEAR(created_at)"))
|
||||
->pluck('count', 'year')
|
||||
->toArray();
|
||||
// dd($dataYearlyWithType3);
|
||||
|
||||
$dataYearlyWithType4 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
|
||||
->whereIn('principal_type_xid', [4])
|
||||
->groupBy(DB::raw("YEAR(created_at)"))
|
||||
->pluck('count', 'year')
|
||||
->toArray();
|
||||
|
||||
|
||||
$customerCount = IamPrincipal::where('principal_type_xid', '=', 3)->count();
|
||||
// $activePassports = ManagePassport::where('is_active', 1)->take(12)->get();
|
||||
// $restaurantCount = ManageRestaurant::where('is_redeem', 1)->count();
|
||||
$restaurantCount = ManageRestaurant::where('is_active', 1)->count();
|
||||
|
||||
// $recent_transaction = OrderedPassport::with('order', 'order_passport', 'carts.passport', 'iamPrincipal')->get()->toArray();
|
||||
// $datas = MyPassportVoucher::with('passportVouchers', 'passportData', 'customer')->get()->toArray();
|
||||
|
||||
// Pass the data to the view
|
||||
// return view('Admin.dashboard', compact('customerCount', 'activePassports', 'restaurantCount', 'recent_transaction', 'datas', 'formattedDefaultData', 'quarterlyData', 'yearlyData', 'dataMonthlyWithType3', 'dataMonthlyWithType4', 'dataQuarterlyWithType3', 'dataQuarterlyWithType4', 'dataYearlyWithType3', 'dataYearlyWithType4','formattedDailyData'));
|
||||
return view('Admin.dashboard', compact('customerCount','restaurantCount','dataMonthlyWithType3','dataMonthlyWithType4','dataQuarterlyWithType3', 'dataQuarterlyWithType4', 'dataYearlyWithType3', 'dataYearlyWithType4'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,162 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models\ManageModule;
|
||||
use App\Models\IamPrincipal;
|
||||
use App\Models\ManageModuleLink;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\Add_Subadmin;
|
||||
class ManageSubAdminController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
return view('Admin.pages.manage_users.manage_sub_admin.manage_subadmin');
|
||||
$sub_admins_module = ManageModule::latest()->get();
|
||||
$sub_admins_data = IamPrincipal::where('principal_type_xid', 2)->latest()->get();
|
||||
|
||||
return view('Admin.pages.manage_users.manage_sub_admin.manage_subadmin',compact('sub_admins_data','sub_admins_module'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$sub_admins_module = ManageModule::latest()->get();
|
||||
|
||||
return view('Admin.pages.manage_users.manage_sub_admin.create', compact('sub_admins_module'));
|
||||
}
|
||||
|
||||
public function store_subadmin(Request $request)
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
Created By : shailesh Gupta
|
||||
Created at : 29 May 2024
|
||||
Use : To store sub admin form and email
|
||||
*/
|
||||
try {
|
||||
|
||||
// DB::beginTransaction();
|
||||
|
||||
|
||||
$sub_admin = new IamPrincipal();
|
||||
$sub_admin->first_name = $request->input('sub_admin_name');
|
||||
$sub_admin->user_name = 'sub_admin';
|
||||
$sub_admin->principal_type_xid = 2;
|
||||
$sub_admin->principal_source_xid = Auth::guard('admin')->user()->principal_source_xid;
|
||||
$sub_admin->email_address = $request->input('sub_admin_email');
|
||||
$sub_admin->password = bcrypt($request->input('password'));
|
||||
$sub_admin->save();
|
||||
|
||||
|
||||
$moduleIds = $request->input('module_id');
|
||||
|
||||
foreach ($moduleIds as $moduleId) {
|
||||
|
||||
$sub_admin_permission = new ManageModuleLink;
|
||||
$sub_admin_permission->principal_xid = $sub_admin->id;
|
||||
$sub_admin_permission->manage_modules_xid = $moduleId;
|
||||
$sub_admin_permission->save();
|
||||
|
||||
}
|
||||
|
||||
$mailData =[
|
||||
'username'=>$request->input('sub_admin_name'),
|
||||
'password'=>$request->input('password'),
|
||||
];
|
||||
|
||||
|
||||
|
||||
// Mail::to($sub_admin->email_address)->send(new Add_Subadmin($mailData));
|
||||
$mail = Mail::to($request->input('sub_admin_email'))->send(new Add_Subadmin($mailData));
|
||||
// dd($mail);
|
||||
|
||||
// DB::commit();
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data'));
|
||||
// return response()->json(['status'=>200]);
|
||||
// return $voucher_data;
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error("restaurant Store Page Load Failed " . $e->getMessage());
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
public function edit($id)
|
||||
{
|
||||
// dd($id);
|
||||
$sub_admins_module = ManageModule::latest()->get();
|
||||
$edit_sub_admin = IamPrincipal::with(['moduleLinks' => function ($query) {
|
||||
$query->with('module');
|
||||
}])->find($id);
|
||||
return view('Admin.pages.manage_users.manage_sub_admin.edit', compact('edit_sub_admin', 'sub_admins_module'));
|
||||
}
|
||||
|
||||
public function delete_sub_admin($id)
|
||||
{
|
||||
/*
|
||||
Created By : Megha
|
||||
Created at : 14 Feb 2024
|
||||
Use : To Delete Admin.
|
||||
*/
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$passport = IamPrincipal::find($id);
|
||||
$passport->delete();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json(['success' => true, 'status' => 200]);
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error("delete_passport function Load Failed " . $e->getMessage());
|
||||
return response()->json(['success' => false, 'status' => 500, 'message' => __('auth.something_went_wrong')]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update_subadmin(Request $request)
|
||||
{
|
||||
/*
|
||||
Created By : Megha
|
||||
Created at : 14 Feb 2024
|
||||
Use : To update sub admin form.
|
||||
*/
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$sub_admin = IamPrincipal::find($request->sub_admin_id);
|
||||
$sub_admin->user_name = 'sub_admin';
|
||||
$sub_admin->first_name = $request->input('sub_admin_name');
|
||||
$sub_admin->principal_type_xid = 2;
|
||||
$sub_admin->principal_source_xid = Auth::guard('admin')->user()->principal_source_xid;
|
||||
$sub_admin->email_address = $request->input('sub_admin_email');
|
||||
// $sub_admin->password = bcrypt($request->input('password'));
|
||||
$sub_admin->save();
|
||||
|
||||
$moduleIds = $request->input('module_id');
|
||||
// dd($moduleIds);
|
||||
$update_module = ManageModuleLink::where('principal_xid', $sub_admin->id)->delete();
|
||||
|
||||
foreach ($moduleIds as $moduleId) {
|
||||
$sub_admin_permission = new ManageModuleLink;
|
||||
$sub_admin_permission->principal_xid = $sub_admin->id;
|
||||
$sub_admin_permission->manage_modules_xid = $moduleId;
|
||||
$sub_admin_permission->save();
|
||||
}
|
||||
|
||||
|
||||
DB::commit();
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data'));
|
||||
// return $voucher_data;
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error("restaurant Store Page Load Failed " . $e->getMessage());
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user