public function actionCreate() { $status = 200; $data = json_decode(file_get_contents('php://input')); // echo "<pre>"; // print_r($data); // echo "</pre>"; // die(); $count_data = count($data); $transaction = Yii::app()->db->beginTransaction(); try { foreach ($data as $key => $value) { $employee = MastersEmployees::model()->findByAttributes(array('code' => $value->nik)); $employee_id = $employee->id; $date = $value->tgl; $shift_id = $employee->getShift($date); $presence_time = $value->presence_time; $presence_photo = $value->presence_photo; $location_id = $value->location_id; $presence_type = $value->presence_type; $presence = new AttendancePresences(); $presence->employee_id = $employee_id; $presence->shift_id = $shift_id; $presence->date = $date; $presence->type = $presence_type; $presence->location_id = $location_id; $presence->presence_date = $presence_time; $presence->photo = $presence_photo; if (!$presence->save()) { $status = 500; } else { $count_data--; $status = 500; } } // $transaction->commit(); if ($count_data == 0) { $transaction->commit(); } else { $transaction->rollback(); } } catch (Exception $e) { $transaction->rollback(); $status = 500; } echo json_encode(array('status' => $status)); }
public function actionImport() { $model = new ImportForm(); if (isset($_POST['ImportForm'])) { $model->attributes = $_POST['ImportForm']; MyHelper::ImportFile($model, AttendancePresences::model()->tableSchema->name, '`year`, `city_id`, `department_id`, `section_id`, `position_id`, `years_of_service_start`, `years_of_service_end`, `level_id`, `grade_id`, `basic_salary_from`, `basic_salary_to`, `basic_salary_inc_amount`, `basic_salary_inc_percentage`', array("attendance/schedulle")); } $this->render("importcsv", array('model' => $model)); }
public function actionImport() { $model = new ImportForm(); if (isset($_POST['ImportForm'])) { $model->attributes = $_POST['ImportForm']; $table = AttendancePresences::model(); $table_name = $table->tableSchema->name; $table_name_temp = $table_name . '_temp'; $table->clearTemporary($table_name_temp); MyHelper::ImportFile($model, $table_name_temp, '`employee_id`, `date`, `shift_id`, `type`, `presence_date`'); $table->moveDataImport($table_name, $table_name_temp); } $this->render("import", array('model' => $model)); }