From e1ddcbbb5b54cd6221c4a8110e7915f6495b333b Mon Sep 17 00:00:00 2001 From: jekkos Date: Wed, 16 Sep 2015 19:31:26 +0200 Subject: [PATCH] Rename Item_quantities model to Item_quantity Rename Stock_locations model to Stock_location Fix barcode generation in receipts (sales + receivings) --- application/config/autoload.php | 2 +- application/controllers/config.php | 10 +- application/controllers/items.php | 32 ++--- application/controllers/receivings.php | 8 +- application/controllers/reports.php | 14 +- application/controllers/sales.php | 8 +- application/libraries/Barcode_lib.php | 14 +- application/libraries/Item_lib.php | 2 +- application/libraries/Receiving_lib.php | 8 +- application/libraries/Sale_lib.php | 8 +- ...{item_quantities.php => item_quantity.php} | 128 +++++++++--------- application/models/receiving.php | 6 +- application/models/sale.php | 6 +- ...stock_locations.php => stock_location.php} | 2 +- 14 files changed, 125 insertions(+), 123 deletions(-) rename application/models/{item_quantities.php => item_quantity.php} (95%) rename application/models/{stock_locations.php => stock_location.php} (99%) diff --git a/application/config/autoload.php b/application/config/autoload.php index 39d60c5ff..7b66e9bce 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -109,7 +109,7 @@ $autoload['language'] = array(); | */ -$autoload['model'] = array('Appconfig','Person','Customer','Employee','Module','Item', 'Item_taxes', 'Sale', 'Sale_suspended', 'Supplier','Inventory','Receiving','Giftcard', 'Item_kit', 'Item_kit_items','Stock_locations','Item_quantities'); +$autoload['model'] = array('Appconfig','Person','Customer','Employee','Module','Item', 'Item_taxes', 'Sale', 'Sale_suspended', 'Supplier','Inventory','Receiving','Giftcard', 'Item_kit', 'Item_kit_items','Stock_location','Item_quantity'); /* End of file autoload.php */ diff --git a/application/controllers/config.php b/application/controllers/config.php index 0d44ec21e..635cd5eee 100644 --- a/application/controllers/config.php +++ b/application/controllers/config.php @@ -11,7 +11,7 @@ class Config extends Secure_area function index() { $location_names = array(); - $data['stock_locations'] = $this->Stock_locations->get_all()->result_array(); + $data['stock_locations'] = $this->Stock_location->get_all()->result_array(); $data['support_barcode'] = $this->barcode_lib->get_list_barcodes(); $this->load->view("configs/manage", $data); $this->_remove_duplicate_cookies(); @@ -86,7 +86,7 @@ class Config extends Secure_area function stock_locations() { - $stock_locations = $this->Stock_locations->get_all()->result_array(); + $stock_locations = $this->Stock_location->get_all()->result_array(); $this->load->view('partial/stock_locations', array('stock_locations' => $stock_locations)); } @@ -105,7 +105,7 @@ class Config extends Secure_area { $this->db->trans_start(); - $deleted_locations = $this->Stock_locations->get_allowed_locations(); + $deleted_locations = $this->Stock_location->get_allowed_locations(); foreach($this->input->post() as $key => $value) { if (strstr($key, 'stock_location')) @@ -114,7 +114,7 @@ class Config extends Secure_area unset($deleted_locations[$location_id]); // save or update $location_data = array('location_name' => $value); - if ($this->Stock_locations->save($location_data, $location_id)) + if ($this->Stock_location->save($location_data, $location_id)) { $this->_clear_session_state(); } @@ -123,7 +123,7 @@ class Config extends Secure_area // all locations not available in post will be deleted now foreach ($deleted_locations as $location_id => $location_name) { - $this->Stock_locations->delete($location_id); + $this->Stock_location->delete($location_id); } $success = $this->db->trans_complete(); echo json_encode(array('success'=>$success,'message'=>$this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully'))); diff --git a/application/controllers/items.php b/application/controllers/items.php index 4ac1b7474..aa559b5da 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -12,7 +12,7 @@ class Items extends Secure_area implements iData_controller function index($limit_from=0) { $stock_location=$this->item_lib->get_item_location(); - $stock_locations=$this->Stock_locations->get_allowed_locations(); + $stock_locations=$this->Stock_location->get_allowed_locations(); $data['controller_name']=$this->get_controller_name(); $data['form_width']=$this->get_form_width(); @@ -215,7 +215,7 @@ class Items extends Secure_area implements iData_controller $item_id = $this->input->post('row_id'); $item_info = $this->Item->get_info($item_id); $stock_location = $this->item_lib->get_item_location(); - $item_quantity = $this->Item_quantities->get_item_quantity($item_id,$stock_location); + $item_quantity = $this->Item_quantity->get_item_quantity($item_id,$stock_location); $item_info->quantity = $item_quantity->quantity; $data_row=get_item_data_row($item_info,$this); @@ -238,10 +238,10 @@ class Items extends Secure_area implements iData_controller $data['default_tax_1_rate']=($item_id==-1) ? $this->Appconfig->get('default_tax_1_rate') : ''; $data['default_tax_2_rate']=($item_id==-1) ? $this->Appconfig->get('default_tax_2_rate') : ''; - $locations_data = $this->Stock_locations->get_undeleted_all()->result_array(); + $locations_data = $this->Stock_location->get_undeleted_all()->result_array(); foreach($locations_data as $location) { - $quantity = $this->Item_quantities->get_item_quantity($item_id,$location['location_id'])->quantity; + $quantity = $this->Item_quantity->get_item_quantity($item_id,$location['location_id'])->quantity; $quantity = ($item_id == -1) ? null: $quantity; $location_array[$location['location_id']] = array('location_name'=>$location['location_name'], 'quantity'=>$quantity); $data['stock_locations']= $location_array; @@ -255,11 +255,11 @@ class Items extends Secure_area implements iData_controller $data['item_info']=$this->Item->get_info($item_id); $data['stock_locations'] = array(); - $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + $stock_locations = $this->Stock_location->get_undeleted_all()->result_array(); foreach($stock_locations as $location_data) { $data['stock_locations'][$location_data['location_id']] = $location_data['location_name']; - $data['item_quantities'][$location_data['location_id']] = $this->Item_quantities->get_item_quantity($item_id,$location_data['location_id'])->quantity; + $data['item_quantities'][$location_data['location_id']] = $this->Item_quantity->get_item_quantity($item_id,$location_data['location_id'])->quantity; } $this->load->view("items/inventory",$data); @@ -270,11 +270,11 @@ class Items extends Secure_area implements iData_controller $data['item_info']=$this->Item->get_info($item_id); $data['stock_locations'] = array(); - $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + $stock_locations = $this->Stock_location->get_undeleted_all()->result_array(); foreach($stock_locations as $location_data) { $data['stock_locations'][$location_data['location_id']] = $location_data['location_name']; - $data['item_quantities'][$location_data['location_id']] = $this->Item_quantities->get_item_quantity($item_id,$location_data['location_id'])->quantity; + $data['item_quantities'][$location_data['location_id']] = $this->Item_quantity->get_item_quantity($item_id,$location_data['location_id'])->quantity; } $this->load->view("items/count_details",$data); @@ -401,17 +401,17 @@ class Items extends Secure_area implements iData_controller //Save item quantity - $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + $stock_locations = $this->Stock_location->get_undeleted_all()->result_array(); foreach($stock_locations as $location_data) { $updated_quantity = $this->input->post($location_data['location_id'].'_quantity'); $location_detail = array('item_id'=>$item_id, 'location_id'=>$location_data['location_id'], 'quantity'=>$updated_quantity); - $item_quantity = $this->Item_quantities->get_item_quantity($item_id, $location_data['location_id']); + $item_quantity = $this->Item_quantity->get_item_quantity($item_id, $location_data['location_id']); if ($item_quantity->quantity != $updated_quantity || $new_item) { - $success &= $this->Item_quantities->save($location_detail, $item_id, $location_data['location_id']); + $success &= $this->Item_quantity->save($location_detail, $item_id, $location_data['location_id']); $inv_data = array ( @@ -492,13 +492,13 @@ class Items extends Secure_area implements iData_controller //Update stock quantity - $item_quantity= $this->Item_quantities->get_item_quantity($item_id,$location_id); + $item_quantity= $this->Item_quantity->get_item_quantity($item_id,$location_id); $item_quantity_data = array( 'item_id'=>$item_id, 'location_id'=>$location_id, 'quantity'=>$item_quantity->quantity + $this->input->post('newquantity') ); - if($this->Item_quantities->save($item_quantity_data,$item_id,$location_id)) + if($this->Item_quantity->save($item_quantity_data,$item_id,$location_id)) { echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_updating').' '. $cur_item_info->name,'item_id'=>$item_id)); @@ -662,7 +662,7 @@ class Items extends Secure_area implements iData_controller $cols = count($data); // array to store information if location got a quantity - $allowed_locations = $this->Stock_locations->get_allowed_locations(); + $allowed_locations = $this->Stock_location->get_allowed_locations(); for ($col = 24; $col < $cols; $col = $col + 2) { $location_id = $data[$col]; @@ -673,7 +673,7 @@ class Items extends Secure_area implements iData_controller 'location_id' => $location_id, 'quantity' => $data[$col + 1], ); - $this->Item_quantities->save($item_quantity_data, $item_data['item_id'], $location_id); + $this->Item_quantity->save($item_quantity_data, $item_data['item_id'], $location_id); $excel_data = array ( 'trans_items'=>$item_data['item_id'], @@ -699,7 +699,7 @@ class Items extends Secure_area implements iData_controller 'location_id' => $location_id, 'quantity' => 0, ); - $this->Item_quantities->save($item_quantity_data, $item_data['item_id'], $data[$col]); + $this->Item_quantity->save($item_quantity_data, $item_data['item_id'], $data[$col]); $excel_data = array ( diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index eddf58780..4f5355b30 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -45,7 +45,7 @@ class Receivings extends Secure_area $mode = $this->input->post("mode"); $this->receiving_lib->set_mode($mode); } - else if ($this->Stock_locations->is_allowed_location($stock_source, 'receivings')) + else if ($this->Stock_location->is_allowed_location($stock_source, 'receivings')) { $this->receiving_lib->set_stock_source($stock_source); $this->receiving_lib->set_stock_destination($stock_destination); @@ -183,7 +183,7 @@ class Receivings extends Secure_area $data['receipt_title']=$this->lang->line('recvs_receipt'); $data['transaction_time']= date($this->config->item('dateformat').' '.$this->config->item('timeformat')); $data['mode']=$this->receiving_lib->get_mode(); - $data['show_stock_locations']=$this->Stock_locations->show_locations('receivings'); + $data['show_stock_locations']=$this->Stock_location->show_locations('receivings'); $supplier_id=$this->receiving_lib->get_supplier(); $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; $comment = $this->input->post('comment'); @@ -307,7 +307,7 @@ class Receivings extends Secure_area $data['mode']=$this->receiving_lib->get_mode(); $data['receipt_title']=$this->lang->line('recvs_receipt'); $data['transaction_time']= date($this->config->item('dateformat').' '.$this->config->item('timeformat'), strtotime($receiving_info['receiving_time'])); - $data['show_stock_locations']=$this->Stock_locations->show_locations('receivings'); + $data['show_stock_locations']=$this->Stock_location->show_locations('receivings'); $supplier_id=$this->receiving_lib->get_supplier(); $emp_info=$this->Employee->get_info($receiving_info['employee_id']); $data['payment_type']=$receiving_info['payment_type']; @@ -335,7 +335,7 @@ class Receivings extends Secure_area $data['modes']=array('receive'=>$this->lang->line('recvs_receiving'),'return'=>$this->lang->line('recvs_return')); $data['mode']=$this->receiving_lib->get_mode(); - $data['stock_locations']=$this->Stock_locations->get_allowed_locations('receivings'); + $data['stock_locations']=$this->Stock_location->get_allowed_locations('receivings'); $show_stock_locations = count($data['stock_locations']) > 1; if ($show_stock_locations) { diff --git a/application/controllers/reports.php b/application/controllers/reports.php index 3c7455ccb..99de820e1 100644 --- a/application/controllers/reports.php +++ b/application/controllers/reports.php @@ -346,7 +346,7 @@ class Reports extends Secure_area function date_input_sales() { $data = $this->_get_common_report_data(); - $stock_locations = $this->Stock_locations->get_allowed_locations('sales'); + $stock_locations = $this->Stock_location->get_allowed_locations('sales'); $stock_locations['all'] = $this->lang->line('reports_all'); $data['stock_locations'] = array_reverse($stock_locations, TRUE); $data['mode'] = 'sale'; @@ -356,7 +356,7 @@ class Reports extends Secure_area function date_input_recv() { $data = $this->_get_common_report_data(); - $stock_locations = $this->Stock_locations->get_allowed_locations('receivings'); + $stock_locations = $this->Stock_location->get_allowed_locations('receivings'); $stock_locations['all'] = $this->lang->line('reports_all'); $data['stock_locations'] = array_reverse($stock_locations, TRUE); $data['mode'] = 'receiving'; @@ -868,7 +868,7 @@ class Reports extends Secure_area $summary_data = array(); $details_data = array(); - $show_locations = $this->Stock_locations->multiple_locations(); + $show_locations = $this->Stock_location->multiple_locations(); foreach($report_data['summary'] as $key=>$row) { @@ -879,7 +879,7 @@ class Reports extends Secure_area $quantity_purchased = $drow['quantity_purchased']; if ($show_locations) { - $quantity_purchased .= ' [' . $this->Stock_locations->get_location_name($drow['item_location']) . ']'; + $quantity_purchased .= ' [' . $this->Stock_location->get_location_name($drow['item_location']) . ']'; } $details_data[$key][] = array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], $quantity_purchased, to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%'); } @@ -911,7 +911,7 @@ class Reports extends Secure_area $summary_data = array(); $details_data = array(); - $show_locations = $this->Stock_locations->multiple_locations(); + $show_locations = $this->Stock_location->multiple_locations(); foreach($report_data['summary'] as $key=>$row) { @@ -922,7 +922,7 @@ class Reports extends Secure_area $quantity_purchased = $drow['receiving_quantity'] > 1 ? $drow['quantity_purchased'] . ' x ' . $drow['receiving_quantity'] : $drow['quantity_purchased']; if ($show_locations) { - $quantity_purchased .= ' [' . $this->Stock_locations->get_location_name($drow['item_location']) . ']'; + $quantity_purchased .= ' [' . $this->Stock_location->get_location_name($drow['item_location']) . ']'; } $details_data[$key][] = array($drow['item_number'], $drow['name'], $drow['category'], $quantity_purchased, to_currency($drow['total']), $drow['discount_percent'].'%'); } @@ -980,7 +980,7 @@ class Reports extends Secure_area $model = $this->Inventory_Summary; $data['item_count'] = $model->getItemCountDropdownArray(); - $stock_locations = $this->Stock_locations->get_allowed_locations(); + $stock_locations = $this->Stock_location->get_allowed_locations(); $stock_locations['all'] = $this->lang->line('reports_all'); $data['stock_locations'] = array_reverse($stock_locations, TRUE); diff --git a/application/controllers/sales.php b/application/controllers/sales.php index ff47c8763..42a3230c8 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -141,7 +141,7 @@ class Sales extends Secure_area $mode = $this->input->post("mode"); $this->sale_lib->set_mode($mode); } - else if ($this->Stock_locations->is_allowed_location($stock_location, 'sales')) + else if ($this->Stock_location->is_allowed_location($stock_location, 'sales')) { $this->sale_lib->set_sale_location($stock_location); } @@ -324,7 +324,7 @@ class Sales extends Secure_area $data['receipt_title']=$this->lang->line('sales_receipt'); $data['transaction_time']= date($this->config->item('dateformat').' '.$this->config->item('timeformat')); $data['transaction_date']= date($this->config->item('dateformat'), strtotime($data['transaction_time'])); - $data['show_stock_locations']=$this->Stock_locations->show_locations('sales'); + $data['show_stock_locations']=$this->Stock_location->show_locations('sales'); $customer_id=$this->sale_lib->get_customer(); $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; $comment=$this->sale_lib->get_comment(); @@ -542,7 +542,7 @@ class Sales extends Secure_area $data['receipt_title']=$this->lang->line('sales_receipt'); $data['transaction_time']= date($this->config->item('dateformat').' '.$this->config->item('timeformat'), strtotime($sale_info['sale_time'])); $data['transaction_date']= date($this->config->item('dateformat'), strtotime($sale_info['sale_time'])); - $data['show_stock_locations']=$this->Stock_locations->show_locations('sales'); + $data['show_stock_locations']=$this->Stock_location->show_locations('sales'); $customer_id=$this->sale_lib->get_customer(); $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; $emp_info=$this->Employee->get_info($employee_id); @@ -698,7 +698,7 @@ class Sales extends Secure_area $data['modes']=array('sale'=>$this->lang->line('sales_sale'),'return'=>$this->lang->line('sales_return')); $data['mode']=$this->sale_lib->get_mode(); - $data['stock_locations']=$this->Stock_locations->get_allowed_locations('sales'); + $data['stock_locations']=$this->Stock_location->get_allowed_locations('sales'); $data['stock_location']=$this->sale_lib->get_sale_location(); $data['subtotal']=$this->sale_lib->get_subtotal(TRUE); diff --git a/application/libraries/Barcode_lib.php b/application/libraries/Barcode_lib.php index e62c3b4a6..3fbdd203a 100644 --- a/application/libraries/Barcode_lib.php +++ b/application/libraries/Barcode_lib.php @@ -65,19 +65,15 @@ class Barcode_lib } } - private function generate_barcode($item, $barcode_config) + public function generate_barcode($barcode_content, $barcode_config) { try { $barcode = $this->get_barcode_instance($barcode_config['barcode_type']); - - $barcode_content = $barcode_config['barcode_content'] !== "id" && isset($item['item_number']) ? $item['item_number'] : $item['item_id']; $barcode->setData($barcode_content); $barcode->setQuality($barcode_config['barcode_quality']); $barcode->setDimensions($barcode_config['barcode_width'], $barcode_config['barcode_height']); - $barcode->draw(); - return $barcode->base64(); } catch(Exception $e) @@ -85,6 +81,12 @@ class Barcode_lib echo 'Caught exception: ', $e->getMessage(), "\n"; } } + + public function generate_item_barcode($item, $barcode_config) + { + $barcode_content = $barcode_config['barcode_content'] !== "id" && isset($item['item_number']) ? $item['item_number'] : $item['item_id']; + return $this->generate_barcode($barcode_content, $barcode_config); + } public function get_barcode($item, $barcode_config) { @@ -115,7 +117,7 @@ class Barcode_lib { $display_table = ""; $display_table .= ""; - $barcode = $this->generate_barcode($item, $barcode_config); + $barcode = $this->generate_item_barcode($item, $barcode_config); $display_table .= ""; $display_table .= ""; $display_table .= ""; diff --git a/application/libraries/Item_lib.php b/application/libraries/Item_lib.php index 08e29f66d..bce8f1fbe 100644 --- a/application/libraries/Item_lib.php +++ b/application/libraries/Item_lib.php @@ -13,7 +13,7 @@ class Item_lib { if(!$this->CI->session->userdata('item_location')) { - $location_id = $this->CI->Stock_locations->get_default_location_id(); + $location_id = $this->CI->Stock_location->get_default_location_id(); $this->set_item_location($location_id); } return $this->CI->session->userdata('item_location'); diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 7ffe841b9..6aa13c995 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -52,7 +52,7 @@ class Receiving_lib { if(!$this->CI->session->userdata('recv_stock_source')) { - $location_id = $this->CI->Stock_locations->get_default_location_id(); + $location_id = $this->CI->Stock_location->get_default_location_id(); $this->set_stock_source($location_id); } return $this->CI->session->userdata('recv_stock_source'); @@ -124,7 +124,7 @@ class Receiving_lib { if(!$this->CI->session->userdata('recv_stock_destination')) { - $location_id = $this->CI->Stock_locations->get_default_location_id(); + $location_id = $this->CI->Stock_location->get_default_location_id(); $this->set_stock_destination($location_id); } return $this->CI->session->userdata('recv_stock_destination'); @@ -192,7 +192,7 @@ class Receiving_lib array( 'item_id'=>$item_id, 'item_location'=>$item_location, - 'stock_name'=>$this->CI->Stock_locations->get_location_name($item_location), + 'stock_name'=>$this->CI->Stock_location->get_location_name($item_location), 'line'=>$insertkey, 'name'=>$item_info->name, 'description'=>$description!=null ? $description: $item_info->description, @@ -201,7 +201,7 @@ class Receiving_lib 'is_serialized'=>$item_info->is_serialized, 'quantity'=>$quantity, 'discount'=>$discount, - 'in_stock'=>$this->CI->Item_quantities->get_item_quantity($item_id, $item_location)->quantity, + 'in_stock'=>$this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity, 'price'=>$price, 'receiving_quantity'=>$receiving_quantity!=null ? $receiving_quantity : $item_info->receiving_quantity, 'total'=>$this->get_item_total($quantity, $price, $discount) diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index a812f0e0e..b39db973f 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -209,7 +209,7 @@ class Sale_lib { if(!$this->CI->session->userdata('sale_location')) { - $location_id = $this->CI->Stock_locations->get_default_location_id(); + $location_id = $this->CI->Stock_location->get_default_location_id(); $this->set_sale_location($location_id); } return $this->CI->session->userdata('sale_location'); @@ -289,7 +289,7 @@ class Sale_lib array( 'item_id'=>$item_id, 'item_location'=>$item_location, - 'stock_name'=>$this->CI->Stock_locations->get_location_name($item_location), + 'stock_name'=>$this->CI->Stock_location->get_location_name($item_location), 'line'=>$insertkey, 'name'=>$item_info->name, 'item_number'=>$item_info->item_number, @@ -299,7 +299,7 @@ class Sale_lib 'is_serialized'=>$item_info->is_serialized, 'quantity'=>$quantity, 'discount'=>$discount, - 'in_stock'=>$this->CI->Item_quantities->get_item_quantity($item_id, $item_location)->quantity, + 'in_stock'=>$this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity, 'price'=>$price, 'total'=>$total, 'discounted_total'=>$this->get_item_total($quantity, $price, $discount, TRUE) @@ -332,7 +332,7 @@ class Sale_lib //$item = $this->CI->Item->get_info($item_id); - $item_quantity = $this->CI->Item_quantities->get_item_quantity($item_id,$item_location)->quantity; + $item_quantity = $this->CI->Item_quantity->get_item_quantity($item_id,$item_location)->quantity; $quantity_added = $this->get_quantity_already_added($item_id,$item_location); if ($item_quantity - $quantity_added < 0) diff --git a/application/models/item_quantities.php b/application/models/item_quantity.php similarity index 95% rename from application/models/item_quantities.php rename to application/models/item_quantity.php index 0094fd32e..551731c00 100644 --- a/application/models/item_quantities.php +++ b/application/models/item_quantity.php @@ -1,66 +1,66 @@ -db->from('item_quantities'); - $this->db->where('item_id',$item_id); - $this->db->where('location_id',$location_id); - $query = $this->db->get(); - - return ($query->num_rows()==1); - } - - function save($location_detail, $item_id, $location_id) - { - if (!$this->exists($item_id,$location_id)) - { - if($this->db->insert('item_quantities',$location_detail)) - { - return true; - } - return false; - } - - $this->db->where('item_id', $item_id); - $this->db->where('location_id', $location_id); - return $this->db->update('item_quantities',$location_detail); - } - - function get_item_quantity($item_id, $location_id) - { - $this->db->from('item_quantities'); - $this->db->where('item_id',$item_id); - $this->db->where('location_id',$location_id); - $result = $this->db->get()->row(); - if(empty($result) == true) - { - //Get empty base parent object, as $item_id is NOT an item - $result=new stdClass(); - //Get all the fields from items table (TODO to be reviewed) - $fields = $this->db->list_fields('item_quantities'); - foreach ($fields as $field) - { - $result->$field=''; - } +db->from('item_quantities'); + $this->db->where('item_id',$item_id); + $this->db->where('location_id',$location_id); + $query = $this->db->get(); + + return ($query->num_rows()==1); + } + + function save($location_detail, $item_id, $location_id) + { + if (!$this->exists($item_id,$location_id)) + { + if($this->db->insert('item_quantities',$location_detail)) + { + return true; + } + return false; + } + + $this->db->where('item_id', $item_id); + $this->db->where('location_id', $location_id); + return $this->db->update('item_quantities',$location_detail); + } + + function get_item_quantity($item_id, $location_id) + { + $this->db->from('item_quantities'); + $this->db->where('item_id',$item_id); + $this->db->where('location_id',$location_id); + $result = $this->db->get()->row(); + if(empty($result) == true) + { + //Get empty base parent object, as $item_id is NOT an item + $result=new stdClass(); + //Get all the fields from items table (TODO to be reviewed) + $fields = $this->db->list_fields('item_quantities'); + foreach ($fields as $field) + { + $result->$field=''; + } $result->quantity = 0; - } - return $result; - } - - /* - * changes to quantity of an item according to the given amount. - * if $quantity_change is negative, it will be subtracted, - * if it is positive, it will be added to the current quantity - */ - function change_quantity($item_id, $location_id, $quantity_change) - { - $quantity_old = $this->get_item_quantity($item_id, $location_id); - $quantity_new = $quantity_old->quantity + intval($quantity_change); - $location_detail = array('item_id'=>$item_id, - 'location_id'=>$location_id, - 'quantity'=>$quantity_new); - return $this->save($location_detail,$item_id,$location_id); - } -} + } + return $result; + } + + /* + * changes to quantity of an item according to the given amount. + * if $quantity_change is negative, it will be subtracted, + * if it is positive, it will be added to the current quantity + */ + function change_quantity($item_id, $location_id, $quantity_change) + { + $quantity_old = $this->get_item_quantity($item_id, $location_id); + $quantity_new = $quantity_old->quantity + intval($quantity_change); + $location_detail = array('item_id'=>$item_id, + 'location_id'=>$location_id, + 'quantity'=>$quantity_new); + return $this->save($location_detail,$item_id,$location_id); + } +} ?> \ No newline at end of file diff --git a/application/models/receiving.php b/application/models/receiving.php index 01d24ad08..2573e2468 100644 --- a/application/models/receiving.php +++ b/application/models/receiving.php @@ -106,8 +106,8 @@ class Receiving extends CI_Model } //Update stock quantity - $item_quantity = $this->Item_quantities->get_item_quantity($item['item_id'], $item['item_location']); - $this->Item_quantities->save(array('quantity'=>$item_quantity->quantity + $items_received, + $item_quantity = $this->Item_quantity->get_item_quantity($item['item_id'], $item['item_location']); + $this->Item_quantity->save(array('quantity'=>$item_quantity->quantity + $items_received, 'item_id'=>$item['item_id'], 'location_id'=>$item['item_location']), $item['item_id'], $item['item_location']); @@ -169,7 +169,7 @@ class Receiving extends CI_Model $this->Inventory->insert($inv_data); // update quantities - $this->Item_quantities->change_quantity($item['item_id'], + $this->Item_quantity->change_quantity($item['item_id'], $item['item_location'], $item['quantity_purchased']*-1); } diff --git a/application/models/sale.php b/application/models/sale.php index 596e3ec83..39bda9e49 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -289,8 +289,8 @@ class Sale extends CI_Model $this->db->insert('sales_items',$sales_items_data); //Update stock quantity - $item_quantity = $this->Item_quantities->get_item_quantity($item['item_id'], $item['item_location']); - $this->Item_quantities->save(array('quantity'=>$item_quantity->quantity - $item['quantity'], + $item_quantity = $this->Item_quantity->get_item_quantity($item['item_id'], $item['item_location']); + $this->Item_quantity->save(array('quantity'=>$item_quantity->quantity - $item['quantity'], 'item_id'=>$item['item_id'], 'location_id'=>$item['item_location']), $item['item_id'], $item['item_location']); @@ -374,7 +374,7 @@ class Sale extends CI_Model $this->Inventory->insert($inv_data); // update quantities - $this->Item_quantities->change_quantity($item['item_id'], + $this->Item_quantity->change_quantity($item['item_id'], $item['item_location'], $item['quantity_purchased']); } diff --git a/application/models/stock_locations.php b/application/models/stock_location.php similarity index 99% rename from application/models/stock_locations.php rename to application/models/stock_location.php index a9d6ce183..5d5337e1d 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_location.php @@ -1,5 +1,5 @@
" . $this->manage_display_layout($barcode_config['barcode_first_row'], $item, $barcode_config) . "
" . $this->manage_display_layout($barcode_config['barcode_second_row'], $item, $barcode_config) . "
" . $this->manage_display_layout($barcode_config['barcode_third_row'], $item, $barcode_config) . "