ria/app/Models/Expense_model.php
2024-10-16 19:07:26 +05:30

48 lines
1.4 KiB
PHP
Executable File

<?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 = [
'transporter_file', 'supplier_id', 'remarks', 'item_description', 'cost', 'cgst', 'sgst', 'igst', 'total',
];
// Retrieve all active expenses
public function getAllExpense($fromDate,$toDate) {
return $this->join('t_supplierdetailsn', 't_expense.supplier_id = t_supplierdetailsn.SupplierID')
->where('t_expense.isactive', 1)
->where('t_expense.created_on >=',"$fromDate")
->where('t_expense.created_on <=',"$toDate")
->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
}
public function deleteFile($expenseId)
{
// Update the database to set transporter_file to null
return $this->update($expenseId, ['transporter_file' => null]);
}
}
?>