I try to get sum of my price column. But I got below error.
Controller:
Model:
View:-
Any one can help me to get this total value and print?
Controller:
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Employee extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model("Login_model");
$this->load->model("Employee_model");
}
public function test(){
$inventory["employee"] = $this->Employee_model->test();
var_dump($inventory);
}
public function employee_list()
{
if ($this->session->userdata('NAME'))
{
$role = $this->session->userdata('ROLE');
if ($role>= 1)
{
$data["employee"] = $this->Employee_model->list_employee();
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('employee/employee_list',$data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
else{
$this->session->set_flashdata('message_name', 'You did not have permission to access this page.');
redirect('user/index');
}
}
else{
$this->session->set_flashdata('message_name', 'Your session has been expired. Please Login');
redirect('login/employee_login');
}
}
function suspended_list()
{
if ($this->session->userdata('NAME'))
{
$role = $this->session->userdata('ROLE');
if ($role>= 1)
{
$data["employee"] = $this->Employee_model->suspended_employee();
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('employee/suspended_employee',$data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
else{
$this->session->set_flashdata('message_name', 'You did not have permission to access this page.');
redirect('user/index');
}
}
else{
$this->session->set_flashdata('message_name', 'Your session has been expired. Please Login');
redirect('login/employee_login');
}
}
public function employee_register()
{
if ($this->session->userdata('NAME'))
{
$role = $this->session->userdata('ROLE');
//Check user rights before redirect admin area
if ($role >= 1)
{
$this->load->helper('form');
$this->load->library('form_validation');
if ($this->input->post()) {
$this->form_validation->set_rules('employee_name', 'Employee Name', 'required');
$this->form_validation->set_rules('designation', 'Designation', 'required');
$this->form_validation->set_rules('b_day', 'Birth Day', 'required');
$this->form_validation->set_rules('address', 'Personal Address', 'required');
$this->form_validation->set_rules('mobile_number', 'Mobile Number', 'required');
if ($this->form_validation->run() === TRUE) {
$this->load->model('Employee_model');
$this->Employee_model->insert();
redirect('Employee/employee_register');
}
}
$this->load->model("Inventary_model");
$company_data["company"] = $this->Inventary_model->get_company();
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('employee/new_employee', $company_data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
} else {
$this->session->set_flashdata('message_name', 'You did not have permission to access this page.');
redirect('user/index');
}
}else{
$this->session->set_flashdata('message_name', 'Your session has been expired. Please Login');
redirect('login/employee_login');
}
}
function employee_get($id)
{
if ($this->session->userdata('NAME'))
{
$role = $this->session->userdata('ROLE');
if ($role>=1)
{
$this->load->helper('form');
$this->load->library('form_validation');
if ($this->input->post()) {
$this->form_validation->set_rules('employee_name', 'Employee Name', 'required');
$this->form_validation->set_rules('designation', 'Designation', 'required');
$this->form_validation->set_rules('b_day', 'Birth Day', 'required');
$this->form_validation->set_rules('address', 'Personal Address', 'required');
$this->form_validation->set_rules('mobile_number', 'Mobile Number', 'required');
if ($this->form_validation->run() === TRUE) {
$this->load->model('Employee_model');
$upload_data= $this->Employee_model->update_employee($id);
//var_dump($upload_data); die();
redirect('Employee/employee_list');
}
}
$employee_data["row"] = $this->Employee_model->get($id);
if ($employee_data["row"] == null)
{
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('error_page/404');
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
else
{
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('employee/edit_employee', $employee_data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
}else
{
$this->session->set_flashdata('message_name', 'You did not have permission to access this page.');
redirect('user/index');
}
}else
{
$this->session->set_flashdata('message_name', 'Your session has been expired. Please Login');
redirect('login/employee_login');
}
}
public function view_profile($id)
{
if ($this->session->userdata('NAME'))
{
$role = $this->session->userdata('ROLE');
if ($role >= 1)
{
$employee_data["row"] = $this->Employee_model->view_data($id);
$employee_data["item"] = $this->Employee_model->view_inventory($id);
//var_dump($employee_data); die();
if ($employee_data["row"] == null) {
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('error_page/404');
$this->load->view('includes/footer');
$this->load->view('includes/settings');
} else {
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('employee/view_employee_profile', $employee_data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
}
else{
$this->session->set_flashdata('message_name', 'You did not have permission to access this page.');
redirect('user/index');
}
}
else
{
$this->session->set_flashdata('message_name', 'Your session has been expired. Please Login');
redirect('login/employee_login');
}
}
function personal_inventory($id)
{
$employee_data["row"] = $this->Employee_model->view_data($id);
$inventory_data["item"] = $this->Employee_model->view_inventory($id);
//Total spends for current employee
$inventory_data["total"] = $this->Employee_model->employee_spends($id);
var_dump( $inventory_data["total"]);
if ($inventory_data["item"]== null) {
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('error_page/no_records', $employee_data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
} else {
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('employee/inventory', $inventory_data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
}
function employee_total_spends($id)
{
$data = $this->Employee_model->employee_spends($id);
echo $data;
}
public function employee_update($id)
{
$this->Employee_model->update_employee($id);
redirect("employee/employee_list");
}
public function employee_suspend($id)
{
$this->Employee_model->suspend_employee($id);
redirect('employee/employee_list');
}
public function white_list_employee($id)
{
$this->Employee_model->unblock_employee($id);
redirect('employee/employee_list');
}
}
Model:
PHP Code:
<?php
Class Employee_model extends CI_model
{
public function __construct()
{
parent:: __construct();
}
public function test()
{
$query = $this->db->query("SELECT
sgh.employee.id,
sgh.employee.employee_name
FROM sgh.inventory,
sgh.employee WHERE sgh.inventory.employee_id=sgh.employee.id");
$row = $query->result();
return $row;
}
public function insert()
{
$config['upload_path'] = './uploads/employee/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 5000000000;
$config['max_width'] = 5000;
$config['max_height'] = 5000;
$this->load->library('upload', $config); //Enable upload library and pass data as $config variable
//upload image
if ($this->upload->do_upload('photo'))
{
echo "File 1 Upload Success!";
$upload_data = $this->upload->data();
$data['photo'] = "uploads/employee/".$upload_data['file_name']; //.$upload_data['file_name']; = Dispaly file name & upload path
}else{
echo $this->upload->display_errors();
}
$data['employee_name'] = $this->input->post('employee_name');
$data['company_id'] = $this->input->post('company_id');
$data['join_date'] = $this->input->post('join_date');
$data['b_day'] = $this->input->post('b_day');
$data['address'] = $this->input->post('address');
$data['mobile_number'] = $this->input->post('mobile_number');
$data['status'] = 0;
$data['created_by'] = $this->session->userdata('ID');
$this->db->insert('employee', $data);
}
public function get_company()
{
$query = $this->db->query("SELECT * FROM company WHERE id>=1");
$result = $query->result();
return $result;
}
public function list_employee()
{
$query = $this->db->query("SELECT
sgh.employee.id,
sgh.employee.employee_name,
sgh.employee.designation,
sgh.employee.mobile_number,
sgh.company.company_name,
sgh.employee.company_id
FROM
sgh.company,
sgh.employee WHERE sgh.employee.company_id=sgh.company.id AND employee.status=0");
$row = $query->result_array();
return $row;
}
function suspended_employee()
{
$query = $this->db->query("SELECT
sgh.employee.id,
sgh.employee.employee_name,
sgh.employee.designation,
sgh.employee.mobile_number,
sgh.company.company_name,
sgh.employee.company_id
FROM
sgh.company,
sgh.employee WHERE sgh.employee.company_id=sgh.company.id AND employee.status=1");
$row = $query->result_array();
return $row;
}
public function get($id)
{
$query = $this->db->query("SELECT
sgh.employee.id,
sgh.employee.employee_name,
sgh.employee.designation,
sgh.employee.join_date,
sgh.employee.b_day,
sgh.employee.address,
sgh.employee.mobile_number,
sgh.employee.photo,
sgh.company.company_name,
sgh.employee.company_id
FROM
sgh.company,
sgh.employee WHERE sgh.employee.company_id=sgh.company.id AND sgh.employee.id='$id'");
$employee_data = $query->row();
return $employee_data;
}
public function view_data($id)
{
$query = $this->db->query("SELECT
sgh.employee.id,
sgh.employee.employee_name,
sgh.employee.designation,
sgh.employee.join_date,
sgh.employee.b_day,
sgh.employee.address,
sgh.employee.mobile_number,
sgh.employee.photo,
sgh.company.company_name,
sgh.employee.company_id
FROM
sgh.company,
sgh.employee WHERE sgh.employee.company_id=sgh.company.id AND sgh.employee.id='$id'");
$employee_data = $query->row();
return $employee_data;
}
public function view_inventory($id){
$query = $this->db->query("SELECT sgh.inventory.id,
sgh.inventory.item_name,
sgh.inventory.price,
sgh.inventory.qty,
sgh.inventory.serial_number,
sgh.inventory.product_key,
sgh.employee.id,
sgh.employee.employee_name
FROM sgh.inventory,
sgh.employee WHERE sgh.inventory.employee_id=sgh.employee.id AND sgh.employee.id='$id'");
$item_data = $query->result_array();
return $item_data;
}
function employee_spends($id)
{
$query = $this->db->query(" SELECT SUM(price) FROM inventory WHERE employee_id='$id'");
$row = $query->row();
return $row;
}
public function user_name($id){
$query = $this->db->query("SELECT sgh.inventory.id,
sgh.employee.id,
sgh.employee.employee_name
FROM sgh.inventory,
sgh.employee WHERE sgh.inventory.employee_id=sgh.employee.id AND sgh.employee.id='$id'");
$item_data = $query-> result();
return $item_data;
}
public function update_employee($id)
{
$config['upload_path'] = './uploads/employee/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 5000000000;
$config['max_width'] = 5000;
$config['max_height'] = 5000;
$this->load->library('upload', $config); //Enable upload library and pass data as $config variable
//upload image
if ($this->upload->do_upload('photo'))
{
echo "File 1 Upload Success!";
$upload_data = $this->upload->data();
$data['photo'] = "uploads/employee/".$upload_data['file_name']; //.$upload_data['file_name']; = Dispaly file name & upload path
}else{
echo $this->upload->display_errors();
}
$data['employee_name'] = $this->input->post('employee_name');
$data['company_id'] = $this->input->post('company_id');
$data['designation'] = $this->input->post('designation');
$data['join_date'] = $this->input->post('join_date');
$data['b_day'] = $this->input->post('b_day');
$data['address'] = $this->input->post('address');
$data['mobile_number'] = $this->input->post('mobile_number');
$data['status'] = 0;
$data['created_by'] = $this->session->userdata('ID');
$this->db->where('id', $id);
$this->db->update('employee', $data);
}
public function suspend_employee($id)
{
$data["status"] = 1;
$this->db->where('id', $id);
$this->db->update('employee', $data);
}
public function unblock_employee($id)
{
$data["status"] = 0;
$this->db->where('id', $id);
$this->db->update('employee', $data);
}
}
PHP Code:
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h2>Personal Inventory Area</h2>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div style="margin-bottom: 10px;" >
<a href="<?= base_url() ?>employee/employee_list/" class="btn btn-info btn-lg">Back
to List</a>
</div>
<div class="box">
<div class="box-header">
<h3 class="box-title">Inventory Items</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="example1" class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Item Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Serial Number</th>
<th>Product Key</th>
</tr>
</thead>
<tbody>
<?php
foreach ($item as $row){
?>
<tr>
<td><?=$row["item_name"]?></td>
<td class="text-left">Rs. <?=$row["price"]?>.00</td>
<td><?=$row["qty"]?></td>
<td><?=$row["serial_number"]?></td>
<td><?=$row["product_key"]?></td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<th>Item Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Serial Number</th>
<th>Product Key</th>
</tr>
</tfoot>
</table>
</div>
<div>
<P>Total Spends is <?=$row->price?></P>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->