?
Current Path : /home1/savoy/www/savoyglobal.net/cocorico/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/www/savoyglobal.net/cocorico/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() { $data = array(); $this->db->select('*'); $this->db->from('designation'); $this->db->order_by('designation_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_designation($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( '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() { $data = array(); $this->db->select('*'); $this->db->from('department'); $this->db->order_by('department_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_department($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( '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() { $data = array(); $this->db->select('*'); $this->db->from('grade'); $this->db->order_by('grade_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_grade($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( '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() { $data = array(); $this->db->select('*'); $this->db->from('status'); $this->db->order_by('status_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_status($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( '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() { $data = array(); $this->db->select('*'); $this->db->from('employee'); $this->db->join('master', 'master_id=employee_id'); $this->db->join('designation', 'designation_id=employee_designation_id'); $this->db->join('department', 'department_id=employee_department_id'); $this->db->join('grade', 'grade_id=employee_grade_id'); $this->db->order_by('employee_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_employee($postdata) { $data = array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $expiry_date = $this->mastermodel->convertdateformat($postdata['employee_visa_expiry_date']); $join_date = $this->mastermodel->convertdateformat($postdata['employee_joining_date']); $relieving_date = $this->mastermodel->convertdateformat($postdata['employee_relieving_date']); $employee_medical_test_expiry_date = $this->mastermodel->convertdateformat($postdata['employee_medical_test_expiry_date']); $employee_passport_expiry_date = $this->mastermodel->convertdateformat($postdata['employee_passport_expiry_date']); $dob = $this->mastermodel->convertdateformat($postdata['employee_dob']); $labour_date = $this->mastermodel->convertdateformat($postdata['employee_labour_card_expiry_date']); $employee_no = $this->mastermodel->get_employee_number(); if (isset($postdata['employee_teacher'])) $employee_teacher = 1; else $employee_teacher = 0; $tblValues = array('employee_id' => $masterid, 'employee_no' => $employee_no, 'employee_name' => $postdata['employee_name'], 'employee_gender' => $postdata['employee_gender'], 'employee_dob' => $dob, 'employee_nationality_id' => $postdata['employee_nationality_id'], 'employee_branch_id' => $postdata['employee_branch_id'], 'employee_designation_id' => $postdata['employee_designation_id'], 'employee_department_id' => $postdata['employee_department_id'], 'employee_grade_id' => $postdata['employee_grade_id'], 'employee_status_id' => $postdata['employee_status_id'], 'employee_local_address' => $postdata['employee_local_address'], 'employee_permanent_address' => $postdata['employee_permanent_address'], 'employee_contact_no' => $postdata['employee_contact_no'], 'employee_mobile_no' => $postdata['employee_mobile_no'], 'employee_email' => $postdata['employee_email'], 'employee_passport_no' => $postdata['employee_passport_no'], 'employee_passport_expiry_date' => $employee_passport_expiry_date, 'employee_visa_type' => $postdata['employee_visa_type'], 'employee_visa_expiry_date' => $expiry_date, 'employee_labour_card_no' => $postdata['employee_labour_card_no'], 'employee_police_certificate' => $postdata['employee_police_certificate'], 'employee_device_no' => $postdata['employee_device_no'], 'employee_labour_card_expiry_date' => $labour_date, 'employee_reporting_to' => $postdata['employee_reporting_to'], 'employee_qatar_id_no' => $postdata['employee_qatar_id_no'], 'employee_teacher' => $employee_teacher, 'employee_joining_date' => $join_date, 'employee_relieving_date' => $relieving_date, 'employee_medical_test_expiry_date' => $employee_medical_test_expiry_date, ); $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', $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); } } $i = 1; while (isset($postdata['course' . $i])) { if ($postdata['course' . $i] != '') { $tblValues = array( 'employee_id' => $masterid, 'course' => $postdata['course' . $i], 'university' => $postdata['university' . $i], 'yearofpassing' => $postdata['yearofpassing' . $i]); $this->db->insert('employee_educational_qualification', $tblValues); } $i++; } $i = 1; while (isset($postdata['employer' . $i])) { if ($postdata['employer' . $i] != '') { $tblValues = array( 'employee_id' => $masterid, 'employer' => $postdata['employer' . $i], 'designation' => $postdata['designation' . $i], 'period' => $postdata['period' . $i]); $this->db->insert('employee_professional_experience', $tblValues); } $i++; } $i = 1; while (isset($postdata['additional_course' . $i])) { if ($postdata['additional_course' . $i] != '') { $tblValues = 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', $tblValues); } $i++; } $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(); if (isset($postdata['employee_teacher'])) $employee_teacher = 1; else $employee_teacher = 0; $join_date = $this->mastermodel->convertdateformat($postdata['employee_joining_date']); $relieving_date = $this->mastermodel->convertdateformat($postdata['employee_relieving_date']); $tblValues = array( 'employee_name' => $postdata['employee_name'], 'employee_gender' => $postdata['employee_gender'], 'employee_dob' => $this->mastermodel->convertdateformat($postdata['employee_dob']), 'employee_device_no' => $postdata['employee_device_no'], 'employee_nationality_id' => $postdata['employee_nationality_id'], 'employee_branch_id' => $postdata['employee_branch_id'], 'employee_passport_no' => $postdata['employee_passport_no'], 'employee_passport_expiry_date' => $this->mastermodel->convertdateformat($postdata['employee_passport_expiry_date']), '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_mobile_no' => $postdata['employee_mobile_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_id' => $postdata['employee_status'], 'employee_labour_card_no' => $postdata['employee_labour_card_no'], 'employee_police_certificate' => $postdata['employee_police_certificate'], 'employee_labour_card_expiry_date' => $this->mastermodel->convertdateformat($postdata['employee_labour_card_expiry_date']), 'employee_email' => $postdata['employee_email'], 'employee_reporting_to' => $postdata['employee_reporting_to'], 'employee_qatar_id_no' => $postdata['employee_qatar_id_no'], 'employee_teacher' => $employee_teacher, 'employee_joining_date' => $join_date, 'employee_relieving_date' => $relieving_date, 'employee_medical_test_expiry_date' => $this->mastermodel->convertdateformat($postdata['employee_medical_test_expiry_date']), ); $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); } } $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(); $this->db->select('*'); $this->db->from('leave_allocation'); $this->db->join('employee', 'employee.employee_id=leave_allocation.employee_id'); $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(); $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'); 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() { $data = array(); $this->db->select('*'); $this->db->from('leave_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(); $tblValues = array( '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(); $this->db->select('*'); $this->db->from('holiday'); $this->db->order_by('holiday_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_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->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_allowdeduc() { $data = array(); $this->db->select('*'); $this->db->from('allowdeduc'); $this->db->order_by('allowdeduc_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_allowdeduc($postdata) { $data = array(); $this->db->trans_begin(); $data['resfunction'] = 'search_allowdeduc'; if ($postdata['allowdeduc_mode'] == 1) $type = 'allowance'; else $type = 'deduction'; $chart = $this->mastermodel->get_data_srow_joined('finance_sub_account_settings', 'finance_chart_master', $type, 'chart_master_id', '1', 'sub_account_settings_id'); $chart_account_type = $chart->chart_type_id; $chart_type_sort = $this->mastermodel->get_single_field_value('finance_chart_type', 'sort', 'chart_type_id ', $chart_account_type); $start = $chart_type_sort * 100000; $max_code = $start + 50000; $code = $this->accountingmodel->account_code_generated($start, $max_code); if ($max_code > ($code)) { $acc_code = $code; $count = $this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $acc_code); if ($count == 0) { $tblValues = array( 'allowdeduc_name' => $postdata['allowdeduc_name'], 'allowdeduc_type' => $postdata['allowdeduc_type'], 'allowdeduc_mode' => $postdata['allowdeduc_mode'], 'chart_account_code' => $acc_code ); $this->db->insert('allowdeduc', $tblValues); $tblValues = array( 'chart_account_code' => $acc_code, 'chart_account_name' => $postdata['allowdeduc_name'], 'chart_type_id' => $chart_account_type, 'parent' => $chart->chart_master_id, 'inactive' => 0 ); $this->db->insert('finance_chart_master', $tblValues); $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } else { $this->db->trans_rollback(); $data['res'] = 1; $data['msg'] = 'Error On Adding Record'; return $data; } } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Account Beyond the Limit'; 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'] ); $this->db->where('allowdeduc_id', $postdata['allowdeduc_id']); $this->db->update('allowdeduc', $tblValues); $tblValues = array('chart_account_name' => $postdata['allowdeduc_name']); $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_salary_setting($pagenum) { $data = array(); $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->join('payment_methods', 'payment_methods.method=employee_salary.payment_method', 'left'); $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'], 'payment_method' => $postdata['paymethod']); $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++; } if ($_POST['paymethod'] == 'bank') { // echo "insert into salarybank values('','1', '$_POST[cheque_no]','$_POST[bank_name]','Bank','Bank'"; $query = $this->db->query("insert into salarybank values('',' $masterid', '$_POST[acc_holder]','$_POST[bank_name]','$_POST[acc_no]','$_POST[branch_name]')"); } $i = 1; while (isset($postdata['type' . $i])) { if ($postdata['type' . $i] != "") { $tblValues = array( 'employee_salary_id' => $masterid, 'type' => $postdata['type' . $i], 'company' => $postdata['company' . $i], 'policy' => $postdata['policy' . $i], 'plan' => $postdata['plan' . $i], 'sum' => $postdata['sum' . $i]); $this->db->insert('employee_salary_medical', $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']); $salid = $postdata['employee_salary_id']; $wef_date = $this->mastermodel->convertdateformat($postdata['wef_date']); if (isset($postdata['return_ticket'])) { $return_ticket = 1; } else { $return_ticket = 0; } $this->db->query("delete from salarybank where sal_id = $salid"); if ($_POST['paymethod'] == 'bank') { $query = $this->db->query("insert into salarybank values('',' $salid', '$_POST[acc_holder]','$_POST[bank_name]','$_POST[acc_no]','$_POST[branch_name]')"); } $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'], 'payment_method' => $postdata['paymethod'] ); $this->db->where('employee_salary_id', $postdata['employee_salary_id']); $this->db->update('employee_salary', $tblValues); $this->db->where('employee_salary_id', $postdata['employee_salary_id']); $this->db->delete('employee_salary_medical'); $i = 1; while (isset($postdata['type' . $i])) { if ($postdata['type' . $i] != "") { $tblValues = array( 'employee_salary_id' => $postdata['employee_salary_id'], 'type' => $postdata['type' . $i], 'company' => $postdata['company' . $i], 'policy' => $postdata['policy' . $i], 'plan' => $postdata['plan' . $i], 'sum' => $postdata['sum' . $i]); $this->db->insert('employee_salary_medical', $tblValues); } $i++; } $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(); $data['results'] = ''; return $data; } function getemployeelist() { $data = array(); $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->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); $data['num'] = $num; 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 where wef_date <= '$date' GROUP BY employee_id) groupedtt ON tt.employee_id = groupedtt.employee_id AND tt.wef_date = groupedtt.wefdate where tt.employee_id = '$employee_id' "; $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(); $data['resfunction'] = 'search_salary_payment'; $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'], 'payment_method' => $postdata['employee_sal_payment_mode'], '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++; } 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]; $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; $payment_method=$salary_payment->payment_method; $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, 'payment_method'=>$payment_method ); $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) { $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->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(); $data['resfunction'] = 'search_payslip'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); $sub_accounts = $this->mastermodel->get_srow('finance_sub_account_settings', 'sub_account_settings_id!='); if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $memo = $postdata['memo']; $bankaccount = $postdata['bank_account_code']; $sal_date = $this->mastermodel->convertdateformat($postdata['wef_date']); $monthName = date("F", strtotime($sal_date)); $year = date("Y", strtotime($sal_date)); if (isset($postdata['salempdet'])) { for ($i = 0; $i < sizeof($postdata['salempdet']); $i++) { if (isset($postdata['salempdet'][$i])) { $salid = $postdata['salempdet'][$i]; $employee_sal = $this->mastermodel->get_data_srow('employee_salary_slip', $salid, 'employee_salary_slip_id'); $basic_salary = $employee_sal->basic_salary; $emp_id = $employee_sal->employee_id; $employee_details = $this->mastermodel->get_data_srow('employee', $emp_id, 'employee_id'); $employee_name = $employee_details->employee_name; $paydate = $employee_sal->pay_date; $salary_date = $employee_sal->salary_date; $monthName = ''; $transaction_id = 3; /* jv */ $payment_type = 0; $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type); $journalid_jv = $this->mastermodel->insertmasterdata(); $journal_date = $employee_sal->pay_date; /* Basic Salary is debited */ $sal_acc_id = $sub_accounts->salary; $sal_acc = $this->mastermodel->get_data_srow('finance_chart_master', $sal_acc_id, 'chart_master_id'); $sal_acc_code = $sal_acc->chart_account_code; $description = "Salary slip of $employee_name ( $employee_details->employee_no ) For the month $monthName $year from Account : $sal_acc->chart_account_name ( $sal_acc_code )"; $tblValues = array( 'journal_id' => $journalid_jv, 'journal_date' => $journal_date, 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $payment_type, 'transaction_id' => $transaction_id, ); $this->db->insert('finance_journal_refs', $tblValues); $tblValues = array( 'journal_id' => $journalid_jv, 'chart_account_code' => $sal_acc_code, 'debit' => $basic_salary, 'credit' => 0, 'description' => "Basic salary of $employee_name ( $employee_details->employee_no ) For the month $monthName $year from Account : $sal_acc->chart_account_name ( $sal_acc_code )", 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); $tblValues = array( 'journal_id' => $journalid_jv, 'param_id' => $salid, 'refs_type' => "Salary slip of $employee_name ( $employee_details->employee_no ) ", 'param_table' => 'employee_salary_slip' ); $this->db->insert('finance_refs', $tblValues); /* Allowence and deduction */ $allowdeduc_details = $this->mastermodel->get_data('employee_salary_slip_allowdeduc', $salid, 'employee_salary_slip_id'); $allowance = 0; $deduction = 0; foreach ($allowdeduc_details as $list) { $allowdeductype = $this->mastermodel->get_data_srow('allowdeduc', $list['allowdeduc_id'], 'allowdeduc_id'); 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; } if ($allowdeductype->allowdeduc_type == 1) { //allowance $allowance+=$asubtotal; $debit = $asubtotal; $credit = 0; $description = "Allowance ( $allowdeductype->allowdeduc_name) for $employee_name ( $employee_details->employee_no ) For the month $monthName $year From Account $allowdeductype->chart_account_code "; } else { //deduction $deduction+=$asubtotal; $debit = 0; $credit = $asubtotal; $description = "Deduction ( $allowdeductype->allowdeduc_name) for $employee_name ( $employee_details->employee_no ) For the month $monthName $year From Account $allowdeductype->chart_account_code "; } /* transaction here */ if ($list['amount'] > 0) { $tblValues = array( 'journal_id' => $journalid_jv, 'chart_account_code' => $allowdeductype->chart_account_code, 'debit' => $debit, 'credit' => $credit, 'description' => $description, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); } } // $net_deduction = $deduction ; // $lop = 0; $net_amount = $basic_salary + $allowance - $deduction; $paid_amount = $net_amount; $tblValues = array( 'unpost' => 0, 'paid_amount' => $paid_amount, 'deduction_amount' => $deduction ); $this->db->where('employee_salary_slip_id', $salid); $this->db->update('employee_salary_slip', $tblValues); /* Employeee Account */ $emp = $this->mastermodel->get_data_srow('employee', $emp_id, 'employee_id'); $emp_acc = $emp->employee_no; $parent = $this->accountingmodel->get_account_settings('employee', 'finance_sub_account_settings'); $chart_type = $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', $emp_acc) == 0) { $tblValues = array( 'chart_account_code' => $emp->employee_no, 'chart_account_name' => $emp->employee_name, 'chart_type_id' => $chart_type, 'parent' => $parent, 'inactive' => 0); $this->db->insert('finance_chart_master', $tblValues); } $tblValues = array( 'journal_id' => $journalid_jv, 'chart_account_code' => $emp_acc, 'debit' => 0, 'credit' => $paid_amount, 'description' => "Salary payable for $employee_name ( $employee_details->employee_no ) For the month $monthName $year ", 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); /* Salary payment */ $transaction_id = 1; /* pv */ $payment_type = 1; $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type); $journalid_pv = $this->mastermodel->insertmasterdata(); $description = "Salary received by $employee_name ( $employee_details->employee_no ) For the month $monthName $year "; $tblValues = array( 'journal_id' => $journalid_pv, 'journal_date' => $journal_date, 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $payment_type, 'transaction_id' => $transaction_id, ); $this->db->insert('finance_journal_refs', $tblValues); $tblValues = array( 'journal_id' => $journalid_pv, 'chart_account_code' => $emp_acc, 'debit' => $paid_amount, 'credit' => 0, 'description' => "Salary received by $employee_name ( $employee_details->employee_no ) For the month $monthName $year From the Account $emp_acc", 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); $tblValues = array( 'journal_id' => $journalid_pv, 'chart_account_code' => $postdata['bank_account_code'], 'debit' => 0, 'credit' => $paid_amount, 'description' => "Salary Paid to $employee_name ( $employee_details->employee_no ) For the month $monthName $year From the Account " . $postdata['bank_account_code'], 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); $tblValues = array( 'journal_id' => $journalid_pv, 'param_id' => $salid, 'refs_type' => "Salary Payment of $employee_name ( $employee_details->employee_no ) ", 'param_table' => 'employee_salary_slip' ); $this->db->insert('finance_refs', $tblValues); } } } 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; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } function insert_single_posted_salary_payment($postdata) { $data = array(); $data['resfunction'] = 'search_payslip'; $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); $sub_accounts = $this->mastermodel->get_data_srow('finance_sub_account_settings', '1', 'sub_account_settings_id'); $payment = $postdata['payamount']; $sal_date = $this->mastermodel->convertdateformat($postdata['wef_date']); $monthName = date("F", strtotime($sal_date)); $year = date("Y", strtotime($sal_date)); if ($fisc_year_id != 0 && $default_currency != 0) { $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'); $transaction_id = 3; /* jv */ $payment_type = 0; $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type); $salary_slip_id = $this->mastermodel->insertmasterdata(); $salary_date = $this->mastermodel->convertdateformat($postdata['salary_date']); $pay_date = date('Y-m-d'); $monthName = ''; $netpayment = $postdata['basic_salary'] + $postdata['allowance'] - $postdata['deduction']; $paid_amount = $postdata['payamount']; $employee_id = $postdata['employee_id']; $employee_details = $this->mastermodel->get_data_srow('employee', $employee_id, 'employee_id'); $employee_name = $employee_details->employee_name; $tblValues = array( 'employee_salary_slip_id' => $salary_slip_id, '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' => $paid_amount, 'unpost' => 0 ); $this->db->insert('employee_salary_slip', $tblValues); $journalid_jv = $this->mastermodel->insertmasterdata(); $journal_date = $pay_date; /* Basic Salary is debited */ $sal_acc_id = $sub_accounts->salary; $sal_acc = $this->mastermodel->get_data_srow('finance_chart_master', $sal_acc_id, 'chart_master_id'); $sal_acc_code = $sal_acc->chart_account_code; $description = "Salary slip of $employee_name ( $employee_details->employee_no ) For the month $monthName $year from Account :$sal_acc->chart_account_name ( $sal_acc_code )"; $tblValues = array( 'journal_id' => $journalid_jv, 'journal_date' => $journal_date, 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $payment_type, 'transaction_id' => $transaction_id, ); $this->db->insert('finance_journal_refs', $tblValues); $tblValues = array( 'journal_id' => $journalid_jv, 'chart_account_code' => $sal_acc_code, 'debit' => $postdata['basic_salary'], 'credit' => 0, 'description' => "Basic salary of $employee_name ( $employee_details->employee_no ) For the month $monthName $year from Account :$sal_acc->chart_account_name ( $sal_acc_code )", 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); $tblValues = array( 'journal_id' => $journalid_jv, 'param_id' => $salary_slip_id, 'refs_type' => "Salary slip of $employee_name ( $employee_details->employee_no ) ", 'param_table' => 'employee_salary_slip' ); $this->db->insert('finance_refs', $tblValues); /* Allowence and deduction */ $i = 1; while (isset($postdata['amount_' . $i])) { $allowaccount = $this->mastermodel->get_data_srow('allowdeduc', $postdata['allowdeduc_id_' . $i], 'allowdeduc_id'); $tblValues = array( 'employee_salary_slip_id' => $salary_slip_id, 'allowdeduc_id' => $postdata['allowdeduc_id_' . $i], 'amount' => $postdata['amount_' . $i]); $this->db->insert('employee_salary_slip_allowdeduc', $tblValues); $allowded_id = mysql_insert_id(); if ($allowaccount->allowdeduc_type == 1) { $debit = $postdata['alltotal_' . $i]; $credit = 0; $description = "Allowance ($allowaccount->allowdeduc_name) for $employee_name ( $employee_details->employee_no ) For the month $monthName $year From Account $allowaccount->chart_account_code "; } else { $debit = 0; $credit = $postdata['alltotal_' . $i]; $description = "Deduction ($allowaccount->allowdeduc_name) for $employee_name ( $employee_details->employee_no ) For the month $monthName $year from Account $allowaccount->chart_account_code "; } if ($postdata['alltotal_' . $i] > 0) { $tblValues = array( 'journal_id' => $journalid_jv, 'chart_account_code' => $allowaccount->chart_account_code, 'debit' => $debit, 'credit' => $credit, 'description' => $description, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); } $i++; } /* Employeee Account */ $emp = $this->mastermodel->get_data_srow('employee', $postdata['employee_id'], 'employee_id'); $emp_acc = $emp->employee_no; $parent = $this->accountingmodel->get_account_settings('employee', 'finance_sub_account_settings'); if ($this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $emp_acc) == 0) { $tblValues = array( 'chart_account_code' => $emp->employee_no, 'chart_account_name' => $emp->employee_name, 'chart_account_type' => 3, 'parent' => $parent, 'inactive' => 0); $this->db->insert('chart_master', $tblValues); } $tblValues = array( 'journal_id' => $journalid_jv, 'chart_account_code' => $emp_acc, 'debit' => 0, 'credit' => $paid_amount, 'description' => "Salary payable of $employee_name ( $employee_details->employee_no ) For the month $monthName $year From the Account : $emp_acc", 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); /* Salary payment */ $transaction_id = 1; /* PV */ $payment_type = $postdata['payment_type_id']; $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type); $journalid_pv = $this->mastermodel->insertmasterdata(); $description = "Salary received by $employee_name ( $employee_details->employee_no ) For the month $monthName $year "; $tblValues = array( 'journal_id' => $journalid_pv, 'journal_date' => $journal_date, 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $payment_type, 'transaction_id' => $transaction_id, ); $this->db->insert('finance_journal_refs', $tblValues); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $journalid_pv, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $postdata['bank_account_code'], 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); }else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $journalid_pv, 'credit_card_holder' => $postdata['holder_name'], 'credit_card_no' => $postdata['card_no'] ); $this->db->insert('finance_credit_card_info', $tblValues); } else if ($postdata['payment_type_id'] == 4) { $tblValues = array( 'journal_id' => $journalid_pv, 'wire_info' => $postdata['bank_transfer_description'] ); $this->db->insert('finance_wire_info', $tblValues); } $tblValues = array( 'journal_id' => $journalid_pv, 'chart_account_code' => $emp_acc, 'debit' => $paid_amount, 'credit' => 0, 'description' => "Salary received by $employee_name ( $employee_details->employee_no ) For the month $monthName $year From the Account $emp_acc", 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); $tblValues = array( 'journal_id' => $journalid_pv, 'chart_account_code' => $postdata['bank_account_code'], 'debit' => 0, 'credit' => $paid_amount, 'description' => "Salary Paid to $employee_name ( $employee_details->employee_no ) For the month $monthName $year From the Account " . $postdata['bank_account_code'], 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); $tblValues = array( 'journal_id' => $journalid_pv, 'param_id' => $salary_slip_id, 'refs_type' => "Salary Payment of $employee_name ( $employee_details->employee_no ) For the month $monthName $year ", 'param_table' => 'employee_salary_slip' ); $this->db->insert('finance_refs', $tblValues); 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; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; 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; } } function getunpaidemployees($month, $year) { $data = array(); $this->db->where("employee.employee_id NOT IN (SELECT `employee_id` FROM `employee_salary_slip` where month(salary_date)='$month' and year(salary_date)='$year')", NULL, FALSE); $Q = $this->db->get('employee'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getstfleavapply($id) { $data = array(); $year = date("Y"); $sql = "select * from leave_application join leave_type on leave_type.leave_type_id =leave_application.leave_type_id where employee_id = '$id' and (from_date like '" . $year . "%')"; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function search_employee_attendence($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('employee_attendance'); $this->db->order_by('employee_attendance.employee_attendance_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_employee_attendence($postdata) { $data = array(); $this->db->trans_begin(); $employee_attendance_id= $this->mastermodel->insertmasterdata(); $tblValues = array( 'employee_attendance_id' => $employee_attendance_id, 'employee_attendance_date' => $this->mastermodel->convertdateformat($postdata['employee_attendance_date']), 'employee_attendance_remarks' => $postdata['employee_attendance_remarks'], ); $this->db->insert('employee_attendance', $tblValues); $i = 1; while (isset($postdata['employee_id' . $i])) { $tblValues = array( 'employee_attendance_id' => $employee_attendance_id, 'employee_id' => $postdata['employee_id' . $i], 'employee_attendance_status' => $postdata['employee_attendance_status' . $i], 'employee_attendance_in_time' => $postdata['start_time_hour' . $i] . ':' . $postdata['start_time_minute' . $i], 'employee_attendance_out_time' => $postdata['end_time_hour' . $i] . ':' . $postdata['end_time_minute' . $i], 'employee_attendance_details_remarks' => $postdata['employee_attendance_details_remarks' . $i] ); $this->db->insert('employee_attendance_details', $tblValues); $i++; } $data['resfunction'] = 'search_employee_attendence'; 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 employee_attendence_details($employee_attendance_id) { $data = array(); $this->db->where('employee_attendance.employee_attendance_id', $employee_attendance_id); $this->db->join('employee_attendance_details', 'employee_attendance_details.employee_attendance_id=employee_attendance.employee_attendance_id'); $this->db->join('employee', 'employee.employee_id=employee_attendance_details.employee_id'); $Q = $this->db->get('employee_attendance'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } // echo $this->db->last_query(); $Q->free_result(); return $data; } function update_employee_attendance($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'employee_attendance_date' => $this->mastermodel->convertdateformat($postdata['employee_attendance_date']), 'employee_attendance_remarks' => $postdata['employee_attendance_remarks'], ); $this->db->where('employee_attendance.employee_attendance_id', $postdata['employee_attendance_id']); $this->db->update('employee_attendance', $tblValues); $this->db->where('employee_attendance_details.employee_attendance_id', $postdata['employee_attendance_id']); $this->db->delete('employee_attendance_details'); $i = 1; while (isset($postdata['employee_id' . $i])) { $tblValues = array( 'employee_attendance_id' =>$postdata['employee_attendance_id'], 'employee_id' => $postdata['employee_id' . $i], 'employee_attendance_status' => $postdata['employee_attendance_status' . $i], 'employee_attendance_in_time' => $postdata['start_time_hour' . $i] . ':' . $postdata['start_time_minute' . $i], 'employee_attendance_out_time' => $postdata['end_time_hour' . $i] . ':' . $postdata['end_time_minute' . $i], 'employee_attendance_details_remarks' => $postdata['employee_attendance_details_remarks' . $i] ); $this->db->insert('employee_attendance_details', $tblValues); $i++; } $data['resfunction'] = 'search_employee_attendence'; 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 get_leave_balance($employee_id,$leave_type_id,$date) { $data = array(); $status="Approved"; $this->db->select('*,DATEDIFF(to_date,from_date) + 1 as days',FALSE); $this->db->from('leave_application'); $this->db->where('YEAR(from_date)', $date); $this->db->where('employee_id', $employee_id); $this->db->where('leave_type_id', $leave_type_id); $this->db->where('leave_status',$status); $Q = $this->db->get(); $row = $Q->row(); $Q->free_result(); return $row; } } ?>