public function patchEditAgent(Request $request) { $name = $request->input('name'); $value = $request->input('value'); $agent = Agents::where('id', $request->input('pk'))->first(); $agent->{$name} = $value; $agent->save(); return $value; }
public function sendToZipCode($inputs) { //Create a new text record $messageId = Appointment_Message::create(['lead_id' => $inputs['lead_id'], 'responses' => 0, 'zipcode' => $inputs['zipcode']]); $zipcode = Zipcode::find($inputs['zipcode']); $agents = AgentData::where('zip', $inputs['zipcode'])->groupBy('agent_id')->get([DB::raw("agent_id,zip,agent_id, COUNT(CASE WHEN source IN ('S','B') THEN 1 END) as closings,COUNT(CASE WHEN source IN ('O') THEN 1 END) as office,COUNT(CASE WHEN source IN ('H') THEN 1 END) as home,COUNT(CASE WHEN source IN ('A') THEN 1 END) as other")])->toArray(); $array_pop = $this->filterAgentsForCollection($agents, $zipcode); $agent_collection = Agents::where('mobile_phone', '!=', '')->where('is_active', 1)->where('days_red', '<=', $zipcode->min_red)->orderBy('agent_order', 'ASC')->find($array_pop); $agent_collection->add(['messageId' => $messageId->id]); return $agent_collection; }
/** * @param Request $request * @return mixed */ public function incomingAppointmentRequest(Request $request) { $inboundRequest = $request->all(); $body = $inboundRequest['Body']; $from_phone = $inboundRequest['From']; $appointmentMessage = Appointment_Message::find($body); if (!$appointmentMessage) { return response()->view('admin.messaging.responses.wrong_code')->header('Content-Type', 'text/xml'); } $agent = Agents::where('mobile_phone', $from_phone)->with('messages')->first(); $agent->messages()->attach($appointmentMessage->id); $zipcode = $appointmentMessage->zipcode; // No message exists, tell the user the wrong code was entered //Other wise, give the user feedback, fire an event and return xml to the user if ($appointmentMessage->responses == 0) { $appointmentMessage->responses = 1; $appointmentMessage->agent_id = $agent->id; $appointmentMessage->save(); //event(new AppointmentWasAssigned($agent)); return response()->view('admin.messaging.responses.lead_accepted', compact('zipcode', 'from_phone'))->header('Content-Type', 'text/xml'); } // Always assume failure and return the response return response()->view('admin.messaging.responses.lead_was_taken')->header('Content-Type', 'text/xml'); }