<?php
require_once(LIB_PATH . '/' . 'database.php');

class Setup extends DatabaseObject
{
    protected static $table_name = "salstructure";
    public $id;
    public $level;
    public $step;
    public $department;
    public $basic;
    public $name;
    public $fullname;
    public $staffid;
    public $gross;
    public $dname;
    public $ename;
    public $amount;
    public $date;
    public $dpunitid;
    public $rent;
    public $status;
    public $paygrade;
    public $stbiodataid;
    public $deductid;
    public $statsum;
    public $totaldeduction;
    public $bankname;
    public $accountnumber;
    public $sum;
    public $totalgross;
    public $totalearnings;
    public $myearnings;
    public $totaldeductions;
    public $totalCount;
    public $curdate;
    public $rowCount;
    
    // $sql = "SELECT s.*, t.gl,t.basic,t.rent,t.gross FROM stbiodata s INNER JOIN conpcass_contediss t ON s.paygrade=t.gl WHERE month(date)=$month AND year(date)=$year ORDER BY s.surname ";
    
    public static function authenticate($username, $password)
    {
      global $database;
      $sql="SELECT * FROM stbiodata WHERE username='$username' AND password='$password' LIMIT 1";
      $result_array=self::find_by_sql($sql);
      return !empty($result_array)?array_shift($result_array):false;

    }
    
    
    
    public static function single_deduction($deduction)
    {
      global $database;
      $sql="SELECT * FROM deduction WHERE id=$deduction LIMIT 1";

      $result_array=self::find_by_sql($sql);
      return !empty($result_array)?array_shift($result_array):false;

    }
    public static function get_all_deduction()
    {
      global $database;
      $sql="SELECT * FROM deduction ORDER BY name";
      return $result_array=self::find_by_sql($sql);
    }
    public static function getstaffiddetails($staffid)
    {
      global $database;
      $sql="SELECT s.* FROM stbiodata s INNER JOIN fin f ON f.id=s.finid WHERE s.staffid='$staffid' LIMIT 1";
      $result_array=self::find_by_sql($sql);
      return !empty($result_array)?array_shift($result_array):false;
    }
    public static function upload_deductions($stbiodata,$deductid,$name,$status,$amount,$date)
    {                                      
      global $database;

      $sql = "INSERT INTO addeddeduction (";
      $sql .= "stbiodataid,deductid,dname,status, amount,date";
    
      $sql .= ") VALUES ('";
      $sql .= $stbiodata . "','";
      $sql .= $deductid . "','";
      $sql .= $name . "','";
      $sql .= $status . "','";
     
      $sql .= $amount . "','";
      $sql .= $date . "'
     )";
    
      if ($database->query($sql)) {
       return  $id=$database->insert_id();
        
         
      } else {
          return false;
      }
    

    }
    public static function get_all_deductions_records()
    {
      global $database;
      $sql="Select count(id) as rowCount From addeddeduction";

      $result_array=self::find_by_sql($sql);
      return !empty($result_array)?array_shift($result_array):false;

    }
    public static function delete_salary_structure($table,$gl)
    {
      global $database;
      $sql="DELETE FROM $table WHERE gl='$gl' LIMIT 1";

      if ($database->query($sql)) {
       
       
        return true;
     } else {
         return false;
     }

    }
    public static function update_salary_structure($table,$gl,$basic,$rent,$gross)
    {
      global $database;
      $sql="update $table SET basic='$basic',rent='$rent',gross=$gross WHERE gl='$gl' LIMIT 1";
  
      if ($database->query($sql)) {
        //  $id=$database->insert_id();
         
          return true;
       } else {
           return false;
       }
    }
    public static function get_salary_structure($table,$gl)
    {
      global $database;
      $sql="SELECT * FROM $table WHERE gl='$gl' LIMIT 1";
      $result_array=self::find_by_sql($sql);
      return !empty($result_array)?array_shift($result_array):false;

    }
    public static function getcurrentdeduction($table='')
    {
      global $database;
      $sql="SELECT date(date) as curdate from $table order by date desc limit 1";
      $result_array=self::find_by_sql($sql);
      return !empty($result_array)? array_shift($result_array):false;
    }
    public static function countdeductions($date='')
    {
     
      global $database;
      
      $sql="SELECT sum(amount) as totalCount from addeddeduction WHERE date(date)='$date'";
      $result_array=self::find_by_sql($sql);
      return !empty($result_array)? array_shift($result_array):false;
    }

    public static function countearnings($date='')
    {
     
      global $database;
      $sql="SELECT sum(amount) as totalCount from addedearnings WHERE date(date)='$date'";
      $result_array=self::find_by_sql($sql);
      return !empty($result_array)? array_shift($result_array):false;
    }

    
