106 lines
3.6 KiB
PHP
106 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
|
|
use App\Models\Expense_model;
|
|
use App\Models\Supplier_model;
|
|
|
|
|
|
|
|
class Expense extends BaseController
|
|
{
|
|
protected $expense_model;
|
|
protected $supplier_model;
|
|
protected $session;
|
|
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->expense_model = new Expense_model();
|
|
$this->supplier_model = new Supplier_model();
|
|
|
|
$this->session = session();
|
|
helper('form'); //$this->load->library('form_validation');
|
|
|
|
$this->isLoggedIn();
|
|
}
|
|
public function index()
|
|
{
|
|
$data['expense_list'] = $this->expense_model->getAllExpense();
|
|
$data['supplier_list'] = json_encode($this->supplier_model->supplierlisting());
|
|
$this->global['pageTitle'] = 'Non IGR / Expense List';
|
|
// echo "<pre>";
|
|
// print_r($data);die;
|
|
$this->loadViews("expense_list", $this->global, $data, NULL);
|
|
}
|
|
|
|
function addExpense()
|
|
{
|
|
$data = array(
|
|
'transporter_file' => $this->request->getPost('transporterfile'),
|
|
'supplier_id' => $this->request->getPost('supplierid'),
|
|
'remarks' => $this->request->getPost('remarks'),
|
|
'cost' => $this->request->getPost('cost'),
|
|
'gst' => $this->request->getPost('gst'),
|
|
'total' => $this->request->getPost('total'),
|
|
'status' => $this->request->getPost('status'),
|
|
'payment_method' => $this->request->getPost('payment_method')
|
|
);
|
|
|
|
$insert_id = $this->expense_model->insertExpense($data);
|
|
|
|
if ($insert_id) {
|
|
// Return success response or redirect
|
|
// $this->session->set_flashdata('success', 'Expense added successfully.');
|
|
// redirect('your_controller/your_method'); // Replace with your redirect path
|
|
return json_encode('true');
|
|
} else {
|
|
// Return error response
|
|
// $this->session->set_flashdata('error', 'Failed to add expense.');
|
|
// redirect('your_controller/your_method'); // Replace with your redirect path
|
|
return json_encode('false');
|
|
}
|
|
}
|
|
|
|
public function getExpenseDetails() {
|
|
$id = $this->request->getPost('id');
|
|
|
|
if ($id) {
|
|
$expense = $this->expense_model->getExpenseById($id);
|
|
echo json_encode($expense);
|
|
} else {
|
|
echo json_encode(['error' => 'Invalid ID']);
|
|
}
|
|
}
|
|
|
|
public function updateExpense() {
|
|
// $id = $this->input->post('id');
|
|
// $data = [
|
|
// 'transporterfile' => $this->input->post('transporterfile'),
|
|
// 'supplierid' => $this->input->post('supplierid'),
|
|
// 'remarks' => $this->input->post('remarks'),
|
|
// 'cost' => $this->input->post('cost'),
|
|
// 'gst' => $this->input->post('gst'),
|
|
// 'total' => $this->input->post('total'),
|
|
// 'status' => $this->input->post('status'),
|
|
// 'payment_method' => $this->input->post('payment_method')
|
|
// ];
|
|
|
|
// if ($id) {
|
|
// $result = $this->Expense_model->updateExpense($id, $data);
|
|
// if ($result) {
|
|
// echo json_encode(['success' => 'Expense updated successfully']);
|
|
// } else {
|
|
// echo json_encode(['error' => 'Failed to update expense']);
|
|
// }
|
|
// } else {
|
|
// echo json_encode(['error' => 'Invalid ID']);
|
|
// }
|
|
}
|
|
}
|