diff --git a/application/controllers/items.php b/application/controllers/items.php index a48078b47..4526148d6 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -207,7 +207,7 @@ class Items extends Secure_area implements iData_controller { $quantity = $this->Item_quantities->get_item_quantity($item_id, $location['location_id'])->quantity; $quantity = ($item_id == -1) ? null: $quantity; - $location_array['stock_'.$location['location_id']] = array('location_name'=>$location['location_name'], + $location_array[$location['location_id']] = array('location_name'=>$location['location_name'], 'quantity'=>$quantity); } $data['stock_locations']= $location_array; @@ -224,8 +224,8 @@ class Items extends Secure_area implements iData_controller $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); foreach($stock_locations as $location_data) { - $data['stock_locations']['stock_'.$location_data['location_id']] = $location_data['location_name']; - $data['item_quantities']['stock_'.$location_data['location_id']] = $this->Item_quantities->get_item_quantity($item_id,$location_data['location_id'])->quantity; + $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; } $this->load->view("items/inventory",$data); @@ -236,11 +236,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_locations->get_undeleted_all()->result_array(); foreach($stock_locations as $location_data) { - $data['stock_locations']['stock_'.$location_data['location_id']] = $location_data['location_name']; - $data['item_quantities']['stock_'.$location_data['location_id']] = $this->Item_quantities->get_item_quantity($item_id,$location_data['location_id'])->quantity; + $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; } $this->load->view("items/count_details",$data); @@ -298,7 +298,6 @@ class Items extends Secure_area implements iData_controller 'allow_alt_description'=>$this->input->post('allow_alt_description'), 'is_serialized'=>$this->input->post('is_serialized'), 'deleted'=>$this->input->post('is_deleted'), /** Parq 131215 **/ - 'stock_type'=>$this->input->post('stock_type'), 'custom1'=>$this->input->post('custom1'), /**GARRISON ADDED 4/21/2013**/ 'custom2'=>$this->input->post('custom2'),/**GARRISON ADDED 4/21/2013**/ 'custom3'=>$this->input->post('custom3'),/**GARRISON ADDED 4/21/2013**/ @@ -347,24 +346,26 @@ class Items extends Secure_area implements iData_controller $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); foreach($stock_locations as $location_data) { - $updated_quantity = $this->input->post('stock_'.$location_data['location_id'].'_quantity'); + $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']); - $this->Item_quantities->save($location_detail, $item_quantity->item_quantity_id); - - $inv_data = array - ( - 'trans_date'=>date('Y-m-d H:i:s'), - 'trans_items'=>$item_id, - 'trans_user'=>$employee_id, - 'trans_location'=>$location_data['location_id'], - 'trans_comment'=>$this->lang->line('items_manually_editing_of_quantity'), - 'trans_inventory'=>$item_quantity->item_quantity_id ? $updated_quantity - $item_quantity->quantity : $updated_quantity - ); - $this->Inventory->insert($inv_data); + $item_quantity = $this->Item_quantities->get_item_quantity($item_id, $location_data['location_id']); + if ($item_quantity->quantity != $updated_quantity) + { + $this->Item_quantities->save($location_detail, $item_id, $location_data['location_id']); + + $inv_data = array + ( + 'trans_date'=>date('Y-m-d H:i:s'), + 'trans_items'=>$item_id, + 'trans_user'=>$employee_id, + 'trans_location'=>$location_data['location_id'], + 'trans_comment'=>$this->lang->line('items_manually_editing_of_quantity'), + 'trans_inventory'=>$updated_quantity - $item_quantity->quantity + ); + $this->Inventory->insert($inv_data); + } } } else//failure @@ -380,7 +381,7 @@ class Items extends Secure_area implements iData_controller { $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; $cur_item_info = $this->Item->get_info($item_id); - $location_id = $this->get_location_id_from_stock_location($this->input->post('stock_location')); + $location_id = $this->input->post('stock_location'); $inv_data = array ( 'trans_date'=>date('Y-m-d H:i:s'), @@ -400,7 +401,7 @@ class Items extends Secure_area implements iData_controller 'location_id'=>$location_id, 'quantity'=>$item_quantity->quantity + $this->input->post('newquantity') ); - if($this->Item_quantities->save($item_quantity_data,$item_quantity->item_quantity_id)) + if($this->Item_quantities->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)); @@ -504,7 +505,6 @@ class Items extends Secure_area implements iData_controller $item_data = array( 'name' => $data[1], 'description' => $data[13], - 'location' => $data[12], 'category' => $data[2], 'cost_price' => $data[4], 'unit_price' => $data[5], @@ -607,9 +607,5 @@ class Items extends Secure_area implements iData_controller echo $this->Item->is_sale_store_item_exist($item_number); } - function get_location_id_from_stock_location($location) - { - return substr($location, 6); - } } ?> \ No newline at end of file diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index f0c4634ac..c5e57004a 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -35,15 +35,20 @@ class Receivings extends Secure_area function change_mode() { - $mode = $this->input->post("mode"); - $this->receiving_lib->set_mode($mode); - - $stock_source = $this->input->post("stock_source"); - $this->receiving_lib->set_stock_source($stock_source); - - $stock_deatination = $this->input->post("stock_deatination"); - $this->receiving_lib->set_stock_destination($stock_deatination); - $this->receiving_lib->empty_cart(); + $stock_destination = $this->input->post('stock_destination'); + $stock_source = $this->input->post("stock_source"); + if ((!$stock_source || $stock_source == $this->receiving_lib->get_stock_source()) && + (!$stock_destination || $stock_destination == $this->receiving_lib->get_stock_destination())) + { + $this->receiving_lib->empty_cart(); + $mode = $this->input->post("mode"); + $this->receiving_lib->set_mode($mode); + } + else + { + $this->receiving_lib->set_stock_source($stock_source); + $this->receiving_lib->set_stock_destination($stock_destination); + } $this->_reload(); } @@ -53,25 +58,26 @@ class Receivings extends Secure_area $mode = $this->receiving_lib->get_mode(); $item_id_or_number_or_item_kit_or_receipt = $this->input->post("item"); $quantity = ($mode=="receive" or $mode=="requisition") ? 1:-1; - + $item_location = $this->receiving_lib->get_stock_source(); if($this->receiving_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt) && $mode=='return') { - $this->receiving_lib->return_entire_receiving($item_id_or_number_or_item_kit_or_receipt); + $this->receiving_lib->return_entire_receiving($item_id_or_number_or_item_kit_or_receipt,$item_location); } elseif($this->receiving_lib->is_valid_item_kit($item_id_or_number_or_item_kit_or_receipt)) { - $this->receiving_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt); + $this->receiving_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt,$item_location); } else { if($mode == 'requisition') { - if(!$this->receiving_lib->add_item_unit($item_id_or_number_or_item_kit_or_receipt)) + // FIXME need to review this part + if(!$this->receiving_lib->add_item_unit($item_id_or_number_or_item_kit_or_receipt,$item_location)) $data['error']=$this->lang->line('reqs_unable_to_add_item'); } else { - if(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt,$quantity)) + if(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt,$quantity,$item_location)) $data['error']=$this->lang->line('recvs_unable_to_add_item'); } @@ -92,6 +98,7 @@ class Receivings extends Secure_area $price = $this->input->post("price"); $quantity = $this->input->post("quantity"); $discount = $this->input->post("discount"); + $item_location = $this->input->post("location"); if ($this->form_validation->run() != FALSE) { @@ -259,7 +266,7 @@ class Receivings extends Secure_area $data['modes']['requisition'] = $this->lang->line('recvs_requisition'); foreach($stock_locations as $location_data) { - $data['stock_locations']['stock_'.$location_data['location_id']] = $location_data['location_name']; + $data['stock_locations'][$location_data['location_id']] = $location_data['location_name']; } $data['stock_source']=$this->receiving_lib->get_stock_source(); diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 8d88094c9..d60e83da1 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -35,12 +35,17 @@ class Sales extends Secure_area function change_mode() { - $this->sale_lib->clear_all(); - $mode = $this->input->post("mode"); - $this->sale_lib->set_mode($mode); - - $stock_location = $this->input->post("stock_location"); - $this->sale_lib->set_sale_location($stock_location); + $stock_location = $this->input->post("stock_location"); + if (!$stock_location || $stock_location == $this->sale_lib->get_sale_location()) + { + $this->sale_lib->clear_all(); + $mode = $this->input->post("mode"); + $this->sale_lib->set_mode($mode); + } + else + { + $this->sale_lib->set_sale_location($stock_location); + } $this->_reload(); } @@ -117,6 +122,7 @@ class Sales extends Secure_area $mode = $this->sale_lib->get_mode(); $item_id_or_number_or_item_kit_or_receipt = $this->input->post("item"); $quantity = ($mode=="return")? -1:1; + $item_location = $this->sale_lib->get_sale_location(); if($this->sale_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt) && $mode=='return') { @@ -124,14 +130,14 @@ class Sales extends Secure_area } elseif($this->sale_lib->is_valid_item_kit($item_id_or_number_or_item_kit_or_receipt)) { - $this->sale_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt); + $this->sale_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt,$item_location); } - elseif(!$this->sale_lib->add_item($item_id_or_number_or_item_kit_or_receipt,$quantity)) + elseif(!$this->sale_lib->add_item($item_id_or_number_or_item_kit_or_receipt,$quantity,$item_location)) { $data['error']=$this->lang->line('sales_unable_to_add_item'); } - if($this->sale_lib->out_of_stock($item_id_or_number_or_item_kit_or_receipt)) + if($this->sale_lib->out_of_stock($item_id_or_number_or_item_kit_or_receipt,$item_location)) { $data['warning'] = $this->lang->line('sales_quantity_less_than_zero'); } @@ -150,6 +156,7 @@ class Sales extends Secure_area $price = $this->input->post("price"); $quantity = $this->input->post("quantity"); $discount = $this->input->post("discount"); + $item_location = $this->input->post("location"); if ($this->form_validation->run() != FALSE) @@ -161,7 +168,7 @@ class Sales extends Secure_area $data['error']=$this->lang->line('sales_error_editing_item'); } - if($this->sale_lib->out_of_stock($this->sale_lib->get_item_id($line))) + if($this->sale_lib->out_of_stock($this->sale_lib->get_item_id($line),$item_location)) { $data['warning'] = $this->lang->line('sales_quantity_less_than_zero'); } @@ -197,7 +204,6 @@ class Sales extends Secure_area $data['payments']=$this->sale_lib->get_payments(); $data['amount_change']=to_currency($this->sale_lib->get_amount_due() * -1); $data['employee']=$emp_info->first_name.' '.$emp_info->last_name; - $data['stock_location']=$this->sale_lib->get_sale_location(); if($customer_id!=-1) { @@ -206,7 +212,7 @@ class Sales extends Secure_area } //SAVE sale to database - $data['sale_id']='POS '.$this->Sale->save($data['cart'], $customer_id,$employee_id,$comment,$data['payments'], $data['stock_location']); + $data['sale_id']='POS '.$this->Sale->save($data['cart'], $customer_id,$employee_id,$comment,$data['payments']); if ($data['sale_id'] == 'POS -1') { $data['error_message'] = $this->lang->line('sales_transaction_failed'); @@ -334,7 +340,7 @@ class Sales extends Secure_area } /* Changed the conditional to account for floating point rounding */ - if ( ( ($this->sale_lib->get_mode() == 'sale_retail') || ($this->sale_lib->get_mode() == 'sale_wholesale')) && + if ( ($this->sale_lib->get_mode() == 'sale') && ( ( to_currency_no_money( $this->sale_lib->get_total() ) - $total_payments ) > 1e-6 ) ) { return false; @@ -347,7 +353,7 @@ class Sales extends Secure_area { $person_info = $this->Employee->get_logged_in_employee_info(); $data['cart']=$this->sale_lib->get_cart(); - $data['modes']['return']=$this->lang->line('sales_return'); + $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'] = array(); @@ -356,14 +362,12 @@ class Sales extends Secure_area if ($show_stock_locations) { foreach($stock_locations as $location_data) { - $data['stock_locations']['stock_'.$location_data['location_id']] = $location_data['location_name']; + $data['stock_locations'][$location_data['location_id']] = $location_data['location_name']; } $data['stock_location']=$this->sale_lib->get_sale_location(); } $data['show_stock_locations'] = $show_stock_locations; - $data['modes']=array('sale'=>$this->lang->line('sales_sale'),'return'=>$this->lang->line('sales_return')); - $data['mode']=$this->sale_lib->get_mode(); $data['subtotal']=$this->sale_lib->get_subtotal(); $data['taxes']=$this->sale_lib->get_taxes(); $data['total']=$this->sale_lib->get_total(); diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 8798d1e46..f48273587 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')) { $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); - $location_name = 'stock_'.$stock_locations[0]['location_id']; + $location_name = $stock_locations[0]['location_id']; $this->set_stock_source($location_name); } return $this->CI->session->userdata('recv_stock_source'); @@ -68,7 +68,7 @@ class Receiving_lib if(!$this->CI->session->userdata('recv_stock_destination')) { $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); - $location_name = 'stock_'.$stock_locations[0]['location_id']; + $location_name = $stock_locations[0]['location_id']; $this->set_stock_destination($location_name); } return $this->CI->session->userdata('recv_stock_destination'); @@ -84,7 +84,7 @@ class Receiving_lib return substr($location, 6); } - function add_item($item_id,$quantity=1,$discount=0,$price=null,$description=null,$serialnumber=null) + function add_item($item_id,$quantity=1,$item_location,$discount=0,$price=null,$description=null,$serialnumber=null) { //make sure item exists in database. if(!$this->CI->Item->exists($item_id)) @@ -121,7 +121,7 @@ class Receiving_lib $maxkey = $item['line']; } - if($item['item_id']==$item_id) + if($item['item_id']==$item_id && $item['item_location']==$item_location) { $itemalreadyinsale=TRUE; $updatekey=$item['line']; @@ -129,20 +129,23 @@ class Receiving_lib } $insertkey=$maxkey+1; - + $item_info=$this->CI->Item->get_info($item_id); //array records are identified by $insertkey and item_id is just another field. $item = array(($insertkey)=> array( 'item_id'=>$item_id, + 'item_location'=>$item_location, + 'stock_name'=>$this->CI->Stock_locations->get_location_name($item_location), 'line'=>$insertkey, - 'name'=>$this->CI->Item->get_info($item_id)->name, - 'description'=>$description!=null ? $description: $this->CI->Item->get_info($item_id)->description, + 'name'=>$item_info->name, + 'description'=>$description!=null ? $description: $item_info->description, 'serialnumber'=>$serialnumber!=null ? $serialnumber: '', - 'allow_alt_description'=>$this->CI->Item->get_info($item_id)->allow_alt_description, - 'is_serialized'=>$this->CI->Item->get_info($item_id)->is_serialized, + 'allow_alt_description'=>$item_info->allow_alt_description, + 'is_serialized'=>$item_info->is_serialized, 'quantity'=>$quantity, 'discount'=>$discount, - 'price'=>$price!=null ? $price: $this->CI->Item->get_info($item_id)->cost_price + 'in_stock'=>$this->CI->Item_quantities->get_item_quantity($item_id, $item_location)->quantity, + 'price'=>$price!=null ? $price: $item_info->cost_price ) ); @@ -319,12 +322,12 @@ class Receiving_lib foreach($this->CI->Receiving->get_receiving_items($receiving_id)->result() as $row) { - $this->add_item($row->item_id,-$row->quantity_purchased,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); + $this->add_item($row->item_id,-$row->quantity_purchased,$row->item_location,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); } $this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); } - function add_item_kit($external_item_kit_id) + function add_item_kit($external_item_kit_id,$item_location) { //KIT # $pieces = explode(' ',$external_item_kit_id); @@ -332,31 +335,31 @@ class Receiving_lib foreach ($this->CI->Item_kit_items->get_info($item_kit_id) as $item_kit_item) { - $this->add_item($item_kit_item['item_id'], $item_kit_item['quantity']); + $this->add_item($item_kit_item['item_id'],$item_kit_item['quantity'],$item_location); } } - function copy_entire_receiving($receiving_id) + function copy_entire_receiving($receiving_id,$item_location) { $this->empty_cart(); $this->delete_supplier(); foreach($this->CI->Receiving->get_receiving_items($receiving_id)->result() as $row) { - $this->add_item($row->item_id,$row->quantity_purchased,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); + $this->add_item($row->item_id,$row->quantity_purchased,$item_location,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); } $this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); } - function copy_entire_requisition($requisition_id) + function copy_entire_requisition($requisition_id,$item_location) { $this->empty_cart(); $this->delete_supplier(); foreach($this->CI->Receiving->get_requisition_items($requisition_id)->result() as $row) { - $this->add_item_unit($row->item_id,$row->requisition_quantity,$row->description); + $this->add_item_unit($row->item_id,$row->requisition_quantity,$item_location,$row->description); } $this->set_supplier($this->CI->Receiving->get_supplier($requisition_id)->person_id); diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index c26567d78..80d815312 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -172,7 +172,7 @@ class Sale_lib if(!$this->CI->session->userdata('sale_location')) { $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); - $location_name = 'stock_'.$stock_locations[0]['location_id']; + $location_name = $stock_locations[0]['location_id']; $this->set_sale_location($location_name); } return $this->CI->session->userdata('sale_location'); @@ -183,7 +183,7 @@ class Sale_lib $this->CI->session->set_userdata('sale_location',$location); } - function add_item($item_id,$quantity=1,$discount=0,$price=null,$description=null,$serialnumber=null) + function add_item($item_id,$quantity=1,$item_location,$discount=0,$price=null,$description=null,$serialnumber=null) { //make sure item exists if($this->validate_item($item_id) == false) @@ -216,7 +216,7 @@ class Sale_lib $maxkey = $item['line']; } - if($item['item_id']==$item_id) + if($item['item_id']==$item_id && $item['item_location']==$item_location) { $itemalreadyinsale=TRUE; $updatekey=$item['line']; @@ -224,26 +224,29 @@ class Sale_lib } $insertkey=$maxkey+1; - + $item_info=$this->CI->Item->get_info($item_id); //array/cart records are identified by $insertkey and item_id is just another field. $item = array(($insertkey)=> array( 'item_id'=>$item_id, + 'item_location'=>$item_location, + 'stock_name'=>$this->CI->Stock_locations->get_location_name($item_location), 'line'=>$insertkey, - 'name'=>$this->CI->Item->get_info($item_id)->name, - 'item_number'=>$this->CI->Item->get_info($item_id)->item_number, - 'description'=>$description!=null ? $description: $this->CI->Item->get_info($item_id)->description, + 'name'=>$item_info->name, + 'item_number'=>$item_info->item_number, + 'description'=>$description!=null ? $description: $item_info->description, 'serialnumber'=>$serialnumber!=null ? $serialnumber: '', - 'allow_alt_description'=>$this->CI->Item->get_info($item_id)->allow_alt_description, - 'is_serialized'=>$this->CI->Item->get_info($item_id)->is_serialized, + 'allow_alt_description'=>$item_info->allow_alt_description, + 'is_serialized'=>$item_info->is_serialized, 'quantity'=>$quantity, 'discount'=>$discount, - 'price'=>$price!=null ? $price: $this->CI->Item->get_info($item_id)->unit_price + 'in_stock'=>$this->CI->Item_quantities->get_item_quantity($item_id, $item_location)->quantity, + 'price'=>$price!=null ? $price: $item_info->unit_price ) ); //Item already exists and is not serialized, add to quantity - if($itemalreadyinsale && ($this->CI->Item->get_info($item_id)->is_serialized ==0) ) + if($itemalreadyinsale && ($item_info->is_serialized ==0) ) { $items[$updatekey]['quantity']+=$quantity; } @@ -258,12 +261,7 @@ class Sale_lib } - function get_location_id_from_stock_location($location) - { - return substr($location, 6); - } - - function out_of_stock($item_id) + function out_of_stock($item_id,$item_location) { //make sure item exists if($this->validate_item($item_id) == false) @@ -273,9 +271,8 @@ class Sale_lib //$item = $this->CI->Item->get_info($item_id); - $location_id = $this->get_location_id_from_stock_location($this->get_sale_location()); - $item_quantity = $this->CI->Item_quantities->get_item_quantity($item_id, $location_id)->quantity; - $quanity_added = $this->get_quantity_already_added($item_id); + $item_quantity = $this->CI->Item_quantities->get_item_quantity($item_id,$item_location)->quantity; + $quanity_added = $this->get_quantity_already_added($item_id,$item_location); if ($item_quantity - $quanity_added < 0) { @@ -285,13 +282,13 @@ class Sale_lib return false; } - function get_quantity_already_added($item_id) + function get_quantity_already_added($item_id,$item_location) { $items = $this->get_cart(); $quanity_already_added = 0; foreach ($items as $item) { - if($item['item_id']==$item_id) + if($item['item_id']==$item_id && $item['item_location']==$item_location) { $quanity_already_added+=$item['quantity']; } @@ -368,12 +365,12 @@ class Sale_lib foreach($this->CI->Sale->get_sale_items($sale_id)->result() as $row) { - $this->add_item($row->item_id,-$row->quantity_purchased,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); + $this->add_item($row->item_id,-$row->quantity_purchased,$row->item_location,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); } $this->set_customer($this->CI->Sale->get_customer($sale_id)->person_id); } - function add_item_kit($external_item_kit_id) + function add_item_kit($external_item_kit_id,$item_location) { //KIT # $pieces = explode(' ',$external_item_kit_id); @@ -381,7 +378,7 @@ class Sale_lib foreach ($this->CI->Item_kit_items->get_info($item_kit_id) as $item_kit_item) { - $this->add_item($item_kit_item['item_id'], $item_kit_item['quantity']); + $this->add_item($item_kit_item['item_id'],$item_kit_item['quantity'],$item_location); } } @@ -392,7 +389,7 @@ class Sale_lib foreach($this->CI->Sale->get_sale_items($sale_id)->result() as $row) { - $this->add_item($row->item_id,$row->quantity_purchased,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); + $this->add_item($row->item_id,$row->quantity_purchased,$row->item_location,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); } foreach($this->CI->Sale->get_sale_payments($sale_id)->result() as $row) { @@ -409,7 +406,7 @@ class Sale_lib foreach($this->CI->Sale_suspended->get_sale_items($sale_id)->result() as $row) { - $this->add_item($row->item_id,$row->quantity_purchased,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); + $this->add_item($row->item_id,$row->quantity_purchased,$row->item_location,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); } foreach($this->CI->Sale_suspended->get_sale_payments($sale_id)->result() as $row) { @@ -517,15 +514,7 @@ class Sale_lib { //try to get item id given an item_number $mode = $this->get_mode(); - $item_id; - if($mode == 'sale_retail') - { - $item_id = $this->CI->Item->get_item_id($item_id, 'sale_stock'); - } - elseif($mode == 'sale_wholesale') - { - $item_id = $this->CI->Item->get_item_id($item_id, 'warehouse'); - } + $item_id = $this->CI->Item->get_item_id($item_id); if(!$item_id) return false; diff --git a/application/models/inventory.php b/application/models/inventory.php index 9b6ba757c..d6e8b5f74 100644 --- a/application/models/inventory.php +++ b/application/models/inventory.php @@ -12,7 +12,7 @@ class Inventory extends CI_Model $this->db->where('trans_items',$item_id); if($location_id != false) { - $this->db->where('location_id',$location_id); + $this->db->where('trans_location',$location_id); } $this->db->order_by("trans_date", "desc"); return $this->db->get(); diff --git a/application/models/item.php b/application/models/item.php index cc90a6dcf..2a5347118 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -108,12 +108,11 @@ class Item extends CI_Model /* Get an item id given an item number */ - function get_item_id($item_number, $stock_type='warehouse') + function get_item_id($item_number) { $this->db->from('items'); $this->db->where('item_number',$item_number); $this->db->where('deleted',0); // Parq 131226 - $this->db->where('stock_type',$stock_type); $query = $this->db->get(); @@ -606,4 +605,4 @@ class Item extends CI_Model return ($query->num_rows()==1); } } -?> +?> \ No newline at end of file diff --git a/application/models/item_quantities.php b/application/models/item_quantities.php index 8ea7eb569..48059e535 100644 --- a/application/models/item_quantities.php +++ b/application/models/item_quantities.php @@ -1,28 +1,29 @@ db->from('item_quantities'); - $this->db->where('item_quantity_id',$item_quantity_id); + $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_quantity_id=false) + function save($location_detail, $item_id, $location_id) { - if (!$item_quantity_id or !$this->exists($item_quantity_id)) + if (!($item_id && $location_id) or !$this->exists($item_id,$location_id)) { if($this->db->insert('item_quantities',$location_detail)) { - $location_detail['item_quantity_id']=$this->db->insert_id(); return true; } return false; } - $this->db->where('item_quantity_id', $item_quantity_id); + $this->db->where('item_id', $item_id); + $this->db->where('location_id', $location_id); return $this->db->update('item_quantities',$location_detail); } diff --git a/application/models/receiving.php b/application/models/receiving.php index 778a09d27..067a7cb69 100644 --- a/application/models/receiving.php +++ b/application/models/receiving.php @@ -24,7 +24,7 @@ class Receiving extends CI_Model return ($query->num_rows()==1); } - function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$stock_location,$receiving_id=false) + function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$receiving_id=false) { if(count($items)==0) return -1; @@ -63,10 +63,10 @@ class Receiving extends CI_Model $this->db->insert('receivings_items',$receivings_items_data); //Update stock quantity - $item_quantity = $this->Item_quantities->get_item_quantity($item['item_id'], $this->receiving_lib->get_location_id_from_stock_location($stock_location)); + $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_id'=>$item['item_id'], - 'location_id'=>$this->receiving_lib->get_location_id_from_stock_location($stock_location)), $item_quantity->item_quantity_id); + 'location_id'=>$item['item_location']), $item_quantity->item_quantity_id); $qty_recv = $item['quantity']; @@ -76,7 +76,7 @@ class Receiving extends CI_Model 'trans_date'=>date('Y-m-d H:i:s'), 'trans_items'=>$item['item_id'], 'trans_user'=>$employee_id, - 'location_id'=>$this->receiving_lib->get_location_id_from_stock_location($stock_location), + 'trans_location'=>$item['item_location'], 'trans_comment'=>$recv_remarks, 'trans_inventory'=>$qty_recv ); @@ -115,7 +115,6 @@ class Receiving extends CI_Model foreach($items as $line=>$item) { $cur_item_info = $this->Item->get_info($item['item_id']); - $related_item_number = $this->Item_unit->get_info($item['item_id'])->related_number; $related_item_unit_quantity = $this->Item_unit->get_info($item['item_id'])->unit_quantity; $related_item_total_quantity = $item['quantity']*$related_item_unit_quantity; $related_item_id; @@ -141,10 +140,8 @@ class Receiving extends CI_Model 'unit_price'=>$cur_item_info->unit_price, 'quantity'=>$related_item_total_quantity, 'reorder_level'=>$cur_item_info->reorder_level, - 'location'=>$cur_item_info->location, 'allow_alt_description'=>$cur_item_info->allow_alt_description, 'is_serialized'=>$cur_item_info->is_serialized, - 'stock_type'=>'sale_stock', 'custom1'=>$cur_item_info->custom1, /**GARRISON ADDED 4/21/2013**/ 'custom2'=>$cur_item_info->custom2,/**GARRISON ADDED 4/21/2013**/ 'custom3'=>$cur_item_info->custom3,/**GARRISON ADDED 4/21/2013**/ @@ -184,7 +181,6 @@ class Receiving extends CI_Model 'location'=>$item_data_temp->location, 'allow_alt_description'=>$item_data_temp->allow_alt_description, 'is_serialized'=>$item_data_temp->is_serialized, - 'stock_type'=>'sale_stock', 'custom1'=>$item_data_temp->custom1, /**GARRISON ADDED 4/21/2013**/ 'custom2'=>$item_data_temp->custom2,/**GARRISON ADDED 4/21/2013**/ 'custom3'=>$item_data_temp->custom3,/**GARRISON ADDED 4/21/2013**/ diff --git a/application/models/sale.php b/application/models/sale.php index 2c5abdf68..4e518125b 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -28,7 +28,7 @@ class Sale extends CI_Model return $success; } - function save ($items,$customer_id,$employee_id,$comment,$payments,$stock_location, $sale_id=false) + function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=false) { if(count($items)==0) return -1; @@ -88,16 +88,17 @@ class Sale extends CI_Model 'quantity_purchased'=>$item['quantity'], 'discount_percent'=>$item['discount'], 'item_cost_price' => $cur_item_info->cost_price, - 'item_unit_price'=>$item['price'] + 'item_unit_price'=>$item['price'], + 'item_location'=>$item['item_location'] ); $this->db->insert('sales_items',$sales_items_data); //Update stock quantity - $item_quantity = $this->Item_quantities->get_item_quantity($item['item_id'], $this->sale_lib->get_location_id_from_stock_location($this->sale_lib->get_sale_location())); + $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_id'=>$item['item_id'], - 'location_id'=>$this->sale_lib->get_location_id_from_stock_location($stock_location)), $item_quantity->item_quantity_id); + 'location_id'=>$item['item_location']), $item_quantity->item_quantity_id); //Ramel Inventory Tracking @@ -109,7 +110,7 @@ class Sale extends CI_Model 'trans_date'=>date('Y-m-d H:i:s'), 'trans_items'=>$item['item_id'], 'trans_user'=>$employee_id, - 'location_id'=>$this->sale_lib->get_location_id_from_stock_location($stock_location), + 'trans_location'=>$item['item_location'], 'trans_comment'=>$sale_remarks, 'trans_inventory'=>$qty_buy ); diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php index 42619bddf..ae7c4fd1c 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_locations.php @@ -43,6 +43,14 @@ class Stock_locations extends CI_Model return $this->db->get()->row()->location_id; } + function get_location_name($location_id) + { + $this->db->from('stock_locations'); + $this->db->where('deleted',0); + $this->db->where('location_id',$location_id); + return $this->db->get()->row()->location_name; + } + function array_save($stock_locations) { $location_db = $this->get_all()->result_array(); diff --git a/application/views/items/count_details.php b/application/views/items/count_details.php index 746ad3bdd..276f4e08b 100644 --- a/application/views/items/count_details.php +++ b/application/views/items/count_details.php @@ -63,7 +63,7 @@ echo form_open('items/save_inventory/'.$item_info->item_id,array('id'=>'item_for @@ -120,12 +120,11 @@ $(document).ready(function() display_stock(); }); -function display_stock(stock) +function display_stock(location_id) { var item_quantities= ; - document.getElementById("quantity").value = item_quantities[stock]; + document.getElementById("quantity").value = item_quantities[location_id]; - var location_id = stock.substring(6); var inventory_data = ; var employee_data = ; @@ -141,7 +140,7 @@ function display_stock(stock) for (var index = 0; index < inventory_data.length; index++) { var data = inventory_data[index]; - if(data['location_id'] == location_id) + if(data['trans_location'] == location_id) { var tr = document.createElement('TR'); tr.setAttribute("bgColor","#CCCCCC"); diff --git a/application/views/items/form.php b/application/views/items/form.php index 5a00385a2..59a60b4ce 100644 --- a/application/views/items/form.php +++ b/application/views/items/form.php @@ -354,11 +354,6 @@ $(document).ready(function() $("#category").result(function(event, data, formatted){}); $("#category").search(); -/** GARRISON ADDED 5/18/2013 **/ - $("#location").autocomplete("",{max:100,minChars:0,delay:10}); - $("#location").result(function(event, data, formatted){}); - $("#location").search(); - $("#custom1").autocomplete("",{max:100,minChars:0,delay:10}); $("#custom1").result(function(event, data, formatted){}); $("#custom1").search(); diff --git a/application/views/receivings/receiving.php b/application/views/receivings/receiving.php index 97d865799..e4173f8fe 100644 --- a/application/views/receivings/receiving.php +++ b/application/views/receivings/receiving.php @@ -16,19 +16,21 @@ if(isset($error)) lang->line('recvs_mode') ?> - + lang->line('recvs_stock_source') ?> - > lang->line('recvs_stock_destination') ?> - - + lang->line('recvs_stock_destination') ?> + 'add_item_form')); ?>