public static function countallNonAcademics()
{


  global $database;
  $sql="SELECT count(id) as totalCount from stbiodata where status=2";
  $result_array=self::find_by_sql($sql);
  return !empty($result_array)? array_shift($result_array):false;
}


public static function countallAcademics()
{
 

  global $database;
  $sql="SELECT count(id) as totalCount from stbiodata where status=1";
  $result_array=self::find_by_sql($sql);
  return !empty($result_array)? array_shift($result_array):false;
}




public static function countallUnit()
{
      global $database;
      $sql="SELECT count(id) as totalCount from dpunit where dpunitid=2";
      $result_array=self::find_by_sql($sql);
      return !empty($result_array)? array_shift($result_array):false;
}

public static function countalldepartment()
{
  global $database;
  $sql="SELECT count(id) as totalCount FROM dpunit WHERE dpunitid=1";
  $result_array=self::find_by_sql($sql);
  return !empty($result_array)? array_shift($result_array):false;
}
public static function get_all_staff_details($staffid){

  global $database;

  $sql="SELECT * FROM stbiodata WHERE staffid=$staffid LIMIT 1";
  $result_array=self::find_by_sql($sql);
  return !empty($result_array)?array_shift($result_array):false;

}
public static function insertfinancialdata($bank,$accnumber){
  global $database;

  $sql = "INSERT INTO fin (";
  $sql .= "bankname, accountnumber";

  $sql .= ") VALUES ('";
  $sql .= $bank . "','";
  $sql .= $accnumber . "'
 )";

  if ($database->query($sql)) {
   return  $id=$database->insert_id();
    
     
  } else {
      return false;
  }

}
  
