Added Total Spent to Customer tabular view

This commit is contained in:
FrancescoUK
2017-04-29 19:55:03 +01:00
parent ac92c16c0a
commit 4c2d63bbd3
4 changed files with 65 additions and 3 deletions

View File

@@ -17,6 +17,13 @@ class Customers extends Persons
$this->_list_id = $CI->encryption->decrypt($CI->Appconfig->get('mailchimp_list_id'));
}
public function index()
{
$data['table_headers'] = $this->xss_clean(get_customer_manage_table_headers());
$this->load->view('people/manage', $data);
}
/*
Returns customer table data rows. This will be called with AJAX.
*/
@@ -34,7 +41,21 @@ class Customers extends Persons
$data_rows = array();
foreach($customers->result() as $person)
{
$data_rows[] = get_person_data_row($person, $this);
// retrieve the total amount the customer spent so far together with min, max and average values
$stats = $this->Customer->get_stats($person->person_id);
if(empty($stats))
{
//create object with empty properties.
$stats = new stdClass;
$stats->total = 0;
$stats->min = 0;
$stats->max = 0;
$stats->average = 0;
$stats->avg_discount = 0;
$stats->quantity = 0;
}
$data_rows[] = get_customer_data_row($person, $stats, $this);
}
$data_rows = $this->xss_clean($data_rows);
@@ -90,7 +111,7 @@ class Customers extends Persons
$data['customer_sales_tax_enabled'] = FALSE;
}
// show the total amount the customer spent so far together with min, max and average values
// retrieve the total amount the customer spent so far together with min, max and average values
$stats = $this->Customer->get_stats($customer_id);
if(!empty($stats))
{

View File

@@ -192,6 +192,46 @@ function get_person_data_row($person, $controller)
));
}
function get_customer_manage_table_headers()
{
$CI =& get_instance();
$headers = array(
array('people.person_id' => $CI->lang->line('common_id')),
array('last_name' => $CI->lang->line('common_last_name')),
array('first_name' => $CI->lang->line('common_first_name')),
array('email' => $CI->lang->line('common_email')),
array('phone_number' => $CI->lang->line('common_phone_number')),
array('total' => $CI->lang->line('common_total_spent'), 'sortable' => FALSE)
);
if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id')))
{
$headers[] = array('messages' => '', 'sortable' => FALSE);
}
return transform_headers($headers);
}
function get_customer_data_row($person, $stats, $controller)
{
$CI =& get_instance();
$controller_name = strtolower(get_class($CI));
return array (
'people.person_id' => $person->person_id,
'last_name' => $person->last_name,
'first_name' => $person->first_name,
'email' => empty($person->email) ? '' : mailto($person->email, $person->email),
'phone_number' => $person->phone_number,
'total' => to_currency($stats->total),
'messages' => empty($person->phone_number) ? '' : anchor("Messages/view/$person->person_id", '<span class="glyphicon glyphicon-phone"></span>',
array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line('messages_sms_send'))),
'edit' => anchor($controller_name."/view/$person->person_id", '<span class="glyphicon glyphicon-edit"></span>',
array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update'))
));
}
function get_suppliers_manage_table_headers()
{
$CI =& get_instance();

View File

@@ -57,6 +57,7 @@ $lang["common_search_options"] = "Search options";
$lang["common_searched_for"] = "Searched for";
$lang["common_state"] = "State";
$lang["common_submit"] = "Submit";
$lang["common_total_spent"] = "Total Spent";
$lang["common_view_recent_sales"] = "View Recent Sales";
$lang["common_website"] = "website";
$lang["common_welcome"] = "Welcome";

View File

@@ -104,7 +104,7 @@ class Customer extends Person
FROM ' . $this->db->dbprefix('sales') . ' AS sales
INNER JOIN ' . $this->db->dbprefix('sales_items') . ' AS sales_items
ON sales_items.sale_id = sales.sale_id
WHERE sales.customer_id=' . $this->db->escape($customer_id) . '
WHERE sales.customer_id = ' . $this->db->escape($customer_id) . '
GROUP BY sale_id
)'
);