?
Current Path : /home1/savoy/www/savoyglobal.net/sibslifemoved/system/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/sibslifemoved/system/application/models/hrmodel.php |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?> <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ class hrmodel extends Model { function hrmodel() { parent::Model(); $this->load->model('customermodel'); } function norecords($tabname) { $data = array(); $sql = "select MAX(id) as maxid from $tabname"; // echo $sql; $res = mysql_query($sql); $row = mysql_fetch_array($res); $numcode = $row['maxid']; if ($numcode != '') { return $numcode; } else { return 0; } } function numcount_data($table, $id, $field) { $query = "select * from $table where $field = '$id'"; // echo $query; $query = $this->db->query($query); if ($query->num_rows() == 0) { return 0; } else { return $query->num_rows(); } } function numcount_data_sal($table, $id, $date) { $date = $this->mastermodel->convdatformat($date); $query = "select id,basicsalary,premiumtarget,commission,currencytype,date,staffid from $table where staffid = '$id' and date <= '$date' order by date DESC limit 1"; // echo $query; $res = mysql_query($query); $num = mysql_num_rows($res); return $num; } function numcount_data_employee_sal($table, $emp, $date) { foreach ($emp as $id) { $num[$id] = $this->numcount_data_sal($table, $id, $date); } return $num; } function get_settlement($table, $unposted, $field, $value, $pageno) { $limit = (($pageno - 1) * 10); $data = array(); $res = $this->db->query("select *,emp_settlement.id as id from $table join staffpersonaldetails on staffpersonaldetails.id=" . $table . ".employee_id where unpost= " . $unposted . " AND " . $field . " like '" . $value . "%' limit " . $limit . "," . 10); //echo $this->db->last_query(); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function get_sal_data($table, $id, $date) { $date = $this->mastermodel->convdatformat($date); $data = array(); $sql = "select paymethod,id,basicsalary,premiumtarget,commission,currencytype,date,staffid from $table where staffid = '$id' and date <= '$date' order by date DESC limit 1"; // echo $sql; $Q = $this->db->query($sql); $row = $Q->row(); return $row; } function get_employee_sal_data($table, $emp, $date) { $row = array(); foreach ($emp as $id) { $row[$id] = $this->get_sal_data($table, $id, $date); } return $row; } function get_com_premgen($staffid, $date) { $data = array(); $splitdate = explode("-", $date); $sql = "select * from placing_slip_premiumdetails inner join placing_slip inner join placing_slip_stakeholders on placing_slip_premiumdetails.placing_slip_id = placing_slip.id and placing_slip_stakeholders.placing_slip_id = placing_slip.id and MONTH(quotation_date) = '$splitdate[1]' and YEAR(quotation_date) = '$splitdate[2]' and placing_slip_stakeholders.staffid = '$staffid' "; // echo $sql; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_employee_com_premgen($emp, $date) { $row = array(); foreach ($emp as $id) { $row[$id] = $this->get_com_premgen($id, $date); } return $row; } function get_com_prempay($staffid, $date) { $data = array(); $splitdate = explode("-", $date); $sql = "select * from placing_slip_payamount inner join placing_slip inner join placing_slip_stakeholders on placing_slip_payamount.placing_slip_id = placing_slip.id and placing_slip_stakeholders.placing_slip_id = placing_slip.id and MONTH(paydate) = '$splitdate[1]' and YEAR(paydate) = '$splitdate[2]' and placing_slip_stakeholders.staffid = '$staffid' "; // echo $sql; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_employee_com_prempay($emp, $date) { $row = array(); foreach ($emp as $id) { $row[$id] = $this->get_com_prempay($id, $date); } return $row; } function get_com_prempay_placinglsip($staffid, $date, $plaslip) { $data = array(); $splitdate = explode("-", $date); $sql = "select * from placing_slip_payamount inner join placing_slip inner join placing_slip_stakeholders on placing_slip_payamount.placing_slip_id = placing_slip.id and placing_slip_stakeholders.placing_slip_id = placing_slip.id and MONTH(paydate) = '$splitdate[1]' and YEAR(paydate) = '$splitdate[2]' and placing_slip_stakeholders.staffid = '$staffid' and placing_slip.id = '$plaslip'"; // echo $sql; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_com_premgen_paid($staffid, $date) { $data = array(); $splitdate = explode("-", $date); $sql = "select * from placing_slip_premiumdetails inner join placing_slip inner join placing_slip_stakeholders inner join placing_slip_payamount on placing_slip_premiumdetails.placing_slip_id = placing_slip.id and placing_slip_stakeholders.placing_slip_id = placing_slip.id and placing_slip_payamount.placing_slip_id = placing_slip.id and MONTH(paydate) = '$splitdate[1]' and YEAR(paydate) = '$splitdate[2]' and placing_slip_stakeholders.staffid = '$staffid' "; //echo $sql; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function addholidays() { $data = array(); $tblValues = array('start_date' => $this->mastermodel->convertdateformat($_POST['start_date']), 'end_date' => $this->mastermodel->convertdateformat($_POST['end_date']), 'occasion' => $_POST['occasion']); return $this->db->insert('holidays', $tblValues); } function insertstaffsalary($data) { if (isset($_POST['returnticket'])) { $returnticket = 1; } else $returnticket = 0; $salarydate = $this->mastermodel->convdatformat($_POST['date']); $sql = "insert into staffsalary (staffid,date,basicsalary,commission,premiumtarget,fromticket,toticket,returnticket,nooftickets,currencytype,paymethod) values('$_POST[employee_id]','$salarydate','$_POST[basicsalary]','" . $_POST['hiddencomm'] . "','$_POST[premiumtarget]','$_POST[fromticket]','$_POST[toticket]','$returnticket','$_POST[nooftickets]','$_POST[currencytype]','$_POST[paymethod]')"; $query = $this->db->query($sql); $sal_id = $this->db->insert_id(); $sql = "select MAX(id) as maxid from staffsalary"; $res = mysql_query($sql); $row = mysql_fetch_array($res); $x = 1; while (isset($_POST['newpolicy_' . $x])) { $newpol[$x] = $_POST['newpolicy_' . $x]; $coverid[$x] = $_POST['coverid_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into staffsalaryallowdeduc values('', '$row[maxid]','$coverid[$i]','$newpol[$i]','1')"); $x--; $i++; } $x = 1; while (isset($_POST['newpolicy1_' . $x])) { $newpol[$x] = $_POST['newpolicy1_' . $x]; $coverid[$x] = $_POST['coverid1_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into staffsalaryallowdeduc values('', '$row[maxid]','$coverid[$i]','$newpol[$i]','0')"); $x--; $i++; } $x = 1; while (isset($_POST['desc_' . $x])) { $desc[$x] = $_POST['desc_' . $x]; $name[$x] = $_POST['name_' . $x]; $x++; } $i = 1; while ($x != 1) { $sql = "insert into staffsalarytickets values('', '$row[maxid]','$desc[$i]','$name[$i]')"; $query = $this->db->query($sql); $x--; $i++; } $x = 1; while (isset($_POST['txt_conType_' . $x])) { $type[$x] = $_POST['txt_conType_' . $x]; $company[$x] = $_POST['txt_conIns_' . $x]; $policy[$x] = $_POST['txt_conPol_' . $x]; $plan[$x] = $_POST['txt_conPlan_' . $x]; $sum[$x] = $_POST['txt_conSum_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into staffsalarymedical values('','$row[maxid]', '$type[$i]','$company[$i]','$policy[$i]','$plan[$i]','$sum[$i]')"); $x--; $i++; } // if($_POST['paymethod']!='cash') // { // 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('',' $sal_id', '$_POST[acc_holder]','$_POST[bank_name]','$_POST[acc_no]','$_POST[branch_name]')"); } // else { // $query=$this->db->query("insert into salarybank values('',' $sal_id', '$_POST[cheque_no]','$_POST[bank_name]','$_POST[acc_no]','$_POST[branch_name]')"); // } // } } function getcomset($table, $id, $field) { $data = array(); $sql = "select max(date) as date,cover_id from $table where $field = '$id' group by cover_id"; $Q = $this->db->query($sql); foreach ($Q->result_array() as $row) { $maxdate = $row['date']; // echo $maxdate; $sql = "select * from $table where $field = '$id' and date = '$maxdate' and cover_id='$row[cover_id]'"; //echo $sql; $Q1 = $this->db->query($sql); if ($Q1->num_rows() > 0) { foreach ($Q1->result_array() as $row1) { $data[] = $row1; } } } $Q1->free_result(); return $data; } function getstfleavalloc($table, $id, $field) { $data = array(); $year = date("Y"); $sql = "select * from $table inner join leaveallocationdetails on leaveallocation.id = leaveallocationdetails.leaveallocationid and $field = '$id' and year = '$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 getstfleavallocs($table, $id, $field) { $data = array(); $year = date("Y"); $sql = "select * from $table where $field = '$id' and year = '$year'"; // echo $sql; //die(); $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function addsettlement_types() { $this->db->trans_begin(); $settlement_code = $this->mastermodel->get_account_code('SET-', '100', 'settlement_types', 'settlement_code'); $query1 = "insert into settlement_types (settlement_code,settlement_name,chartgroup_name) values('$settlement_code','$_POST[settlement_name]','$settlement_code')"; $this->db->query($query1); //die(); $parent = $this->accountingsmodel->get_subaccount_setting('settlement'); $chart_type = $this->mastermodel->getSingleFieldValue('chart_master', 'chart_type', 'id', $parent); $tblValues = array('account_code' => $settlement_code, 'account_name' => $_POST['settlement_name'] , 'chart_type' => $chart_type, 'parent' => $parent, 'inactive' => 0); $this->db->insert('chart_master', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } function addallowdeduction() { $this->db->trans_begin(); if ($_POST['allowdeductype'] == 'Allowance') { $code = $this->mastermodel->get_account_code('ALLOW-', '100', 'allowdeduc', 'allowdeduccode'); $parent = $this->accountingsmodel->get_subaccount_setting('allowance'); } else { $code = $this->mastermodel->get_account_code('DEDUC-', '100', 'allowdeduc', 'allowdeduccode'); $parent = $this->accountingsmodel->get_subaccount_setting('deduction'); } $query1 = "insert into allowdeduc (allowdeduccode,allowdeducname,allowdeductype,mode,chartgroup_name) values('$code','$_POST[allowdeducname]','$_POST[allowdeductype]','$_POST[mode]','$code')"; $this->db->query($query1); $chart_type = $this->mastermodel->getSingleFieldValue('chart_master', 'chart_type', 'id', $parent); $tblValues = array('account_code' => $code, 'account_name' => $_POST['allowdeducname'] , 'chart_type' => $chart_type, 'parent' => $parent, 'inactive' => 0); $this->db->insert('chart_master', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } function getstfleavapply($id) { $data = array(); $year = date("Y"); $sql = "select * from assignleave where staffid = '$id' and (fromdate 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 insertcommissionsettings($data) { $x = 1; while (isset($_POST['newpolicy_' . $x])) { $newpol[$x] = $_POST['newpolicy_' . $x]; $ren[$x] = $_POST['renewal_' . $x]; $coverid[$x] = $_POST['coverid_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into commissionsettings (date,cover_id,designationid,newpolicy,renewal) values('$_POST[date]]','$coverid[$i]','$_POST[designationid]','$newpol[$i]','$ren[$i]')"); $staffs = $this->mastermodel->get_data('staffemployeedetails', $_POST['designationid'], 'designationid'); foreach ($staffs as $stid) { $query = $this->db->query("insert into staffcommissionsettings (date,cover_id,staffid,newpolicy,renewal) values('$_POST[date]]','$coverid[$i]','$stid[staffid]','$newpol[$i]','$ren[$i]')"); } $x--; $i++; } } function insertsalarysettlement() { $paymentdate = $this->mastermodel->convdatformat($_POST['date']); $relieving_date = $this->mastermodel->convdatformat($_POST['rel_date']); $netpayment = $_POST['basicsalary'] + $_POST['allowance'] - $_POST['deduction']; $query1 = "insert into emp_settlement (employee_id,relieving_date,pay_date,basic_salary,allowance,deduction,netpayment,currencytype,paidamount,commission) values('$_POST[employee_id]','$relieving_date','$paymentdate','$_POST[basicsalary]','$_POST[allowance]','$_POST[deduction]','$netpayment','$_POST[currencytype]','$_POST[payamount]','$_POST[commission]')"; $query = $this->db->query($query1); $settlementid = mysql_insert_id(); $x = 1; while (isset($_POST['allowvalue_' . $x])) { $coverid[$x] = $_POST['allowid_' . $x]; $newpol[$x] = $_POST['allowvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $sql = "insert into salarysettlementallowdeduc values('','$settlementid','$coverid[$i]','$newpol[$i]','1')"; $query = $this->db->query($sql); $x--; $i++; } $x = 1; while (isset($_POST['deducvalue_' . $x])) { $coverid[$x] = $_POST['deducid_' . $x]; $newpol[$x] = $_POST['deducvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into salarysettlementallowdeduc values('','$settlementid','$coverid[$i]','$newpol[$i]','0')"); $x--; $i++; } if (isset($_POST['settlement_type'])) { foreach ($_POST['settlement_type'] as $key) { $type = $key; $amount = $_POST['amount_' . $key]; $query = $this->db->query("insert into emp_settlement_types values('','$settlementid','$type','$amount')"); } } } function updatesalarysettlement() { $paymentdate = $this->mastermodel->convdatformat($_POST['date']); $relieving_date = $this->mastermodel->convdatformat($_POST['rel_date']); $netpayment = $_POST['basicsalary'] + $_POST['allowance'] - $_POST['deduction']; $settlementid = $_POST['emp_settlement_id']; $query1 = "update emp_settlement set employee_id='$_POST[employee_id]', relieving_date='$relieving_date', pay_date='$paymentdate', basic_salary='$_POST[basicsalary]', allowance='$_POST[allowance]', deduction='$_POST[deduction]', netpayment='$netpayment', currencytype='$_POST[currencytype]', paidamount='$netpayment', unpost='1', commission='$_POST[commission]' where id='$settlementid'"; $query = $this->db->query($query1); // echo $query1;die(); $this->db->where('salarysettlementid', $settlementid); $this->db->delete('salarysettlementallowdeduc'); $this->db->where('salarysettlementid', $settlementid); $this->db->delete('emp_settlement_types'); $x = 1; while (isset($_POST['allowvalue_' . $x])) { $coverid[$x] = $_POST['allowid_' . $x]; $newpol[$x] = $_POST['allowvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $sql = "insert into salarysettlementallowdeduc values('','$settlementid','$coverid[$i]','$newpol[$i]','1')"; $query = $this->db->query($sql); $x--; $i++; } $x = 1; while (isset($_POST['deducvalue_' . $x])) { $coverid[$x] = $_POST['deducid_' . $x]; $newpol[$x] = $_POST['deducvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into salarysettlementallowdeduc values('','$settlementid','$coverid[$i]','$newpol[$i]','0')"); $x--; $i++; } if (isset($_POST['settlement_type'])) { foreach ($_POST['settlement_type'] as $key) { $type = $key; $amount = $_POST['amount_' . $key]; $query = $this->db->query("insert into emp_settlement_types values('','$settlementid','$type','$amount')"); } } } function insertsalarypayment() { $paydate = date('Y-m-d'); $salarydate = $this->mastermodel->convdatformat($_POST['salarydate']); $netpayment = $_POST['basicsalary'] + $_POST['allowance'] - $_POST['deduction']; $query1 = "insert into emp_salary_slip (employee_id,salary_date,pay_date,basic_salary,allowance,deduction,netpayment,currencytype,paidamount,commission) values('$_POST[staffid]','$salarydate','$paydate','$_POST[basicsalary]','$_POST[allowance]','$_POST[deduction]','$netpayment','$_POST[currencytype]','$_POST[payamount]','$_POST[commission]')"; $query = $this->db->query($query1); $salid = mysql_insert_id(); $x = 1; while (isset($_POST['allowvalue_' . $x])) { $coverid[$x] = $_POST['allowid_' . $x]; $newpol[$x] = $_POST['allowvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $sql = "insert into salarypaymentallowdeduc values('','$salid','$coverid[$i]','$newpol[$i]','1')"; $query = $this->db->query($sql); $x--; $i++; } $x = 1; while (isset($_POST['deducvalue_' . $x])) { $coverid[$x] = $_POST['deducid_' . $x]; $newpol[$x] = $_POST['deducvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into salarypaymentallowdeduc values('','$salid','$coverid[$i]','$newpol[$i]','0')"); $x--; $i++; } } function insertcommissionpayment() { $query = $this->db->query("insert into commissionpayment (staffid,date,commission) values('$_POST[staffid]','$_POST[date]','$_POST[totalpremium]')"); $sql = "select MAX(id) as maxid from commissionpayment"; $res = mysql_query($sql); $row = mysql_fetch_array($res); $x = 1; while (isset($_POST['cover_id_' . $x])) { $cover_id[$x] = $_POST['cover_id_' . $x]; $comperc[$x] = $_POST['comperc_' . $x]; $comon[$x] = $_POST['comon_' . $x]; $comamt[$x] = $_POST['comamt_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into commissionpaymentdetails values('', '$row[maxid]','$cover_id[$i]]','$comperc[$i]','$comon[$i]','$comamt[$i]')"); $x--; $i++; } } function insertleaveallocation($data) { $x = 1; $query = $this->db->query("insert into leaveallocation (staffid,year) values('$_POST[employee_id]','$_POST[year]')"); $lastid = mysql_insert_id(); while (isset($_POST['leavetypeid_' . $x])) { $leavetypeid[$x] = $_POST['leavetypeid_' . $x]; $noofdays[$x] = $_POST['noofdays_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into leaveallocationdetails values('', '$lastid','$leavetypeid[$i]','$noofdays[$i]')"); $x--; $i++; } } function insertstaff() { if ($_POST['type'] == 'Agent') { $code = $this->mastermodel->get_account_code('AGENT', '99', 'staffpersonaldetails', 'employeeid'); $parent = $this->accountingsmodel->get_subaccount_setting('agent'); } else { $code = $this->mastermodel->get_account_code('EMP', '99', 'staffpersonaldetails', 'employeeid'); $parent = $this->accountingsmodel->get_subaccount_setting('employee'); } $enam = $_POST['name']; $sql = "insert into staffpersonaldetails (employeeid,name,gender,dob,maritalstatus,nationality,idno,passportno,typeofvisa,expiryofvisa,type) values('$code','$_POST[name]','$_POST[gender]','$_POST[dob]','$_POST[maritalstatus]','$_POST[nationality]','$_POST[idno]','$_POST[passportno]','$_POST[typeofvisa]','$_POST[expiryofvisa]','$_POST[type]')"; //die(); $query = $this->db->query($sql); //insert Employee Bank Account to chart_master $chart_type = $this->mastermodel->getSingleFieldValue('chart_master', 'chart_type', 'id', $parent); $tblValues = array('account_code' => $code, 'account_name' => $enam , 'chart_type' => $chart_type, 'parent' => $parent, 'inactive' => 0); $this->db->insert('chart_master', $tblValues); $sql = "select MAX(id) as maxid from staffpersonaldetails"; $res = mysql_query($sql); $row = mysql_fetch_array($res); $query1 = $this->db->query("insert into staffemployeedetails (staffid,designationid,deptid,gradeid,statusid,joiningdate,reportingtostaffid,branchid,labourcardno,labourcardexpiry,device_no) values('$row[maxid]','$_POST[designation]','$_POST[department]','$_POST[grade]','$_POST[status]','$_POST[joiningdate]','$_POST[reportingtostaffid]','$_POST[branch]','$_POST[labno]','$_POST[labexp]','$_POST[device_no]')"); $query2 = $this->db->query("insert into staffpermaddress (staffid,emailid,phone,mobile,address,pobox,country,city) values('$row[maxid]','$_POST[emailid]','$_POST[phone]','$_POST[mobile]','$_POST[address]','$_POST[pobox]','$_POST[country]','$_POST[city]')"); $query3 = $this->db->query("insert into stafflocaladdress (staffid,phone,mobile,address,pobox,country,city) values('$row[maxid]','$_POST[lphone]','$_POST[lmobile]','$_POST[laddress]','$_POST[lpobox]','$_POST[lcountry]','$_POST[lcity]')"); $course[1] = $_POST['txt_conCourse_1']; $uty[1] = $_POST['txt_conUty_1']; $yop[1] = $_POST['txt_conYop_1']; $x = 2; while (isset($_POST['txt_conCourse_' . $x])) { $course[$x] = $_POST['txt_conCourse_' . $x]; $uty[$x] = $_POST['txt_conUty_' . $x]; $yop[$x] = $_POST['txt_conYop_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into staffeduquali values ('', '$row[maxid]','$course[$i]','$uty[$i]','$yop[$i]')"); $x--; $i++; } $course[1] = $_POST['txt_conCourseCer_1']; $uty[1] = $_POST['txt_conUInstCer_1']; $yop[1] = $_POST['txt_conYopCer_1']; $x = 2; while (isset($_POST['txt_conCourseCer_' . $x])) { $course[$x] = $_POST['txt_conCourse_' . $x]; $uty[$x] = $_POST['txt_conUInstCer_' . $x]; $yop[$x] = $_POST['txt_conYopCer_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into staffaddcert values ('', '$row[maxid]','$course[$i]','$uty[$i]','$yop[$i]')"); $x--; $i++; } $course[1] = $_POST['txt_conEmp_1']; $uty[1] = $_POST['txt_conDesg_1']; $yop[1] = $_POST['txt_conPow_1']; $x = 2; while (isset($_POST['txt_conEmp_' . $x])) { $course[$x] = $_POST['txt_conCourse_' . $x]; $uty[$x] = $_POST['txt_conDesg_' . $x]; $yop[$x] = $_POST['txt_conPow_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into staffproffexp values ('', '$row[maxid]','$course[$i]','$uty[$i]','$yop[$i]')"); $x--; $i++; } if ($query > 0) { return 1; } else { return 0; } } function updatedesignation($table) { $query = $this->db->query("update $table set designation='$_POST[designation]', reportingtoid = $_POST[reportingtoid] where id='$_POST[designationid]'"); } function updateofferletter($table) { $query = $this->db->query("update $table set name='$_POST[name]', email = '$_POST[email]',subdate='$_POST[subdate]', contactno = '$_POST[contactno]', designationid = '$_POST[designationid]', joindate ='$_POST[joindate]' where id='$_POST[offerletterid]'"); } function updateassignleave($table) { $fromdate = $date = $this->mastermodel->convdatformat($_POST['fromdate']); $todate = $date = $this->mastermodel->convdatformat($_POST['todate']); $query = $this->db->query("update $table set fromdate = '$fromdate', todate = '$todate', type = '$_POST[type]', remarks = '$_POST[remarks]' where id='$_POST[assignleaveid]'"); } function updateassignleavepermit($table) { $fromdate = $date = $this->mastermodel->convdatformat($_POST['fromdate']); $todate = $date = $this->mastermodel->convdatformat($_POST['todate']); $query = $this->db->query("update $table set fromdate = '$fromdate', todate = '$todate', type = '$_POST[type]', remarks = '$_POST[remarks]',leavestatus = '$_POST[leavestatus]' where id='$_POST[assignleaveid]'"); } function updatedepartment($table) { $query = $this->db->query("update $table set departmentname='$_POST[departmentname]' where id='$_POST[departmentid]'"); } function updategrade($table) { $query = $this->db->query("update $table set gradename='$_POST[gradename]' where id='$_POST[gradeid]'"); } function updatestatus($table) { $query = $this->db->query("update $table set statusname='$_POST[statusname]' where id='$_POST[statusid]'"); } function updatecommissionsettings($table) { $query = $this->db->query("update $table set cover_id='$_POST[cover_id]',designationid='$_POST[designationid]',newpolicy='$_POST[newpolicy]',renewal='$_POST[renewal]' where id='$_POST[commissionsettingsid]'"); } function updatesettlement_types($table) { $query = $this->db->query("update $table set settlement_name='$_POST[settlement_name]' where id='$_POST[id]'"); $tblValues = array('account_name' => $_POST['settlement_name']); $this->db->where('account_code', $_POST['chartgroup_name']); $this->db->update('chart_master', $tblValues); } function updateallowdeduc($table) { $query = $this->db->query("update $table set allowdeducname='$_POST[allowdeducname]', allowdeductype = '$_POST[allowdeductype]',mode='$_POST[mode]' where id='$_POST[allowdeducid]'"); $tblValues = array('account_name' => $_POST['allowdeducname']); $this->db->where('account_code', $_POST['chartgroup_name']); $this->db->update('chart_master', $tblValues); } function updateleavetype($table) { $query = $this->db->query("update $table set leavecode='$_POST[leavecode]',leavename='$_POST[leavename]', gender = '$_POST[gender]', carryforward = '$_POST[carryforward]', salaryrefund = '$_POST[refundable]' where id='$_POST[leavetypeid]'"); } function updateholidays($table) { $start_date = $this->mastermodel->convertdateformat($_POST['start_date']); $end_date = $this->mastermodel->convertdateformat($_POST['end_date']); $query = $this->db->query("update $table set occasion='$_POST[occasion]',start_date='$start_date',end_date='$end_date' where id='$_POST[holidaysid]'"); } function updateworkshifts() { $data = array(); $tblValues = array( 'work_shift_name' => $_POST['work_shift_name'], 'work_shift_starting_time' => $_POST['start_hour'] . ':' . $_POST['start_minute'], 'work_shift_ending_time' => $_POST['end_hour'] . ':' . $_POST['end_minute'], 'work_shift_grace_time' => $_POST['work_shift_grace_time'], 'work_shift_break_starting_time' => $_POST['break_start_hour'] . ':' . $_POST['break_start_minute'], 'work_shift_break_ending_time' => $_POST['break_end_hour'] . ':' . $_POST['break_end_minute'], 'work_shift_ending_time_half' => $_POST['end_hour_half'] . ':' . $_POST['end_minute_half']); $this->db->where('work_shift_id', $_POST['workshiftid']); $this->db->update('timesheet_work_shift', $tblValues); $this->db->where('work_shift_id', $_POST['workshiftid']); $this->db->delete('timesheet_work_shift_employees'); $i = 1; if (isset($_POST['employees_2'])) { foreach ($_POST['employees_2'] as $employee) { $tblValues = array( 'work_shift_id' => $_POST['workshiftid'], 'employee_id' => $employee); $this->db->insert('timesheet_work_shift_employees', $tblValues); $i++; //echo $this->db->last_query(); } } } function addweeklyholiday() { $this->db->query("truncate timesheet_weekly_holiday"); foreach ($_POST['weekly_holiday'] as $holiday) { $this->db->query("insert into timesheet_weekly_holiday values(null,'" . $holiday . "')"); } $this->db->query("truncate timesheet_weekly_holiday_half"); foreach ($_POST['weekly_holiday_half'] as $holidayhalf) { $this->db->query("insert into timesheet_weekly_holiday_half values(null,'" . $holidayhalf . "')"); } return 1; } function addworkshift() { $data = array(); $tblValues = array( 'work_shift_name' => $_POST['work_shift_name'], 'work_shift_wef_date' => $this->mastermodel->convertdateformat($_POST['work_shift_wef_date']), 'work_shift_starting_time' => $_POST['start_hour'] . ':' . $_POST['start_minute'], 'work_shift_ending_time' => $_POST['end_hour'] . ':' . $_POST['end_minute'], 'work_shift_grace_time' => $_POST['work_shift_grace_time'], 'work_shift_break_starting_time' => $_POST['break_start_hour'] . ':' . $_POST['break_start_minute'], 'work_shift_break_ending_time' => $_POST['break_end_hour'] . ':' . $_POST['break_end_minute'], 'work_shift_ending_time_half' => $_POST['end_hour_half'] . ':' . $_POST['end_minute_half'] ); $this->db->insert('timesheet_work_shift', $tblValues); $work_shift_id = mysql_insert_id(); $i = 1; if (isset($_POST['employees_2'])) { foreach ($_POST['employees_2'] as $employee) { $tblValues = array('id' => 'null', 'work_shift_id' => $work_shift_id, 'employee_id' => $employee); $this->db->insert('timesheet_work_shift_employees', $tblValues); $i++; } } } function get_employee_shift($employee_device_id, $date) { $qry = "SELECT * from timesheet_work_shift inner join timesheet_work_shift_employees ON (`timesheet_work_shift_employees`.`work_shift_id` = `timesheet_work_shift`.`work_shift_id`) inner join staffemployeedetails ON (`staffemployeedetails`.`staffid` = `timesheet_work_shift_employees`.`employee_id`) WHERE device_no = '$employee_device_id' AND work_shift_wef_date <='$date' order by work_shift_wef_date desc limit 1"; $res = $this->db->query($qry); $data = $res->row(); return $data; } function get_employee_attendance($employee_device_id, $from_date, $to_date) { $data = array(); $from_date = $this->mastermodel->convertdateformat($from_date); $from_date = $from_date . " 00:00:00"; $to_date = $this->mastermodel->convertdateformat($to_date); $to_date = $to_date . " 23:59:59"; $this->db->where('employee_device_id', $employee_device_id); $this->db->where('attendance_date >=', $from_date); $this->db->where('attendance_date <=', $to_date); $this->db->order_by('attendance_date', 'asc'); $Q = $this->db->get('timesheet_attendance'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function insertbulkattendance() { $data = array(); $weekly_holidays = $this->mastermodel->getdatas('timesheet_weekly_holiday', 'weekly_holiday_id'); $holiday = array(); foreach ($weekly_holidays as $weekly) { $holiday[] = $weekly['weekly_holiday']; } $weekly_holidays_half = $this->mastermodel->getdatas('timesheet_weekly_holiday_half', 'weekly_holiday_id'); $holiday_half = array(); foreach ($weekly_holidays_half as $weekly_half) { $holiday_half[] = $weekly_half['weekly_holiday_half']; } $start_date = $this->mastermodel->convertdateformat($_POST['from_date']); $end_date = $this->mastermodel->convertdateformat($_POST['to_date']); while (strtotime($start_date) <= strtotime($end_date)) { if (in_array(date('l', strtotime($start_date)), $holiday) || $this->is_special_holiday($start_date) > 0) { } else if (in_array(date('l', strtotime($start_date)), $holiday_half)) { foreach ($_POST['employee'] as $employee) { $shift_details = $this->get_employee_shift($employee, $start_date); $num = $this->mastermodel->number_rows('timesheet_attendance', 'employee_device_id', $employee, 'attendance_date', $start_date . " " . $shift_details->work_shift_starting_time, 'attendance_mode', 0); if ($num == 0) { $tblValues = array('employee_device_id' => $employee, 'attendance_date' => $start_date . " " . $shift_details->work_shift_starting_time, 'attendance_mode' => 0, 'attendance_remarks' => $_POST['attendance_remarks'] ); $this->db->insert('timesheet_attendance', $tblValues); } $num = $this->mastermodel->number_rows('timesheet_attendance', 'employee_device_id', $employee, 'attendance_date', $start_date . " " . $shift_details->work_shift_ending_time, 'attendance_mode', 1); if ($num == 0) { $tblValues1 = array('employee_device_id' => $employee, 'attendance_date' => $start_date . " " . $shift_details->work_shift_ending_time_half, 'attendance_mode' => 1, 'attendance_remarks' => $_POST['attendance_remarks'], ); $this->db->insert('timesheet_attendance', $tblValues1); } } } else { foreach ($_POST['employee'] as $employee) { $shift_details = $this->get_employee_shift($employee, $start_date); $num = $this->mastermodel->number_rows('timesheet_attendance', 'employee_device_id', $employee, 'attendance_date', $start_date . " " . $shift_details->work_shift_starting_time, 'attendance_mode', 0); if ($num == 0) { $tblValues = array('employee_device_id' => $employee, 'attendance_date' => $start_date . " " . $shift_details->work_shift_starting_time, 'attendance_mode' => 0, 'attendance_remarks' => $_POST['attendance_remarks'] ); $this->db->insert('timesheet_attendance', $tblValues); } $num = $this->mastermodel->number_rows('timesheet_attendance', 'employee_device_id', $employee, 'attendance_date', $start_date . " " . $shift_details->work_shift_ending_time, 'attendance_mode', 1); if ($num == 0) { $tblValues1 = array('employee_device_id' => $employee, 'attendance_date' => $start_date . " " . $shift_details->work_shift_ending_time, 'attendance_mode' => 1, 'attendance_remarks' => $_POST['attendance_remarks'], ); $this->db->insert('timesheet_attendance', $tblValues1); } } } $start_date = date("Y-m-d", strtotime("+1 day", strtotime($start_date))); } } function insertupdateattendance($postdata) { $data = array(); for ($i = 1; $i <= $postdata['num_rows']; $i++) { if (isset($postdata['present_' . $i])) { $tblValues = array( 'attendance_mode' => $postdata['attendance_mode_' . $i], 'attendance_remarks' => $postdata['attendance_remarks_' . $i] ); $this->db->where('timesheet_attendance_id', $postdata['timesheet_attendance_id_' . $i]); $this->db->update('timesheet_attendance', $tblValues); } else { $this->db->where('timesheet_attendance_id', $postdata['timesheet_attendance_id_' . $i]); $this->db->delete('timesheet_attendance'); } } } function insertmarkattendance() { $data = array(); $date = $this->mastermodel->convertdateformat($_POST['date']); $tblValues = array('employee_device_id' => $_POST['device_id'], 'attendance_date' => $date . " " . $_POST['time_hour'] . ":" . $_POST['time_minute'] . ":00", 'attendance_mode' => $_POST['attendance_mode'], 'attendance_remarks' => $_POST['attendance_remarks'] ); $this->db->insert('timesheet_attendance', $tblValues); //echo $this->db->last_query(); //die(); } function updateresumemanagement($table) { $query = $this->db->query("update $table set name='$_POST[name]',department='$_POST[department]',qualification='$_POST[qualification]',email='$_POST[email]',subdate='$_POST[subdate]',expectedsalary='$_POST[expectedsalary]',experience='$_POST[experience]',contactno='$_POST[contactno]' where id='$_POST[resumemanagementid]'"); } function updatestaff() { $query = $this->db->query("update staffpersonaldetails set name='" . $_POST['name'] . "',gender='$_POST[gender]',dob='$_POST[dob]',maritalstatus='$_POST[maritalstatus]',nationality='$_POST[nationality]',idno='$_POST[idno]',passportno='$_POST[passportno]',typeofvisa='$_POST[typeofvisa]',expiryofvisa='$_POST[expiryofvisa]',type='$_POST[type]' where id='$_POST[staffid]'"); $query1 = $this->db->query("update staffemployeedetails set designationid='$_POST[designation]',deptid='$_POST[department]',gradeid='$_POST[grade]',statusid='$_POST[status]',joiningdate='$_POST[joiningdate]',reportingtostaffid='$_POST[reportingtostaffid]',branchid='$_POST[branch]',labourcardno='$_POST[labno]',labourcardexpiry='$_POST[labexp]',device_no='$_POST[device_no]' where staffid='$_POST[staffid]'"); $query2 = $this->db->query("update staffpermaddress set emailid='$_POST[emailid]',phone='$_POST[phone]',mobile='$_POST[mobile]',address='$_POST[address]',pobox='$_POST[pobox]',country='$_POST[country]',city='$_POST[city]' where staffid='$_POST[staffid]'"); $query3 = $this->db->query("update stafflocaladdress set phone='$_POST[lphone]',mobile='$_POST[lmobile]',address='$_POST[laddress]',pobox='$_POST[lpobox]',country='$_POST[lcountry]',city='$_POST[lcity]' where staffid='$_POST[staffid]'"); $numcont = $this->db->query("select * from staffeduquali where staffid='$_POST[staffid]'"); $numcontact = $numcont->num_rows(); $x = 1; while (isset($_POST['txt_conCourse_' . $x]) != '') { $course[$x] = $_POST['txt_conCourse_' . $x]; $uty[$x] = $_POST['txt_conUty_' . $x]; $yop[$x] = $_POST['txt_conYop_' . $x]; if ($x <= $numcontact) { $id[$x] = $_POST['hided_' . $x]; $sql = "update staffeduquali set `course`='$course[$x]',`university`='$uty[$x]',`yearofpassing`='$yop[$x]' where id='$id[$x]' "; $query = $this->db->query($sql); // echo $sql; } else { if (!empty($_POST['txt_conCourse_' . $x])) { $query = $this->db->query("insert into staffeduquali values ('', '$_POST[staffid]', '$course[$x]', '$uty[$x]', '$yop[$x]')"); } } $x++; } $numcont = $this->db->query("select * from staffaddcert where staffid='$_POST[staffid]'"); $numcontact = $numcont->num_rows(); $x = 1; while (isset($_POST['txt_conCourseCer_' . $x]) != '') { $course[$x] = $_POST['txt_conCourseCer_' . $x]; $inst[$x] = $_POST['txt_conUInstCer_' . $x]; $yop[$x] = $_POST['txt_conYopCer_' . $x]; if ($x <= $numcontact) { $id[$x] = $_POST['hidcer_' . $x]; $sql = "update staffaddcert set `course`='$course[$x]',`institute`='$inst[$x]',`yearofpassing`='$yop[$x]' where id='$id[$x]' "; $query = $this->db->query($sql); } else { if (!empty($_POST['txt_conCourseCer_' . $x])) { $query = $this->db->query("insert into staffaddcert values ('', '$_POST[staffid]', '$course[$x]', '$inst[$x]', '$yop[$x]')"); } } $x++; } $numcont = $this->db->query("select * from staffproffexp where staffid='$_POST[staffid]'"); $numcontact = $numcont->num_rows(); $x = 1; while (isset($_POST['txt_conEmp_' . $x]) != '') { // echo $x."<br>"; $emp[$x] = $_POST['txt_conEmp_' . $x]; $desg[$x] = $_POST['txt_conDesg_' . $x]; $pow[$x] = $_POST['txt_conPow_' . $x]; if ($x <= $numcontact) { $id[$x] = $_POST['hidprof_' . $x]; $sql = "update staffproffexp set `employer`='$emp[$x]',`designation`='$desg[$x]',`period`='$pow[$x]' where id='$id[$x]' "; $query = $this->db->query($sql); } else { if (!empty($_POST['txt_conEmp_' . $x])) { $query = $this->db->query("insert into staffproffexp values ('', '$_POST[staffid]', '$emp[$x]', '$desg[$x]', '$pow[$x]')"); } } $x++; } } function updateleaveallocation($data) { $x = 1; $query = $this->db->query("update leaveallocation set staffid = '$_POST[staffid]', year = '$_POST[year]' where id = '$_POST[leaveallocationid]'"); $lastid = mysql_insert_id(); $sql = "delete from leaveallocationdetails where leaveallocationid = '$_POST[leaveallocationid]'"; $this->db->query($sql); while (isset($_POST['leavetypeid_' . $x])) { $leavetypeid[$x] = $_POST['leavetypeid_' . $x]; $noofdays[$x] = $_POST['noofdays_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into leaveallocationdetails values('', '$_POST[leaveallocationid]','$leavetypeid[$i]','$noofdays[$i]')"); $x--; $i++; } } function updatestaffsalary() { $date = $this->mastermodel->convdatformat($_POST['date']); $query = $this->db->query("update staffsalary set staffid='$_POST[employee_id]',date='$date',basicsalary='$_POST[basicsalary]',paymethod='$_POST[paymethod]',currencytype='$_POST[currencytype]' where id='$_POST[staffsalaryid]'"); echo mysql_error(); $numcont = $this->db->query("select * from staffsalaryallowdeduc where staffsalaryid='$_POST[staffsalaryid]' and allowdeductype = '1'"); $numcontact = $numcont->num_rows(); $salid = $_POST['staffsalaryid']; $this->db->query("delete from staffsalaryallowdeduc where staffsalaryid = '$salid'"); $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]')"); } $x = 1; while (isset($_POST['newpolicy_' . $x])) { $coverid[$x] = $_POST['allowid_' . $x]; $newpol[$x] = $_POST['newpolicy_' . $x]; $x++; } $i = 1; while ($x != 1) { $sql = "insert into staffsalaryallowdeduc values('','$salid','$coverid[$i]','$newpol[$i]','1')"; $query = $this->db->query($sql); $x--; $i++; } $x = 1; while (isset($_POST['newpolicy1_' . $x])) { $coverid[$x] = $_POST['deducid_' . $x]; $newpol[$x] = $_POST['newpolicy1_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into staffsalaryallowdeduc values('','$salid','$coverid[$i]','$newpol[$i]','0')"); $x--; $i++; } $x = 1; $this->db->query("delete from staffsalarymedical where staffsalaryid = '$_POST[staffsalaryid]'"); while (isset($_POST['txt_conType_' . $x])) { $type[$x] = $_POST['txt_conType_' . $x]; $company[$x] = $_POST['txt_conIns_' . $x]; $policy[$x] = $_POST['txt_conPol_' . $x]; $plan[$x] = $_POST['txt_conPlan_' . $x]; $sum[$x] = $_POST['txt_conSum_' . $x]; $x++; } $i = 1; while ($x != 1) { $query = $this->db->query("insert into staffsalarymedical values('','$_POST[staffsalaryid]', '$type[$i]','$company[$i]','$policy[$i]','$plan[$i]','$sum[$i]')"); $x--; $i++; } // if($_POST['last_method']=='cash') // { // // // 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('',' $_POST[staffsalaryid]', '$_POST[cheque_no]','$_POST[bank_name]','','')"); // // } // else { // $query=$this->db->query("insert into salarybank values('',' $_POST[staffsalaryid]', '$_POST[cheque_no]','$_POST[bank_name]','$_POST[acc_no]','$_POST[branch_name]')"); // } // // } // // // // // // // if($_POST['paymethod']!='cash') // { // // if($_POST['paymethod']=='bank') // { // // // echo "insert into salarybank values('','1', '$_POST[cheque_no]','$_POST[bank_name]','Bank','Bank'"; // $query=$this->db->query("update salarybank set ch_dep_no='$_POST[cheque_no]',bank_name='$_POST[bank_name]',acc_no='',branch_name='' where sal_id='$_POST[staffsalaryid]'"); // // } // else { // // $query=$this->db->query("update salarybank set ch_dep_no='$_POST[cheque_no]',bank_name='$_POST[bank_name]',acc_no='$_POST[acc_no]',branch_name='$_POST[branch_name]' where sal_id='$_POST[staffsalaryid]'"); // } // } // // else if($_POST['paymethod']=='cash') // { // $query=$this->db->query("delete from salarybank where sal_id='$_POST[staffsalaryid]'"); // } } function updatecomstafffin($table) { $x = 1; while (isset($_POST['comid_' . $x]) != '') { $sql = "update staffcommissionsettings set `newpolicy`='" . $_POST['newpolicy_' . $x] . "',`renewal`='" . $_POST['renewal_' . $x] . "' where id= '" . $_POST['comid_' . $x] . "'"; //echo $sql; $query = $this->db->query($sql); $x++; } } function get_data_search($table, $id, $field, $page, $per_page) { if ($page) { $start = ($page - 1) * $per_page; } else { $start = 0; } switch ($field) { case "name": $sql = "select * from $table where $field like '" . $id . "%' limit $start,$per_page"; break; case "designation": $query = "select id from designation where $field like '" . $id . "%'"; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and designationid in ($query) limit $start,$per_page"; break; case "department": $query = "select id from department where departmentname like '" . $id . "%'"; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and deptid in ($query) limit $start,$per_page"; break; } //echo $sql; return $sql; } function get_data_search_others($table, $id, $field, $page, $per_page) { if ($page) { $start = ($page - 1) * $per_page; } else { $start = 0; } if ($field == "reportingtoid") { $qry = "select id from designation where designation like '" . $id . "%'"; $sql = "select * from $table where $field in ($qry) limit $start,$per_page"; } else if ($field == "staffid") { $qry = "select id from staffpersonaldetails where name like '" . $id . "%'"; $sql = "select * from $table where $field in ($qry) limit $start,$per_page"; // echo $sql; } else if ($field == "cover_id") { $qry = "select id from covers where cover like '" . $id . "%'"; $sql = "select * from $table where $field in ($qry) limit $start,$per_page"; } else if ($field == "designationid") { $qry = "select id from designation where designation like '" . $id . "%'"; $sql = "select * from $table where $field in ($qry) limit $start,$per_page"; // echo $sql; } else if ($field == "type") { $qry = "select id from leavetype where leavename like '" . $id . "%'"; //echo $qry; $sql = "select * from $table where $field in ($qry) limit $start,$per_page"; // echo $sql; } else { $sql = "select * from $table where $field like '%" . $id . "%' limit $start,$per_page"; } return $sql; } function get_data_search_all($table, $id, $field) { switch ($field) { case "name": $sql = "select * from $table where $field like '" . $id . "%'"; break; case "designation": $query = "select id from designation where $field like '" . $id . "%'"; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and designationid in ($query)"; break; case "department": $query = "select id from department where departmentname like '" . $id . "%'"; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and deptid in ($query)"; break; } $res = mysql_query($sql); return mysql_num_rows($res); } function get_data_search_others_all($table, $id, $field) { if ($field == "reportingtoid") { $qry = "select id from designation where designation like '" . $id . "%'"; $sql = "select * from $table where $field in ($qry)"; } else { $sql = "select * from $table where $field like '" . $id . "%'"; } $res = mysql_query($sql); return mysql_num_rows($res); } function get_data_search_othersnew($table, $id, $field, $page, $per_page) { $staffids = $this->mastermodel->tracestaff(); $staffids = implode(',', $staffids); if ($this->mastermodel->ret_private()) { $where = ' where staffid in (' . $staffids . ') and'; } else { $where = ' where '; } if ($page) { $start = ($page - 1) * $per_page; } else { $start = 0; } if ($field == "reportingtoid") { $qry = "select id from designation where designation like '" . $id . "%'"; $sql = "select * from $table $where $field in ($qry) limit $start,$per_page"; } else if ($field == "staffid") { $qry = "select id from staffpersonaldetails where name like '" . $id . "%'"; $sql = "select * from $table $where $field in ($qry) limit $start,$per_page"; } else if ($field == "cover_id") { if ($table == 'commissionsettings') { $sql = "SELECT * FROM commissionsettings c join staffemployeedetails se on se.designationid=c.designationid join covers cv on c.cover_id=cv.id where cover like '" . $id . "%' and se.staffid in($staffids)"; } else { $qry = "select id from covers where cover like '" . $id . "%'"; $sql = "select * from $table $where $field in ($qry) limit $start,$per_page"; } } else if ($field == "designationid") { $qry = "select id from designation where designation like '" . $id . "%'"; $sql = "select * from $table where $field in ($qry) limit $start,$per_page"; } else if ($field == "type") { $qry = "select id from leavetype where leavename like '" . $id . "%'"; $sql = "select * from $table $where $field in ($qry) limit $start,$per_page"; } else { $sql = "select * from $table $where $field like '" . $id . "%' limit $start,$per_page"; } //echo $sql; return $sql; } function get_data_search_others_allnew($table, $id, $field) { $staffids = $this->mastermodel->tracestaff(); $staffids = implode(',', $staffids); if ($this->mastermodel->ret_private()) { $where = ' where staffid in (' . $staffids . ') and'; } else { $where = ' where '; } if ($field == "reportingtoid") { $qry = "select id from designation where designation like '" . $id . "%'"; $sql = "select * from $table $where $field in ($qry)"; } else if ($field == "staffid") { $qry = "select id from staffpersonaldetails where name like '" . $id . "%'"; $sql = "select * from $table $where $field in ($qry)"; } else if ($field == "cover_id") { if ($table == 'commissionsettings') { $sql = "SELECT * FROM commissionsettings c join staffemployeedetails se on se.designationid=c.designationid join covers cv on c.cover_id=cv.id where cover like '" . $id . "%' and se.staffid in($staffids)"; } else { $qry = "select id from covers where cover like '" . $id . "%'"; $sql = "select * from $table $where $field in ($qry) "; } } else if ($field == "designationid") { $qry = "select id from designation where designation like '" . $id . "%'"; $sql = "select * from $table where $field in ($qry)"; } else if ($field == "type") { $qry = "select id from leavetype where leavename like '" . $id . "%'"; $sql = "select * from $table $where $field in ($qry)"; } else { $sql = "select * from $table $where $field like '" . $id . "%'"; } // echo $sql; $res = mysql_query($sql); return mysql_num_rows($res); } function get_data_searchnew($table, $id, $field, $page, $per_page) { $staffids = $this->mastermodel->tracestaff(); $staffids = implode(',', $staffids); if ($this->mastermodel->ret_private()) { $where = ' where staffpersonaldetails.id in (' . $staffids . ') and'; } else { $where = ' where '; } if ($page) { $start = ($page - 1) * $per_page; } else { $start = 0; } switch ($field) { case "name": $sql = "select * from $table $where $field like '" . $id . "%' limit $start,$per_page"; break; case "employeeid": $sql = "select * from $table $where $field like '" . $id . "%' limit $start,$per_page"; break; case "designation": $query = "select id from designation where $field like '" . $id . "%'"; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select department.departmentname,designation.designation,staffpersonaldetails.id,staffpersonaldetails.employeeid,staffpersonaldetails.name from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid join designation on staffemployeedetails.designationid=designation.id join department on staffemployeedetails.deptid=department.id $where designation.designation like '" . $id . "%' limit $start,$per_page"; break; case "department": $query = "select id from department where departmentname like '" . $id . "%'"; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select department.departmentname,staffpersonaldetails.id,staffpersonaldetails.employeeid,staffpersonaldetails.name from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid join department on staffemployeedetails.deptid=department.id $where department.departmentname like '" . $id . "%' limit $start,$per_page"; break; } return $sql; } function get_data_search_allnew($table, $id, $field) { $staffids = $this->mastermodel->tracestaff(); $staffids = implode(',', $staffids); if ($this->mastermodel->ret_private()) { $where = ' where staffpersonaldetails.id in (' . $staffids . ') and'; } else { $where = ' where '; } switch ($field) { case "name": $sql = "select * from $table $where $field like '" . $id . "%'"; break; case "employeeid": $sql = "select * from $table $where $field like '" . $id . "%'"; break; case "designation": $query = "select id from designation where $field like '" . $id . "%'"; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select department.departmentname,designation.designation,staffpersonaldetails.id,staffpersonaldetails.employeeid,staffpersonaldetails.name from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid join designation on staffemployeedetails.designationid=designation.id join department on staffemployeedetails.deptid=department.id $where designation.designation like '" . $id . "%'"; break; case "department": $query = "select id from department where departmentname like '" . $id . "%'"; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select department.departmentname,staffpersonaldetails.id,staffpersonaldetails.employeeid,staffpersonaldetails.name from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid join department on staffemployeedetails.deptid=department.id $where department.departmentname like '" . $id . "%'"; break; } $res = mysql_query($sql); return mysql_num_rows($res); } function employeelist($staffname = "", $searchBy = "") { $data = array(); if ($searchBy == 'employeeid' || $searchBy == 'name') { $qry = "SELECT * from staffpersonaldetails where $searchBy like '" . $staffname . "%'"; $Q = $this->db->query($qry); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } else if ($searchBy == 'designation') { $query = "select id from designation where $searchBy like '" . $staffname . "%'"; // echo $query; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and staffemployeedetails.designationid in ($query)"; $Q = $this->db->query($sql); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } else if ($searchBy == 'departmentname') { $query = "select id from department where $searchBy like '" . $staffname . "%'"; //echo $query; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and staffemployeedetails.deptid in ($query)"; $Q = $this->db->query($sql); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } return $data; } function get_leave_balance($staffid, $type, $year) { $balleav = 0; $sql = "select datediff(todate,fromdate) as leavbal from assignleave where type = '$type' and leavestatus = 'Approved' and staffid = '$staffid' and (fromdate like '" . $year . "%')"; $Q = $this->db->query($sql); $rows = $Q->result_array(); foreach ($rows as $rw) { $balleav+=$rw['leavbal']; } return $balleav; } function employeelistpagination($PageNo = 1, $pageSize, $staffname = "", $searchBy = "") { $limtvalue = ($PageNo - 1) * $pageSize . "," . $pageSize; $data = array(); if ($searchBy == 'employeeid' || $searchBy == 'name') { $qry = "SELECT * from staffpersonaldetails where $searchBy like '" . $staffname . "%' limit " . $limtvalue; $Q = $this->db->query($qry); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } else if ($searchBy == 'designation') { $query = "select id from designation where $searchBy like '" . $staffname . "%'"; // echo $query; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and staffemployeedetails.designationid in ($query)"; $Q = $this->db->query($sql); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } else if ($searchBy == 'departmentname') { $query = "select id from department where $searchBy like '" . $staffname . "%'"; //echo $query; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and staffemployeedetails.deptid in ($query)"; $Q = $this->db->query($sql); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } return $data; } function agentlistpagination($PageNo = 1, $pageSize, $staffname = "", $searchBy = "") { $limtvalue = ($PageNo - 1) * $pageSize . "," . $pageSize; $data = array(); if ($searchBy == 'employeeid' || $searchBy == 'name') { $qry = "SELECT * from staffpersonaldetails where $searchBy like '" . $staffname . "%' and type = 'Agent' limit " . $limtvalue; $Q = $this->db->query($qry); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } else if ($searchBy == 'designation') { $query = "select id from designation where $searchBy like '" . $staffname . "%'"; // echo $query; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and staffemployeedetails.designationid in ($query)"; $Q = $this->db->query($sql); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } else if ($searchBy == 'departmentname') { $query = "select id from department where $searchBy like '" . $staffname . "%'"; //echo $query; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and staffemployeedetails.deptid in ($query)"; $Q = $this->db->query($sql); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } return $data; } function emponlypagination($PageNo = 1, $pageSize, $staffname = "", $searchBy = "") { $limtvalue = ($PageNo - 1) * $pageSize . "," . $pageSize; $data = array(); if ($searchBy == 'employeeid' || $searchBy == 'name') { $qry = "SELECT * from staffpersonaldetails where $searchBy like '" . $staffname . "%' and type = 'Employee' limit " . $limtvalue; $Q = $this->db->query($qry); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } else if ($searchBy == 'designation') { $query = "select id from designation where $searchBy like '" . $staffname . "%'"; // echo $query; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and staffemployeedetails.designationid in ($query)"; $Q = $this->db->query($sql); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } else if ($searchBy == 'departmentname') { $query = "select id from department where $searchBy like '" . $staffname . "%'"; //echo $query; $res = mysql_query($query); $row = mysql_fetch_array($res); $sql = "select * from staffpersonaldetails inner join staffemployeedetails on staffpersonaldetails.id = staffemployeedetails.staffid and staffemployeedetails.deptid in ($query)"; $Q = $this->db->query($sql); $rows = $Q->result_array(); foreach ($rows as $rw) { $newRow['id'] = $rw['id']; $newRow['name'] = $rw['name']; $newRow['employeeid'] = $rw['employeeid']; $sql = "select designation from designation inner join staffemployeedetails on designation.id = staffemployeedetails.designationid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q1 = $this->db->query($sql); $rows1 = $Q1->result_array(); foreach ($rows1 as $rw1) $newRow['designation'] = $rw1['designation']; $sql1 = "select departmentname from department inner join staffemployeedetails on department.id = staffemployeedetails.deptid and staffemployeedetails.staffid = '" . $newRow['id'] . "'"; $Q2 = $this->db->query($sql1); $rows2 = $Q2->result_array(); foreach ($rows2 as $rw2) $newRow['department'] = $rw2['departmentname']; $data[] = $newRow; $newRow = ""; } } return $data; } function addresume($table) { $contactno = $this->input->post('contactno'); $email = $this->input->post('email'); $subdate = $this->input->post('subdate'); $name = $this->input->post('name'); $department = $this->input->post('department'); $qualification = $this->input->post('qualification'); $experience = $this->input->post('experience'); $expectedsalary = $this->input->post('expectedsalary'); $resumefile = $_FILES['userfile']['name']; $tblValues = array('name' => $name, 'department' => $department, 'qualification' => $qualification, 'email' => $email, 'subdate' => $subdate, 'expectedsalary' => $expectedsalary, 'experience' => $experience, 'contactno' => $contactno, 'filename' => $resumefile); $res = $this->db->insert($table, $tblValues); if ($res > 0) { return 1; } else { return 0; } } function addoffer($table) { $contactno = $this->input->post('contactno'); $email = $this->input->post('email'); $subdate = $this->input->post('subdate'); $name = $this->input->post('name'); $joindate = $this->input->post('joindate'); $designation = $this->input->post('designationid'); $expectedsalary = $this->input->post('expectedsalary'); $offerfile = $_FILES['userfile']['name']; $tblValues = array('name' => $name, 'designationid' => $designation, 'email' => $email, 'subdate' => $subdate, 'joindate' => $joindate, 'contactno' => $contactno, 'filename' => $offerfile); $res = $this->db->insert($table, $tblValues); if ($res > 0) { return 1; } else { return 0; } } function filecheck($file, $table) { $query = "select id from $table where filename = '" . $file . "'"; $res = $this->db->query($query); $data = $res->num_rows(); return $data; } function monthdays($someMonth, $someYear) { return date("t", strtotime($someYear . "-" . $someMonth . "-01")); } function checksalarymonth($id, $date) { $date = $this->mastermodel->convdatformat($date); $this->db->select('id'); $this->db->from('emp_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 post_sal_settlement($id) { $this->db->trans_begin(); $tblValues = array('unpost' => 0,); $this->db->where('id', $id); $this->db->update('emp_settlement', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } function multiplesalarypayment() { $this->db->trans_begin(); $saldate = $this->mastermodel->convdatformat($_POST['date']); $paydate = date('Y-m-d'); for ($i = 0; $i < sizeof($_POST['salempdet']); $i++) { if (isset($_POST['salempdet'][$i])) { $empid = $_POST['salempdet'][$i]; $salpay = $this->get_sal_data('staffsalary', $empid, $_POST['date']); $basicsalary = $salpay->basicsalary; $staffsalaryid = $salpay->id; $currency = $salpay->currencytype; $query1 = "insert into emp_salary_slip (employee_id,salary_date,pay_date,basic_salary,currencytype) values('$empid','$saldate','$paydate','$basicsalary','$currency')"; $query = $this->db->query($query1); $salid = mysql_insert_id(); $allowance = 0; $deduction = 0; $coverid = array(); $newpol = array(); if (isset($_POST['staffid_' . $empid])) { $x = 1; while (isset($_POST['allowvalue_' . $empid . '_' . $x])) { $coverid[$x] = $_POST['allowid_' . $empid . '_' . $x]; $newpol[$x] = $_POST['allowvalue_' . $empid . '_' . $x]; $x++; } $j = 1; while ($x != 1) { $sql = "insert into salarypaymentallowdeduc values('','$salid','$coverid[$j]','$newpol[$j]','1')"; $query = $this->db->query($sql); $x--; $j++; } $x = 1; while (isset($_POST['deducvalue_' . $empid . '_' . $x])) { $coverid[$x] = $_POST['deducid_' . $empid . '_' . $x]; $newpol[$x] = $_POST['deducvalue_' . $empid . '_' . $x]; $x++; } $j = 1; while ($x != 1) { $query = $this->db->query("insert into salarypaymentallowdeduc values('','$salid','$coverid[$j]','$newpol[$j]','0')"); $x--; $j++; } } else { $allowded = $this->getallowdeductdet($staffsalaryid); foreach ($allowded as $value) { $tblValues = array('salarypaymentid' => $salid, 'allowdeducid' => $value['allowdeducid'], 'amount' => $value['amount'], 'allowdeductype' => $value['allowdeductype']); $res = $this->db->insert('salarypaymentallowdeduc', $tblValues); if ($value['allowdeductype'] == 1) { //allowance if ($value['mode'] == 1) { $sf = 1; $amount = $value['amount'] * $sf; $asubtotal = $amount; } else { $sf = 0.01; $amount = $value['amount'] * $sf; $asubtotal = $basicsalary * $amount; } $allowance+=$asubtotal; } else { if ($value['mode'] == 1) { $sf = 1; $amount = $value['amount'] * $sf; $dsubtotal = $amount; } else { $sf = 0.01; $amount = $value['amount'] * $sf; $dsubtotal = $basicsalary * $amount; } $deduction+=$dsubtotal; } } } $netpayment = $basicsalary + $allowance - $deduction; $tblValues = array('allowance' => $allowance, 'deduction' => $deduction, 'netpayment' => $netpayment, 'paidamount' => $netpayment); $this->db->where('id', $salid); $res = $this->db->update('emp_salary_slip', $tblValues); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } function getallowdeductdet($sid) { $data = array(); $res = $this->db->query("select mode,allowdeducid,amount,s.allowdeductype,chartgroup_name from allowdeduc a join staffsalaryallowdeduc s on s.allowdeducid=a.id where s.staffsalaryid='$sid' "); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function getallowdeductdetpayslip($sid) { $data = array(); $res = $this->db->query("select mode,allowdeducid,amount,s.allowdeductype,chartgroup_name from allowdeduc a join salarypaymentallowdeduc s on s.allowdeducid=a.id where s.salarypaymentid='$sid' "); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function loademployeesalary($post, $date) { $data = array(); $saldate = $this->mastermodel->convdatformat($date); $res = $this->db->query("SELECT es.id as esid,es.salary_date,employee_id,employeeid,name from emp_salary_slip es join staffpersonaldetails sp on sp.id=es.employee_id where month(salary_date)=month('$saldate') and unpost='$post' order by employee_id"); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function postsalarysettlement() { $this->db->trans_begin(); $settlementid = $_POST['emp_settlement_id']; $this->db->where('salarysettlementid', $settlementid); $this->db->delete('salarysettlementallowdeduc'); $this->db->where('salarysettlementid', $settlementid); $this->db->delete('emp_settlement_types'); $paymentdate = $this->mastermodel->convdatformat($_POST['date']); $relieving_date = $this->mastermodel->convdatformat($_POST['rel_date']); $netpayment = $_POST['basicsalary'] + $_POST['allowance'] - $_POST['deduction']; $basicsalary = $_POST['basicsalary']; $query1 = "update emp_settlement set employee_id='$_POST[employee_id]', relieving_date='$relieving_date', pay_date='$paymentdate', basic_salary='$_POST[basicsalary]', allowance='$_POST[allowance]', deduction='$_POST[deduction]', netpayment='$netpayment', currencytype='$_POST[currencytype]', paidamount='$netpayment', commission='$_POST[commission]', unpost=0 where id='$settlementid'"; $query = $this->db->query($query1); $memo = $_POST['memo']; $empaccount = $_POST['emp_account']; $acccode1 = $_POST['bankacc']; $acccode = explode('~', $acccode1); $bankcode = $acccode[1]; $bankid = $acccode[0]; $tra_cod = $this->customermodel->getSingleFieldValue('transaction_code', 'code', 'trans', 3); $reference = $this->accountingsmodel->get_reference_code('3'); $insertvals = array('type' => '3', 'reference' => $reference); // inserting values to refs table $this->db->insert('refs', $insertvals); $ref_id = $this->db->insert_id(); $fyear = $this->accountingsmodel->fiscalyear(); $insValuesA = array( 'trans_no' => $ref_id, 'user' => $_SESSION['userid'], 'date_trans' => $paymentdate, 'fiscal_year' => $fyear, 'gl_date' => $paymentdate ); $this->db->insert('audit_trail', $insValuesA); $x = 1; while (isset($_POST['allowvalue_' . $x])) { $coverid[$x] = $_POST['allowid_' . $x]; $newpol[$x] = $_POST['allowvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $allowaccount = $this->customermodel->getSingleFieldValue('allowdeduc', 'chartgroup_name', 'id', $coverid[$i]); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paymentdate, 'account' => $allowaccount, 'memo' => $memo, 'amount' => $newpol[$i]); $str = $this->db->insert('gl_trans', $tblValues); $sql = "insert into salarysettlementallowdeduc values('','$settlementid','$coverid[$i]','$newpol[$i]','1')"; $query = $this->db->query($sql); $x--; $i++; } $x = 1; while (isset($_POST['deducvalue_' . $x])) { $coverid[$x] = $_POST['deducid_' . $x]; $newpol[$x] = $_POST['deducvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $dedaccount = $this->customermodel->getSingleFieldValue('allowdeduc', 'chartgroup_name', 'id', $coverid[$i]); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paymentdate, 'account' => $dedaccount, 'memo' => $memo, 'amount' => -$newpol[$i]); $str = $this->db->insert('gl_trans', $tblValues); $sql = "insert into salarysettlementallowdeduc values('','$settlementid','$coverid[$i]','$newpol[$i]','0')"; $query = $this->db->query($sql); $x--; $i++; } if (isset($_POST['settlement_type'])) { foreach ($_POST['settlement_type'] as $key) { $type = $key; $amount = $_POST['amount_' . $key]; $settlement_account = $this->customermodel->getSingleFieldValue('settlement_types', 'chartgroup_name', 'id', $type); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paymentdate, 'account' => $settlement_account, 'memo' => $memo, 'amount' => $amount); $str = $this->db->insert('gl_trans', $tblValues); $query = $this->db->query("insert into emp_settlement_types values('','$settlementid','$type','$amount')"); } } // $k = 1; // while (isset($_POST['txt_conType_' . $k]) && isset($_POST['txt_conAmount_' . $k])) { // $type = $_POST['txt_conType_' . $k]; // $amount = $_POST['txt_conAmount_' . $k]; // $query = $this->db->query("insert into emp_settlement_types values('','$settlementid','$type','$amount')"); // $k++; // } $famount = $netpayment; $tblValues = array('type_no' => $ref_id, 'tran_date' => $paymentdate, 'account' => $empaccount, 'memo' => $memo, 'amount' => -$famount); $str = $this->db->insert('gl_trans', $tblValues); // // $tblValues=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>-$commissionamount); // $str= $this->db->insert('gl_trans', $tblValues); $tblValuescu = array('type_no' => $ref_id, 'tran_date' => $paymentdate, 'account' => $empaccount, 'memo' => $memo, 'amount' => -$famount); $str = $this->db->insert('agent_trans', $tblValuescu); // $tblValuescu=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>-$commissionamount); // $str= $this->db->insert('agent_trans', $tblValuescu); // $commission_acc = $this->documentsmodel->get_commission_pay_acc(); $accsett = $this->accountingsmodel->Getsubacc_settings(); $salary1 = $accsett->row()->salary; $salary = $this->customermodel->getSingleFieldValue('chart_master', 'account_code', 'id', $salary1); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paymentdate, 'account' => $salary, 'memo' => $memo, 'amount' => $basicsalary); $str = $this->db->insert('gl_trans', $tblValues); // if (!empty($commissionamount)) { // $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $commission_acc, 'memo' => 'Commission Paid', 'amount' => $commissionamount); // $str = $this->db->insert('gl_trans', $tblValues); // } /* Second transaction */ $tra_cod = $this->customermodel->getSingleFieldValue('transaction_code', 'code', 'trans', 1); $reference = $this->accountingsmodel->get_reference_code('1'); $insertvals = array('type' => '1', 'reference' => $reference); // inserting values to refs table $this->db->insert('refs', $insertvals); $ref_id = $this->db->insert_id(); $fyear = $this->accountingsmodel->fiscalyear(); $insValuesA = array( 'trans_no' => $ref_id, 'user' => $_SESSION['userid'], 'date_trans' => $paymentdate, 'fiscal_year' => $fyear, 'gl_date' => $paymentdate ); $this->db->insert('audit_trail', $insValuesA); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paymentdate, 'account' => $empaccount, 'memo' => $memo, 'amount' => $famount); $str = $this->db->insert('gl_trans', $tblValues); // $tblValues=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>$commissionamount); // $str= $this->db->insert('gl_trans', $tblValues); $tblValuescu = array('type_no' => $ref_id, 'tran_date' => $paymentdate, 'account' => $empaccount, 'memo' => $memo, 'amount' => $famount); $str = $this->db->insert('agent_trans', $tblValuescu); // $tblValuescu=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>$commissionamount); // $str= $this->db->insert('agent_trans', $tblValuescu); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paymentdate, 'account' => $bankcode, 'memo' => $memo, 'amount' => -$famount); $str = $this->db->insert('gl_trans', $tblValues); // $tblValues=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$bankcode,'memo'=>'Commission Paid','amount'=>-$commissionamount); // $str= $this->db->insert('gl_trans', $tblValues); $tblValues3 = array('trans_no' => $ref_id, 'bank_act' => $bankid, 'ref' => $reference, 'trans_date' => $paymentdate, 'amount' => -$famount, 'reconciled' => ''); $query = $this->db->insert('bank_trans', $tblValues3); // $tblValues3=array('trans_no'=>$ref_id,'bank_act'=>$bankid,'ref'=>$reference,'trans_date'=>$paydate,'amount'=>-$commissionamount,'reconciled'=>''); // $query= $this->db->insert('bank_trans', $tblValues3); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } function postsalarypayment() { $this->db->trans_begin(); $salid = $_POST['staffsalaryid']; $this->db->query("delete from emp_salary_slip where id = '$salid'"); $this->db->query("delete from salarypaymentallowdeduc where salarypaymentid = '$salid'"); $paydate = date('Y-m-d'); $salarydate = $_POST['salarydate']; $netpayment = $_POST['basicsalary'] + $_POST['allowance'] - $_POST['deduction']; $basicsalary = $_POST['basicsalary']; $commissionamount = $_POST['commission']; $query1 = "insert into emp_salary_slip (employee_id,salary_date,pay_date,basic_salary,allowance,deduction,netpayment,currencytype,paidamount,unpost,commission) values('$_POST[staff_id]','$salarydate','$paydate','$_POST[basicsalary]','$_POST[allowance]','$_POST[deduction]','$netpayment','$_POST[currencytype]','$_POST[payamount]',0,'$_POST[commission]')"; $query = $this->db->query($query1); $salid = mysql_insert_id(); $memo = $_POST['memo']; $empaccount = $_POST['emp_account']; $acccode1 = $_POST['bankacc']; $acccode = explode('~', $acccode1); $bankcode = $acccode[1]; $bankid = $acccode[0]; $tra_cod = $this->customermodel->getSingleFieldValue('transaction_code', 'code', 'trans', 3); $reference = $this->accountingsmodel->get_reference_code('3'); $insertvals = array('type' => '3', 'reference' => $reference); // inserting values to refs table $this->db->insert('refs', $insertvals); $ref_id = $this->db->insert_id(); $fyear = $this->accountingsmodel->fiscalyear(); $insValuesA = array( 'trans_no' => $ref_id, 'user' => $_SESSION['userid'], 'date_trans' => $paydate, 'fiscal_year' => $fyear, 'gl_date' => $paydate ); $this->db->insert('audit_trail', $insValuesA); $x = 1; while (isset($_POST['allowvalue_' . $x])) { $coverid[$x] = $_POST['allowid_' . $x]; $newpol[$x] = $_POST['allowvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $allowaccount = $this->customermodel->getSingleFieldValue('allowdeduc', 'chartgroup_name', 'id', $coverid[$i]); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $allowaccount, 'memo' => $memo, 'amount' => $newpol[$i]); $str = $this->db->insert('gl_trans', $tblValues); $sql = "insert into salarypaymentallowdeduc values('','$salid','$coverid[$i]','$newpol[$i]','1')"; $query = $this->db->query($sql); $x--; $i++; } $x = 1; while (isset($_POST['deducvalue_' . $x])) { $coverid[$x] = $_POST['deducid_' . $x]; $newpol[$x] = $_POST['deducvalue_' . $x]; $x++; } $i = 1; while ($x != 1) { $dedaccount = $this->customermodel->getSingleFieldValue('allowdeduc', 'chartgroup_name', 'id', $coverid[$i]); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $dedaccount, 'memo' => $memo, 'amount' => -$newpol[$i]); $str = $this->db->insert('gl_trans', $tblValues); $query = $this->db->query("insert into salarypaymentallowdeduc values('','$salid','$coverid[$i]','$newpol[$i]','0')"); $x--; $i++; } $famount = $netpayment + $commissionamount; $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $empaccount, 'memo' => $memo, 'amount' => -$famount); $str = $this->db->insert('gl_trans', $tblValues); // // $tblValues=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>-$commissionamount); // $str= $this->db->insert('gl_trans', $tblValues); $tblValuescu = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $empaccount, 'memo' => $memo, 'amount' => -$famount); $str = $this->db->insert('agent_trans', $tblValuescu); // $tblValuescu=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>-$commissionamount); // $str= $this->db->insert('agent_trans', $tblValuescu); $commission_acc = $this->documentsmodel->get_commission_pay_acc(); $accsett = $this->accountingsmodel->Getsubacc_settings(); $salary1 = $accsett->row()->salary; $salary = $this->customermodel->getSingleFieldValue('chart_master', 'account_code', 'id', $salary1); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $salary, 'memo' => $memo, 'amount' => $basicsalary); $str = $this->db->insert('gl_trans', $tblValues); if (!empty($commissionamount)) { $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $commission_acc, 'memo' => 'Commission Paid', 'amount' => $commissionamount); $str = $this->db->insert('gl_trans', $tblValues); } /* Second transaction */ $tra_cod = $this->customermodel->getSingleFieldValue('transaction_code', 'code', 'trans', 1); $reference = $this->accountingsmodel->get_reference_code('1'); $insertvals = array('type' => '1', 'reference' => $reference); // inserting values to refs table $this->db->insert('refs', $insertvals); $ref_id = $this->db->insert_id(); $fyear = $this->accountingsmodel->fiscalyear(); $insValuesA = array( 'trans_no' => $ref_id, 'user' => $_SESSION['userid'], 'date_trans' => $paydate, 'fiscal_year' => $fyear, 'gl_date' => $paydate ); $this->db->insert('audit_trail', $insValuesA); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $empaccount, 'memo' => $memo, 'amount' => $famount); $str = $this->db->insert('gl_trans', $tblValues); // $tblValues=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>$commissionamount); // $str= $this->db->insert('gl_trans', $tblValues); $tblValuescu = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $empaccount, 'memo' => $memo, 'amount' => $famount); $str = $this->db->insert('agent_trans', $tblValuescu); // $tblValuescu=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>$commissionamount); // $str= $this->db->insert('agent_trans', $tblValuescu); $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $bankcode, 'memo' => $memo, 'amount' => -$famount); $str = $this->db->insert('gl_trans', $tblValues); // $tblValues=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$bankcode,'memo'=>'Commission Paid','amount'=>-$commissionamount); // $str= $this->db->insert('gl_trans', $tblValues); $tblValues3 = array('trans_no' => $ref_id, 'bank_act' => $bankid, 'ref' => $reference, 'trans_date' => $paydate, 'amount' => -$famount, 'reconciled' => ''); $query = $this->db->insert('bank_trans', $tblValues3); // $tblValues3=array('trans_no'=>$ref_id,'bank_act'=>$bankid,'ref'=>$reference,'trans_date'=>$paydate,'amount'=>-$commissionamount,'reconciled'=>''); // $query= $this->db->insert('bank_trans', $tblValues3); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } function multiplepostsalarypayment() { $this->db->trans_begin(); $saldate = $this->mastermodel->convdatformat($_POST['date']); $paydate = date('Y-m-d'); $memo = $_POST['memo']; $acccode1 = $_POST['bankacc']; $acccode = explode('~', $acccode1); $bankcode = $acccode[1]; $bankid = $acccode[0]; $bnkcount = 1; $bnkcount2 = 1; $salaryamount = 0; $salcommamount = 0; $all = array(); $trtype = 0; for ($i = 0; $i < sizeof($_POST['salempdet']); $i++) { if (isset($_POST['salempdet'][$i])) { $salid = $_POST['salempdet'][$i]; // echo $salid; $tblValues = array('unpost' => '0'); $this->db->where('id', $salid); $res = $this->db->update('emp_salary_slip', $tblValues); $salpay = $this->mastermodel->get_data_srow('emp_salary_slip', $salid, 'id'); $netpayment = $salpay->netpayment; $empid = $salpay->employee_id; $commissionamount = $salpay->commission; $basicsalary = $salpay->basic_salary; $empaccount = $this->customermodel->getSingleFieldValue('staffpersonaldetails', 'employeeid', 'id', $empid); $msalarymonth = date_parse_from_format("d-m-Y", $_POST['date']); $memo = "Salary payment/$empaccount for " . $msalarymonth['month'] . "/" . $msalarymonth['year']; $famount = $netpayment + $commissionamount; $staffsalpay = $this->get_sal_data('staffsalary', $empid, $_POST['date']); $paymethod = $staffsalpay->paymethod; if ($paymethod == 'bank') { $salaryamount+=$basicsalary; $salcommamount+=$famount; if ($bnkcount == 1) { $tra_cod = $this->customermodel->getSingleFieldValue('transaction_code', 'code', 'trans', 3); $reference = $this->accountingsmodel->get_reference_code('3'); $bnkreferencejv = $reference; $insertvals = array('type' => '3', 'reference' => $reference); // inserting values to refs table $this->db->insert('refs', $insertvals); $ref_id = $this->db->insert_id(); $bankref_idjv = $ref_id; $fyear = $this->accountingsmodel->fiscalyear(); $insValuesA = array( 'trans_no' => $ref_id, 'user' => $_SESSION['userid'], 'date_trans' => $paydate, 'fiscal_year' => $fyear, 'gl_date' => $paydate ); $this->db->insert('audit_trail', $insValuesA); } $referencebnkjv = $bnkreferencejv; $ref_idbnkjv = $bankref_idjv; $reference = $referencebnkjv; $ref_id = $ref_idbnkjv; $trtype = 1; } else if ($paymethod == 'cash' || $paymethod == 'cheque') { $tra_cod = $this->customermodel->getSingleFieldValue('transaction_code', 'code', 'trans', 3); $reference = $this->accountingsmodel->get_reference_code('3'); $insertvals = array('type' => '3', 'reference' => $reference); // inserting values to refs table $this->db->insert('refs', $insertvals); $ref_id = $this->db->insert_id(); $fyear = $this->accountingsmodel->fiscalyear(); $insValuesA = array( 'trans_no' => $ref_id, 'user' => $_SESSION['userid'], 'date_trans' => $paydate, 'fiscal_year' => $fyear, 'gl_date' => $paydate ); $this->db->insert('audit_trail', $insValuesA); } $allowded = $this->getallowdeductdetpayslip($salid); $allamt = 0; foreach ($allowded as $alld) { $alldtype = $alld['allowdeductype']; if ($paymethod == 'bank') { $alldamount = $alld['amount']; $alldaccount = $alld['chartgroup_name']; if (!isset($all[$alldaccount])) $all[$alldaccount][$alldtype] = $alld['amount']; else $all[$alldaccount][$alldtype] += $alld['amount']; // if(!array_key_exists($alldaccount, $all)) // { // $all[$alldaccount]=$alld['amount']; // } // else // { // $allamt+= $alld['amount']; // $all[$alldaccount]=$allamt; // } } else if ($paymethod == 'cash' || $paymethod == 'cheque') { if ($alld['allowdeductype'] == 0) { $alld['amount'] = 0 - $alld['amount']; } $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $alld['chartgroup_name'], 'memo' => $memo, 'amount' => $alld['amount']); $str = $this->db->insert('gl_trans', $tblValues); } } $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $empaccount, 'memo' => $memo, 'amount' => -$famount); $str = $this->db->insert('gl_trans', $tblValues); // $tblValues=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>-$commissionamount); // $str= $this->db->insert('gl_trans', $tblValues); $tblValuescu = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $empaccount, 'memo' => $memo, 'amount' => -$famount); $str = $this->db->insert('agent_trans', $tblValuescu); // $tblValuescu=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>-$commissionamount); // $str= $this->db->insert('agent_trans', $tblValuescu); $commission_acc = $this->documentsmodel->get_commission_pay_acc(); $accsett = $this->accountingsmodel->Getsubacc_settings(); $salary1 = $accsett->row()->salary; $salary = $this->customermodel->getSingleFieldValue('chart_master', 'account_code', 'id', $salary1); if ($paymethod != 'bank') { $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $salary, 'memo' => $memo, 'amount' => $basicsalary); $str = $this->db->insert('gl_trans', $tblValues); } if ($commissionamount != 0) { $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $commission_acc, 'memo' => 'Commission Paid', 'amount' => $commissionamount); $str = $this->db->insert('gl_trans', $tblValues); } /* Second transaction */ if ($paymethod == 'bank') { if ($bnkcount == 1) { $tra_cod = $this->customermodel->getSingleFieldValue('transaction_code', 'code', 'trans', 1); $reference = $this->accountingsmodel->get_reference_code('1'); $bnkreferencepv = $reference; $insertvals = array('type' => '1', 'reference' => $reference); // inserting values to refs table $this->db->insert('refs', $insertvals); $ref_id = $this->db->insert_id(); $bankref_idpv = $ref_id; $fyear = $this->accountingsmodel->fiscalyear(); $insValuesA = array( 'trans_no' => $ref_id, 'user' => $_SESSION['userid'], 'date_trans' => $paydate, 'fiscal_year' => $fyear, 'gl_date' => $paydate ); $this->db->insert('audit_trail', $insValuesA); $bnkcount = 2; } $referencebnkpv = $bnkreferencepv; $ref_idbnkpv = $bankref_idpv; $reference = $referencebnkpv; $ref_id = $ref_idbnkpv; } else if ($paymethod == 'cash' || $paymethod == 'cheque') { $tra_cod = $this->customermodel->getSingleFieldValue('transaction_code', 'code', 'trans', 1); $reference = $this->accountingsmodel->get_reference_code('1'); $insertvals = array('type' => '1', 'reference' => $reference); // inserting values to refs table $this->db->insert('refs', $insertvals); $ref_id = $this->db->insert_id(); $fyear = $this->accountingsmodel->fiscalyear(); $insValuesA = array( 'trans_no' => $ref_id, 'user' => $_SESSION['userid'], 'date_trans' => $paydate, 'fiscal_year' => $fyear, 'gl_date' => $paydate ); $this->db->insert('audit_trail', $insValuesA); } $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $empaccount, 'memo' => $memo, 'amount' => $famount); $str = $this->db->insert('gl_trans', $tblValues); // $tblValues=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>$commissionamount); // $str= $this->db->insert('gl_trans', $tblValues); $tblValuescu = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $empaccount, 'memo' => $memo, 'amount' => $famount); $str = $this->db->insert('agent_trans', $tblValuescu); // $tblValuescu=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$empaccount,'memo'=>'Commission Paid','amount'=>$commissionamount); // $str= $this->db->insert('agent_trans', $tblValuescu); if ($paymethod != 'bank') { $tblValues = array('type_no' => $ref_id, 'tran_date' => $paydate, 'account' => $bankcode, 'memo' => $memo, 'amount' => -$famount); $str = $this->db->insert('gl_trans', $tblValues); } // $tblValues=array('type_no'=>$ref_id,'tran_date'=>$paydate,'account'=>$bankcode,'memo'=>'Commission Paid','amount'=>-$commissionamount); // $str= $this->db->insert('gl_trans', $tblValues); $tblValues3 = array('trans_no' => $ref_id, 'bank_act' => $bankid, 'ref' => $reference, 'trans_date' => $paydate, 'amount' => -$famount, 'reconciled' => ''); $query = $this->db->insert('bank_trans', $tblValues3); } } if ($trtype == 1) { $tblValues = array('type_no' => $ref_idbnkjv, 'tran_date' => $paydate, 'account' => $salary, 'memo' => $memo, 'amount' => $salaryamount); $str = $this->db->insert('gl_trans', $tblValues); $tblValues = array('type_no' => $ref_idbnkpv, 'tran_date' => $paydate, 'account' => $bankcode, 'memo' => $memo, 'amount' => -$salcommamount); $str = $this->db->insert('gl_trans', $tblValues); foreach ($all as $keyd => $valued) { foreach ($valued as $k => $vamount) { if ($k == 0) { $vamount = 0 - $vamount; } $tblValues = array('type_no' => $ref_idbnkjv, 'tran_date' => $paydate, 'account' => $keyd, 'memo' => $memo, 'amount' => $vamount); $str = $this->db->insert('gl_trans', $tblValues); } } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); return 1; } } function getmaxexpense() { $res = $this->db->query("SELECT max(`account_code`) as max FROM `chart_master` WHERE `chart_type`='3' and `account_code` like '30%'"); $row = $res->row(); return $row->max; } function addassignleave() { $fromdate = $date = $this->mastermodel->convdatformat($_POST['fromdate']); $todate = $date = $this->mastermodel->convdatformat($_POST['todate']); $userid = $_SESSION['userid']; $staffid = $this->customermodel->getSingleFieldValue('users', 'staff_id', 'id', $userid); if ($staffid != '') { $tblValues = array('staffid' => $staffid, 'fromdate' => $fromdate, 'todate' => $todate, 'type' => $_POST['type'], 'remarks' => $_POST['remarks'], 'leavestatus' => 'Pending'); $str = $this->db->insert('assignleave', $tblValues); } } function checkforappliedleave() { $userid = $_SESSION['userid']; $staffid = $this->customermodel->getSingleFieldValue('users', 'staff_id', 'id', $userid); $res = $this->db->query("SELECT * FROM `assignleave` a join staffemployeedetails s on a.staffid=s.staffid where s.reportingtostaffid='$staffid' and a.leavestatus='Pending'"); $count = $res->num_rows(); return $count; } function updateleavestatus() { $leavestatus = $_POST['leavestatus']; $id = $_POST['id']; $res = $this->db->query("update assignleave set leavestatus='$leavestatus' where id ='$id'"); if ($res > 0) { return 1; } else { return 0; } } function get_monthly_attendance_report() { $data = array(); $qry = "SELECT * FROM `staffemployeedetails` JOIN `department` on `department`.`id`=`staffemployeedetails`.`deptid` JOIN `designation` ON `designation`.`id` = `staffemployeedetails`.`designationid` JOIN `staffpersonaldetails` ON `staffemployeedetails`.`staffid` = `staffpersonaldetails`.`id` where `staffemployeedetails`.`device_no` !=''"; if ($_POST['employee_id'] != "") { $qry.=" and `staffpersonaldetails`.`id` = '" . $_POST['employee_id'] . "'"; } else { if ($_POST['department_id'] != "") $qry.=" and `department`.`id` = '" . $_POST['department_id'] . "'"; if ($_POST['designation_id'] != "") $qry.=" and `designation`.`id` = '" . $_POST['designation_id'] . "'"; } $qry.="order by `department`.`id`, `staffpersonaldetails`.`id` asc"; $res = $this->db->query($qry); if ($res->num_rows() > 0) { foreach ($res->result_array() as $row) { $data[] = $row; } } $res->free_result(); return $data; } function get_attendance_day($employee_device_id, $date) { $this->db->from('timesheet_attendance'); $this->db->like('attendance_date', $date); $this->db->where('employee_device_id', $employee_device_id); $num = $this->db->count_all_results(); $this->db->last_query(); return $num; } function get_employee_timesheet_report() { $ts = strtotime($_POST['month'] . " " . $_POST['year']); $from_date = date('Y-m-01', $ts); $to_date = date('Y-m-t', $ts); return $this->get_employee_attendance($_POST['employee_id'], $from_date, $to_date); } function get_time_day($employee_device_id, $date) { $qry = "SELECT * FROM `timesheet_attendance` where `employee_device_id` = '$employee_device_id' and attendance_date like '$date %' order by attendance_date asc"; $res = $this->db->query($qry); if ($res->num_rows() == 0) { return 0; } else { $flag = 0; $temp = 0; $hours = 0; $inmode = 0; $outmode = 0; foreach ($res->result_array() as $row) { if ($flag == 0) { if ($row['attendance_mode'] != 0) return -1; else { $temp = $row['attendance_date']; $inmode++; } } if ($flag == count($res->result_array()) - 1) { if ($row['attendance_mode'] != 1) { return -1; } else { $hours += round(abs(strtotime($row['attendance_date']) - strtotime($temp)) / 60 / 60, 2); $temp = 0; $outmode++; } } $flag++; } if ($inmode == $outmode) return $hours; else return -1; } } function get_late_day($employee_id, $employee_device_id, $date) { $this->db->where('timesheet_attendance.employee_device_id', $employee_device_id); $this->db->like('timesheet_attendance.attendance_date', $date); $this->db->where('timesheet_attendance.attendance_mode', '0'); $this->db->order_by('timesheet_attendance.attendance_date', 'asc'); $Q1 = $this->db->get('timesheet_attendance'); $row1 = $Q1->row(); if (empty($row1)) return ''; $this->db->where('timesheet_work_shift_employees.employee_id', $employee_id); $this->db->where('work_shift_wef_date <=', $date); $this->db->join('timesheet_work_shift_employees', 'timesheet_work_shift_employees.work_shift_id=timesheet_work_shift.work_shift_id'); $this->db->order_by('work_shift_wef_date', 'desc'); $Q = $this->db->get('timesheet_work_shift'); $row = $Q->row(); $to_time = strtotime($row1->attendance_date); $from_time = strtotime($date . " " . $row->work_shift_starting_time); if (round(abs($to_time - $from_time) / 60, 2) > $row->work_shift_grace_time) return round(abs($to_time - $from_time) / 60, 2); else return ''; } function get_employee_attendance_status($employee_id, $employee_device_id, $date, $attendance_mode) { if ($this->first_punch_in($employee_device_id, $date)) { $this->db->where('timesheet_work_shift_employees.employee_id', $employee_id); $this->db->where('work_shift_wef_date <=', substr($date, 0, 11)); $this->db->join('timesheet_work_shift_employees', 'timesheet_work_shift_employees.work_shift_id=timesheet_work_shift.work_shift_id'); $this->db->order_by('work_shift_wef_date', 'desc'); $Q = $this->db->get('timesheet_work_shift'); $row = $Q->row(); $to_time = strtotime($date); $from_time = strtotime(substr($date, 0, 11) . " " . $row->work_shift_starting_time); if (round(abs($to_time - $from_time) / 60, 2) > $row->work_shift_grace_time) return "Late In"; else return ''; } if ($this->last_punch_out($employee_device_id, $date)) { $this->db->where('timesheet_work_shift_employees.employee_id', $employee_id); $this->db->where('work_shift_wef_date <=', substr($date, 0, 11)); $this->db->join('timesheet_work_shift_employees', 'timesheet_work_shift_employees.work_shift_id=timesheet_work_shift.work_shift_id'); $this->db->order_by('work_shift_wef_date', 'desc'); $Q = $this->db->get('timesheet_work_shift'); $row = $Q->row(); $to_time = strtotime($date); $weekly_holidays = $this->mastermodel->getdatas('timesheet_weekly_holiday_half', 'weekly_holiday_id'); $holiday = array(); foreach ($weekly_holidays as $weekly) { $holiday[] = $weekly['weekly_holiday_half']; } if (in_array(date('l', strtotime($date)), $holiday)) $from_time = strtotime(substr($date, 0, 11) . " " . $row->work_shift_ending_time_half); else $from_time = strtotime(substr($date, 0, 11) . " " . $row->work_shift_ending_time); if ($to_time < $from_time) return "Early Out"; else return ''; } if ($attendance_mode == 2) { $this->db->where('timesheet_work_shift_employees.employee_id', $employee_id); $this->db->where('work_shift_wef_date <=', substr($date, 0, 11)); $this->db->join('timesheet_work_shift_employees', 'timesheet_work_shift_employees.work_shift_id=timesheet_work_shift.work_shift_id'); $this->db->order_by('work_shift_wef_date', 'desc'); $Q = $this->db->get('timesheet_work_shift'); $row = $Q->row(); $to_time = strtotime($date); $from_time = strtotime(substr($date, 0, 11) . " " . $row->work_shift_break_starting_time); if ($to_time < $from_time) return "Early Break Out"; else return ''; } if ($attendance_mode == 3) { $this->db->where('timesheet_work_shift_employees.employee_id', $employee_id); $this->db->where('work_shift_wef_date <=', substr($date, 0, 11)); $this->db->join('timesheet_work_shift_employees', 'timesheet_work_shift_employees.work_shift_id=timesheet_work_shift.work_shift_id'); $this->db->order_by('work_shift_wef_date', 'desc'); $Q = $this->db->get('timesheet_work_shift'); $row = $Q->row(); $to_time = strtotime($date); $from_time = strtotime(substr($date, 0, 11) . " " . $row->work_shift_break_ending_time); if ($to_time > $from_time) { if (round(abs($to_time - $from_time) / 60, 2) > $row->work_shift_grace_time) return "Late Break In"; else return ''; } else return ''; } } function first_punch_in($employee_device_id, $date) { $this->db->where('timesheet_attendance.employee_device_id', $employee_device_id); $this->db->like('timesheet_attendance.attendance_date', substr($date, 0, 11)); $this->db->where('timesheet_attendance.attendance_mode', '0'); $this->db->order_by('timesheet_attendance.attendance_date', 'asc'); $Q1 = $this->db->get('timesheet_attendance'); $row1 = $Q1->row(); if (!empty($row1) && $row1->attendance_date == $date) return 1; else return 0; } function last_punch_out($employee_device_id, $date) { $this->db->where('timesheet_attendance.employee_device_id', $employee_device_id); $this->db->like('timesheet_attendance.attendance_date', substr($date, 0, 11)); $this->db->where('timesheet_attendance.attendance_mode', '1'); $this->db->order_by('timesheet_attendance.attendance_date', 'desc'); $Q1 = $this->db->get('timesheet_attendance'); $row1 = $Q1->row(); if (!empty($row1) && $row1->attendance_date == $date) return 1; else return 0; } function get_punches($device_no, $date) { $data = array(); $date = $this->mastermodel->convertdateformat($date); $this->db->where('employee_device_id', $device_no); $this->db->like('timesheet_attendance.attendance_date', $date); $this->db->order_by('attendance_date', 'asc'); $Q = $this->db->get('timesheet_attendance'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_leave_day($employee_id, $date) { $this->db->select('*'); $this->db->join('leavetype', 'leavetype.id=assignleave.type'); $this->db->where("'" . $date . "' BETWEEN fromdate AND todate", NULL, FALSE); $this->db->where('leavestatus', "Approved"); $this->db->where('staffid', $employee_id); $Q = $this->db->get('assignleave'); if ($Q->num_rows() > 0) return $Q->row(); else return 0; } function is_special_holiday($date) { $this->db->from('holidays'); $this->db->where('start_date <=', $date); $this->db->where('end_date >=', $date); $num = $this->db->count_all_results(); $this->db->last_query(); return $num; } function unpostedpayslip($sal_id) { $this->db->select('*,emp_salary_slip.id as emp_salary_id'); $this->db->from('emp_salary_slip'); $this->db->join('staffpersonaldetails', 'staffpersonaldetails.id=emp_salary_slip.employee_id'); $this->db->join('staffemployeedetails', 'staffemployeedetails.staffid=emp_salary_slip.employee_id'); $this->db->join('department', 'department.id=staffemployeedetails.deptid'); $this->db->join('designation', 'designation.id=staffemployeedetails.designationid'); $this->db->where('emp_salary_slip.id', $sal_id); $Q = $this->db->get(); //echo $this->db->last_query(); // var_dump($Q->row()); return $Q->row(); } function get_data_allowdeduc($allowdeducttype, $salary_slip_id) { $data = array(); $this->db->where('salarypaymentallowdeduc.allowdeductype', $allowdeducttype); $this->db->where('salarypaymentid', $salary_slip_id); $this->db->join('allowdeduc', "allowdeduc.id=salarypaymentallowdeduc.allowdeducid"); $this->db->order_by('allowdeduccode', 'desc'); $Q = $this->db->get('salarypaymentallowdeduc'); // echo $this->db->last_query(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } } ?>