Provide a way to enter a line total and have the quantity sold automatically calculated (#1647)

This commit is contained in:
FrancescoUK
2018-01-02 22:07:20 +00:00
3 changed files with 12 additions and 11 deletions

View File

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

View File

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

View File

@@ -179,11 +179,11 @@ if(isset($success))
<?php
if($item['item_type'] == 2)
{
echo form_input(array('name'=>'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']);
}
?>
</td>
@@ -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()
});