From 461de2f04888b7e99b0d75770dc9c5e1c55df2ec Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sat, 19 Sep 2015 15:10:04 +0100 Subject: [PATCH] #162 fix further issues due to cost & retail prices added to the table --- application/controllers/item_kits.php | 83 ++++++++++++++------------ application/views/giftcards/manage.php | 7 +-- application/views/item_kits/manage.php | 11 ++-- application/views/items/manage.php | 2 +- 4 files changed, 53 insertions(+), 50 deletions(-) diff --git a/application/controllers/item_kits.php b/application/controllers/item_kits.php index 4d451cbc4..dff462d4d 100644 --- a/application/controllers/item_kits.php +++ b/application/controllers/item_kits.php @@ -8,6 +8,26 @@ class Item_kits extends Secure_area implements iData_controller parent::__construct('item_kits'); } + // add the total cost and retail price to a passed items kit retrieving the data from each singolar item part of the kit + private function add_totals_to_item_kit($item_kit) + { + $total_cost_price = 0; + $total_unit_price = 0; + + foreach ($this->Item_kit_items->get_info($item_kit->item_kit_id) as $item_kit_item) + { + $item_info = $this->Item->get_info($item_kit_item['item_id']); + + $total_cost_price += $item_info->cost_price; + $total_unit_price += $item_info->unit_price; + } + + $item_kit->total_cost_price = $total_cost_price; + $item_kit->total_unit_price = $total_unit_price; + + return $item_kit; + } + function index($limit_from=0) { $data['controller_name'] = $this->get_controller_name(); @@ -15,24 +35,10 @@ class Item_kits extends Secure_area implements iData_controller $lines_per_page = $this->Appconfig->get('lines_per_page'); $item_kits = $this->Item_kit->get_all($lines_per_page, $limit_from); - // calculate the total cost and retail price of the Kit so it can be printed out in the manage table foreach($item_kits->result() as $item_kit) { - $item_kit_info = $this->Item_kit->get_info($item_kit->item_kit_id); - - $total_cost_price = 0; - $total_unit_price = 0; - - foreach ($this->Item_kit_items->get_info($item_kit_info->item_kit_id) as $item_kit_item) - { - $item_info = $this->Item->get_info($item_kit_item['item_id']); - - $total_cost_price += $item_info->cost_price; - $total_unit_price += $item_info->unit_price; - } - - $item_kit->total_cost_price = $total_cost_price; - $item_kit->total_unit_price = $total_unit_price; + // calculate the total cost and retail price of the Kit so it can be printed out in the manage table + $item_kit = $this->add_totals_to_item_kit($item_kit); } $data['links'] = $this->_initialize_pagination($this->Item_kit, $lines_per_page, $limit_from); @@ -47,10 +53,17 @@ class Item_kits extends Secure_area implements iData_controller $search = $this->input->post('search'); $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); - $customers = $this->Item_kit->search($search, $lines_per_page, $limit_from); + $item_kits = $this->Item_kit->search($search, $lines_per_page, $limit_from); $total_rows = $this->Item_kit->get_found_rows($search); $links = $this->_initialize_pagination($this->Item_kit, $lines_per_page, $limit_from, $total_rows, 'search'); - $data_rows = get_item_kits_manage_table_data_rows($customers, $this); + + foreach($item_kits->result() as $item_kit) + { + // calculate the total cost and retail price of the Kit so it can be printed out in the manage table + $item_kit = $this->add_totals_to_item_kit($item_kit); + } + + $data_rows = get_item_kits_manage_table_data_rows($item_kits, $this); $this->_remove_duplicate_cookies(); echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links)); @@ -69,9 +82,11 @@ class Item_kits extends Secure_area implements iData_controller function get_row() { $item_kit_id = $this->input->post('row_id'); - $data_row = get_item_kit_data_row($this->Item_kit->get_info($item_kit_id), $this); - echo $data_row; + // calculate the total cost and retail price of the Kit so it can be added to the table refresh + $item_kit = $this->add_totals_to_item_kit($this->Item_kit->get_info($item_kit_id)); + + echo (get_item_kit_data_row($item_kit, $this)); $this->_remove_duplicate_cookies(); } @@ -84,8 +99,8 @@ class Item_kits extends Secure_area implements iData_controller function save($item_kit_id=-1) { $item_kit_data = array( - 'name'=>$this->input->post('name'), - 'description'=>$this->input->post('description') + 'name' => $this->input->post('name'), + 'description' => $this->input->post('description') ); if ($this->Item_kit->save($item_kit_data, $item_kit_id)) @@ -93,10 +108,11 @@ class Item_kits extends Secure_area implements iData_controller //New item kit if ($item_kit_id==-1) { + $item_kit_id = $item_kit_data['item_kit_id']; + echo json_encode(array('success'=>true, 'message'=>$this->lang->line('item_kits_successful_adding').' '.$item_kit_data['name'], - 'item_kit_id'=>$item_kit_data['item_kit_id'])); - $item_kit_id = $item_kit_data['item_kit_id']; + 'item_kit_id'=>$item_kit_id)); } else //previous item { @@ -113,7 +129,7 @@ class Item_kits extends Secure_area implements iData_controller $item_kit_items[] = array( 'item_id' => $item_id, 'quantity' => $quantity - ); + ); } $this->Item_kit_items->save($item_kit_items, $item_kit_id); @@ -150,22 +166,11 @@ class Item_kits extends Secure_area implements iData_controller $item_kit_ids = explode(':', $item_kit_ids); foreach ($item_kit_ids as $item_kid_id) - { - $item_kit_info = $this->Item_kit->get_info($item_kid_id); - + { // calculate the total cost and retail price of the Kit so it can be added to the barcode text at the bottom - $total_cost_price = 0; - $total_unit_price = 0; - - foreach ($this->Item_kit_items->get_info($item_kit_info->item_kit_id) as $item_kit_item) - { - $item_info = $this->Item->get_info($item_kit_item['item_id']); - - $total_cost_price += $item_info->cost_price; - $total_unit_price += $item_info->unit_price; - } + $item_kit = $this->add_totals_to_item_kit($this->Item_kit->get_info($item_kid_id)); - $result[] = array('name'=>$item_kit_info->name, 'item_id'=>'KIT '.$item_kid_id, 'item_number'=>'KIT '.$item_kid_id, 'cost_price'=>$total_cost_price, 'unit_price'=>$total_unit_price); + $result[] = array('name'=>$item_kit->name, 'item_id'=>'KIT '.$item_kid_id, 'item_number'=>'KIT '.$item_kid_id, 'cost_price'=>$item_kit->total_cost_price, 'unit_price'=>$item_kit->total_unit_price); } $data['items'] = $result; diff --git a/application/views/giftcards/manage.php b/application/views/giftcards/manage.php index 1664c81c1..42315abe6 100644 --- a/application/views/giftcards/manage.php +++ b/application/views/giftcards/manage.php @@ -7,9 +7,8 @@ $(document).ready(function() enable_checkboxes(); enable_row_selection(); enable_search({suggest_url: '', - confirm_search_messsage: 'wlang->line("common_confirm_search")?>'}); + confirm_message: 'lang->line("common_confirm_search")?>'}); enable_delete('lang->line($controller_name."_confirm_delete")?>','lang->line($controller_name."_none_selected")?>'); - }); function init_table_sorting() @@ -22,7 +21,8 @@ function init_table_sorting() sortList: [[1,0]], headers: { - 0: { sorter: false} + 0: { sorter: false}, + 5: { sorter: false} } }); } @@ -54,7 +54,6 @@ function post_giftcard_form_submit(response) } } } -
diff --git a/application/views/item_kits/manage.php b/application/views/item_kits/manage.php index 54ce7fa6b..9bb59e7d4 100644 --- a/application/views/item_kits/manage.php +++ b/application/views/item_kits/manage.php @@ -7,9 +7,8 @@ $(document).ready(function() enable_select_all(); enable_checkboxes(); enable_row_selection(); - var widget = enable_search({suggest_url : '', - confirm_message : 'lang->line("common_confirm_search")?>' - }); + enable_search({suggest_url : '', + confirm_message : 'lang->line("common_confirm_search")?>'}); enable_delete('lang->line($controller_name."_confirm_delete")?>','lang->line($controller_name."_none_selected")?>'); $('#generate_barcodes').click(function() @@ -36,7 +35,7 @@ function init_table_sorting() headers: { 0: { sorter: false}, - 4: { sorter: false} + 6: { sorter: false} } }); } @@ -51,9 +50,9 @@ function post_item_kit_form_submit(response) else { //This is an update, just update one row - if(jQuery.inArray(response.item_id,get_visible_checkbox_ids()) != -1) + if(jQuery.inArray(response.item_kit_id,get_visible_checkbox_ids()) != -1) { - update_row(response.item_id,''); + update_row(response.item_kit_id,''); set_feedback(response.message,'success_message',false); } diff --git a/application/views/items/manage.php b/application/views/items/manage.php index 6a3fae3b4..633be9e96 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -12,7 +12,7 @@ $(document).ready(function() extra_params : { 'is_deleted' : function () { return $("#is_deleted").is(":checked") ? 1 : 0; - } + } }}); // clear suggestion cache when toggling filter $("#is_deleted").change(function() {