public function add() { if ($this->input->is_ajax_request()) { if ($this->input->post() == FALSE) { $data = $this->_list_data(); $this->load->view("employee/add", $data); } else { //SAVING DATA $this->_set_rules(); if ($_FILES['photo']['name'] != '') { $upload_file = $this->_upload_file('photo', $this->input->post('employee_name') . '-' . date('YmdHis')); } else { if ($this->input->post('gender_id') == 1) { $upload_file = array('photo' => 'male.png', 'photo_thumb' => 'male_thumb.png'); } else { $upload_file = array('photo' => 'female.png', 'photo_thumb' => 'female_thumb.png'); } } if ($this->form_validation->run() == TRUE) { $data_employee = array('employee_name' => $this->input->post('employee_name'), 'employee_no' => $this->input->post('employee_no'), 'birth_place_id' => $this->input->post('birth_place_id'), 'birth_date' => $this->input->post('year') . '-' . $this->input->post('month') . '-' . $this->input->post('day'), 'gender_id' => $this->input->post('gender_id'), 'marriage_status_id' => $this->input->post('marriage_status_id'), 'phone' => $this->input->post('phone'), 'address' => $this->input->post('address'), 'start_date' => human_to_sql($this->input->post('start_date')), 'status_id' => $this->input->post('status_id'), 'division_id' => $this->input->post('division_id'), 'position_id' => $this->input->post('birth_place_id'), 'npwp' => $this->input->post('npwp'), 'religion_id' => $this->input->post('religion_id'), 'education_id' => $this->input->post('education_id'), 'photo' => $upload_file['photo'], 'photo_thumb' => $upload_file['photo_thumb']); $query = $this->global_model->save_data('t_mtr_employee', $data_employee); if ($query == TRUE) { $response = array('status' => 'success', 'message' => 'Berhasil menambah karyawan.<br>Tambah lagi?'); } else { $response = array('status' => 'error', 'message' => 'Gagal menambah karyawan, silahkan coba lagi atau hubungi administrator.'); } } else { $response = array('status' => 'error', 'message' => validation_errors()); } echo json_encode($response); } } else { echo 'Forbidden access!'; } }
public function edit($param = '') { if ($this->input->is_ajax_request()) { if ($this->input->post() == FALSE) { $this->load->model(array('account_model')); $data = $this->db->get_where('t_trx_journals', array('journals_id' => decode($param)))->row_array(); $data['journals_date'] = sql_to_human($data['journals_date']); $data['journals_id'] = $param; $data['journals_detail'] = $this->db->get_where('t_trx_journals_detail', array('journals_id' => decode($param)))->result(); $data['account_list'] = $this->account_model->get_all(); $data['title'] = 'Edit Jurnal Umum'; $data['content'] = 'journals/edit'; $this->load->view($data['content'], $data); } else { //SAVING DATA HERE $this->_set_rules(); if ($this->form_validation->run() == TRUE) { $this->db->trans_start(); $journals_id = decode($this->input->post('journals_id')); //save header $data_header = array('journals_id' => $journals_id, 'journals_date' => human_to_sql($this->input->post('journals_date')), 'transaction_id' => $this->input->post('transaction_id'), 'remark' => $this->input->post('remark'), 'journals_type' => 1); $this->global_model->save_data('t_trx_journals', $data_header, 'journals_id'); //delete old detail $this->db->delete('t_trx_journals_detail', array('journals_id' => $journals_id)); //save detail foreach ($this->input->post('account_id') as $key => $value) { $data_detail = array('journals_id' => $journals_id, 'account_id' => $this->input->post("account_id[{$key}]"), 'debit' => $this->input->post("debit[{$key}]"), 'credit' => $this->input->post("credit[{$key}]")); $this->global_model->save_data('t_trx_journals_detail', $data_detail); } $response = array(); $this->db->trans_complete(); if ($this->db->trans_status() == TRUE) { $response = array('status' => 'success', 'message' => 'Berhasil mengedit jurnal.'); } else { $response = array('status' => 'error', 'message' => 'Gagal mengedit jurnal.'); } } else { $response = array('status' => 'warning', 'message' => validation_errors()); } echo json_encode($response); } } else { echo 'Forbidden access'; } }