File: /home/cafsindia/allyindian_com/backend/application/models/Package_model.php
<?php
class Package_model extends CI_Model{
public function search($search,$rows = 0,$limit_from= 0,$sort='status',$order='asc'){
$this->db->select('*');
$this->db->from('package');
$this->db->where('status',1)->or_where('status',0);
$this->db->group_start();
$this->db->like('package_id',$search);
$this->db->or_like('package_title',$search);
$this->db->or_like('package_title2',$search);
$this->db->group_end();
$this->db->order_by('status',DESC);
if($rows>0){
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
public function GetInfo($package_id){
$this->db->from('package');
$this->db->where('package_id',$package_id);
$a=$this->db->get();
if($a->num_rows() === 1){
return $a->row();
}else{
foreach ($this->db->list_fields('package') as $field){
$PersonObj->field= '';
}
return $PersonObj;
}
}
public function get_found_rows($search){
$this->db->select('*');
$this->db->from('package');
$this->db->where('status',1)->or_where('status',0);
return $this->db->get()->num_rows();
}
public function get_boarding(){
$this->db->from('boarding_point');
$this->db->order_by('boarding_name', 'asc');
$this->db->where('status',1);
return $this->db->get()->result_array();
}
public function get_package_type(){
$this->db->from('package_type');
$this->db->where('status',1);
return $this->db->get()->result_array();
}
public function get_vehicle_category(){
$this->db->from('veh_category');
$this->db->where('status',1);
return $this->db->get()->result_array();
}
public function get_vehicle_type($id){
$this->db->from('veh_type');
$this->db->where('veh_category', $id);
$this->db->where('status', 1);
return $this->db->get()->result();
}
public function get_vehicle(){
$this->db->from('vehicle');
$this->db->order_by('vehicle_no', 'asc');
$this->db->where('status',1);
return $this->db->get()->result_array();
}
public function get_vehicles($id){
$this->db->from('vehicle');
$this->db->join('veh_type', 'veh_type.veh_type_id = vehicle.vehicle_type');
$this->db->where('vehicle_type', $id);
$this->db->where('vehicle.status', 1);
return $this->db->get()->result();
}
public function get_cancelfee(){
$this->db->from('cancelfee');
return $this->db->get()->result_array();
}
public function save_package(&$package_data,$package_id= FALSE){
if(!$this->present($package_id, TRUE) || !$package_id){
if($this->db->insert('package',$package_data)){
$pack_id = $this->db->insert_id();
$this->save_package_log($package_data,$pack_id,"INSERT");
return true;
}else{
return False;
}
}else{
$this->db->where('package_id',$package_id);
$this->db->update('package',$package_data);
return $this->save_package_log($package_data,$package_id,"UPDATE");
}
}
public function save_package_log($package_data,$package_id,$operation){
$log_data = array(
'package_id' => $package_id,
'region' => $package_data['region'],
'operation' => $operation,
'package_title' => $package_data['package_title'],
'package_title2' => $package_data['package_title2'],
'package_title3' => $package_data['package_title3'],
'duration' => $package_data['duration'],
'dep_date' => $package_data['dep_date'],
'discountdetail' => $package_data['discountdetail'],
'servicetax' => $package_data['servicetax'],
'cancelfee' => $package_data['cancelfee'],
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date('Y-m-d h:i:s')
);
return $this->db->insert('package_log',$log_data);
}
public function present($package_id){
$this->db->from('package');
$this->db->where('package_id',$package_id);
return $this->db->get()->num_rows();
}
public function save_trip_details($trip_data,$trip_id){
$package_id = $trip_data['trippackid'];
$vehicleid = $trip_data['vehicleid'];
$vehicle_data = $this->get_vehicle_data($vehicleid);
$trip_data['vehiclename'] = $vehicle_data->vehicle_no;
$trip_data['vehicle_lower'] = $vehicle_data->vehicle_lower;
$trip_data['vehicle_upper'] = $vehicle_data->vehicle_upper;
$trip_data['vehiclecapacity'] = $vehicle_data->seat_capacity;
$trip_data['seat_type'] = $vehicle_data->seat_type;
$trip_data['multi_type'] = $vehicle_data->multi_type;
$trip_data['no_of_seats_up'] = $vehicle_data->no_of_seats_up;
$trip_data['seats_per_row_up'] = $vehicle_data->seats_per_row_up;
$trip_data['seats_in_last_row_up'] = $vehicle_data->seats_in_last_row_up;
$trip_data['no_of_seats_low'] = $vehicle_data->no_of_seats_low;
$trip_data['seats_per_row_low'] = $vehicle_data->seats_per_row_low;
$trip_data['seats_in_last_row_low'] = $vehicle_data->seats_in_last_row_low;
if(!$trip_id){
$exist_pack = $this->get_existing_trip($package_id);
$tripcode = $exist_pack + 1;
$trip_data['tripcode'] = "TRIP-00".$tripcode;
if($this->db->insert('vehicletrips',$trip_data)){
return $this->get_trip_data($package_id);
}else{
return False;
}
}
$this->db->where('tripid',$trip_id);
$this->db->update('vehicletrips',$trip_data);
return $this->get_trip_data($package_id);
}
public function get_vehicle_data($vehicleid){
$this->db->from('vehicle');
$this->db->where('vehicle_id',$vehicleid);
return $this->db->get()->row();
}
public function get_trip_data($package_id){
$this->db->select("*,(select count(orderid) from sblttweb_ticketorder where packid = '$package_id' and orderstat = '1') as count,sblttweb_veh_category.veh_category as cat");
$this->db->from('vehicletrips');
$this->db->join('vehicle', 'vehicle.vehicle_id = vehicletrips.vehicleid');
$this->db->join('veh_type', 'veh_type.veh_type_id = vehicle.vehicle_type');
$this->db->join('veh_category', 'veh_category.veh_cat_id = veh_type.veh_category');
$this->db->where('trippackid', $package_id);
$this->db->where('vehicletrips.status', 1);
return $this->db->get()->result_array();
}
public function get_trips($tripid){
$this->db->from('vehicletrips');
$this->db->join('vehicle', 'vehicle.vehicle_id = vehicletrips.vehicleid');
$this->db->join('veh_type', 'veh_type.veh_type_id = vehicle.vehicle_type');
$this->db->join('veh_category', 'veh_category.veh_cat_id = veh_type.veh_category');
$this->db->where('tripid', $tripid);
$this->db->where('vehicletrips.status', 1);
return $this->db->get()->result_array();
}
public function get_existing_trip($package_id){
$this->db->from('vehicletrips');
$this->db->where('trippackid',$package_id);
$this->db->where('status', 1);
return $this->db->get()->num_rows();
}
/** START Boarding Details Insert / Update **/
public function save_boarding_details($boarding_data,$boarding_id){
$package_id = $boarding_data['package_id'];
if(!$boarding_id){
if($this->db->insert('boarding',$boarding_data)){
return $this->get_boarding_data($package_id);
}else{
return False;
}
}
$this->db->where('boarding_id',$boarding_id);
$this->db->update('boarding',$boarding_data);
return $this->get_boarding_data($package_id);
}
public function get_boarding_data($package_id){
$this->db->from('boarding');
$this->db->join('boarding_point', 'boarding_point.board_point_id = boarding.board_point_id');
$this->db->where('package_id', $package_id);
$this->db->where('boarding.status', 1);
return $this->db->get()->result_array();
}
public function get_boarding_up($boarding_id){
$this->db->from('boarding');
$this->db->join('boarding_point', 'boarding_point.board_point_id = boarding.board_point_id');
$this->db->where('boarding_id', $boarding_id);
$this->db->where('boarding.status', 1);
return $this->db->get()->result_array();
}
/** END Boarding Details Insert / Update **/
/** START Tariff Details Insert / Update **/
public function save_tariff_details($tariff_data,$pcostid){
$package_id = $tariff_data['packid'];
if(!$pcostid){
if($this->db->insert('packcost',$tariff_data)){
return $this->get_tariff_data($package_id);
}else{
return False;
}
}
$this->db->where('pcostid',$pcostid);
$this->db->update('packcost',$tariff_data);
return $this->get_tariff_data($package_id);
}
public function get_tariff_data($package_id){
$this->db->from('packcost');
$this->db->join('package_type', 'package_type.package_type_id = packcost.packtypeid');
$this->db->where('packid', $package_id);
$this->db->where('pcoststatus', 1);
return $this->db->get()->result_array();
}
public function get_tariff_up($pcostid){
$this->db->from('packcost');
$this->db->join('package_type', 'package_type.package_type_id = packcost.packtypeid');
$this->db->where('pcostid', $pcostid);
return $this->db->get()->result_array();
}
/** END Tariff Details Insert / Update **/
public function save_itinerary($itinerary_data,$itinerary_id){
$package_id = $itinerary_data['itpackid'];
if(!$itinerary_id){
$this->db->insert('itinerary',$itinerary_data);
return $this->get_itinerary_data($package_id);
}else{
$this->db->where('itid',$itinerary_id);
$this->db->update('itinerary',$itinerary_data);
return $this->get_itinerary_data($package_id);
}
}
public function get_itinerary_data($package_id){
$this->db->from('itinerary');
$this->db->where('itpackid', $package_id);
$this->db->where('itstatus', 1);
return $this->db->get()->result_array();
}
public function get_itinerary($itid){
$this->db->from('itinerary');
$this->db->where('itid', $itid);
$this->db->where('itstatus', 1);
return $this->db->get()->result_array();
}
public function delete_list($package_ids){
$this->db->where_in('package_id',$package_ids);
return $this->db->update('package',array('status'=>2,'deleted_by' => $this->session->userdata('emp_id'),'deleted_date' => date('Y-m-d h:i:s')));
}
}
?>