59 lines
1.8 KiB
PHP
Executable File
59 lines
1.8 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 = [
|
|
'serial_number' , 'transporter_file', 'supplier_id', 'remarks', 'item_description', 'cost', 'cgst', 'sgst', 'igst', 'total', 'bill_no' ,'bill_date'
|
|
];
|
|
|
|
public function getLastSerialNumber($financialYear)
|
|
{
|
|
return $this->db->table('t_expense')
|
|
->select('serial_number')
|
|
->like('serial_number', "$financialYear/", 'after')
|
|
->orderBy('serial_number', 'DESC')
|
|
->limit(1)
|
|
->get()
|
|
->getRow('serial_number');
|
|
}
|
|
|
|
// 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]);
|
|
}
|
|
}
|
|
?>
|