Commit 1b48ee4fb1c452f0eb72f33cacb849e2d57d4c0d

Authored by Hayk Nazaryan
1 parent eff54ff661
Exists in master

export fix

Showing 1 changed file with 5 additions and 10 deletions Inline Diff

app/Http/Controllers/WorkerController.php
1 <?php 1 <?php
2 2
3 namespace App\Http\Controllers; 3 namespace App\Http\Controllers;
4 4
5 use App\Classes\RusDate; 5 use App\Classes\RusDate;
6 use App\Classes\Tools; 6 use App\Classes\Tools;
7 use App\Http\Requests\DocumentsRequest; 7 use App\Http\Requests\DocumentsRequest;
8 use App\Http\Requests\PrevCompanyRequest; 8 use App\Http\Requests\PrevCompanyRequest;
9 use App\Http\Requests\SertificationRequest; 9 use App\Http\Requests\SertificationRequest;
10 use App\Models\Ad_employer; 10 use App\Models\Ad_employer;
11 use App\Models\ad_response; 11 use App\Models\ad_response;
12 use App\Models\Chat; 12 use App\Models\Chat;
13 use App\Models\Dop_info; 13 use App\Models\Dop_info;
14 use App\Models\Employer; 14 use App\Models\Employer;
15 use App\Models\EmployerAutoliftOption; 15 use App\Models\EmployerAutoliftOption;
16 use App\Models\infobloks; 16 use App\Models\infobloks;
17 use App\Models\Job_title; 17 use App\Models\Job_title;
18 use App\Models\Like_vacancy; 18 use App\Models\Like_vacancy;
19 use App\Models\Message; 19 use App\Models\Message;
20 use App\Models\place_works; 20 use App\Models\place_works;
21 use App\Models\PrevCompany; 21 use App\Models\PrevCompany;
22 use App\Models\ResponseWork; 22 use App\Models\ResponseWork;
23 use App\Models\sertification; 23 use App\Models\sertification;
24 use App\Models\Static_worker; 24 use App\Models\Static_worker;
25 use App\Models\Title_worker; 25 use App\Models\Title_worker;
26 use App\Models\User; 26 use App\Models\User;
27 use App\Models\User as User_Model; 27 use App\Models\User as User_Model;
28 use App\Models\Worker; 28 use App\Models\Worker;
29 use App\Models\WorkerAutoliftOption; 29 use App\Models\WorkerAutoliftOption;
30 use Barryvdh\DomPDF\Facade\Pdf; 30 use Barryvdh\DomPDF\Facade\Pdf;
31 use Carbon\Carbon; 31 use Carbon\Carbon;
32 use Illuminate\Auth\Events\Registered; 32 use Illuminate\Auth\Events\Registered;
33 use Illuminate\Database\Eloquent\Builder; 33 use Illuminate\Database\Eloquent\Builder;
34 use Illuminate\Http\RedirectResponse; 34 use Illuminate\Http\RedirectResponse;
35 use Illuminate\Http\Request; 35 use Illuminate\Http\Request;
36 use Illuminate\Pagination\LengthAwarePaginator; 36 use Illuminate\Pagination\LengthAwarePaginator;
37 use Illuminate\Support\Facades\Auth; 37 use Illuminate\Support\Facades\Auth;
38 use Illuminate\Support\Facades\DB; 38 use Illuminate\Support\Facades\DB;
39 use Illuminate\Support\Facades\Hash; 39 use Illuminate\Support\Facades\Hash;
40 use Illuminate\Support\Facades\Storage; 40 use Illuminate\Support\Facades\Storage;
41 use Illuminate\Support\Facades\Validator; 41 use Illuminate\Support\Facades\Validator;
42 use Illuminate\View\View; 42 use Illuminate\View\View;
43 use JsonException; 43 use JsonException;
44 use PhpOffice\PhpSpreadsheet\Spreadsheet; 44 use PhpOffice\PhpSpreadsheet\Spreadsheet;
45 use PhpOffice\PhpSpreadsheet\Writer\Xlsx; 45 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
46 use Symfony\Component\HttpFoundation\StreamedResponse; 46 use Symfony\Component\HttpFoundation\StreamedResponse;
47 use App\Enums\DbExportColumns; 47 use App\Enums\DbExportColumns;
48 use App\Enums\WorkerStatuses; 48 use App\Enums\WorkerStatuses;
49 use DateTime; 49 use DateTime;
50 50
51 class WorkerController extends Controller 51 class WorkerController extends Controller
52 { 52 {
53 //профиль 53 //профиль
54 public function profile(Worker $worker) 54 public function profile(Worker $worker)
55 { 55 {
56 $get_date = date('Y.m'); 56 $get_date = date('Y.m');
57 57
58 $c = Static_worker::query()->where('year_month', '=', $get_date) 58 $c = Static_worker::query()->where('year_month', '=', $get_date)
59 ->where('user_id', '=', $worker->users->id) 59 ->where('user_id', '=', $worker->users->id)
60 ->get(); 60 ->get();
61 61
62 if ($c->count() > 0) { 62 if ($c->count() > 0) {
63 $upd = Static_worker::find($c[0]->id); 63 $upd = Static_worker::find($c[0]->id);
64 $upd->lookin = $upd->lookin + 1; 64 $upd->lookin = $upd->lookin + 1;
65 $upd->save(); 65 $upd->save();
66 } else { 66 } else {
67 $crt = new Static_worker(); 67 $crt = new Static_worker();
68 $crt->lookin = 1; 68 $crt->lookin = 1;
69 $crt->year_month = $get_date; 69 $crt->year_month = $get_date;
70 $crt->user_id = $worker->user_id; 70 $crt->user_id = $worker->user_id;
71 $crt->save(); 71 $crt->save();
72 } 72 }
73 73
74 $stat = Static_worker::query()->where('year_month', '=', $get_date) 74 $stat = Static_worker::query()->where('year_month', '=', $get_date)
75 ->where('user_id', '=', $worker->users->id) 75 ->where('user_id', '=', $worker->users->id)
76 ->get(); 76 ->get();
77 77
78 return view('public.workers.profile', compact('worker', 'stat')); 78 return view('public.workers.profile', compact('worker', 'stat'));
79 } 79 }
80 80
81 // лист база резюме 81 // лист база резюме
82 public function bd_resume(Request $request) 82 public function bd_resume(Request $request)
83 { 83 {
84 if (isset(Auth()->user()->id)) { 84 if (isset(Auth()->user()->id)) {
85 if ((Auth()->user()->is_worker) || (!Auth()->user()->is_lookin)) 85 if ((Auth()->user()->is_worker) || (!Auth()->user()->is_lookin))
86 return redirect()->route('index')->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]); 86 return redirect()->route('index')->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]);
87 } 87 }
88 88
89 $status_work = WorkerStatuses::getWorkerStatuses(); 89 $status_work = WorkerStatuses::getWorkerStatuses();
90 90
91 $resumes = Worker::query()->with('users')->with('job_titles')->orderByDesc('updated_at'); 91 $resumes = Worker::query()->with('users')->with('job_titles')->orderByDesc('updated_at');
92 $resumes = $resumes->whereHas('users', function (Builder $query) { 92 $resumes = $resumes->whereHas('users', function (Builder $query) {
93 $query->Where('is_worker', '=', '1') 93 $query->Where('is_worker', '=', '1')
94 ->Where('is_bd', '=', '0'); 94 ->Where('is_bd', '=', '0');
95 }); 95 });
96 96
97 if (($request->has('job')) && ($request->get('job') > 0)) { 97 if (($request->has('job')) && ($request->get('job') > 0)) {
98 $resumes = $resumes->whereHas('job_titles', function (Builder $query) use ($request) { 98 $resumes = $resumes->whereHas('job_titles', function (Builder $query) use ($request) {
99 $query->Where('job_titles.id', $request->get('job')); 99 $query->Where('job_titles.id', $request->get('job'));
100 }); 100 });
101 } 101 }
102 102
103 $Job_title = Job_title::query() 103 $Job_title = Job_title::query()
104 ->where('is_remove', '=', '0') 104 ->where('is_remove', '=', '0')
105 ->where('is_bd', '=' , '1') 105 ->where('is_bd', '=' , '1')
106 ->orderByDesc('sort') 106 ->orderByDesc('sort')
107 ->get(); 107 ->get();
108 108
109 if ($request->get('sort')) { 109 if ($request->get('sort')) {
110 $sort = $request->get('sort'); 110 $sort = $request->get('sort');
111 switch ($sort) { 111 switch ($sort) {
112 case 'looking_for_work': 112 case 'looking_for_work':
113 $resumes->where('status_work', '=', WorkerStatuses::LookingForWork->value); 113 $resumes->where('status_work', '=', WorkerStatuses::LookingForWork->value);
114 break; 114 break;
115 case 'considering_offers': 115 case 'considering_offers':
116 $resumes->where('status_work', '=', WorkerStatuses::ConsideringOffers->value); 116 $resumes->where('status_work', '=', WorkerStatuses::ConsideringOffers->value);
117 break; 117 break;
118 case 'not_looking_for_work': 118 case 'not_looking_for_work':
119 $resumes->where('status_work', '=', WorkerStatuses::NotLookingForWork->value); 119 $resumes->where('status_work', '=', WorkerStatuses::NotLookingForWork->value);
120 break; 120 break;
121 } 121 }
122 } 122 }
123 123
124 $resumes = $resumes->get()->filter(function ($worker) { 124 $resumes = $resumes->get()->filter(function ($worker) {
125 return Tools::getWorkerProfilePercent($worker) >= 50; 125 return Tools::getWorkerProfilePercent($worker) >= 50;
126 }); 126 });
127 127
128 $res_count = $resumes->count(); 128 $res_count = $resumes->count();
129 129
130 $currentPage = $_GET['page'] ?? 1; 130 $currentPage = $_GET['page'] ?? 1;
131 $resumes = new LengthAwarePaginator( 131 $resumes = new LengthAwarePaginator(
132 items: $resumes->slice(4 * ($currentPage - 1), 4), 132 items: $resumes->slice(4 * ($currentPage - 1), 4),
133 total: $res_count, 133 total: $res_count,
134 perPage: 4, 134 perPage: 4,
135 ); 135 );
136 $resumes->setPath('bd-resume'); 136 $resumes->setPath('bd-resume');
137 137
138 if ($request->ajax()) { 138 if ($request->ajax()) {
139 // Условия обставлены 139 // Условия обставлены
140 if ($request->has('block') && ($request->get('block') == 1)) { 140 if ($request->has('block') && ($request->get('block') == 1)) {
141 return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count')); 141 return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count'));
142 } 142 }
143 } else { 143 } else {
144 return view('resume', compact('resumes', 'status_work', 'res_count', 'Job_title')); 144 return view('resume', compact('resumes', 'status_work', 'res_count', 'Job_title'));
145 } 145 }
146 } 146 }
147 147
148 public function basic_information(){ 148 public function basic_information(){
149 if (!isset(Auth()->user()->id)) { 149 if (!isset(Auth()->user()->id)) {
150 abort(404); 150 abort(404);
151 } 151 }
152 152
153 $user_id = Auth()->user()->id; 153 $user_id = Auth()->user()->id;
154 154
155 $user = User::query() 155 $user = User::query()
156 ->with('workers') 156 ->with('workers')
157 ->with(['jobtitles' => function ($query) { 157 ->with(['jobtitles' => function ($query) {
158 $query->select('job_titles.id'); 158 $query->select('job_titles.id');
159 }]) 159 }])
160 ->where('id', '=', $user_id) 160 ->where('id', '=', $user_id)
161 ->first(); 161 ->first();
162 $user->workers[0]->job_titles = $user->workers[0]->job_titles->pluck('id')->toArray(); 162 $user->workers[0]->job_titles = $user->workers[0]->job_titles->pluck('id')->toArray();
163 163
164 $job_titles = Job_title::query() 164 $job_titles = Job_title::query()
165 ->where('is_remove', '=', 0) 165 ->where('is_remove', '=', 0)
166 ->where('is_bd', '=', 1) 166 ->where('is_bd', '=', 1)
167 ->orderByDesc('sort') 167 ->orderByDesc('sort')
168 ->get() 168 ->get()
169 ; 169 ;
170 170
171 return view('workers.form_basic_information', compact('user', 'job_titles')); 171 return view('workers.form_basic_information', compact('user', 'job_titles'));
172 } 172 }
173 173
174 public function additional_documents(){ 174 public function additional_documents(){
175 if (!isset(Auth()->user()->id)) { 175 if (!isset(Auth()->user()->id)) {
176 abort(404); 176 abort(404);
177 } 177 }
178 178
179 $user_id = Auth()->user()->id; 179 $user_id = Auth()->user()->id;
180 180
181 $info_blocks = infobloks::query()->OrderBy('name')->get(); 181 $info_blocks = infobloks::query()->OrderBy('name')->get();
182 $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует']; 182 $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует'];
183 183
184 $worker = Worker::query() 184 $worker = Worker::query()
185 ->with('users') 185 ->with('users')
186 ->with('infobloks') 186 ->with('infobloks')
187 ->WhereHas('users', function (Builder $query) use ($user_id) { 187 ->WhereHas('users', function (Builder $query) use ($user_id) {
188 $query->Where('id', $user_id); 188 $query->Where('id', $user_id);
189 }) 189 })
190 ->first(); 190 ->first();
191 if ($worker->dop_info->count()){ 191 if ($worker->dop_info->count()){
192 $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray(); 192 $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray();
193 } 193 }
194 194
195 return view('workers.form_additional_documents', compact('worker', 'info_blocks', 'additional_document_statuses')); 195 return view('workers.form_additional_documents', compact('worker', 'info_blocks', 'additional_document_statuses'));
196 } 196 }
197 197
198 //Лайк резюме 198 //Лайк резюме
199 public function like_controller() { 199 public function like_controller() {
200 200
201 } 201 }
202 202
203 // анкета соискателя 203 // анкета соискателя
204 public function resume_profile(Worker $worker) 204 public function resume_profile(Worker $worker)
205 { 205 {
206 if (isset(Auth()->user()->id)) { 206 if (isset(Auth()->user()->id)) {
207 $idiot = Auth()->user()->id; 207 $idiot = Auth()->user()->id;
208 } else { 208 } else {
209 $idiot = 0; 209 $idiot = 0;
210 } 210 }
211 211
212 $status_work = WorkerStatuses::getWorkerStatuses(); 212 $status_work = WorkerStatuses::getWorkerStatuses();
213 $Query = Worker::query()->with('users')->with('job_titles') 213 $Query = Worker::query()->with('users')->with('job_titles')
214 ->with('place_worker')->with('sertificate')->with('prev_company') 214 ->with('place_worker')->with('sertificate')->with('prev_company')
215 ->with('infobloks')->with('response'); 215 ->with('infobloks')->with('response');
216 $Query = $Query->where('id', '=', $worker->id); 216 $Query = $Query->where('id', '=', $worker->id);
217 $Query = $Query->get(); 217 $Query = $Query->get();
218 218
219 $get_date = date('Y.m'); 219 $get_date = date('Y.m');
220 220
221 $infoblocks = infobloks::query()->get(); 221 $infoblocks = infobloks::query()->get();
222 222
223 $c = Static_worker::query()->where('year_month', '=', $get_date) 223 $c = Static_worker::query()->where('year_month', '=', $get_date)
224 ->where('user_id', '=', $worker->user_id) 224 ->where('user_id', '=', $worker->user_id)
225 ->get(); 225 ->get();
226 226
227 if ($c->count() > 0) { 227 if ($c->count() > 0) {
228 $upd = Static_worker::find($c[0]->id); 228 $upd = Static_worker::find($c[0]->id);
229 $upd->lookin = $upd->lookin + 1; 229 $upd->lookin = $upd->lookin + 1;
230 $upd->save(); 230 $upd->save();
231 } else { 231 } else {
232 $crt = new Static_worker(); 232 $crt = new Static_worker();
233 $crt->lookin = 1; 233 $crt->lookin = 1;
234 $crt->year_month = $get_date; 234 $crt->year_month = $get_date;
235 $crt->user_id = $worker->user_id; 235 $crt->user_id = $worker->user_id;
236 $status = $crt->save(); 236 $status = $crt->save();
237 } 237 }
238 238
239 $stat = Static_worker::query()->where('year_month', '=', $get_date) 239 $stat = Static_worker::query()->where('year_month', '=', $get_date)
240 ->where('user_id', '=', $worker->user_id) 240 ->where('user_id', '=', $worker->user_id)
241 ->get(); 241 ->get();
242 242
243 return view('worker', compact('Query', 'infoblocks', 'status_work', 'idiot', 'stat')); 243 return view('worker', compact('Query', 'infoblocks', 'status_work', 'idiot', 'stat'));
244 } 244 }
245 245
246 // скачать анкету соискателя 246 // скачать анкету соискателя
247 public function resume_download(Worker $worker) 247 public function resume_download(Worker $worker)
248 { 248 {
249 $status_work = WorkerStatuses::getWorkerStatuses(); 249 $status_work = WorkerStatuses::getWorkerStatuses();
250 $Query = Worker::query()->with('users')->with('job_titles') 250 $Query = Worker::query()->with('users')->with('job_titles')
251 ->with('place_worker')->with('sertificate')->with('prev_company') 251 ->with('place_worker')->with('sertificate')->with('prev_company')
252 ->with('infobloks'); 252 ->with('infobloks');
253 $Query = $Query->where('id', '=', $worker->id); 253 $Query = $Query->where('id', '=', $worker->id);
254 $Query = $Query->get(); 254 $Query = $Query->get();
255 255
256 view()->share('Query',$Query); 256 view()->share('Query',$Query);
257 257
258 $status_work = WorkerStatuses::getWorkerStatuses(); 258 $status_work = WorkerStatuses::getWorkerStatuses();
259 $infoblocks = infobloks::query()->get(); 259 $infoblocks = infobloks::query()->get();
260 260
261 //return view('layout.pdf', compact('Query', 'status_work', 'infoblocks')); 261 //return view('layout.pdf', compact('Query', 'status_work', 'infoblocks'));
262 $pdf = PDF::loadView('layout.pdf', [ 262 $pdf = PDF::loadView('layout.pdf', [
263 'Query' => $Query, 263 'Query' => $Query,
264 'status_work' => $status_work, 264 'status_work' => $status_work,
265 'infoblocks' => $infoblocks 265 'infoblocks' => $infoblocks
266 ])->setPaper('a4', 'landscape'); 266 ])->setPaper('a4', 'landscape');
267 267
268 return $pdf->download(); 268 return $pdf->download();
269 } 269 }
270 270
271 public function resume_download_all(Request $request) { 271 public function resume_download_all(Request $request) {
272 $spreadsheet = new Spreadsheet(); 272 $spreadsheet = new Spreadsheet();
273 $sheet = $spreadsheet->getActiveSheet(); 273 $sheet = $spreadsheet->getActiveSheet();
274 274
275 $columnMap = range('A', 'Z'); 275 $columnMap = range('A', 'Z');
276 $columns = []; 276 $columns = [];
277 277
278 foreach (DbExportColumns::toArray() as $key => $value){ 278 foreach (DbExportColumns::toArray() as $key => $value){
279 if ($request->input($key, 0)){ 279 if ($request->input($key, 0)){
280 $sheet->setCellValue("{$columnMap[count($columns)]}1", ucfirst($value)); 280 $sheet->setCellValue("{$columnMap[count($columns)]}1", ucfirst($value));
281 $columns[] = str_replace('__', '.', $key); 281 $columns[] = str_replace('__', '.', $key);
282 } 282 }
283 } 283 }
284 284
285 if (empty($columns)) { 285 if (empty($columns)) {
286 return redirect()->back()->with('error', 'Пожалуйста выберите хотя бы 1 колонку для экспорта.'); 286 return redirect()->back()->with('error', 'Пожалуйста выберите хотя бы 1 колонку для экспорта.');
287 } 287 }
288 288
289 $jobIds = $request->input('job_title_list', []); 289 $jobIds = $request->input('job_title_list', []);
290 290
291 /* //query for mysql ver 8.0 or higher 291 /* //query for mysql ver 8.0 or higher
292 $users = DB::select( 292 $users = DB::select(
293 "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` 293 "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone`
294 from users 294 from users
295 join workers on `users`.`id` = `workers`.`user_id` 295 join workers on `users`.`id` = `workers`.`user_id`
296 join `job_titles` 296 join `job_titles`
297 where `users`.`is_bd` = 1 297 where `users`.`is_bd` = 1
298 and (`workers`.`position_work` = `job_titles`.`id` 298 and (`workers`.`position_work` = `job_titles`.`id`
299 or exists (select 1 299 or exists (select 1
300 from JSON_TABLE( 300 from JSON_TABLE(
301 workers.positions_work, 301 workers.positions_work,
302 '$[*]' COLUMNS (id INT PATH '$')) pw 302 '$[*]' COLUMNS (id INT PATH '$')) pw
303 where pw.id = job_titles.id) 303 where pw.id = job_titles.id)
304 )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') 304 )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '')
305 );*/ 305 );*/
306 306
307 $users = DB::select( 307 $users = DB::select("SELECT`job_titles`.`name`,`users`.`surname`,`users`.`name_man`,`users`.`surname2`,`users`.`email`,`users`.`telephone` FROM users
308 "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` 308 JOIN workers ON `users`.`id` = `workers`.`user_id`
309 from users 309 JOIN job_titles ON (`workers`.`position_work` = `job_titles`.`id`
310 join workers on `users`.`id` = `workers`.`user_id` 310 OR JSON_CONTAINS(`workers`.`positions_work`, JSON_QUOTE(CAST(`job_titles`.`id` AS CHAR)), '$'))
311 join `job_titles` 311 WHERE `users`.`is_bd` = 1 " . ((!empty($jobIds)) ? 'AND job_titles.id IN (' . implode(',', $jobIds) . ')' : '') . "");
312 where `users`.`is_bd` = 1
313 and (`workers`.`position_work` = `job_titles`.`id`
314 or `workers`.`positions_work`
315 )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '')
316 );
317 312
318 $users = collect($users); 313 $users = collect($users);
319 314
320 if ($users->count()) { 315 if ($users->count()) {
321 $i = 2; 316 $i = 2;
322 foreach ($users->toArray() as $user){ 317 foreach ($users->toArray() as $user){
323 $j = 0; 318 $j = 0;
324 foreach ($user as $field){ 319 foreach ($user as $field){
325 $sheet->setCellValue("{$columnMap[$j++]}$i", $field); 320 $sheet->setCellValue("{$columnMap[$j++]}$i", $field);
326 } 321 }
327 $i++; 322 $i++;
328 } 323 }
329 } 324 }
330 $writer = new Xlsx($spreadsheet); 325 $writer = new Xlsx($spreadsheet);
331 $fileName = 'DB.xlsx'; 326 $fileName = 'DB.xlsx';
332 327
333 $response = new StreamedResponse(function() use ($writer) { 328 $response = new StreamedResponse(function() use ($writer) {
334 $writer->save('php://output'); 329 $writer->save('php://output');
335 }); 330 });
336 331
337 $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 332 $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
338 $response->headers->set('Content-Disposition', 'attachment;filename="' . $fileName . '"'); 333 $response->headers->set('Content-Disposition', 'attachment;filename="' . $fileName . '"');
339 $response->headers->set('Cache-Control', 'max-age=0'); 334 $response->headers->set('Cache-Control', 'max-age=0');
340 335
341 return $response; 336 return $response;
342 } 337 }
343 338
344 // Кабинет работника 339 // Кабинет работника
345 public function cabinet(Request $request) 340 public function cabinet(Request $request)
346 { 341 {
347 // дата год и месяц 342 // дата год и месяц
348 $get_date = date('Y.m'); 343 $get_date = date('Y.m');
349 344
350 $id = Auth()->user()->id; 345 $id = Auth()->user()->id;
351 346
352 $Infobloks = infobloks::query()->get(); 347 $Infobloks = infobloks::query()->get();
353 348
354 $Worker = Worker::query() 349 $Worker = Worker::query()
355 ->with(['users', 'sertificate', 'prev_company', 'infobloks', 'place_worker']) 350 ->with(['users', 'sertificate', 'prev_company', 'infobloks', 'place_worker'])
356 ->WhereHas('users', function (Builder $query) use ($id) { 351 ->WhereHas('users', function (Builder $query) use ($id) {
357 $query->Where('id', $id); 352 $query->Where('id', $id);
358 })->first(); 353 })->first();
359 354
360 $Job_titles = Job_title::query()->where('is_remove', '=', '0') 355 $Job_titles = Job_title::query()->where('is_remove', '=', '0')
361 ->where('is_bd', '=' , '1') 356 ->where('is_bd', '=' , '1')
362 ->OrderByDesc('sort')->OrderBy('name') 357 ->OrderByDesc('sort')->OrderBy('name')
363 ->get(); 358 ->get();
364 359
365 $stat = Static_worker::query()->where('year_month', '=', $get_date) 360 $stat = Static_worker::query()->where('year_month', '=', $get_date)
366 ->where('user_id', '=', $id) 361 ->where('user_id', '=', $id)
367 ->get(); 362 ->get();
368 363
369 $persent = Tools::getWorkerProfilePercent($Worker); 364 $persent = Tools::getWorkerProfilePercent($Worker);
370 365
371 $status_work = WorkerStatuses::getWorkerStatuses(); 366 $status_work = WorkerStatuses::getWorkerStatuses();
372 $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует']; 367 $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует'];
373 $info_blocks = infobloks::query()->OrderBy('name')->get(); 368 $info_blocks = infobloks::query()->OrderBy('name')->get();
374 369
375 $worker = Worker::query() 370 $worker = Worker::query()
376 ->with('users') 371 ->with('users')
377 ->with('sertificate') 372 ->with('sertificate')
378 ->with('prev_company') 373 ->with('prev_company')
379 ->with('infobloks') 374 ->with('infobloks')
380 ->with('place_worker') 375 ->with('place_worker')
381 ->with('job_titles') 376 ->with('job_titles')
382 ->WhereHas('users', function (Builder $query) use ($id) { 377 ->WhereHas('users', function (Builder $query) use ($id) {
383 $query->Where('id', $id); 378 $query->Where('id', $id);
384 }) 379 })
385 ->first(); 380 ->first();
386 if ($worker->dop_info->count()){ 381 if ($worker->dop_info->count()){
387 $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray(); 382 $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray();
388 } 383 }
389 384
390 //dd($worker->dop_info); 385 //dd($worker->dop_info);
391 386
392 if ($request->has('print')) { 387 if ($request->has('print')) {
393 dd($Worker); 388 dd($Worker);
394 } else { 389 } else {
395 return view('workers.cabinet', compact( 'persent', 'Job_titles', 'stat', 390 return view('workers.cabinet', compact( 'persent', 'Job_titles', 'stat',
396 'worker', 'info_blocks', 'status_work', 'additional_document_statuses' 391 'worker', 'info_blocks', 'status_work', 'additional_document_statuses'
397 )); 392 ));
398 } 393 }
399 } 394 }
400 395
401 // Сохранение данных 396 // Сохранение данных
402 public function cabinet_save(Worker $worker, Request $request) 397 public function cabinet_save(Worker $worker, Request $request)
403 { 398 {
404 $id = $worker->id; 399 $id = $worker->id;
405 $params = $request->all(); 400 $params = $request->all();
406 $job_title_id = $request->get('job_title_id'); 401 $job_title_id = $request->get('job_title_id');
407 402
408 $rules = [ 403 $rules = [
409 'surname' => ['required', 'string', 'max:255'], 404 'surname' => ['required', 'string', 'max:255'],
410 'name_man' => ['required', 'string', 'max:255'], 405 'name_man' => ['required', 'string', 'max:255'],
411 'email' => ['required', 'string', 'email', 'max:255'], 406 'email' => ['required', 'string', 'email', 'max:255'],
412 407
413 ]; 408 ];
414 409
415 $messages = [ 410 $messages = [
416 'required' => 'Укажите обязательное поле', 411 'required' => 'Укажите обязательное поле',
417 'min' => [ 412 'min' => [
418 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 413 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
419 'integer' => 'Поле «:attribute» должно быть :min или больше', 414 'integer' => 'Поле «:attribute» должно быть :min или больше',
420 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 415 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
421 ], 416 ],
422 'max' => [ 417 'max' => [
423 'string' => 'Поле «:attribute» должно быть не больше :max символов', 418 'string' => 'Поле «:attribute» должно быть не больше :max символов',
424 'integer' => 'Поле «:attribute» должно быть :max или меньше', 419 'integer' => 'Поле «:attribute» должно быть :max или меньше',
425 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 420 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
426 ] 421 ]
427 ]; 422 ];
428 423
429 $validator = Validator::make($params, $rules, $messages); 424 $validator = Validator::make($params, $rules, $messages);
430 425
431 if ($validator->fails()) { 426 if ($validator->fails()) {
432 return redirect()->route('worker.cabinet')->withErrors($validator); 427 return redirect()->route('worker.cabinet')->withErrors($validator);
433 } else { 428 } else {
434 429
435 if ($request->has('photo')) { 430 if ($request->has('photo')) {
436 if (!empty($worker->photo)) { 431 if (!empty($worker->photo)) {
437 Storage::delete($worker->photo); 432 Storage::delete($worker->photo);
438 } 433 }
439 $params['photo'] = $request->file('photo')->store("worker/$id", 'public'); 434 $params['photo'] = $request->file('photo')->store("worker/$id", 'public');
440 } 435 }
441 436
442 if ($request->has('file')) { 437 if ($request->has('file')) {
443 if (!empty($worker->file)) { 438 if (!empty($worker->file)) {
444 Storage::delete($worker->file); 439 Storage::delete($worker->file);
445 } 440 }
446 $params['file'] = $request->file('file')->store("worker/$id", 'public'); 441 $params['file'] = $request->file('file')->store("worker/$id", 'public');
447 } 442 }
448 443
449 $worker->update($params); 444 $worker->update($params);
450 $use = User::find($worker->user_id); 445 $use = User::find($worker->user_id);
451 $use->surname = $request->get('surname'); 446 $use->surname = $request->get('surname');
452 $use->name_man = $request->get('name_man'); 447 $use->name_man = $request->get('name_man');
453 $use->surname2 = $request->get('surname2'); 448 $use->surname2 = $request->get('surname2');
454 449
455 $use->save(); 450 $use->save();
456 $worker->job_titles()->sync($job_title_id); 451 $worker->job_titles()->sync($job_title_id);
457 452
458 return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены'); 453 return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены');
459 } 454 }
460 } 455 }
461 456
462 public function cabinet_save_foto(Worker $worker, Request $request){ 457 public function cabinet_save_foto(Worker $worker, Request $request){
463 $params = ['photo' => null]; 458 $params = ['photo' => null];
464 459
465 if ($request->has('photo')) { 460 if ($request->has('photo')) {
466 if (!empty($worker->photo)) { 461 if (!empty($worker->photo)) {
467 Storage::delete($worker->photo); 462 Storage::delete($worker->photo);
468 } 463 }
469 $params['photo'] = $request->file('photo')->store("worker/$worker->id", 'public'); 464 $params['photo'] = $request->file('photo')->store("worker/$worker->id", 'public');
470 } 465 }
471 466
472 if ($request->has('file')) { 467 if ($request->has('file')) {
473 if (!empty($worker->file)) { 468 if (!empty($worker->file)) {
474 Storage::delete($worker->file); 469 Storage::delete($worker->file);
475 } 470 }
476 $params['file'] = $request->file('file')->store("worker/$worker->id", 'public'); 471 $params['file'] = $request->file('file')->store("worker/$worker->id", 'public');
477 } 472 }
478 473
479 $worker->update($params); 474 $worker->update($params);
480 475
481 return redirect()->route('worker.cabinet'); 476 return redirect()->route('worker.cabinet');
482 } 477 }
483 478
484 // Сообщения данные 479 // Сообщения данные
485 public function messages($type_message) 480 public function messages($type_message)
486 { 481 {
487 $user_id = Auth()->user()->id; 482 $user_id = Auth()->user()->id;
488 483
489 $chats = Chat::get_user_chats($user_id); 484 $chats = Chat::get_user_chats($user_id);
490 $admin_chat = Chat::get_user_admin_chat($user_id); 485 $admin_chat = Chat::get_user_admin_chat($user_id);
491 $user_type = 'worker'; 486 $user_type = 'worker';
492 487
493 return view('workers.messages', compact('chats', 'admin_chat','user_id', 'user_type')); 488 return view('workers.messages', compact('chats', 'admin_chat','user_id', 'user_type'));
494 } 489 }
495 490
496 // Избранный 491 // Избранный
497 public function favorite() 492 public function favorite()
498 { 493 {
499 return view('workers.favorite'); 494 return view('workers.favorite');
500 } 495 }
501 496
502 // Сменить пароль 497 // Сменить пароль
503 public function new_password() 498 public function new_password()
504 { 499 {
505 $email = Auth()->user()->email; 500 $email = Auth()->user()->email;
506 return view('workers.new_password', compact('email')); 501 return view('workers.new_password', compact('email'));
507 } 502 }
508 503
509 // Обновление пароля 504 // Обновление пароля
510 public function save_new_password(Request $request) { 505 public function save_new_password(Request $request) {
511 $use = Auth()->user(); 506 $use = Auth()->user();
512 $request->validate([ 507 $request->validate([
513 'password' => 'required|string', 508 'password' => 'required|string',
514 'new_password' => 'required|string', 509 'new_password' => 'required|string',
515 'new_password2' => 'required|string' 510 'new_password2' => 'required|string'
516 ]); 511 ]);
517 512
518 if ($request->get('new_password') == $request->get('new_password2')) 513 if ($request->get('new_password') == $request->get('new_password2'))
519 if ($request->get('password') !== $request->get('new_password')) { 514 if ($request->get('password') !== $request->get('new_password')) {
520 $credentials = $request->only('email', 'password'); 515 $credentials = $request->only('email', 'password');
521 if (Auth::attempt($credentials, $request->has('save_me'))) { 516 if (Auth::attempt($credentials, $request->has('save_me'))) {
522 517
523 if (!is_null($use->email_verified_at)){ 518 if (!is_null($use->email_verified_at)){
524 519
525 $user_data = User_Model::find($use->id); 520 $user_data = User_Model::find($use->id);
526 $user_data->update([ 521 $user_data->update([
527 'password' => Hash::make($request->get('new_password')), 522 'password' => Hash::make($request->get('new_password')),
528 'pubpassword' => base64_encode($request->get('new_password')), 523 'pubpassword' => base64_encode($request->get('new_password')),
529 ]); 524 ]);
530 return redirect() 525 return redirect()
531 ->route('worker.new_password') 526 ->route('worker.new_password')
532 ->with('success', 'Поздравляю! Вы обновили свой пароль!'); 527 ->with('success', 'Поздравляю! Вы обновили свой пароль!');
533 } 528 }
534 529
535 return redirect() 530 return redirect()
536 ->route('worker.new_password') 531 ->route('worker.new_password')
537 ->withError('Данная учетная запись не было верифицированна!'); 532 ->withError('Данная учетная запись не было верифицированна!');
538 } 533 }
539 } 534 }
540 535
541 return redirect() 536 return redirect()
542 ->route('worker.new_password') 537 ->route('worker.new_password')
543 ->withErrors('Не совпадение данных, обновите пароли!'); 538 ->withErrors('Не совпадение данных, обновите пароли!');
544 } 539 }
545 540
546 // Удаление профиля форма 541 // Удаление профиля форма
547 public function delete_profile() 542 public function delete_profile()
548 { 543 {
549 $login = Auth()->user()->email; 544 $login = Auth()->user()->email;
550 return view('workers.delete_profile', compact('login')); 545 return view('workers.delete_profile', compact('login'));
551 } 546 }
552 547
553 // Удаление профиля код 548 // Удаление профиля код
554 public function delete_profile_result(Request $request) { 549 public function delete_profile_result(Request $request) {
555 $Answer = $request->all(); 550 $Answer = $request->all();
556 $user_id = Auth()->user()->id; 551 $user_id = Auth()->user()->id;
557 $request->validate([ 552 $request->validate([
558 'password' => 'required|string', 553 'password' => 'required|string',
559 ]); 554 ]);
560 555
561 $credentials = $request->only('email', 'password'); 556 $credentials = $request->only('email', 'password');
562 if (Auth::attempt($credentials)) { 557 if (Auth::attempt($credentials)) {
563 Auth::logout(); 558 Auth::logout();
564 $it = User_Model::find($user_id); 559 $it = User_Model::find($user_id);
565 $it->delete(); 560 $it->delete();
566 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); 561 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт');
567 } else { 562 } else {
568 return redirect()->route('worker.delete_profile') 563 return redirect()->route('worker.delete_profile')
569 ->withErrors( 'Неверный пароль! Нужен корректный пароль'); 564 ->withErrors( 'Неверный пароль! Нужен корректный пароль');
570 } 565 }
571 } 566 }
572 567
573 // Регистрация соискателя 568 // Регистрация соискателя
574 public function register_worker(Request $request) 569 public function register_worker(Request $request)
575 { 570 {
576 $params = $request->all(); 571 $params = $request->all();
577 $params['is_worker'] = 1; 572 $params['is_worker'] = 1;
578 573
579 $rules = [ 574 $rules = [
580 'surname' => ['required', 'string', 'max:255'], 575 'surname' => ['required', 'string', 'max:255'],
581 'name_man' => ['required', 'string', 'max:255'], 576 'name_man' => ['required', 'string', 'max:255'],
582 'email' => ['required', 'email', 'max:255', 'unique:users'], 577 'email' => ['required', 'email', 'max:255', 'unique:users'],
583 'password' => ['required', 'string', 'min:6'] 578 'password' => ['required', 'string', 'min:6']
584 ]; 579 ];
585 580
586 $messages = [ 581 $messages = [
587 'required' => 'Укажите обязательное поле', 582 'required' => 'Укажите обязательное поле',
588 'min' => [ 583 'min' => [
589 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 584 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
590 'integer' => 'Поле «:attribute» должно быть :min или больше', 585 'integer' => 'Поле «:attribute» должно быть :min или больше',
591 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 586 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
592 ], 587 ],
593 'max' => [ 588 'max' => [
594 'string' => 'Поле «:attribute» должно быть не больше :max символов', 589 'string' => 'Поле «:attribute» должно быть не больше :max символов',
595 'integer' => 'Поле «:attribute» должно быть :max или меньше', 590 'integer' => 'Поле «:attribute» должно быть :max или меньше',
596 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 591 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
597 ] 592 ]
598 ]; 593 ];
599 594
600 $email = $request->get('email'); 595 $email = $request->get('email');
601 if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) { 596 if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) {
602 return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл")); 597 return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл"));
603 } 598 }
604 599
605 if ($request->get('password') !== $request->get('confirmed')){ 600 if ($request->get('password') !== $request->get('confirmed')){
606 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); 601 return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля"));
607 } 602 }
608 603
609 if (strlen($request->get('password')) < 6) { 604 if (strlen($request->get('password')) < 6) {
610 return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!")); 605 return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!"));
611 } 606 }
612 607
613 if (($request->has('politik')) && ($request->get('politik') == 1)) { 608 if (($request->has('politik')) && ($request->get('politik') == 1)) {
614 $validator = Validator::make($params, $rules, $messages); 609 $validator = Validator::make($params, $rules, $messages);
615 610
616 if ($validator->fails()) { 611 if ($validator->fails()) {
617 return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); 612 return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе."));
618 } else { 613 } else {
619 $user = $this->create($params); 614 $user = $this->create($params);
620 event(new Registered($user)); 615 event(new Registered($user));
621 Auth::guard()->login($user); 616 Auth::guard()->login($user);
622 } 617 }
623 if ($user) { 618 if ($user) {
624 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));; 619 return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));;
625 } else { 620 } else {
626 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!")); 621 return json_encode(Array("ERROR" => "Error2: Данные были утеряны!"));
627 } 622 }
628 623
629 } else { 624 } else {
630 return json_encode(Array("ERROR" => "Error3: Вы не согласились с политикой конфидициальности!")); 625 return json_encode(Array("ERROR" => "Error3: Вы не согласились с политикой конфидициальности!"));
631 } 626 }
632 } 627 }
633 628
634 // Звездная оценка и ответ 629 // Звездная оценка и ответ
635 public function stars_answer(Request $request) { 630 public function stars_answer(Request $request) {
636 $params = $request->all(); 631 $params = $request->all();
637 $rules = [ 632 $rules = [
638 'message' => ['required', 'string', 'max:255'], 633 'message' => ['required', 'string', 'max:255'],
639 ]; 634 ];
640 635
641 $messages = [ 636 $messages = [
642 'required' => 'Укажите обязательное поле', 637 'required' => 'Укажите обязательное поле',
643 'min' => [ 638 'min' => [
644 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 639 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
645 'integer' => 'Поле «:attribute» должно быть :min или больше', 640 'integer' => 'Поле «:attribute» должно быть :min или больше',
646 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 641 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
647 ], 642 ],
648 'max' => [ 643 'max' => [
649 'string' => 'Поле «:attribute» должно быть не больше :max символов', 644 'string' => 'Поле «:attribute» должно быть не больше :max символов',
650 'integer' => 'Поле «:attribute» должно быть :max или меньше', 645 'integer' => 'Поле «:attribute» должно быть :max или меньше',
651 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 646 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
652 ] 647 ]
653 ]; 648 ];
654 $response_worker = ResponseWork::create($params); 649 $response_worker = ResponseWork::create($params);
655 return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!'); 650 return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!');
656 } 651 }
657 652
658 public function TestWorker() 653 public function TestWorker()
659 { 654 {
660 $Use = new User(); 655 $Use = new User();
661 656
662 $Code_user = $Use->create([ 657 $Code_user = $Use->create([
663 'name' => 'surname name_man', 658 'name' => 'surname name_man',
664 'name_man' => 'name_man', 659 'name_man' => 'name_man',
665 'surname' => 'surname', 660 'surname' => 'surname',
666 'surname2' => 'surname2', 661 'surname2' => 'surname2',
667 'subscribe_email' => '1', 662 'subscribe_email' => '1',
668 'email' => 'email@mail.com', 663 'email' => 'email@mail.com',
669 'telephone' => '1234567890', 664 'telephone' => '1234567890',
670 'password' => Hash::make('password'), 665 'password' => Hash::make('password'),
671 'pubpassword' => base64_encode('password'), 666 'pubpassword' => base64_encode('password'),
672 'email_verified_at' => Carbon::now(), 667 'email_verified_at' => Carbon::now(),
673 'is_worker' => 1, 668 'is_worker' => 1,
674 ]); 669 ]);
675 670
676 if ($Code_user->id > 0) { 671 if ($Code_user->id > 0) {
677 $Worker = new Worker(); 672 $Worker = new Worker();
678 $Worker->user_id = $Code_user->id; 673 $Worker->user_id = $Code_user->id;
679 $Worker->position_work = 1; //'job_titles'; 674 $Worker->position_work = 1; //'job_titles';
680 $Worker->email = 'email@email.com'; 675 $Worker->email = 'email@email.com';
681 $Worker->telephone = '1234567890'; 676 $Worker->telephone = '1234567890';
682 $status = $Worker->save(); 677 $status = $Worker->save();
683 678
684 $Title_Worker = new Title_worker(); 679 $Title_Worker = new Title_worker();
685 $Title_Worker->worker_id = $Worker->id; 680 $Title_Worker->worker_id = $Worker->id;
686 $Title_Worker->job_title_id = 1; 681 $Title_Worker->job_title_id = 1;
687 $Title_Worker->save(); 682 $Title_Worker->save();
688 } 683 }
689 } 684 }
690 685
691 // Создание пользователя 686 // Создание пользователя
692 protected function create(array $data) 687 protected function create(array $data)
693 { 688 {
694 $Use = new User(); 689 $Use = new User();
695 690
696 $Code_user = $Use->create([ 691 $Code_user = $Use->create([
697 'name' => $data['surname']." ".$data['name_man'], 692 'name' => $data['surname']." ".$data['name_man'],
698 'name_man' => $data['name_man'], 693 'name_man' => $data['name_man'],
699 'surname' => $data['surname'], 694 'surname' => $data['surname'],
700 'surname2' => $data['surname2'], 695 'surname2' => $data['surname2'],
701 'subscribe_email' => $data['email'], 696 'subscribe_email' => $data['email'],
702 'email' => $data['email'], 697 'email' => $data['email'],
703 'telephone' => $data['telephone'], 698 'telephone' => $data['telephone'],
704 'password' => Hash::make($data['password']), 699 'password' => Hash::make($data['password']),
705 'pubpassword' => base64_encode($data['password']), 700 'pubpassword' => base64_encode($data['password']),
706 'email_verified_at' => Carbon::now(), 701 'email_verified_at' => Carbon::now(),
707 'is_worker' => $data['is_worker'], 702 'is_worker' => $data['is_worker'],
708 ]); 703 ]);
709 704
710 if ($Code_user->id > 0) { 705 if ($Code_user->id > 0) {
711 $Worker = new Worker(); 706 $Worker = new Worker();
712 $Worker->user_id = $Code_user->id; 707 $Worker->user_id = $Code_user->id;
713 $Worker->position_work = $data['job_titles']; 708 $Worker->position_work = $data['job_titles'];
714 $Worker->email = $data['email']; 709 $Worker->email = $data['email'];
715 $Worker->telephone = $data['telephone']; 710 $Worker->telephone = $data['telephone'];
716 $Worker->save(); 711 $Worker->save();
717 712
718 if (isset($Worker->id)) { 713 if (isset($Worker->id)) {
719 $Title_Worker = new Title_worker(); 714 $Title_Worker = new Title_worker();
720 $Title_Worker->worker_id = $Worker->id; 715 $Title_Worker->worker_id = $Worker->id;
721 $Title_Worker->job_title_id = $data['job_titles']; 716 $Title_Worker->job_title_id = $data['job_titles'];
722 $Title_Worker->save(); 717 $Title_Worker->save();
723 } 718 }
724 719
725 return $Code_user; 720 return $Code_user;
726 } 721 }
727 } 722 }
728 723
729 // Вакансии избранные 724 // Вакансии избранные
730 public function colorado(Request $request) { 725 public function colorado(Request $request) {
731 $Arr = Like_vacancy::Query() 726 $Arr = Like_vacancy::Query()
732 ->select('code_record') 727 ->select('code_record')
733 ->where('user_id', Auth::user()->id) 728 ->where('user_id', Auth::user()->id)
734 ->get(); 729 ->get();
735 730
736 if ($Arr->count()) { 731 if ($Arr->count()) {
737 $A = Array(); 732 $A = Array();
738 foreach ($Arr as $it) { 733 foreach ($Arr as $it) {
739 $A[] = $it->code_record; 734 $A[] = $it->code_record;
740 } 735 }
741 736
742 $Query = Ad_employer::query()->whereIn('id', $A); 737 $Query = Ad_employer::query()->whereIn('id', $A);
743 } else { 738 } else {
744 $Query = Ad_employer::query()->where('id', '=', '0'); 739 $Query = Ad_employer::query()->where('id', '=', '0');
745 } 740 }
746 741
747 $Query = $Query->with(['jobs', 'cat', 'employer']) 742 $Query = $Query->with(['jobs', 'cat', 'employer'])
748 ->whereHas('jobs_code', function ($query) use ($request) { 743 ->whereHas('jobs_code', function ($query) use ($request) {
749 if ($request->ajax()) { 744 if ($request->ajax()) {
750 if (null !== ($request->get('job'))) { 745 if (null !== ($request->get('job'))) {
751 $query->where('job_title_id', $request->get('job')); 746 $query->where('job_title_id', $request->get('job'));
752 } 747 }
753 } 748 }
754 }) 749 })
755 ->select('ad_employers.*'); 750 ->select('ad_employers.*');
756 751
757 if ($request->get('search') !== null) { 752 if ($request->get('search') !== null) {
758 $search = $request->get('search'); 753 $search = $request->get('search');
759 $Query->where('name', 'LIKE', "%$search%"); 754 $Query->where('name', 'LIKE', "%$search%");
760 } 755 }
761 756
762 //dd($Query->get()); 757 //dd($Query->get());
763 758
764 $Job_title = Job_title::query()->OrderBy('name')->get(); 759 $Job_title = Job_title::query()->OrderBy('name')->get();
765 760
766 $Query_count = $Query->count(); 761 $Query_count = $Query->count();
767 762
768 $Query = $Query->OrderBy('updated_at')->paginate(3); 763 $Query = $Query->OrderBy('updated_at')->paginate(3);
769 764
770 return view('workers.favorite', compact('Query', 765 return view('workers.favorite', compact('Query',
771 'Query_count', 766 'Query_count',
772 'Job_title')); 767 'Job_title'));
773 768
774 } 769 }
775 770
776 //Переписка 771 //Переписка
777 public function dialog(Chat $chat, Request $request) { 772 public function dialog(Chat $chat, Request $request) {
778 // Получение параметров. 773 // Получение параметров.
779 if ($request->has('ad_employer')){ 774 if ($request->has('ad_employer')){
780 $ad_employer = $request->get('ad_employer'); 775 $ad_employer = $request->get('ad_employer');
781 } else { 776 } else {
782 $ad_employer = 0; 777 $ad_employer = 0;
783 } 778 }
784 779
785 $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first(); 780 $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first();
786 $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first(); 781 $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first();
787 782
788 $Messages = Chat::get_chat_messages($chat); 783 $Messages = Chat::get_chat_messages($chat);
789 784
790 Message::where('chat_id_to', '=', $chat->id)->update(['flag_new' => 0]); 785 Message::where('chat_id_to', '=', $chat->id)->update(['flag_new' => 0]);
791 786
792 return view('workers.dialog', compact('companion', 'sender', 'chat', 'Messages', 'ad_employer')); 787 return view('workers.dialog', compact('companion', 'sender', 'chat', 'Messages', 'ad_employer'));
793 } 788 }
794 789
795 // Даунылоады 790 // Даунылоады
796 public function download(Worker $worker) { 791 public function download(Worker $worker) {
797 $arr_house = ['0' => 'Проверка, проверка, проверка, проверка, проверка...']; 792 $arr_house = ['0' => 'Проверка, проверка, проверка, проверка, проверка...'];
798 view()->share('house',$arr_house); 793 view()->share('house',$arr_house);
799 $pdf = PDF::loadView('layout.pdf', $arr_house)->setPaper('a4', 'landscape'); 794 $pdf = PDF::loadView('layout.pdf', $arr_house)->setPaper('a4', 'landscape');
800 return $pdf->stream(); 795 return $pdf->stream();
801 } 796 }
802 797
803 // Поднятие анкеты 798 // Поднятие анкеты
804 public function up(Worker $worker) { 799 public function up(Worker $worker) {
805 $worker->updated_at = Carbon::now(); 800 $worker->updated_at = Carbon::now();
806 $worker->save(); 801 $worker->save();
807 // 0 802 // 0
808 return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных'); 803 return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных');
809 } 804 }
810 805
811 // Форма сертификате 806 // Форма сертификате
812 public function new_sertificate(Worker $worker) { 807 public function new_sertificate(Worker $worker) {
813 return view('workers.sertificate_add', compact('worker')); 808 return view('workers.sertificate_add', compact('worker'));
814 } 809 }
815 810
816 // Добавление сертификата 811 // Добавление сертификата
817 public function add_serificate(SertificationRequest $request) { 812 public function add_serificate(SertificationRequest $request) {
818 $request->validate([ 813 $request->validate([
819 'name' => 'required|string|max:255', 814 'name' => 'required|string|max:255',
820 'end_begin' => 'required|date|date_format:d.m.Y' 815 'end_begin' => 'required|date|date_format:d.m.Y'
821 ], 816 ],
822 [ 817 [
823 'name' => 'Навание сертификата обязательно для заполнения.', 818 'name' => 'Навание сертификата обязательно для заполнения.',
824 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг' 819 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг'
825 ]); 820 ]);
826 821
827 $params = $request->all(); 822 $params = $request->all();
828 823
829 $end_begin = DateTime::createFromFormat('d.m.Y', $params['end_begin']); 824 $end_begin = DateTime::createFromFormat('d.m.Y', $params['end_begin']);
830 $params['end_begin'] = $end_begin->format('Y-m-d'); 825 $params['end_begin'] = $end_begin->format('Y-m-d');
831 826
832 $Sertificate = new sertification(); 827 $Sertificate = new sertification();
833 $Sertificate->create($params); 828 $Sertificate->create($params);
834 829
835 return response()->json([ 830 return response()->json([
836 'success' => true 831 'success' => true
837 ]); 832 ]);
838 } 833 }
839 834
840 // Удалить сертификат 835 // Удалить сертификат
841 public function delete_sertificate(sertification $doc) { 836 public function delete_sertificate(sertification $doc) {
842 $doc->delete(); 837 $doc->delete();
843 838
844 return redirect()->route('worker.cabinet'); 839 return redirect()->route('worker.cabinet');
845 } 840 }
846 841
847 // Редактирование сертификата 842 // Редактирование сертификата
848 public function edit_sertificate(Worker $worker, sertification $doc) { 843 public function edit_sertificate(Worker $worker, sertification $doc) {
849 return view('workers.sertificate_edit', compact('doc', 'worker')); 844 return view('workers.sertificate_edit', compact('doc', 'worker'));
850 } 845 }
851 846
852 // Редактирование обновление сертификата 847 // Редактирование обновление сертификата
853 public function update_serificate(SertificationRequest $request, sertification $doc) { 848 public function update_serificate(SertificationRequest $request, sertification $doc) {
854 $request->validate([ 849 $request->validate([
855 'name' => 'required|string|max:255', 850 'name' => 'required|string|max:255',
856 'end_begin' => 'required|date|date_format:d.m.Y' 851 'end_begin' => 'required|date|date_format:d.m.Y'
857 ], 852 ],
858 [ 853 [
859 'name' => 'Навание сертификата обязательно для заполнения.', 854 'name' => 'Навание сертификата обязательно для заполнения.',
860 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг' 855 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг'
861 ]); 856 ]);
862 857
863 $all = $request->all(); 858 $all = $request->all();
864 859
865 $end_begin = DateTime::createFromFormat('d.m.Y', $all['end_begin']); 860 $end_begin = DateTime::createFromFormat('d.m.Y', $all['end_begin']);
866 $all['end_begin'] = $end_begin->format('Y-m-d'); 861 $all['end_begin'] = $end_begin->format('Y-m-d');
867 862
868 $doc->worker_id = $all['worker_id']; 863 $doc->worker_id = $all['worker_id'];
869 $doc->name = $all['name']; 864 $doc->name = $all['name'];
870 $doc->end_begin = $all['end_begin']; 865 $doc->end_begin = $all['end_begin'];
871 $doc->save(); 866 $doc->save();
872 867
873 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!'); 868 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!');
874 } 869 }
875 870
876 public function edit_diploms(Request $request, Worker $worker) { 871 public function edit_diploms(Request $request, Worker $worker) {
877 $dop_info_data = $request->input('diploms'); 872 $dop_info_data = $request->input('diploms');
878 873
879 if (empty($dop_info_data)) { 874 if (empty($dop_info_data)) {
880 return redirect()->route('worker.additional_documents')->with('error', 'Данные не предоставлены!'); 875 return redirect()->route('worker.additional_documents')->with('error', 'Данные не предоставлены!');
881 } 876 }
882 877
883 foreach ($dop_info_data as $infoblok_id => $status) { 878 foreach ($dop_info_data as $infoblok_id => $status) {
884 Dop_info::updateOrCreate( 879 Dop_info::updateOrCreate(
885 ['worker_id' => $worker->id, 'infoblok_id' => $infoblok_id], 880 ['worker_id' => $worker->id, 'infoblok_id' => $infoblok_id],
886 ['status' => $status] 881 ['status' => $status]
887 ); 882 );
888 } 883 }
889 884
890 return redirect()->route('worker.additional_documents')->with('success', 'Успешно сохранено!'); 885 return redirect()->route('worker.additional_documents')->with('success', 'Успешно сохранено!');
891 } 886 }
892 887
893 public function delete_add_diplom(Request $request, Worker $worker) { 888 public function delete_add_diplom(Request $request, Worker $worker) {
894 $infoblok_id = $request->get('infoblok_id'); 889 $infoblok_id = $request->get('infoblok_id');
895 890
896 if (Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->count() > 0) 891 if (Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->count() > 0)
897 $id = Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->delete(); 892 $id = Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->delete();
898 else { 893 else {
899 $params['infoblok_id'] = $infoblok_id; 894 $params['infoblok_id'] = $infoblok_id;
900 $params['worker_id'] = $worker->id; 895 $params['worker_id'] = $worker->id;
901 $params['status'] = $request->get('val'); 896 $params['status'] = $request->get('val');
902 $id = Dop_info::create($params); 897 $id = Dop_info::create($params);
903 //$id = $worker->infobloks()->sync([$infoblok_id]); 898 //$id = $worker->infobloks()->sync([$infoblok_id]);
904 } 899 }
905 900
906 //$Infoblocks = infobloks::query()->get(); 901 //$Infoblocks = infobloks::query()->get();
907 return $id; //redirect()->route('worker.cabinet')->getTargetUrl(); //view('workers.ajax.diploms_dop', compact('worker', 'Infoblocks')); 902 return $id; //redirect()->route('worker.cabinet')->getTargetUrl(); //view('workers.ajax.diploms_dop', compact('worker', 'Infoblocks'));
908 } 903 }
909 904
910 905
911 906
912 // Добавление диплома 907 // Добавление диплома
913 public function add_diplom_ajax(Request $request) { 908 public function add_diplom_ajax(Request $request) {
914 // конец 909 // конец
915 $params = $request->all(); 910 $params = $request->all();
916 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); 911 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count();
917 912
918 if ($count == 0) $dop_info = Dop_info::create($params); 913 if ($count == 0) $dop_info = Dop_info::create($params);
919 $Infoblocks = infobloks::query()->get(); 914 $Infoblocks = infobloks::query()->get();
920 $Worker = Worker::query()->where('id', $request->get('worker_id'))->get(); 915 $Worker = Worker::query()->where('id', $request->get('worker_id'))->get();
921 $data = Dop_info::query()->where('worker_id', $request->has('worker_id')); 916 $data = Dop_info::query()->where('worker_id', $request->has('worker_id'));
922 return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker')); 917 return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker'));
923 } 918 }
924 919
925 // Добавление диплома без ajax 920 // Добавление диплома без ajax
926 public function add_diplom(Worker $worker) { 921 public function add_diplom(Worker $worker) {
927 $worker_id = $worker->id; 922 $worker_id = $worker->id;
928 $Infoblocks = infobloks::query()->get(); 923 $Infoblocks = infobloks::query()->get();
929 return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks')); 924 return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks'));
930 } 925 }
931 // Сохранить 926 // Сохранить
932 // Сохраняю диплом 927 // Сохраняю диплом
933 public function add_diplom_save(Request $request) { 928 public function add_diplom_save(Request $request) {
934 $params = $request->all(); 929 $params = $request->all();
935 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); 930 $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count();
936 if ($count == 0) $dop_info = Dop_info::create($params); 931 if ($count == 0) $dop_info = Dop_info::create($params);
937 return redirect()->route('worker.cabinet'); 932 return redirect()->route('worker.cabinet');
938 } 933 }
939 934
940 // Добавление стандартного документа 935 // Добавление стандартного документа
941 public function add_document(Worker $worker) { 936 public function add_document(Worker $worker) {
942 return view('workers.docs', compact('worker')); 937 return view('workers.docs', compact('worker'));
943 } 938 }
944 939
945 //Сохранение стандартого документа 940 //Сохранение стандартого документа
946 public function add_document_save(DocumentsRequest $request) { 941 public function add_document_save(DocumentsRequest $request) {
947 $params = $request->all(); 942 $params = $request->all();
948 place_works::create($params); 943 place_works::create($params);
949 return response()->json(['success' => true]); 944 return response()->json(['success' => true]);
950 } 945 }
951 946
952 // Редактирование документа 947 // Редактирование документа
953 public function edit_document(place_works $doc, Worker $worker) { 948 public function edit_document(place_works $doc, Worker $worker) {
954 return view('workers.docs-edit', compact('doc', 'worker')); 949 return view('workers.docs-edit', compact('doc', 'worker'));
955 } 950 }
956 951
957 //Сохранение отредактированного документа 952 //Сохранение отредактированного документа
958 public function edit_document_save(DocumentsRequest $request, place_works $doc) { 953 public function edit_document_save(DocumentsRequest $request, place_works $doc) {
959 $params = $request->all(); 954 $params = $request->all();
960 $doc->update($params); 955 $doc->update($params);
961 956
962 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!'); 957 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!');
963 } 958 }
964 959
965 // Удаление документа 960 // Удаление документа
966 public function delete_document(place_works $doc) { 961 public function delete_document(place_works $doc) {
967 $doc->delete(); 962 $doc->delete();
968 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); 963 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!');
969 } 964 }
970 965
971 //Отправка нового сообщения 966 //Отправка нового сообщения
972 public function new_message(Request $request) 967 public function new_message(Request $request)
973 { 968 {
974 $params = $request->all(); 969 $params = $request->all();
975 970
976 $id = $params['user_from']; 971 $id = $params['user_from'];
977 972
978 Message::add_message( 973 Message::add_message(
979 $request, 974 $request,
980 $params['user_from'], 975 $params['user_from'],
981 $params['user_to'], 976 $params['user_to'],
982 [ 977 [
983 'text' => $params['comment'] ?? null, 978 'text' => $params['comment'] ?? null,
984 'ad_employer_id' => $params['vacancy'], 979 'ad_employer_id' => $params['vacancy'],
985 'flag_new' => 1 980 'flag_new' => 1
986 ], 981 ],
987 file_store_path: "worker/$id" 982 file_store_path: "worker/$id"
988 ); 983 );
989 984
990 if ($request->ajax()) { 985 if ($request->ajax()) {
991 return response([]); 986 return response([]);
992 } 987 }
993 return redirect()->back(); 988 return redirect()->back();
994 } 989 }
995 990
996 991
997 public function test123(Request $request) { 992 public function test123(Request $request) {
998 $params = $request->all(); 993 $params = $request->all();
999 $user1 = $params['user_id']; 994 $user1 = $params['user_id'];
1000 $user2 = $params['to_user_id']; 995 $user2 = $params['to_user_id'];
1001 996
1002 $rules = [ 997 $rules = [
1003 'text' => 'nullable|required_without:file|min:1|max:150000', 998 'text' => 'nullable|required_without:file|min:1|max:150000',
1004 'file' => 'nullable|file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' 999 'file' => 'nullable|file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000'
1005 ]; 1000 ];
1006 $messages = [ 1001 $messages = [
1007 'required_without' => 'Поле «:attribute» обязательно, если файл не прикреплен', 1002 'required_without' => 'Поле «:attribute» обязательно, если файл не прикреплен',
1008 'min' => [ 1003 'min' => [
1009 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 1004 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
1010 'integer' => 'Поле «:attribute» должно быть :min или больше', 1005 'integer' => 'Поле «:attribute» должно быть :min или больше',
1011 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 1006 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
1012 ], 1007 ],
1013 'max' => [ 1008 'max' => [
1014 'string' => 'Поле «:attribute» должно быть не больше :max символов', 1009 'string' => 'Поле «:attribute» должно быть не больше :max символов',
1015 'integer' => 'Поле «:attribute» должно быть :max или меньше', 1010 'integer' => 'Поле «:attribute» должно быть :max или меньше',
1016 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 1011 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
1017 ] 1012 ]
1018 ]; 1013 ];
1019 1014
1020 $validator = Validator::make($request->all(), $rules, $messages); 1015 $validator = Validator::make($request->all(), $rules, $messages);
1021 1016
1022 if ($validator->fails()) { 1017 if ($validator->fails()) {
1023 $chat = Chat::where('user_id', $user1) 1018 $chat = Chat::where('user_id', $user1)
1024 ->where('to_user_id', $user2) 1019 ->where('to_user_id', $user2)
1025 ->where('is_removed', 0) 1020 ->where('is_removed', 0)
1026 ->first(); 1021 ->first();
1027 1022
1028 if ($chat->id){ 1023 if ($chat->id){
1029 return redirect()->route('worker.dialog', ['chat' => $chat->id])->withErrors($validator); 1024 return redirect()->route('worker.dialog', ['chat' => $chat->id])->withErrors($validator);
1030 } else { 1025 } else {
1031 return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator); 1026 return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator);
1032 } 1027 }
1033 } else { 1028 } else {
1034 $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); 1029 $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
1035 1030
1036 //dd('new message', $new_message); 1031 //dd('new message', $new_message);
1037 return redirect()->route('worker.dialog', ['chat' => $new_message->chat_id_from]); 1032 return redirect()->route('worker.dialog', ['chat' => $new_message->chat_id_from]);
1038 } 1033 }
1039 } 1034 }
1040 1035
1041 // Информация о предыдущих компаниях 1036 // Информация о предыдущих компаниях
1042 public function new_prev_company(Worker $worker) { 1037 public function new_prev_company(Worker $worker) {
1043 return view('workers.prev_company_form', compact('worker')); 1038 return view('workers.prev_company_form', compact('worker'));
1044 } 1039 }
1045 1040
1046 // Добавление контакта компании 1041 // Добавление контакта компании
1047 public function add_prev_company(PrevCompanyRequest $request) { 1042 public function add_prev_company(PrevCompanyRequest $request) {
1048 // Возвращение параметров 1043 // Возвращение параметров
1049 $all = $request->all(); 1044 $all = $request->all();
1050 PrevCompany::create($all); 1045 PrevCompany::create($all);
1051 1046
1052 return response()->json(['success' => true]); 1047 return response()->json(['success' => true]);
1053 } 1048 }
1054 1049
1055 // Редактирование контакта компании 1050 // Редактирование контакта компании
1056 public function edit_prev_company(PrevCompany $doc, Worker $worker) { 1051 public function edit_prev_company(PrevCompany $doc, Worker $worker) {
1057 return view('workers.prev_company_edit_form', compact('doc', 'worker')); 1052 return view('workers.prev_company_edit_form', compact('doc', 'worker'));
1058 } 1053 }
1059 1054
1060 //Сохранение редактирования контакта компании 1055 //Сохранение редактирования контакта компании
1061 public function update_prev_company(PrevCompany $doc, Request $request){ 1056 public function update_prev_company(PrevCompany $doc, Request $request){
1062 $all = $request->all(); 1057 $all = $request->all();
1063 $doc->update($all); 1058 $doc->update($all);
1064 1059
1065 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись'); 1060 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись');
1066 } 1061 }
1067 1062
1068 // Удаление контакта предыдущей компании 1063 // Удаление контакта предыдущей компании
1069 public function delete_prev_company(PrevCompany $doc) { 1064 public function delete_prev_company(PrevCompany $doc) {
1070 $doc->delete(); 1065 $doc->delete();
1071 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); 1066 return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!');
1072 } 1067 }
1073 1068
1074 public function autoresponder() 1069 public function autoresponder()
1075 { 1070 {
1076 $user = Auth::user(); 1071 $user = Auth::user();
1077 return view('workers.autoresponder', compact('user')); 1072 return view('workers.autoresponder', compact('user'));
1078 } 1073 }
1079 1074
1080 public function autoresponderSave(Request $request): RedirectResponse 1075 public function autoresponderSave(Request $request): RedirectResponse
1081 { 1076 {
1082 /** @var Employer $employer */ 1077 /** @var Employer $employer */
1083 $employer = Auth::user(); 1078 $employer = Auth::user();
1084 $employer->autoresponder = $request->get('autoresponder', false) === 'on'; 1079 $employer->autoresponder = $request->get('autoresponder', false) === 'on';
1085 $employer->autoresponder_message = $request->get('autoresponder_message'); 1080 $employer->autoresponder_message = $request->get('autoresponder_message');
1086 $employer->save(); 1081 $employer->save();
1087 1082
1088 return redirect(route('worker.autoresponder')); 1083 return redirect(route('worker.autoresponder'));
1089 } 1084 }
1090 /** 1085 /**
1091 * @throws JsonException 1086 * @throws JsonException
1092 */ 1087 */
1093 public function resumeAutoLiftForm(): View 1088 public function resumeAutoLiftForm(): View
1094 { 1089 {
1095 $worker = Auth::user()->workers[0]; 1090 $worker = Auth::user()->workers[0];
1096 1091
1097 $options = $worker->autoliftOptions ?? new WorkerAutoliftOption(); 1092 $options = $worker->autoliftOptions ?? new WorkerAutoliftOption();
1098 1093
1099 return view('workers.resume_autolift', compact('worker', 'options')); 1094 return view('workers.resume_autolift', compact('worker', 'options'));
1100 } 1095 }
1101 1096
1102 /** 1097 /**
1103 * @throws JsonException 1098 * @throws JsonException
1104 */ 1099 */
1105 public function resumeAutoLiftSave(Request $request) 1100 public function resumeAutoLiftSave(Request $request)
1106 { 1101 {
1107 $worker = Auth::user()->workers[0]; 1102 $worker = Auth::user()->workers[0];
1108 1103
1109 $worker->autoliftOptions()->updateOrCreate( 1104 $worker->autoliftOptions()->updateOrCreate(
1110 [ 1105 [
1111 'worker_id' => $worker->id, 1106 'worker_id' => $worker->id,
1112 ], 1107 ],
1113 [ 1108 [
1114 'is_enabled' => $request->get('is_enabled') === 'true', 1109 'is_enabled' => $request->get('is_enabled') === 'true',
1115 'times_per_day' => $request->get('times_per_day'), 1110 'times_per_day' => $request->get('times_per_day'),
1116 'days_repeat' => $request->get('days_repeat'), 1111 'days_repeat' => $request->get('days_repeat'),
1117 'time_send_first' => $request->get('time_send_first'), 1112 'time_send_first' => $request->get('time_send_first'),
1118 'time_send_second' => $request->get('time_send_second'), 1113 'time_send_second' => $request->get('time_send_second'),
1119 'time_send_third' => $request->get('time_send_third'), 1114 'time_send_third' => $request->get('time_send_third'),
1120 'time_send_tg' => $request->get('time_send_tg'), 1115 'time_send_tg' => $request->get('time_send_tg'),
1121 'autolift_site' => $request->get('autolift_site') === 'on', 1116 'autolift_site' => $request->get('autolift_site') === 'on',
1122 ] 1117 ]
1123 ); 1118 );
1124 1119
1125 return response()->json(['success' => true]); 1120 return response()->json(['success' => true]);
1126 } 1121 }
1127 } 1122 }
1128 1123
1129 1124