ria/app/Models/Expense_model.php
2024-08-27 11:31:42 +05:30

39 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class Expense_model extends Model
{
protected $table = 't_expense'; // Table name
protected $primaryKey = 'id'; // Primary key
protected $allowedFields = [
'transporterfile', 'supplier_id', 'remarks', 'cost', 'gst', 'total', 'status', 'payment_method'
];
// Retrieve all active expenses
public function getAllExpense() {
return $this->join('t_supplierdetailsn', 't_expense.supplier_id = t_supplierdetailsn.SupplierID')
->where('t_expense.isactive', 1)
->orderBy('t_expense.created_on', 'DESC')
->findAll();
}
// Insert new expense
public function insertExpense($data) {
return $this->insert($data) ? $this->insertID() : false;
}
// Get expense by ID
public function getExpenseById($id) {
return $this->where($this->primaryKey, $id)->first(); // Use primary key
}
// Update expense by ID
public function updateExpense($id, $data) {
return $this->update($id, $data); // Use primary key
}
}
?>