/** * Execute the console command. * * @return mixed */ public function fire() { $projects = []; foreach (Claim::month()->get() as $claim) { $projects[$claim->project_id][] = $claim; } foreach ($projects as $key => $claims) { $project = Project::find($key); $styleTd = 'style="border:1px solid #000;"'; $table = '<table cellpadding="2" cellspacing="0" style="margin: 0; width:100%;">'; $table .= "<tr><td {$styleTd}>id</td><td {$styleTd}>Дата</td><td {$styleTd}>Клиент</td><td {$styleTd}>Контактный телефон</td><td {$styleTd}>Описание</td><td {$styleTd}>Дата обратного звонка</td><td {$styleTd}>Статус</td>"; $propertiesPR = Property::where('model_initiator', '=', 'project')->where('link_id', '=', $key)->orderBy('sort')->get(); foreach ($propertiesPR as $property) { $table .= "<td {$styleTd}>" . $property->title . "</td>"; } $table .= "</tr>"; foreach ($claims as $claim) { $table .= "<tr>"; $table .= "<td {$styleTd}>{$claim->id}</td>"; $table .= "<td {$styleTd}>" . $claim->created_at->format('d.m.Y H:i') . "</td>"; $table .= "<td {$styleTd}>{$claim->name}</td>"; $table .= "<td {$styleTd}>{$claim->phone}</td>"; $table .= "<td {$styleTd}>{$claim->text}</td>"; $table .= "<td {$styleTd}>{$claim->backcall_at}</td>"; $table .= "<td {$styleTd}>" . $claim->statusT->title . "</td>"; $propertiesByTitle = []; $properties = \App\Property::showPropertyValue($claim); foreach ($properties as $prop) { $propertiesByTitle[$prop["title"]] = $prop["value"]; } foreach ($propertiesPR as $property) { if (!empty($propertiesByTitle[$property->title])) { $table .= "<td {$styleTd}>" . $propertiesByTitle[$property->title] . "</td>"; } else { $table .= "<td {$styleTd}></td>"; } } $table .= "</tr>"; } $table .= "</table>"; $title = "Отчет за месяц: " . $project->title; \Mail::send('emails.reports', compact('table', 'title'), function ($message) use($project) { $emails = ['*****@*****.**', '*****@*****.**']; /* $emails[] = $project->client->email; if(!empty($project->client->send_email)){ $emailsSplit = explode(",",$project->client->send_email); foreach($emailsSplit as $item) { $emails[] = trim($item); } } */ $message->to($emails, 'Callcenter №1')->subject('Круглосуточный call-центр №1'); }); } }
public function getClaims(Request $request) { if (!$request->has('key')) { abort('500', 'Key not found'); } $user = User::where('apikey', '=', $request->input('key'))->first(); if (is_null($user)) { abort('500', 'User with this key not found'); } $projects = Project::where('client_id', '=', $user->id)->get(); $claims = []; foreach ($projects as $project) { $claimCollection = Claim::where('project_id', '=', $project->id); if ($request->has('dts')) { $dtsObj = new \DateTime($request->input('dts')); if (get_class($dtsObj) !== "DateTime") { abor(500, 'Wrong date format'); } $claimCollection = $claimCollection->where('created_at', '>=', $dtsObj->format('Y-m-d H:i:s')); } if ($request->has('dte')) { $dteObj = new \DateTime($request->input('dte')); if (get_class($dteObj) !== "DateTime") { abor(500, 'Wrong date format'); } $claimCollection = $claimCollection->where('created_at', '<=', $dteObj->format('Y-m-d H:i:s')); } $claimCollection = $claimCollection->orderBy('created_at', "DESC")->get(); foreach ($claimCollection as $claim) { $claimEl["id"] = $claim->id; $claimEl["project"] = $project->title; $claimEl["title"] = $claim->title; $claimEl["text"] = $claim->text; $claimEl["note"] = $claim->note; $claimEl["phone"] = $claim->phone; $claimEl["backcall_at"] = $claim->backcall_at; $claimEl["created_at"] = $claim->created_at->format('Y-m-d H:i:s'); $claimEl["statusT"] = $claim->statusT->title; $claimEl['properties'] = []; foreach (\App\Property::showPropertyValue($claim) as $property) { $claimEl['properties'][$property["code"]] = $property['value']; } $claims[] = $claimEl; } } $response = new KodiResponse(); return $response->createResponse($claims, 200); }
/** * Execute the console command. * * @return mixed */ public function fire() { $projects = []; if ($this->argument('type') == "daily") { foreach (Claim::daily()->get() as $claim) { $projects[$claim->project_id][] = $claim; } } if ($this->argument('type') == "weekly") { foreach (Claim::weekly()->get() as $claim) { $projects[$claim->project_id][] = $claim; } } if ($this->argument('type') == "monthly") { foreach (Claim::monthly()->get() as $claim) { $projects[$claim->project_id][] = $claim; } } $this->drawTable($projects); }
/** * @param Request $request * @return Response */ public function postStatuschange(Request $request) { if (Auth::guest()) { if ($request::ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('auth/login'); } } $id = Request::get('id'); $claim = Claim::findOrFail($id); $claim->status = Request::get('status'); $claim->note = Request::get('note'); $claim->save(); return redirect("claim/{$id}"); }