Fixes to reports tax summary and rewards regressions

This commit is contained in:
FrancescoUK
2017-06-04 10:46:24 +01:00
parent 8f019b4631
commit 91fd435cca
9 changed files with 146 additions and 86 deletions

View File

@@ -2,7 +2,7 @@
require_once("Secure_Controller.php");
class Config extends Secure_Controller
class Config extends Secure_Controller
{
public function __construct()
{
@@ -86,11 +86,11 @@ class Config extends Secure_Controller
foreach($array as $key => $val)
{
if(is_array($val) && $key == 'dependencies')
{
{
foreach($val as $key1 => $val1)
{
if(is_array($val1))
{
{
$license[$i]['text'] .= 'component: ' . $key1 . "\n";
foreach($val1 as $key2 => $val2)
@@ -121,7 +121,7 @@ class Config extends Secure_Controller
}
}
}
$license[$i]['text'] = $this->xss_clean($license[$i]['text']);
}
@@ -140,7 +140,7 @@ class Config extends Secure_Controller
if(is_array($val))
{
$license[$i]['text'] .= 'component: ' . $key . "\n";
foreach($val as $key1 => $val1)
{
if(is_array($val1))
@@ -221,7 +221,7 @@ class Config extends Secure_Controller
else
{
$data['mailchimp']['api_key'] = '';
$data['mailchimp']['list_id'] = '';
$data['mailchimp']['list_id'] = '';
}
// load mailchimp lists associated to the given api key, already XSS cleaned in the private function
@@ -241,7 +241,7 @@ class Config extends Secure_Controller
'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'),
'fax' => $this->input->post('fax'),
'website' => $this->input->post('website'),
'website' => $this->input->post('website'),
'return_policy' => $this->input->post('return_policy')
);
@@ -334,7 +334,7 @@ class Config extends Secure_Controller
'dateformat' => $this->input->post('dateformat'),
'timeformat' => $this->input->post('timeformat'),
'thousands_separator' => $this->input->post('thousands_separator'),
'number_locale' => $this->input->post('number_locale'),
'number_locale' => $this->input->post('number_locale'),
'currency_decimals' => $this->input->post('currency_decimals'),
'tax_decimals' => $this->input->post('tax_decimals'),
'quantity_decimals' => $this->input->post('quantity_decimals'),
@@ -363,7 +363,7 @@ class Config extends Secure_Controller
{
$password = $this->encryption->encrypt($this->input->post('smtp_pass'));
}
$batch_save_data = array(
'protocol' => $this->input->post('protocol'),
'mailpath' => $this->input->post('mailpath'),
@@ -393,13 +393,13 @@ class Config extends Secure_Controller
$password = $this->encryption->encrypt($this->input->post('msg_pwd'));
}
$batch_save_data = array(
$batch_save_data = array(
'msg_msg' => $this->input->post('msg_msg'),
'msg_uid' => $this->input->post('msg_uid'),
'msg_pwd' => $password,
'msg_src' => $this->input->post('msg_src')
);
$result = $this->Appconfig->batch_save($batch_save_data);
$success = $result ? TRUE : FALSE;
@@ -429,7 +429,7 @@ class Config extends Secure_Controller
}
}
}
return $result;
}
@@ -437,7 +437,7 @@ class Config extends Secure_Controller
AJAX call from mailchimp config form to fetch the Mailchimp lists when a valid API key is inserted
*/
public function ajax_check_mailchimp_api_key()
{
{
// load mailchimp lists associated to the given api key, already XSS cleaned in the private function
$lists = $this->_mailchimp($this->input->post('mailchimp_api_key'));
$success = count($lists) > 0 ? TRUE : FALSE;
@@ -464,7 +464,7 @@ class Config extends Secure_Controller
'mailchimp_api_key' => $api_key,
'mailchimp_list_id' => $list_id
);
$result = $this->Appconfig->batch_save($batch_save_data);
$success = $result ? TRUE : FALSE;
@@ -473,34 +473,34 @@ class Config extends Secure_Controller
'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
));
}
public function stock_locations()
public function stock_locations()
{
$stock_locations = $this->Stock_location->get_all()->result_array();
$stock_locations = $this->xss_clean($stock_locations);
$this->load->view('partial/stock_locations', array('stock_locations' => $stock_locations));
}
public function dinner_tables()
}
public function dinner_tables()
{
$dinner_tables = $this->Dinner_table->get_all()->result_array();
$dinner_tables = $this->xss_clean($dinner_tables);
$this->load->view('partial/dinner_tables', array('dinner_tables' => $dinner_tables));
}
public function customer_rewards()
public function customer_rewards()
{
$customer_rewards = $this->Customer_rewards->get_all()->result_array();
$customer_rewards = $this->xss_clean($customer_rewards);
$this->load->view('partial/customer_rewards', array('customer_rewards' => $customer_rewards));
}
private function _clear_session_state()
{
$this->sale_lib->clear_sale_location();
@@ -511,11 +511,11 @@ class Config extends Secure_Controller
$this->receiving_lib->clear_stock_destination();
$this->receiving_lib->clear_all();
}
public function save_locations()
public function save_locations()
{
$this->db->trans_start();
$deleted_locations = $this->Stock_location->get_allowed_locations();
foreach($this->input->post() as $key => $value)
{
@@ -539,16 +539,19 @@ class Config extends Secure_Controller
}
$this->db->trans_complete();
$success = $this->db->trans_status();
echo json_encode(array('success' => $success, 'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')));
echo json_encode(array(
'success' => $success,
'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
));
}
public function save_tables()
public function save_tables()
{
$this->db->trans_start();
$this->Appconfig->save('dinner_table_enable',$this->input->post('dinner_table_enable'));
$deleted_tables = $this->Dinner_table->get_all()->result_array();
@@ -574,65 +577,73 @@ class Config extends Secure_Controller
foreach ($deleted_tables as $dinner_table)
{
if(!in_array($dinner_table['dinner_table_id'],$not_to_delete))
{
{
$this->Dinner_table->delete($dinner_table['dinner_table_id']);
}
}
$this->db->trans_complete();
$success = $this->db->trans_status();
echo json_encode(array('success' => $success, 'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')));
echo json_encode(array(
'success' => $success,
'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
));
}
public function save_rewards()
public function save_rewards()
{
$this->db->trans_start();
$this->Appconfig->save('customer_reward_enable',$this->input->post('customer_reward_enable'));
$deleted_packages = $this->Customer_rewards->get_all()->result_array();
$not_to_delete = array();
$array_save = array();
foreach($this->input->post() as $key => $value)
{
if (strstr($key, 'reward_points') && $key != 'customer_reward_enable')
{
if(strstr($key, 'reward_points') && $key != 'customer_reward_enable')
{
$customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
$not_to_delete[] = $customer_reward_id;
$array_save[$customer_reward_id]['points_percent'] = $value;
}
if (strstr($key, 'customer_reward') && $key != 'customer_reward_enable')
if(strstr($key, 'customer_reward') && $key != 'customer_reward_enable')
{
$customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
$not_to_delete[] = $customer_reward_id;
$array_save[$customer_reward_id]['package_name'] = $value;
}
}
if(!empty($array_save))
foreach ($array_save as $key => $value) {
{
foreach($array_save as $key => $value)
{
// save or update
$table_data = array('package_name' => $value['package_name'],'points_percent' => $value['points_percent']);
if ($this->Customer_rewards->save($table_data, $key))
{
$this->_clear_session_state();
}
}
}
// all locations not available in post will be deleted now
foreach ($deleted_packages as $customer_reward)
foreach($deleted_packages as $customer_reward)
{
if(!in_array($customer_reward['customer_reward_id'],$not_to_delete))
{
{
$this->Customer_rewards->delete($customer_reward['customer_reward_id']);
}
}
$this->db->trans_complete();
$success = $this->db->trans_status();
echo json_encode(array(
'success' => $success,
'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
@@ -660,7 +671,7 @@ class Config extends Secure_Controller
$result = $this->Appconfig->batch_save($batch_save_data);
$success = $result ? TRUE : FALSE;
echo json_encode(array(
'success' => $success,
'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
@@ -735,7 +746,7 @@ class Config extends Secure_Controller
public function remove_logo()
{
$result = $this->Appconfig->batch_save(array('company_logo' => ''));
echo json_encode(array('success' => $result));
}
@@ -755,7 +766,7 @@ class Config extends Secure_Controller
return strlen($this->upload->display_errors()) == 0 || !strcmp($this->upload->display_errors(), '<p>'.$this->lang->line('upload_no_file_selected').'</p>');
}
private function _check_encryption()
{
$encryption_key = $this->config->item('encryption_key');
@@ -782,7 +793,7 @@ class Config extends Secure_Controller
// Chmod the file
@chmod($config_path, 0777);
// Write the new config.php file
$handle = fopen($config_path, 'w+');
@@ -797,10 +808,10 @@ class Config extends Secure_Controller
// Chmod the file
@chmod($config_path, 0444);
return $result;
}
return TRUE;
}

View File

@@ -750,7 +750,9 @@ class Reports extends Secure_Controller
{
$details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], to_quantity_decimals($drow['quantity_purchased']), to_currency($drow['subtotal']), to_currency($drow['tax']), to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%'));
}
if(isset($report_data['rewards'][$key])){
if(isset($report_data['rewards'][$key]))
{
foreach($report_data['rewards'][$key] as $drow)
{
$details_data_rewards[$row['sale_id']][] = $this->xss_clean(array($drow['used'], $drow['earned']));
@@ -801,6 +803,7 @@ class Reports extends Secure_Controller
$summary_data = array();
$details_data = array();
$details_data_rewards = array();
foreach($report_data['summary'] as $key => $row)
{
@@ -821,6 +824,14 @@ class Reports extends Secure_Controller
{
$details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], to_quantity_decimals($drow['quantity_purchased']), to_currency($drow['subtotal']), to_currency($drow['tax']), to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%'));
}
if(isset($report_data['rewards'][$key]))
{
foreach($report_data['rewards'][$key] as $drow)
{
$details_data_rewards[$row['sale_id']][] = $this->xss_clean(array($drow['used'], $drow['earned']));
}
}
}
$employee_info = $this->Employee->get_info($employee_id);
@@ -830,6 +841,7 @@ class Reports extends Secure_Controller
'headers' => $headers,
'summary_data' => $summary_data,
'details_data' => $details_data,
'details_data_rewards' => $details_data_rewards,
'overall_summary_data' => $this->xss_clean($model->getSummaryData($inputs))
);
@@ -867,6 +879,7 @@ class Reports extends Secure_Controller
$summary_data = array();
$details_data = array();
$details_data_rewards = array();
foreach($report_data['summary'] as $key => $row)
{
@@ -887,6 +900,14 @@ class Reports extends Secure_Controller
{
$details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], to_quantity_decimals($drow['quantity_purchased']), to_currency($drow['subtotal']), to_currency($drow['tax']), to_currency($drow['total']), to_currency($drow['profit']), $drow['discount_percent'].'%'));
}
if(isset($report_data['rewards'][$key]))
{
foreach($report_data['rewards'][$key] as $drow)
{
$details_data_rewards[$row['sale_id']][] = $this->xss_clean(array($drow['used'], $drow['earned']));
}
}
}
$data = array(
@@ -895,6 +916,7 @@ class Reports extends Secure_Controller
'headers' => $headers,
'summary_data' => $summary_data,
'details_data' => $details_data,
'details_data_rewards' => $details_data_rewards,
'overall_summary_data' => $this->xss_clean($model->getSummaryData($inputs))
);
@@ -981,7 +1003,9 @@ class Reports extends Secure_Controller
}
$details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], $quantity_purchased, to_currency($drow['subtotal']), to_currency($drow['tax']), to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%'));
}
if(isset($report_data['rewards'][$key])){
if(isset($report_data['rewards'][$key]))
{
foreach($report_data['rewards'][$key] as $drow)
{
$details_data_rewards[$row['sale_id']][] = $this->xss_clean(array($drow['used'], $drow['earned']));
@@ -1188,4 +1212,4 @@ class Reports extends Secure_Controller
return $subtitle;
}
}
?>
?>

View File

@@ -124,9 +124,8 @@ class Detailed_sales extends Report
public function getSummaryData(array $inputs)
{
$this->db->select('SUM(subtotal) AS subtotal, SUM(sales_taxes.sale_tax_amount) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit');
$this->db->from('sales_items_temp as sales_items_temp');
$this->db->join('sales_taxes as sales_taxes', 'sales_items_temp.sale_id = sales_taxes.sale_id');
$this->db->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit');
$this->db->from('sales_items_temp');
if($inputs['location_id'] != 'all')
{

View File

@@ -79,6 +79,7 @@ class Specific_customer extends Report
$data = array();
$data['summary'] = $this->db->get()->result_array();
$data['details'] = array();
$data['rewards'] = array();
foreach($data['summary'] as $key=>$value)
{
@@ -97,9 +98,8 @@ class Specific_customer extends Report
public function getSummaryData(array $inputs)
{
$this->db->select('SUM(subtotal) AS subtotal, SUM(sales_taxes.sale_tax_amount) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit');
$this->db->from('sales_items_temp as sales_items_temp');
$this->db->join('sales_taxes as sales_taxes', 'sales_items_temp.sale_id = sales_taxes.sale_id');
$this->db->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit');
$this->db->from('sales_items_temp');
$this->db->where('customer_id', $inputs['customer_id']);
if($inputs['sale_type'] == 'sales')

View File

@@ -39,7 +39,10 @@ class Specific_discount extends Report
$this->lang->line('reports_total'),
$this->lang->line('reports_tax'),
$this->lang->line('reports_profit'),
$this->lang->line('reports_discount'))
$this->lang->line('reports_discount')),
'details_rewards' => array(
$this->lang->line('reports_used'),
$this->lang->line('reports_earned'))
);
}
@@ -74,13 +77,18 @@ class Specific_discount extends Report
$data = array();
$data['summary'] = $this->db->get()->result_array();
$data['details'] = array();
$data['rewards'] = array();
foreach($data['summary'] as $key=>$value)
{
$this->db->select('name, serialnumber, category, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent');
$this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent');
$this->db->from('sales_items_temp');
$this->db->where('sale_id', $value['sale_id']);
$data['details'][$key] = $this->db->get()->result_array();
$this->db->select('used, earned');
$this->db->from('sales_reward_points');
$this->db->where('sale_id', $value['sale_id']);
$data['rewards'][$key] = $this->db->get()->result_array();
}
return $data;
@@ -88,9 +96,8 @@ class Specific_discount extends Report
public function getSummaryData(array $inputs)
{
$this->db->select('SUM(subtotal) AS subtotal, SUM(sales_taxes.sale_tax_amount) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit');
$this->db->from('sales_items_temp as sales_items_temp');
$this->db->join('sales_taxes as sales_taxes', 'sales_items_temp.sale_id = sales_taxes.sale_id');
$this->db->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit');
$this->db->from('sales_items_temp');
$this->db->where('discount_percent >=', $inputs['discount']);
if($inputs['sale_type'] == 'sales')

View File

@@ -41,7 +41,10 @@ class Specific_employee extends Report
$this->lang->line('reports_total'),
$this->lang->line('reports_cost'),
$this->lang->line('reports_profit'),
$this->lang->line('reports_discount'))
$this->lang->line('reports_discount')),
'details_rewards' => array(
$this->lang->line('reports_used'),
$this->lang->line('reports_earned'))
);
}
@@ -61,11 +64,11 @@ class Specific_employee extends Report
$this->db->from('sales_items_temp');
$this->db->where('employee_id', $inputs['employee_id']);
if ($inputs['sale_type'] == 'sales')
if($inputs['sale_type'] == 'sales')
{
$this->db->where('quantity_purchased > 0');
}
elseif ($inputs['sale_type'] == 'returns')
elseif($inputs['sale_type'] == 'returns')
{
$this->db->where('quantity_purchased < 0');
}
@@ -76,6 +79,7 @@ class Specific_employee extends Report
$data = array();
$data['summary'] = $this->db->get()->result_array();
$data['details'] = array();
$data['rewards'] = array();
foreach($data['summary'] as $key=>$value)
{
@@ -83,6 +87,10 @@ class Specific_employee extends Report
$this->db->from('sales_items_temp');
$this->db->where('sale_id', $value['sale_id']);
$data['details'][$key] = $this->db->get()->result_array();
$this->db->select('used, earned');
$this->db->from('sales_reward_points');
$this->db->where('sale_id', $value['sale_id']);
$data['rewards'][$key] = $this->db->get()->result_array();
}
return $data;
@@ -90,16 +98,15 @@ class Specific_employee extends Report
public function getSummaryData(array $inputs)
{
$this->db->select('SUM(subtotal) AS subtotal, SUM(sales_taxes.sale_tax_amount) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit');
$this->db->from('sales_items_temp as sales_items_temp');
$this->db->join('sales_taxes as sales_taxes', 'sales_items_temp.sale_id = sales_taxes.sale_id');
$this->db->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit');
$this->db->from('sales_items_temp');
$this->db->where('employee_id', $inputs['employee_id']);
if ($inputs['sale_type'] == 'sales')
if($inputs['sale_type'] == 'sales')
{
$this->db->where('quantity_purchased > 0');
}
elseif ($inputs['sale_type'] == 'returns')
elseif($inputs['sale_type'] == 'returns')
{
$this->db->where('quantity_purchased < 0');
}

View File

@@ -77,8 +77,8 @@ if(isset($error))
</div>
<div class="list-group">
<?php
show_report('', 'reports_inventory_low');
show_report('', 'reports_inventory_summary');
show_report('', 'reports_inventory_low');
show_report('', 'reports_inventory_summary');
?>
</div>
</div>
@@ -88,4 +88,4 @@ if(isset($error))
</div>
</div>
<?php $this->load->view("partial/footer"); ?>
<?php $this->load->view("partial/footer"); ?>

View File

@@ -26,7 +26,14 @@
<?php $this->load->view('partial/bootstrap_tables_locale'); ?>
var detail_data = <?php echo json_encode($details_data); ?>;
var details_data_rewards = <?php echo json_encode($details_data_rewards); ?>;
<?php
if($this->config->item('customer_reward_enable') == TRUE && !empty($details_data_rewards))
{
?>
var details_data_rewards = <?php echo json_encode($details_data_rewards); ?>;
<?php
}
?>
var init_dialog = function()
{
@@ -60,12 +67,17 @@
columns: <?php echo transform_headers_readonly($headers['details']); ?>,
data: detail_data[(!isNaN(row.id) && row.id) || $(row[0] || row.id).text().replace(/(POS|RECV)\s*/g, '')]
});
<?php if(isset($details_data_rewards) && $details_data_rewards!= null && !empty($details_data_rewards)) { ?>
$detail.append('<table></table>').find("table").bootstrapTable({
columns: <?php echo transform_headers_readonly($headers['details_rewards']); ?>,
data: details_data_rewards[(!isNaN(row.id) && row.id) || $(row[0] || row.id).text().replace(/(POS|RECV)\s*/g, '')]
});
<?php } ?>
<?php
if($this->config->item('customer_reward_enable') == TRUE && !empty($details_data_rewards))
{
?>
$detail.append('<table></table>').find("table").bootstrapTable({
columns: <?php echo transform_headers_readonly($headers['details_rewards']); ?>,
data: details_data_rewards[(!isNaN(row.id) && row.id) || $(row[0] || row.id).text().replace(/(POS|RECV)\s*/g, '')]
});
<?php
}
?>
}
});
@@ -73,4 +85,4 @@
});
</script>
<?php $this->load->view("partial/footer"); ?>
<?php $this->load->view("partial/footer"); ?>

View File

@@ -292,7 +292,7 @@ if(isset($success))
</tr>
<?php if($this->config->item('customer_reward_enable') == TRUE): ?>
<?php
if(!empty($customer_rewards) && isset($customer_rewards))
if(!empty($customer_rewards))
{
?>
<tr>