File: /home/cafsindia/crm_cafsindia_com/application/controllers/Renewal.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Secure_Controller.php");
class Renewal extends Secure_Controller
{
public function __construct()
{
parent::__construct('renewal');
$this->load->model('Renewal_model');
}
public function index()
{
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['table_headers'] = $this->xss_clean(get_renewal_table_headers());
$this->load->view('renewal/manage', $data);
}
public function search() {
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
$filters = array('start_date' => $this->input->get('start_date'),
'end_date' => $this->input->get('end_date'),
'General_Insurance' => FALSE,
'Portfolio' => FALSE,
'Health_Insurance' => FALSE,
'Mutual_Funds' => FALSE,
'Term_Plan' => FALSE);
$filledup = array_fill_keys($this->input->get('filters'), TRUE);
$filters = array_merge($filters, $filledup);
$all_leads = $this->Renewal_model->search($search, $filters, $limit, $offset, $sort, $order);
$total_rows = $this->Renewal_model->get_found_rows($search, $filters);
$data_rows = array();
foreach($all_leads->result() as $leads)
{
//$data_rows[] = $this->xss_clean(get_renewal_data_row($leads, $this));
$data_rows[] = get_renewal_data_row($leads, $this);
}
echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
}
public function view($renew_id = -1)
{
$info = $this->Renewal_model->get_info($renew_id);
foreach(get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['renewal_info'] = $info;
$data['renewal_log'] = $this->Renewal_model->get_renewal_log($renew_id);
$company_info[""] = "---- Select Company ----";
foreach($this->Renewal_model->get_company()->result_array() as $row){
$company_info[$this->xss_clean($row['vendor_id'])] = $this->xss_clean($row['vendorcompanyname']);
}
$data['company_info'] = $company_info;
$product_info[""] = "---- Select Plan ----";
foreach($this->Renewal_model->get_product()->result_array() as $row){
$product_info[$this->xss_clean($row['product_id'])] = $this->xss_clean($row['product_name']);
}
$data['product_info'] = $product_info;
$family_info[""] = "---- Select Life Assured ----";
foreach($this->Renewal_model->get_family($renew_id)->result_array() as $row){
$family_info[$this->xss_clean($row['family_id'])] = $this->xss_clean($row['fam_name']);
}
$data['family_info'] = $family_info;
$data['family_infos'] = $this->Renewal_model->get_family_list($renew_id);
$this->load->view("renewal/form", $data);
}
public function view_history($renewal_id)
{
$data['history'] = $this->Renewal_model->view_history($renewal_id);
$this->load->view("renewal/form_history", $data);
}
public function view_login($cust_id){
$data['cust_info'] = $this->Renewal_model->cust_info($cust_id);
$data['family_info'] = $this->Renewal_model->get_view_family($cust_id);
$data['login_history'] = $this->Renewal_model->view_login($cust_id);
$this->load->view("renewal/form_login", $data);
}
public function save($renewal_id = -1){
$category = $this->input->post('category');
$renewal_status = $this->input->post('renewal_status');
if($category === "2"){
$policy_no = $this->input->post('policy_no');
$net_premium = $this->input->post('net_premium');
$gst = $this->input->post('gst');
$total_premium = $this->input->post('total_premium');
$rider_net_premium = $this->input->post('rider_net_premium');
$rider_gst = $this->input->post('rider_gst');
$rider_total_premium = $this->input->post('rider_total_premium');
$overall_net_premium = $this->input->post('overall_net_premium');
$overall_total_premium = $this->input->post('overall_total_premium');
$total_premium = $this->input->post('total_premium');
$renew_date = date('Y-m-d',strtotime($this->input->post('renewal_date')));
$due_date = date('Y-m-d',strtotime($this->input->post('due_date')));
$paying_year = $this->input->post('paying_year');
if($renewal_status === "Paid"){
$renew_date = date('Y-m-d',strtotime($this->input->post('due_date')));
$paying_year = $paying_year+1;
}
}else
if($category === "3"){
$policy_no = $this->input->post('policy_no');
$net_premium = $this->input->post('net_premium');
$gst = $this->input->post('gst');
$total_premium = $this->input->post('total_premium');
$overall_total_premium = $this->input->post('total_premium');
$renew_date = date('Y-m-d',strtotime($this->input->post('renewal_date')));
$paying_year = $this->input->post('paying_year');
$from = date('Y-m-d',strtotime($this->input->post('from')));
$due_date = date('Y-m-d',strtotime($this->input->post('due_date')));
if($renewal_status === "Renewed"){
$paying_year = $paying_year + 1;
$policy_no = $this->input->post('new_policy_no');
$net_premium = $this->input->post('new_net_premium');
$gst = $this->input->post('new_gst');
$total_premium = $this->input->post('new_total_premium');
$overall_net_premium = $this->input->post('new_net_premium');
$overall_total_premium = $this->input->post('new_total_premium');
$from = date('Y-m-d',strtotime($this->input->post('new_from')));
$due_date = date('Y-m-d',strtotime($this->input->post('new_to')));
$renew_date = date('Y-m-d',strtotime($this->input->post('new_from')));
}
}
$renewal_data = array(
'issued_date' => date('Y-m-d',strtotime($this->input->post('issued_date'))),
'renewal_date' => $renew_date,
'paying_year' => $paying_year,
'policy_no' => $policy_no,
'from' => $from,
'to' => $due_date,
'mode' => $this->input->post('mode'),
'sum_assured' => $this->input->post('sum_assured'),
'ren_rider' => $this->input->post('ren_rider'),
'ren_rider_name' => $this->input->post('ren_rider_name'),
'ren_net_premium' => $net_premium,
'ren_gst' => $gst,
'ren_total_premium' => $total_premium,
'ren_rider_net_premium' => $rider_net_premium,
'ren_rider_gst' => $rider_gst,
'ren_rider_total_premium' => $rider_total_premium,
'ren_overall_net_premium' => $overall_net_premium,
'ren_overall_total_premium'=> $overall_total_premium,
'renew_paid_by' => $this->input->post('renew_paid_by'),
'renew_status' => $this->input->post('renewal_status'),
'client_status' => $this->input->post('client_status'),
'renew_reason' => $this->input->post('reason'),
'not_contact_reason' => $this->input->post('not_contact_reason'),
'premium_status' => $this->input->post('premium_status'),
'type' => $this->input->post('type'),
'days' => $this->input->post('days'),
'ncd' => date('Y-m-d',strtotime($this->input->post('ncd'))),
'remarks' => $this->input->post('remarks'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date('Y-m-d h:i:s'),
);
//print_r($renewal_data); die;
$renewal_log_data = array(
'renewal_id' => $renewal_id,
'log_policy_no' => $policy_no,
'log_sum_assured' => $this->input->post('sum_assured'),
'log_renewal_date' => $renew_date,
'log_net_premium' => $net_premium,
'log_gst' => $gst,
'log_total_premium' => $total_premium,
'log_rider_net_premium' => $rider_net_premium,
'log_rider_gst' => $rider_gst,
'log_rider_total_premium' => $rider_total_premium,
'log_overall_net_premium' => $overall_net_premium,
'log_overall_total_premium' => $overall_total_premium,
'log_from' => $from,
'log_to' => $due_date,
'log_mode' => $this->input->post('mode'),
'log_renew_paid_by' => $this->input->post('renew_paid_by'),
'log_due_date' => $due_date,
'log_paying_year' => $paying_year,
'log_renew_status' => $this->input->post('renewal_status'),
'log_client_status' => $this->input->post('client_status'),
'log_renew_reason' => $this->input->post('reason'),
'log_not_contact_reason' => $this->input->post('not_contact_reason'),
'log_premium_status' => $this->input->post('premium_status'),
'log_type' => $this->input->post('type'),
'log_days' => $this->input->post('days'),
'log_remarks' => $this->input->post('remarks'),
//'log_amount' => $this->input->post('amount'),
//'log_rejected_reason' => $this->input->post('rejected_reason'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date('Y-m-d h:i:s'),
);
$mode = $this->input->post('mode');
if($renewal_status === "Paid"){
$due_date = $this->Renewal_model->update_next_renewal($renewal_id,$mode);
$renewal_log_data['log_due_date'] = $due_date;
}else
if($renewal_status === "Renewed"){
$this->Renewal_model->update_next_HTH_renewal($renewal_id,$due_date,$paying_year);
}
$this->Renewal_model->save($renewal_data,$renewal_id);
$this->Renewal_model->save_log($renewal_log_data,$renewal_id);
echo json_encode(array('success' => TRUE, 'message' => "Renewal updated".' '. $renewal_id, 'id' => $renewal_id));
}
public function get_rm_name($rm_name){
$final_rm = $this->Renewal_model->get_rm_name($rm_name);
echo $final_rm;
}
public function get_tl_name($source){
$tl_name = $this->Renewal_model->get_source_name($source);
echo $tl_name;
}
}
?>