public static function updatestaffdetails($staffupdatedid,$status,$email,$phone,$finid)
  {

    global $database;
    $sql="update stbiodata SET designation='$status',email='$email',phone='$phone',finid=$finid WHERE id=$staffupdatedid LIMIT 1";
  
    if ($database->query($sql)) {
        $id=$database->insert_id();
       
        return true;
     } else {
         return false;
     }
   
  
  
  
  
  }
  
  
  
  
  public static function fetch_staff_acct_details($id)
  {
    global $database;

    $sql="SELECT fullname, paygrade FROM stbiodata WHERE finid=$id LIMIT 1";
    $result_array=self::find_by_sql($sql);
    return !empty($result_array)?array_shift($result_array):false;
  }
  public static function get_each_total_staff_earnings($id, $month, $year)
 {
  global $database;
  $sql = "SELECT sum(e.amount) as totalearnings, e.date,e.ename FROM addedearnings  e INNER JOIN stbiodata s ON s.id=e.stbiodataid WHERE s.finid=$id AND month(e.date)=$month AND year(e.date)=$year";
  $result_array=self::find_by_sql($sql);
  return !empty($result_array)? array_shift($result_array):false;
 }

 public static function get_each_total_staff_deductions($id, $month, $year)
 {
  global $database;
  $sql = "SELECT sum(e.amount) as totaldeductions FROM addeddeduction e INNER JOIN stbiodata s ON s.id=e.stbiodataid WHERE s.finid=$id AND month(e.date)=$month AND year(e.date)=$year";
  $result_array=self::find_by_sql($sql);
  return !empty($result_array)? array_shift($result_array):false;
 }


  public static function bank_summary_money($accountnumber)
  {
    global $database;
    $sql = "SELECT * FROM fin WHERE accountnumber='$accountnumber' LIMIT 1";
    $result_array=self::find_by_sql($sql);
    return !empty($result_array)? array_shift($result_array):false;
 
  }
 
  public static function get_single_bank($bank)
  {
    global $database;
    $sql="SELECT * FROM fin WHERE bankname='$bank'";
    return $result_array=self::find_by_sql($sql);

  }
 public static function get_all_bank_name()
 {
  global $database;
  $sql="SELECT distinct(bankname),id FROM fin group by bankname";
  return $result_array=self::find_by_sql($sql);
 }   

 public static function fetch_gross_individual_bank_money_aca($bankname,$table)
  {
    global $database;
     $sql="SELECT SUM(c.gross) as totalgross FROM $table c INNER JOIN stbiodata t ON t.paygrade=c.gl INNER JOIN fin f ON f.id=t.finid WHERE f.bankname='$bankname'";
     $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;

    }


 public static function get_all_gross_amount($table,$status,$bankid)
{
  global $database;
  $sql="SELECT SUM(t.gross) as gross FROM $table t INNER JOIN stbiodata s ON s.paygrade= t.gl INNER JOIN fin f ON f.id=s.finid WHERE s.status=$status and s.finid=$bankid";
   $result_array=self::find_by_sql($sql);
   return !empty($result_array)? array_shift($result_array):false;

}

public static function get_selected_single_cooperative($selectedcoop='')
{
global $database;
$sql = "SELECT * FROM deduction where id=$selectedcoop LIMIT 1";
 $result_array = self::find_by_sql($sql);
return !empty($result_array) ? array_shift($result_array) : false;

}
public static function get_selected_cooperative($selectedcoop, $month, $year)
{
  global $database;
  $sql = "SELECT s.*, b.fullname FROM addeddeduction s INNER JOIN stbiodata b ON s.stbiodataid=b.id WHERE s.deductid=$selectedcoop AND month(s.date)=$month AND year(s.date)=$year";
  $result_array=self::find_by_sql($sql);;
 return $result_array = self::find_by_sql($sql);
  //return !empty($result_array) ? array_shift($result_array) : false;


}
public static function get_all_cooperative()
{
  global $database;

  $sql="SELECT * FROM deduction";

  return $result_array = self::find_by_sql($sql);

}

public static function get_individual_earnings($staffid, $eid, $month, $year)
{
  global $database;

  $sql="SELECT * FROM addedearnings WHERE stbiodataid=$staffid AND earningsid=$eid AND month(date)=$month AND year(date)=$year LIMIT 1";
  
  $result_array = self::find_by_sql($sql);
  return !empty($result_array) ? array_shift($result_array) : false;

}
 public static function fetch_all_payroll_details($did)
 {
  global $database;

  //$sql="SELECT g.*,b.fullname,b.staffid, b.paygrade FROM stbiodata b INNER JOIN conpcass g ON b.paygrade=g.gl INNER JOIN fin f ON f.id=b.finid WHERE b.deptid=$did ORDER BY b.fullname";
 
  //INNER JOIN conpcass_contediss t ON s.paygrade=t.gl WHERE month(date)=$month AND year(date)=$year ORDER BY s.surname ";

  $sql="SELECT g.*,b.fullname,b.staffid, b.paygrade FROM stbiodata b INNER JOIN conpcass g ON b.paygrade=g.gl INNER JOIN fin f ON f.id=b.finid WHERE b.deptid=$did ORDER BY b.fullname";
 
  return $result_array=self::find_by_sql($sql);
}

