Improves the behavior of dinner table selection.

This commit is contained in:
SteveIreland
2019-07-20 15:20:16 -04:00
parent fa71bc6ed6
commit f95d777dc2
4 changed files with 105 additions and 44 deletions

View File

@@ -176,11 +176,23 @@ class Sales extends Secure_Controller
$this->sale_lib->set_sale_type(SALE_TYPE_RETURN);
}
if($this->config->item('dinner_table_enable') == TRUE)
{
$occupied_dinner_table = $this->input->post('dinner_table');
$released_dinner_table = $this->sale_lib->get_dinner_table();
$occupied = $this->Dinner_table->is_occupied($released_dinner_table);
if($occupied && ($occupied_dinner_table != $released_dinner_table))
{
$this->Dinner_table->swap_tables($released_dinner_table, $occupied_dinner_table);
}
$this->sale_lib->set_dinner_table($occupied_dinner_table);
}
$stock_location = $this->input->post('stock_location');
if(!$stock_location || $stock_location == $this->sale_lib->get_sale_location())
{
$dinner_table = $this->input->post('dinner_table');
$this->sale_lib->set_dinner_table($dinner_table);
}
elseif($this->Stock_location->is_allowed_location($stock_location, 'sales'))
@@ -508,6 +520,7 @@ class Sales extends Secure_Controller
$sale_type = $this->sale_lib->get_sale_type();
$data = array();
$data['dinner_table'] = $this->sale_lib->get_dinner_table();
$data['cart'] = $this->sale_lib->get_cart();
$data['include_hsn'] = ($this->config->item('include_hsn') == '1');
@@ -1051,8 +1064,8 @@ class Sales extends Secure_Controller
$data['modes'] = $this->sale_lib->get_register_mode_options();
$data['mode'] = $this->sale_lib->get_mode();
$data['empty_tables'] = $this->sale_lib->get_empty_tables();
$data['selected_table'] = $this->sale_lib->get_dinner_table();
$data['empty_tables'] = $this->sale_lib->get_empty_tables($data['selected_table']);
$data['stock_locations'] = $this->Stock_location->get_allowed_locations('sales');
$data['stock_location'] = $this->sale_lib->get_sale_location();
$data['tax_exclusive_subtotal'] = $this->sale_lib->get_subtotal(TRUE, TRUE);
@@ -1332,6 +1345,13 @@ class Sales extends Secure_Controller
if($sale_id != -1 && $sale_id != '')
{
$sale_type = $this->sale_lib->get_sale_type();
if($this->config->item('dinner_table_enable') == TRUE)
{
$dinner_table = $this->sale_lib->get_dinner_table();
$this->Dinner_table->release($dinner_table);
}
if($sale_type == SALE_TYPE_WORK_ORDER)
{
$this->Sale->update_sale_status($sale_id, CANCELED);
@@ -1366,18 +1386,15 @@ class Sales extends Secure_Controller
*/
public function suspend()
{
$mode = $this->sale_lib->get_mode();
$sale_id = $this->sale_lib->get_sale_id();
$dinner_table = $this->sale_lib->get_dinner_table();
$cart = $this->sale_lib->get_cart();
$payments = $this->sale_lib->get_payments();
$employee_id = $this->Employee->get_logged_in_employee_info()->person_id;
$customer_id = $this->sale_lib->get_customer();
$customer_info = $this->Customer->get_info($customer_id);
$invoice_number = $this->sale_lib->get_invoice_number();
$work_order_number = $this->sale_lib->get_work_order_number();
$quote_number = $this->sale_lib->get_quote_number();
$sale_id = $this->sale_lib->get_sale_id();
$sale_type = $this->sale_lib->get_sale_type();
if($sale_type == '')
{

View File

@@ -1284,9 +1284,9 @@ class Sale_lib
return $total;
}
public function get_empty_tables()
public function get_empty_tables($current_dinner_table_id)
{
return $this->CI->Dinner_table->get_empty_tables();
return $this->CI->Dinner_table->get_empty_tables($current_dinner_table_id);
}
public function check_for_cash_rounding($total)

View File

@@ -31,10 +31,11 @@ class Dinner_table extends CI_Model
/**
Get empty tables
*/
public function get_empty_tables()
public function get_empty_tables($current_dinner_table_id)
{
$this->db->from('dinner_tables');
$this->db->where('status', 0);
$this->db->or_where('dinner_table_id', $current_dinner_table_id);
$this->db->where('deleted', 0);
$empty_tables = $this->db->get()->result_array();
@@ -63,6 +64,21 @@ class Dinner_table extends CI_Model
}
}
public function is_occupied($dinner_table_id)
{
if(empty($dinner_table_id))
{
return FALSE;
}
else
{
$this->db->from('dinner_tables');
$this->db->where('dinner_table_id', $dinner_table_id);
return ($this->db->get()->row()->status == 1);
}
}
public function get_all()
{
$this->db->from('dinner_tables');
@@ -80,5 +96,47 @@ class Dinner_table extends CI_Model
return $this->db->update('dinner_tables', array('deleted' => 1));
}
/**
* Occupy table
* Ignore the Delivery and Takeaway "tables". They should never be occupied.
*/
public function occupy($dinner_table_id)
{
if($dinner_table_id > 2 )
{
$this->db->where('dinner_table_id', $dinner_table_id);
return $this->db->update('dinner_tables', array('status' => 1));
}
else
{
return true;
}
}
/**
Release table
*/
public function release($dinner_table_id)
{
if($dinner_table_id > 2 )
{
$this->db->where('dinner_table_id', $dinner_table_id);
return $this->db->update('dinner_tables', array('status' => 0));
}
else
{
return true;
}
}
/**
Swap tables
*/
public function swap_tables($release_dinner_table_id, $occupy_dinner_table_id)
{
return $this->release($release_dinner_table_id) && $this->occupy($occupy_dinner_table_id);
}
}
?>

View File

@@ -609,8 +609,6 @@ class Sale extends CI_Model
return -1;
}
$table_status = $this->determine_sale_status($sale_status, $dinner_table);
$sales_data = array(
'sale_time' => date('Y-m-d H:i:s'),
'customer_id' => $this->Customer->exists($customer_id) ? $customer_id : NULL,
@@ -738,12 +736,17 @@ class Sale extends CI_Model
$this->save_sales_items_taxes($sale_id, $sales_taxes[1]);
}
$dinner_table_data = array(
'status' => $table_status
);
$this->db->where('dinner_table_id',$dinner_table);
$this->db->update('dinner_tables', $dinner_table_data);
if($this->config->item('dinner_table_enable') == TRUE)
{
if($sale_status == COMPLETED)
{
$this->Dinner_table->release($dinner_table);
}
else
{
$this->Dinner_table->occupy($dinner_table);
}
}
$this->db->trans_complete();
@@ -1358,13 +1361,11 @@ class Sale extends CI_Model
//Run these queries as a transaction, we want to make sure we do all or nothing
$this->db->trans_start();
$dinner_table = $this->get_dinner_table($sale_id);
$dinner_table_data = array(
'status' => 0
);
$this->db->where('dinner_table_id', $dinner_table);
$this->db->update('dinner_tables', $dinner_table_data);
if($this->config->item('dinner_table_enable') == TRUE)
{
$dinner_table = $this->get_dinner_table($sale_id);
$this->Dinner_table->release($dinner_table);
}
$this->update_sale_status($sale_id, CANCELED);
@@ -1381,13 +1382,12 @@ class Sale extends CI_Model
{
$this->db->trans_start();
$dinner_table = $this->get_dinner_table($sale_id);
$dinner_table_data = array(
'status' => 0
);
$this->db->where('dinner_table_id', $dinner_table);
$this->db->update('dinner_tables', $dinner_table_data);
if($this->config->item('dinner_table_enable') == TRUE)
{
$dinner_table = $this->get_dinner_table($sale_id);
$this->Dinner_table->release($dinner_table);
}
$this->db->delete('sales_payments', array('sale_id' => $sale_id));
$this->db->delete('sales_items_taxes', array('sale_id' => $sale_id));
@@ -1438,19 +1438,5 @@ class Sale extends CI_Model
}
}
/**
* @param $sale_status
* @param $dinner_table
* @return int
*/
private function determine_sale_status(&$sale_status, $dinner_table)
{
if($sale_status == SUSPENDED && $dinner_table > 2) //not delivery or take away
{
return SUSPENDED;
}
return COMPLETED;
}
}
?>