<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of Customer
*
* @author nut_channarong
*/
class Customer extends CI_Controller {
//put your code here
public $group_id = '2';
public $menu_id = '3';
public $perPage = 20;
public function __construct() {
parent::__construct();
$this->auth->isLogin($this->menu_id);
$this->load->model('customer_model');
$this->load->library('ajax_pagination');
}
public function index() {
$data = array(
'group_id' => $this->group_id,
'menu_id' => $this->menu_id,
'title' => $this->accesscontrol->getNameTitle($this->menu_id),
'css' => array('datetimepicker.css', 'jquery-ui.min.css'),
'js' => array('input-valid.js', 'jquery.datetimepicker.js', 'jquery-ui.min.js', 'customer.js')
);
$this->renderView('customer_view', $data);
}
public function ajax() {
$search_text = $this->input->post('search_text');
$date_start_filter = $this->input->post('date_start_filter');
$date_end_filter = $this->input->post('date_end_filter');
$count = $this->customer_model->count_All($search_text,$date_start_filter, $date_end_filter);
$config['div'] = 'page-result';
$config['base_url'] = base_url('customer/ajax');
$config['total_rows'] = $count;
$config['per_page'] = $this->perPage;
$config['additional_param'] = "{ 'search_text' : '$search_text' , 'date_start_filter' : '$date_start_filter' , 'date_end_filter' : '$date_end_filter' }";
$config['num_links'] = 4;
$config['uri_segment'] = 3;
$this->ajax_pagination->initialize($config);
$segment = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$params = array('start' => $segment, 'limit' => $this->perPage);
$data = array(
'rows' => $this->customer_model->get_All($search_text,$date_start_filter,$date_end_filter, $params),
'count' => $count,
'segment' => $segment,
'links' => $this->ajax_pagination->create_links(),
'search_text' => $search_text
);
$this->load->view('ajax/customer_page', $data);
}
public function modalAdd() {
$this->load->view('modal/add_customer_modal');
}
public function add() {
$birthdate = $this->input->post('birthdate');
list($year,$month, $day) = explode("-", $birthdate);
$data = array(
'custom_id' => $this->input->post('custom_id'),
'prefix_id' => $this->input->post('prefix_id'),
'customer_fname' => $this->input->post('customer_fname'),
'customer_lname' => $this->input->post('customer_lname'),
'customer_address' => $this->input->post('customer_address'),
'customer_tel' => $this->input->post('customer_tel'),
'email' => $this->input->post('email'),
'birthdate' => ($year - 543).'-'.$month.'-'.$day,//$this->input->post('birthdate'),
'discount_id' => $this->input->post('discount_id'),
'lose_drug' => $this->input->post('lose_drug'),
'comment' => $this->input->post('comment'),
'date_create' => $this->mics->getdate(),
'gender_id' => $this->input->post('gender_id'),
'blood_id' => $this->input->post('blood_id'),
'status_id' => 1,
'admin_id' => $this->input->post('admin_id'),
);
$this->customer_model->insert($data);
redirect(base_url() . 'customer');
}
public function checkId() {
$custom_id = $this->input->post('custom_id');
$count = $this->customer_model->count_custom_id($custom_id);
if ($count > 0) {
echo '1';
} else {
echo '0';
}
}
public function modalEdit() {
$id = $this->input->post('id');
$row = $this->customer_model->get_All(null,null,null,array(null, null), $id);
$data = array(
'row' => $row->row(),
'id' => $id
);
$this->load->view('modal/edit_customer_modal', $data);
}
public function edit() {
$id = $this->input->post('customer_id');
$birthdate = $this->input->post('birthdate');
list($year,$month, $day) = explode("-", $birthdate);
$data = array(
'prefix_id' => $this->input->post('prefix_id'),
'customer_fname' => $this->input->post('customer_fname'),
'customer_lname' => $this->input->post('customer_lname'),
'customer_address' => $this->input->post('customer_address'),
'customer_tel' => $this->input->post('customer_tel'),
'email' => $this->input->post('email'),
'birthdate' => ($year - 543).'-'.$month.'-'.$day,
'discount_id' => $this->input->post('discount_id'),
'lose_drug' => $this->input->post('lose_drug'),
'comment' => $this->input->post('comment'),
'gender_id' => $this->input->post('gender_id'),
'blood_id' => $this->input->post('blood_id'),
'status_id' => $this->input->post('status_id'),
);
$this->customer_model->update($data, $id);
redirect(base_url() . 'customer');
}
public function modalview() {
$id = $this->input->post('id');
$row = $this->customer_model->get_All(null,null,null, array(null, null), $id);
$data = array(
'row' => $row->row(),
'id' => $id
);
$this->load->view('modal/view_customer_modal', $data);
}
public function delete() {
$id = $this->input->post('delete_id');
$this->customer_model->delete($id);
redirect(base_url() . 'customer');
}
public function ajax_view() {
$data = array(
'customer_id' => $this->input->post('customer_id'),
'date_start_filter' => $this->input->post('date_start_filter'),
'date_end_filter' => $this->input->post('date_end_filter'),
);
$this->load->view('ajax/view_customer_page', $data);
}
public function getday() {
$date_start = array();
$return['date_start'] = $this->customer_model->get_day()->row()->day_start;
echo json_encode($return);
}
public function getday_customer() {
$date_start = array();
$return['date_start'] = $this->customer_model->get_day_customer()->row()->day_start;
echo json_encode($return);
}
}