moduleUtil = $moduleUtil; } protected function authorizeAccess(): void { $business_id = request()->session()->get('user.business_id'); TelemarketingUtil::authorizeTelemarketing($this->moduleUtil, $business_id, 'crm.telemarketing.manage_offers'); } public function index() { $this->authorizeAccess(); $business_id = request()->session()->get('user.business_id'); if (request()->ajax()) { $query = CrmOfferCatalog::where('business_id', $business_id); return Datatables::of($query) ->addColumn('action', function ($row) { return ''; }) ->editColumn('offer_type', function ($row) { return CrmOfferCatalog::offerTypes()[$row->offer_type] ?? $row->offer_type; }) ->rawColumns(['action']) ->make(true); } $offerTypes = CrmOfferCatalog::offerTypes(); return view('crm::telemarketing.offers.index')->with(compact('offerTypes')); } public function store(Request $request) { $this->authorizeAccess(); $business_id = request()->session()->get('user.business_id'); CrmOfferCatalog::create(array_merge($request->only([ 'name', 'offer_type', 'description', 'min_cooperation_score', 'estimated_value', ]), [ 'business_id' => $business_id, 'target_industries' => $request->input('target_industries', []), 'required_signals' => $request->input('required_signals', []), 'is_active' => $request->boolean('is_active', true), 'created_by' => auth()->id(), ])); return response()->json(['success' => true, 'msg' => __('lang_v1.added_success')]); } public function update(Request $request, $id) { $this->authorizeAccess(); $business_id = request()->session()->get('user.business_id'); $offer = CrmOfferCatalog::where('business_id', $business_id)->findOrFail($id); $offer->update(array_merge($request->only([ 'name', 'offer_type', 'description', 'min_cooperation_score', 'estimated_value', ]), [ 'target_industries' => $request->input('target_industries', []), 'required_signals' => $request->input('required_signals', []), 'is_active' => $request->boolean('is_active', true), ])); return response()->json(['success' => true, 'msg' => __('lang_v1.updated_success')]); } public function companyOffers($company_id) { $this->authorizeAccess(); $business_id = request()->session()->get('user.business_id'); $offers = CrmCompanyOffer::whereHas('company', function ($q) use ($business_id, $company_id) { $q->where('business_id', $business_id)->where('id', $company_id); })->with('catalog')->get(); return view('crm::telemarketing.offers.company_offers')->with(compact('offers', 'company_id')); } }