public function insert($name, $order, $use_complete = false, $use_seeding = false, $use_pest_control = false) { $work = new Work(); $work->name = $name; $work->use_complete = $use_complete; $work->use_seeding = $use_seeding; $work->use_pest_control = $use_pest_control; $work->display_order = $order; $work->save(); }
/** * Save data from user */ public function save() { if ($this->validate()) { $work = new Work(); $work->konkurs_id = 1; $work->participant_id = 2; $work->category_id = $this->category_id; $work->file_name = 'test'; $work->file_type = 'pdf'; $work->date = $this->date; $work->title = $this->title; $work->picture = 'test.jpg'; return $work->save(); } return false; }
public function save() { if ($this->validate()) { $model = checkTimesheet(); //nếu timesheet khác false if ($model != false) { if ($model == null) { $model = new Timesheet(['user_id' => $this->user_id, 'date' => $this->date, 'status' => 0]); $model->save(); } $work = new Work(['timesheet_id' => $model->id, 'team_id' => $this->team_id, 'process_id' => $this->process_id, 'work_time' => $this->work_time, 'work_name' => $this->work_name]); if ($work->save()) { return $model; } } else { return null; } return null; } return null; }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $validateData = ['datetime_input' => 'required|date_format:"' . config('format.input.datetime-local') . '"', 'crop_id' => 'required', 'work_diary_ids' => 'required', 'work_id' => 'required']; if (!empty($this->input('work_id'))) { $this->work = Work::findOrFail($this->input('work_id')); if ($this->work->use_seeding) { // 播種、定植の場合に追加で必須にする属性 $validateData['cultivar_id'] = 'required'; $validateData['intrarow_spacing'] = 'required|numeric|between:1,100'; } } return $validateData; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Work::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['kpi' => $this->kpi, 'target' => $this->target, 'result' => $this->result]); $query->andFilterWhere(['like', 'prov', $this->prov]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = WorkModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'konkurs_id' => $this->konkurs_id, 'user_id' => $this->user_id, 'category_id' => $this->category_id, 'date' => $this->date]); $query->andFilterWhere(['like', 'file_name', $this->file_name])->andFilterWhere(['like', 'file_type', $this->file_type])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'picture', $this->picture]); return $dataProvider; }
/** * auto generate nik * * 1. get organisationcode * 2. get join date * 3. get last nik order number * @param model of employee * @return $nik */ public function generateNIK($employee) { //1. get organisationcode $code = $employee->organisation->code; //2. get join date $work = Work::personid($employee)->notchartid(0)->orderby('start', 'desc')->first(); if ($work) { $join_year = $work->start; } else { $join_year = Carbon::now(); } $nik = $code . $join_year->format('y') . '.'; //3. get last nik order number $last_nik = Employee::selectraw('max(uniqid)')->where('uniqid', 'like', $nik . '%')->organisationid($employee->organisation_id)->first(); if ($last_nik) { $number = 1 + (int) substr($last_nik['uniqid'], 6); } else { $number = 1; } return $nik . str_pad($number, 3, "0", STR_PAD_LEFT); }
/** * @return \yii\db\ActiveQuery */ public function getWorks() { return $this->hasMany(Work::className(), ['category_id' => 'id']); }
/** * Delete a schedule (throw to queue) * * @return Response */ public function delete($org_id = null, $cal_id = null, $id = null) { // $schedule = \App\Models\Schedule::id($id)->calendarid($cal_id)->with(['calendar', 'calendar.calendars'])->first(); if (!$schedule) { return new JSend('error', (array) Input::all(), 'Jadwal tidak ditemukan.'); } $errors = new MessageBag(); DB::beginTransaction(); //1. store schedule of calendar to queue $schedule = $schedule->toArray(); //1a. Validate Basic schedule Parameter $parameter = $schedule; unset($parameter['calendar']); $total = \App\Models\Work::calendarid($cal_id)->count(); $queue = new \App\Models\Queue(); $queue->fill(['process_name' => 'hr:schedules', 'process_option' => 'delete', 'parameter' => json_encode($parameter), 'total_process' => $total, 'task_per_process' => 1, 'process_number' => 0, 'total_task' => $total, 'message' => 'Initial Commit']); if (!$queue->save()) { $errors->add('Schedule', $queue->getError()); } //End of validate schedule //2. store schedule of calendars to queue if (!$errors->count() && isset($schedule['calendar']['calendars']) && is_array($schedule['calendar']['calendars'])) { foreach ($schedule['calendar']['calendars'] as $key => $value) { $cals_data = \App\Models\Calendar::id($value['id'])->calendarid($cal_id)->first(); if (!$cals_data) { $errors->add('Calendar', 'Tidak ada kalender ' . $value['name']); } if (!$errors->count()) { $total = \App\Models\Work::calendarid($value['id'])->count(); $parameter['calendar_id'] = $value['id']; $queue = new \App\Models\Queue(); $queue->fill(['process_name' => 'hr:schedules', 'process_option' => 'delete', 'parameter' => json_encode($parameter), 'total_process' => $total, 'task_per_process' => 1, 'process_number' => 0, 'total_task' => $total, 'message' => 'Initial Commit']); if (!$queue->save()) { $errors->add('Schedule', $queue->getError()); } } } } //End of validate calendar schedule if ($errors->count()) { DB::rollback(); return new JSend('error', (array) Input::all(), $errors); } DB::commit(); return new JSend('success', (array) $schedule); }
/** * 作成処理 * * @param WorkRecordStoreRequest $request * @return \Illuminate\Http\RedirectResponse */ public function store(WorkRecordStoreRequest $request) { $cropId = $request->input('crop_id'); $errors = new MessageBag(); DB::transaction(function () use($request, $cropId, &$errors) { $workId = $request->input('work_id'); $workDiaryIds = (array) $request->input('work_diary_ids'); $work = Work::findOrFail($workId); $workDiaries = WorkDiary::whereIn('id', $workDiaryIds)->lockForUpdate()->get(); if ($workDiaries->count() !== $workDiaries->where('crop_id', $cropId)->where('archive', false)->count()) { // 不正な作業日誌が選択されている $errors->add('work_diary_ids', message('others_update')); DB::rollBack(); return; } // 作業記録登録 $workRecord = new WorkRecord(); $workRecord->fill($request->all()); $workRecord->work_id = $workId; $workRecord->crop_id = $cropId; // use_complete=falseの場合は常にtrue $workRecord->complete = !$work->use_complete || $request->has('complete'); $workRecord->save(); // 防除記録 if ($work->use_pest_control) { $sessionPesticides = session()->get('workRecord.pesticides'); $pesticideIds = $sessionPesticides->keys(); $pesticides = Pesticide::whereIn('id', $pesticideIds)->whereHas('crops', function ($query) use($cropId) { $query->where('crop_id', $cropId); }); if ($pesticideIds->count() !== $pesticides->count()) { // 農薬の選択が不正 $errors->add('pesticide', message('others_update')); DB::rollBack(); return; } foreach ($sessionPesticides as $sessionPesticide) { $workPestControl = new WorkPestControl(); $workPestControl->work_record_id = $workRecord->id; $workPestControl->pesticide_id = $sessionPesticide->get('pesticide_id'); $workPestControl->usage = $sessionPesticide->get('usage'); $workPestControl->save(); } } // 播種/定植記録 if ($work->use_seeding) { $workSeeding = new WorkSeeding(); $workSeeding->work_record_id = $workRecord->id; $workSeeding->cultivar_id = $request->input('cultivar_id'); $workSeeding->fill($request->all()); $workSeeding->save(); } // 日誌紐付け $workRecord->workDiaries()->attach($workDiaryIds); }); if ($errors->any()) { return $this->buildFailedValidationResponse($request, $errors->toArray()); } // 農薬情報をクリア session()->forget('workRecord.pesticides'); return redirect()->route('workRecord.index', ['crop_id' => $cropId])->with('complete', 'store'); }
/** * @return \yii\db\ActiveQuery */ public function getWorks() { return $this->hasMany(Work::className(), ['konkurs_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getWork() { return $this->hasOne(Work::className(), ['id' => 'work_id']); }
/** * Finds the Work model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $kpi * @param string $prov * @return Work the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($kpi, $prov) { if (($model = Work::findOne(['kpi' => $kpi, 'prov' => $prov])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Finds the Work model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Work the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Work::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }