?
Current Path : /home1/savoy/public_html/savoyglobal.net/sibsmoved/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/public_html/savoyglobal.net/sibsmoved/system/application/models/settingsmodel.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 settingsmodel extends Model { function settingsmodel() { parent::Model(); $this->load->model('mastermodel'); $this->load->model('customermodel'); $this->load->model('accountingsmodel'); } function AddReminder() { $name = $this->input->post('remname'); $date = $this->input->post('remdt'); $description = $this->input->post('desc'); $before = $this->input->post('numbef'); $userid = $_SESSION['userid']; $date = $this->mastermodel->convertdateformat($this->input->post('remdt')); $tblValues = array('remind_name' => $name, 'remind_date' => $date, 'beforedt' => $before, 'description' => $description, 'userid' => $userid); $data = $this->db->insert('reminder', $tblValues); return $data; } function GetReminder($pageno, $field, $value = "") { $limit = (($pageno - 1) * 10); $data = array(); $curdate = date('Y-m-d'); $sql = "select * from reminder where userid =" . $_SESSION['userid'] . " and " . $field . " like '" . $value . "%' and remind_date >='$curdate' limit " . $limit . "," . 10; $res = $this->db->query($sql); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function Getschedule($pageno, $field, $value = "") { $limit = (($pageno - 1) * 10); $data = array(); $res = $this->db->query("select * from activities where " . $field . " like '" . $value . "%' limit " . $limit . "," . 10); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function searchschedule($pageno, $where) { $limit = (($pageno - 1) * 10); $data = array(); $que = "SELECT activities.amount , activities.beforedt , IFNULL(customer_corp_info.insured, customer_personal_ind.insured) as CustomerName , covers.cover , activities.date , activities.policy_id , activities.id ,policynote.policyno FROM customers LEFT JOIN customer_corp_info ON (customer_corp_info.customer_id = customers.id) LEFT JOIN customer_personal_ind ON (customer_personal_ind.customer_id = customers.id) INNER JOIN broking_slip ON (broking_slip.customer_id = customers.id) INNER JOIN covers ON (broking_slip.cover_id = covers.id) INNER JOIN policynote ON (policynote.quotation_ref = broking_slip.quotation_ref) INNER JOIN activities ON(policynote.id=activities.policy_id) $where limit " . $limit . "," . 10; // echo $que; $res = $this->db->query($que); $data = $res->result_array(); return $data; } function count_allsche($table, $where) { $que = "SELECT activities.amount , activities.beforedt , IFNULL(customer_corp_info.insured, customer_personal_ind.insured) as CustomerName , covers.cover , activities.date , activities.policy_id , activities.id ,policynote.policyno FROM customers LEFT JOIN customer_corp_info ON (customer_corp_info.customer_id = customers.id) LEFT JOIN customer_personal_ind ON (customer_personal_ind.customer_id = customers.id) INNER JOIN broking_slip ON (broking_slip.customer_id = customers.id) INNER JOIN covers ON (broking_slip.cover_id = covers.id) INNER JOIN policynote ON (policynote.quotation_ref = broking_slip.quotation_ref) INNER JOIN activities ON(policynote.id=activities.policy_id) $where "; // echo $que; $res = $this->db->query($que); $data = $res->num_rows(); // echo $data; return $data; } function Getevents($pageno, $field, $value = "") { $limit = (($pageno - 1) * 10); $data = array(); $qry = "SELECT * from events where userid =" . $_SESSION['userid'] . " and " . $field . " like '" . $value . "%' limit " . $limit . ",10"; $res = $this->db->query($qry); return $res->result_array(); } function Get_editreminder_data($id) { $res = $this->db->query("select * from reminder where id='" . $id . "'"); $result = $res->row(); return $res; } function Get_editschedule($id) { $res = $this->db->query("select * from activities where id='" . $id . "'"); $result = $res->row(); return $res; } function Get_activity_data($id) { $res = $this->db->query("select * from events where id='" . $id . "'"); $result = $res->row(); return $res; } function count_alls($table, $field, $value = "") { $res = $this->db->query("select * from " . $table . " where " . $field . " like '" . $value . "%'"); return $res->num_rows(); } function updatereminder() { $name = $this->input->post('remname'); $date = $this->mastermodel->convertdateformat($this->input->post('remdt')); $descp = $this->input->post('desc'); $before = $this->input->post('numbef'); $id = $this->input->post('id'); $res = $this->db->query("update reminder set remind_name='" . $name . "',remind_date='" . $date . "',beforedt='" . $before . "',description='" . $descp . "' where id='" . $id . "'"); } function updateschedule() { $date = $this->input->post('date'); $amount = $this->input->post('amount'); $before = $this->input->post('before'); $pid = $this->input->post('pid'); $id = $this->input->post('id'); $res = $this->db->query("update activities set policy_id='" . $pid . "',date='" . $date . "',amount='" . $amount . "',beforedt='" . $before . "' where id='" . $id . "'"); } function updateevents() { $eventname = $this->input->post('eventname'); $description = $this->input->post('description'); $location = $this->input->post('location'); $status = $this->input->post('status'); $before = $this->input->post('before'); $priority = $this->input->post('priority'); $startdate = $this->input->post('startdate'); $enddate = $this->input->post('enddate'); $id = $this->input->post('id'); $remark = $this->input->post('remark'); $res = $this->db->query("update events set eventname='" . $eventname . "',alert='" . $before . "',description='" . $description . "',location='" . $location . "',status='" . $status . "',priority='" . $priority . "',startdate='" . $startdate . "',enddate='" . $enddate . "',remark='" . $remark . "' where id='" . $id . "'"); } function getmaxminlist($currentpage, $noofpages, $nooflists) { $this->load->library('Fpaginate'); $data['listnos'] = $this->fpaginate->paginate($currentpage, $noofpages, $nooflists); return $data; } function deletereminder($table, $id) { $res = $this->db->delete($table, array('id' => $id)); if ($res > 0) { return 1; } else { return 0; } } function Addschedule() { $date = $this->input->post('date'); $before = $this->input->post('before'); $amount = $this->input->post('amount'); $pid = $this->input->post('pid'); $tblValues = array('policy_id' => $pid, 'date' => $date, 'beforedt' => $before, 'amount' => $amount); $data = $this->db->insert('activities', $tblValues); return $data; } function Addevents() { $eventname = $this->input->post('eventname'); $description = $this->input->post('description'); $location = $this->input->post('location'); $status = $this->input->post('status'); $asign = $this->input->post('asign'); $priority = $this->input->post('priority'); $startdate = $this->input->post('startdate'); $enddate = $this->input->post('enddate'); $remark = $this->input->post('remark'); $before = $this->input->post('before'); $userid = $_SESSION['userid']; $tblValues = array('eventname' => $eventname, 'description' => $description, 'location' => $location, 'status' => $status, 'userid' => $userid, 'priority' => $priority, 'startdate' => $startdate, 'enddate' => $enddate, 'alert' => $before, 'remark' => $remark); $data = $this->db->insert('events', $tblValues); return $data; } function buildMenu($moduleid) { $user_id = $_SESSION['userid']; $data = array(); $Q = $this->db->query("select * from menu where module_id='" . $moduleid . "' order by sort"); $P = $this->db->query("select permission from users where id='" . $user_id . "'"); $result = $P->row(); $permission = explode(',', $result->permission); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { if (in_array($row['menu_id'], $permission)) { $data[] = $row; } } } $Q->free_result(); return $data; } function permissionList() { $permission = array(); $user_id = $_SESSION['userid']; $P = $this->db->query("select permission from users where id='" . $user_id . "'"); $result = $P->row(); $permission = explode(',', $result->permission); return $permission; } function homePermissionLIst() { $permission = array(); $user_id = $_SESSION['userid']; $P = $this->db->query("select home from users where id='" . $user_id . "'"); $result = $P->row(); $permission = explode(',', $result->home); return $permission; } function buildModule() { $flag = 0; $homemodel = 0; $data = array(); $P = $this->db->query("select permission from users where id='" . $_SESSION['userid'] . "'"); $result = $P->row(); $permission = explode(',', $result->permission); $Q = $this->db->query("select * from modules order by sort"); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $R = $this->db->query("select * from menu where module_id='" . $row['module_id'] . "'"); foreach ($R->result_array() as $menu) { if (in_array($menu['menu_id'], $permission)) { $flag = 1; } } if ($homemodel == 0) { $data[] = $row; $homemodel = 1; } if ($flag == 1) { $data[] = $row; $flag = 0; } else { $flag = 0; } } } $Q->free_result(); return $data; } function insertrolemodel() { $role = $this->input->post('txtrolename'); $permission = $this->input->post('Chk_Permission'); $read_permission = $this->input->post('combine'); $privatepermission = $this->input->post('private'); $homepermission = $this->input->post('home'); $privatepermission = array_filter($privatepermission); $private = implode(',', $privatepermission); $home = implode(',', $homepermission); $read_permission = array_filter($read_permission); $overall = implode(',', $read_permission); $allowed = implode(',', $permission); $res = $this->db->query("select * from user_roles where name= '$role'"); $count = $res->num_rows(); if ($count == 0) { $tblValues = array('name' => $role, 'permission' => $allowed, 'edit_del_permission' => $overall, 'private' => $private,'home'=>$home); $this->db->insert('user_roles', $tblValues); echo "Role Inserted Sucessfully"; } else { echo "Profile Name Already Exist"; } } function getrolelist() { $data = array(); $result = $this->db->query("select id,name from user_roles"); foreach ($result->result_array() as $row) { $data[] = $row; } return $data; } function getSingleFieldValue($table, $field, $condition, $value) { //echo "select ". $field. " from ". $table . " where ". $condition . "='". $value ."'"; $data = $this->db->query("select " . $field . " from " . $table . " where " . $condition . "='" . $value . "'"); $result = $data->row(); if ($result) { return $result->$field; } else { return ""; } } function getstafflist() { $data = array(); $result = $this->db->query("select * from staffpersonaldetails"); foreach ($result->result_array() as $row) { $data[] = $row; } return $data; } function ListUsersModel() { $data = array(); $result = $this->db->query("select * from users"); foreach ($result->result_array() as $row) { $data[] = $row; } return $data; } function ListUsersSearchModel($searchoption, $value = "") { $data = array(); $tablefield = explode("~", $searchoption); if ($tablefield[0] == 'users') { $result = $this->db->query("select * from users where username like'$value%'"); } else { $result = $this->db->query("select * from users inner join staffpersonaldetails on staffpersonaldetails.id = users.staff_id where staffpersonaldetails.name like'$value%'"); } foreach ($result->result_array() as $row) { $data[] = $row; } return $data; } function getSingleField($table, $field, $condition, $value) { //echo "select ". $field. " from ". $table . " where ". $condition . "='". $value ."'"; $data = $this->db->query("select " . $field . " from " . $table . " where " . $condition . "='" . $value . "'"); $result = $data->row(); if ($result) { return $result->$field; } else { return ""; } } function GetSingleUserModel($id) { $data = array(); $result = $this->db->query("select * from users where id='" . $id . "'"); $data = $result->row(); return $data; } function GetSingleRoleModel($id) { $data = array(); $result = $this->db->query("select * from user_roles where id='" . $id . "'"); $data = $result->row(); return $data; } function GetSingleRoleByUserIdModel($id) { $data = array(); $result = $this->db->query("select * from users where id='" . $id . "'"); $data = $result->row(); return $data; } function InsertUsersModel() { $username = $this->input->post('uname'); $password = $this->input->post('pword'); $repassword = $this->input->post('repassword'); $password = md5($password); $repassword = md5($repassword); $role = $this->input->post('role'); $staffid = $this->input->post('EmpId'); $permission = $this->input->post('Chk_Permission'); $read_permission = $this->input->post('combine'); $privatepermission = $this->input->post('private'); $privatepermission = array_filter($privatepermission); $private = implode(',', $privatepermission); $read_permission = array_filter($read_permission); $overall = implode(',', $read_permission); $commaseperated = implode(',', $permission); $res = $this->db->query("select * from users where username= '$username'"); $count = $res->num_rows(); if ($count == 0) { if ($username != "" && $password != "" && $repassword == $password && $role != "" && $staffid != "") { $tblValues = array('username' => $username, 'password' => $password, 'role_id' => $role, 'staff_id' => $staffid, 'permission' => $commaseperated, 'edit_del_permission' => $overall, 'private' => $private); $this->db->insert('users', $tblValues); $userid=$this->db->insert_id(); $report_perissions = array(); if(isset($_POST['report_perissions'])) $report_perissions=$_POST['report_perissions']; foreach ($report_perissions as $value) { $report_id=$value[0]; $newtblvalues=array('user_id'=>$userid, 'report_id'=>$report_id); $this->db->insert('report_list_permission',$newtblvalues); } echo "Insert Successfully"; } else { echo "fill all the fields"; } } else { echo "User name already exists"; } } function GetRepotPermissionByUserIdModel($userid) { $this->db->select('report_id') ->from('report_list_permission') ->where('user_id',$userid); $result= $this->db->get(); return $result->result_array(); } function UpdateUsersModel() { $oldpassword = $this->input->post('oldpassword'); $uid = $this->input->post('uid'); $username = $this->input->post('uname'); $role = $this->input->post('role'); $staffid = $this->input->post('EmpId'); $permission = $this->input->post('Chk_Permission'); $read_permission = $this->input->post('combine'); $privatepermission = $this->input->post('private'); $privatepermission = array_filter($privatepermission); $private = implode(',', $privatepermission); $homepermission=$this->input->post('home'); $homepermission = array_filter($homepermission); $home = implode(',', $homepermission); $read_permission = array_filter($read_permission); $overall = implode(',', $read_permission); $commaseperated = implode(',', $permission); $tblValues = array('username' => $username, 'role_id' => $role, 'staff_id' => $staffid, 'permission' => $commaseperated, 'edit_del_permission' => $overall, 'private' => $private ,'home' => $home); $this->db->where('id', $uid); $this->db->update('users', $tblValues); $this->db->where('user_id',$uid); $this->db->delete('report_list_permission'); $report_perissions = array(); if(isset($_POST['report_perissions'])) $report_perissions=$_POST['report_perissions']; foreach ($report_perissions as $value) { $report_id=$value; $newtblvalues=array('user_id'=>$uid, 'report_id'=>$report_id); $this->db->insert('report_list_permission',$newtblvalues); } echo "Updated Sucessfully"; } function change_Pass_Model($uid, $oldpass, $newpass) { $oldpass = md5($oldpass); $newpass = md5($newpass); if ($this->getSingleFieldValue('users', 'password', 'id', $uid) == $oldpass) { $tblValues = array('password' => $newpass); $this->db->where('id', $uid); $this->db->update('users', $tblValues); echo "Password Changed Sucessfully"; } else { echo "Invalide Password"; } } function change_Pass_Without_old_Model($uid, $newpass) { $newpass = md5($newpass); $tblValues = array('password' => $newpass); $this->db->where('id', $uid); $this->db->update('users', $tblValues); echo "Password Changed Sucessfully"; } function UpdateRoleModel() { $roleid = $this->input->post('editRoleId'); $permission = $this->input->post('Chk_Permission'); $read_permission = $this->input->post('combine'); $privatepermission = $this->input->post('private'); $privatepermission = array_filter($privatepermission); $private = implode(',', $privatepermission); $homepermission=$this->input->post('home'); $homepermission = array_filter($homepermission); $home = implode(',', $homepermission); $read_permission = array_filter($read_permission); $overall = implode(',', $read_permission); $allowed = implode(',', $permission); $tblValues = array('permission' => $allowed, 'edit_del_permission' => $overall, 'private' => $private, 'home' => $home); $this->db->where('id', $roleid); $this->db->update('user_roles', $tblValues); $tblValues_u = array('permission' => $allowed, 'edit_del_permission' => $overall, 'private' => $private, 'home' => $home); $this->db->where('role_id', $roleid); $this->db->update('users', $tblValues_u); echo "Updated Sucessfully"; } function delete_user_model($id) { $this->db->query("delete from users where id='" . $id . "'"); } function delete_role_model($id) { $res = $this->db->query("select * from users where role_id= '$id '"); $count = $res->num_rows(); if ($count == 0) { $this->db->query("delete from user_roles where id='" . $id . "'"); } } function ListRolesModel() { $data = array(); $result = $this->db->query("select * from user_roles"); foreach ($result->result_array() as $row) { $data[] = $row; } return $data; } function SearchRolesModel($value) { $data = array(); $qry = "select id from designation where designation like'$value%'"; $result = $this->db->query("select * from user_roles where name in ($qry)"); foreach ($result->result_array() as $row) { $data[] = $row; } return $data; } function GetCurrency($pageno, $field, $value = "") { $limit = (($pageno - 1) * 10); $data = array(); $res = $this->db->query("select * from country where " . $field . " like '" . $value . "%' limit " . $limit . "," . 10); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function GetCurrencyId() { $res = $this->db->query("select * from default_currency"); return $res; } function updatecurrency($id) { $res = $this->db->query("select * from default_currency"); $count = $res->num_rows(); if ($count == 0) { $this->db->query("insert into default_currency values ('$id')"); } else { $this->db->query("update default_currency set currency_id='$id'"); } } function Getuserlist() { $this->db->query("select * from users"); return $this; } function profileget($eid) { //echo "SELECT u.id FROM user_roles u join designation d on u.name=d.id join staffemployeedetails s on s.designationid=d.id where s.staffid=$eid"; $res = $this->db->query("SELECT u.id FROM user_roles u join designation d on u.name=d.id join staffemployeedetails s on s.designationid=d.id where s.staffid=$eid"); $data = $result->row(); return $res; } function GetRolefromCid($id) { $data = array(); $result = $this->db->query("select * from user_roles where name='" . $id . "'"); $data = $result->row(); return $data; } function Getfiscal($pageno, $field, $value = "") { $limit = (($pageno - 1) * 10); $data = array(); $qry = "SELECT * from fiscal_year where " . $field . " like '" . $value . "%' limit " . $limit . ",10"; $res = $this->db->query($qry); return $res->result_array(); } function Addfiscal() { $startdate = $this->input->post('startdate'); $enddate = $this->input->post('enddate'); $close = $this->input->post('close'); $startdate = $this->mastermodel->convdatformat($startdate); $enddate = $this->mastermodel->convdatformat($enddate); $tblValues = array('begin' => $startdate, 'end' => $enddate, 'closed' => $close); $data = $this->db->insert('fiscal_year', $tblValues); return $data; } function profitlosscalc($type, $fid) { $this->db->select('sum(gl_trans.amount) as amount'); $this->db->from('chart_master'); $this->db->join('gl_trans', 'chart_master.account_code = gl_trans.account'); $this->db->join('char_type', 'char_type.id = chart_master.chart_type'); $this->db->join('audit_trail', 'audit_trail.trans_no=gl_trans.type_no'); $this->db->where('char_type.chart_types', $type); $this->db->where('audit_trail.fiscal_year', $fid); $bg = $this->db->get(); $amt = $bg->row()->amount; return $amt; } function validatefiscaldate($sdate, $enddate) { $sdate = $this->mastermodel->convdatformat($sdate); $enddate = $this->mastermodel->convdatformat($enddate); // $qry="select * from fiscal_year where begin between '$sdate' and '$enddate' or end between '$sdate' and '$enddate'"; $qry = "select * from fiscal_year where end >= '$sdate' "; $res = $this->db->query($qry); $data = $res->num_rows(); echo $data; // $s_date=explode('-', $sdate); // $limit_1= $s_date[2].'-01-01'; // $limit_2= $s_date[2].'-12-31'; // $sdate = $this->mastermodel->convdatformat($sdate); // $qry="select * from fiscal_year where begin between '".$limit_1."' and '".$limit_2."'"; // $res=$this->db->query($qry); // $data=$res->num_rows(); // echo $data; } function Get_fiscal_data($id) { $res = $this->db->query("select * from fiscal_year where id='" . $id . "'"); // $result= $res->row(); return $res; } function deletefyear($table, $id) { $res = $this->db->query("select * from fiscal_year where id<'" . $id . "'"); $data = $res->num_rows(); if ($data == 0) { $back = $this->db->query("delete from fiscal_year where id='" . $id . "'"); echo $back; } else { echo 0; } } function Getmainacc_settings($what) { $data = array(); $res = $this->db->query("select * from mainacc_setting"); if ($what == 'data') { return $res; } else { return $res->num_rows(); } } function add_mainacc_settings() { $commission = $this->input->post('commission'); $cstart = $this->input->post('covercode'); $tblValues = array('commission_pay_acc' => $commission, 'cover_start' => $cstart); $data = $this->db->insert('mainacc_setting', $tblValues); return $data; } function updatemainacc_settings() { $commission = $this->input->post('commission'); $cstart = $this->input->post('covercode'); $id = $this->input->post('id'); $tblValues = array('commission_pay_acc' => $commission, 'cover_start' => $cstart); $this->db->where('id', $id); $res = $this->db->update('mainacc_setting', $tblValues); return $res; } function deletetabledata($table, $field, $id) { $this->db->where($field, $id); $this->db->delete($table); } function chekunpostedtransaction() { $data = array(); $qry = "SELECT count(*) as count FROM unposted_pay_dep where unpost =0"; $res = $this->db->query($qry); $data = $res->row()->count; if ($data == 0) { $qry = "SELECT count(*) as count FROM unposted_journal where unpost =0"; $res = $this->db->query($qry); $data = $res->row()->count; } return $data; } } ?>