public function insertcongvandi($congvandi, $phongs, $nguoitao) { $capphathanh_id = $this->getcapphathanhid($congvandi->noisoanthao_id); $noiphathanh_id = $this->getnoiphathanhid($congvandi->noisoanthao_id); $nguoiky = $this->getnguoiky($congvandi->nguoiky_id); if ($congvandi->hantraloi != NULL) { $congvandi_hantraloi = $congvandi->hantraloi; } else { $congvandi_hantraloi = NULL; } foreach ($phongs as $phong) { $sohosoluu = Congvanden::getsohosoluu($phong); $congvanden = new Congvanden(['sohosoluu' => $sohosoluu, 'socongvandenso' => $congvandi->socongvandiso, 'socongvandenchu' => $congvandi->socongvandichu, 'capphathanh_id' => $capphathanh_id, 'noiphathanh_ids' => $noiphathanh_id, 'ngayky' => $congvandi->ngayky, 'danhmucdomat_id' => $congvandi->danhmucdomat_id, 'danhmucmucdich_id' => $congvandi->danhmucmucdich_id, 'danhmucloaicongvan_id' => $congvandi->danhmucloaicongvan_id, 'linhvucchuyende_id' => $congvandi->linhvucchuyende_id, 'danhmucchuyende_id' => $congvandi->danhmucchuyende_id, 'nguoiky' => $nguoiky->name, 'danhmucdokhan_id' => $congvandi->danhmucdokhan_id, 'ngayden' => $congvandi->ngayphathanh, 'noiluucv' => $congvandi->noiluu, 'trichyeucongvanden' => $congvandi->trichyeucongvandi, 'dukienthoihanketthucxuly' => $congvandi_hantraloi, 'phong_id' => $phong, 'nguoitao_id' => $nguoitao]); $congvanden->save(); } }
/** * Store a newly created resource in storage. * Lưu công văn đến từ địa phương * @return Response */ public function store(CongvandenCreateFormRequest $request) { if (Auth::check() && $this->rolechucnangs && $this->rolechucnangs->Them == 1) { // validate name $nowtime = date("m/d/Y", time()); $nowyear = date('Y'); //$namky = date('Y',strtotime($request->input('ngayky'))); $namden = date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngayden')))); $namdens = substr($namden, 0, 4); //echo $namdens; if ($namdens != $nowyear) { return \Redirect::route('congvanden.create')->with('error', 'Năm của ngày đến không đúng (chỉ nhập được công văn của năm hiện tại)')->withInput(); } else { $phong_id = User::where('id', Auth::user()->id)->value('phong_id'); $sohosoluu = $request->input('sohosoluu'); // kiem tra so ho luu da ton tai chua ? if (Congvanden::checksohosoluu($sohosoluu, $phong_id) == TRUE) { return \Redirect::route('congvanden.create')->with('error', 'Số công văn lưu đã tồn tại')->withInput(); //return response()->json('socongvanluu'); } else { $sohosoluu = $sohosoluu; } $socongvandengocso = $request->input('socongvandengocso'); if ($socongvandengocso == '') { $socongvandengocso = NULL; } $socongvandengocchu = $request->input('socongvandengocchu'); if ($socongvandengocchu == '') { $socongvandengocchu = NULL; } //dd($socongvandengocso); // luu cong van $congvanden = new Congvanden(array('sohosoluu' => $sohosoluu, 'socongvandenso' => $request->input('socongvandenso'), 'socongvandenchu' => $request->input('socongvandenchu'), 'capphathanh_id' => $request->input('capphathanh'), 'noiphathanh_id' => $request->input('noiphathanh'), 'ngayky' => date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngayky')))), 'danhmucdomat_id' => $request->input('domatcongvan'), 'danhmucmucdich_id' => $request->input('mucdich'), 'danhmucloaicongvan_id' => $request->input('loaicongvan'), 'linhvucchuyende_id' => $request->input('linhvucchuyende'), 'danhmucchuyende_id' => $request->input('chuyende'), 'nguoiky' => $request->input('nguoiky'), 'danhmucdokhan_id' => $request->input('dokhancongvan'), 'ngayden' => date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngayden')))), 'noiluucv' => $request->input('noiluucv'), 'trichyeucongvanden' => $request->input('trichyeucongvanden'), 'quatrinhxuly' => $request->input('quatrinhxuly'), 'trichykienlanhdao' => $request->input('trichykienlanhdao'), 'socongvangocso' => $request->input('socongvandengocso'), 'socongvangocchu' => $request->input('socongvandengocchu'), 'ngayphathanhcongvangoc' => date('Y-m-d', strtotime(str_replace('/', '-', $request->input('ngaycongvangoc')))), 'capphathanhcongvangoc_id' => $request->input('capphathanhcongvangoc'), 'noiphathanhcongvangoc_id' => $request->input('noiphathanhcongvangoc'), 'ketquaxuly' => $request->input('ketquaxuly'), 'dukienthoihanketthucxuly' => date('Y-m-d', strtotime(str_replace('/', '-', $request->input('dukienthoihanketthucxuly')))), 'traloicongvan' => $request->input('traloicongvan'), 'phong_id' => $phong_id, 'nguoitao_id' => \Auth::user()->id)); $congvanden->save(); $insertedId = $congvanden->id; $congvandenfind = Congvanden::findOrFail($insertedId); $phongs = $request->input('phong'); // phòng if ($phongs != NULL) { $congvandenfind->danhmucphongs()->sync($phongs); } $dois = $request->input('doi'); // đội if ($dois != NULL) { $congvandenfind->danhmucdois()->sync($dois); } $canbos = $request->input('canbo'); // cá nhân if ($canbos != NULL) { $congvandenfind->danhmuccanbos()->sync($canbos); } // xu ly file if ($request->input('upload-file') && $request->hasFile('files')) { $files = $request->file('files'); $newnamefiles = File::savefiles($files, Auth::user()->id); $congvandenfind->files()->sync($newnamefiles); } //Gửi email //dd($listfiles); if ($request->input('guiemail') == 'on' && $request->input('upload-file')) { $dataemail = array('emails' => $request->input('emails'), 'tieude' => $request->input('tieude'), 'noidungemail' => $request->input('noidungemail'), 'attachfiles' => $newnamefiles); guimails($dataemail); } else { if ($request->input('guiemail') == 'on') { $dataemail = ['emails' => $request->input('emails'), 'tieude' => $request->input('tieude'), 'noidungemail' => $request->input('noidungemail')]; guimails($dataemail); } } return \Redirect::route('congvanden.index')->with('message', 'Lưu thành công!'); //return response()->json('success'); } } else { return \Redirect::route('congvanden.index')->with('message-error', 'Không có quyền truy cập'); } }