From 86d3c6bf0492cf47bd8008515a2622c22f81a2f5 Mon Sep 17 00:00:00 2001 From: jekkos Date: Fri, 4 Aug 2017 04:29:31 +0200 Subject: [PATCH 1/5] Cleanup Sales controller --- application/config/autoload.php | 2 +- application/controllers/Sales.php | 172 +------------ application/libraries/Sale_lib.php | 66 +---- application/libraries/Token_lib.php | 28 ++- application/libraries/tokens/Token.php | 25 +- .../libraries/tokens/Token_customer.php | 15 +- .../libraries/tokens/Token_invoice_count.php | 6 +- .../tokens/Token_invoice_sequence.php | 6 + application/models/Sale.php | 138 +++++++---- application/models/Sale_suspended.php | 226 ------------------ application/views/sales/form.php | 2 +- application/views/sales/invoice.php | 2 +- application/views/sales/quote.php | 2 +- application/views/sales/register.php | 2 +- database/3.0.2_to_3.1.0.sql | 22 +- database/constraints.sql | 29 --- database/database.sql | 162 ++----------- database/migrate_phppos_dist.sql | 162 ++----------- database/tables.sql | 133 ++--------- 19 files changed, 243 insertions(+), 957 deletions(-) delete mode 100644 application/models/Sale_suspended.php diff --git a/application/config/autoload.php b/application/config/autoload.php index 7b0454a6b..3a86b403b 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -132,4 +132,4 @@ $autoload['language'] = array(); | | $autoload['model'] = array('first_model' => 'first'); */ -$autoload['model'] = array('Appconfig', 'Person', 'Customer', 'Employee', 'Module', 'Item', 'Item_taxes', 'Sale', 'Sale_suspended', 'Supplier', 'Inventory', 'Receiving', 'Giftcard', 'Item_kit', 'Item_kit_items', 'Stock_location', 'Item_quantity', 'Dinner_table', 'Customer_rewards', 'Rewards', 'Tax'); +$autoload['model'] = array('Appconfig', 'Person', 'Customer', 'Employee', 'Module', 'Item', 'Item_taxes', 'Sale', 'Supplier', 'Inventory', 'Receiving', 'Giftcard', 'Item_kit', 'Item_kit_items', 'Stock_location', 'Item_quantity', 'Dinner_table', 'Customer_rewards', 'Rewards', 'Tax'); diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index f6553678d..d8cc07d35 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -438,11 +438,6 @@ class Sales extends Secure_Controller $this->_reload(); } - public function complete_receipt() - { - $this->complete(); - } - public function complete() { $data = array(); @@ -619,7 +614,7 @@ class Sales extends Secure_Controller } } - public function send_invoice($sale_id) + public function send_pdf($sale_id, $type = 'invoice') { $sale_data = $this->_load_sale_data($sale_id); @@ -629,61 +624,26 @@ class Sales extends Secure_Controller if(!empty($sale_data['customer_email'])) { $to = $sale_data['customer_email']; - $subject = $this->lang->line('sales_invoice') . ' ' . $sale_data['invoice_number']; + $number = $sale_data[$type."_number"]; + $subject = $this->lang->line("sales_$type") . ' ' . $number; $text = $this->config->item('invoice_email_message'); - $text = str_replace('$INV', $sale_data['invoice_number'], $text); - $text = str_replace('$CO', 'POS ' . $sale_data['sale_id'], $text); - $text = $this->_substitute_customer($text, (object)$sale_data); + $tokens = array(new Token_invoice_sequence($sale_data['invoice_number']), + new Token_invoice_count('POS ' . $sale_data['sale_id']), + new Token_customer((object)$sale_data)); + $text = $this->token_lib->render($text, $tokens); // generate email attachment: invoice in pdf format - $html = $this->load->view('sales/invoice_email', $sale_data, TRUE); + $html = $this->load->view("sales/" . $type . "_email", $sale_data, TRUE); // load pdf helper $this->load->helper(array('dompdf', 'file')); - $filename = sys_get_temp_dir() . '/' . $this->lang->line('sales_invoice') . '-' . str_replace('/', '-', $sale_data['invoice_number']) . '.pdf'; + $filename = sys_get_temp_dir() . '/' . $this->lang->line("sales_N") . '-' . str_replace('/', '-', $number) . '.pdf'; if(file_put_contents($filename, pdf_create($html)) !== FALSE) { $result = $this->email_lib->sendEmail($to, $subject, $text, $filename); } - $message = $this->lang->line($result ? 'sales_invoice_sent' : 'sales_invoice_unsent') . ' ' . $to; - } - - echo json_encode(array('success' => $result, 'message' => $message, 'id' => $sale_id)); - - $this->sale_lib->clear_all(); - - return $result; - } - - public function send_quote($sale_id) - { - $sale_data = $this->_load_sale_data($sale_id); - - $result = FALSE; - $message = $this->lang->line('sales_invoice_no_email'); - - if(!empty($sale_data['customer_email'])) - { - $to = $sale_data['customer_email']; - $subject = $this->lang->line('sales_quote') . ' ' . $sale_data['quote_number']; - - $text = $this->config->item('invoice_email_message'); - $text = str_replace('$INV', $sale_data['invoice_number'], $text); - $text = str_replace('$CO', 'POS ' . $sale_data['sale_id'], $text); - $text = $this->_substitute_customer($text, (object)$sale_data); - - // generate email attachment: invoice in pdf format - $html = $this->load->view('sales/quote_email', $sale_data, TRUE); - // load pdf helper - $this->load->helper(array('dompdf', 'file')); - $filename = sys_get_temp_dir() . '/' . $this->lang->line('sales_quote') . '-' . str_replace('/', '-', $sale_data['quote_number']) . '.pdf'; - if(file_put_contents($filename, pdf_create($html)) !== FALSE) - { - $result = $this->email_lib->sendEmail($to, $subject, $text, $filename); - } - - $message = $this->lang->line($result ? 'sales_quote_sent' : 'sales_quote_unsent') . ' ' . $to; + $message = $this->lang->line($result ? "sales_" . $type . "_sent" : "sales_" . $type . "_unsent") . ' ' . $to; } echo json_encode(array('success' => $result, 'message' => $message, 'id' => $sale_id)); @@ -721,83 +681,6 @@ class Sales extends Secure_Controller return $result; } - private function _substitute_variable($text, $variable, $object, $function) - { - // don't query if this variable isn't used - if(strstr($text, $variable)) - { - $value = call_user_func(array($object, $function)); - $text = str_replace($variable, $value, $text); - } - - return $text; - } - - private function _substitute_customer($text, $customer_info) - { - // substitute customer info - $customer_id = $this->sale_lib->get_customer(); - if($customer_id != -1 && $customer_info != '') - { - $text = str_replace('$CU', $customer_info->first_name . ' ' . $customer_info->last_name, $text); - $words = preg_split("/\s+/", trim($customer_info->first_name . ' ' . $customer_info->last_name)); - $acronym = ''; - - foreach($words as $w) - { - $acronym .= $w[0]; - } - $text = str_replace('$CI', $acronym, $text); - } - - return $text; - } - - private function _is_custom_invoice_number($customer_info) - { - $invoice_number = $this->config->config['sales_invoice_format']; - $invoice_number = $this->_substitute_variables($invoice_number, $customer_info); - - return $this->sale_lib->get_invoice_number() != $invoice_number; - } - - private function _is_custom_quote_number($customer_info) - { - $quote_number = $this->config->config['sales_quote_format']; - $quote_number = $this->_substitute_variables($quote_number, $customer_info); - - return $this->sale_lib->get_quote_number() != $quote_number; - } - - private function _substitute_variables($text, $customer_info) - { - $text = $this->_substitute_variable($text, '$YCO', $this->Sale, 'get_invoice_number_for_year'); - $text = $this->_substitute_variable($text, '$CO', $this->Sale, 'get_invoice_count'); - $text = $this->_substitute_variable($text, '$SCO', $this->Sale, 'get_suspended_invoice_count'); - $text = strftime($text); - $text = $this->_substitute_customer($text, $customer_info); - - return $text; - } - - private function _substitute_invoice_number($customer_info) - { - $invoice_number = $this->config->config['sales_invoice_format']; - $invoice_number = $this->_substitute_variables($invoice_number, $customer_info); - $this->sale_lib->set_invoice_number($invoice_number, TRUE); - - return $this->sale_lib->get_invoice_number(); - } - - private function _substitute_quote_number($customer_info) - { - $quote_number = $this->config->config['sales_quote_format']; - $quote_number = $this->_substitute_variables($quote_number, $customer_info); - $this->sale_lib->set_quote_number($quote_number, TRUE); - - return $this->sale_lib->get_quote_number(); - } - private function _load_customer_data($customer_id, &$data, $stats = FALSE) { $customer_info = ''; @@ -1171,10 +1054,10 @@ class Sales extends Secure_Controller $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->_is_custom_invoice_number($customer_info) ? $this->sale_lib->get_invoice_number() : NULL; + $invoice_number = $this->sale_lib->get_invoice_number(); $quote_number = $this->sale_lib->get_quote_number(); $comment = $this->sale_lib->get_comment(); - $sale_status = '1'; + $sale_status = $this->sale_lib->is_quote_mode() ? '2' : '1'; $data = array(); $sales_taxes = array(); @@ -1191,30 +1074,6 @@ class Sales extends Secure_Controller $this->_reload($data); } - public function suspend_quote($quote_number) - { - $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); - $dinner_table = $this->sale_lib->get_dinner_table(); - $invoice_number = $this->_is_custom_invoice_number($customer_info) ? $this->sale_lib->get_invoice_number() : NULL; - $comment = $this->sale_lib->get_comment(); - $sale_status = '2'; // Suspend - - $data = array(); - $sales_taxes = array(); - if($this->Sale->save($sale_status, $cart, $customer_id, $employee_id, $comment, $invoice_number, $quote_number, $payments, $dinner_table, $sales_taxes) == '-1') - { - $data['error'] = $this->lang->line('sales_unsuccessfully_suspended_sale'); - } - else - { - $data['success'] = $this->lang->line('sales_successfully_suspended_sale'); - } - } - public function suspended() { $customer_id = $this->sale_lib->get_customer(); @@ -1238,13 +1097,6 @@ class Sales extends Secure_Controller $this->sale_lib->copy_entire_sale($sale_id); $this->Sale->delete_suspended_sale($sale_id); } - else - { - // This will unsuspended older suspended sales - $sale_id = $sale_id * -1; - $this->sale_lib->copy_entire_suspended_tables_sale($sale_id); - $this->Sale_suspended->delete($sale_id); - } $this->_reload(); } diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 52b05eda2..d30ef94a5 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -319,11 +319,6 @@ class Sale_lib return $subtotal; } - public function get_cash_rounding() - { - - } - /** * Returns 'subtotal', 'total', 'cash_total', 'payment_total', 'amount_due', 'cash_amount_due', 'paid_in_full' * 'subtotal', 'discounted_subtotal', 'tax_exclusive_subtotal' @@ -483,7 +478,8 @@ class Sale_lib { $this->set_mode($this->CI->config->item('default_register_mode')); } - else{ + else + { $this->set_mode('sale'); } } @@ -650,14 +646,7 @@ class Sale_lib // 0 will print, 2 will not print. The decision about 1 is made here if($print_option =='1') { - if($price == 0) - { - $print_option = '2'; - } - else - { - $print_option = '0'; - } + $print_option = ($price == 0) ? '2' : '0'; } $total = $this->get_item_total($quantity, $price, $discount); @@ -889,55 +878,6 @@ class Sale_lib return $this->CI->session->userdata('sales_cart'); } - public function copy_entire_suspended_sale($sale_id) - { - $this->empty_cart(); - $this->remove_customer(); - - foreach($this->CI->Sale->get_sale_items($sale_id)->result() as $row) - { - $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, $row->item_unit_price, - $row->description, $row->serialnumber, TRUE, $row->print_option, $row->stock_type); - } - - foreach($this->CI->Sale->get_sale_payments($sale_id)->result() as $row) - { - $this->add_payment($row->payment_type, $row->payment_amount); - } - - $suspended_sale_info = $this->CI->Sale->get_info($sale_id)->row(); - $this->set_customer($suspended_sale_info->person_id); - $this->set_comment($suspended_sale_info->comment); - $this->set_invoice_number($suspended_sale_info->invoice_number); - $this->set_quote_number($suspended_sale_info->quote_number); - $this->set_dinner_table($suspended_sale_info->dinner_table_id); - } - - public function copy_entire_suspended_tables_sale($sale_id) - { - $this->empty_cart(); - $this->remove_customer(); - - foreach($this->CI->Sale_suspended->get_sale_items($sale_id)->result() as $row) - { - $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, $row->item_unit_price, - $row->description, $row->serialnumber, TRUE, $row->print_option, $row->stock_type); - } - - foreach($this->CI->Sale_suspended->get_sale_payments($sale_id)->result() as $row) - { - $this->add_payment($row->payment_type, $row->payment_amount); - } - - $suspended_sale_info = $this->CI->Sale_suspended->get_info($sale_id)->row(); - $this->set_customer($suspended_sale_info->person_id); - $this->set_comment($suspended_sale_info->comment); - - $this->set_invoice_number($suspended_sale_info->invoice_number); - $this->set_quote_number($suspended_sale_info->quote_number); - $this->set_dinner_table($suspended_sale_info->dinner_table_id); - } - public function clear_all() { $this->set_invoice_number_enabled(FALSE); diff --git a/application/libraries/Token_lib.php b/application/libraries/Token_lib.php index 956360580..8029225c6 100644 --- a/application/libraries/Token_lib.php +++ b/application/libraries/Token_lib.php @@ -20,18 +20,9 @@ class Token_lib /** * Expands all of the tokens found in a given text string and returns the results. */ - public function render($tokened_text) + public function render($tokened_text, $tokens = array()) { - // Transform legacy "$" tokens to their brace token equivalent - if(strpos($tokened_text, '$') !== FALSE) - { - $tokened_text = str_replace('$YCO', '{YCO}', $tokened_text); - $tokened_text = str_replace('$CO', '{CO}', $tokened_text); - $tokened_text = str_replace('$SCO', '{SCO}', $tokened_text); - $tokened_text = str_replace('$CU', '{CU}', $tokened_text); - } - // Apply the transformation for the "%" tokens if any are used if(strpos($tokened_text, '%') !== FALSE) { @@ -55,7 +46,7 @@ class Token_lib $token_values = array(); $tokens_to_replace = array(); - $this->generate($token_tree, $tokens_to_replace, $token_values); + $this->generate($token_tree, $tokens_to_replace, $token_values, $tokens); return str_replace($tokens_to_replace, $token_values, $tokened_text); } @@ -87,12 +78,12 @@ class Token_lib return $token_tree; } - public function generate($used_tokens, &$tokens_to_replace, &$token_values) + public function generate($used_tokens, &$tokens_to_replace, &$token_values, $tokens) { foreach($used_tokens as $token_code => $token_info) { // Generate value here based on the key value - $token_value = (new Token())->replace($token_code); + $token_value = $this->resolveToken($token_code); foreach($token_info as $length => $token_spec) { @@ -109,6 +100,17 @@ class Token_lib } return $token_values; } + + private function resolveToken($token_code, $tokens = array()) + { + foreach (array_merge($tokens, Token::get_tokens()) as $token) { + if ($token->token_id() == $token_code) + { + return $token->get_value(); + } + } + return ''; + } } ?> diff --git a/application/libraries/tokens/Token.php b/application/libraries/tokens/Token.php index 067b05ff0..06697e712 100644 --- a/application/libraries/tokens/Token.php +++ b/application/libraries/tokens/Token.php @@ -12,13 +12,16 @@ require_once(APPPATH . 'libraries/tokens/Token_year_invoice_count.php'); * Token class */ -class Token +abstract class Token { protected $CI; - public function __construct() + protected $value = ''; + + public function __construct($value = '') { $this->CI =& get_instance(); + $this->value = $value; } static function get_tokens() @@ -27,23 +30,23 @@ class Token new Token_quote_sequence(), new Token_suspended_invoice_count(), new Token_quote_sequence(), new Token_year_invoice_count()); } + abstract public function token_id(); + + abstract public function get_value(); + function matches($token_id) { - return false; + return token_id() == $token_id; } - public function replace($token_id) + function replace($text) { - foreach(Token::get_tokens() as $token) + if (strstr($text, $this->token_id())) { - if ($token->token_id() == $token_id) - { - return $token->get_value(); - } + return str_replace($this->token_id(), $this->get_value(), $text); } - return ''; + return $text; } - } ?> diff --git a/application/libraries/tokens/Token_customer.php b/application/libraries/tokens/Token_customer.php index 61b0e0750..c36fe1b0f 100644 --- a/application/libraries/tokens/Token_customer.php +++ b/application/libraries/tokens/Token_customer.php @@ -6,10 +6,13 @@ class Token_customer extends Token { - public function __construct() + + private $customer_info; + + public function __construct($customer_info = '') { parent::__construct(); - + $this->customer_info = $customer_info; $this->CI->load->library('sale_lib'); } @@ -22,7 +25,7 @@ class Token_customer extends Token { // substitute customer info $customer_id = $this->CI->sale_lib->get_customer(); - if($customer_id != -1) + if ($customer_id != -1 && empty($this->customer_info)) { $customer_info = $this->CI->Customer->get_info($customer_id); if($customer_info != '') @@ -30,8 +33,12 @@ class Token_customer extends Token return trim($customer_info->first_name . ' ' . $customer_info->last_name); } } + elseif (!empty($this->customer_info)) + { - return ''; + } + + return $value; } } ?> diff --git a/application/libraries/tokens/Token_invoice_count.php b/application/libraries/tokens/Token_invoice_count.php index 5cfc1ead1..0d96b4ddf 100644 --- a/application/libraries/tokens/Token_invoice_count.php +++ b/application/libraries/tokens/Token_invoice_count.php @@ -6,9 +6,9 @@ class Token_invoice_count extends Token { - public function __construct() + public function __construct($value = '') { - parent::__construct(); + parent::__construct($value); $this->CI->load->model('Sale'); } @@ -20,7 +20,7 @@ class Token_invoice_count extends Token public function get_value() { - return $this->CI->Sale->get_invoice_count(); + return empty($value) ? $this->CI->Sale->get_invoice_count() : $value; } } ?> diff --git a/application/libraries/tokens/Token_invoice_sequence.php b/application/libraries/tokens/Token_invoice_sequence.php index cabee22d7..3beadb14a 100644 --- a/application/libraries/tokens/Token_invoice_sequence.php +++ b/application/libraries/tokens/Token_invoice_sequence.php @@ -6,6 +6,12 @@ class Token_invoice_sequence extends Token { + + public function __construct($value = '') + { + parent::__construct($value); + } + public function token_id() { return 'ISEQ'; diff --git a/application/models/Sale.php b/application/models/Sale.php index e5da680a7..bb5bb9a97 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -532,27 +532,14 @@ class Sale extends CI_Model return -1; } - if($sale_status == '1') //suspend sales - { - if($dinner_table > 2) //not delivery or take away - { - $table_status = 1; - } - else - { - $table_status = 0; - } - } - else - { - $table_status = 0; - } + $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, 'employee_id' => $employee_id, 'comment' => $comment, + 'sale_status' => $sale_status, 'invoice_number' => $invoice_number, 'quote_number' => $quote_number, 'dinner_table_id'=> $dinner_table, @@ -593,23 +580,7 @@ class Sale extends CI_Model $total_amount = floatval($total_amount) + floatval($payment['payment_amount']); } - if(!empty($customer_id) && $this->config->item('customer_reward_enable') == TRUE) - { - $package_id = $this->Customer->get_info($customer_id)->package_id; - - if(!empty($package_id)) - { - $points_percent = $this->Customer_rewards->get_points_percent($package_id); - $points = $this->Customer->get_info($customer_id)->points; - $points = ($points==NULL ? 0 : $points); - $points_percent = ($points_percent==NULL ? 0 : $points_percent); - $total_amount_earned = ($total_amount*$points_percent/100); - $points = $points + $total_amount_earned; - $this->Customer->update_reward_points_value($customer_id, $points); - $rewards_data = array('sale_id'=>$sale_id, 'earned'=>$total_amount_earned, 'used'=>$total_amount_used); - $this->Rewards->save($rewards_data); - } - } + $this->save_customer_rewards($customer_id, $sale_id, $total_amount, $total_amount_used); $customer = $this->Customer->get_info($customer_id); @@ -1199,16 +1170,12 @@ class Sale extends CI_Model if($customer_id == -1) { $query = $this->db->query('select sale_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from ' - . $this->db->dbprefix('sales') . ' where sale_status = 1 ' - . ' union select sale_id, sale_id*-1 as suspended_sale_id, 2 as sale_status, sale_time, dinner_table_id, customer_id, comment from ' - . $this->db->dbprefix('sales_suspended')); + . $this->db->dbprefix('sales') . ' where sale_status = 1'); } else { - $query = $this->db->query('select sale_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from ' - . $this->db->dbprefix('sales') . ' where sale_status = 1 AND customer_id = ' . $customer_id - . ' union select sale_id, sale_id*-1 as suspended_sale_id, 2 as sale_status, sale_time, dinner_table_id, customer_id, comment from ' - . $this->db->dbprefix('sales_suspended') . ' where customer_id = ' . $customer_id); + $query = $this->db->query('select sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from ' + . $this->db->dbprefix('sales') . ' where sale_status = 1 AND customer_id = ' . $customer_id); } return $query->result_array(); @@ -1299,7 +1266,7 @@ class Sale extends CI_Model $this->db->delete('sales_items_taxes', array('sale_id' => $sale_id)); $this->db->delete('sales_items', array('sale_id' => $sale_id)); $this->db->delete('sales_taxes', array('sale_id' => $sale_id)); - $this->db->delete('sales', array('sale_id' => $sale_id)); + $this->db->delete('sales', array('sale_id' => $sale_id, 'sale_status' => 1)); $this->db->trans_complete(); @@ -1317,5 +1284,96 @@ class Sale extends CI_Model return $this->db->get(); } + + function get_day_total($sale_time) + { + $this->db->select("SUM(ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100),2)) as total", FALSE); + $this->db->from('sales'); + $this->db->join('sales_items', "sales_items.sale_id = sales.sale_id"); + $this->db->where("DATE_FORMAT(sale_time, '%Y-%m-%d') = '" . date('Y-m-d', strtotime($sale_time)) . "'"); + return $this->db->get()->result_array(); + } + + function get_totals($from, $to=NULL) + { + $this->db->select("SUM(payment_amount)"); + $this->db->select('sale_time'); + $this->db->from('sales'); + $this->db->join('sales_payments', "sales_payments.sale_id = sales.sale_id"); + if (isset($to)) + { + $this->db->where("sale_time BETWEEN DATE(" . $this->db->escape($from) . ") AND DATE(" . $this->db->escape($to) . ")"); + $this->db->group_by("DAY(sale_time)"); + } + else + { + $this->db->where("DATE(sale_time) = DATE(" . $this->db->escape($from) . ")"); + } + return $this->db->get(); + } + + function get_payments_by_day($sale_time) + { + $this->db->from('sales'); + $this->db->join('sales_payments', "sales_payments.sale_id = sales.sale_id"); + $this->db->where("DATE_FORMAT(sale_time,'%Y-%m-%d') = " . $this->db->escape(date('Y-m-d', strtotime($sale_time)))); + $this->db->where('payment_type', 'Contant'); + $this->db->where('invoice_number IS NULL'); + $this->db->or_where('invoice_number', ''); + return $this->db->get()->result_array(); + } + + function update_sale_item($sale_id, $item_id, $sale_item) + { + $this->db->where('sale_id', $sale_id); + $this->db->where('item_id', $item_id); + $this->db->update('sales_items', $sale_item); + } + + function update_sale_payment($sale_payment_id, $sale_payment) + { + $this->db->where('sale_id', $sale_payment_id); + $this->db->where('payment_type', 'Contant'); + $this->db->update('sales_payments', $sale_payment); + } + + /** + * @param $customer_id + * @param $sale_id + * @param $total_amount + * @param $total_amount_used + */ + private function save_customer_rewards($customer_id, $sale_id, $total_amount, $total_amount_used) + { + if (!empty($customer_id) && $this->config->item('customer_reward_enable') == TRUE) { + $package_id = $this->Customer->get_info($customer_id)->package_id; + + if (!empty($package_id)) { + $points_percent = $this->Customer_rewards->get_points_percent($package_id); + $points = $this->Customer->get_info($customer_id)->points; + $points = ($points == NULL ? 0 : $points); + $points_percent = ($points_percent == NULL ? 0 : $points_percent); + $total_amount_earned = ($total_amount * $points_percent / 100); + $points = $points + $total_amount_earned; + $this->Customer->update_reward_points_value($customer_id, $points); + $rewards_data = array('sale_id' => $sale_id, 'earned' => $total_amount_earned, 'used' => $total_amount_used); + $this->Rewards->save($rewards_data); + } + } + } + + /** + * @param $sale_status + * @param $dinner_table + * @return int + */ + private function determine_sale_status(&$sale_status, $dinner_table) + { + if ($sale_status == '1' && $dinner_table > 2) //not delivery or take away + { + return 1; + } + return 0; + } } ?> diff --git a/application/models/Sale_suspended.php b/application/models/Sale_suspended.php deleted file mode 100644 index e2174ff0a..000000000 --- a/application/models/Sale_suspended.php +++ /dev/null @@ -1,226 +0,0 @@ -db->from('sales_suspended'); - $this->db->order_by('sale_id'); - - return $this->db->get(); - } - - public function get_info($sale_id) - { - $this->db->from('sales_suspended'); - $this->db->where('sale_id', $sale_id); - $this->db->join('people', 'people.person_id = sales_suspended.customer_id', 'LEFT'); - - return $this->db->get(); - } - - /* - Gets total of invocie rows - */ - public function get_invoice_count() - { - $this->db->from('sales_suspended'); - $this->db->where('invoice_number IS NOT NULL'); - - return $this->db->count_all_results(); - } - - public function get_sale_by_invoice_number($invoice_number) - { - $this->db->from('sales_suspended'); - $this->db->where('invoice_number', $invoice_number); - - return $this->db->get(); - } - - public function exists($sale_id) - { - $this->db->from('sales_suspended'); - $this->db->where('sale_id', $sale_id); - - return ($this->db->get()->num_rows() == 1); - } - - public function update($sale_data, $sale_id) - { - $this->db->where('sale_id', $sale_id); - - return $this->db->update('sales_suspended', $sale_data); - } - - public function save($items, $customer_id, $employee_id, $comment, $invoice_number, $quote_number, $payments, $dinner_table, $sale_id = FALSE) - { - if(count($items) == 0) - { - return -1; - } - - if($dinner_table > 2) //not delivery or take away - { - $table_status = 1; - } - else - { - $table_status = 0; - } - - $sales_data = array( - 'sale_time' => date('Y-m-d H:i:s'), - 'customer_id' => $this->Customer->exists($customer_id) ? $customer_id : null, - 'employee_id' => $employee_id, - 'comment' => $comment, - 'invoice_number' => $invoice_number, - 'quote_number' => $quote_number, - 'dinner_table_id' => $dinner_table - ); - - //Run these queries as a transaction, we want to make sure we do all or nothing - $this->db->trans_start(); - - $this->db->insert('sales_suspended', $sales_data); - $sale_id = $this->db->insert_id(); - - foreach($payments as $payment_id=>$payment) - { - $sales_payments_data = array( - 'sale_id' => $sale_id, - 'payment_type' => $payment['payment_type'], - 'payment_amount' => $payment['payment_amount'] - ); - - $this->db->insert('sales_suspended_payments', $sales_payments_data); - } - - foreach($items as $line=>$item) - { - $cur_item_info = $this->Item->get_info($item['item_id']); - - $sales_items_data = array( - 'sale_id' => $sale_id, - 'item_id' => $item['item_id'], - 'line' => $item['line'], - 'description' => character_limiter($item['description'], 30), - 'serialnumber' => character_limiter($item['serialnumber'], 30), - 'quantity_purchased' => $item['quantity'], - 'discount_percent' => $item['discount'], - 'item_cost_price' => $cur_item_info->cost_price, - 'item_unit_price' => $item['price'], - 'item_location' => $item['item_location'] - ); - - $this->db->insert('sales_suspended_items', $sales_items_data); - - $customer = $this->Customer->get_info($customer_id); - if($customer_id == -1 || $customer->taxable) - { - foreach($this->Item_taxes->get_info($item['item_id']) as $row) - { - $sales_items_taxes = array( - 'sale_id' => $sale_id, - 'item_id' => $item['item_id'], - 'line' => $item['line'], - 'name' => $row['name'], - 'percent' => $row['percent'] - ); - - $this->db->insert('sales_suspended_items_taxes', $sales_items_taxes); - } - } - } - - $dinner_table_data = array( - 'status' => $table_status - ); - - $this->db->where('dinner_table_id',$dinner_table); - $this->db->update('dinner_tables', $dinner_table_data); - - $this->db->trans_complete(); - - if($this->db->trans_status() === FALSE) - { - return -1; - } - - return $sale_id; - } - - public function delete($sale_id) - { - //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); - - $this->db->delete('sales_suspended_payments', array('sale_id' => $sale_id)); - $this->db->delete('sales_suspended_items_taxes', array('sale_id' => $sale_id)); - $this->db->delete('sales_suspended_items', array('sale_id' => $sale_id)); - $this->db->delete('sales_suspended', array('sale_id' => $sale_id)); - - $this->db->trans_complete(); - - return $this->db->trans_status(); - } - - public function get_sale_items($sale_id) - { - $this->db->select(' - sale_id, - sales_suspended_items.item_id, - sales_suspended_items.description, - serialnumber, - line, - quantity_purchased, - item_cost_price, - item_unit_price, - discount_percent, - item_location, - print_option, - stock_type'); - $this->db->from('sales_suspended_items'); - $this->db->join('items as items', 'sales_suspended_items.item_id = items.item_id'); - $this->db->where('sale_id', $sale_id); - - return $this->db->get(); - } - - public function get_sale_payments($sale_id) - { - $this->db->from('sales_suspended_payments'); - $this->db->where('sale_id', $sale_id); - - return $this->db->get(); - } - - public function get_comment($sale_id) - { - $this->db->from('sales_suspended'); - $this->db->where('sale_id', $sale_id); - - return $this->db->get()->row()->comment; - } - - public function get_dinner_table($sale_id) - { - $this->db->from('sales_suspended'); - $this->db->where('sale_id', $sale_id); - - return $this->db->get()->row()->dinner_table_id; - } -} -?> diff --git a/application/views/sales/form.php b/application/views/sales/form.php index f3f16de5e..d50e22327 100755 --- a/application/views/sales/form.php +++ b/application/views/sales/form.php @@ -99,7 +99,7 @@ $(document).ready(function() $("#send_invoice").click(function(event) { if (confirm("lang->line('sales_invoice_confirm') . ' ' . $sale_info['email'] ?>")) { - $.get('', + $.get('', function(response) { dialog_support.hide(); table_support.handle_submit('', response); diff --git a/application/views/sales/invoice.php b/application/views/sales/invoice.php index 5dd8d0ceb..c7443d6b8 100755 --- a/application/views/sales/invoice.php +++ b/application/views/sales/invoice.php @@ -14,7 +14,7 @@ $(document).ready(function() { var send_email = function() { - $.get('', + $.get('', function(response) { $.notify(response.message, { type: response.success ? 'success' : 'danger'} ); diff --git a/application/views/sales/quote.php b/application/views/sales/quote.php index 858ce207e..d89552725 100644 --- a/application/views/sales/quote.php +++ b/application/views/sales/quote.php @@ -14,7 +14,7 @@ if (isset($error_message)) { var send_email = function() { - $.get('', + $.get('', function(response) { $.notify(response.message, { type: response.success ? 'success' : 'danger'} ); diff --git a/application/views/sales/register.php b/application/views/sales/register.php index d02bbd158..c0614da4d 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -686,7 +686,7 @@ $(document).ready(function() $("#finish_sale_button").click(function() { - $('#buttons_form').attr('action', ''); + $('#buttons_form').attr('action', ''); $('#buttons_form').submit(); }); diff --git a/database/3.0.2_to_3.1.0.sql b/database/3.0.2_to_3.1.0.sql index 4e1d1f09e..27848a254 100644 --- a/database/3.0.2_to_3.1.0.sql +++ b/database/3.0.2_to_3.1.0.sql @@ -299,13 +299,29 @@ ALTER TABLE `ospos_customers` -- add reCAPTCHA configuration + INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('gcaptcha_enable', '0'), ('gcaptcha_secret_key', ''), ('gcaptcha_site_key', ''); +-- replace old tokens in ospos_app_config --- add Barcode formats +UPDATE `ospos_app_config` SET `value` = REPLACE(`value`, '$CO', '{CO}'); +UPDATE `ospos_app_config` SET `value` = REPLACE(`value`, '$CU', '{CU}'); +UPDATE `ospos_app_config` SET `value` = REPLACE(`value`, '$INV', '{ISEQ}'); +UPDATE `ospos_app_config` SET `value` = REPLACE(`value`, '$SCO', '{SCO}'); -INSERT INTO `ospos_app_config` (`key`, `value`) VALUES - ('barcode_formats', '[]'); +-- +-- Copy suspended sales to sales table +-- + +INSERT INTO `ospos_sales` (sale_time, customer_id, employee_id, comment, invoice_number, sale_status) + SELECT sale_time, customer_id, employee_id, comment, invoice_number, 1 FROM `ospos_sales_suspended`; +INSERT INTO `ospos_sales_items` (sale_id, item_id, description, serialnumber, line, quantity_purchased, item_cost_price, item_unit_price, + discount_percent, item_location) SELECT sale_id, item_id, description, serialnumber, line, quantity_purchased, item_cost_price, item_unit_price, + discount_percent, item_location FROM ospos_sales_suspended_items; +INSERT INTO `ospos_sales_payments` (sale_id, payment_type, payment_amount) SELECT sale_id, payment_type, payment_amount FROM `ospos_sales_suspended_payments`; +INSERT INTO `ospos_sales_items_taxes` (sale_id, item_id, line, name, percent) SELECT sale_id, item_id, line, name, percent FROM `ospos_sales_suspended_items_taxes`; + +DROP TABLE ospos_sales_suspended_payments, ospos_sales_suspended_item_taxes, ospos_sales_suspended_items, ospos_sales_suspended; \ No newline at end of file diff --git a/database/constraints.sql b/database/constraints.sql index f0765e849..a293fc690 100644 --- a/database/constraints.sql +++ b/database/constraints.sql @@ -99,35 +99,6 @@ ALTER TABLE `ospos_sales_items_taxes` ALTER TABLE `ospos_sales_payments` ADD CONSTRAINT `ospos_sales_payments_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales` (`sale_id`); --- --- Constraints for table `ospos_sales_suspended` --- -ALTER TABLE `ospos_sales_suspended` - ADD CONSTRAINT `ospos_sales_suspended_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `ospos_employees` (`person_id`), - ADD CONSTRAINT `ospos_sales_suspended_ibfk_2` FOREIGN KEY (`customer_id`) REFERENCES `ospos_customers` (`person_id`), - ADD CONSTRAINT `ospos_sales_suspended_ibfk_3` FOREIGN KEY (`dinner_table_id`) REFERENCES `ospos_dinner_tables` (`dinner_table_id`); - --- --- Constraints for table `ospos_sales_suspended_items` --- -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_3` FOREIGN KEY (`item_location`) REFERENCES `ospos_stock_locations` (`location_id`); - --- --- Constraints for table `ospos_sales_suspended_items_taxes` --- -ALTER TABLE `ospos_sales_suspended_items_taxes` - ADD CONSTRAINT `ospos_sales_suspended_items_taxes_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_suspended_items` (`sale_id`), - ADD CONSTRAINT `ospos_sales_suspended_items_taxes_ibfk_2` FOREIGN KEY (`item_id`) REFERENCES `ospos_items` (`item_id`); - --- --- Constraints for table `ospos_sales_suspended_payments` --- -ALTER TABLE `ospos_sales_suspended_payments` - ADD CONSTRAINT `ospos_sales_suspended_payments_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_suspended` (`sale_id`); - -- -- Constraints for table `ospos_item_quantities` -- diff --git a/database/database.sql b/database/database.sql index c6664aa7d..bc68a57c5 100644 --- a/database/database.sql +++ b/database/database.sql @@ -51,10 +51,10 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('last_used_invoice_number', '0'), ('last_used_quote_number', '0'), ('line_sequence', '0'), -('recv_invoice_format', '$CO'), -('sales_invoice_format', '$CO'), +('recv_invoice_format', '{CO}'), +('sales_invoice_format', '{CO}'), ('sales_quote_format', 'Q%y{QSEQ:6}'), -('invoice_email_message', 'Dear $CU, In attachment the receipt for sale $INV'), +('invoice_email_message', 'Dear {CU}, In attachment the receipt for sale $INV'), ('invoice_default_comments', 'This is a default comment'), ('print_silently', '1'), ('print_header', '0'), @@ -151,7 +151,7 @@ CREATE TABLE `ospos_employees` ( -- INSERT INTO `ospos_employees` (`username`, `password`, `person_id`, `deleted`, `hash_version`) VALUES -('admin', '$2y$10$vJBSMlD02EC7ENSrKfVQXuvq9tNRHMtcOA8MSK2NYS748HHWm.gcG', 1, 0, 2); + ('admin', '$2y$10$vJBSMlD02EC7ENSrKfVQXuvq9tNRHMtcOA8MSK2NYS748HHWm.gcG', 1, 0, 2); -- -------------------------------------------------------- @@ -660,99 +660,6 @@ CREATE TABLE `ospos_sales_taxes` ( -- --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended` --- - -CREATE TABLE `ospos_sales_suspended` ( - `sale_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `customer_id` int(10) DEFAULT NULL, - `employee_id` int(10) NOT NULL DEFAULT '0', - `comment` text NOT NULL, - `invoice_number` varchar(32) DEFAULT NULL, - `quote_number` varchar(32) DEFAULT NULL, - `sale_id` int(10) NOT NULL AUTO_INCREMENT, - `dinner_table_id` int(11) NULL, - PRIMARY KEY (`sale_id`), - KEY `customer_id` (`customer_id`), - KEY `employee_id` (`employee_id`), - KEY `dinner_table_id` (`dinner_table_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Dumping data for table `ospos_sales_suspended` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended_items` --- - -CREATE TABLE `ospos_sales_suspended_items` ( - `sale_id` int(10) NOT NULL DEFAULT '0', - `item_id` int(10) NOT NULL DEFAULT '0', - `description` varchar(30) DEFAULT NULL, - `serialnumber` varchar(30) DEFAULT NULL, - `line` int(3) NOT NULL DEFAULT '0', - `quantity_purchased` decimal(15,3) NOT NULL DEFAULT '0', - `item_cost_price` decimal(15,2) NOT NULL, - `item_unit_price` decimal(15,2) NOT NULL, - `discount_percent` decimal(15,2) NOT NULL DEFAULT '0', - `item_location` int(11) NOT NULL, - `print_option` TINYINT(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; - --- --- Dumping data for table `ospos_sales_suspended_items` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended_items_taxes` --- - -CREATE TABLE `ospos_sales_suspended_items_taxes` ( - `sale_id` int(10) NOT NULL, - `item_id` int(10) NOT NULL, - `line` int(3) NOT NULL DEFAULT '0', - `name` varchar(255) NOT NULL, - `percent` decimal(15,3) NOT NULL, - PRIMARY KEY (`sale_id`,`item_id`,`line`,`name`,`percent`), - KEY `item_id` (`item_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Dumping data for table `ospos_sales_suspended_items_taxes` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended_payments` --- - -CREATE TABLE `ospos_sales_suspended_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`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Dumping data for table `ospos_sales_suspended_payments` --- - - -- -------------------------------------------------------- -- @@ -789,7 +696,7 @@ CREATE TABLE `ospos_stock_locations` ( -- Dumping data for table `ospos_stock_locations` -- -INSERT INTO `ospos_stock_locations` ( `deleted`, `location_name` ) VALUES ('0', 'stock'); +INSERT INTO `ospos_stock_locations` (`location_name` ) VALUES ('stock'); -- -------------------------------------------------------- @@ -806,7 +713,7 @@ CREATE TABLE `ospos_suppliers` ( `deleted` int(1) NOT NULL DEFAULT '0', UNIQUE KEY `account_number` (`account_number`), KEY `person_id` (`person_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -- -------------------------------------------------------- @@ -820,16 +727,16 @@ CREATE TABLE IF NOT EXISTS `ospos_tax_categories` ( `tax_category` varchar(32) NOT NULL, `tax_group_sequence` tinyint(2) NOT NULL, PRIMARY KEY (`tax_category_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -- -- Dumping data for table `ospos_stock_locations` -- -INSERT INTO `ospos_tax_categories` ( `tax_category_id`,`tax_category`, `tax_group_sequence` ) VALUES - (1, 'Standard', 10), - (2, 'Service', 12), - (3, 'Alcohol', 11); +INSERT INTO `ospos_tax_categories` (`tax_category`, `tax_group_sequence` ) VALUES + ('Standard', 10), + ('Service', 12), + ('Alcohol', 11); -- -------------------------------------------------------- @@ -883,15 +790,13 @@ CREATE TABLE `ospos_dinner_tables` ( `status` tinyint(1) NOT NULL DEFAULT '0', `deleted` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`dinner_table_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -- -- Dumping data for table `ospos_dinner_tables` -- -INSERT INTO `ospos_dinner_tables` (`dinner_table_id`, `name`, `status`, `deleted`) VALUES -(1, 'Delivery', 0, 0), -(2, 'Take Away', 0, 0); +INSERT INTO `ospos_dinner_tables` (`name`) VALUES ('Delivery'), ('Take Away'); -- -------------------------------------------------------- @@ -908,12 +813,12 @@ CREATE TABLE IF NOT EXISTS `ospos_customers_packages` ( PRIMARY KEY (`package_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -INSERT INTO `ospos_customers_packages` (`package_id`, `package_name`, `points_percent`, `deleted`) VALUES -(1, 'Default', 0, 0), -(2, 'Bronze', 10, 0), -(3, 'Silver', 20, 0), -(4, 'Gold', 30, 0), -(5, 'Premium', 50, 0); +INSERT INTO `ospos_customers_packages` (`package_name`, `points_percent`) VALUES + ('Default', 0), + ('Bronze', 10), + ('Silver', 20), + ('Gold', 30), + ('Premium', 50); -- -------------------------------------------------------- @@ -1054,35 +959,6 @@ ALTER TABLE `ospos_sales_items_taxes` ALTER TABLE `ospos_sales_payments` ADD CONSTRAINT `ospos_sales_payments_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales` (`sale_id`); --- --- Constraints for table `ospos_sales_suspended` --- -ALTER TABLE `ospos_sales_suspended` - ADD CONSTRAINT `ospos_sales_suspended_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `ospos_employees` (`person_id`), - ADD CONSTRAINT `ospos_sales_suspended_ibfk_2` FOREIGN KEY (`customer_id`) REFERENCES `ospos_customers` (`person_id`), - ADD CONSTRAINT `ospos_sales_suspended_ibfk_3` FOREIGN KEY (`dinner_table_id`) REFERENCES `ospos_dinner_tables` (`dinner_table_id`); - --- --- Constraints for table `ospos_sales_suspended_items` --- -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_3` FOREIGN KEY (`item_location`) REFERENCES `ospos_stock_locations` (`location_id`); - --- --- Constraints for table `ospos_sales_suspended_items_taxes` --- -ALTER TABLE `ospos_sales_suspended_items_taxes` - ADD CONSTRAINT `ospos_sales_suspended_items_taxes_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_suspended_items` (`sale_id`), - ADD CONSTRAINT `ospos_sales_suspended_items_taxes_ibfk_2` FOREIGN KEY (`item_id`) REFERENCES `ospos_items` (`item_id`); - --- --- Constraints for table `ospos_sales_suspended_payments` --- -ALTER TABLE `ospos_sales_suspended_payments` - ADD CONSTRAINT `ospos_sales_suspended_payments_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_suspended` (`sale_id`); - -- -- Constraints for table `ospos_item_quantities` -- diff --git a/database/migrate_phppos_dist.sql b/database/migrate_phppos_dist.sql index da8b9b000..cd6f6797b 100644 --- a/database/migrate_phppos_dist.sql +++ b/database/migrate_phppos_dist.sql @@ -51,10 +51,10 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('last_used_invoice_number', '0'), ('last_used_quote_number', '0'), ('line_sequence', '0'), -('recv_invoice_format', '$CO'), -('sales_invoice_format', '$CO'), +('recv_invoice_format', '{CO}'), +('sales_invoice_format', '{CO}'), ('sales_quote_format', 'Q%y{QSEQ:6}'), -('invoice_email_message', 'Dear $CU, In attachment the receipt for sale $INV'), +('invoice_email_message', 'Dear {CU}, In attachment the receipt for sale $INV'), ('invoice_default_comments', 'This is a default comment'), ('print_silently', '1'), ('print_header', '0'), @@ -151,7 +151,7 @@ CREATE TABLE `ospos_employees` ( -- INSERT INTO `ospos_employees` (`username`, `password`, `person_id`, `deleted`, `hash_version`) VALUES -('admin', '$2y$10$vJBSMlD02EC7ENSrKfVQXuvq9tNRHMtcOA8MSK2NYS748HHWm.gcG', 1, 0, 2); + ('admin', '$2y$10$vJBSMlD02EC7ENSrKfVQXuvq9tNRHMtcOA8MSK2NYS748HHWm.gcG', 1, 0, 2); -- -------------------------------------------------------- @@ -660,99 +660,6 @@ CREATE TABLE `ospos_sales_taxes` ( -- --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended` --- - -CREATE TABLE `ospos_sales_suspended` ( - `sale_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `customer_id` int(10) DEFAULT NULL, - `employee_id` int(10) NOT NULL DEFAULT '0', - `comment` text NOT NULL, - `invoice_number` varchar(32) DEFAULT NULL, - `quote_number` varchar(32) DEFAULT NULL, - `sale_id` int(10) NOT NULL AUTO_INCREMENT, - `dinner_table_id` int(11) NULL, - PRIMARY KEY (`sale_id`), - KEY `customer_id` (`customer_id`), - KEY `employee_id` (`employee_id`), - KEY `dinner_table_id` (`dinner_table_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Dumping data for table `ospos_sales_suspended` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended_items` --- - -CREATE TABLE `ospos_sales_suspended_items` ( - `sale_id` int(10) NOT NULL DEFAULT '0', - `item_id` int(10) NOT NULL DEFAULT '0', - `description` varchar(30) DEFAULT NULL, - `serialnumber` varchar(30) DEFAULT NULL, - `line` int(3) NOT NULL DEFAULT '0', - `quantity_purchased` decimal(15,3) NOT NULL DEFAULT '0', - `item_cost_price` decimal(15,2) NOT NULL, - `item_unit_price` decimal(15,2) NOT NULL, - `discount_percent` decimal(15,2) NOT NULL DEFAULT '0', - `item_location` int(11) NOT NULL, - `print_option` TINYINT(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; - --- --- Dumping data for table `ospos_sales_suspended_items` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended_items_taxes` --- - -CREATE TABLE `ospos_sales_suspended_items_taxes` ( - `sale_id` int(10) NOT NULL, - `item_id` int(10) NOT NULL, - `line` int(3) NOT NULL DEFAULT '0', - `name` varchar(255) NOT NULL, - `percent` decimal(15,3) NOT NULL, - PRIMARY KEY (`sale_id`,`item_id`,`line`,`name`,`percent`), - KEY `item_id` (`item_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Dumping data for table `ospos_sales_suspended_items_taxes` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended_payments` --- - -CREATE TABLE `ospos_sales_suspended_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`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Dumping data for table `ospos_sales_suspended_payments` --- - - -- -------------------------------------------------------- -- @@ -789,7 +696,7 @@ CREATE TABLE `ospos_stock_locations` ( -- Dumping data for table `ospos_stock_locations` -- -INSERT INTO `ospos_stock_locations` ( `deleted`, `location_name` ) VALUES ('0', 'stock'); +INSERT INTO `ospos_stock_locations` (`location_name` ) VALUES ('stock'); -- -------------------------------------------------------- @@ -806,7 +713,7 @@ CREATE TABLE `ospos_suppliers` ( `deleted` int(1) NOT NULL DEFAULT '0', UNIQUE KEY `account_number` (`account_number`), KEY `person_id` (`person_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -- -------------------------------------------------------- @@ -820,16 +727,16 @@ CREATE TABLE IF NOT EXISTS `ospos_tax_categories` ( `tax_category` varchar(32) NOT NULL, `tax_group_sequence` tinyint(2) NOT NULL, PRIMARY KEY (`tax_category_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -- -- Dumping data for table `ospos_stock_locations` -- -INSERT INTO `ospos_tax_categories` ( `tax_category_id`,`tax_category`, `tax_group_sequence` ) VALUES - (1, 'Standard', 10), - (2, 'Service', 12), - (3, 'Alcohol', 11); +INSERT INTO `ospos_tax_categories` (`tax_category`, `tax_group_sequence` ) VALUES + ('Standard', 10), + ('Service', 12), + ('Alcohol', 11); -- -------------------------------------------------------- @@ -883,15 +790,13 @@ CREATE TABLE `ospos_dinner_tables` ( `status` tinyint(1) NOT NULL DEFAULT '0', `deleted` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`dinner_table_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -- -- Dumping data for table `ospos_dinner_tables` -- -INSERT INTO `ospos_dinner_tables` (`dinner_table_id`, `name`, `status`, `deleted`) VALUES -(1, 'Delivery', 0, 0), -(2, 'Take Away', 0, 0); +INSERT INTO `ospos_dinner_tables` (`name`) VALUES ('Delivery'), ('Take Away'); -- -------------------------------------------------------- @@ -908,12 +813,12 @@ CREATE TABLE IF NOT EXISTS `ospos_customers_packages` ( PRIMARY KEY (`package_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -INSERT INTO `ospos_customers_packages` (`package_id`, `package_name`, `points_percent`, `deleted`) VALUES -(1, 'Default', 0, 0), -(2, 'Bronze', 10, 0), -(3, 'Silver', 20, 0), -(4, 'Gold', 30, 0), -(5, 'Premium', 50, 0); +INSERT INTO `ospos_customers_packages` (`package_name`, `points_percent`) VALUES + ('Default', 0), + ('Bronze', 10), + ('Silver', 20), + ('Gold', 30), + ('Premium', 50); -- -------------------------------------------------------- @@ -1225,35 +1130,6 @@ ALTER TABLE `ospos_sales_items_taxes` ALTER TABLE `ospos_sales_payments` ADD CONSTRAINT `ospos_sales_payments_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales` (`sale_id`); --- --- Constraints for table `ospos_sales_suspended` --- -ALTER TABLE `ospos_sales_suspended` - ADD CONSTRAINT `ospos_sales_suspended_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `ospos_employees` (`person_id`), - ADD CONSTRAINT `ospos_sales_suspended_ibfk_2` FOREIGN KEY (`customer_id`) REFERENCES `ospos_customers` (`person_id`), - ADD CONSTRAINT `ospos_sales_suspended_ibfk_3` FOREIGN KEY (`dinner_table_id`) REFERENCES `ospos_dinner_tables` (`dinner_table_id`); - --- --- Constraints for table `ospos_sales_suspended_items` --- -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_3` FOREIGN KEY (`item_location`) REFERENCES `ospos_stock_locations` (`location_id`); - --- --- Constraints for table `ospos_sales_suspended_items_taxes` --- -ALTER TABLE `ospos_sales_suspended_items_taxes` - ADD CONSTRAINT `ospos_sales_suspended_items_taxes_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_suspended_items` (`sale_id`), - ADD CONSTRAINT `ospos_sales_suspended_items_taxes_ibfk_2` FOREIGN KEY (`item_id`) REFERENCES `ospos_items` (`item_id`); - --- --- Constraints for table `ospos_sales_suspended_payments` --- -ALTER TABLE `ospos_sales_suspended_payments` - ADD CONSTRAINT `ospos_sales_suspended_payments_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_suspended` (`sale_id`); - -- -- Constraints for table `ospos_item_quantities` -- diff --git a/database/tables.sql b/database/tables.sql index 984a58a05..d3d2e5dd8 100644 --- a/database/tables.sql +++ b/database/tables.sql @@ -51,10 +51,10 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('last_used_invoice_number', '0'), ('last_used_quote_number', '0'), ('line_sequence', '0'), -('recv_invoice_format', '$CO'), -('sales_invoice_format', '$CO'), +('recv_invoice_format', '{CO}'), +('sales_invoice_format', '{CO}'), ('sales_quote_format', 'Q%y{QSEQ:6}'), -('invoice_email_message', 'Dear $CU, In attachment the receipt for sale $INV'), +('invoice_email_message', 'Dear {CU}, In attachment the receipt for sale $INV'), ('invoice_default_comments', 'This is a default comment'), ('print_silently', '1'), ('print_header', '0'), @@ -151,7 +151,7 @@ CREATE TABLE `ospos_employees` ( -- INSERT INTO `ospos_employees` (`username`, `password`, `person_id`, `deleted`, `hash_version`) VALUES -('admin', '$2y$10$vJBSMlD02EC7ENSrKfVQXuvq9tNRHMtcOA8MSK2NYS748HHWm.gcG', 1, 0, 2); + ('admin', '$2y$10$vJBSMlD02EC7ENSrKfVQXuvq9tNRHMtcOA8MSK2NYS748HHWm.gcG', 1, 0, 2); -- -------------------------------------------------------- @@ -660,99 +660,6 @@ CREATE TABLE `ospos_sales_taxes` ( -- --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended` --- - -CREATE TABLE `ospos_sales_suspended` ( - `sale_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `customer_id` int(10) DEFAULT NULL, - `employee_id` int(10) NOT NULL DEFAULT '0', - `comment` text NOT NULL, - `invoice_number` varchar(32) DEFAULT NULL, - `quote_number` varchar(32) DEFAULT NULL, - `sale_id` int(10) NOT NULL AUTO_INCREMENT, - `dinner_table_id` int(11) NULL, - PRIMARY KEY (`sale_id`), - KEY `customer_id` (`customer_id`), - KEY `employee_id` (`employee_id`), - KEY `dinner_table_id` (`dinner_table_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Dumping data for table `ospos_sales_suspended` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended_items` --- - -CREATE TABLE `ospos_sales_suspended_items` ( - `sale_id` int(10) NOT NULL DEFAULT '0', - `item_id` int(10) NOT NULL DEFAULT '0', - `description` varchar(30) DEFAULT NULL, - `serialnumber` varchar(30) DEFAULT NULL, - `line` int(3) NOT NULL DEFAULT '0', - `quantity_purchased` decimal(15,3) NOT NULL DEFAULT '0', - `item_cost_price` decimal(15,2) NOT NULL, - `item_unit_price` decimal(15,2) NOT NULL, - `discount_percent` decimal(15,2) NOT NULL DEFAULT '0', - `item_location` int(11) NOT NULL, - `print_option` TINYINT(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; - --- --- Dumping data for table `ospos_sales_suspended_items` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended_items_taxes` --- - -CREATE TABLE `ospos_sales_suspended_items_taxes` ( - `sale_id` int(10) NOT NULL, - `item_id` int(10) NOT NULL, - `line` int(3) NOT NULL DEFAULT '0', - `name` varchar(255) NOT NULL, - `percent` decimal(15,3) NOT NULL, - PRIMARY KEY (`sale_id`,`item_id`,`line`,`name`,`percent`), - KEY `item_id` (`item_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Dumping data for table `ospos_sales_suspended_items_taxes` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `ospos_sales_suspended_payments` --- - -CREATE TABLE `ospos_sales_suspended_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`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Dumping data for table `ospos_sales_suspended_payments` --- - - -- -------------------------------------------------------- -- @@ -789,7 +696,7 @@ CREATE TABLE `ospos_stock_locations` ( -- Dumping data for table `ospos_stock_locations` -- -INSERT INTO `ospos_stock_locations` ( `deleted`, `location_name` ) VALUES ('0', 'stock'); +INSERT INTO `ospos_stock_locations` (`location_name` ) VALUES ('stock'); -- -------------------------------------------------------- @@ -806,7 +713,7 @@ CREATE TABLE `ospos_suppliers` ( `deleted` int(1) NOT NULL DEFAULT '0', UNIQUE KEY `account_number` (`account_number`), KEY `person_id` (`person_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -- -------------------------------------------------------- @@ -820,16 +727,16 @@ CREATE TABLE IF NOT EXISTS `ospos_tax_categories` ( `tax_category` varchar(32) NOT NULL, `tax_group_sequence` tinyint(2) NOT NULL, PRIMARY KEY (`tax_category_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -- -- Dumping data for table `ospos_stock_locations` -- -INSERT INTO `ospos_tax_categories` ( `tax_category_id`,`tax_category`, `tax_group_sequence` ) VALUES - (1, 'Standard', 10), - (2, 'Service', 12), - (3, 'Alcohol', 11); +INSERT INTO `ospos_tax_categories` (`tax_category`, `tax_group_sequence` ) VALUES + ('Standard', 10), + ('Service', 12), + ('Alcohol', 11); -- -------------------------------------------------------- @@ -883,15 +790,13 @@ CREATE TABLE `ospos_dinner_tables` ( `status` tinyint(1) NOT NULL DEFAULT '0', `deleted` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`dinner_table_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -- -- Dumping data for table `ospos_dinner_tables` -- -INSERT INTO `ospos_dinner_tables` (`dinner_table_id`, `name`, `status`, `deleted`) VALUES -(1, 'Delivery', 0, 0), -(2, 'Take Away', 0, 0); +INSERT INTO `ospos_dinner_tables` (`name`) VALUES ('Delivery'), ('Take Away'); -- -------------------------------------------------------- @@ -908,12 +813,12 @@ CREATE TABLE IF NOT EXISTS `ospos_customers_packages` ( PRIMARY KEY (`package_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; -INSERT INTO `ospos_customers_packages` (`package_id`, `package_name`, `points_percent`, `deleted`) VALUES -(1, 'Default', 0, 0), -(2, 'Bronze', 10, 0), -(3, 'Silver', 20, 0), -(4, 'Gold', 30, 0), -(5, 'Premium', 50, 0); +INSERT INTO `ospos_customers_packages` (`package_name`, `points_percent`) VALUES + ('Default', 0), + ('Bronze', 10), + ('Silver', 20), + ('Gold', 30), + ('Premium', 50); -- -------------------------------------------------------- From 6b0a2576a399d32669d0904e3eec72174752eb3a Mon Sep 17 00:00:00 2001 From: jekkos Date: Fri, 4 Aug 2017 04:40:03 +0200 Subject: [PATCH 2/5] Remove unused methods --- application/models/Sale.php | 55 ++----------------------------------- 1 file changed, 2 insertions(+), 53 deletions(-) diff --git a/application/models/Sale.php b/application/models/Sale.php index bb5bb9a97..518210d90 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -1280,63 +1280,12 @@ class Sale extends CI_Model { $this->db->from('sales'); $this->db->where('sale_id', $sale_id); - $this->db->join('people', 'people.person_id = sales_suspended.customer_id', 'LEFT'); + $this->db->join('people', 'people.person_id = sales.customer_id', 'LEFT'); + $this->db-where('sale_status', 1); return $this->db->get(); } - function get_day_total($sale_time) - { - $this->db->select("SUM(ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100),2)) as total", FALSE); - $this->db->from('sales'); - $this->db->join('sales_items', "sales_items.sale_id = sales.sale_id"); - $this->db->where("DATE_FORMAT(sale_time, '%Y-%m-%d') = '" . date('Y-m-d', strtotime($sale_time)) . "'"); - return $this->db->get()->result_array(); - } - - function get_totals($from, $to=NULL) - { - $this->db->select("SUM(payment_amount)"); - $this->db->select('sale_time'); - $this->db->from('sales'); - $this->db->join('sales_payments', "sales_payments.sale_id = sales.sale_id"); - if (isset($to)) - { - $this->db->where("sale_time BETWEEN DATE(" . $this->db->escape($from) . ") AND DATE(" . $this->db->escape($to) . ")"); - $this->db->group_by("DAY(sale_time)"); - } - else - { - $this->db->where("DATE(sale_time) = DATE(" . $this->db->escape($from) . ")"); - } - return $this->db->get(); - } - - function get_payments_by_day($sale_time) - { - $this->db->from('sales'); - $this->db->join('sales_payments', "sales_payments.sale_id = sales.sale_id"); - $this->db->where("DATE_FORMAT(sale_time,'%Y-%m-%d') = " . $this->db->escape(date('Y-m-d', strtotime($sale_time)))); - $this->db->where('payment_type', 'Contant'); - $this->db->where('invoice_number IS NULL'); - $this->db->or_where('invoice_number', ''); - return $this->db->get()->result_array(); - } - - function update_sale_item($sale_id, $item_id, $sale_item) - { - $this->db->where('sale_id', $sale_id); - $this->db->where('item_id', $item_id); - $this->db->update('sales_items', $sale_item); - } - - function update_sale_payment($sale_payment_id, $sale_payment) - { - $this->db->where('sale_id', $sale_payment_id); - $this->db->where('payment_type', 'Contant'); - $this->db->update('sales_payments', $sale_payment); - } - /** * @param $customer_id * @param $sale_id From 4a05f00307fea4b5ed8d06543b08fc201eb71202 Mon Sep 17 00:00:00 2001 From: jekkos Date: Sat, 5 Aug 2017 19:56:54 +0200 Subject: [PATCH 3/5] Some indentation --- application/libraries/tokens/Token_customer.php | 4 ---- application/models/Sale.php | 6 ++++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/application/libraries/tokens/Token_customer.php b/application/libraries/tokens/Token_customer.php index c36fe1b0f..615e72d26 100644 --- a/application/libraries/tokens/Token_customer.php +++ b/application/libraries/tokens/Token_customer.php @@ -33,10 +33,6 @@ class Token_customer extends Token return trim($customer_info->first_name . ' ' . $customer_info->last_name); } } - elseif (!empty($this->customer_info)) - { - - } return $value; } diff --git a/application/models/Sale.php b/application/models/Sale.php index 518210d90..0b6ae5b0b 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -1294,10 +1294,12 @@ class Sale extends CI_Model */ private function save_customer_rewards($customer_id, $sale_id, $total_amount, $total_amount_used) { - if (!empty($customer_id) && $this->config->item('customer_reward_enable') == TRUE) { + if (!empty($customer_id) && $this->config->item('customer_reward_enable') == TRUE) + { $package_id = $this->Customer->get_info($customer_id)->package_id; - if (!empty($package_id)) { + if (!empty($package_id)) + { $points_percent = $this->Customer_rewards->get_points_percent($package_id); $points = $this->Customer->get_info($customer_id)->points; $points = ($points == NULL ? 0 : $points); From 9d08e9e5beb2d9449a390cc0cfafa293d3625eed Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sun, 6 Aug 2017 10:15:36 +0100 Subject: [PATCH 4/5] Restore barcode formats --- database/3.0.2_to_3.1.0.sql | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/database/3.0.2_to_3.1.0.sql b/database/3.0.2_to_3.1.0.sql index 27848a254..538d2c14f 100644 --- a/database/3.0.2_to_3.1.0.sql +++ b/database/3.0.2_to_3.1.0.sql @@ -115,7 +115,6 @@ CREATE TABLE IF NOT EXISTS `ospos_sales_reward_points` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; - -- alter ospos_customers table ALTER TABLE ospos_customers @@ -275,7 +274,6 @@ UPDATE `ospos_tax_code_rates` SET rate_tax_category_id = 1 WHERE rate_tax_catego INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('receipt_font_size', '12'); - -- -- Add rewards foreign keys -- @@ -296,15 +294,18 @@ ALTER TABLE `ospos_customers` ADD KEY `package_id` (`package_id`), ADD CONSTRAINT `ospos_customers_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`); - -- add reCAPTCHA configuration - INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('gcaptcha_enable', '0'), ('gcaptcha_secret_key', ''), ('gcaptcha_site_key', ''); +-- add Barcode formats + +INSERT INTO `ospos_app_config` (`key`, `value`) VALUES + ('barcode_formats', '[]'); + -- replace old tokens in ospos_app_config UPDATE `ospos_app_config` SET `value` = REPLACE(`value`, '$CO', '{CO}'); @@ -324,4 +325,4 @@ INSERT INTO `ospos_sales_items` (sale_id, item_id, description, serialnumber, li INSERT INTO `ospos_sales_payments` (sale_id, payment_type, payment_amount) SELECT sale_id, payment_type, payment_amount FROM `ospos_sales_suspended_payments`; INSERT INTO `ospos_sales_items_taxes` (sale_id, item_id, line, name, percent) SELECT sale_id, item_id, line, name, percent FROM `ospos_sales_suspended_items_taxes`; -DROP TABLE ospos_sales_suspended_payments, ospos_sales_suspended_item_taxes, ospos_sales_suspended_items, ospos_sales_suspended; \ No newline at end of file +DROP TABLE ospos_sales_suspended_payments, ospos_sales_suspended_item_taxes, ospos_sales_suspended_items, ospos_sales_suspended; From 6c714b2dc40fab471a814e3c90bd2084399babc9 Mon Sep 17 00:00:00 2001 From: jekkos Date: Sun, 6 Aug 2017 15:01:10 +0200 Subject: [PATCH 5/5] Add constants for magic numbers --- application/controllers/Item_kits.php | 2 +- application/controllers/Items.php | 4 +- application/controllers/Sales.php | 12 +++--- application/libraries/Sale_lib.php | 28 +++++++------- application/models/Customer.php | 2 +- application/models/Item.php | 37 +++++++++++++------ application/models/Sale.php | 30 ++++++++------- application/models/reports/Detailed_sales.php | 16 ++++---- .../models/reports/Specific_customer.php | 16 ++++---- .../models/reports/Specific_discount.php | 16 ++++---- .../models/reports/Specific_employee.php | 16 ++++---- application/models/reports/Summary_report.php | 8 ++-- application/views/item_kits/form.php | 12 +++--- application/views/items/form.php | 8 ++-- application/views/partial/header.php | 2 +- 15 files changed, 113 insertions(+), 96 deletions(-) diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index 545389aa0..77fde8338 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -88,7 +88,7 @@ class Item_kits extends Secure_Controller if($item_kit_id == -1) { $info->price_option = '0'; - $info->print_option = '0'; + $info->print_option = PRINT_ALL; $info->kit_item_id = 0; } foreach(get_object_vars($info) as $property => $value) diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 373aad6b5..24fe93427 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -195,8 +195,8 @@ class Items extends Secure_Controller $item_info->receiving_quantity = 1; $item_info->reorder_level = 1; - $item_info->item_type = '0'; // standard - $item_info->stock_type = '0'; // stock + $item_info->item_type = ITEM; // standard + $item_info->stock_type = HAS_STOCK; $item_info->tax_category_id = 1; // Standard } diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index d8cc07d35..67425e7ce 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -351,7 +351,7 @@ class Sales extends Secure_Controller } $price = NULL; - $print_option = 0; // Always include in list of items on invoice + $print_option = PRINT_ALL; // Always include in list of items on invoice if(!empty($kit_item_id)) { @@ -525,7 +525,7 @@ class Sales extends Secure_Controller else { $data['invoice_number'] = $invoice_number; - $data['sale_status'] = '0'; // Complete + $data['sale_status'] = COMPLETED; // Save the data to the sales table $data['sale_id_num'] = $this->Sale->save($data['sale_status'], $data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $data["quote_number"], $data['payments'], $data['dinner_table'], $data['taxes']); @@ -570,7 +570,7 @@ class Sales extends Secure_Controller { $data['invoice_number'] = $invoice_number; $data['quote_number'] = $quote_number; - $data['sale_status'] = '1'; // Suspended + $data['sale_status'] = SUSPENDED; $data['sale_id_num'] = $this->Sale->save($data['sale_status'], $data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $quote_number, $data['payments'], $data['dinner_table'], $data['taxes']); $this->sale_lib->set_suspended_id($data['sale_id_num']); @@ -1057,7 +1057,7 @@ class Sales extends Secure_Controller $invoice_number = $this->sale_lib->get_invoice_number(); $quote_number = $this->sale_lib->get_quote_number(); $comment = $this->sale_lib->get_comment(); - $sale_status = $this->sale_lib->is_quote_mode() ? '2' : '1'; + $sale_status = $this->sale_lib->is_quote_mode() ? QUOTE : SUSPENDED; $data = array(); $sales_taxes = array(); @@ -1114,11 +1114,11 @@ class Sales extends Secure_Controller $filtered_cart = array(); foreach($cart as $id => $item) { - if($item['print_option'] == '0') // always include + if($item['print_option'] == PRINT_ALL) // always include { $filtered_cart[$id] = $item; } - elseif($item['print_option'] == '1' && $item['price'] != 0) // include only if the price is not zero + elseif($item['print_option'] == PRINT_PRICED && $item['price'] != 0) // include only if the price is not zero { $filtered_cart[$id] = $item; } diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index d30ef94a5..3fa6688bd 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -580,7 +580,7 @@ class Sale_lib $this->CI->session->unset_userdata('sales_rewards_remainder'); } - public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $price = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE, $print_option = '0', $stock_type = '0') + public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $price = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE, $print_option = '0', $stock_type = HAS_STOCK) { $item_info = $this->CI->Item->get_info_by_id_or_number($item_id); @@ -644,9 +644,9 @@ class Sale_lib // For print purposes this simpifies line selection // 0 will print, 2 will not print. The decision about 1 is made here - if($print_option =='1') + if($print_option == PRINT_PRICED) { - $print_option = ($price == 0) ? '2' : '0'; + $print_option = ($price == 0) ? PRINT_KIT : PRINT_ALL; } $total = $this->get_item_total($quantity, $price, $discount); @@ -699,7 +699,7 @@ class Sale_lib { $item_info = $this->CI->Item->get_info_by_id_or_number($item_id); - if($item_info->stock_type == '0') + if($item_info->stock_type == HAS_STOCK) { $item_quantity = $this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity; $quantity_added = $this->get_quantity_already_added($item_id, $item_location); @@ -800,17 +800,17 @@ class Sale_lib foreach($this->CI->Item_kit_items->get_info($item_kit_id) as $item_kit_item) { - if($price_option == '0') // all + if($price_option == PRICE_ALL) // all { $price = null; } - elseif($price_option == '1') // item kit only + elseif($price_option == PRICE_KIT) // item kit only { $price = 0; } - elseif($price_option == '2') // item kit plus stock items (assuming materials) + elseif($price_option == PRICE_ITEMS) // item kit plus stock items (assuming materials) { - if($item_kit_item['stock_type'] == 0) // stock item + if($item_kit_item['stock_type'] == ITEM) // stock item { $price = null; } @@ -820,17 +820,17 @@ class Sale_lib } } - if($kit_print_option == '0') // all + if($kit_print_option == PRINT_ALL) { - $print_option = '0'; // print always + $print_option = PRINT_ALL; } - elseif($kit_print_option == '1') // priced + elseif($kit_print_option == PRINT_PRICED) // priced { - $print_option = '1'; // print if price not zero + $print_option = PRINT_PRICED; // print if price not zero } - elseif($kit_print_option == '2') // kit only if price is not zero + elseif($kit_print_option == PRINT_KIT) // kit only if price is not zero { - $print_option = '2'; // Do not include in list + $print_option = PRINT_KIT; // Do not include in list } $result &= $this->add_item($item_kit_item['item_id'], $item_kit_item['quantity'], $item_location, $discount, $price, null, null, null, $print_option, $item_kit_item['stock_type']); diff --git a/application/models/Customer.php b/application/models/Customer.php index ae2baf102..6061d584f 100644 --- a/application/models/Customer.php +++ b/application/models/Customer.php @@ -130,7 +130,7 @@ class Customer extends Person $this->db->join('sales_payments AS sales_payments', 'sales.sale_id = sales_payments.sale_id'); $this->db->join('sales_items_temp AS sales_items_temp', 'sales.sale_id = sales_items_temp.sale_id'); $this->db->where('sales.customer_id', $customer_id); - $this->db->where('sales.sale_status', 0); + $this->db->where('sales.sale_status', COMPLETED); $this->db->group_by('sales.customer_id'); $stat = $this->db->get()->row(); diff --git a/application/models/Item.php b/application/models/Item.php index 28bdb740d..f8eb442a7 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -1,5 +1,18 @@ db->select('item_id, name'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->like('name', $search); $this->db->order_by('name', 'asc'); foreach($this->db->get()->result() as $row) @@ -433,7 +446,7 @@ class Item extends CI_Model $this->db->select('item_id, item_number'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->like('item_number', $search); $this->db->order_by('item_number', 'asc'); foreach($this->db->get()->result() as $row) @@ -447,7 +460,7 @@ class Item extends CI_Model $this->db->select('category'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->distinct(); $this->db->like('category', $search); $this->db->order_by('category', 'asc'); @@ -462,7 +475,7 @@ class Item extends CI_Model $this->db->like('company_name', $search); // restrict to non deleted companies only if is_deleted is FALSE $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->distinct(); $this->db->order_by('company_name', 'asc'); foreach($this->db->get()->result() as $row) @@ -474,7 +487,7 @@ class Item extends CI_Model $this->db->select('item_id, name, description'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->like('description', $search); $this->db->order_by('description', 'asc'); foreach($this->db->get()->result() as $row) @@ -503,7 +516,7 @@ class Item extends CI_Model $this->db->or_like('custom10', $search); $this->db->group_end(); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later foreach($this->db->get()->result() as $row) { $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); @@ -529,7 +542,7 @@ class Item extends CI_Model $this->db->select('item_id, name'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->like('name', $search); $this->db->order_by('name', 'asc'); @@ -541,7 +554,7 @@ class Item extends CI_Model $this->db->select('item_id, item_number'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->like('item_number', $search); $this->db->order_by('item_number', 'asc'); @@ -556,7 +569,7 @@ class Item extends CI_Model $this->db->select('category'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->distinct(); $this->db->like('category', $search); @@ -583,7 +596,7 @@ class Item extends CI_Model $this->db->select('item_id, name, description'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->like('description', $search); $this->db->order_by('description', 'asc'); @@ -612,7 +625,7 @@ class Item extends CI_Model $this->db->or_like('custom9', $search); $this->db->or_like('custom10', $search); $this->db->group_end(); - $this->db->where("item_type = '0'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->where('deleted', $filters['is_deleted']); foreach($this->db->get()->result() as $row) @@ -639,7 +652,7 @@ class Item extends CI_Model $this->db->select('item_id, name'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = '1'"); // standard, exclude kit items since kits will be picked up later + $this->db->where("item_type = " . ITEM_KIT); // standard, exclude kit items since kits will be picked up later $this->db->like('name', $search); $this->db->order_by('name', 'asc'); foreach($this->db->get()->result() as $row) diff --git a/application/models/Sale.php b/application/models/Sale.php index 0b6ae5b0b..3f374e8fd 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -1,5 +1,9 @@ db->where('sales.sale_status = 0 AND payment_amount > 0'); + $this->db->where('sales.sale_status = ' . COMPLETED . ' AND payment_amount > 0'); } elseif($filters['sale_type'] == 'quotes') { - $this->db->where('sales.sale_status = 1 AND sales.quote_number IS NOT NULL'); + $this->db->where('sales.sale_status = ' . SUSPENDED . ' AND sales.quote_number IS NOT NULL'); } elseif($filters['sale_type'] == 'returns') { - $this->db->where('sales.sale_status = 0 AND payment_amount < 0'); + $this->db->where('sales.sale_status = ' . COMPLETED . ' AND payment_amount < 0'); } if($filters['only_invoices'] != FALSE) @@ -606,7 +610,7 @@ class Sale extends CI_Model $this->db->insert('sales_items', $sales_items_data); - if($cur_item_info->stock_type === '0' && $sale_status === '0') + if($cur_item_info->stock_type === HAS_STOCK && $sale_status === COMPLETED) { // Update stock quantity if item type is a standard stock item and the sale is a standard sale $item_quantity = $this->Item_quantity->get_item_quantity($item['item_id'], $item['item_location']); @@ -807,7 +811,7 @@ class Sale extends CI_Model { $cur_item_info = $this->Item->get_info($item['item_id']); - if($cur_item_info->stock_type === '0') { + if($cur_item_info->stock_type === HAS_STOCK) { // create query to update inventory tracking $inv_data = array( 'trans_date' => date('Y-m-d H:i:s'), @@ -1170,12 +1174,12 @@ class Sale extends CI_Model if($customer_id == -1) { $query = $this->db->query('select sale_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from ' - . $this->db->dbprefix('sales') . ' where sale_status = 1'); + . $this->db->dbprefix('sales') . ' where sale_status = ' . SUSPENDED); } else { $query = $this->db->query('select sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from ' - . $this->db->dbprefix('sales') . ' where sale_status = 1 AND customer_id = ' . $customer_id); + . $this->db->dbprefix('sales') . ' where sale_status = '. SUSPENDED .' AND customer_id = ' . $customer_id); } return $query->result_array(); @@ -1240,7 +1244,7 @@ class Sale extends CI_Model { $this->db->from('sales'); $this->db->where('invoice_number IS NOT NULL'); - $this->db->where('sale_status', '1'); + $this->db->where('sale_status', SUSPENDED); return $this->db->count_all_results(); } @@ -1266,7 +1270,7 @@ class Sale extends CI_Model $this->db->delete('sales_items_taxes', array('sale_id' => $sale_id)); $this->db->delete('sales_items', array('sale_id' => $sale_id)); $this->db->delete('sales_taxes', array('sale_id' => $sale_id)); - $this->db->delete('sales', array('sale_id' => $sale_id, 'sale_status' => 1)); + $this->db->delete('sales', array('sale_id' => $sale_id, 'sale_status' => SUSPENDED)); $this->db->trans_complete(); @@ -1281,7 +1285,7 @@ class Sale extends CI_Model $this->db->from('sales'); $this->db->where('sale_id', $sale_id); $this->db->join('people', 'people.person_id = sales.customer_id', 'LEFT'); - $this->db-where('sale_status', 1); + $this->db-where('sale_status', SUSPENDED); return $this->db->get(); } @@ -1320,11 +1324,11 @@ class Sale extends CI_Model */ private function determine_sale_status(&$sale_status, $dinner_table) { - if ($sale_status == '1' && $dinner_table > 2) //not delivery or take away + if ($sale_status == SUSPENDED && $dinner_table > 2) //not delivery or take away { - return 1; + return SUSPENDED; } - return 0; + return COMPLETED; } } ?> diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index d1eb34217..d295ef10d 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -88,19 +88,19 @@ class Detailed_sales extends Report if($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = 0 and quantity_purchased > 0'); + $this->db->where('sale_status = '. COMPLETED . ' and quantity_purchased > 0'); } elseif($inputs['sale_type'] == 'all') { - $this->db->where('sale_status = 0'); + $this->db->where('sale_status = ' . COMPLETED); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = 1 and quote_number IS NOT NULL'); + $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = 0 and quantity_purchased < 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); } $this->db->group_by('sale_id'); @@ -138,19 +138,19 @@ class Detailed_sales extends Report if($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = 0 and quantity_purchased > 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); } elseif($inputs['sale_type'] == 'all') { - $this->db->where('sale_status = 0'); + $this->db->where('sale_status = ' . COMPLETED); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = 1 and quote_number IS NOT NULL'); + $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = 0 and quantity_purchased < 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Specific_customer.php b/application/models/reports/Specific_customer.php index 2d3a19295..2ce8e31e9 100644 --- a/application/models/reports/Specific_customer.php +++ b/application/models/reports/Specific_customer.php @@ -61,19 +61,19 @@ class Specific_customer extends Report if($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = 0 and quantity_purchased > 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); } elseif($inputs['sale_type'] == 'all') { - $this->db->where('sale_status = 0'); + $this->db->where('sale_status = ' . COMPLETED); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = 1 and quote_number IS NOT NULL'); + $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = 0 and quantity_purchased < 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); } $this->db->group_by('sale_id'); @@ -107,19 +107,19 @@ class Specific_customer extends Report if($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = 0 and quantity_purchased > 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); } elseif($inputs['sale_type'] == 'all') { - $this->db->where('sale_status = 0'); + $this->db->where('sale_status = ' . COMPLETED); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = 1 and quote_number IS NOT NULL'); + $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = 0 and quantity_purchased < 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index 03ad11ce7..5c67ef061 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -59,19 +59,19 @@ class Specific_discount extends Report if($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = 0 and quantity_purchased > 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); } elseif($inputs['sale_type'] == 'all') { - $this->db->where('sale_status = 0'); + $this->db->where('sale_status = ' . COMPLETED); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = 1 and quote_number IS NOT NULL'); + $this->db->where('sale_status = '. SUSPENDED .' and quote_number IS NOT NULL'); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = 0 and quantity_purchased < 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); } $this->db->group_by('sale_id'); @@ -105,19 +105,19 @@ class Specific_discount extends Report if($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = 0 and quantity_purchased > 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); } elseif($inputs['sale_type'] == 'all') { - $this->db->where('sale_status = 0'); + $this->db->where('sale_status = ' . COMPLETED); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = 1 and quote_number IS NOT NULL'); + $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = 0 and quantity_purchased < 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 1969b6ed0..5eace2d21 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -61,19 +61,19 @@ class Specific_employee extends Report if($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = 0 and quantity_purchased > 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); } elseif($inputs['sale_type'] == 'all') { - $this->db->where('sale_status = 0'); + $this->db->where('sale_status = ' . COMPLETED); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = 1 and quote_number IS NOT NULL'); + $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = 0 and quantity_purchased < 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); } $this->db->group_by('sale_id'); @@ -107,19 +107,19 @@ class Specific_employee extends Report if($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = 0 and quantity_purchased > 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); } elseif($inputs['sale_type'] == 'all') { - $this->db->where('sale_status = 0'); + $this->db->where('sale_status = ' . COMPLETED); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = 1 and quote_number IS NOT NULL'); + $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = 0 and quantity_purchased < 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Summary_report.php b/application/models/reports/Summary_report.php index 0c36a32ce..02ae835d9 100644 --- a/application/models/reports/Summary_report.php +++ b/application/models/reports/Summary_report.php @@ -92,19 +92,19 @@ abstract class Summary_report extends Report if($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = 0 and quantity_purchased > 0'); + $this->db->where('sale_status = '. COMPLETED . ' and quantity_purchased > 0'); } elseif($inputs['sale_type'] == 'all') { - $this->db->where('sale_status = 0'); + $this->db->where('sale_status = '. COMPLETED); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = 1 and quote_number IS NOT NULL'); + $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = 0 and quantity_purchased < 0'); + $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); } diff --git a/application/views/item_kits/form.php b/application/views/item_kits/form.php index 0613b4c8e..9269dbb99 100644 --- a/application/views/item_kits/form.php +++ b/application/views/item_kits/form.php @@ -59,7 +59,7 @@ 'type'=>'radio', 'id'=>'price_option', 'value'=>0, - 'checked'=>$item_kit_info->price_option === '0') + 'checked'=>$item_kit_info->price_option === PRICE_ALL) ); ?> lang->line('item_kits_kit_and_components'); ?> @@ -93,7 +93,7 @@ 'type'=>'radio', 'id'=>'print_option', 'value'=>0, - 'checked'=>$item_kit_info->print_option === '0') + 'checked'=>$item_kit_info->print_option === PRINT_ALL) ); ?> lang->line('item_kits_all'); ?> diff --git a/application/views/items/form.php b/application/views/items/form.php index 6ac40be74..97724726b 100644 --- a/application/views/items/form.php +++ b/application/views/items/form.php @@ -56,7 +56,7 @@ 'type'=>'radio', 'id'=>'stock_type', 'value'=>0, - 'checked'=>$item_info->stock_type === '0') + 'checked'=>$item_info->stock_type === HAS_STOCK) ); ?> lang->line('items_stock'); ?> @@ -80,7 +80,7 @@ 'type'=>'radio', 'id'=>'item_type', 'value'=>0, - 'checked'=>$item_info->item_type === '0') + 'checked'=>$item_info->item_type === ITEM) ); ?> lang->line('items_standard'); ?> diff --git a/application/views/partial/header.php b/application/views/partial/header.php index 8caf67bc9..6307fbccd 100644 --- a/application/views/partial/header.php +++ b/application/views/partial/header.php @@ -74,7 +74,7 @@ - +