<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Laporan_model extends CI_Model {
    private $table = 'laporan';
    public function get_by_penghuni($id_penghuni) {
        $this->db->where('id_penghuni', $id_penghuni);
        $this->db->order_by('tanggal_laporan', 'DESC');
        return $this->db->get($this->table)->result();
    }
    public function get_by_id($id_laporan) {
        $this->db->where('id_laporan', $id_laporan);
        return $this->db->get($this->table)->row();
    }
    public function insert($data) {
        return $this->db->insert($this->table, $data);
    }
    public function update($id_laporan, $data) {
        $this->db->where('id_laporan', $id_laporan);
        return $this->db->update($this->table, $data);
    }
    public function delete($id_laporan) {
        $this->db->where('id_laporan', $id_laporan);
        return $this->db->delete($this->table);
    }
    public function count_by_status($id_penghuni, $status) {
        $this->db->where('id_penghuni', $id_penghuni);
        $this->db->where('status', $status);
        return $this->db->count_all_results($this->table);
    }
}