Various fixes for the item kit feature.

This commit is contained in:
Steve Ireland
2018-04-21 17:46:39 -04:00
parent 9384b53a22
commit cdd966878d
12 changed files with 220 additions and 162 deletions

View File

@@ -14,9 +14,11 @@ class Item_kits extends Secure_Controller
*/
private function _add_totals_to_item_kit($item_kit)
{
$kit_item_info = $this->Item->get_info($item_kit->item_id);
$item_kit->total_cost_price = 0;
$item_kit->total_unit_price = 0;
$item_kit->total_unit_price = $kit_item_info->unit_price;
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']);
@@ -24,11 +26,17 @@ class Item_kits extends Secure_Controller
{
$item_info->$property = $this->xss_clean($value);
}
$item_kit->total_cost_price += $item_info->cost_price * $item_kit_item['quantity'];
$item_kit->total_unit_price += $item_info->unit_price * $item_kit_item['quantity'];
if($item_kit->price_option == PRICE_OPTION_ALL || ($item_kit->price_option == PRICE_OPTION_KIT_STOCK && $item_info->stock_type == HAS_STOCK )) {
$item_kit->total_unit_price += $item_info->unit_price * $item_kit_item['quantity'];
}
}
$discount_fraction = bcdiv($item_kit->kit_discount_percent, 100);
$item_kit->total_unit_price = $item_kit->total_unit_price - round(bcmul($item_kit->total_unit_price, $discount_fraction), totals_decimals(), PHP_ROUND_HALF_UP);
return $item_kit;
}
@@ -50,6 +58,8 @@ class Item_kits extends Secure_Controller
$sort = $this->input->get('sort');
$order = $this->input->get('order');
error_log('>>>search started');
$item_kits = $this->Item_kit->search($search, $limit, $offset, $sort, $order);
$total_rows = $this->Item_kit->get_found_rows($search);
@@ -75,7 +85,7 @@ class Item_kits extends Secure_Controller
{
// 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($row_id));
echo json_encode(get_item_kit_data_row($item_kit));
}

View File

@@ -490,8 +490,8 @@ function get_item_kits_manage_table_headers()
array('item_kit_id' => $CI->lang->line('item_kits_kit')),
array('name' => $CI->lang->line('item_kits_name')),
array('description' => $CI->lang->line('item_kits_description')),
array('cost_price' => $CI->lang->line('items_cost_price'), 'sortable' => FALSE),
array('unit_price' => $CI->lang->line('items_unit_price'), 'sortable' => FALSE)
array('total_cost_price' => $CI->lang->line('items_cost_price'), 'sortable' => FALSE),
array('total_unit_price' => $CI->lang->line('items_unit_price'), 'sortable' => FALSE)
);
return transform_headers($headers);
@@ -509,8 +509,8 @@ function get_item_kit_data_row($item_kit)
'item_kit_id' => $item_kit->item_kit_id,
'name' => $item_kit->name,
'description' => $item_kit->description,
'cost_price' => to_currency($item_kit->total_cost_price),
'unit_price' => to_currency($item_kit->total_unit_price),
'total_cost_price' => to_currency($item_kit->total_cost_price),
'total_unit_price' => to_currency($item_kit->total_unit_price),
'edit' => anchor($controller_name."/view/$item_kit->item_kit_id", '<span class="glyphicon glyphicon-edit"></span>',
array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update'))
));

View File

@@ -68,7 +68,7 @@ class Sale_lib
foreach($cart as $k=>$v)
{
if($v['print_option'] == '0')
if($v['print_option'] == PRINT_YES)
{
$filtered_cart[] = $v;
}
@@ -683,7 +683,7 @@ class Sale_lib
$this->CI->session->unset_userdata('sales_rewards_remainder');
}
public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $price_mode = PRICE_MODE_STANDARD, $kit_price_option = NULL, $kit_print_option = NULL, $price_override = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE )
public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $price_mode = PRICE_MODE_STANDARD, $kit_price_option = NULL, $kit_print_option = NULL, $price_override = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE, $print_option = NULL )
{
$item_info = $this->CI->Item->get_info_by_id_or_number($item_id);
@@ -802,7 +802,14 @@ class Sale_lib
}
else
{
$print_option_selected = PRINT_YES;
if ($print_option != NULL)
{
$print_option_selected = $print_option;
}
else
{
$print_option_selected = PRINT_YES;
}
}
$total = $this->get_item_total($quantity, $price, $discount);
@@ -981,7 +988,7 @@ class Sale_lib
foreach($this->CI->Sale->get_sale_items_ordered($sale_id)->result() as $row)
{
$this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE);
$this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option);
}
foreach($this->CI->Sale->get_sale_payments($sale_id)->result() as $row)
@@ -1009,7 +1016,7 @@ class Sale_lib
$this->empty_cart();
foreach($this->CI->Sale->get_sale_items_ordered($sale_id)->result() as $row)
{
$this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE);
$this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option);
}
return $this->CI->session->userdata('sales_cart');

