attempt(['email' => $request->email, 'password' => $request->password])) { return redirect()->route('admin.home')->with('success', 'Login Successfully'); } return redirect()->route('login')->with('error', 'Not Authenticate'); } public function search(Request $request) { $query = $request->input('query'); // Perform the search using the query $projects = project::where('business_name', 'like', '%' . $query . '%')->get(); // Pass the search term along with the projects to the view return view('project.index', compact('projects', 'query')); } public function getSalesData(Request $request) { $projects=project::all(); // Default to 'all time' if no filter is applied $filter = $request->get('filter', 'all'); // Get the date range based on the filter $dateRange = null; if ($filter == 'last_7_days') { $dateRange = Carbon::now()->subDays(7); } elseif ($filter == 'last_14_days') { $dateRange = Carbon::now()->subDays(14); } elseif ($filter == 'today') { $dateRange = Carbon::today(); } elseif ($filter == 'last_month') { // Get the start and end of the last month $dateRange = Carbon::now()->subMonth()->startOfMonth(); $endOfLastMonth = Carbon::now()->subMonth()->endOfMonth(); } // Filter the projects based on the date range if set $query = DB::table('projects'); if ($dateRange) { // If it's the last month filter, apply the start and end of the month if (isset($endOfLastMonth)) { $query->whereBetween('created_at', [$dateRange, $endOfLastMonth]); } else { $query->where('created_at', '>=', $dateRange); } } // Get revenue by BDE $revenueByBDE = $query ->select('bde_executive', DB::raw('SUM(amount_recieve) as total_revenue')) ->groupBy('bde_executive') ->get(); // Get total remaining balance for each BDE Executive $balanceByBDE = $query ->select('bde_executive', DB::raw('SUM(balance_remaing) as total_balance')) ->groupBy('bde_executive') ->get(); // Pass both data sets and filter to the view return view('admin.dashboard', compact('revenueByBDE', 'balanceByBDE', 'filter','projects')); } public function chart_builder() { return view('chart_builder'); } public function upload_excel(Request $request) { $request->validate([ 'excel_file' => 'required|mimes:xlsx,xls', ]); $file = $request->file('excel_file'); // Read the data from the Excel file $data = Excel::toArray([], $file); // Analyze the data to determine chart type $chartType = $this->detectChartType($data); // Pass the data and chart type to the view return view('chart_builder', compact('data', 'chartType')); } private function detectChartType($data) { // This is a simple analysis, you can extend this logic to detect more complex scenarios // Check for a single column of data and numeric values (ideal for a pie chart) if (count($data[0]) == 1) { return 'pie'; } // Check if the first column looks like a date (time-series data) if ($this->isDateColumn($data[0])) { return 'line'; // Time-series data often works best with line charts } // Check for multiple numeric columns (ideal for bar or line charts) return 'bar'; } private function isDateColumn($data) { // Check if the first column contains valid date values foreach ($data as $row) { if (strtotime($row[0]) === false) { return false; } } return true; } public function project() { // Fetch all projects, ordered by 'created_at' in descending order using latest() $projects = Project::latest()->get(); // Pass the projects to the view return view('project.index', ['projects' => $projects]); } public function filterProjects(Request $request) { // Get the filter value from the request $filter = $request->input('filter'); // Determine the date range based on the selected filter switch ($filter) { case '7_days': $projects = Project::where('created_at', '>=', Carbon::now()->subDays(7))->latest()->get(); break; case '14_days': $projects = Project::where('created_at', '>=', Carbon::now()->subDays(14))->latest()->get(); break; case 'last_month': $projects = Project::where('created_at', '>=', Carbon::now()->subMonth())->latest()->get(); break; default: $projects = Project::latest()->get(); break; } return view('project.index', ['projects' => $projects]); } public function project_form() { return view('project.form'); } public function project_add(Request $request) { // Save project data $project = new Project(); $project->fill($request->all()); $project->save(); // Generate the PDF instance $pdf = Pdf::loadView('pdf.form', ['project' => $project]); // Send the email with the generated PDF Mail::to('backend@sspsoftproindia.com')->send(new sendmail($project, $pdf)); Mail::to('gm@sspsoftproindia.com')->send(new sendmail($project, $pdf)); Mail::to('admin@sspsoftproindia.com')->send(new sendmail($project, $pdf)); //Mail::to('p327583@gmail.com')->send(new sendmail($project, $pdf)); // Mail::to('utsav6626@gmail.com')->send(new sendmail($project, $pdf)); return redirect()->route('project')->with('success', 'Project and Mail Sent Successfully'); } public function project_pdf($id) { // Fetch the project data (adjust your model accordingly) $project = \App\Models\project::findOrFail($id); // Pass the project data to the view and load it into DomPDF $pdf = Pdf::loadView('pdf.form', compact('project')); // Return the generated PDF to the browser for download return $pdf->stream('project-details.pdf'); } public function project_pdf_download($id) { // Fetch the project data (adjust your model accordingly) $project = \App\Models\project::findOrFail($id); // Pass the project data to the view and load it into DomPDF $pdf = Pdf::loadView('pdf.form', compact('project')); // Return the generated PDF to the browser for download return $pdf->download('project-details.pdf'); } public function project_delete($id) { $project = project::find($id); $project->delete(); return back()->with('success', 'Image Deleted Successfully'); } public function logout() { Session::flush('admin'); return redirect()->route('login'); } }