public static function fetch_union_all($did)
{
  global $database;

  $sql="SELECT g.*,b.fullname,b.staffid, b.paygrade FROM stbiodata b INNER JOIN conpcass_contediss g ON b.paygrade=g.gl INNER JOIN fin f ON f.id=b.finid WHERE b.deptid=$did and b.status=g.status group by b.staffid ORDER BY b.fullname";
 
  return $result_array=self::find_by_sql($sql);
 
  return $result_array=self::find_by_sql($did);
}
public static function fetch_all_payroll_details_2($did)
 {
  global $database;

  $sql="SELECT g.*,b.fullname,b.staffid, b.paygrade FROM stbiodata b INNER JOIN contediss g ON b.paygrade=g.gl INNER JOIN fin f ON f.id=b.finid  WHERE b.deptid=$did ORDER BY b.fullname";
 
  return $result_array=self::find_by_sql($sql);
}

public static function fetch_all_department_title()
    
{
      global $database;

      $sql="SELECT * FROM departments order by department ";
      return $result_array=self::find_by_sql($sql);
 }


  


    public static function fetch_added_deduction($stid='',$de='',$status, $month, $year)
    {
      global $database;

      $sql = "SELECT stbiodataid,amount,deductid FROM addeddeduction WHERE stbiodataid=$stid AND deductid=$de AND status=$status AND month(date)=$month AND year(date)=$year  ";
       $result_array = self::find_by_sql($sql);
       return !empty($result_array) ? array_shift($result_array) : false;
    }



    public static function fetch_added_deduction_content($stid, $deid, $status)
    {
      global $database;
      $sql = "SELECT * FROM addeddeduction WHERE stbiodataid=$stid AND deductid=$deid AND status=$status LIMIT 1  ";
      $result_array = self::find_by_sql($sql);
      return !empty($result_array) ? array_shift($result_array) : 0.00;
    }

    public static function get_each_deduction_amount($id,$status,$month,$year)
    {
      global $database;

      $sql="SELECT sum(amount) as totaldeduction FROM addeddeduction WHERE deductid=$id AND status=$status AND month(date)=$month AND year(date)=$year LIMIT 1";
      $result_array = self::find_by_sql($sql);
      return !empty($result_array) ? array_shift($result_array) : 0.00;
  
    }

    public static function fetch_deduction_title($status)
    {
      global $database;
      $sql = "SELECT * FROM deduction WHERE status=$status  ";

      return $result_array = self::find_by_sql($sql);
      
    }



    public static function get_each_earnings_amount($id, $month, $year)
    {
      global $database;
      $sql = "SELECT sum(amount) as myearnings, date FROM addedearnings WHERE earningsid=$id AND month(date)=$month AND year(date)=$year ";
       $result_array = self::find_by_sql($sql);
      return !empty($result_array) ? array_shift($result_array) : false;
    }
    public static function fetch_earnings_title()
    {
      global $database;
      $sql = "SELECT * FROM earnings";

      return $result_array = self::find_by_sql($sql);
      
    }


    public static function fetch_deduction_content()
    {
      global $database;
      $sql = "SELECT s.*, t.gl,t.basic,t.rent,t.gross FROM stbiodata s INNER JOIN conpcass_contediss t ON s.paygrade=t.gl group by s.paygrade ORDER BY s.fullname ";

      return $result_array = self::find_by_sql($sql);
      
    }




    public static function fetch_deduction_content_2($status)
    {
      global $database;
      $sql = "SELECT s.*, c.gl,c.basic,c.rent,c.gross FROM stbiodata s INNER JOIN conpcass c ON s.paygrade=c.gl WHERE status=$status ";

      return $result_array = self::find_by_sql($sql);
      
    }



    public static function searchdeductname($deductionid='')
    {
      global $database;
      $sql = "SELECT * FROM deduction WHERE id=$deductionid LIMIT 1";

      $result_array = self::find_by_sql($sql);
      return !empty($result_array) ? array_shift($result_array) : false;
    }



    public static function searchearningsname($earningsid='')
    {
      global $database;
      $sql = "SELECT * FROM earnings WHERE id=$earningsid LIMIT 1";

      $result_array = self::find_by_sql($sql);
      return !empty($result_array) ? array_shift($result_array) : false;
    }




    public static function removeearnings($staffid='',$earningsid='')
    {
      global $database;
      $sql= "DELETE from addedearnings WHERE stbiodataid=$staffid AND id=$earningsid LIMIT 1";
      
      if ($database->query($sql)) {
        $id=$database->insert_id();
       return true;
        
     } else {
         return false;
     }
    
    }
    public static function removedeductionid($staffid='',$deductionid='')
    {
      global $database;
      $sql= "DELETE from addeddeduction WHERE stbiodataid=$staffid AND id=$deductionid LIMIT 1";
      
      if ($database->query($sql)) {
        $id=$database->insert_id();
       return true;
        
     } else {
         return false;
     }
    
    }
    public static function savedeductionid($staffid,$deductionid,$deduction_name,$deduction_status,$deamount)
    {
      global $database;

      $sql = "INSERT INTO addeddeduction (";
        $sql .= "stbiodataid, deductid,dname,status,amount";

        $sql .= ") VALUES ('";
        $sql .= $staffid . "','";
        $sql .= $deductionid . "','";
        $sql .= $deduction_name . "','";
        $sql .= $deduction_status . "','";
        $sql .= $deamount . "' 
       )";

        if ($database->query($sql)) {
           $id=$database->insert_id();
          return true;
           
        } else {
            return false;
        }


    }


    public static function saveearningsid($staffid,$earningsid,$earnings_name,$deamount)
    {
      global $database;

      $sql = "INSERT INTO addedearnings (";
        $sql .= "stbiodataid, earningsid,ename,amount";

        $sql .= ") VALUES ('";
        $sql .= $staffid . "','";
        $sql .= $earningsid . "','";
        $sql .= $earnings_name . "','";
       
        $sql .= $deamount . "' 
       )";

        if ($database->query($sql)) {
           $id=$database->insert_id();
          return true;
           
        } else {
            return false;
        }


    }

    public static function fetch_single_from_addeddeductions($id)
    {
      global $database;

      $sql="SELECT * FROM addeddeduction WHERE id=$id LIMIT 1";

      $result_array = self::find_by_sql($sql);
      return !empty($result_array) ? array_shift($result_array) : false;

    }


    public static function fetch_single_added_earnings($id)
    {
      global $database;

      $sql="SELECT * FROM addedearnings WHERE id=$id LIMIT 1";

      $result_array = self::find_by_sql($sql);
      return !empty($result_array) ? array_shift($result_array) : false;

    } 
    public static function fetch_single_earnings($id)
    {
      global $database;

      $sql="SELECT * FROM earnings WHERE id=$id LIMIT 1";

      $result_array = self::find_by_sql($sql);
      return !empty($result_array) ? array_shift($result_array) : false;

    } 

    public static function all_added_deduction($id)
    {
      global $database;

      $sql="SELECT * FROM addeddeduction WHERE stbiodataid=$id";
      return  $result_array = self::find_by_sql($sql);
    }

    public static function fetch_single_deductions($id)
    {
      global $database;

      $sql="SELECT * FROM deduction WHERE id=$id LIMIT 1";

      $result_array = self::find_by_sql($sql);
      return !empty($result_array) ? array_shift($result_array) : false;

    } 
   public static function update_department($deptid="",$dp="")
   {
    global $database;
   
    $sql = "UPDATE dpunit SET name='$dp' WHERE id=$deptid  LIMIT 1";
   
   
    if ($database->query($sql)) {
      $id=$database->insert_id();
      return true;
       
    } else {
        return false;
    }
   } 



  public static function  fetch_department($dept="")
    {
      $sql="SELECT * FROM dpunit WHERE id='$dept' LIMIT 1";
      $result_array = self::find_by_sql($sql);
        return !empty($result_array) ? array_shift($result_array) : false;
    }  
    
    

