|
Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/angkasapuraretail.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sales_list extends Admin_Controller {
//this property is used for validating existing customer title on call back edit customer
private $sales_current_id = NULL;
function __construct() {
parent::__construct();
if (!in_array('customers', $this->data['allowed_module'])) {
$this->data['allowed'] = false;
} else {
$this->data['allowed'] = true;
}
}
//this is to list all customers
public function index() {
$count_sales = $this->db->select('*')->from('sales_list')->order_by('id','ASC')->get()->result();
//pagination in action. 100 results per page
$this->load->library('pagination');
$config = array();
$this->load->helper('pagination_helper');
$config = pagination_format();
$config['base_url'] = base_url('admin/sales_list/index');
$config['total_rows'] = count($count_sales);
$config['per_page'] = 100;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
//fetch all customers
$this->data['sales_list'] = $this->db->select('*')->from('sales_list')->order_by('id','ASC')->limit($config['per_page'], $this->uri->segment(4))->get()->result();
$this->data['use_pagination'] = 'yes';
//load view
$this->data['subview'] = 'admin/sales_list/index';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
public function upload_sales_list(){
$config['upload_path'] = 'uploads/excel/';
$config['allowed_types'] = 'xlsx|xls';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile')){
$this->session->set_flashdata('upload_excel_info', '<p style="background:red; color:white; padding:5px; font-weight:bold;">'.strip_tags($this->upload->display_errors()).'</p>');
redirect('admin/sales_list');
}
else{
require_once APPPATH . 'third_party/PHPExcel/IOFactory.php';
$data = array('upload_data' => $this->upload->data());
$upload_data = $this->upload->data(); //Mengambil detail data yang di upload
$filename = $upload_data['file_name'];//Nama File
ini_set('memory_limit', '-1');
$inputFileName = 'uploads/excel/'.$filename;
try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
}
catch(Exception $e) {
die('Error loading file :' . $e->getMessage());
}
$worksheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$numRows = count($worksheet);
$this->db->empty_table('sales_list');
for ($i=1; $i < ($numRows+1) ; $i++) {
if($i != 1){
$ins = array(
"employee_id" => $worksheet[$i]["A"],
"sales_name" => $worksheet[$i]["B"],
"sales_work_location" => $worksheet[$i]["C"],
"sales_ba_dept" => $worksheet[$i]["D"],
"position" => $worksheet[$i]["E"],
"handphone" => '0' . $worksheet[$i]["F"],
"email" => $worksheet[$i]["G"],
"email_manager" => $worksheet[$i]["H"],
);
$this->db->insert('sales_list', $ins);
}
}
unlink('uploads/excel/'.$filename);
$this->session->set_flashdata('upload_excel_info', '<p style="background:green; color:white; padding:5px; font-weight:bold;">Upload Sales List File Success</p>');
redirect('admin/sales_list');
}
}
}