Files
freeu-project/app/Http/Controllers/Admin/ManageLeadController.php

196 lines
6.2 KiB
PHP
Raw Normal View History

2024-03-28 14:52:40 +05:30
<?php
namespace App\Http\Controllers\Admin;
use App\Models\User;
use App\Models\Category;
use Illuminate\Http\Request;
use App\Traits\HttpResponse;
use App\Notifications\UserAdmin;
use App\Http\Controllers\Controller;
use App\Services\Admin\LeadService;
use App\Http\Requests\StoreLeadRequest;
use App\Http\Requests\StoreTaskRequest;
use App\Http\Requests\UpdateLeadRequest;
use App\Http\Requests\StoreNotesRequest;
use App\Http\Requests\StoreMeetingRequest;
use App\Http\Requests\StoreAttachmentsRequest;
class ManageLeadController extends Controller
{
use HttpResponse;
protected $lead;
public function __construct(LeadService $lead)
{
$this->lead = $lead;
}
public function index()
{
2024-04-09 17:56:07 +05:30
$check = checkSidebarAccess('manage-leads');
if (!$check) {
abort(404);
}
2024-03-28 14:52:40 +05:30
return view('Admin.Pages.manage_leads.manage_leads', [
'leads' => $this->lead->getAllLeads(),
'leadCount' => $this->lead->totalLead(),
'productName' => $this->lead->getAllProducts(),
'newCount' => $this->lead->newTotalLead(),
'ongoingCount' => $this->lead->ongoingTotalLead(),
'completedCount' => $this->lead->completedTotalLead(),
'oldCount' => $this->lead->oldTotalLead(),
'lostCount' => $this->lead->lostTotalLead()
]);
}
public function new_leads()
{
return view('Admin.Pages.manage_leads.new_leads', [
'leads' => $this->lead->newLeads(),
'productName' => $this->lead->getAllProducts()
]);
}
2024-04-26 18:40:07 +05:30
public function getInvestorDetail(Request $request)
{
$id = $request->id;
return response()->json([
'status'=>200,
'data'=>User::where('id',$id)->select('contact_number','email','name')->first(),
]);
}
2024-03-28 14:52:40 +05:30
public function ongoing_leads()
{
// return view('Admin.Pages.manage_leads.ongoing_leads');
// dd($this->lead->ongoingLeads());
return view('Admin.Pages.manage_leads.ongoing_leads', [
'leads' => $this->lead->ongoingLeads(),
'productName' => $this->lead->getAllProducts()
]);
}
public function completed_leads()
{
return view('Admin.Pages.manage_leads.completed_leads', [
'leads' => $this->lead->completedLeads(),
'productName' => $this->lead->getAllProducts()
]);
}
public function old_leads()
{
return view('Admin.Pages.manage_leads.old_leads', [
'leads' => $this->lead->oldLeads(),
'productName' => $this->lead->getAllProducts()
]);
}
public function lost_leads()
{
return view('Admin.Pages.manage_leads.lost_leads', [
'leads' => $this->lead->lostLeads(),
'productName' => $this->lead->getAllProducts()
]);
}
public function addLead()
{
return view('Admin.Pages.manage_leads.add_lead', [
'user' => User::admins()->active()->get(),
'investor' => User::users()->get(),
'categories' => Category::active()->get(),
]);
}
public function createLead(StoreLeadRequest $request)
{
$leadCreated = $this->lead->store($request);
$user = \Auth::user($request->lead_owner);
$notify['message'] = "You have been assigned a new lead!";
$type = 'Leads Assigned';
$user->notify(new UserAdmin($notify, $type));
return $leadCreated ?
$this->response('Lead Created Succesfully', 200) :
$this->response('Error Creating Lead!', 400);
}
public function viewLead($id)
{
return view('Admin.Pages.manage_leads.view-lead', [
'lead' => $this->lead->show($id)
]);
}
public function downloadFile(Request $request )
2024-03-28 14:52:40 +05:30
{
// dd($file_name);
$path = $request->query('path');
// dd("hello",$request->query('path'),$path['path']);
return $this->lead->download($path['path']);
2024-03-28 14:52:40 +05:30
}
public function editLead($id)
{
return view('Admin.Pages.manage_leads.edit-lead', [
'lead' => $this->lead->edit($id),
'users' => User::admins()->get(),
'investor' => User::users()->get(),
]);
}
public function updateLead(UpdateLeadRequest $request)
{
$leadUpdated = $this->lead->update($request);
return $leadUpdated ?
$this->response('Lead updated successfully', 200) :
$this->response('Lead not updated. Error!!', 400);
}
public function createNotes(StoreNotesRequest $request)
{
$leadNoteAdded = $this->lead->storeNote($request);
return $leadNoteAdded ?
$this->response('Lead Note Created Succesfully!', 200) :
$this->response('Error Creating Lead Note!', 400);
}
public function createAttachments(StoreAttachmentsRequest $request)
{
$leadAttachmentAdded = $this->lead->storeAttachments($request);
return $leadAttachmentAdded ?
$this->response('Lead Attached Created Succesfully!', 200) :
$this->response('Error Creating Lead Attachment!', 400);
}
public function sortNotes(Request $request)
{
return $this->lead->sortNotes($request);
}
public function createTask(StoreTaskRequest $request)
{
$taskCreated = $this->lead->storeTasks($request);
return $taskCreated ?
$this->response('Lead Task Created Succesfully!', 200) :
$this->response('Error Creating Lead Task!', 400);
}
public function createMeeting(StoreMeetingRequest $request)
{
$meetingCreated = $this->lead->storeMeetings($request);
return $meetingCreated ?
$this->response('Lead Meeting Created Succesfully!', 200) :
$this->response('Error Creating Lead Meeting!', 400);
}
public function convertClosed(Request $request)
{
$convertClosed = $this->lead->convertActivity($request);
2024-04-25 11:40:12 +05:30
// dd(convertClosed);
2024-03-28 14:52:40 +05:30
return $convertClosed ?
$this->response('Converted To Closed Activity Succesfully!', 200) :
$this->response('Error Converting it to Closed Activity!', 400);
}
2024-04-09 17:56:07 +05:30
}