Esempio n. 1
0
 /**
  * Handle the event.
  *
  * @param  ClaimCreate  $event
  * @return void
  */
 public function handle(ClaimCreate $event)
 {
     $claim = $event->claim;
     $properties = \App\Property::showPropertyValue($claim);
     $send = 1;
     $rType = $event->claim->typeR();
     if (!empty($rType)) {
         $send = $rType->send_mail;
     }
     if ($send == 1) {
         \Mail::send('emails.claimcreate', compact('claim', 'properties'), function ($message) use($event) {
             $emails = [];
             $emails[] = $event->claim->project->client->email;
             if (!empty($event->claim->project->client->send_email)) {
                 $emailsSplit = explode(",", $event->claim->project->client->send_email);
                 foreach ($emailsSplit as $item) {
                     $emails[] = trim($item);
                 }
             }
             Log::alert('Отправка письма ' . $event->claim->id . ", email:" . $event->claim->project->client->send_email . ", " . $event->claim->project->client->email);
             $res = $message->to($emails, 'Callcenter №1')->subject('Круглосуточный call-центр №1');
             Log::info(json_encode($res));
         });
     }
     if (!empty($event->destinations)) {
         \Mail::send('emails.claimcreate', compact('claim', 'properties'), function ($message) use($event) {
             $message->to($event->destinations, 'Callcenter №1')->subject('Круглосуточный call-центр №1');
         });
     }
 }
Esempio n. 2
0
 /**
  * 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');
         });
     }
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     try {
         $claim = Claim::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
     $properties = Property::getPropertyByModel($claim);
     $propertiesValue = \App\Property::showPropertyValue($claim);
     foreach ($properties as $property) {
         if (!empty($propertiesValue[$property->id]["value"])) {
             $property->value = $propertiesValue[$property->id]["value"];
         } else {
             $property->value = '';
         }
     }
     return view('claim.edit', compact('claim', 'properties'));
 }