From b4ac74aa55cffb56dd2541f8e5006a1512740c66 Mon Sep 17 00:00:00 2001 From: Martes Erede Date: Thu, 29 Jan 2015 16:14:12 +0100 Subject: [PATCH 1/2] Bugfix #28 if invoice number is empty, set it to null, so no error occurs --- application/controllers/receivings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index 23d1bb50c..1c326b979 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -344,7 +344,7 @@ class Receivings extends Secure_area 'supplier_id' => $this->input->post('supplier_id') ? $this->input->post('supplier_id') : null, 'employee_id' => $this->input->post('employee_id'), 'comment' => $this->input->post('comment'), - 'invoice_number' => $this->input->post('invoice_number') + 'invoice_number' => $this->input->post('invoice_number') != '' ? $this->input->post('invoice_number') : null ); if ($this->Receiving->update($receiving_data, $receiving_id)) From 4ddec66d7b5bd0075d1b7d2176045e986726261b Mon Sep 17 00:00:00 2001 From: Martes Erede Date: Thu, 29 Jan 2015 16:22:44 +0100 Subject: [PATCH 2/2] #27 Using bc-style operations now. --- application/models/item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/models/item.php b/application/models/item.php index 7b18032fb..7025e1294 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -614,7 +614,7 @@ class Item extends CI_Model $old_total_quantity = $this->db->get()->row()->quantity; $total_quantity = $old_total_quantity + $items_received; - $average_price = ($items_received * $new_price + $old_total_quantity * $old_price)/$total_quantity; + $average_price = bcdiv(bcadd(bcmul($items_received, $new_price), bcmul($old_total_quantity, $old_price)), $total_quantity); $data = array('cost_price' => $average_price);