/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(WorkRequest $request)
 {
     $work = $this->permissionSection(function () use($request) {
         $newWork = DB::transaction(function () use($request) {
             $newWork = new Work();
             $newWork->slug = CommonController::uniqueSlugFunc($request->title, 'works');
             $newWork->title = $request->title;
             $newWork->description = $request->description;
             $newWork->deadline = strtotime(str_replace('/', '-', $request->deadline));
             $newWork->importance = $request->importance;
             $newWork->created_by = $this->currentUser->getId();
             $newWork->save();
             $departmentWork = new DepartmentWork();
             $departmentWork->department_id = $request->department;
             $departmentWork->assign_date = time();
             //@todo DATE HATASI !!! BURALAR REVİZE EDİLMELİ
             $departmentWork->accepted = 0;
             $departmentWork->save();
             $newWork->last_department_work_id = $departmentWork->id;
             $newWork->save();
             if ($request->hasFile('file')) {
                 $file = $request->file('file');
                 $fileName = CommonController::fileUpload($file, 'uploads/works-files');
                 $newWork->file = $fileName;
                 $newWork->save();
             }
             if ($request->is_senior == 1 && $request->has('department_worker')) {
                 $userWork = new UserWork();
                 $userWork->department_id = $request->department;
                 $userWork->assign_date = time();
                 //@todo DATE HATASI !!! BURALAR REVİZE EDİLMELİ
                 $userWork->assigned_to = $request->department_worker;
                 $userWork->accepted = 0;
                 $userWork->save();
                 $departmentWork->accepted = 1;
                 $departmentWork->last_user_work_id = $userWork->id;
                 $departmentWork->save();
                 /**
                  * İŞ AÇILAN KİŞİYE MAİL ATMA
                  */
                 $user = User::where('id', '=', $request->department_worker)->first();
                 $username = $user->first_name . " " . $user->last_name;
                 $username = mb_convert_case($username, MB_CASE_TITLE, 'utf-8');
                 $workCreator = User::where('id', '=', $newWork->created_by)->first();
                 $creatorusername = $workCreator->first_name . " " . $workCreator->last_name;
                 $creatorusername = mb_convert_case($creatorusername, MB_CASE_TITLE, 'utf-8');
                 CommonController::mailSendNotQueue('IS TAKIP SISTEMI', [$user->email], ['fullname' => $username, 'work' => $newWork, 'message' => 'Departman lideriniz ' . $creatorusername . ' tarafından size , "' . $newWork->title . '" başlıklı yeni bir iş açıldı. Detaylar için lütfen
                     sisteme gidiniz.'], 'emails.work-mail-template');
                 CommonController::sendSms('RHPOZTFYAY', $user->phone, 'Merhaba ' . $username . ', departman lideriniz ' . $creatorusername . ' tarafından size yeni bir iş açıldı
                 lütfen sistem üzerinden ayrıntıları inceleyin');
                 /**
                  * İŞİ OLUŞTURAN KİŞİYE BİLGİLENDİRME
                  */
                 $departmentWithSenior = Department::where('id', '=', $request->department)->with('senior')->first();
                 $seniorUser = $departmentWithSenior->senior[0];
                 $seniorUsername = $seniorUser->first_name . " " . $seniorUser->last_name;
                 $seniorUsername = mb_convert_case($seniorUsername, MB_CASE_TITLE, 'utf-8');
                 CommonController::mailSendNotQueue('IS TAKIP SISTEMI', [$seniorUser->email], ['fullname' => $seniorUsername, 'message' => 'Departmanınıza "' . $newWork->title . '" başlıklı yeni bir iş açılmış ve bu
                      iş ' . $username . ' kişisine atanmıştır. İşin detayları ve işi atamak için lütfen sisteme gidiniz.'], 'emails.work-mail-template');
                 CommonController::sendSms('RHPOZTFYAY', $seniorUser->phone, 'Merhaba ' . $seniorUsername . ', departmanınıza "' . $newWork->title . '" başlıklı yeni
                 bir iş açılmış ve bu iş ' . $username . ' kişisine atanmıştır . İşin detayları ve işi atamak için lütfen sisteme gidiniz.');
             } else {
                 $departmentWithSenior = Department::where('id', '=', $request->department)->with('senior')->first();
                 $user = $departmentWithSenior->senior[0];
                 $username = $user->first_name . " " . $user->last_name;
                 $username = mb_convert_case($username, MB_CASE_TITLE, 'utf-8');
                 $workCreator = User::where('id', '=', $newWork->created_by)->first();
                 $creatorusername = $workCreator->first_name . " " . $workCreator->last_name;
                 $creatorusername = mb_convert_case($creatorusername, MB_CASE_TITLE, 'utf-8');
                 CommonController::mailSendNotQueue('IS TAKIP SISTEMI', [$user->email], ['fullname' => $username, 'message' => 'Departmanınıza  ' . $creatorusername . ' tarafından , "' . $newWork->title . '" başlıklı yeni bir iş açılmıştır. İşin detayları ve
                     işi atamak için lütfen sisteme gidiniz.'], 'emails.work-mail-template');
                 CommonController::sendSms('RHPOZTFYAY', $user->phone, 'Merhaba ' . $username . ', departmanınıza 
                 "' . $newWork->title . '" başlıklı yeni bir iş açılmıştır. İşin detayları ve işi atamak için lütfen sisteme gidiniz.');
             }
             return $newWork;
         });
         return $newWork;
     }, 'wts.work.create');
     $departmentDetail = Department::where('id', '=', $request->department)->first();
     $work->deadline = date("d-m-y H:i", $work->deadline);
     if ($request->is_senior == 1 && $request->has('department_worker')) {
         return response()->json(['success' => true, 'messages' => 'Kayıt İşlemi Başarılı', 'work' => ['data' => $work, 'department_name' => $departmentDetail->name, 'assigned_to' => $request->department_worker]]);
     } else {
         return response()->json(['success' => true, 'messages' => 'Kayıt İşlemi Başarılı', 'work' => ['data' => $work, 'department_name' => $departmentDetail->name]]);
     }
 }
Exemplo n.º 2
0
     $work->work_type_description = $description;
     $work->project_id = $project->id;
     $work->work_type_id = $workType->id;
     $work->save();
 }
 $description = 'A new landing page is required to support Fall 2016 GNO.';
 if (is_null($work = Work::checkIfExists($description))) {
     // get $project->id
     $project = Project::where('name', '=', 'Magento Development')->first();
     // get $project->id
     $workType = WorkType::where('type', '=', 'Feature')->first();
     $work = new Work();
     $work->work_type_description = $description;
     $work->project_id = $project->id;
     $work->work_type_id = $workType->id;
     $work->save();
 }
 /*******************************************************************************************************************
  * time_card insert(s)
  ******************************************************************************************************************/
 // get $work->id
 $work = Work::where('work_type_description', '=', 'The catalog view is performing too slowly.')->first();
 // get $timeCardFormat->id
 $timeCardFormat = TimeCardFormat::where('description', '=', 'Day of week starts on SAT and ends on SUN')->first();
 $timeCard = new TimeCard();
 $timeCard->work_id = $work->id;
 $timeCard->time_card_format_id = $timeCardFormat->id;
 if (is_null(TimeCard::checkIfExists($timeCard))) {
     $timeCard->iso_beginning_dow_date = '2015-11-09';
     $timeCard->save();
 }