Fixed sale suspending / unsuspending (adapt db scripts)

Cleanup old code
More code review
Update item_quantities database model (composite pk)
This commit is contained in:
jekkos-t520
2014-08-05 09:02:08 +02:00
parent 8802831831
commit cf20194e23
16 changed files with 197 additions and 191 deletions

View File

@@ -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);
}
}
?>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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);
}
}
?>
?>

View File

@@ -1,28 +1,29 @@
<?php
class Item_quantities extends CI_Model
{
function exists($item_quantity_id)
function exists($item_id,$location_id)
{
$this->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);
}

View File

@@ -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**/

View File

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

View File

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

View File

@@ -63,7 +63,7 @@ echo form_open('items/save_inventory/'.$item_info->item_id,array('id'=>'item_for
</td>
<td>
<?php
echo form_dropdown('stock_location',$stock_locations,current($stock_locations),'onchange="display_stock(this.value)"');
echo form_dropdown('stock_location',$stock_locations,current($stock_locations),'onchange="display_stock(this.value)"');
?>
</td>
</tr>
@@ -120,12 +120,11 @@ $(document).ready(function()
display_stock(<?php echo json_encode(key($stock_locations)); ?>);
});
function display_stock(stock)
function display_stock(location_id)
{
var item_quantities= <?php echo json_encode($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 = <?php echo json_encode($inventory_array); ?>;
var employee_data = <?php echo json_encode($employee_name); ?>;
@@ -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");

View File

@@ -354,11 +354,6 @@ $(document).ready(function()
$("#category").result(function(event, data, formatted){});
$("#category").search();
/** GARRISON ADDED 5/18/2013 **/
$("#location").autocomplete("<?php echo site_url('items/suggest_location');?>",{max:100,minChars:0,delay:10});
$("#location").result(function(event, data, formatted){});
$("#location").search();
$("#custom1").autocomplete("<?php echo site_url('items/suggest_custom1');?>",{max:100,minChars:0,delay:10});
$("#custom1").result(function(event, data, formatted){});
$("#custom1").search();

View File

@@ -16,19 +16,21 @@ if(isset($error))
<span><?php echo $this->lang->line('recvs_mode') ?></span>
<?php echo form_dropdown('mode',$modes,$mode,'onchange="$(\'#mode_form\').submit();"'); ?>
<?php if ($show_stock_locations): ?>
<?php
if ($show_stock_locations)
{
?>
<span><?php echo $this->lang->line('recvs_stock_source') ?></span>
<?php echo form_dropdown('stock_source',$stock_locations,$stock_source,'onchange="$(\'#mode_form\').submit();"'); ?>
<?php
$opacity_style='';
if($mode!='requisition')
{
$opacity_style = 'style="opacity:0.0;"';
}
if($mode=='requisition')
{
?>
<span <?php echo $opacity_style; ?> > <?php echo $this->lang->line('recvs_stock_destination') ?></span>
<?php echo form_dropdown('stock_deatination',$stock_locations,$stock_destination,'onchange="$(\'#mode_form\').submit();" '.$opacity_style); ?>
<?php endif; ?>
<span><?php echo $this->lang->line('recvs_stock_destination') ?></span>
<?php echo form_dropdown('stock_destination',$stock_locations,$stock_destination,'onchange="$(\'#mode_form\').submit();"');
}
}
?>
</form>
<?php echo form_open("receivings/add",array('id'=>'add_item_form')); ?>
<label id="item_label" for="item">
@@ -59,32 +61,27 @@ if(isset($error))
<table id="register">
<thead>
<tr>
<?php
if($mode=='requisition')
{
?>
<th style="width:11%;"><?php echo $this->lang->line('common_delete'); ?></th>
<th style="width:30%;"><?php echo $this->lang->line('recvs_item_name'); ?></th>
<th style="width:11%;"><?php echo $this->lang->line('reqs_quantity'); ?></th>
<th style="width:25%;"><?php echo $this->lang->line('reqs_related_item'); ?></th>
<th style="width:11%;"><?php echo $this->lang->line('reqs_unit_quantity'); ?></th>
<th style="width:15%;"><?php echo $this->lang->line('reqs_unit_quantity_total'); ?></th>
<th style="width:11%;"><?php echo $this->lang->line('recvs_edit'); ?></th>
<?php
}
else
{
?>
<th style="width:11%;"><?php echo $this->lang->line('common_delete'); ?></th>
<th style="width:30%;"><?php echo $this->lang->line('recvs_item_name'); ?></th>
<?php
if($mode!='requisition')
{
?>
<th style="width:11%;"><?php echo $this->lang->line('recvs_cost'); ?></th>
<?php
}
?>
<th style="width:11%;"><?php echo $this->lang->line('recvs_quantity'); ?></th>
<?php
if($mode!='requisition')
{
?>
<th style="width:11%;"><?php echo $this->lang->line('recvs_discount'); ?></th>
<?php
}
?>
<th style="width:15%;"><?php echo $this->lang->line('recvs_total'); ?></th>
<th style="width:11%;"><?php echo $this->lang->line('recvs_edit'); ?></th>
<?php
}
?>
</tr>
</thead>
<tbody id="cart_contents">
@@ -107,12 +104,15 @@ else
?>
<tr>
<td><?php echo anchor("receivings/delete_item/$line",'['.$this->lang->line('common_delete').']');?></td>
<td style="align:center;"><?php echo $item['name']; ?><br /> [<?php echo $this->Item->get_info($item['item_id'])->quantity; ?> in stock]</td>
<td style="align:center;"><?php echo $item['name']; ?><br /> [<?php echo $item['in_stock']; ?> in <?php echo $item['stock_name']; ?>]
<?php echo form_hidden('location', $item['item_location']); ?>
</td>
<td>
<?php
echo form_input(array('name'=>'quantity','value'=>$item['quantity'],'size'=>'2'));
?>
</td>
<td><?php echo $item['related_item']; ?></td>
<td><?php echo $item['unit_quantity']; ?></td>
@@ -129,7 +129,8 @@ else
?>
<tr>
<td><?php echo anchor("receivings/delete_item/$line",'['.$this->lang->line('common_delete').']');?></td>
<td style="align:center;"><?php echo $item['name']; ?><br />
<td style="align:center;"><?php echo $item['name']; ?><br /> [<?php echo $item['in_stock']; ?> in <?php echo $item['stock_name']; ?>]</td>
<?php echo form_hidden('location', $item['item_location']); ?>
<?php
echo $item['description'];

View File

@@ -55,7 +55,6 @@ else
?>
</div>
-->
</form>
<table id="register">
<thead>
@@ -93,17 +92,16 @@ else
<tr>
<td><?php echo anchor("sales/delete_item/$line",'['.$this->lang->line('common_delete').']');?></td>
<td><?php echo $item['item_number']; ?></td>
<td style="align: center;"><?php echo $item['name']; ?><br /> [<?php
$item_quantity = $this->Item_quantities->get_item_quantity($item['item_id'], $this->sale_lib->get_location_id_from_stock_location($stock_location));
echo $item_quantity->quantity;
?> in stock]</td>
<td style="align: center;"><?php echo $item['name']; ?><br /> [<?php echo $item['in_stock'] ?> in <?php echo $item['stock_name']; ?>]
<?php echo form_hidden('location', $item['item_location']); ?>
</td>
<?php if ($items_module_allowed)
{
?>
<td><?php echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6'));?></td>
<?php
}
else
@@ -482,7 +480,8 @@ function post_item_form_submit(response)
{
if(response.success)
{
$("#item").attr("value",response.item_id);
var $stock_location = $("select[name='stock_location']").val();
$("#item_location").val($stock_location);
$("#add_item_form").submit();
}
}

View File

@@ -146,7 +146,6 @@ CREATE TABLE `ospos_items` (
`allow_alt_description` tinyint(1) NOT NULL,
`is_serialized` tinyint(1) NOT NULL,
`deleted` int(1) NOT NULL DEFAULT '0',
`stock_type` enum('sale_stock','warehouse') NOT NULL DEFAULT 'warehouse',
`custom1` VARCHAR(25) NOT NULL,
`custom2` VARCHAR(25) NOT NULL,
`custom3` VARCHAR(25) NOT NULL,
@@ -228,11 +227,10 @@ CREATE TABLE `ospos_item_kit_items` (
--
CREATE TABLE IF NOT EXISTS `ospos_item_quantities` (
`item_quantity_id` int(11) NOT NULL AUTO_INCREMENT,
`item_id` int(11) NOT NULL,
`location_id` int(11) NOT NULL,
`quantity` int(11) NOT NULL,
PRIMARY KEY (`item_quantity_id`),
PRIMARY KEY (`item_id`,`location_id`),
KEY `item_id` (`item_id`),
KEY `location_id` (`location_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
@@ -365,6 +363,7 @@ CREATE TABLE `ospos_receivings_items` (
`quantity_purchased` decimal(15,2) NOT NULL DEFAULT '0',
`item_cost_price` decimal(15,2) NOT NULL,
`item_unit_price` decimal(15,2) NOT NULL,
`item_location` int(11) NOT NULL,
`discount_percent` decimal(15,2) NOT NULL DEFAULT '0',
PRIMARY KEY (`receiving_id`,`item_id`,`line`),
KEY `item_id` (`item_id`)
@@ -413,9 +412,12 @@ CREATE TABLE `ospos_sales_items` (
`quantity_purchased` decimal(15,2) NOT NULL DEFAULT '0.00',
`item_cost_price` decimal(15,2) NOT NULL,
`item_unit_price` decimal(15,2) NOT NULL,
`item_location` int(11) NOT NULL,
`discount_percent` decimal(15,2) NOT NULL DEFAULT '0',
PRIMARY KEY (`sale_id`,`item_id`,`line`),
KEY `item_id` (`item_id`)
KEY `sale_id` (`sale_id`),
KEY `item_id` (`item_id`),
KEY `item_location` (`item_location`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
@@ -436,6 +438,7 @@ CREATE TABLE `ospos_sales_items_taxes` (
`name` varchar(255) NOT NULL,
`percent` decimal(15,2) NOT NULL,
PRIMARY KEY (`sale_id`,`item_id`,`line`,`name`,`percent`),
KEY `sale_id` (`sale_id`),
KEY `item_id` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -454,7 +457,8 @@ CREATE TABLE `ospos_sales_payments` (
`sale_id` int(10) NOT NULL,
`payment_type` varchar(40) NOT NULL,
`payment_amount` decimal(15,2) NOT NULL,
PRIMARY KEY (`sale_id`,`payment_type`)
PRIMARY KEY (`sale_id`,`payment_type`),
KEY `sale_id` (`sale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
@@ -500,8 +504,10 @@ CREATE TABLE `ospos_sales_suspended_items` (
`quantity_purchased` decimal(15,2) NOT NULL DEFAULT '0.00',
`item_cost_price` decimal(15,2) NOT NULL,
`item_unit_price` decimal(15,2) NOT NULL,
`item_location` int(11) NOT NULL,
`discount_percent` decimal(15,2) NOT NULL DEFAULT '0',
PRIMARY KEY (`sale_id`,`item_id`,`line`),
KEY `sale_id` (`sale_id`),
KEY `item_id` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -683,7 +689,8 @@ ALTER TABLE `ospos_sales`
--
ALTER TABLE `ospos_sales_items`
ADD CONSTRAINT `ospos_sales_items_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `ospos_items` (`item_id`),
ADD CONSTRAINT `ospos_sales_items_ibfk_2` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales` (`sale_id`);
ADD CONSTRAINT `ospos_sales_items_ibfk_2` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales` (`sale_id`),
ADD CONSTRAINT `ospos_sales_items_ibfk_3` FOREIGN KEY (`item_location`) REFERENCES `ospos_stock_locations` (`location_id`);
--
-- Constraints for table `ospos_sales_items_taxes`
@@ -710,7 +717,8 @@ ALTER TABLE `ospos_sales_suspended`
--
ALTER TABLE `ospos_sales_suspended_items`
ADD CONSTRAINT `ospos_sales_suspended_items_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `ospos_items` (`item_id`),
ADD CONSTRAINT `ospos_sales_suspended_items_ibfk_2` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_suspended` (`sale_id`);
ADD CONSTRAINT `ospos_sales_suspended_items_ibfk_2` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_suspended` (`sale_id`),
ADD CONSTRAINT `ospos_sales_suspended_items_ibfk_3` FOREIGN KEY (`item_location`) REFERENCES `ospos_stock_locations` (`location_id`);
--
-- Constraints for table `ospos_sales_suspended_items_taxes`