public function importAction()
 {
     $translate = Zend_Registry::get('Zend_Translate');
     $this->view->title = 'Quản lý cán bộ - ' . $translate->_('TEXT_DEFAULT_TITLE');
     $this->view->headTitle($this->view->title);
     $layoutPath = APPLICATION_PATH . '/templates/' . TEMPLATE_USED;
     $option = array('layout' => '1_column/layout', 'layoutPath' => $layoutPath);
     Zend_Layout::startMvc($option);
     $date_format = 'd/m/Y';
     $locale = new Zend_Locale('vi_VN');
     Zend_Date::setOptions(array('format_type' => 'php'));
     $employeesModel = new Front_Model_Employees();
     $phongbanModel = new Front_Model_Phongban();
     $nghachcongchucModel = new Front_Model_NgachCongChuc();
     $hesoModel = new Front_Model_EmployeesHeso();
     $bacluongModel = new Front_Model_BacLuong();
     $min = 20;
     $max = 10 * 1024 * 1024;
     //2MB
     $dir = '/excel';
     //thu muc uploads
     $dir_upload = IMPORT_PATH . $dir;
     //duong dan
     $upload = new Zend_File_Transfer_Adapter_Http();
     $upload->setDestination($dir_upload);
     $upload->addValidator('Count', false, array('min' => 1, 'max' => 1))->addValidator('Size', false, array('min' => $min, 'max' => $max))->addValidator('Extension', false, 'xlsx,xls');
     $files = $upload->getFileInfo();
     $arrFileName = array();
     $success_message = '';
     $error_message = array();
     if ($this->getRequest()->isPost()) {
         if ($upload->isValid()) {
             foreach ($files as $file => $info) {
                 if ($info['name'] != '') {
                     $validator = new Zend_Validate_File_Exists($dir_upload);
                     if ($validator->isValid($info['name'])) {
                         $file_name = $upload->getFileName($info['name']);
                         preg_match("/\\.([^\\.]+)\$/", $file_name, $matches);
                         $file_ext = $matches[1];
                         $file_name = time() . '.' . $file_ext;
                         $arrFileName[$file] = $file_name;
                         $upload->addFilter('Rename', $dir_upload . '/' . $file_name);
                     } else {
                         $arrFileName[$file] = $info['name'];
                     }
                     $upload->receive($file);
                 }
             }
             $file_name = $arrFileName['filedata'];
             //photo la ten form
             $full_path = $dir_upload . '/' . $file_name;
             $objPHPExcel = PHPExcel_IOFactory::load($full_path);
             $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
             $current_time = new Zend_Db_Expr('NOW()');
             $i = 0;
             $j;
             foreach ($sheetData as $row) {
                 $i++;
                 if ($i >= 4) {
                     $data = array();
                     $phongban = $phongbanModel->getPhongBanByName($this->strtolower_utf8(trim($row['E'])));
                     if ($phongban) {
                         $data['em_phong_ban'] = $phongban->pb_id;
                     }
                     $ngach_cc = $nghachcongchucModel->getByMaNgach($this->strtolower_utf8(trim($row['F'])));
                     if ($ngach_cc) {
                         $data['em_ngach_cong_chuc'] = $ngach_cc->ncc_id;
                     } else {
                         $data['em_ngach_cong_chuc'] = 0;
                     }
                     $data['em_ho'] = $row['A'];
                     $data['em_ten'] = $row['B'];
                     if (strtoupper(trim($row['C'])) == 'NAM') {
                         $data['em_gioi_tinh'] = 1;
                     } else {
                         $data['em_gioi_tinh'] = 0;
                     }
                     if (trim($row['D']) != '') {
                         $date_ngay_sinh = new Zend_Date(trim($row['D']), 'd/m/Y');
                         $data['em_ngay_sinh'] = $date_ngay_sinh->get('Y-m-d');
                     }
                     if (trim($row['H']) != '') {
                         $date_time_cong_tac = new Zend_Date(trim($row['H']), 'd/m/Y');
                         $data['em_time_cong_tac'] = $date_time_cong_tac->get('Y-m-d');
                     }
                     $data['em_so_cong_chuc'] = $row['Z'];
                     $data['em_status'] = 1;
                     $data['em_date_added'] = $current_time;
                     $data['em_date_modified'] = $current_time;
                     $employeesModel->insert($data);
                     $last_id = $employeesModel->getAdapter()->lastInsertId();
                     $bacluong = $bacluongModel->fetchRow('bl_name=' . trim($row['K']));
                     $data_heso = array('eh_pc_kv' => $row['P'], 'eh_pc_thu_hut' => $row['M'], 'eh_pc_cong_viec' => $row['N'], 'eh_pc_trach_nhiem' => $row['O'], 'eh_pc_tnvk_phan_tram' => $row['Q'], 'eh_pc_udn_phan_tram' => $row['R'], 'eh_pc_cong_vu_phan_tram' => $row['S'], 'eh_pc_kiem_nhiem' => $row['T'], 'eh_pc_khac' => $row['W'], 'eh_pc_khac_type' => 0, 'eh_pc_doc_hai' => $row['U'], 'eh_pc_doc_hai_type' => 0, 'eh_date_modified' => $current_time);
                     if ($bacluong) {
                         $data_heso['eh_bac_luong'] = $bacluong->bl_id;
                         $he_so_theo_bac = unserialize($bacluong->bl_he_so_luong);
                         if (isset($he_so_theo_bac[$ngach_cc->ncc_id])) {
                             $data_heso['eh_he_so'] = $he_so_theo_bac[$ngach_cc->ncc_id];
                         } else {
                             $data_heso['eh_he_so'] = $row['L'];
                         }
                     } else {
                         $data_heso['eh_bac_luong'] = 0;
                         $data_heso['eh_he_so'] = $row['L'];
                     }
                     if ($this->strtolower_utf8(trim($row['I'])) === 'biên chế') {
                         $data_heso['eh_loai_luong'] = 0;
                     } else {
                         $data_heso['eh_loai_luong'] = 1;
                     }
                     if ($this->strtolower_utf8(trim($row['J'])) === 'chính thức') {
                         $data_heso['eh_giai_doan'] = 0;
                     } else {
                         $data_heso['eh_giai_doan'] = 1;
                     }
                     if ($this->strtolower_utf8(trim($row['V'])) === 'tiền') {
                         $data_heso['eh_pc_doc_hai_type'] = 1;
                     }
                     if (trim($row['X']) == '%') {
                         $data_heso['eh_pc_khac_type'] = 1;
                     }
                     $date_dieu_chinh = new Zend_Date(trim($row['Y']), 'd/m/Y');
                     $data_heso['eh_han_dieu_chinh'] = $date_dieu_chinh->get('Y-m-1');
                     $data_heso['eh_han_ap_dung'] = $date_dieu_chinh->get('Y-m-1');
                     if (trim($row['G']) != '') {
                         $date_time_tham_nien = new Zend_Date(trim($row['G']), 'd/m/Y');
                         $data_heso['eh_tham_niem'] = $date_time_tham_nien->get('Y-m-1');
                     }
                     $data_heso['eh_em_id'] = $last_id;
                     $data_heso['eh_date_added'] = $current_time;
                     $hesoModel->insert($data_heso);
                     $j++;
                 }
             }
             $success_message = "Đã thêm {$j} nhân viên mới.";
         } else {
             $error_message[] = 'Lỗi khi upload file (chỉ cho upload file *.xls, *.xlsx và dưới 10MB).';
         }
     }
     $this->view->error_message = $error_message;
     $this->view->success_message = $success_message;
     $this->view->page = $this->_page;
 }