public static function update_basic($level='',$step='',$basic='')
{
  global $database;
  $sql = "UPDATE salstructure SET basic='$basic' WHERE level='$level' AND step='$step' LIMIT 1";
 
 
  if ($database->query($sql)) {
    $id=$database->insert_id();
    return true;
     
  } else {
      return false;
  }
}

public static function  delete_department($dept='')
{
  global $database;
  $sql="DELETE FROM dpunit WHERE id='$dept' LIMIT 1";
  if ($database->query($sql)) {
    $id=$database->insert_id();
    return true;
     
  } else {
      return false;
  }
}


public static function  delete_basic($level='',$step='',$basic='')
{
  global $database;
  $sql="DELETE FROM salstructure WHERE level='$level' AND step='$step' AND basic='$basic' LIMIT 1";
  if ($database->query($sql)) {
    $id=$database->insert_id();
    return true;
     
  } else {
      return false;
  }


}
public static function fetch_basic($level='',$step='') 
{
  global $database;

  $sql="SELECT * FROM salstructure WHERE level='$level' AND step='$step' LIMIT 1";
  $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;
} 





public static function fetch_salarystru(){

  global $database;

   $sql="SELECT * FROM salstructure";
  return $result_array=self::find_by_sql($sql);

}   
public static function fetch_all_department($dpid=''){

  global $database;

  $sql="SELECT * FROM dpunit WHERE dpunitid=$dpid ORDER BY name ";
  return $result_array=self::find_by_sql($sql);

}