View File

@@ -729,7 +729,7 @@ class Item extends CI_Model
$this->db->select('item_id, name');
$this->db->from('items');
$this->db->where('deleted', $filters['is_deleted']);
$this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later
$this->db->where('item_type', ITEM_KIT);
$this->db->like('name', $search);
$this->db->order_by('name', 'asc');
foreach($this->db->get()->result() as $row)
@@ -741,6 +741,7 @@ class Item extends CI_Model
$this->db->from('items');
$this->db->where('deleted', $filters['is_deleted']);
$this->db->like('item_number', $search);
$this->db->where('item_type', ITEM_KIT);
$this->db->order_by('item_number', 'asc');
foreach($this->db->get()->result() as $row)
{
@@ -753,6 +754,7 @@ class Item extends CI_Model
$this->db->select('category');
$this->db->from('items');
$this->db->where('deleted', $filters['is_deleted']);
$this->db->where('item_type', ITEM_KIT);
$this->db->distinct();
$this->db->like('category', $search);
$this->db->order_by('category', 'asc');
@@ -778,6 +780,7 @@ class Item extends CI_Model
$this->db->select('item_id, name, description');
$this->db->from('items');
$this->db->where('deleted', $filters['is_deleted']);
$this->db->where('item_type', ITEM_KIT);
$this->db->like('description', $search);
$this->db->order_by('description', 'asc');
foreach($this->db->get()->result() as $row)
@@ -794,6 +797,7 @@ class Item extends CI_Model
{
$this->db->from('items');
$this->db->group_start();
$this->db->where('item_type', ITEM_KIT);
$this->db->like('custom1', $search);
$this->db->or_like('custom2', $search);
$this->db->or_like('custom3', $search);

View File

@@ -117,28 +117,40 @@ $(document).ready(function()
<?php
foreach($cart as $line=>$item)
{
?>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><textarea rows="4" cols="6"><?php echo $item['name']; ?></textarea></td>
<td style='text-align:center;'><textarea rows="5" cols="6"><?php echo to_quantity_decimals($item['quantity']); ?></textarea></td>
<td><textarea rows="4" cols="6"><?php echo to_currency($item['price']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo $item['discount'] . '%'; ?></textarea></td>
<?php if ($item['discount'] > 0): ?>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></textarea></td>
<?php endif; ?>
<td style='border-right: solid 1px; text-align:right;'><textarea rows="4" cols="6"><?php echo to_currency($item['discounted_total']); ?></textarea></td>
</tr>
<?php
if($item['is_serialized'] || $item['allow_alt_description'] && !empty($item['description']))
if($item['print_option'] == PRINT_YES)
{
?>
<tr class="item-row" >
<td ></td >
<td class="item-description" colspan = "4" ><div><?php echo $item['description']; ?></div></td>
<td style='text-align:center;'><textarea><?php echo $item['serialnumber']; ?></textarea></td>
?>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><textarea rows="4" cols="6"><?php echo $item['name']; ?></textarea></td>
<td style='text-align:center;'><textarea rows="5"
cols="6"><?php echo to_quantity_decimals($item['quantity']); ?></textarea>
</td>
<td><textarea rows="4" cols="6"><?php echo to_currency($item['price']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="4"
cols="6"><?php echo $item['discount'] . '%'; ?></textarea>
</td>
<?php if ($item['discount'] > 0): ?>
<td style='text-align:center;'><textarea rows="4"
cols="6"><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></textarea>
</td>
<?php endif; ?>
<td style='border-right: solid 1px; text-align:right;'><textarea rows="4"
cols="6"><?php echo to_currency($item['discounted_total']); ?></textarea>
</td>
</tr>
<?php
<?php
if ($item['is_serialized'] || $item['allow_alt_description'] && !empty($item['description'])) {
?>
<tr class="item-row">
<td></td>
<td class="item-description" colspan="4">
<div><?php echo $item['description']; ?></div>
</td>
<td style='text-align:center;'><textarea><?php echo $item['serialnumber']; ?></textarea></td>
</tr>
<?php
}
}
}
?>

View File

@@ -81,19 +81,22 @@
<?php
foreach($cart as $line=>$item)
{
?>
if($item['print_option'] == PRINT_YES)
{
?>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo $item['discount'] .'%'; ?></td>
<td><?php echo $item['discount'] . '%'; ?></td>
<?php if ($item['discount'] > 0): ?>
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>
<td class="total-line"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php
<?php
}
}
?>

View File

@@ -117,30 +117,42 @@ if (isset($error_message))
<?php
foreach($cart as $line=>$item)
{
?>
if($item['print_option'] == PRINT_YES)
{
?>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><textarea rows="4" cols="6"><?php echo $item['name']; ?></textarea></td>
<td style='text-align:center;'><textarea rows="5" cols="6"><?php echo to_quantity_decimals($item['quantity']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="5"
cols="6"><?php echo to_quantity_decimals($item['quantity']); ?></textarea>
</td>
<td><textarea rows="4" cols="6"><?php echo to_currency($item['price']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo $item['discount'] . '%'; ?></textarea></td>
<td style='text-align:center;'><textarea rows="4"
cols="6"><?php echo $item['discount'] . '%'; ?></textarea></td>
<?php if ($item['discount'] > 0): ?>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="4"
cols="6"><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></textarea>
</td>
<?php endif; ?>
<td style='border-right: solid 1px; text-align:right;'><textarea rows="4" cols="6"><?php echo to_currency($item['discounted_total']); ?></textarea></td>
<td style='border-right: solid 1px; text-align:right;'><textarea rows="4"
cols="6"><?php echo to_currency($item['discounted_total']); ?></textarea>
</td>
</tr>
<?php if($item['is_serialized'] || $item['allow_alt_description'] && !empty($item['description']))
<?php if ($item['is_serialized'] || $item['allow_alt_description'] && !empty($item['description']))
{
?>
<tr class="item-row">
<td></td>
<td class="item-name" colspan = "4"><div><?php echo $item['description']; ?></div></td>
<td style='text-align:center;'><textarea><?php echo $item['serialnumber']; ?></textarea></td>
</tr>
<?php
?>
<tr class="item-row">
<td></td>
<td class="item-name" colspan="4">
<div><?php echo $item['description']; ?></div>
</td>
<td style='text-align:center;'><textarea><?php echo $item['serialnumber']; ?></textarea></td>
</tr>
<?php
}
}
}
?>
<tr>

View File

@@ -81,19 +81,22 @@
<?php
foreach($cart as $line=>$item)
{
?>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo $item['discount'] .'%'; ?></td>
<?php if ($item['discount'] > 0): ?>
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>
<td class="total-line"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php
if($item['print_option'] == PRINT_YES)
{
?>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo $item['discount'] . '%'; ?></td>
<?php if ($item['discount'] > 0): ?>
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>
<td class="total-line"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php
}
}
?>

View File

@@ -65,43 +65,42 @@
<?php
foreach($cart as $line=>$item)
{
?>
<tr>
<td><?php echo ucfirst($item['name']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td class="total-value"><?php echo to_currency($item[($this->config->item('receipt_show_total_discount') ? 'total' : 'discounted_total')]); ?></td>
</tr>
<tr>
<?php
if($this->config->item('receipt_show_description'))
{
?>
<td colspan="2"><?php echo $item['description']; ?></td>
<?php
}
?>
<?php
if($this->config->item('receipt_show_serialnumber'))
{
?>
<td><?php echo $item['serialnumber']; ?></td>
<?php
}
?>
</tr>
<?php
if($item['discount'] > 0)
if($item['print_option'] == PRINT_YES)
{
?>
?>
<tr>
<td colspan="3" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included")?></td>
<td class="total-value"><?php echo to_currency($item['discounted_total']) ; ?></td>
<td><?php echo ucfirst($item['name']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td class="total-value"><?php echo to_currency($item[($this->config->item('receipt_show_total_discount') ? 'total' : 'discounted_total')]); ?></td>
</tr>
<?php
<tr>
<?php
if ($this->config->item('receipt_show_description')) {
?>
<td colspan="2"><?php echo $item['description']; ?></td>
<?php
}
?>
<?php
if ($this->config->item('receipt_show_serialnumber')) {
?>
<td><?php echo $item['serialnumber']; ?></td>
<?php
}
?>
</tr>
<?php
if ($item['discount'] > 0) {
?>
<tr>
<td colspan="3"
class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<td class="total-value"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php
}
}
?>
<?php
}
?>

View File

@@ -60,47 +60,43 @@
<?php
foreach($cart as $line=>$item)
{
?>
<tr>
<td><?php echo ucfirst($item['name']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td style="text-align:right;"><?php echo to_currency($item[($this->config->item('receipt_show_total_discount') ? 'total' : 'discounted_total')]); ?></td>
</tr>
<tr>
<?php
if($this->config->item('receipt_show_description'))
{
?>
<td colspan="2"><?php echo $item['description']; ?></td>
<?php
}
?>
<?php
if($this->config->item('receipt_show_serialnumber'))
{
?>
<td><?php echo $item['serialnumber']; ?></td>
<?php
}
?>
</tr>
<?php
if($item['discount'] > 0)
if($item['print_option'] == PRINT_YES)
{
?>
?>
<tr>
<td colspan="3" style="font-weight: bold;"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included")?></td>
<td style="text-align:right;"><?php echo to_currency($item['discounted_total']) ; ?></td>
<td><?php echo ucfirst($item['name']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td style="text-align:right;"><?php echo to_currency($item[($this->config->item('receipt_show_total_discount') ? 'total' : 'discounted_total')]); ?></td>
</tr>
<?php
<tr>
<?php
if ($this->config->item('receipt_show_description')) {
?>
<td colspan="2"><?php echo $item['description']; ?></td>
<?php
}
?>
<?php
if ($this->config->item('receipt_show_serialnumber')) {
?>
<td><?php echo $item['serialnumber']; ?></td>
<?php
}
?>
</tr>
<?php
if ($item['discount'] > 0) {
?>
<tr>
<td colspan="3"
style="font-weight: bold;"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<td style="text-align:right;"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php
}
}
?>
<?php
}
?>
<?php
if($this->config->item('receipt_show_total_discount') && $discount > 0)
{
?>

View File

@@ -112,26 +112,35 @@ if (isset($error_message))
<?php
foreach($cart as $line=>$item)
{
if($item['print_option'] == PRINT_YES)
{
?>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><textarea rows="4" cols="6"><?php echo $item['name']; ?></textarea></td>
<td style='text-align:center;'><textarea rows="5" cols="6"><?php echo to_quantity_decimals($item['quantity']); ?></textarea></td>
<td><textarea rows="4" cols="6"><?php if($print_price_info) echo to_currency($item['price']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo $item['discount'] . '%'; ?></textarea></td>
<td style='border-right: solid 1px; text-align:right;'><textarea rows="4" cols="6"><?php if($print_price_info) echo to_currency($item['discounted_total']); ?></textarea></td>
</tr>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><textarea rows="4" cols="6"><?php echo $item['name']; ?></textarea></td>
<td style='text-align:center;'><textarea rows="5" cols="6"><?php echo to_quantity_decimals($item['quantity']); ?></textarea>
</td>
<td><textarea rows="4" cols="6"><?php if ($print_price_info) echo to_currency($item['price']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="4"
cols="6"><?php echo $item['discount'] . '%'; ?></textarea></td>
<td style='border-right: solid 1px; text-align:right;'><textarea rows="4"
cols="6"><?php if ($print_price_info) echo to_currency($item['discounted_total']); ?></textarea>
</td>
</tr>
<?php if($item['is_serialized'] || $item['allow_alt_description'] && !empty($item['description']))
{
?>
<tr class="item-row">
<td></td>
<td class="item-name" colspan = "4"><div><?php echo $item['description']; ?></div></td>
<td style='text-align:center;'><textarea><?php echo $item['serialnumber']; ?></textarea></td>
</tr>
<?php
}
<?php if ($item['is_serialized'] || $item['allow_alt_description'] && !empty($item['description']))
{
?>
<tr class="item-row">
<td></td>
<td class="item-name" colspan="4">
<div><?php echo $item['description']; ?></div>
</td>
<td style='text-align:center;'><textarea><?php echo $item['serialnumber']; ?></textarea></td>
</tr>
<?php
}
}
}
?>
<tr>

View File

@@ -78,16 +78,19 @@
<?php
foreach($cart as $line=>$item)
{
?>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo $item['discount'] .'%'; ?></td>
<td class="total-line"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php
if($item['print_option'] == PRINT_YES)
{
?>
<tr class="item-row">
<td><?php echo $item['item_number']; ?></td>
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo $item['discount'] . '%'; ?></td>
<td class="total-line"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php
}
}
?>