66 lines
2.6 KiB
PHP
Executable File
66 lines
2.6 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','status','created_by','updated_by'
|
|
];
|
|
|
|
public function getLastSerialNumber()
|
|
{
|
|
return $this->db->table('t_expense')
|
|
->select('serial_number')
|
|
->orderBy('id', 'DESC')
|
|
->limit(1)
|
|
->get()
|
|
->getRow('serial_number');
|
|
}
|
|
|
|
// Retrieve all active expenses
|
|
public function getAllExpense($fromDate,$toDate) {
|
|
|
|
return $this->db->table('t_expense')
|
|
->select([
|
|
"t_expense.id","t_expense.serial_number","t_expense.transporter_file","t_expense.supplier_id","t_expense.item_description","t_expense.cost","t_expense.cgst","t_expense.sgst","t_expense.igst","t_expense.total","t_expense.remarks","t_expense.status","t_expense.payment_method","t_expense.created_on","t_expense.created_by","t_expense.updated_on","t_expense.updated_by","t_expense.isactive","t_expense.bill_no","t_expense.bill_date",
|
|
"t_supplierdetailsn.SupplierName",
|
|
"CONCAT_WS(' ', emp.FirstName, emp.LastName) as created_name"
|
|
])
|
|
->join('t_supplierdetailsn', 't_expense.supplier_id = t_supplierdetailsn.SupplierID', 'left')
|
|
->join('tbl_users as creator', ' t_expense.created_by = creator.userid', 'left')
|
|
->join('t_employee_details as emp', 'emp.empid=creator.empid', 'left')
|
|
->where('t_expense.isactive', 1)
|
|
->where('t_expense.created_on >=',"$fromDate")
|
|
->orderBy('t_expense.created_on', 'DESC')
|
|
->get()->getResult();
|
|
}
|
|
|
|
// 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]);
|
|
}
|
|
}
|
|
?>
|