?
Current Path : /home1/savoy/public_html/savoyglobal.net/rms/application/models/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/rms/application/models/hrmodel.php |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Hrmodel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); // $this->load->model('hrmodel'); } function search_designation($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('designation'); $this->db->join('master','master_id=designation_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('designation_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_designation($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'designation_id'=>$masterid, 'designation_name'=>$postdata['designation_name'], ); $this->db->insert('designation', $tblValues); $data['resfunction']='search_designation'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_designation($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array('designation_name'=>$postdata['designation_name']); $this->db->where('designation_id',$postdata['designation_id']); $this->db->update('designation', $tblValues); $data['resfunction']='search_designation'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_department($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('department'); $this->db->join('master','master_id=department_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('department_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_department($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'department_id'=>$masterid, 'department_name'=>$postdata['department_name'], ); $this->db->insert('department', $tblValues); $data['resfunction']='search_department'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_department($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'department_name'=>$postdata['department_name'] ); $this->db->where('department_id',$postdata['department_id']); $this->db->update('department', $tblValues); $data['resfunction']='search_department'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_grade($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('grade'); $this->db->join('master','master_id=grade_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('grade_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_grade($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'grade_id'=>$masterid, 'grade_name'=>$postdata['grade_name'], ); $this->db->insert('grade', $tblValues); $data['resfunction']='search_grade'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_grade($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'grade_name'=>$postdata['grade_name'] ); $this->db->where('grade_id',$postdata['grade_id']); $this->db->update('grade', $tblValues); $data['resfunction']='search_grade'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_status($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('status'); $this->db->join('master','master_id=status_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('status_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_status($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'status_id'=>$masterid, 'status_name'=>$postdata['status_name'], ); $this->db->insert('status', $tblValues); $data['resfunction']='search_status'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_status($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'status_name'=>$postdata['status_name'] ); $this->db->where('status_id',$postdata['status_id']); $this->db->update('status', $tblValues); $data['resfunction']='search_status'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_employee($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('employee'); $this->db->join('master','master_id=employee_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('employee_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_employee($postdata) { $data=array(); $this->db->trans_begin(); $employee_no=$this->mastermodel->get_master_code('employee','Employee','employee_no','employee_id'); $masterid = $this->mastermodel->insertmasterdata(); $emp_watchman = 0; if(isset ($postdata['employee_watchman'])) $emp_watchman = 1; $emp_supervisor = 0; if(isset ($postdata['employee_supervisor'])) $emp_supervisor = 1; $tblValues=array( 'employee_id'=>$masterid, 'employee_name'=>$postdata['employee_name'], 'employee_gender'=>$postdata['employee_gender'], 'employee_dob'=>$this->mastermodel->convertdateformat($postdata['employee_dob']), 'employee_marital_status'=>$postdata['employee_marital_status'], 'employee_nationality'=>$postdata['employee_nationality'], 'employee_no'=>$employee_no, 'employee_passport_no'=>$postdata['employee_passport_no'], 'employee_visa_type'=>$postdata['employee_visa_type'], 'employee_visa_expiry_date'=>$this->mastermodel->convertdateformat($postdata['employee_visa_expiry_date']), 'employee_contact_no'=>$postdata['employee_contact_no'], 'employee_local_address'=>$postdata['employee_local_address'], 'employee_permanent_address'=>$postdata['employee_permanent_address'], 'employee_designation_id'=>$postdata['employee_designation_id'], 'employee_department_id'=>$postdata['employee_department_id'], 'employee_grade_id'=>$postdata['employee_grade_id'], 'employee_status'=>$postdata['employee_status'], 'employee_joining_date'=>$this->mastermodel->convertdateformat($postdata['employee_joining_date']), 'employee_labour_card_no'=>$postdata['employee_labour_card_no'], 'employee_labour_card_expiry_date'=>$this->mastermodel->convertdateformat($postdata['employee_labour_card_expiry_date']), 'employee_health_card_no'=>$postdata['employee_health_card_no'], 'employee_health_card_expiry_date'=>$this->mastermodel->convertdateformat($postdata['employee_health_card_expiry_date']), 'employee_vehicle_no'=>$postdata['employee_vehicle_no'], 'employee_vehicle_expiry_date'=>$this->mastermodel->convertdateformat($postdata['employee_vehicle_expiry_date']), 'employee_email'=>$postdata['employee_email'], 'employee_watchman'=>$emp_watchman, 'employee_reporting_to'=>$postdata['employee_reporting_to'], 'employee_supervisor'=>$emp_supervisor, 'passport_expiry_date'=>$this->mastermodel->convertdateformat($postdata['passport_expiry_date']), 'passport_remind_before'=>$postdata['passport_remind_before'], 'visa_remind_before'=>$postdata['visa_remind_before'], 'health_card_remind_before'=>$postdata['health_card_remind_before'], 'vehicle_remind_before'=>$postdata['vehicle_remind_before'], 'labor_card_remind_before'=>$postdata['labor_card_remind_before'] ); $this->db->insert('employee', $tblValues); $parent= $this->mastermodel->get_account_settings('employee','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); if($this->mastermodel->get_num_rows('finance_chart_master','chart_account_code',$employee_no)==0) { $tblValues=array('chart_account_code'=>$employee_no, 'chart_account_name'=>$postdata['employee_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues=array( 'chart_account_name'=>$postdata['employee_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->where('chart_account_code', $employee_no); $this->db->update('finance_chart_master', $tblValues); } } $i=1; while(isset($postdata['course'.$i])) { if($postdata['course'.$i]!='') { $tblValues1=array( 'employee_id'=>$masterid, 'course'=>$postdata['course'.$i], 'university'=>$postdata['university'.$i], 'yearofpassing'=>$postdata['yearofpassing'.$i] ); $this->db->insert('employee_educational_qualification', $tblValues1); } $i++; } $i=1; while(isset($postdata['employer'.$i])) { if($postdata['employer'.$i]!='') { $tblValues1=array( 'employee_id'=>$masterid, 'employer'=>$postdata['employer'.$i], 'designation'=>$postdata['designation'.$i], 'period'=>$postdata['period'.$i]); $this->db->insert('employee_professional_experience', $tblValues1); } $i++; } $i=1; while(isset($postdata['additional_course'.$i])) { if($postdata['additional_course'.$i]!='') { $tblValues1=array( 'employee_id'=>$masterid, 'course'=>$postdata['additional_course'.$i], 'institute'=>$postdata['additional_institute'.$i], 'yearofpassing'=>$postdata['additional_yearofpassing'.$i]); $this->db->insert('employee_additional_certification', $tblValues1); } $i++; } if(($postdata['visa_remind_before'])!='') { $masterid1 = $this->mastermodel->insertmasterdata(); $date=$this->mastermodel->convertdateformat($postdata['employee_visa_expiry_date']); $date=date('Y-m-d', strtotime($date. ' - '.$postdata['visa_remind_before'].' days')); $tblValues=array( 'alert_id'=>$masterid1, 'alert_record_id'=>$masterid, 'alert_master_id'=>$postdata['visa_alert_master_id'], 'alert_date'=>$date, 'alert_status'=>'1' ); $this->db->insert('alert',$tblValues); for($i=1;$i<$postdata['visa_alert_limit'];$i++) { if(isset($postdata['visa_alert_'.$i])) { $tblValues=array( 'alert_id'=>$masterid1, 'employee_id'=>$postdata['visa_alert_'.$i] ); $this->db->insert('alert_employee',$tblValues); } } } if(($postdata['health_card_remind_before'])!='') { $masterid1 = $this->mastermodel->insertmasterdata(); $date=$this->mastermodel->convertdateformat($postdata['employee_health_card_expiry_date']); $date=date('Y-m-d', strtotime($date. ' - '.$postdata['health_card_remind_before'].' days')); $tblValues=array( 'alert_id'=>$masterid1, 'alert_record_id'=>$masterid, 'alert_master_id'=>$postdata['health_alert_master_id'], 'alert_date'=>$date, 'alert_status'=>'1' ); $this->db->insert('alert',$tblValues); for($i=1;$i<$postdata['health_alert_limit'];$i++) { if(isset($postdata['health_alert_'.$i])) { $tblValues=array( 'alert_id'=>$masterid1, 'employee_id'=>$postdata['health_alert_'.$i] ); $this->db->insert('alert_employee',$tblValues); } } } if(($postdata['vehicle_remind_before'])!='') { $masterid1 = $this->mastermodel->insertmasterdata(); $date=$this->mastermodel->convertdateformat($postdata['employee_vehicle_expiry_date']); $date=date('Y-m-d', strtotime($date. ' - '.$postdata['vehicle_remind_before'].' days')); $tblValues=array( 'alert_id'=>$masterid1, 'alert_record_id'=>$masterid, 'alert_master_id'=>$postdata['vehicle_alert_master_id'], 'alert_date'=>$date, 'alert_status'=>'1' ); $this->db->insert('alert',$tblValues); for($i=1;$i<$postdata['vehicle_alert_limit'];$i++) { if(isset($postdata['vehicle_alert_'.$i])) { $tblValues=array( 'alert_id'=>$masterid1, 'employee_id'=>$postdata['vehicle_alert_'.$i] ); $this->db->insert('alert_employee',$tblValues); } } } if(($postdata['labor_card_remind_before'])!='') { $date=$this->mastermodel->convertdateformat($postdata['employee_labour_card_expiry_date']); $date=date('Y-m-d', strtotime($date. ' - '.$postdata['labor_card_remind_before'].' days')); $masterid1 = $this->mastermodel->insertmasterdata(); $tblValues=array( 'alert_id'=>$masterid1, 'alert_record_id'=>$masterid, 'alert_master_id'=>$postdata['labor_alert_master_id'], 'alert_date'=>$date, 'alert_status'=>'1' ); $this->db->insert('alert',$tblValues); for($i=1;$i<$postdata['labor_alert_limit'];$i++) { if(isset($postdata['labor_alert_'.$i])) { $tblValues=array( 'alert_id'=>$masterid1, 'employee_id'=>$postdata['labor_alert_'.$i] ); $this->db->insert('alert_employee',$tblValues); } } } $data['resfunction']='search_employee'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_employee($postdata) { $data=array(); $this->db->trans_begin(); $emp_watchman = 0; if(isset ($postdata['employee_watchman'])) $emp_watchman = 1; $emp_supervisor = 0; if(isset ($postdata['employee_supervisor'])) $emp_supervisor = 1; $tblValues=array( 'employee_name'=>$postdata['employee_name'], 'employee_gender'=>$postdata['employee_gender'], 'employee_dob'=>$this->mastermodel->convertdateformat($postdata['employee_dob']), 'employee_marital_status'=>$postdata['employee_marital_status'], 'employee_nationality'=>$postdata['employee_nationality'], 'employee_passport_no'=>$postdata['employee_passport_no'], 'employee_visa_type'=>$postdata['employee_visa_type'], 'employee_visa_expiry_date'=>$this->mastermodel->convertdateformat($postdata['employee_visa_expiry_date']), 'employee_contact_no'=>$postdata['employee_contact_no'], 'employee_local_address'=>$postdata['employee_local_address'], 'employee_permanent_address'=>$postdata['employee_permanent_address'], 'employee_designation_id'=>$postdata['employee_designation_id'], 'employee_department_id'=>$postdata['employee_department_id'], 'employee_grade_id'=>$postdata['employee_grade_id'], 'employee_status'=>$postdata['employee_status'], 'employee_joining_date'=>$this->mastermodel->convertdateformat($postdata['employee_joining_date']), 'employee_labour_card_no'=>$postdata['employee_labour_card_no'], 'employee_labour_card_expiry_date'=>$this->mastermodel->convertdateformat($postdata['employee_labour_card_expiry_date']), 'employee_email'=>$postdata['employee_email'], 'employee_watchman'=>$emp_watchman, 'employee_reporting_to'=>$postdata['employee_reporting_to'], 'employee_supervisor'=>$emp_supervisor, 'passport_expiry_date'=>$this->mastermodel->convertdateformat($postdata['passport_expiry_date']), 'passport_remind_before'=>$postdata['passport_remind_before'], 'visa_remind_before'=>$postdata['visa_remind_before'], 'labor_card_remind_before'=>$postdata['labor_card_remind_before'] ); $this->db->where('employee_id',$postdata['employee_id']); $this->db->update('employee',$tblValues); $this->db->where('employee_id',$postdata['employee_id']); $this->db->delete('employee_educational_qualification'); $i=1; while(isset($postdata['course'.$i])) { if($postdata['course'.$i]!='') { $tblValues1=array( 'employee_id'=>$postdata['employee_id'], 'course'=>$postdata['course'.$i], 'university'=>$postdata['university'.$i], 'yearofpassing'=>$postdata['yearofpassing'.$i] ); $this->db->insert('employee_educational_qualification', $tblValues1); } $i++; } $this->db->where('employee_id',$postdata['employee_id']); $this->db->delete('employee_professional_experience'); $i=1; while(isset($postdata['employer'.$i])) { if($postdata['employer'.$i]!='') { $tblValues1=array( 'employee_id'=>$postdata['employee_id'], 'employer'=>$postdata['employer'.$i], 'designation'=>$postdata['designation'.$i], 'period'=>$postdata['period'.$i]); $this->db->insert('employee_professional_experience', $tblValues1); } $i++; } $this->db->where('employee_id',$postdata['employee_id']); $this->db->delete('employee_additional_certification'); $i=1; while(isset($postdata['additional_course'.$i])!='') { if($postdata['additional_course'.$i]!='') { $tblValues1=array( 'employee_id'=>$postdata['employee_id'], 'course'=>$postdata['additional_course'.$i], 'institute'=>$postdata['additional_institute'.$i], 'yearofpassing'=>$postdata['additional_yearofpassing'.$i]); $this->db->insert('employee_additional_certification', $tblValues1); } $i++; } $this->db->where('employee_id',$postdata['employee_id']); $this->db->update('employee', $tblValues); $parent= $this->mastermodel->get_account_settings('employee','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); if($this->mastermodel->get_num_rows('finance_chart_master','chart_account_code',$postdata['employee_no'])==0) { $tblValues=array('chart_account_code'=>$postdata['employee_no'], 'chart_account_name'=>$postdata['employee_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues=array( 'chart_account_name'=>$postdata['employee_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->where('chart_account_code', $postdata['employee_no']); $this->db->update('finance_chart_master', $tblValues); } } // $tblValues=array('chart_account_name'=>$postdata['employee_name']); // $this->db->where('chart_account_code',$postdata['employee_no']); // $this->db->update('finance_chart_master', $tblValues); $data['resfunction']='search_employee'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_leave_allocation($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('leave_allocation'); $this->db->join('employee','employee.employee_id=leave_allocation.employee_id'); $this->db->join('master','master_id=leave_allocation_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('leave_allocation_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_leave_allocation($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array('leave_allocation_id'=>$masterid, 'employee_id'=> $postdata['employee_id'], 'leave_allocation_year'=> $postdata['leave_allocation_year']); $this->db->insert('leave_allocation', $tblValues); $i=1; while(isset($postdata['leave_type_id'.$i])) { $tblValues=array('leave_allocation_id'=>$masterid, 'leave_type_id'=>$postdata['leave_type_id'.$i], 'leave_allocation_days'=> $postdata['leave_allocation_days'.$i]); $this->db->insert('leave_allocation_detail', $tblValues); $i++; } $data['resfunction']='search_leave_allocation'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_leave_allocation($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['leave_allocation_id']); $tblValues=array( 'leave_allocation_year'=> $postdata['leave_allocation_year']); $this->db->where('leave_allocation_id', $postdata['leave_allocation_id']); $this->db->update('leave_allocation', $tblValues); $this->db->where('leave_allocation_id', $postdata['leave_allocation_id']); $this->db->delete('leave_allocation_detail'); $i=1; while(isset($postdata['leave_type_id'.$i])) { $tblValues=array('leave_allocation_id'=>$postdata['leave_allocation_id'], 'leave_type_id'=>$postdata['leave_type_id'.$i], 'leave_allocation_days'=> $postdata['leave_allocation_days'.$i]); $this->db->insert('leave_allocation_detail', $tblValues); $i++; } $data['resfunction']='search_leave_allocation'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_leave_application($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $emp=$this->mastermodel->get_single_field_value('user','employee_id','user_id',$_SESSION['user_id']); $this->db->select('*'); $this->db->from('leave_application'); $this->db->join('employee','employee.employee_id=leave_application.employee_id'); $this->db->join('master','master_id=leave_application_id'); $this->db->where('master.login_type_id',$log_in_type); if($_SESSION['user_id']!=1) $this->db->where('employee.employee_reporting_to',$emp); $this->db->order_by('leave_application_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_leave_application($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $fromdate = $this->mastermodel->convertdateformat($postdata['from_date']); $todate = $this->mastermodel->convertdateformat($postdata['to_date']); $tblValues=array('leave_application_id'=>$masterid, 'employee_id'=> $postdata['employee_id'], 'leave_type_id'=> $postdata['leave_type_id'], 'from_date'=> $fromdate, 'to_date'=> $todate, 'remarks'=> $postdata['remarks']); $this->db->insert('leave_application', $tblValues); $data['resfunction']='search_leave_application'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_leave_application($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['leave_application_id']); $fromdate = $this->mastermodel->convertdateformat($postdata['from_date']); $todate = $this->mastermodel->convertdateformat($postdata['to_date']); $tblValues=array( 'leave_type_id'=> $postdata['leave_type_id'], 'from_date'=> $fromdate, 'to_date'=> $todate, 'remarks'=> $postdata['remarks']); $this->db->where('leave_application_id', $postdata['leave_application_id']); $this->db->update('leave_application', $tblValues); $data['resfunction']='search_leave_application'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function leave_approval($id,$status) { $tblvalue=array( 'leave_status'=>$status ); $this->db->where('leave_application_id',$id); $this->db->update('leave_application',$tblvalue); } function search_leave_type($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('leave_type'); $this->db->join('master','master_id=leave_type_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('leave_type_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_leave_type($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'leave_type_id'=>$masterid, 'leave_code'=>$postdata['leave_code'], 'leave_type_name'=>$postdata['leave_type_name'] ); $this->db->insert('leave_type', $tblValues); $data['resfunction']='search_leave_type'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_leave_type($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'leave_code'=>$postdata['leave_code'], 'leave_type_name'=>$postdata['leave_type_name'] ); $this->db->where('leave_type_id',$postdata['leave_type_id']); $this->db->update('leave_type', $tblValues); $data['resfunction']='search_leave_type'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_holiday($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('holiday'); $this->db->join('master','master_id=holiday_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('holiday_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_holiday($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'holiday_id'=>$masterid, 'holiday_name'=>$postdata['holiday_name'], 'holiday_start_date'=>$this->mastermodel->convertdateformat($postdata['holiday_start_date']), 'holiday_end_date'=>$this->mastermodel->convertdateformat($postdata['holiday_end_date']), ); $this->db->insert('holiday', $tblValues); $data['resfunction']='search_holiday'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_holiday($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'holiday_name'=>$postdata['holiday_name'], 'holiday_start_date'=>$this->mastermodel->convertdateformat($postdata['holiday_start_date']), 'holiday_end_date'=>$this->mastermodel->convertdateformat($postdata['holiday_end_date']), ); $this->db->where('holiday_id',$postdata['holiday_id']); $this->db->update('holiday', $tblValues); $data['resfunction']='search_holiday'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_tool_kit($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('tool_kit'); $this->db->join('master','master_id=tool_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('tool_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_tool_kit($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array('tool_id'=>$masterid, 'designation_id'=>$postdata['designation_id']); $this->db->insert('tool_kit', $tblValues); $i=1; while(isset($postdata['tool_name'.$i])!='') { $tblValues=array( 'tool_id'=>$masterid, 'tool_name'=>$postdata['tool_name'.$i] ); $this->db->insert('tool_kit_details', $tblValues); $i++; } $data['resfunction']='search_tool_kit'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_tool_kit($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['tool_id']); $i=1; $this->db->where('tool_id',$postdata['tool_id']); $this->db->delete('tool_kit_details'); while(isset($postdata['tool_id'.$i])) { $tblValues=array('tool_id'=>$postdata['tool_id'], 'tool_name'=> $postdata['tool_id'.$i]); $this->db->insert('tool_kit_details', $tblValues); $i++; } $data['resfunction']='search_tool_kit'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_allowdeduc($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('allowdeduc'); $this->db->join('master','master_id=allowdeduc_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('allowdeduc_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_allowdeduc($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $accno = $this->getmaxexpense(); $dedacc = $accno + 1; $tblValues = array( 'allowdeduc_id' => $masterid, 'allowdeduc_name' => $postdata['allowdeduc_name'], 'allowdeduc_type' => $postdata['allowdeduc_type'], 'allowdeduc_mode' => $postdata['allowdeduc_mode'], 'chart_account_code' => $dedacc ); $this->db->insert('allowdeduc', $tblValues); $parent= $this->mastermodel->get_account_settings('salary','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); $tblValues=array( 'chart_account_code'=>$dedacc, 'chart_account_name'=>$postdata['allowdeduc_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0 ); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues=array('chart_account_name'=>$postdata['allowdeduc_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->where('chart_account_code',$dedacc); $this->db->update('finance_chart_master',$tblValues); } $data['resfunction']='search_allowdeduc'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function getmaxexpense() { $parent= $this->mastermodel->get_account_settings('salary','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); $res= $this->db->query("SELECT max(`chart_account_code`) as max FROM `finance_chart_master` WHERE `chart_type_id`=$chart_type_id and parent=$parent"); $row=$res->row(); return $row->max; } } function update_allowdeduc($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array('allowdeduc_name'=>$postdata['allowdeduc_name'], 'allowdeduc_type'=>$postdata['allowdeduc_type'], 'allowdeduc_mode'=>$postdata['allowdeduc_mode'] ); $this->db->where('allowdeduc_id',$postdata['allowdeduc_id']); $this->db->update('allowdeduc', $tblValues); $tblValues=array('chart_account_name'=>$postdata['allowdeduc_name'] ); $this->db->where('chart_account_code',$postdata['chart_account_code']); $this->db->update('finance_chart_master', $tblValues); $data['resfunction']='search_allowdeduc'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_tool_allocation($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('tool_allocation'); $this->db->join('master','master_id=tool_allocation_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('tool_allocation_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_tool_allocation($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'tool_allocation_id'=>$masterid, 'employee_id'=>$postdata['employee_id'], 'tool_allocation_date'=>$this->mastermodel->convertdateformat($postdata['tool_allocation_date']), ); $this->db->insert('tool_allocation', $tblValues); $i=1; while (isset($postdata['tool_id'.$i])) { if(isset($postdata['select_tool_'.$i])) { $tblValues=array( 'tool_allocation_id'=>$masterid, 'tool_allocation_kit_id'=>$postdata['tool_id'.$i], 'tool_allocation_kit_qty'=>$postdata['tool_allocation_kit_qty'.$i], 'tool_allocation_kit_remarks'=>$postdata['tool_allocation_kit_remarks'.$i] ); $this->db->insert('tool_allocation_details', $tblValues); } $i++; } $data['resfunction']='search_tool_allocation'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_tool_allocation($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['tool_allocation_id']); $tblValues=array('tool_allocation_date'=>$this->mastermodel->convertdateformat($postdata['tool_allocation_date']), 'employee_id'=>$postdata['employee_id'] ); $this->db->where('tool_allocation_id', $postdata['tool_allocation_id']); $this->db->update('tool_allocation', $tblValues); $this->db->where('tool_allocation_id', $postdata['tool_allocation_id']); $this->db->delete('tool_allocation_details'); $i=1; while (isset($postdata['tool_id'.$i])) { $tblValues=array( 'tool_allocation_id'=>$postdata['tool_allocation_id'], 'tool_allocation_kit_id'=>$postdata['tool_id'.$i], 'tool_allocation_kit_qty'=>$postdata['tool_allocation_kit_qty'.$i], 'tool_allocation_kit_remarks'=>$postdata['tool_allocation_kit_remarks'.$i] ); $this->db->insert('tool_allocation_details', $tblValues); $i++; } $data['resfunction']='search_tool_allocation'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_tool_return($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('tool_return'); $this->db->join('master','master_id=tool_return_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('tool_return_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_tool_return($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'tool_return_id'=>$masterid, 'employee_id'=>$postdata['employee_id'], 'tool_return_date'=>$this->mastermodel->convertdateformat($postdata['tool_return_date']), ); $this->db->insert('tool_return', $tblValues); $i=1; while (isset($postdata['tool_id'.$i])) { if(isset($postdata['select_tool_'.$i])) { $tblValues=array( 'tool_return_id'=>$masterid, 'tool_kit_id'=>$postdata['tool_id'.$i], 'tool_return_qty'=>$postdata['tool_return_qty'.$i], 'tool_return_remarks'=>$postdata['tool_return_remarks'.$i] ); $this->db->insert('tool_return_details', $tblValues); } $i++; } $data['resfunction']='search_tool_return'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_tool_return($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['tool_return_id']); $tblValues=array('tool_return_date'=>$this->mastermodel->convertdateformat($postdata['tool_return_date'])); $this->db->where('tool_return_id', $postdata['tool_return_id']); $this->db->update('tool_return', $tblValues); $this->db->where('tool_return_id', $postdata['tool_return_id']); $this->db->delete('tool_return_details'); $i=1; while (isset($postdata['tool_id'.$i])) { if(isset($postdata['select_tool_'.$i])) { $tblValues=array( 'tool_return_id'=>$postdata['tool_return_id'], 'tool_kit_id'=>$postdata['tool_id'.$i], 'tool_return_qty'=>$postdata['tool_return_qty'.$i], 'tool_return_remarks'=>$postdata['tool_return_remarks'.$i] ); $this->db->insert('tool_return_details', $tblValues); } $i++; } $data['resfunction']='search_tool_return'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_salary_setting($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('employee_salary'); $this->db->join('master','master_id=employee_salary_id'); $this->db->join('employee','employee.employee_id=employee_salary.employee_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('employee_salary_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_salary_setting($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $wef_date = $this->mastermodel->convertdateformat($postdata['wef_date']); if(isset($postdata['return_ticket'])) { $return_ticket=1; } else { $return_ticket=0; } $tblValues=array('employee_salary_id'=>$masterid, 'employee_id' => $postdata['employee_id'], 'wef_date'=> $wef_date, 'basic_salary'=> $postdata['basic_salary'], 'from_ticket'=> $postdata['from_ticket'], 'to_ticket'=> $postdata['to_ticket'], 'return_ticket'=> $return_ticket, 'no_tickets'=> $postdata['no_tickets'], 'bank_name'=> $postdata['bank_name'], 'branch_name'=> $postdata['branch_name'], 'account_no'=> $postdata['account_no'], 'payment_method'=> $postdata['payment_method']); $this->db->insert('employee_salary', $tblValues); $i=1; while(isset($postdata['amount_'.$i])) { $tblValues=array( 'employee_salary_id'=>$masterid, 'allowdeduc_id'=>$postdata['allowdeduc_id_'.$i], 'amount'=>$postdata['amount_'.$i]); $this->db->insert('employee_salary_allowdeduc', $tblValues); $i++; } $data['resfunction']='search_salary_setting'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_salary_setting($postdata) { $data=array(); $this->db->trans_begin(); $this->mastermodel->updatemasterdata($postdata['employee_salary_id']); $wef_date = $this->mastermodel->convertdateformat($postdata['wef_date']); if(isset($postdata['return_ticket'])) { $return_ticket=1; } else { $return_ticket=0; } $tblValues=array( 'employee_id' => $postdata['employee_id'], 'wef_date'=> $wef_date, 'basic_salary'=> $postdata['basic_salary'], 'from_ticket'=> $postdata['from_ticket'], 'to_ticket'=> $postdata['to_ticket'], 'return_ticket'=> $return_ticket, 'no_tickets'=> $postdata['no_tickets'], 'bank_name'=> $postdata['bank_name'], 'branch_name'=> $postdata['branch_name'], 'account_no'=> $postdata['account_no'], 'payment_method'=> $postdata['payment_method'] ); $this->db->where('employee_salary_id', $postdata['employee_salary_id']); $this->db->update('employee_salary', $tblValues); $i=1; $this->db->where('employee_salary_id',$postdata['employee_salary_id']); $this->db->delete('employee_salary_allowdeduc'); while(isset ($postdata['amount_'.$i])) { $tblValues=array( 'employee_salary_id'=>$postdata['employee_salary_id'], 'allowdeduc_id'=>$postdata['allowdeduc_id_'.$i], 'amount'=>$postdata['amount_'.$i]); $this->db->insert('employee_salary_allowdeduc', $tblValues); $i++; } $data['resfunction']='search_salary_setting'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function search_salary_payment($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $data['results']=''; return $data; } function getemployeelist() { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('employee'); $this->db->join('master','master_id=employee_id'); $this->db->join('department','department.department_id=employee.employee_department_id'); $this->db->join('designation','designation.designation_id=employee.employee_designation_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('employee_visa_expiry_date','asc'); $Q = $this->db->get(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function count_data_salary($table,$id,$date) { $date=$this->mastermodel->convdatformat($date); $query = "select employee_salary_id from $table where employee_id = '$id' and wef_date <= '$date' order by wef_date DESC limit 1"; $res = mysql_query($query); $num= mysql_num_rows($res); return $num; } function check_salary_month($id,$date) { $date=$this->mastermodel->convdatformat($date); $this->db->select('employee_salary_slip_id'); $this->db->from('employee_salary_slip'); $this->db->where('employee_id',$id); $where="month(salary_date)=month('$date') and year(salary_date)=year('$date')"; $this->db->where($where,NULL,FALSE); return $this->db->count_all_results(); } function get_employee_salary_id($employee_id,$date) { $data = array(); $date = $this->mastermodel->convertdateformat($date); $sql = "SELECT tt.* FROM employee_salary tt INNER JOIN (SELECT employee_id, MAX(wef_date) AS wefdate FROM employee_salary GROUP BY employee_id) groupedtt ON tt.employee_id = groupedtt.employee_id AND tt.wef_date = groupedtt.wefdate where tt.employee_id = '$employee_id' AND wefdate <= '$date'"; $Q = $this->db->query($sql); $result= $Q->row(); if(!empty ($result)) return $result->employee_salary_id; else return ''; } function insert_single_salary_payment($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $salary_date = $this->mastermodel->convertdateformat($postdata['salary_date']); $pay_date=date('Y-m-d'); $netpayment=$postdata['basic_salary']+$postdata['allowance']-$postdata['deduction']; $tblValues=array( 'employee_salary_slip_id'=>$masterid, 'employee_id' => $postdata['employee_id'], 'salary_date'=> $salary_date, 'pay_date'=> $pay_date, 'basic_salary'=> $postdata['basic_salary'], 'allowance_amount'=> $postdata['allowance'], 'deduction_amount'=> $postdata['deduction'], 'net_payment'=> $netpayment, 'commission_amount'=> $postdata['commission'], 'paid_amount'=> $postdata['payamount'] ); $this->db->insert('employee_salary_slip', $tblValues); $i=1; while(isset($postdata['amount_'.$i])) { $tblValues=array( 'employee_salary_slip_id'=>$masterid, 'allowdeduc_id'=>$postdata['allowdeduc_id_'.$i], 'amount'=>$postdata['amount_'.$i]); $this->db->insert('employee_salary_slip_allowdeduc', $tblValues); $i++; } $data['resfunction']='search_salary_payment'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Employee Salary Processed successfully'; return $data; } } function insert_multiple_salary_payment($postdata) { $data=array(); $this->db->trans_begin(); $salary_date = $this->mastermodel->convertdateformat($postdata['salary_date']); $pay_date=date('Y-m-d'); if(isset ($postdata['salempdet'])) { for($i=0;$i<sizeof($postdata['salempdet']);$i++) { if(isset($postdata['salempdet'][$i])) { $masterid = $this->mastermodel->insertmasterdata(); $employee_id=$postdata['salempdet'][$i]; // echo $employee_id; // die(); $salary_payment=$this->get_employee_salary_data('employee_salary',$employee_id,$postdata['salary_date']); $basic_salary = $salary_payment->basic_salary; $employee_salary_id=$salary_payment->employee_salary_id; $allowdeduc_details=$this->mastermodel->get_data('employee_salary_allowdeduc',$employee_salary_id,'employee_salary_id'); $tblValues=array('employee_salary_slip_id'=>$masterid, 'employee_id' => $employee_id, 'salary_date'=> $salary_date, 'pay_date'=> $pay_date, 'basic_salary'=> $basic_salary, ); $this->db->insert('employee_salary_slip', $tblValues); $allowance=0; $deduction=0; foreach ($allowdeduc_details as $list) { $tblValues=array( 'employee_salary_slip_id'=>$masterid, 'allowdeduc_id'=>$list['allowdeduc_id'], 'amount'=>$list['amount']); $res=$this->db->insert('employee_salary_slip_allowdeduc', $tblValues); $allowdeductype=$this->mastermodel->get_data_srow('allowdeduc',$list['allowdeduc_id'],'allowdeduc_id'); if($allowdeductype->allowdeduc_type==1) //allowance { if($allowdeductype->allowdeduc_mode==1) { $sf=1; $amount = $list['amount'] * $sf; $asubtotal= $amount; } else { $sf=0.01; $amount= $list['amount'] * $sf; $asubtotal= $basic_salary *$amount; } $allowance+=$asubtotal; } else { if($allowdeductype->allowdeduc_mode==1) { $sf=1; $amount= $list['amount'] * $sf; $dsubtotal= $amount; } else { $sf=0.01; $amount= $list['amount'] * $sf; $dsubtotal= $basic_salary *$amount; } $deduction+=$dsubtotal; } } $netpayment=$basic_salary+$allowance-$deduction; $tblValues=array('allowance_amount'=>$allowance,'deduction_amount'=>$deduction,'net_payment'=>$netpayment,'paid_amount'=>$netpayment); $this->db->where('employee_salary_slip_id',$masterid); $res=$this->db->update('employee_salary_slip', $tblValues); } } $data['resfunction']='search_salary_payment'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Salary processed succesfully'; return $data; } } else { $data['resfunction']='search_salary_payment'; $this->db->trans_rollback(); $data['res']=1; $data['msg']='No employee selected'; return $data; } } function get_employee_salary_data($table,$id,$date) { $date=$this->mastermodel->convdatformat($date); $data = array(); $sql = "select * from $table where employee_id = '$id' and wef_date <= '$date' order by wef_date DESC limit 1"; $Q= $this->db->query($sql) ; $row=$Q->row(); return $row; } function load_employee_details($id) { $employee_id=$this->mastermodel->get_single_field_value('employee','employee_id','employee_id',$id); $data['emp']=$this->mastermodel->get_data_srow('employee',$employee_id,'employee_id'); $data['designation']=$this->mastermodel->get_single_field_value('designation','designation_name','designation_id',$data['emp']->employee_designation_id); $data['department']=$this->mastermodel->get_single_field_value('department','department_name','department_id',$data['emp']->employee_department_id); $this->load->view('hr/employee_details',$data); } function search_payslip($pagenum) { $data=array(); $data['startpage']=''; $data['endpage']=''; $data['count']=''; $data['results']=''; return $data; } function search_final_settlement($pagenum) { $data=array(); $data['startpage']=''; $data['endpage']=''; $data['count']=''; $data['results']=''; return $data; } function loademployeesalary($post,$date) { $log_in_type=$_SESSION['login_type']; $data=array(); $salary_date=$this->mastermodel->convdatformat($date); $this->db->select('employee_salary_slip.employee_salary_slip_id,employee_salary_slip.salary_date,employee_salary_slip.employee_id,employee.employee_no,employee.employee_name'); $this->db->from('employee_salary_slip'); $this->db->join('master','master_id=employee_id'); $this->db->join('employee','employee.employee_id=employee_salary_slip.employee_id'); $this->db->where("month(salary_date)=month('$salary_date')and year(salary_date)=year('$salary_date') and unpost='$post'"); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('employee_salary_slip.employee_id','desc'); $res = $this->db->get(); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function loadunpostedsalary($sal_id) { $this->db->select('*'); $this->db->from('employee_salary_slip'); $this->db->join('employee','employee.employee_id=employee_salary_slip.employee_id'); $this->db->join('department','department.department_id=employee.employee_department_id'); $this->db->join('designation','designation.designation_id=employee.employee_designation_id'); $this->db->where('employee_salary_slip_id',$sal_id); $this->db->where('unpost',1); $Q = $this->db->get(); return $Q->row(); } function loadpostedsalary($sal_id) { $this->db->select('*'); $this->db->from('employee_salary_slip'); $this->db->join('employee','employee.employee_id=employee_salary_slip.employee_id'); $this->db->join('department','department.department_id=employee.employee_department_id'); $this->db->join('designation','designation.designation_id=employee.employee_designation_id'); $this->db->where('employee_salary_slip_id',$sal_id); $this->db->where('unpost',0); $Q = $this->db->get(); return $Q->row(); } function insert_multiple_posted_salary_payment($postdata) { $data=array(); $this->db->trans_begin(); $paydate=date("Y-m-d"); $memo=$postdata['memo']; $bankaccount=$postdata['bank_account_code']; if(isset($postdata['salempdet'])) { for($i=0;$i<sizeof($postdata['salempdet']);$i++) { if(isset($postdata['salempdet'][$i])) { $salid=$postdata['salempdet'][$i]; $tblValues=array( 'unpost'=>0 ); $this->db->where('employee_salary_slip_id',$salid); $this->db->update('employee_salary_slip', $tblValues); $reference_code= $this->accountingmodel->getreferencecode(3); $ref_id = $this->mastermodel->insertmasterdata(); $refdata=array('ref_id'=>$ref_id, 'ref_transaction_type_id'=>'3', 'ref_code'=>$reference_code); $this->db->insert('refs', $refdata); $fiscal_year_id=$this->mastermodel->getSingleFieldValue('company','fiscal_year_id','company_id','1'); $audittraildata=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'fiscal_year'=>$fiscal_year_id, ); $this->db->insert('audit_trail', $audittraildata); $this->db->query("insert into unposted_journal select '', '$ref_id' , '$paydate',chart_account_code,if(allowdeduc_mode<1,if(allowdeduc_type<1,-(basic_salary*amount)/100,-amount),amount),'$memo',1 from employee_salary_slip_allowdeduc join allowdeduc on allowdeduc.allowdeduc_id=employee_salary_slip_allowdeduc.allowdeduc_id join employee_salary_slip on employee_salary_slip.employee_salary_slip_id=employee_salary_slip_allowdeduc.employee_salary_slip_id where employee_salary_slip.employee_salary_slip_id='$salid'"); $this->db->query("insert into gl_trans select '','$ref_id' , '$paydate',chart_account_code,'$memo',if(allowdeduc_mode<1,if(allowdeduc_type<1,-(basic_salary*amount)/100,-amount),amount) from employee_salary_slip_allowdeduc join allowdeduc on allowdeduc.allowdeduc_id=employee_salary_slip_allowdeduc.allowdeduc_id join employee_salary_slip on employee_salary_slip.employee_salary_slip_id=employee_salary_slip_allowdeduc.employee_salary_slip_id where employee_salary_slip.employee_salary_slip_id='$salid'"); $this->db->query("insert into unposted_journal select '','$ref_id' , '$paydate',employee_no,0-paid_amount,'$memo',1 from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); $this->db->query("insert into gl_trans select '','$ref_id' , '$paydate',employee_no,'$memo',0-paid_amount from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); $commission_acc=$this->mastermodel->getSingleFieldValue('main_account_settings','commission','main_account_settings_id','1'); $salary_acc=$this->mastermodel->getSingleFieldValue('sub_account_settings','salary','sub_account_settings_id','1'); $this->db->query("insert into unposted_journal select '','$ref_id' , '$paydate','$salary_acc',basic_salary,'$memo',1 from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); $this->db->query("insert into gl_trans select '','$ref_id' , '$paydate',$salary_acc,'$memo',basic_salary from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); $this->db->query("insert into unposted_journal select '','$ref_id' , '$paydate','$commission_acc',commission_amount,'$memo',1 from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); $this->db->query("insert into gl_trans select '','$ref_id' , '$paydate','$commission_acc','$memo',commission_amount from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); /*Second Transaction*/ $reference_code= $this->accountingmodel->getreferencecode(1); $ref_id = $this->mastermodel->insertmasterdata(); $refdata=array('ref_id'=>$ref_id, 'ref_transaction_type_id'=>'1', 'ref_code'=>$reference_code); $this->db->insert('refs', $refdata); $audittraildata=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'fiscal_year'=>$fiscal_year_id, ); $this->db->insert('audit_trail', $audittraildata); $this->db->query("insert into unposted_journal select '','$ref_id' , '$paydate',employee_no,paid_amount,'$memo',1 from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); $this->db->query("insert into gl_trans select '','$ref_id' , '$paydate',employee_no,'$memo',paid_amount from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); $this->db->query("insert into unposted_journal select '','$ref_id' , '$paydate','$bankaccount',0-paid_amount,'$memo',1 from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); $this->db->query("insert into gl_trans select '','$ref_id' , '$paydate','$bankaccount','$memo',0-paid_amount from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); $this->db->query("insert into bank_transaction select '','$ref_id' ,'$bankaccount', '$paydate',0-paid_amount,'' from employee_salary_slip join employee on employee_salary_slip.employee_id=employee.employee_id where employee_salary_slip_id='$salid'"); } } } $data['resfunction']='search_payslip'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Employee Salary Processed successfully'; return $data; } } function insert_single_posted_salary_payment($postdata) { $data=array(); $this->db->trans_begin(); $this->db->where('employee_salary_slip_id',$postdata['employee_salary_slip_id']); $this->db->delete('employee_salary_slip'); $this->db->where('employee_salary_slip_id',$postdata['employee_salary_slip_id']); $this->db->delete('employee_salary_slip_allowdeduc'); $masterid = $this->mastermodel->insertmasterdata(); $salary_date = $this->mastermodel->convertdateformat($postdata['salary_date']); $pay_date=date('Y-m-d'); $netpayment=$postdata['basic_salary']+$postdata['allowance']-$postdata['deduction']; $tblValues=array('employee_salary_slip_id'=>$masterid, 'employee_id' => $postdata['employee_id'], 'salary_date'=> $salary_date, 'pay_date'=> $pay_date, 'basic_salary'=> $postdata['basic_salary'], 'allowance_amount'=> $postdata['allowance'], 'deduction_amount'=> $postdata['deduction'], 'net_payment'=> $netpayment, 'commission_amount'=> $postdata['commission'], 'paid_amount'=> $postdata['payamount'], 'unpost'=>0 ); $this->db->insert('employee_salary_slip', $tblValues); $reference_code= $this->getreferencecode(3); $ref_id = $this->mastermodel->insertmasterdata(); $refdata=array('ref_id'=>$ref_id, 'ref_transaction_type_id'=>'3', 'ref_code'=>$reference_code); $this->db->insert('refs', $refdata); $fiscal_year_id=$this->mastermodel->getSingleFieldValue('company','fiscal_year_id','company_id','1'); $audittraildata=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'fiscal_year'=>$fiscal_year_id, ); $this->db->insert('audit_trail', $audittraildata); $i=1; while(isset($postdata['amount_'.$i])) { $allowaccount=$this->mastermodel->getSingleFieldValue('allowdeduc','chart_account_code','allowdeduc_id',$postdata['allowdeduc_id_'.$i]); if($postdata['mode_id_'.$i]=='Deduction') $postdata['alltotal_'.$i]=0-$postdata['alltotal_'.$i]; $tblValues=array('ref_id'=>$ref_id, 'payment_date'=>date("Y-m-d"), 'account_code'=>$allowaccount, 'amount'=>$postdata['alltotal_'.$i], 'memo'=>$postdata['memo'], 'unpost'=>1); $this->db->insert('unposted_journal', $tblValues); $tblValues=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'account_code'=>$allowaccount, 'memo'=>$postdata['memo'], 'amount'=>$postdata['alltotal_'.$i]); $str= $this->db->insert('gl_trans', $tblValues); $tblValues=array( 'employee_salary_slip_id'=>$masterid, 'allowdeduc_id'=>$postdata['allowdeduc_id_'.$i], 'amount'=>$postdata['amount_'.$i]); $this->db->insert('employee_salary_slip_allowdeduc', $tblValues); $i++; } $tblValues=array('ref_id'=>$ref_id, 'payment_date'=>date("Y-m-d"), 'account_code'=>$postdata['empaccount'], 'amount'=>-$postdata['payamount'], 'memo'=>$postdata['memo'], 'unpost'=>1); $this->db->insert('unposted_journal', $tblValues); $tblValues=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'account_code'=>$postdata['empaccount'], 'memo'=>$postdata['memo'], 'amount'=>-$postdata['payamount']); $this->db->insert('gl_trans', $tblValues); $commission_acc=$this->mastermodel->getSingleFieldValue('main_account_settings','commission','main_account_settings_id','1'); $salary_acc=$this->mastermodel->getSingleFieldValue('sub_account_settings','salary','sub_account_settings_id','1'); $tblValues=array('ref_id'=>$ref_id, 'payment_date'=>date("Y-m-d"), 'account_code'=>$salary_acc, 'amount'=>$postdata['basic_salary'], 'memo'=>$postdata['memo'], 'unpost'=>1); $this->db->insert('unposted_journal', $tblValues); $tblValues=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'account_code'=>$salary_acc, 'memo'=>$postdata['memo'], 'amount'=>$postdata['basic_salary']); $this->db->insert('gl_trans', $tblValues); if(!empty($postdata['commission'])) { $tblValues=array('ref_id'=>$ref_id, 'payment_date'=>date("Y-m-d"), 'account_code'=>$commission_acc, 'amount'=>$postdata['commission'], 'memo'=>'Commission Paid', 'unpost'=>1); $this->db->insert('unposted_journal', $tblValues); $tblValues=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'account_code'=>$commission_acc, 'memo'=>'Commission Paid', 'amount'=>$postdata['commission']); $this->db->insert('gl_trans', $tblValues); } /*Second Transaction*/ $reference_code= $this->getreferencecode(1); $ref_id = $this->mastermodel->insertmasterdata(); $refdata=array('ref_id'=>$ref_id, 'ref_transaction_type_id'=>'1', 'ref_code'=>$reference_code); $this->db->insert('finance_refs', $refdata); $audittraildata=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'fiscal_year'=>$fiscal_year_id, ); $this->db->insert('audit_trail', $audittraildata); $tblValues=array('ref_id'=>$ref_id, 'payment_date'=>date("Y-m-d"), 'account_code'=>$postdata['empaccount'], 'amount'=>$postdata['payamount'], 'memo'=>$postdata['memo'], 'unpost'=>1); $this->db->insert('unposted_journal', $tblValues); $tblValues=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'account_code'=>$postdata['empaccount'], 'memo'=>$postdata['memo'], 'amount'=>$postdata['payamount']); $this->db->insert('gl_trans', $tblValues); $tblValues=array('ref_id'=>$ref_id, 'payment_date'=>date("Y-m-d"), 'account_code'=>$postdata['bank_account_code'], 'amount'=>-$postdata['payamount'], 'memo'=>$postdata['memo'], 'unpost'=>1); $this->db->insert('unposted_journal', $tblValues); $tblValues=array('ref_id'=>$ref_id, 'transaction_date'=>date("Y-m-d"), 'account_code'=>$postdata['bank_account_code'], 'memo'=>$postdata['memo'], 'amount'=>-$postdata['payamount']); $this->db->insert('gl_trans', $tblValues); $tblValues3=array('ref_id'=>$ref_id, 'bank_account_code'=>$postdata['bank_account_code'], 'transaction_date'=>date("Y-m-d"), 'amount'=>-$postdata['payamount'], ); $query= $this->db->insert('bank_transaction', $tblValues3); $data['resfunction']='search_payslip'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Employee Salary Processed successfully'; return $data; } } function getreferencecode($trans) { $code=$this->mastermodel->getSingleFieldValue('finance_transaction_code','transaction_code','transaction_id',$trans); if($code=='') return 0; else { $num=$this->mastermodel->get_num_rows('refs','ref_transaction_type_id',$trans); $num++; return $code.'/'.date("Y").'/'.$num; } } } ?>