Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/reward points customer #1178

Merged
merged 6 commits into from
Mar 12, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@
|
| $autoload['model'] = array('first_model' => 'first');
*/
$autoload['model'] = array('Appconfig', 'Person', 'Customer', 'Employee', 'Module', 'Item', 'Item_taxes', 'Sale', 'Sale_suspended', 'Supplier', 'Inventory', 'Receiving', 'Giftcard', 'Item_kit', 'Item_kit_items', 'Stock_location', 'Item_quantity','Dinner_table');
$autoload['model'] = array('Appconfig', 'Person', 'Customer', 'Employee', 'Module', 'Item', 'Item_taxes', 'Sale', 'Sale_suspended', 'Supplier', 'Inventory', 'Receiving', 'Giftcard', 'Item_kit', 'Item_kit_items', 'Stock_location', 'Item_quantity','Dinner_table','Customer_rewards','Rewards');
2 changes: 1 addition & 1 deletion application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
| https://codeigniter.com/user_guide/libraries/encryption.html
|
*/
$config['encryption_key'] = '';
$config['encryption_key'] = 'ec58a27d5854523044e3283b673a97c1deb59fe1e6f2ca7f77ed5e0f4c5aa02a';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove your key

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done Removed key and pushed


/*
|--------------------------------------------------------------------------
Expand Down
60 changes: 60 additions & 0 deletions application/controllers/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public function index()
{
$data['stock_locations'] = $this->Stock_location->get_all()->result_array();
$data['dinner_tables'] = $this->Dinner_table->get_all()->result_array();
$data['customer_rewards'] = $this->Customer_rewards->get_all()->result_array();
$data['support_barcode'] = $this->barcode_lib->get_list_barcodes();
$data['logo_exists'] = $this->config->item('company_logo') != '';
$data['line_sequence_options'] = $this->sale_lib->get_line_sequence_options();
Expand Down Expand Up @@ -385,6 +386,15 @@ public function dinner_tables()

$this->load->view('partial/dinner_tables', array('dinner_tables' => $dinner_tables));
}

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()
{
Expand Down Expand Up @@ -471,6 +481,56 @@ public function save_tables()
echo json_encode(array('success' => $success, 'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')));
}

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')
{
$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')
{
$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) {
// 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)
{
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')));
}

public function save_barcode()
{
$batch_save_data = array(
Expand Down
8 changes: 8 additions & 0 deletions application/controllers/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public function view($customer_id = -1)
$data['person_info'] = $info;

$data['total'] = $this->xss_clean($this->Customer->get_totals($customer_id)->total);
$packages = array('' => $this->lang->line('items_none'));
foreach($this->Customer_rewards->get_all()->result_array() as $row)
{
$packages[$this->xss_clean($row['package_id'])] = $this->xss_clean($row['package_name']);
}
$data['packages'] = $packages;
$data['selected_package'] = $info->package_id;

$this->load->view("customers/form", $data);
}
Expand Down Expand Up @@ -98,6 +105,7 @@ public function save($customer_id = -1)
'account_number' => $this->input->post('account_number') == '' ? NULL : $this->input->post('account_number'),
'company_name' => $this->input->post('company_name') == '' ? NULL : $this->input->post('company_name'),
'discount_percent' => $this->input->post('discount_percent') == '' ? 0.00 : $this->input->post('discount_percent'),
'package_id' => $this->input->post('package_id') == '' ? NULL : $this->input->post('package_id'),
'taxable' => $this->input->post('taxable') != NULL
);

Expand Down
17 changes: 16 additions & 1 deletion application/controllers/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ public function specific_customer($start_date, $end_date, $customer_id, $sale_ty

$summary_data = array();
$details_data = array();
$details_data_rewards = array();

foreach($report_data['summary'] as $key => $row)
{
Expand All @@ -749,6 +750,12 @@ public function specific_customer($start_date, $end_date, $customer_id, $sale_ty
{
$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']));
}
}
}

$customer_info = $this->Customer->get_info($customer_id);
Expand All @@ -758,6 +765,7 @@ public function specific_customer($start_date, $end_date, $customer_id, $sale_ty
'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))
);

Expand Down Expand Up @@ -940,6 +948,7 @@ public function detailed_sales($start_date, $end_date, $sale_type, $location_id

$summary_data = array();
$details_data = array();
$details_data_rewards = array();

$show_locations = $this->xss_clean($this->Stock_location->multiple_locations());

Expand Down Expand Up @@ -972,6 +981,12 @@ public function detailed_sales($start_date, $end_date, $sale_type, $location_id
}
$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])){
foreach($report_data['rewards'][$key] as $drow)
{
$details_data_rewards[$row['sale_id']][] = $this->xss_clean(array($drow['used'], $drow['earned']));
}
}
}

$data = array(
Expand All @@ -981,9 +996,9 @@ public function detailed_sales($start_date, $end_date, $sale_type, $location_id
'editable' => 'sales',
'summary_data' => $summary_data,
'details_data' => $details_data,
'details_data_rewards' => $details_data_rewards,
'overall_summary_data' => $this->xss_clean($model->getSummaryData($inputs))
);

$this->load->view('reports/tabular_details', $data);
}

Expand Down
48 changes: 47 additions & 1 deletion application/controllers/Sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,38 @@ public function add_payment()
$this->sale_lib->add_payment($payment_type, $amount_tendered);
}
}
else if ($payment_type == $this->lang->line('sales_rewards'))
{
$customer_id = $this->sale_lib->get_customer();
$package_id = $this->Customer->get_info($customer_id)->package_id;
if(isset($package_id) && $package_id!=NULL){
$package_name = $this->Customer_rewards->get_name($package_id);
$points = $this->Customer->get_info($customer_id)->points;
$points = ($points==NULL ? 0 : $points);

$payments = $this->sale_lib->get_payments();
$payment_type = $payment_type;
$current_payments_with_rewards = isset($payments[$payment_type]) ? $payments[$payment_type]['payment_amount'] : 0;
$cur_rewards_value = $points;

if(($cur_rewards_value - $current_payments_with_rewards) <= 0)
{
$data['error'] = $this->lang->line('rewards_remaining_balance', to_currency($cur_rewards_value));
}
else
{
$new_reward_value = $points - $this->sale_lib->get_amount_due();
$new_reward_value = $new_reward_value >= 0 ? $new_reward_value : 0;
$this->sale_lib->set_rewards_remainder($new_reward_value);
$new_reward_value = str_replace('$', '\$', to_currency($new_reward_value));
$data['warning'] = $this->lang->line('rewards_remaining_balance', $new_reward_value);
$amount_tendered = min($this->sale_lib->get_amount_due(), $points);

$this->sale_lib->add_payment($payment_type, $amount_tendered);
}
}

}
else
{
$amount_tendered = $this->input->post('amount_tendered');
Expand Down Expand Up @@ -375,6 +407,8 @@ public function delete_item($item_number)
public function remove_customer()
{
$this->sale_lib->clear_giftcard_remainder();
$this->sale_lib->clear_rewards_remainder();
$this->sale_lib->delete_payment($this->lang->line('sales_rewards'));
$this->sale_lib->clear_invoice_number();
$this->sale_lib->remove_customer();

Expand Down Expand Up @@ -415,6 +449,7 @@ public function complete()
));
$data['invoice_number_enabled'] = $this->sale_lib->is_invoice_mode();
$data['cur_giftcard_value'] = $this->sale_lib->get_giftcard_remainder();
$data['cur_rewards_value'] = $this->sale_lib->get_rewards_remainder();
$data['print_after_sale'] = $this->sale_lib->is_print_after_sale();
$data['email_receipt'] = $this->sale_lib->get_email_receipt();
$customer_id = $this->sale_lib->get_customer();
Expand Down Expand Up @@ -739,6 +774,14 @@ private function _load_customer_data($customer_id, &$data, $totals = FALSE)
}
$data['customer_account_number'] = $customer_info->account_number;
$data['customer_discount_percent'] = $customer_info->discount_percent;
$package_id = $this->Customer->get_info($customer_id)->package_id;
if($package_id!=NULL){
$package_name = $this->Customer_rewards->get_name($package_id);
$points = $this->Customer->get_info($customer_id)->points;
$data['customer_rewards']['package_id'] = $package_id;
$data['customer_rewards']['points'] = ($points==NULL ? 0 : $points);
$data['customer_rewards']['package_name'] = $package_name;
}
if ($totals)
{
$cust_totals = $this->Customer->get_totals($customer_id);
Expand Down Expand Up @@ -835,7 +878,10 @@ private function _reload($data = array())
$data['payments_total'] = $this->sale_lib->get_payments_total();
$data['amount_due'] = $this->sale_lib->get_amount_due();
$data['payments'] = $this->sale_lib->get_payments();
$data['payment_options'] = $this->Sale->get_payment_options();
if($customer_info)
$data['payment_options'] = $this->Sale->get_payment_options(TRUE,TRUE);
else
$data['payment_options'] = $this->Sale->get_payment_options();
$quote_number = $this->sale_lib->get_quote_number();
if ($quote_number != NULL)
{
Expand Down
7 changes: 7 additions & 0 deletions application/language/en/config_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,10 @@
$lang["config_number_locale_invalid"] = "The entered locale is invalid. Check the link in the tooltip to find a sensible value";
$lang["config_number_locale_tooltip"] = "Find a suitable locale through this link";
$lang["config_theme"] = "Theme";
$lang["config_reward"] = "Reward";
$lang["config_reward_configuration"] = "Reward Configuration";
$lang["config_customer_reward"] = "Reward";
$lang["config_customer_reward_enable"] = "Enable Customer Rewards";
$lang["config_customer_reward_duplicate"] = "Please use an unique reward name";
$lang["config_customer_reward_invalid_chars"] = "The reward name can not contain '_'";
$lang["config_customer_reward_required"] = "Reward is a required field";
2 changes: 2 additions & 0 deletions application/language/en/customers_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
$lang["customers_excel_import_nodata_wrongformat"] = "Your uploaded file has no data or wrong format";
$lang["customers_excel_import_success"] = "Import of Customers successful";
$lang["customers_excel_import_partially_failed"] = "Most Customers imported. But some were not, here is the list";
$lang["rewards_package"] = "Rewards Package";
$lang["customers_available_points"] = "Available Points";
2 changes: 2 additions & 0 deletions application/language/en/reports_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@
$lang["reports_zero_and_less"] = "Zero and less";
$lang["reports_more_than_zero"] = "More than zero";
$lang["reports_no_reports_to_display"] = "No Items to display";
$lang["reports_used"] = "Points Used";
$lang["reports_earned"] = "Points Earned";
5 changes: 5 additions & 0 deletions application/language/en/sales_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@
$lang["sales_update"] = "Update";
$lang["sales_date_range"] = "Date Range";
$lang["sales_none_selected"] = "You have not selected any sales to delete";
$lang["rewards_package"] = "Rewards";
$lang["customers_available_points"] = "Available Points";
$lang["sales_rewards"] = "Reward Points";
$lang["sales_rewards_balance"] = "Reward Points Balance";
$lang["rewards_remaining_balance"] = "Reward Points remaining value is %1!";
15 changes: 15 additions & 0 deletions application/libraries/Sale_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,21 @@ public function clear_giftcard_remainder()
$this->CI->session->unset_userdata('sales_giftcard_remainder');
}

public function set_rewards_remainder($value)
{
$this->CI->session->set_userdata('sales_rewards_remainder', $value);
}

public function get_rewards_remainder()
{
return $this->CI->session->userdata('sales_rewards_remainder');
}

public function clear_rewards_remainder()
{
$this->CI->session->unset_userdata('sales_rewards_remainder');
}

public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $price = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE, $print_option = '0', $stock_type = '0')
{
$item_info = $this->CI->Item->get_info_by_id_or_number($item_id);
Expand Down
10 changes: 10 additions & 0 deletions application/models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public function save_customer(&$person_data, &$customer_data, $customer_id = FAL
return $success;
}

/*
Updates reward points value
*/
public function update_reward_points_value($customer_id, $value)
{
$this->db->where('person_id', $customer_id);
$this->db->update('customers', array('points' => $value));
}


/*
Deletes one customer
*/
Expand Down