diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index f49c49386..4b8f6a776 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)) 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);