db->select('A.* , A.category as category_value , SUM(A.cost) as total , SUM(A.current_cost) as total_current_cost , categories.name as category_name '); $this->db->group_by('A.category'); $this->db->from('asset A'); $this->db->join('categories', 'categories.id = A.category', '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_assets($business_id , $category , $purchase_date_from = null , $purchase_date_to = null) { $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.category)', $category); if($purchase_date_from != null && $purchase_date_to != null) { $this->db->where('A.purchase_date >=', $purchase_date_from); $this->db->where('A.purchase_date <=', $purchase_date_to); } $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_category_id($id) { $this->db->select(); $this->db->from('categories'); $this->db->where('id', $id); $this->db->where('is_active', 1); $query = $this->db->get(); $query = $query->result_array(); 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_asset__id($id,$table,$business_id) { $this->db->select(); $this->db->from($table); $this->db->where('business_id', $business_id); $this->db->where('md5(id)', $id); $this->db->where('is_active', 1); $query = $this->db->get(); $query = $query->row(); 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('A.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('A.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('A.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('A.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; } public function get_asset_id($id,$table,$business_id) { $this->db->select(); $this->db->from($table); $this->db->where('business_id', $business_id); $this->db->where('md5(id)', $id); $this->db->where('is_active', 1); $query = $this->db->get(); $query = $query->row(); return $query; } public function get_latest_asset_value($asset_id,$business_id) { $this->db->select(); $this->db->from('asset_value'); $this->db->where('asset_id', $asset_id); $this->db->where('business_id', $business_id); $this->db->where('is_active', 1); $this->db->order_by('id', 'DESC'); $this->db->limit(1); $query = $this->db->get(); $query = $query->row(); return $query; } public function amc_insurance_report($type,$business_id) { $query = $this->db->query("SELECT amc.*,service_provider.name as service_provider_name,insurance_company.name as insurance_company_name, asset.id,asset.name as asset_name,asset.tag,asset.serial,asset.model,asset.purchase_date,asset.cost as purchase_cost,status.display_name as status , categories.name as category,locations.location as location,manufacturer.name as manufacturer, Supplier.name as Supplier FROM asset LEFT JOIN amc ON asset.id = amc.asset_id AND amc.created_at = (SELECT MAX(amc.created_at) FROM amc WHERE asset.id = amc.asset_id and amc.is_active=1 and amc.type=".$type.") LEFT JOIN third_parties as service_provider ON amc.service_provider = service_provider.id LEFT JOIN third_parties as insurance_company ON amc.insurance_company = insurance_company.id LEFT JOIN status ON asset.status = status.id LEFT JOIN categories ON asset.category = categories.id LEFT JOIN locations ON asset.location = locations.id LEFT JOIN third_parties as manufacturer ON asset.manufacturer = manufacturer.id LEFT JOIN third_parties as Supplier ON asset.Supplier = Supplier.id where asset.business_id =".$business_id." and asset.is_active=1"); $result =$query->result_array(); return $result; } public function depreciation_report($business_id) { $query = $this->db->query("SELECT asset_value.*, asset.id,asset.name as asset_name,asset.tag,asset.serial,asset.current_cost,asset.model,asset.purchase_date,asset.cost as purchase_cost,status.display_name as status , categories.name as category,locations.location as location,manufacturer.name as manufacturer, Supplier.name as Supplier FROM asset LEFT JOIN asset_value ON asset.id = asset_value.asset_id AND asset_value.created_at = (SELECT MAX(asset_value.created_at) FROM asset_value WHERE asset.id = asset_value.asset_id and asset_value.is_active=1) LEFT JOIN status ON asset.status = status.id LEFT JOIN categories ON asset.category = categories.id LEFT JOIN locations ON asset.location = locations.id LEFT JOIN third_parties as manufacturer ON asset.manufacturer = manufacturer.id LEFT JOIN third_parties as Supplier ON asset.Supplier = Supplier.id where asset.business_id =".$business_id." and asset.is_active=1"); $result =$query->result_array(); return $result; } public function get_third_party_value_by_md5_id($business_id , $type) { $this->db->select('B.* , state.name as state '); $this->db->from('third_parties B'); $this->db->join('state', 'state.id = B.state', 'left'); $this->db->where('B.type', $type); $this->db->where('business_id', $business_id); $this->db->where('is_active', 1); $query = $this->db->get(); $query = $query->result(); return $query; } public function delete_user_by_md5_id($id,$business_id) { $this->db->where('md5(id)', $id); if ($business_id != NULL) { $this->db->where('business_id', $business_id); } $this->db->set('is_active',0); $this->db->update('users'); return; } public function get_third_party_by_md5_id($id) { $this->db->select('B.* , state.id as state_id , state.name as state_name'); $this->db->from('third_parties B'); $this->db->join('state', 'state.id = B.state', 'left'); $this->db->where('md5(B.id)', $id); $query = $this->db->get(); $query = $query->row(); return $query; } function get_by_id($id,$table) { $this->db->select(); $this->db->from($table); $this->db->where('md5(id)', $id); $query = $this->db->get(); $query = $query->row(); return $query; } }