File: //home/cafsindia/.trash/application.1/controllers/Income_tax_process.php
<?php
if (!defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Income_tax_process extends Action_controller{
public function __construct(){
parent::__construct('income_tax_process');
$this->load->model('income_tax_process_model');
if (!$this->Appconfig->isAppvalid()){
redirect('config');
}
// Load pdf library
require_once "./dist/eos-1.0.0/eos.class.php";
$eq = new eqEOS();
$this->load->library('pdf');
}
// LOAD PAGE WITH TABLE DATA
public function index(){
//PAGE INFO FUNCTION
$this->page_info();
$role_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_category` where trans_status = 1 and prime_category_id !=1')");
$role_result = $role_info->result();
$role_info->next_result();
$process_role[""] = "---- Select Role ----";
foreach ($role_result as $for){
$role_id = $for->prime_category_id;
$category_name = $for->category_name;
$process_role[$role_id] = $category_name;
}
$data['process_role'] = $process_role;
$data['table_headers'] = $this->xss_clean(get_dbtable_headers($this->table_info));
$data['fliter_list'] = $this->fliter_list;
$data['link_info'] = $this->quick_link;
$data['key'] = $this->generateKey();
$this->load->view("$this->control_name/manage", $data);
}
public function emp_suggest(){
//Encryption
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$search_term = $this->input->post('term');
$final_qry = 'select employee_code,emp_name from cw_employees where trans_status = 1 and (employee_code like "' . $search_term . '%" or emp_name like "' . $search_term . '%")';
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_result = $final_data->result();
$final_data->next_result();
foreach($final_result as $rslt){
$employee_code = $rslt->employee_code;
$emp_name = $rslt->emp_name;
$suggestions[] = array(
'value' => $employee_code,
'label' => "$employee_code - $emp_name"
);
}
if(empty($suggestions)){
$suggestions[] = array(
'value' => "0",
'label' => "No data found for this search"
);
}
echo json_encode($suggestions);
}
//SAVE MODEL DATA TO DATA BASE
public function process_tax(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$this->save_info();
$process_month = $this->input->post('process_month');
$annexure_sts = $this->input->post('annexure_sts');
$process_type = (int) $this->input->post('process_type');
$process_emp_code = $this->input->post('process_emp_id');
$process_role = (int) $this->input->post('process_role');
$process_mode = $this->input->post('process_mode');
$proof_wise = $this->input->post('proof_wise');
$month_name = date("F", strtotime("01-" . $process_month));
$logged_id = $this->session->userdata('logged_id');
$today_date = date("Y-m-d H:i:s");
$process_from = "income_tax_process";
$rslt = $this->income_tax_process_model->income_tax_with_process_payroll($process_month,$annexure_sts,$process_type,$process_emp_code,$process_role,$process_mode,$proof_wise,$month_name,$logged_id,$today_date,$process_from,"");
return $rslt;
}
public function view_tax(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$employee_code = $this->input->post('employee_code');
$process_month = $this->input->post('process_month');
$month_ar = "01-".$process_month;
$fin_year = date("m",strtotime($month_ar)) >= 4 ? date("Y",strtotime($month_ar)). '-' . (date("Y",strtotime($month_ar))+1) : (date("Y",strtotime($month_ar)) - 1). '-' . date("Y",strtotime($month_ar));
$fin_year = explode('-', $fin_year);
$start_month = $fin_year[0]."-04";
$end_month = $fin_year[1]."-03";
$view_tax_qry = 'select process_month,monthly_tds from cw_transactions where employee_code like "' . $employee_code . '" and trans_status = 1 and DATE_FORMAT(str_to_date(CONCAT("01-", process_month), "%d-%m-%Y"), "%Y-%m") >= "'.$start_month.'" and DATE_FORMAT(str_to_date(CONCAT("01-", process_month), "%d-%m-%Y"), "%Y-%m") <= "'.$end_month.'" order by DATE_FORMAT(str_to_date(CONCAT("01-", process_month), "%d-%m-%Y"), "%Y-%m") desc';
$view_tax_data = $this->db->query("CALL sp_a_run ('SELECT','$view_tax_qry')");
$view_tax_result= $view_tax_data->result_array();
$view_tax_data->next_result();
$tr_line = "";
foreach ($view_tax_result as $value) {
$process_month = $value['process_month'];
//$tds = $value['tds'];
$month_tds = $value['monthly_tds'];
$tr_line .= "<tr><td>$process_month</td><td>$tds</td><td>$month_tds</td></tr>";
}
$view_table_data = "<table class='table table-striped table-hover' id='view_table_info'>
<thead>
<th>Process Month</th><th>Tds</th><th>Monthly Tds</th>
</thead>
<tbody>$tr_line</tbody>
</table>";
echo json_encode(array('success' => TRUE,'view_table_data' => $view_table_data));
}
public function generate_pdf(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$employee_code = $this->input->post('code');
$content = $this->input->post('html');
$process_month = $this->input->post('process_month');
$cat_name = $this->input->post('category');
$password = $this->input->post('password_column');
$category_name = strtolower(str_replace(" ","_",$cat_name));
// Load HTML content
$this->dompdf->loadHtml($content);
// (Optional) Setup the paper size and orientation
$this->dompdf->setPaper('A3', 'portrait');
// Render the HTML as PDF
$this->dompdf->render();
if($password){
define('DOMPDF_ENABLE_AUTOLOAD', false);
$this->dompdf->get_canvas()->get_cpdf()->setEncryption($password, $password);
}
// Output the generated PDF (1 = download and 0 = preview)
$output = $this->dompdf->output();
$folder = "worksheet/".$category_name."/".$process_month;
//Check Folder Exist
if (!file_exists($folder)){
mkdir($folder, 0777, true);
}
//Check File Exist
if (file_exists($folder."/".$employee_code.".pdf")) {
unlink($folder."/".$employee_code.".pdf");
}
file_put_contents($folder."/".$employee_code.".pdf", $output);
//echo "BSK ".base_url().$folder."/".$employee_code.".pdf"; die;
echo trim(base_url().$folder."/".$employee_code.".pdf");
}
//UPDATE STATUS TO DELETE IN MODULE PRIMARY TABLE
public function delete(){
$delete_ids = implode(",", $this->input->post('delete_ids'));
$can_process = TRUE;
$delete_status = FALSE;
if ($this->check_delete_status()) {
$delete_status = TRUE;
$check_table_query = 'SELECT GROUP_CONCAT(prime_module_id) as prime_module_id,GROUP_CONCAT(label_name) as label_name from cw_form_setting WHERE pick_table = "' . $this->prime_table . '" and trans_status = 1 ';
$check_table_info = $this->db->query("CALL sp_a_run ('SELECT','$check_table_query')");
$check_table_rlst = $check_table_info->row();
$check_table_info->next_result();
if ($check_table_rlst->prime_module_id) {
$prime_module_id = explode(",", $check_table_rlst->prime_module_id);
$label_name = explode(",", $check_table_rlst->label_name);
$i = 0;
$select_table = '';
$select_label = '';
$select_trans_status = '';
$select_where = '';
foreach ($prime_module_id as $check_modules) {
$table_name = "cw_" . $check_modules;
$table_rename = $table_name . "_$i";
$select_table .= "$table_rename.$label_name[$i],";
$select_label .= " $table_name $table_rename,";
if ((int) $i === 0) {
$select_trans_status .= "( $table_rename.trans_status = 1";
$select_where .= " and ($table_rename.$label_name[$i] in ($delete_ids)";
} else {
$select_trans_status .= " and $table_rename.trans_status = 1";
$select_where .= " or $table_rename.$label_name[$i] in ($delete_ids)";
}
$i++;
}
$select_trans_status .= ")";
$select_where .= ")";
$select_table = rtrim($select_table, ',');
$select_label = rtrim($select_label, ',');
$check_module_query .= 'SELECT ' . $select_table . ' from ' . $select_label . ' WHERE ' . $select_trans_status . ' ' . $select_where . ' LIMIT 0,1';
$check_module_info = $this->db->query("CALL sp_a_run ('SELECT','$check_module_query')");
$values_count = $check_module_info->num_rows();
$check_module_info->next_result();
if ((int) $values_count > 0) {
$can_process = False;
$delete_status = False;
}
}
if ($delete_status) {
$delete_query = 'DELETE FROM ' . $this->prime_table . ' WHERE ' . $this->prime_id . ' in (' . $delete_ids . ')';
if ($this->db->query("CALL sp_a_run ('RUN','$delete_query')")) {
$row_set_query = 'SELECT form_view_label_name from cw_form_view_setting where form_view_type = "3" and prime_view_module_id = "' . $this->control_name . '" and trans_status = 1';
$row_set_info = $this->db->query("CALL sp_a_run ('SELECT','$row_set_query')");
$row_count = (int) $row_set_info->num_rows();
$row_set_info->next_result();
if ($row_count !== 0) {
$row_set_result = $row_set_info->result();
$delete_table_name = '';
$delete_table_condition = '';
foreach ($row_set_result as $row_set) {
$row_set_table_name = "cw_" . $this->control_name . "_" . $row_set->form_view_label_name;
$delete_table_name .= "$row_set_table_name,";
$delete_table_condition .= " $row_set_table_name.$this->prime_id in ('$delete_ids') and";
}
$delete_table_name = rtrim($delete_table_name, ',');
$delete_table_condition = rtrim($delete_table_condition, 'and');
$delete_row_set_query = 'DELETE FROM ' . $delete_table_name . ' WHERE ' . $delete_table_condition . '';
$this->db->query("CALL sp_a_run ('RUN','$delete_row_set_query')");
}
$can_process = False;
}
}
}
if ($can_process) {
$created_on = date("Y-m-d h:i:s");
$prime_upd_query .= 'trans_deleted_by = "' . $this->logged_id . '",trans_deleted_date = "' . $created_on . '"';
$prime_update_query = 'UPDATE ' . $this->prime_table . ' SET trans_status = 0,' . $prime_upd_query . ' WHERE ' . $this->prime_id . ' in (' . $delete_ids . ')';
if ($this->db->query("CALL sp_a_run ('UPDATE','$prime_update_query')")) {
echo json_encode(array(
'success' => TRUE,
'message' => "Successfully Deleted"
));
} else {
echo json_encode(array(
'success' => FALSE,
'message' => "Unable to delete"
));
}
} else if ($delete_status) {
echo json_encode(array(
'success' => TRUE,
'message' => "Successfully Deleted"
));
} else {
$modules = ucwords($check_table_rlst->prime_module_id);
echo json_encode(array(
'success' => FALSE,
'message' => "Unable to delete, This value is already used in $modules modules"
));
}
}
//CHECK UNIQUE FIELD STATUS
public function check_delete_status(){
$check_delete_query = 'SELECT GROUP_CONCAT(unique_field) as unique_field from cw_form_setting WHERE prime_module_id = "' . $this->control_name . '" and trans_status = 1 ';
$check_delete_info = $this->db->query("CALL sp_a_run ('SELECT','$check_delete_query')");
$check_delete_rlst = $check_delete_info->row();
$check_delete_info->next_result();
$unique_info = explode(",", $check_delete_rlst->unique_field);
if (in_array('1', $unique_info ?? [])) {
return TRUE;
} else {
return FALSE;
}
}
public function get_yearly_annex($annex_pdf_check, $emp_code, $view_det, $emp_name, $designation)
{
$financial_info = $this->get_financial_year();
$start_date = $financial_info[0]->start_date;
$end_date = $financial_info[0]->end_date;
$start_text = date("d-M-Y", strtotime($start_date));
$end_text = date("d-M-Y", strtotime($end_date));
$begin = new DateTime($start_date);
$end = new DateTime($end_date);
$month_td = "";
$arr = array(
"total" => "Total"
);
while ($begin <= $end) {
$month_list = $begin->format('M');
$month = $begin->format('m-Y');
echo $begin->modify('first day of next month');
$month_td .= "<td><b>$month_list</b></td>";
$arr[$month] = "";
}
$month_td_list = "<tr><td><b>Earnings</b></td>$month_td</tr>";
$tr_line = "";
foreach ($annex_pdf_check as $lable => $annex_val){
if($lable !== 'total'){
$view_lable = $view_det[$lable];
}else{
$view_lable = 'Total';
}
$td_line = "";
$total_array = array();
foreach ($annex_val as $ann_key => $ann_val) {
$arr[$ann_key] += $ann_val;
$td_line .= "<td>$ann_val</td>";
}
$tr_line .= "<tr><td>$view_lable</td>$td_line</tr>";
}
$final_td = "";
$final_tr = "";
foreach ($arr as $arr_key => $arr_val){
if ($arr_val !== "Total") {
$arr_val = number_format((float) $arr_val, 2, '.', '');
}
$final_td .= "<td>$arr_val</td>";
}
$final_tr = "<tr style='font-weight:bold;'>$final_td</tr>";
$company_name = $this->company_info[0]->company_name;
$company_address = $this->company_info[0]->address;
$company_city = $this->company_info[0]->city;
$company_state = $this->company_info[0]->state;
$company_country = $this->company_info[0]->country;
$company_details = "<b>$company_name</b><br/><b>$company_address</b><br/><b>$company_city</b><br/><b>$company_state</b><br/><b>$company_country</b>";
$table_data = "<div style='page-break-after: always;width:auto; margin-left: auto; margin-right: auto; padding: 15px; background-color: #EEEEEE; border-radius: 3px; box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);'>
<table style='width:100%;border-collapse: collapse;border-spacing: 0;border-color: #CCCCCC !important;border: 1px solid black;text-align: left;font-size: 14px;background-color: #FFFFFF;' border='1' cellspacing='0' cellpadding='4'>
<tbody>
<tr>
<td colspan='5'>$company_details</td>
<td colspan='8'><b>Code: $emp_code</b><br/><b>Name: $emp_name</b><br/><b>Designation: $designation</b><br/><b>$start_text - $end_text</b></td>
</tr>
$month_td_list
$tr_line
$final_tr
</tbody>
</table>
</div>";
return $table_data;
}
}
?>