?
Current Path : /home1/savoy/public_html/savoyglobal.net/rms/application/models/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/rms/application/models/mastermodel.php |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Mastermodel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); } /*Common function starts here*/ function authenticate($user_name,$password) { $data=array(); $ip=$this->input->post('ip'); $logintime=$today = date("Y-m-d H:i:s"); $password1=md5($password); $query= $this->db->query("select * from user where user_name='$user_name' and password='$password1'"); $data['numrows']=$query->num_rows(); if($query->num_rows()>0) { $lastid= $this->get_single_value('login_details','id','user_name',$user_name); $result= $query->row(); $data['user_id']= $result->user_id; $data['user_name']=$user_name; $data['clogintime']=$logintime; $data['lastid']=$lastid; $query1= $this->db->query("select * from login_details where user_name='$user_name' and id>='$lastid'"); $data['attempt']=($query1->num_rows())-1; $tblValues=array('user_name'=>$user_name,'password'=>$password1,'login_time '=>$logintime,'user_id '=>$result->user_id,'ip_address '=>$ip,'status '=>'Success'); $this->db->insert('login_details', $tblValues); } else { $tblValues=array('user_name'=>$user_name,'password'=>$password,'login_time '=>$logintime,'user_id '=>'','failing_time '=>$logintime,'ip_address '=>$ip,'status '=>'failed'); $this->db->insert('login_details', $tblValues); } return $data; } function getenumvalues($table, $column) { $sql = "SHOW COLUMNS FROM $table LIKE '$column'"; $result = mysql_query($sql); if ($result) { $enum = mysql_fetch_object($result); preg_match_all("/'([\w ]*)'/", $enum->Type, $values); $data['val'] = $values[1]; return $data; } else { die("Unable to fetch enum values: ".mysql_error()); } } function get_num_rows($table,$field='',$id='') { if($field!='') $this->db->where($field,$id); $Q=$this->db->get($table); return $Q->num_rows(); } function getdistinctfield($field,$table,$sortfield="") { $data = array(); $this->db->distinct(); $this->db->select($field); if(!empty ($sortfield)) { $this->db->order_by($sortfield, "asc"); } $Q = $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function convdatformat($xdate) { $mydate = explode('-',$xdate); if(sizeof($mydate)>2) return $mydate[2]."-".$mydate[1]."-".$mydate[0]; else if(sizeof($mydate)>1) return $mydate[1]."-".$mydate[0]; else return $mydate[0]; } function number_rows($tabname,$field1='',$value1='',$field2='',$value2='',$field3='',$value3='',$primary_field='') { $this->db->from($tabname); if($primary_field != '') { $this->db->join('master',"master.master_id=$tabname.$primary_field"); $this->db->where('login_type_id',$_SESSION['login_type']); } if($field1 !='') $this->db->where($field1,$value1); if($field2 !='') $this->db->where($field2,$value2); if($field3 !='') $this->db->where($field3,$value3); $num = $this->db->count_all_results(); return $num; } function get_single_value($table,$field,$condition,$value) { $data=$this->db->query("select max(". $field. ") as ".$field." from ". $table . " where ". $condition . "='". $value ."' and status='Success'"); $result= $data->row(); if($result) { return $result->$field; } else { return ""; } } function getSingleFieldValue($table,$field,$condition,$value) { $data=$this->db->query("select ". $field. " from ". $table . " where ". $condition . "='". $value ."'"); $result= $data->row(); if($result) { return $result->$field; } else { return ""; } } function get_no_rows($table,$field,$id,$cond1,$cond2) { $this->db->where($field,$id); $this->db->where($cond1,$cond2); $Q=$this->db->get($table); $num=$Q->num_rows(); return $num; } function get_master_code($table,$prefix_name,$field,$primary_field) { $Q=$this->db->get($table); $num=$Q->num_rows(); $prefix_values=$this->mastermodel->get_data_srow('prefix_code',$prefix_name,'prefix_name'); $prefix_count=$prefix_values->prefix_digit; $prefix_code=$prefix_values->prefix; $num=$this->mastermodel->number_rows($table,'','','','','','',$primary_field); $num++; do { $master_code = $prefix_code.str_pad($num, $prefix_count, "0", STR_PAD_LEFT); $num_rows_code = $this->mastermodel->number_rows($table,$field,$master_code); $num++; }while($num_rows_code!=0); return $master_code; } function get_extension_code($code) { $this->db->join('master','master_id=extension_id'); $this->db->where('login_type_id',$_SESSION['login_type']); $Q=$this->db->get('extension'); $num=$Q->num_rows(); $prefix_count=3; $prefix_code=$code; $num=$this->mastermodel->number_rows('extension','','','','','','','extension_id'); $num++; do { $master_code = $prefix_code.'/RNV'.str_pad($num, $prefix_count, "0", STR_PAD_LEFT); $num_rows_code = $this->mastermodel->number_rows('extension','extension_code',$master_code); $num++; }while($num_rows_code!=0); return $master_code; } function check_private($module_id='') { if($module_id=='') $module_id=$_SESSION['current_mode']; $perm = $this->get_data_srow('user',$_SESSION['user_id'],'user_id'); $array_private=explode(',',$perm->home_page); $array_module=explode(',',$perm->user_modules); $found=array_search($module_id,$array_module); $val=$array_private[$found]; if($val==1) { return true; } else { return false; } } function get_lease_code($building_id) { $building_code = $this->get_single_field_value('building_details', 'building_code', 'building_id', $building_id); $this->db->join('master','master_id=lease_id'); $this->db->where('login_type_id',$_SESSION['login_type']); $Q=$this->db->get('lease_agreement'); $num=$Q->num_rows(); $prefix_count=3; $prefix_code=$building_code.'/'.date("Y"); $num=$this->mastermodel->number_rows('lease_agreement','','','','','','','lease_id'); $num++; do { $master_code = $prefix_code.'/'.str_pad($num, $prefix_count, "0", STR_PAD_LEFT); $num_rows_code = $this->mastermodel->number_rows('lease_agreement','lease_agreement_code',$master_code); $num++; }while($num_rows_code!=0); return $master_code; } function get_building_code($building_type_id) { $building_type_code = $this->get_single_field_value('building_type','building_type_code','building_type_id',$building_type_id); $this->db->like('building_code',$building_type_code); $this->db->join('master','master.master_id=building_id'); $this->db->where('login_type_id',$_SESSION['login_type']); $Q=$this->db->get('building_details'); $num=$Q->num_rows(); do { $code = $building_type_code.'/'.(1000+$num); $num_rows_code = $this->mastermodel->number_rows('building_details','building_code',$code); }while($num_rows_code!=0); return $code; } function get_single_field_value($table,$field,$condition,$value,$primary_field='') { // $data=$this->db->query("select ". $field. " from ". $table . " where ". $condition . "='". $value ."'"); $data = array(); $this->db->select($field); if(!empty ($primary_field)) { $this->db->join('master',"master.master_id=$table.$primary_field"); $this->db->where('login_type_id',$_SESSION['login_type']); } $this->db->where($condition, $value); $data= $this->db->get($table); $result= $data->row(); if($result) { return $result->$field; } else { return ""; } } function get_single_field_value_two($table,$field,$condition,$value,$condition1,$value1) { $sql ="select ". $field. " from ". $table . " where ". $condition . "='". $value ."' and ". $condition1 . "='". $value1 ."'"; $data=$this->db->query($sql); $result= $data->row(); if($result) { return $result->$field; } else { return ""; } } function get_single_joined_value($field,$table1,$table2,$field1,$field2,$condition,$value) { $data=$this->db->query("select $table1.$field from ". $table1 . " inner join ". $table2 ." on $table1.$field1=$table2.$field2 where ". $condition . "='". $value ."'"); $result= $data->row(); if($result) { return $result->$field; } else { return ""; } } function build_menu($moduleid="") { $user_id=$_SESSION['user_id']; $data = array(); $Q= $this->db->query("select * from menu where parent_menu_id = 0 and active=1 order by sort"); $P=$this->db->query("select user_modules,modules_permission from user where user_id='" . $_SESSION['user_id'] ."'"); $result= $P->row(); $permission=explode(',',$result->user_modules); $edit_del_permission=explode(',',$result->modules_permission); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $check=$this->mastermodel->check_user_permission($row['menu_id'],$_SESSION['user_id'],'0'); if($check) { $data[]=$row; } } } $Q->free_result(); return $data; } function get_sub_menu_child() { $user_id=$_SESSION['user_id']; $data = array(); $Q= $this->db->query("SELECT child.* FROM `menu` parent join menu as child on(parent.menu_id = child.parent_menu_id) where child.active=1 order by child.sort"); $P=$this->db->query("select user_modules,modules_permission from user where user_id='" . $_SESSION['user_id'] ."'"); $result= $P->row(); $permission=explode(',',$result->user_modules); $edit_del_permission=explode(',',$result->modules_permission); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $check=$this->mastermodel->check_user_permission($row['menu_id'],$_SESSION['user_id'],'0'); if($check) { $data[]=$row; } } } $Q->free_result(); return $data; } function build_module() { $flag=0; $homemodel=0; $data = array(); $P=$this->db->query("select user_modules from user where user_id='" . $_SESSION['user_id'] ."'"); $result= $P->row(); $permission=explode(',',$result->user_modules); $Q= $this->db->query("select * from module where active = '1' 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'] ."' and active = 1"); foreach($R->result_array() as $menu) { $check=$this->mastermodel->check_user_permission($menu['menu_id'],$_SESSION['user_id'],'0'); if($check) { $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 chk_url_permission($menuid) { if(!isset($_SESSION['user_id'])) die(); $uid=$_SESSION['user_id']; $permission= $this->get_single_field_value('user','user_modules','user_id',$uid); $array=explode(',',$permission); if(in_array($menuid, $array)) { return true; } else { return false; } } function getdatas($table,$sortfield="",$sort_order="asc",$primary_field='') { $data = array(); if(!empty ($sortfield)) { $this->db->order_by($sortfield, $sort_order); } if(!empty ($primary_field)) { $this->db->join('master',"master.master_id=$table.$primary_field"); $this->db->where('login_type_id',$_SESSION['login_type']); } $Q = $this->db->get($table); // echo $this->db->last_query(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_data($table,$id,$field,$sortfield="",$primary_field='',$sort='asc') { $data = array(); $this->db->where($field,$id); if(!empty($sortfield)) { $this->db->order_by($sortfield,$sort); } if(!empty ($primary_field)) { $this->db->join('master',"master.master_id=$table.$primary_field"); $this->db->where('login_type_id',$_SESSION['login_type']); } $Q= $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_data_joined($table1,$table2,$field1,$field2,$id='',$field='',$sortfield="") { $data = array(); if($id!='') $this->db->where($field,$id); $this->db->join($table2,"$table2.$field2=$table1.$field1"); if(!empty($sortfield)) { $this->db->order_by($sortfield,'desc'); } $Q= $this->db->get($table1); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_data_srow($table,$id,$field,$isarray=FALSE) { $data = array(); $this->db->where($field,$id); $Q= $this->db->get($table); if($isarray) $row=$Q->row_array(); else $row=$Q->row(); return $row; } function get_data_srow_joined($table1,$table2,$field1,$field2,$id,$field) { $this->db->join($table2,"$table2.$field2=$table1.$field1"); $this->db->where($field,$id); $Q= $this->db->get($table1); $row=$Q->row(); return $row; } function get_data_scoloumn($table,$id,$field,$coloumn,$sortfield="") { $data = array(); $this->db->where($field,$id); if(!empty($sortfield)) { $this->db->order_by($sortfield,'asc'); } $this->db->select($coloumn); $Q= $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getmoduledatamaster() { $data=array(); $res=$this->db->query("select module.module_name,module.module_title,menu.caption,menu.target,menu.menu_id,menu.module_id,menu.sort,menu.login_type from module join menu on module.module_id=menu.module_id where module.active = '1' and menu.active='1' order by module.sort, menu.sort"); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function getmoduledata() { $data=array(); $res=$this->db->query("select module.module_title,module.module_name,menu.caption,menu.target,menu.menu_id,menu.module_id,menu.sort,menu.login_type from module join menu on module.module_id=menu.module_id where menu.active=1 order by module.sort, menu.sort"); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function replacemenu($menuid) { $uid=$_SESSION['user_id']; $permission= $this->get_single_field_value('user','user_modules','user_id',$uid); $array=explode(',',$permission); if(in_array($menuid, $array)) { return $menuid; } else { return false; } } function permissionList() { $permission=array(); $user_id=$_SESSION['user_id']; $P=$this->db->query("select user_modules from user where user_id='" . $user_id ."'"); $result= $P->row(); $permission=explode(',',$result->user_modules); return $permission; } function checkexistencearray($table,$field,$value) { $tbarr=explode('~',$table); $fdarr=explode('~',$field); for($i=0;$i<sizeof($tbarr);$i++) { $this->db->from($tbarr[$i]); $this->db->where($fdarr[$i], $value); $count= $this->db->count_all_results(); if($count>0) { return $count; break; } else { continue; } } } function checkexistence($table,$field,$value,$primary_field) { $this->db->from($table); $this->db->join('master', "master.master_id=$table.$primary_field"); $this->db->where($field, $value); $this->db->where('login_type_id', $_SESSION['login_type']); $count= $this->db->count_all_results(); return $count; } function check_user_permission($menuid,$user_id,$check) { $this->db->select('user_modules,modules_permission'); $this->db->from('user'); $this->db->where('user_id', $user_id); $data=$this->db->get(); $result= $data->row(); $array_perm=explode(',',$result->modules_permission); $array_mod=explode(',',$result->user_modules); $found=array_search($menuid,$array_mod); $val=$array_perm[$found]; $a=decbin($val); $d=sprintf('%03u',$a); $ar = str_split($d); if($ar[$check]==1) { return true; } else { return false; } } function check_home_page($menuid,$user_id,$check) { $this->db->select('*'); $this->db->from('user'); $this->db->where('user_id', $user_id); $data=$this->db->get(); $result= $data->row(); $array_perm=explode(',',$result->modules_permission); $array_mod=explode(',',$result->user_modules); $array_home_page=explode(',',$result->home_page); $found=array_search($menuid,$array_mod); $val=$array_perm[$found]; $a=decbin($val); $d=sprintf('%03u',$a); $ar = str_split($d); if($ar[$check]==1 && $array_home_page[$found]==1) { return $this->check_menu_in_login($menuid); } else { return false; } } function check_menu_in_login($menuid) { $login_value = $this->get_single_field_value('menu', 'login_type', 'menu_id', $menuid); $login_array= explode(',', $login_value); if(in_array($_SESSION['login_type'], $login_array)) return true; else return false; } function getreminder() { $data=array(); $tdate=date('Y-m-d'); $data=$this->db->query("select * from reminder join master on master_id=reminder_id where creator_id=".$_SESSION['user_id']." and remind_before >= datediff(reminder_date,now()) and datediff(reminder_date,now())>=0"); return $data; } function add($postdata) { $data=array(); $data['resfunction']=$postdata['resfunction']; $table = $postdata['tab_name']; unset ($postdata['tab_name']); unset ($postdata['resfunction']); $res=$this->db->insert($table,$postdata); $cnt=$this->db->insert_id(); if($res>0) { $data['res']=1; $data['msg']='Record Added Successfully'; } else { $data['res']=0; $data['msg']='Error On Adding Record'; } return $data; } function update($postdata) { $data=array(); $data['resfunction']=$postdata['resfunction']; $table = $postdata['tab_name']; $field = $postdata['tab_field']; $id= $postdata['tab_id']; unset ($postdata['resfunction']); unset ($postdata['tab_name']); unset ($postdata['tab_field']); unset ($postdata['tab_id']); $this->db->where($field, $id); $res=$this->db->update($table,$postdata); if($res>0) { $data['res']=1; $data['msg']='Record Updated Successfully'; } else { $data['res']=0; $data['msg']='Error On updating Record'; } return $data; } function deletedata($table,$id,$field) { $data=array(); $this->db->trans_begin(); $this->db->delete($table,array($field=>$id)); $this->db->trans_status(); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Unable to delete record because of associated data'; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Data Deleted Successfully'; } return $data; } function norecords($tabname) { $data = array(); $sql = "select MAX(id) as maxid from $tabname"; $res = mysql_query($sql); $row = mysql_fetch_array($res); $numcode = $row['maxid']; if ($numcode != '') { return $numcode; } else { return 0; } } function convertdateformat($date) { if($date == "" || $date == "00-00-0000") { return ""; } else { $time = strtotime( $date ); return date( 'Y-m-d', $time ); } } function convertdatenormalformat($date) { if($date == "" || $date == "0000-00-00") { return ""; } else { $time = strtotime( $date ); return date( 'd-m-Y', $time ); } } function insertmasterdata() { $time= date("Y-m-d H:i:s"); $tblValues=array('menu_id'=>$_SESSION['current_mode'], 'creator_id'=> $_SESSION['user_id'], 'owner_id'=> $_SESSION['user_id'], 'created_time'=> $time, 'login_type_id'=>$_SESSION['login_type'], 'ip_address'=> $_SERVER['REMOTE_ADDR']); $this->db->insert('master', $tblValues); return mysql_insert_id(); } function updatemasterdata($id,$branch_id='') { $time= date("Y-m-d H:i:s"); $tblValues=array('modifier_id'=> $_SESSION['user_id'], 'modified_time'=>$time, 'ip_address'=> $_SERVER['REMOTE_ADDR']); $this->db->where('master_id',$id); $this->db->update('master', $tblValues); } /*Common function ends here*/ /*Search function starts here*/ function convert_number($number) { if (($number < 0) || ($number > 999999999)) { throw new Exception("Number is out of range"); } $Gn = floor($number / 1000000); /* Millions (giga) */ $number -= $Gn * 1000000; $kn = floor($number / 1000); /* Thousands (kilo) */ $number -= $kn * 1000; $Hn = floor($number / 100); /* Hundreds (hecto) */ $number -= $Hn * 100; $Dn = floor($number / 10); /* Tens (deca) */ $n = $number % 10; /* Ones */ $res = ""; if ($Gn) { $res .= $this->convert_number($Gn) . " Million"; } if ($kn) { $res .= (empty($res) ? "" : " ") . $this->convert_number($kn) . " Thousand"; } if ($Hn) { $res .= (empty($res) ? "" : " ") . $this->convert_number($Hn) . " Hundred"; } $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"); $tens = array("", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"); if ($Dn || $n) { if (!empty($res)) { $res .= " and "; } if ($Dn < 2) { $res .= $ones[$Dn * 10 + $n]; } else { $res .= $tens[$Dn]; if ($n) { $res .= " " . $ones[$n]; } } } if (empty($res)) { $res = "zero"; } return $res; } function getdistinctfield_condition($field,$table,$id,$value,$sortfield="") { $data = array(); $this->db->distinct(); $this->db->select($field); $this->db->where($id,$value); if(!empty ($sortfield)) { $this->db->order_by($sortfield, "asc"); } $Q = $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } /* functions for building type */ function search_building_type($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('building_type'); $this->db->order_by('building_type_id','asc'); $data['results']=$this->db->get(); return $data; } function insert_building_type($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'building_type_id'=>$masterid, 'building_type'=>$postdata['building_type'], 'building_type_code'=>$postdata['building_type_code'], 'building_type_remarks'=> $postdata['building_type_remarks'] ); $this->db->insert('building_type', $tblValues); $data['resfunction']='search_building_type'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_building_type($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'building_type'=>$postdata['building_type'], 'building_type_code'=>$postdata['building_type_code'], 'building_type_remarks'=>$postdata['building_type_remarks'] ); $this->db->where('building_type_id',$postdata['building_type_id']); $this->db->update('building_type', $tblValues); $data['resfunction']='search_building_type'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for location */ function search_location($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('location'); $this->db->join('master','master_id=location_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('location_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_location($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'location_id'=>$masterid, 'location_name'=>$postdata['location_name'], 'location_remarks'=> $postdata['location_remarks'] ); $this->db->insert('location', $tblValues); $data['resfunction']='search_location'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_location($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'location_name'=>$postdata['location_name'], 'location_remarks'=> $postdata['location_remarks'] ); $this->db->where('location_id',$postdata['location_id']); $this->db->update('location', $tblValues); $data['resfunction']='search_location'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for bedroom */ function search_bedroom($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('bedroom'); $this->db->join('master','master_id=bedroom_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('bedroom_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_bedroom($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'bedroom_id'=>$masterid, 'bedroom_number'=>$postdata['bedroom_number'], 'bedroom_remarks'=> $postdata['bedroom_remarks'] ); $this->db->insert('bedroom', $tblValues); $data['resfunction']='search_bedroom'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_bedroom($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'bedroom_number'=>$postdata['bedroom_number'], 'bedroom_remarks'=> $postdata['bedroom_remarks'] ); $this->db->where('bedroom_id',$postdata['bedroom_id']); $this->db->update('bedroom', $tblValues); $data['resfunction']='search_bedroom'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for area */ function search_area($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('area'); $this->db->join('master','master_id=area_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('area_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_area($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'area_id'=>$masterid, 'area_sq_meter'=>$postdata['area_sq_meter'], 'area_remarks'=> $postdata['area_remarks'] ); $this->db->insert('area', $tblValues); $data['resfunction']='search_area'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_area($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'area_sq_meter'=>$postdata['area_sq_meter'], 'area_remarks'=> $postdata['area_remarks'] ); $this->db->where('area_id',$postdata['area_id']); $this->db->update('area', $tblValues); $data['resfunction']='search_area'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for facility */ function search_facility($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('facility'); $this->db->join('master','master_id=facility_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('facility_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_facility($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'facility_id'=>$masterid, 'facility_type'=>$postdata['facility_type'], 'facility_remarks'=> $postdata['facility_remarks'] ); $this->db->insert('facility', $tblValues); $data['resfunction']='search_facility'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_facility($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'facility_type'=>$postdata['facility_type'], 'facility_remarks'=> $postdata['facility_remarks'] ); $this->db->where('facility_id',$postdata['facility_id']); $this->db->update('facility', $tblValues); $data['resfunction']='search_facility'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for amenities */ function search_amenities($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('amenities'); $this->db->join('master','master_id=amenities_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('amenities_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_amenities($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues=array( 'amenities_id'=>$masterid, 'amenities_type'=>$postdata['amenities_type'], 'amenities_remarks'=> $postdata['amenities_remarks'] ); $this->db->insert('amenities', $tblValues); $data['resfunction']='search_amenities'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_amenities($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'amenities_type'=>$postdata['amenities_type'], 'amenities_remarks'=> $postdata['amenities_remarks'] ); $this->db->where('amenities_id',$postdata['amenities_id']); $this->db->update('amenities', $tblValues); $data['resfunction']='search_amenities'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for agent */ function search_agent($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('agent'); $this->db->join('master','master_id=agent_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('agent_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_agent($postdata) { $data=array(); $this->db->trans_begin(); $status=$postdata['status']; $master_id=$this->mastermodel->insertmasterdata(); $code=$this->mastermodel->get_master_code('agent','Agent','agent_code','agent_id'); $tblValues=array( 'agent_id'=>$master_id, 'agent_name'=>$postdata['agent_name'], 'agent_code'=> $code, 'comments'=>$postdata['comments'], 'status'=>$status, 'location'=>$postdata['location'], 'address'=>$postdata['address'], 'contact_no'=>$postdata['contact_no'], 'e_mail'=>$postdata['e_mail'] ); $this->db->insert('agent', $tblValues); $data['resfunction']='search_agent'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_agent($postdata) { $data=array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $status=$postdata['status']; $tblValues=array( 'agent_name'=>$postdata['agent_name'], //'agent_code'=> $postdata['agent_code'], 'comments'=>$postdata['comments'], 'status'=>$status, 'location'=>$postdata['location'], 'address'=>$postdata['address'], 'contact_no'=>$postdata['contact_no'], 'e_mail'=>$postdata['e_mail'] ); $this->db->where('agent_id',$postdata['agent_id']); $this->db->update('agent', $tblValues); $data['resfunction']='search_agent'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for contracting company*/ function search_contract($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('contracting_company'); $this->db->join('master','master_id=cc_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('cc_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_contract($postdata) { $data=array(); $this->db->trans_begin(); $master_id=$this->mastermodel->insertmasterdata(); $code=$this->mastermodel->get_master_code('contracting_company','Contracting Company','cc_code','cc_id'); $tblValues=array( 'cc_id'=>$master_id, 'cc_name'=>$postdata['cc_name'], 'cc_code'=> $code, 'cc_address'=>$postdata['cc_address'], 'cc_country'=>$postdata['cc_country'], 'cc_location'=>$postdata['cc_location'], 'cc_phone'=>$postdata['cc_phone'], 'cc_fax'=>$postdata['cc_fax'], 'cc_mobile'=>$postdata['cc_mobile'], 'cc_e_mail'=>$postdata['cc_e_mail'], 'cc_remarks'=>$postdata['cc_remarks'] ); $this->db->insert('contracting_company', $tblValues); $i=1; while(isset($postdata['cc_contact_name'.$i])) { if($postdata['cc_contact_name'.$i]!="") { $tblValues=array( 'cc_id'=>$master_id, 'cc_contact_name'=>$postdata['cc_contact_name'.$i], 'cc_contact_designation'=>$postdata['cc_contact_designation'.$i], 'cc_contact_mobile'=>$postdata['cc_contact_mobile'.$i], 'cc_contact_phone'=>$postdata['cc_contact_phone'.$i], 'cc_contact_email'=>$postdata['cc_contact_email'.$i] ); $this->db->insert('contracting_company_details',$tblValues); } $i++; } $data['resfunction']='search_contract'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_contract($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'cc_name'=>$postdata['cc_name'], 'cc_address'=>$postdata['cc_address'], 'cc_country'=>$postdata['cc_country'], 'cc_location'=>$postdata['cc_location'], 'cc_phone'=>$postdata['cc_phone'], 'cc_fax'=>$postdata['cc_fax'], 'cc_mobile'=>$postdata['cc_mobile'], 'cc_e_mail'=>$postdata['cc_e_mail'], 'cc_remarks'=>$postdata['cc_remarks'] ); $this->db->where('cc_id',$postdata['cc_id']); $this->db->update('contracting_company', $tblValues); $this->db->where('cc_id',$postdata['cc_id']); $this->db->delete('contracting_company_details'); $i=1; while(isset($postdata['cc_contact_name'.$i])) { if($postdata['cc_contact_name'.$i]!="") { $tblValues=array( 'cc_id'=>$postdata['cc_id'], 'cc_contact_name'=>$postdata['cc_contact_name'.$i], 'cc_contact_designation'=>$postdata['cc_contact_designation'.$i], 'cc_contact_mobile'=>$postdata['cc_contact_mobile'.$i], 'cc_contact_phone'=>$postdata['cc_contact_phone'.$i], 'cc_contact_email'=>$postdata['cc_contact_email'.$i] ); $this->db->insert('contracting_company_details',$tblValues); } $i++; } $data['resfunction']='search_contract'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functopns for maintenance contracting company */ function search_maintenance_contract($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('maintenance_cc'); $this->db->join('master','master_id=maintenance_cc_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('maintenance_cc_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_maintenance_contract($postdata) { $data=array(); $master_id=$this->mastermodel->insertmasterdata(); $code=$this->mastermodel->get_master_code('maintenance_cc','Maintenance Contracting Company','maintenance_cc_code','maintenance_cc_id'); $this->db->trans_begin(); $tblValues=array( 'maintenance_cc_id'=>$master_id, 'maintenance_cc_name'=>$postdata['maintenance_cc_name'], 'maintenance_cc_code'=> $code, 'maintenance_cc_address'=>$postdata['maintenance_cc_address'], 'maintenance_cc_country'=>$postdata['maintenance_cc_country'], 'maintenance_cc_location'=>$postdata['maintenance_cc_location'], 'maintenance_cc_phone'=>$postdata['maintenance_cc_phone'], 'maintenance_cc_fax'=>$postdata['maintenance_cc_fax'], 'maintenance_cc_mobile'=>$postdata['maintenance_cc_mobile'], 'maintenance_cc_e_mail'=>$postdata['maintenance_cc_e_mail'], 'maintenance_cc_work_type'=>$postdata['maintenance_cc_work_type'], 'maintenance_cc_remarks'=>$postdata['maintenance_cc_remarks'] ); $this->db->insert('maintenance_cc', $tblValues); $parent= $this->get_account_settings('maintenance_contract','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); if($this->mastermodel->get_num_rows('finance_chart_master','chart_account_code',$code)==0) { $tblValues=array('chart_account_code'=>$code, 'chart_account_name'=>$postdata['maintenance_cc_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues=array('chart_account_name'=>$postdata['maintenance_cc_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->where('chart_account_code',$code); $this->db->update('finance_chart_master', $tblValues); } } $i=1; while(isset($postdata['maintenance_contact_name'.$i])) { if($postdata['maintenance_contact_name'.$i]!="") { $tblValues=array( 'maintenance_cc_id'=>$master_id, 'maintenance_contact_name'=>$postdata['maintenance_contact_name'.$i], 'maintenance_contact_designation'=>$postdata['maintenance_contact_designation'.$i], 'maintenance_contact_mobile'=>$postdata['maintenance_contact_mobile'.$i], 'maintenance_contact_phone'=>$postdata['maintenance_contact_phone'.$i], 'maintenance_contact_email'=>$postdata['maintenance_contact_email'.$i] ); $this->db->insert('maintenance_cc_details',$tblValues); } $i++; } $data['resfunction']='search_maintenance_contract'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_maintenance_contract($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'maintenance_cc_name'=>$postdata['maintenance_cc_name'], 'maintenance_cc_address'=>$postdata['maintenance_cc_address'], 'maintenance_cc_country'=>$postdata['maintenance_cc_country'], 'maintenance_cc_location'=>$postdata['maintenance_cc_location'], 'maintenance_cc_phone'=>$postdata['maintenance_cc_phone'], 'maintenance_cc_fax'=>$postdata['maintenance_cc_fax'], 'maintenance_cc_mobile'=>$postdata['maintenance_cc_mobile'], 'maintenance_cc_e_mail'=>$postdata['maintenance_cc_e_mail'], 'maintenance_cc_work_type'=>$postdata['maintenance_cc_work_type'], 'maintenance_cc_remarks'=>$postdata['maintenance_cc_remarks'] ); $this->db->where('maintenance_cc_id',$postdata['maintenance_cc_id']); $this->db->update('maintenance_cc', $tblValues); $this->db->where('maintenance_cc_id',$postdata['maintenance_cc_id']); $this->db->delete('maintenance_cc_details'); $i=1; while(isset($postdata['maintenance_contact_name'.$i])) { if($postdata['maintenance_contact_name'.$i]!="") { $tblValues=array( 'maintenance_cc_id'=>$postdata['maintenance_cc_id'], 'maintenance_contact_name'=>$postdata['maintenance_contact_name'.$i], 'maintenance_contact_designation'=>$postdata['maintenance_contact_designation'.$i], 'maintenance_contact_mobile'=>$postdata['maintenance_contact_mobile'.$i], 'maintenance_contact_phone'=>$postdata['maintenance_contact_phone'.$i], 'maintenance_contact_email'=>$postdata['maintenance_contact_email'.$i] ); $this->db->insert('maintenance_cc_details',$tblValues); } $i++; } $parent= $this->get_account_settings('maintenance_contract','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); if($this->mastermodel->get_num_rows('finance_chart_master','chart_account_code',$postdata['maintenance_cc_code'])==0) { $tblValues=array('chart_account_code'=>$postdata['maintenance_cc_code'], 'chart_account_name'=>$postdata['maintenance_cc_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues=array('chart_account_name'=>$postdata['maintenance_cc_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->where('chart_account_code',$postdata['maintenance_cc_code']); $this->db->update('finance_chart_master', $tblValues); } } // $tblValues=array('chart_account_name'=>$postdata['maintenance_cc_name']); // $this->db->where('chart_account_code', $postdata['maintenance_cc_code']); // $this->db->update('finance_chart_master', $tblValues); $data['resfunction']='search_maintenance_contract'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for appliance */ function search_appliance($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('appliance'); $this->db->join('master','master_id=appliance_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('appliance_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_appliance($postdata) { $data=array(); $this->db->trans_begin(); $master_id = $this->mastermodel->insertmasterdata(); $tblValues=array( 'appliance_id'=>$master_id, 'appliance_type'=>$postdata['appliance_type'], 'appliance_remarks'=>$postdata['appliance_remarks'] ); $this->db->insert('appliance', $tblValues); $data['resfunction']='search_appliance'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_appliance($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'appliance_type'=>$postdata['appliance_type'], 'appliance_remarks'=>$postdata['appliance_remarks'] ); $this->db->where('appliance_id',$postdata['appliance_id']); $this->db->update('appliance', $tblValues); $data['resfunction']='search_appliance'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for inventory */ function search_inventory($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('inventory'); $this->db->join('master','master_id=inventory_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('inventory_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_inventory($postdata) { $data=array(); $this->db->trans_begin(); $master_id = $this->mastermodel->insertmasterdata(); $tblValues=array( 'inventory_id'=>$master_id, 'inventory_type'=>$postdata['inventory_type'], 'inventory_remarks'=>$postdata['inventory_remarks'] ); $this->db->insert('inventory', $tblValues); $data['resfunction']='search_inventory'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_inventory($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'inventory_type'=>$postdata['inventory_type'], 'inventory_remarks'=>$postdata['inventory_remarks'] ); $this->db->where('inventory_id',$postdata['inventory_id']); $this->db->update('inventory', $tblValues); $data['resfunction']='search_inventory'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for letter */ function search_letter($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('letter'); $this->db->join('master','master_id=letter_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('letter_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_letter($postdata) { $data=array(); $this->db->trans_begin(); $master_id = $this->mastermodel->insertmasterdata(); $tblValues=array( 'letter_id'=>$master_id, 'letter_type'=>$postdata['letter_type'], 'letter_remarks'=>$postdata['letter_remarks'] ); $this->db->insert('letter', $tblValues); $data['resfunction']='search_letter'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_letter($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'letter_type'=>$postdata['letter_type'], 'letter_remarks'=>$postdata['letter_remarks'] ); $this->db->where('letter_id',$postdata['letter_id']); $this->db->update('letter', $tblValues); $data['resfunction']='search_letter'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* function for vendor */ function search_vendor($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('vendor'); $this->db->join('master','master_id=vendor_id'); $this->db->where('master.login_type_id',$log_in_type); $this->db->order_by('vendor_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_vendor($postdata) { $data=array(); $this->db->trans_begin(); $master_id=$this->mastermodel->insertmasterdata(); $code=$this->mastermodel->get_master_code('vendor','Vendor','vendor_code','vendor_id'); $tblValues=array( 'vendor_id'=>$master_id, 'vendor_name'=>$postdata['vendor_name'], 'vendor_code'=> $code, 'vendor_address'=>$postdata['vendor_address'], 'vendor_country'=>$postdata['vendor_country'], 'vendor_location'=>$postdata['vendor_location'], 'vendor_phone'=>$postdata['vendor_phone'], 'vendor_fax'=>$postdata['vendor_fax'], 'vendor_mobile'=>$postdata['vendor_mobile'], 'vendor_e_mail'=>$postdata['vendor_e_mail'], 'vendor_type'=>$postdata['vendor_type'], 'vendor_remarks'=>$postdata['vendor_remarks'] ); $this->db->insert('vendor', $tblValues); $parent= $this->get_account_settings('vendor','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); if($this->mastermodel->get_num_rows('finance_chart_master','chart_account_code',$code)==0) { $tblValues=array('chart_account_code'=>$code, 'chart_account_name'=>$postdata['vendor_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues=array('chart_account_name'=>$postdata['vendor_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->where('chart_account_code',$code); $this->db->update('finance_chart_master', $tblValues); } } $data['resfunction']='search_vendor'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_vendor($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'vendor_name'=>$postdata['vendor_name'], 'vendor_address'=>$postdata['vendor_address'], 'vendor_country'=>$postdata['vendor_country'], 'vendor_location'=>$postdata['vendor_location'], 'vendor_phone'=>$postdata['vendor_phone'], 'vendor_fax'=>$postdata['vendor_fax'], 'vendor_mobile'=>$postdata['vendor_mobile'], 'vendor_e_mail'=>$postdata['vendor_e_mail'], 'vendor_type'=>$postdata['vendor_type'], 'vendor_remarks'=>$postdata['vendor_remarks'] ); $this->db->where('vendor_id',$postdata['vendor_id']); $this->db->update('vendor', $tblValues); $parent= $this->get_account_settings('vendor','finance_sub_account_settings'); if($parent) { $chart_type_id=$this->mastermodel->get_single_field_value('finance_chart_master','chart_type_id','chart_master_id',$parent); if($this->mastermodel->get_num_rows('finance_chart_master','chart_account_code',$postdata['vendor_code'])==0) { $tblValues=array('chart_account_code'=>$postdata['vendor_code'], 'chart_account_name'=>$postdata['vendor_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues=array('chart_account_name'=>$postdata['vendor_name'], 'chart_type_id'=>$chart_type_id, 'parent'=>$parent, 'inactive'=>0); $this->db->where('chart_account_code',$postdata['vendor_code']); $this->db->update('finance_chart_master', $tblValues); } } // $tblValues=array('chart_account_name'=>$postdata['vendor_name']); // $this->db->where('chart_account_code', $postdata['vendor_code']); // $this->db->update('finance_chart_master', $tblValues); $data['resfunction']='search_vendor'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for company details */ function search_company($pagenum) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select('*'); $this->db->from('company_details'); $this->db->join('master','master_id=company_id'); $this->db->where('master.login_type_id',$log_in_type); $data['results']=$this->db->get(); return $data; } function update_company($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'company_name'=>$postdata['company_name'], 'company_display_name'=> $postdata['company_display_name'], 'company_city'=>$postdata['company_city'], 'company_country'=>$postdata['company_country'], 'company_address'=>$postdata['company_address'], 'company_contact_no'=>$postdata['company_contact_no'], 'company_email'=>$postdata['company_email'], 'company_fax'=>$postdata['company_fax'], 'company_website'=>$postdata['company_website'] // 'company_logo'=>$file ); $this->db->where('company_id',$postdata['company_id']); $this->db->update('company_details', $tblValues); $data['resfunction']='search_company'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } /* functions for building details */ function search_building_details($pagenum) { $data=array(); $this->db->select('*'); $this->db->from('building_details'); $this->db->join('building_type','building_type.building_type_id=building_details.building_type_id'); $this->db->join('location','building_details.building_location_id=location.location_id'); $this->db->order_by('building_id','desc'); $data['results']=$this->db->get(); return $data; } function insert_cost_center($master_id,$table_id,$code,$name,$parent) { $tblValues=array( 'cost_master_id'=>$master_id, 'cost_table_id'=>$table_id, 'cost_center_code'=>$code, 'cost_center_name'=>$name, 'cost_center_parent'=>$parent, ); $this->db->insert('cost_center', $tblValues); return mysql_insert_id(); } function insert_building_details($postdata) { $data=array(); $this->db->trans_begin(); $master_id=$this->mastermodel->insertmasterdata(); $code=$this->get_building_code($postdata['building_type_id']); $tblValues=array( 'building_id'=>$master_id, 'building_name'=>$postdata['building_name'], 'building_code'=>$code, 'building_type_id'=>$postdata['building_type_id'], 'building_location_id'=>$postdata['building_location_id'], 'building_country'=>$postdata['building_country'], 'building_address'=>$postdata['building_address'], 'building_po_code'=>$postdata['building_po_code'], 'building_remarks'=>$postdata['building_remarks'], 'building_agent_id'=>$postdata['building_agent_id'] ); $this->db->insert('building_details', $tblValues); $cost_center_parent=$this->insert_cost_center($master_id, 0, $code,$postdata['building_name'] ,$postdata['building_type_id'] ); $i=1; while(isset($postdata['watchman_id'.$i])) { if($postdata['watchman_id'.$i]!="") { $tblValues=array( 'building_id'=>$master_id, 'building_watchman_id'=>$postdata['watchman_id'.$i] ); $this->db->insert('building_watchman', $tblValues); } $i++; } $i=1; while(isset($postdata['supervisor_id'.$i])) { if($postdata['supervisor_id'.$i]!="") { $tblValues=array( 'building_id'=>$master_id, 'building_supervisor_id'=>$postdata['supervisor_id'.$i] ); $this->db->insert('building_supervisor', $tblValues); } $i++; } $limit=$postdata['amenities_limit']; for($i=0;$i<$limit;$i++) { if(isset($postdata['amenities_'.$i])) { $tblValues=array( 'building_id'=>$master_id, 'amenity_type_id'=>$postdata['amenities_'.$i] ); $this->db->insert('building_amenities_details',$tblValues); } } $limit=$postdata['facility_limit']; for($i=0;$i<$limit;$i++) { if(isset($postdata['facility_'.$i])) { $tblValues=array( 'building_id'=>$master_id, 'facility_type_id'=>$postdata['facility_'.$i] ); $this->db->insert('building_facility_details',$tblValues); } } $i=1; while(isset($postdata['commercial_floor'.$i])) { if($postdata['commercial_floor'.$i]!="") { $tblValues=array( 'building_id'=>$master_id, 'commercial_floor'=>$postdata['commercial_floor'.$i], 'commercial_office'=>$postdata['commercial_office'.$i], 'commercial_square'=>$postdata['commercial_square'.$i] ); $this->db->insert('building_commercial_building_details',$tblValues); $cost_table_id=mysql_insert_id(); $cost_center=$this->insert_cost_center($master_id, $cost_table_id, $code,$postdata['commercial_floor'.$i],$cost_center_parent); } $i++; } $i=1; while(isset($postdata['commercial_villa_number'.$i])) { if($postdata['commercial_villa_number'.$i]!="") { $tblValues=array( 'building_id'=>$master_id, 'commercial_villa_number'=>$postdata['commercial_villa_number'.$i], 'commercial_villa_square'=>$postdata['commercial_villa_square'.$i] ); $this->db->insert('building_commercial_villa_details',$tblValues); $cost_table_id=mysql_insert_id(); $cost_center=$this->insert_cost_center($master_id, $cost_table_id, $code,$postdata['commercial_villa_number'.$i],$cost_center_parent); } $i++; } $i=1; while(isset($postdata['residential_villa_number'.$i])) { if($postdata['residential_villa_number'.$i]!="") { $tblValues=array( 'building_id'=>$master_id, 'residential_villa_number'=>$postdata['residential_villa_number'.$i], 'residential_bedroom_no'=>$postdata['residential_bedroom_no'.$i] ); $this->db->insert('building_residential_villa_details',$tblValues); $cost_table_id=mysql_insert_id(); $cost_center=$this->insert_cost_center($master_id, $cost_table_id, $code,$postdata['residential_villa_number'.$i],$cost_center_parent); } $i++; } $i=1; while(isset($postdata['apartment_floor'.$i])) { if($postdata['apartment_floor'.$i]!="") { $tblValues=array( 'building_id'=>$master_id, 'apartment_floor'=>$postdata['apartment_floor'.$i], 'apartment_no'=>$postdata['apartment_no'.$i], 'apartment_bedroom_no'=>$postdata['apartment_bedroom_no'.$i] ); $this->db->insert('building_apartment_details',$tblValues); $cost_table_id=mysql_insert_id(); $cost_center=$this->insert_cost_center($master_id, $cost_table_id, $code,$postdata['apartment_floor'.$i],$cost_center_parent); } $i++; } $data['resfunction']='search_building_details'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Added Successfully'; return $data; } } function update_building_details($postdata) { $data=array(); $this->db->trans_begin(); $tblValues=array( 'building_name'=>$postdata['building_name'], 'building_location_id'=>$postdata['building_location_id'], 'building_country'=>$postdata['building_country'], 'building_address'=>$postdata['building_address'], 'building_po_code'=>$postdata['building_po_code'], 'building_remarks'=>$postdata['building_remarks'], 'building_agent_id'=>$postdata['building_agent_id'] ); $this->db->where('building_id', $postdata['building_id']); $this->db->update('building_details', $tblValues); $this->db->where('building_id', $postdata['building_id']); $this->db->delete('building_amenities_details'); $limit=$postdata['amenities_limit']; for($i=0;$i<$limit;$i++) { if(isset($postdata['amenities_'.$i])) { $tblValues=array('building_id'=>$postdata['building_id'], 'amenity_type_id'=>$postdata['amenities_'.$i]); $this->db->insert('building_amenities_details',$tblValues); } } $limit=$postdata['facility_limit']; $this->db->where('building_id', $postdata['building_id']); $this->db->delete('building_facility_details'); $i=1; $this->db->where('building_id',$postdata['building_id']); $this->db->delete('building_watchman'); while(isset($postdata['building_watchman_id'.$i])) { if($postdata['building_watchman_id'.$i]!="") { $tblValues=array( 'building_id'=>$postdata['building_id'], 'building_watchman_id'=> $postdata['building_watchman_id'.$i]); $this->db->insert('building_watchman', $tblValues); } $i++; } $i=1; $this->db->where('building_id',$postdata['building_id']); $this->db->delete('building_supervisor'); while(isset($postdata['building_supervisor_id'.$i])) { if($postdata['building_supervisor_id'.$i]!="") { $tblValues=array( 'building_id'=>$postdata['building_id'], 'building_supervisor_id'=> $postdata['building_supervisor_id'.$i]); $this->db->insert('building_supervisor', $tblValues); } $i++; } for($i=0;$i<$limit;$i++) { if(isset($postdata['facility_'.$i])) { $tblValues=array( 'building_id'=>$postdata['building_id'], 'facility_type_id'=>$postdata['facility_'.$i] ); $this->db->insert('building_facility_details',$tblValues); } } $i=1; while(isset($postdata['commercial_floor'.$i])) { if($postdata['commercial_floor'.$i]!="") { $tblValues=array( 'building_id'=>$postdata['building_id'], 'commercial_floor'=>$postdata['commercial_floor'.$i], 'commercial_office'=>$postdata['commercial_office'.$i], 'commercial_square'=>$postdata['commercial_square'.$i] ); $this->db->insert('building_commercial_building_details',$tblValues); } $i++; } $i=1; while(isset($postdata['commercial_villa_number'.$i])) { if($postdata['commercial_villa_number'.$i]!="") { $tblValues=array( 'building_id'=>$postdata['building_id'], 'commercial_villa_number'=>$postdata['commercial_villa_number'.$i], 'commercial_villa_square'=>$postdata['commercial_villa_square'.$i] ); $this->db->insert('building_commercial_villa_details',$tblValues); } $i++; } $i=1; while(isset($postdata['residential_villa_number'.$i])) { if($postdata['residential_villa_number'.$i]!="") { $tblValues=array( 'building_id'=>$postdata['building_id'], 'residential_villa_number'=>$postdata['residential_villa_number'.$i], 'residential_bedroom_no'=>$postdata['residential_bedroom_no'.$i] ); $this->db->insert('building_residential_villa_details',$tblValues); } $i++; } $i=1; while(isset($postdata['apartment_floor'.$i])) { if($postdata['apartment_floor'.$i]!="") { $tblValues=array( 'building_id'=>$postdata['building_id'], 'apartment_floor'=>$postdata['apartment_floor'.$i], 'apartment_no'=>$postdata['apartment_no'.$i], 'apartment_bedroom_no'=>$postdata['apartment_bedroom_no'.$i] ); $this->db->insert('building_apartment_details',$tblValues); } $i++; } $data['resfunction']='search_building_details'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res']=0; $data['msg']='Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res']=1; $data['msg']='Record Updated Successfully'; return $data; } } function get_building_details($building_id) { $this->db->join('building_type','building_type.building_type_id=building_details.building_type_id'); $this->db->join('location','building_details.building_location_id=location.location_id'); $this->db->join('agent','building_details.building_agent_id=agent.agent_id','left'); $this->db->where('building_details.building_id',$building_id); $Q=$this->db->get('building_details'); $row=$Q->row(); return $row; } function upload_file($postdata) { $this->db->trans_begin(); $tbl1Values=array('master_id'=>$postdata['master_id'], 'file_name'=>$postdata['file_name'], 'file_date'=>date("Y-m-d"), 'file_location'=>$postdata['file_location']); $this->db->insert('file', $tbl1Values); $this->db->trans_commit(); } function getsupervisor($table,$sortfield="",$sort_order="asc",$primary_field='') { $data = array(); $this->db->where('employee_supervisor','1'); if(!empty ($sortfield)) { $this->db->order_by($sortfield, $sort_order); } if(!empty ($primary_field)) { $this->db->join('master',"master.master_id=$table.$primary_field"); $this->db->where('login_type_id',$_SESSION['login_type']); } $Q = $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_lease_codes() { $data = array(); $this->db->select('lease_id,CONCAT(lease_agreement_code, " - ",customer_name) as tenancy_no', FALSE); $this->db->where('lease_status','Active'); $this->db->join('master',"master.master_id=lease_id"); $this->db->join('customer',"customer_id=lease_customer_id"); $this->db->where('login_type_id',$_SESSION['login_type']); $Q= $this->db->get('lease_agreement'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_maintenance_contract_codes() { $data = array(); $this->db->select('maintenance_contract_id,CONCAT(maintenance_contract_code, " - ",maintenance_cc_name, " - ",building_name) as tenancy_no', FALSE); $this->db->join('master',"master.master_id=maintenance_contract_id"); $this->db->join('maintenance_cc',"maintenance_cc_id=maintenance_contracting_company_id"); $this->db->join('building_details',"building_id=maintenance_contract_building_id"); $this->db->where('login_type_id',$_SESSION['login_type']); $Q= $this->db->get('maintenance_contract'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_project_contract_codes() { $data = array(); $this->db->select('project_id,CONCAT(project_code, " - ",cc_name) as project_code', FALSE); $this->db->join('master',"master.master_id=project_id"); $this->db->join('contracting_company',"cc_id=project_contractor_id"); $this->db->where('login_type_id',$_SESSION['login_type']); $Q= $this->db->get('project'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_data_dual_srow($table,$id1,$field1,$id2,$field2,$sortfield="") { $data = array(); $this->db->where($field1,$id1); $this->db->where($field2,$id2); if(!empty($sortfield)) { $this->db->order_by($sortfield,'asc'); } $Q= $this->db->get($table); $row=$Q->row(); return $row; } function get_data_dual($table,$id1,$field1,$id2,$field2,$sortfield="",$primary_field='',$sort='asc') { $data = array(); $this->db->where($field1,$id1); $this->db->where($field2,$id2); if(!empty($sortfield)) { $this->db->order_by($sortfield,$sort); } if(!empty ($primary_field)) { $this->db->join('master',"master.master_id=$table.$primary_field"); $this->db->where('login_type_id',$_SESSION['login_type']); } $Q= $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_alert_datas() { $data = array(); $sql="SELECT `alert_master_name`,`alert`.`alert_master_id`,count(alert.alert_id) FROM `alert_master` join alert on alert_master.alert_master_id=alert.alert_master_id JOIN master on master.master_id=alert.alert_record_id WHERE master.login_type_id=".$_SESSION['login_type']." and alert.alert_status=1 GROUP BY `alert_master`.`alert_master_id` "; $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_bank_account() { $data = array(); $this->db->order_by('bank_account_id', 'asc'); $this->db->join('finance_chart_master',"finance_chart_master.chart_account_code=finance_bank_account.chart_account_code"); $this->db->join('master',"master.master_id=finance_bank_account.bank_account_id"); $this->db->where('login_type_id',$_SESSION['login_type']); $Q = $this->db->get('finance_bank_account'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getdistinct_rec_date() { $log_in_type = $_SESSION['login_type']; $data = array(); $this->db->distinct(); $this->db->select('reconcile_date'); $this->db->join('master', 'master_id=journal_id'); $this->db->where('master.login_type_id', $log_in_type); $this->db->where('reconcile_date IS NOT NULL'); $this->db->order_by('reconcile_date', "asc"); $Q = $this->db->get('finance_journal'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_account_settings($field,$table) { $data=array(); $log_in_type=$_SESSION['login_type']; $this->db->select($field); $this->db->join('master','master_id=sub_account_settings_id'); $this->db->where('master.login_type_id',$log_in_type); $q=$this->db->get($table); if($q->num_rows()>0) $res=$q->row()->$field; else $res=0; return $res; } }