From e85e2e5e557b4ccbf9886894bd2ceedef8e9b975 Mon Sep 17 00:00:00 2001 From: Steve Ireland Date: Sat, 9 Sep 2017 17:16:38 -0400 Subject: [PATCH] Final touch on Work Orders --- application/controllers/Sales.php | 28 ++++++++++++++++---- application/language/en-US/reports_lang.php | 2 ++ application/language/en-US/sales_lang.php | 6 ++++- application/models/Sale.php | 29 ++++++++++++++------- application/models/enums/Rounding_mode.php | 2 +- database/3.1.1_to_3.2.0.sql | 9 +++++++ 6 files changed, 60 insertions(+), 16 deletions(-) diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index c10c9c061..729b070fb 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -1099,16 +1099,34 @@ class Sales extends Secure_Controller public function delete($sale_id = -1, $update_inventory = TRUE) { $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; - $sale_ids = $sale_id == -1 ? $this->input->post('ids') : array($sale_id); + $has_grant = $this->Employee->has_grant('sales_delete', $employee_id); - if($this->Sale->delete_list($sale_ids, $employee_id, $update_inventory)) + if(!$has_grant) { - echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('sales_successfully_deleted') . ' ' . - count($sale_ids) . ' ' . $this->lang->line('sales_one_or_multiple'), 'ids' => $sale_ids)); + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('sales_not_authorized'))); } else { - echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('sales_unsuccessfully_deleted'))); + $sale_ids = $sale_id == -1 ? $this->input->post('ids') : array($sale_id); + $reactivate = FALSE; + + if($this->Sale->delete_list($sale_ids, $employee_id, $update_inventory, $reactivate)) + { + if(!$reactivate) + { + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('sales_successfully_deleted') . ' ' . + count($sale_ids) . ' ' . $this->lang->line('sales_one_or_multiple'), 'ids' => $sale_ids)); + } + else + { + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('sales_successfully_reactivated') . ' ' . + count($sale_ids) . ' ' . $this->lang->line('sales_one_or_multiple'), 'ids' => $sale_ids)); + } + } + else + { + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('sales_unsuccessfully_deleted'))); + } } } diff --git a/application/language/en-US/reports_lang.php b/application/language/en-US/reports_lang.php index 81dcf34d0..6bccb28ad 100644 --- a/application/language/en-US/reports_lang.php +++ b/application/language/en-US/reports_lang.php @@ -12,6 +12,8 @@ $lang["reports_code_return"] = "RET"; $lang["reports_code_type"] = "Type"; $lang["reports_code_work_order"] = "W/O"; $lang["reports_comments"] = "Comments"; +$lang["reports_complete"] = "Completed Sales and Returns"; +$lang["reports_completed_sales"] = "Completed Sales"; $lang["reports_cost"] = "Wholesale"; $lang["reports_cost_price"] = "Wholesale Price"; $lang["reports_count"] = "Count"; diff --git a/application/language/en-US/sales_lang.php b/application/language/en-US/sales_lang.php index 7f037a720..ce38f67db 100644 --- a/application/language/en-US/sales_lang.php +++ b/application/language/en-US/sales_lang.php @@ -18,7 +18,7 @@ $lang["sales_comment"] = "Comment"; $lang["sales_comments"] = "Comments"; $lang["sales_complete_sale"] = "Complete"; $lang["sales_confirm_cancel_sale"] = "Are you sure you want to clear this sale? All items will cleared."; -$lang["sales_confirm_delete"] = "Are you sure you want to delete the selected Sale(s)?"; +$lang["sales_confirm_delete"] = "Are you sure you want to delete or reactivate the selected Sale(s)?"; $lang["sales_credit"] = "Credit Card"; $lang["sales_credit_deposit"] = "Credit Deposit"; $lang["sales_customer"] = "Name"; @@ -84,6 +84,7 @@ $lang["sales_no_filter"] = "All"; $lang["sales_no_items_in_cart"] = "There are no Items in the cart."; $lang["sales_no_sales_to_display"] = "No Sales to display."; $lang["sales_none_selected"] = "You have not selected any Sale(s) to delete."; +$lang["sales_not_authorized"]= "You are not authorized to delete sales transactions"; $lang["sales_one_or_multiple"] = "Sale(s)"; $lang["sales_payment"] = "Payment Type"; $lang["sales_payment_amount"] = "Amount"; @@ -110,6 +111,7 @@ $lang["sales_return"] = "Return"; $lang["sales_rewards"] = "Reward Points"; $lang["sales_rewards_balance"] = "Reward Points Balance"; $lang["sales_sale"] = "Sale"; +$lang["sales_delete"] = "Allow Delete"; $lang["sales_sale_by_invoice"] = "Sale by Invoice"; $lang["sales_sale_for_customer"] = "Customer:"; $lang["sales_sale_time"] = "Time"; @@ -124,10 +126,12 @@ $lang["sales_show_invoice"] = "Show Invoice"; $lang["sales_show_receipt"] = "Show Receipt"; $lang["sales_start_typing_customer_name"] = "Start typing customer details..."; $lang["sales_start_typing_item_name"] = "Start typing Item Name or scan Barcode..."; +$lang["sales_stock"] = "Stock"; $lang["sales_stock_location"] = "Stock Location"; $lang["sales_sub_total"] = "Subtotal"; $lang["sales_successfully_deleted"] = "You have successfully deleted"; $lang["sales_successfully_suspended_sale"] = "Sale suspend successful."; +$lang["sales_successfully_reactivated"] = "You have successfully reactivated"; $lang["sales_successfully_updated"] = "Sale update successful."; $lang["sales_suspend_sale"] = "Suspend"; $lang["sales_suspended_doc_id"] = "Document"; diff --git a/application/models/Sale.php b/application/models/Sale.php index 3cab08104..d39574f75 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -808,13 +808,13 @@ class Sale extends CI_Model /** * Deletes list of sales */ - public function delete_list($sale_ids, $employee_id, $update_inventory = TRUE) + public function delete_list($sale_ids, $employee_id, &$reactivated, $update_inventory = TRUE) { $result = TRUE; foreach($sale_ids as $sale_id) { - $result &= $this->delete($sale_id, $employee_id, $update_inventory); + $result &= $this->delete($sale_id, $employee_id, $reactivated, $update_inventory); } return $result; @@ -825,12 +825,14 @@ class Sale extends CI_Model * When a sale is "deleted" it is simply changed to a status of canceled. * However, if applicable the inventory still needs to be updated */ - public function delete($sale_id, $employee_id, $update_inventory = TRUE) + public function delete($sale_id, $employee_id, &$reactivated, $update_inventory = TRUE) { // start a transaction to assure data integrity $this->db->trans_start(); - if($update_inventory && $sale_status = $this->get_sale_status($sale_id) == COMPLETED) + $sale_status = $this->get_sale_status($sale_id); + + if($update_inventory && $sale_status == COMPLETED) { // defect, not all item deletions will be undone?? // get array with all the items involved in the sale to update the inventory tracking @@ -858,8 +860,17 @@ class Sale extends CI_Model } } - // Set the status of the sale to canceled - $this->update_sale_status($sale_id, CANCELED); + // Set the sale_status is canceled the reactive the sale by setting the status to suspended + // otherwise set the status to canceled + if($sale_status == CANCELED) + { + $this->update_sale_status($sale_id, SUSPENDED); + $reactivated = TRUE; + } + else + { + $this->update_sale_status($sale_id, CANCELED); + } // execute transaction $this->db->trans_complete(); @@ -1401,11 +1412,11 @@ class Sale extends CI_Model */ private function save_customer_rewards($customer_id, $sale_id, $total_amount, $total_amount_used) { - if (!empty($customer_id) && $this->config->item('customer_reward_enable') == TRUE) + if(!empty($customer_id) && $this->config->item('customer_reward_enable') == TRUE) { $package_id = $this->Customer->get_info($customer_id)->package_id; - if (!empty($package_id)) + if(!empty($package_id)) { $points_percent = $this->Customer_rewards->get_points_percent($package_id); $points = $this->Customer->get_info($customer_id)->points; @@ -1427,7 +1438,7 @@ class Sale extends CI_Model */ private function determine_sale_status(&$sale_status, $dinner_table) { - if ($sale_status == SUSPENDED && $dinner_table > 2) //not delivery or take away + if($sale_status == SUSPENDED && $dinner_table > 2) //not delivery or take away { return SUSPENDED; } diff --git a/application/models/enums/Rounding_mode.php b/application/models/enums/Rounding_mode.php index 603b24054..812845a26 100644 --- a/application/models/enums/Rounding_mode.php +++ b/application/models/enums/Rounding_mode.php @@ -28,7 +28,7 @@ class Rounding_mode $CI =& get_instance(); $CI->load->helper('language'); - if (empty($code)) + if(empty($code)) { return lang('common_unknown'); } diff --git a/database/3.1.1_to_3.2.0.sql b/database/3.1.1_to_3.2.0.sql index afdfcd0d5..cb0bce55c 100644 --- a/database/3.1.1_to_3.2.0.sql +++ b/database/3.1.1_to_3.2.0.sql @@ -57,3 +57,12 @@ WHERE `quote_number` IS NOT NULL; UPDATE `ospos_sales` SET `sale_type` = 1 WHERE `invoice_number` IS NOT NULL; + + +-- Add permissions for deleting sales and default grant for employee id 1 + +INSERT INTO `ospos_permissions` (`permission_id`, `module_id`) VALUES +('sales_delete', 'sales'); + +INSERT INTO `ospos_grants` (`permission_id`, `person_id`, `menu_group`) VALUES +('sales_delete', 1, '--');