#162 fix further issues due to cost & retail prices added to the table

This commit is contained in:
FrancescoUK
2015-09-19 15:10:04 +01:00
parent 4106378a6c
commit 461de2f048
4 changed files with 53 additions and 50 deletions

View File

@@ -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;

View File

@@ -7,9 +7,8 @@ $(document).ready(function()
enable_checkboxes();
enable_row_selection();
enable_search({suggest_url: '<?php echo site_url("$controller_name/suggest")?>',
confirm_search_messsage: 'w<?php echo $this->lang->line("common_confirm_search")?>'});
confirm_message: '<?php echo $this->lang->line("common_confirm_search")?>'});
enable_delete('<?php echo $this->lang->line($controller_name."_confirm_delete")?>','<?php echo $this->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)
}
}
}
</script>
<div id="title_bar">

View File

@@ -7,9 +7,8 @@ $(document).ready(function()
enable_select_all();
enable_checkboxes();
enable_row_selection();
var widget = enable_search({suggest_url : '<?php echo site_url("$controller_name/suggest")?>',
confirm_message : '<?php echo $this->lang->line("common_confirm_search")?>'
});
enable_search({suggest_url : '<?php echo site_url("$controller_name/suggest")?>',
confirm_message : '<?php echo $this->lang->line("common_confirm_search")?>'});
enable_delete('<?php echo $this->lang->line($controller_name."_confirm_delete")?>','<?php echo $this->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,'<?php echo site_url("$controller_name/get_row")?>');
update_row(response.item_kit_id,'<?php echo site_url("$controller_name/get_row")?>');
set_feedback(response.message,'success_message',false);
}

View File

@@ -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() {