public static function fetch_all_department_unit(){

  global $database;

  $sql="SELECT * FROM dpunit  ORDER BY dpunitid, name";
  return $result_array=self::find_by_sql($sql);

}




// public static function fetch_added_earnings($userid)
// {
//   global $database;
//   $sql = "SELECT * FROM addedearnings WHERE stbiodataid=$userid ";
//   return $result_array = self::find_by_sql($sql);
// }
 public static function fetch_all_earnings($userid)
 {
  global $database;
  $sql="SELECT * FROM earnings  WHERE NOT EXISTS (SELECT * FROM addedearnings WHERE earnings.id =addedearnings.earningsid AND stbiodataid=$userid)";
  return $result_array = self::find_by_sql($sql);
 }


public static function fetch_added_deductions($userid)
{
  global $database;
  $sql = "SELECT * FROM addeddeduction WHERE stbiodataid=$userid ";
  return $result_array = self::find_by_sql($sql);
}

public static function fetch_details($staffid)
{
  global $database;
  $sql = "SELECT * FROM stbiodata WHERE id=$staffid LIMIT 1";
  $result_array = self::find_by_sql($sql);
  return !empty($result_array) ? array_shift($result_array) : false;
}


public static function fetch_added_single_earnings($userid, $table)
{
  global $database;
  $sql = "SELECT t.gl,t.basic,t.rent FROM  $table t INNER JOIN stbiodata st ON st.paygrade=t.gl WHERE st.id=$userid LIMIT 1 ";
  $result_array = self::find_by_sql($sql);
  return !empty($result_array) ? array_shift($result_array) : false;

}

public static function fetch_added_earnings($userid)
{
  global $database;
  $sql = "SELECT e.* FROM addedearnings e INNER JOIN stbiodata st ON st.id=e.stbiodataid  WHERE st.id=$userid ";
  return $result_array = self::find_by_sql($sql);
}



 public static function fetch_all_deductions($userid)
 {
  global $database;
  $sql="SELECT * FROM deduction  WHERE NOT EXISTS (SELECT * FROM addeddeduction WHERE deduction.id =addeddeduction.deductid AND stbiodataid=$userid)";
  return $result_array = self::find_by_sql($sql);
 }



