diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 0e2f871ea..4df21f37e 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -454,9 +454,9 @@ class Sales extends Secure_Controller { $data = array(); - $this->form_validation->set_rules('price', 'lang:items_price', 'required|callback_numeric'); - $this->form_validation->set_rules('quantity', 'lang:items_quantity', 'required|callback_numeric'); - $this->form_validation->set_rules('discount', 'lang:items_discount', 'required|callback_numeric'); + $this->form_validation->set_rules('price', 'lang:sales_price', 'required|callback_numeric'); + $this->form_validation->set_rules('quantity', 'lang:sales_quantity', 'required|callback_numeric'); + $this->form_validation->set_rules('discount', 'lang:sales_discount', 'required|callback_numeric'); $description = $this->input->post('description'); $serialnumber = $this->input->post('serialnumber'); @@ -464,11 +464,11 @@ class Sales extends Secure_Controller $quantity = parse_decimals($this->input->post('quantity')); $discount = parse_decimals($this->input->post('discount')); $item_location = $this->input->post('location'); - $total = $this->input->post('total') != '' ? $this->input->post('total') : NULL; + $discounted_total = $this->input->post('discounted_total') != '' ? $this->input->post('discounted_total') : NULL; if($this->form_validation->run() != FALSE) { - $this->sale_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $price, $total); + $this->sale_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $price, $discounted_total); } else { diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index cc9d3bef1..c286002ca 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -883,15 +883,16 @@ class Sale_lib return -1; } - public function edit_item($line, $description, $serialnumber, $quantity, $discount, $price, $total=NULL) + public function edit_item($line, $description, $serialnumber, $quantity, $discount, $price, $discounted_total=NULL) { $items = $this->get_cart(); if(isset($items[$line])) { $line = &$items[$line]; - if($total != NULL && $total != $line['total']) + if($discounted_total != NULL && $discounted_total != $line['discounted_total']) { - $quantity = $this->get_quantity_sold($total, $price); + // Note when entered the "discounted_total" is expected to be entered without a discount + $quantity = $this->get_quantity_sold($discounted_total, $price); } $line['description'] = $description; $line['serialnumber'] = $serialnumber; diff --git a/application/views/sales/register.php b/application/views/sales/register.php index 6be9d9552..f8484d3e4 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -179,11 +179,11 @@ if(isset($success)) 'total', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($item['total']), 'tabindex'=>++$tabindex)); + echo form_input(array('name'=>'discounted_total', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($item['discounted_total']), 'tabindex'=>++$tabindex)); } else { - echo to_currency($item['price']*$item['quantity']-$item['price']*$item['quantity']*$item['discount']/100); + echo to_currency($item['discounted_total']); } ?> @@ -803,7 +803,7 @@ $(document).ready(function() } } - $('[name="price"],[name="quantity"],[name="discount"],[name="description"],[name="serialnumber"],[name="total"]').change(function() { + $('[name="price"],[name="quantity"],[name="discount"],[name="description"],[name="serialnumber"],[name="discounted_total"]').change(function() { $(this).parents("tr").prevAll("form:first").submit() });