mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-06-03 05:06:30 -04:00
Fixed sale suspending / unsuspending (adapt db scripts)
Cleanup old code More code review Update item_quantities database model (composite pk) git-svn-id: svn+ssh://svn.code.sf.net/p/opensourcepos/code/@120 c3eb156b-1dc0-44e1-88ae-e38439141b53
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user