public static function insert_deductions($deduct, $dname)
{
  global $database;

  $deduct = $database->escape_value($deduct);
  $dname = $database->escape_value($dname);
  $sql = "INSERT INTO deduction (";
        $sql .= "name, status";

        $sql .= ") VALUES ('";
        $sql .= $dname . "','";
        $sql .= $deduct . "' 
       )";

        if ($database->query($sql)) {
          return $id=$database->insert_id();
         // return true;
           
        } else {
            return false;
        }

}
public static function insert_department($dname='',$dpid='')
{
  global $database;

  $dname = $database->escape_value($dname);
  $dpid = $database->escape_value($dpid);
  $sql = "INSERT INTO dpunit (";
        $sql .= "name, dpunitid";

        $sql .= ") VALUES ('";
        $sql .= $dname . "','";
        $sql .= $dpid . "' 
       )";

        if ($database->query($sql)) {
          $id=$database->insert_id();
          return true;
           
        } else {
            return false;
        }
}


public static function insert_salary($table,$gl,$basic, $rent, $gross){
        global $database;

        $gl = $database->escape_value($gl);
        $basic = $database->escape_value($basic);
        $rent = $database->escape_value($rent);
        $gross = $database->escape_value($gross);
            
       
        $sql = "INSERT INTO $table (";
        $sql .= "gl, basic, rent,gross";

        $sql .= ") VALUES ('";
        $sql .= $gl . "', '";
      
        $sql .= $basic . "', '";
        $sql .= $rent . "', '";
                
        $sql .= $gross . "'
          
       )";

        if ($database->query($sql)) {
          $id=$database->insert_id();
          return true;
           
        } else {
            return false;
        }


    }


    public static function insert_salary_both($gl,$basic, $rent, $gross, $status){
      global $database;

      $gl = $database->escape_value($gl);
      $basic = $database->escape_value($basic);
      $rent = $database->escape_value($rent);
      $gross = $database->escape_value($gross);
      $status = $database->escape_value($status);
          
     
      $sql = "INSERT INTO conpcass_contediss (";
      $sql .= "gl, basic, rent,gross,status";

      $sql .= ") VALUES ('";
      $sql .= $gl . "', '";
    
      $sql .= $basic . "', '";
      $sql .= $rent . "', '";
      $sql .= $gross . "', '";
      $sql .= $status . "'
        
     )";

      if ($database->query($sql)) {
        $id=$database->insert_id();
        return true;
         
      } else {
          return false;
      }


  }







public static function get_access_level($id="", $role="")
{
  global $database;

  $sql="SELECT log.*,rank.*,opr.* FROM tbl_login log inner join  tbl_rank rank on log.rid=rank.id inner join tbl_operation opr ON rank.id=opr.created_access WHERE opr.created_access=$role and rank.id=$id LIMIT 1";

  $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;
}


public static function get_staff_rank($menuid=""){

  global $database;
  
      $sql = "SELECT rk.*,br.* FROM tbl_rank rk INNER JOIN tbl_staffs st ON st.staff_branch_id=rk.id INNER JOIN tbl_branches br ON st.staff_branch_id=br.branch_id WHERE rk.id=$menuid LIMIT 1";
      $result_array = self::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;       
}

public static function add_hidden_submenu_links($menuid="", $menuList="")
{
  global $database; 

  $sql = "SELECT * FROM ".self::$tbl_operation." WHERE mainmenuid=menuid AND hidden=0  AND created_access IN ($menuList) order by mainmenuid desc";
     return $result_array = self::find_by_sql($sql);
    //return !empty($result_array) ? array_shift($result_array) : false;                    

 }
public static function add_hidden_submenu_descending_links($menuid="", $menuList="")
{
  global $database; 

  $sql = "SELECT * FROM ".self::$tbl_operation." WHERE mainmenuid=menuid AND hidden=0  AND created_access IN ($menuList) order by mainmenuid desc";
     return $result_array = self::find_by_sql($sql);
    //return !empty($result_array) ? array_shift($result_array) : false;                    

 }


}

//Common database Methods
 $group = new Setup();
?>