113 lines
4.3 KiB
PHP
113 lines
4.3 KiB
PHP
<?php
|
|
class Asset_model extends MY_Model {
|
|
|
|
public function get_assets($business_id)
|
|
{
|
|
$this->db->select('A.* , categories.name as category_name , third_parties.name as manufacturer_name ,tp.name as supplier_name , locations.location as location_name , status.display_name as status_display_name');
|
|
$this->db->from('asset A');
|
|
$this->db->join('categories', 'categories.id = A.category', 'left');
|
|
$this->db->join('third_parties', 'third_parties.id = A.manufacturer', 'left');
|
|
$this->db->join('third_parties as tp', 'tp.id = A.supplier', 'left');
|
|
$this->db->join('locations', 'locations.id = A.location', 'left');
|
|
$this->db->join('status', 'status.id = A.status', 'left');
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->order_by('A.id','ASC');
|
|
$this->db->where('A.is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
|
|
public function get_asset_by_md5_id($id,$business_id)
|
|
{
|
|
$this->db->select('A.* , categories.name as category_name , third_parties.name as manufacturer_name ,tp.name as supplier_name , locations.location as location_name, status.display_name as status_display_name ');
|
|
$this->db->from('asset A');
|
|
$this->db->join('categories', 'categories.id = A.category', 'left');
|
|
$this->db->join('third_parties', 'third_parties.id = A.manufacturer', 'left');
|
|
$this->db->join('third_parties as tp', 'tp.id = A.supplier', 'left');
|
|
$this->db->join('locations', 'locations.id = A.location', 'left');
|
|
$this->db->join('status', 'status.id = A.status', 'left');
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->where('md5(A.id)', $id);
|
|
$query = $this->db->get();
|
|
$query = $query->row();
|
|
return $query;
|
|
}
|
|
|
|
|
|
|
|
public function get_by_asset_id($id,$table,$business_id)
|
|
{
|
|
$this->db->select();
|
|
$this->db->from($table);
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->where('md5(asset_id)', $id);
|
|
$this->db->where('is_active', 1);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
public function get_amc_with_join($id,$business_id)
|
|
{
|
|
$this->db->select('A.* , third_parties.name as service_provider_name ');
|
|
$this->db->from('amc A');
|
|
$this->db->join('third_parties', 'third_parties.id = A.service_provider', 'left');
|
|
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->where('md5(A.asset_id)', $id);
|
|
$this->db->where('is_active', 1);
|
|
$this->db->where('A.type', 3);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
public function get_amc_by_id_with_join($id)
|
|
{
|
|
$this->db->select('A.* , third_parties.name as service_provider_name ');
|
|
$this->db->from('amc A');
|
|
$this->db->join('third_parties', 'third_parties.id = A.service_provider', 'left');
|
|
$this->db->where('md5(A.id)', $id);
|
|
$this->db->where('is_active', 1);
|
|
$this->db->where('A.type', 3);
|
|
$query = $this->db->get();
|
|
$query = $query->row();
|
|
return $query;
|
|
}
|
|
|
|
public function get_insurance_with_join($id,$business_id)
|
|
{
|
|
$this->db->select('A.* , third_parties.name as insurance_company_name ');
|
|
$this->db->from('amc A');
|
|
$this->db->join('third_parties', 'third_parties.id = A.insurance_company', 'left');
|
|
$this->db->where('A.business_id', $business_id);
|
|
$this->db->where('md5(A.asset_id)', $id);
|
|
$this->db->where('is_active', 1);
|
|
$this->db->where('A.type', 4);
|
|
$query = $this->db->get();
|
|
$query = $query->result();
|
|
return $query;
|
|
}
|
|
public function get_insurance_by_id_with_join($id)
|
|
{
|
|
$this->db->select('A.* , third_parties.name as insurance_company_name ');
|
|
$this->db->from('amc A');
|
|
$this->db->join('third_parties', 'third_parties.id = A.insurance_company', 'left');
|
|
$this->db->where('md5(A.id)', $id);
|
|
$this->db->where('is_active', 1);
|
|
$this->db->where('A.type', 4);
|
|
$query = $this->db->get();
|
|
$query = $query->row();
|
|
return $query;
|
|
}
|
|
public function delete_by_md5_id($id,$business_id,$table)
|
|
{
|
|
$this->db->where('md5(id)', $id);
|
|
$this->db->where('business_id', $business_id);
|
|
$this->db->set('is_active',0);
|
|
$this->db->update($table);
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
} |