diff --git a/application/config/config.php b/application/config/config.php index 32cfc75d9..94a0b5aa5 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -8,7 +8,7 @@ | | */ -$config['application_version'] = '3.1.1'; +$config['application_version'] = '3.2.0'; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 6684f52ed..dc0bc8b17 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -206,6 +206,7 @@ class Config extends Secure_Controller $data['register_mode_options'] = $this->sale_lib->get_register_mode_options(); $data['rounding_options'] = Rounding_mode::get_rounding_options(); $data['tax_codes'] = $this->get_tax_code_options(); + $data['show_office_group'] = $this->Module->get_show_office_group(); $data = $this->xss_clean($data); @@ -308,6 +309,8 @@ class Config extends Secure_Controller 'custom10_name' => $this->input->post('custom10_name') ); + $this->Module->set_show_office_group($this->input->post('show_office_group') != NULL); + $result = $this->Appconfig->batch_save($batch_save_data); $success = $result ? TRUE : FALSE; @@ -841,7 +844,10 @@ class Config extends Secure_Controller 'invoice_email_message' => $this->input->post('invoice_email_message'), 'line_sequence' => $this->input->post('line_sequence'), 'last_used_invoice_number' =>$this->input->post('last_used_invoice_number'), - 'last_used_quote_number' =>$this->input->post('last_used_quote_number') + 'last_used_quote_number' =>$this->input->post('last_used_quote_number'), + 'work_order_enable' => $this->input->post('work_order_enable') != NULL, + 'work_order_format' => $this->input->post('work_order_format'), + 'last_used_work_order_number' =>$this->input->post('last_used_work_order_number') ); $result = $this->Appconfig->batch_save($batch_save_data); diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index 533f334b2..18960ad4a 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -61,6 +61,7 @@ class Employees extends Persons { $module->module_id = $this->xss_clean($module->module_id); $module->grant = $this->xss_clean($this->Employee->has_grant($module->module_id, $person_info->person_id)); + $module->menu_group = $this->xss_clean($this->Employee->get_menu_group($module->module_id, $person_info->person_id)); $modules[] = $module; } @@ -134,6 +135,16 @@ class Employees extends Persons 'comments' => $this->input->post('comments'), ); $grants_data = $this->input->post('grants') != NULL ? $this->input->post('grants') : array(); + $menu_groups = $this->input->post('menu_groups') != NULL ? $this->input->post('menu_groups') : array(); + + $grants_array = array(); + foreach ($grants_data as $key => $value) + { + $grants = array(); + $grants['permission_id'] = $value; + $grants['menu_group'] = $menu_groups[$key]; + $grants_array[] = $grants; + } //Password has been changed OR first time password set if($this->input->post('password') != '') @@ -149,7 +160,7 @@ class Employees extends Persons $employee_data = array('username' => $this->input->post('username')); } - if($this->Employee->save_employee($person_data, $employee_data, $grants_data, $employee_id)) + if($this->Employee->save_employee($person_data, $employee_data, $grants_array, $employee_id)) { // New employee if($employee_id == -1) diff --git a/application/controllers/Home.php b/application/controllers/Home.php index 87c1df243..1b8bca464 100644 --- a/application/controllers/Home.php +++ b/application/controllers/Home.php @@ -4,6 +4,11 @@ require_once("Secure_Controller.php"); class Home extends Secure_Controller { + function __construct() + { + parent::__construct(NULL, NULL, 'home'); + } + public function index() { $this->load->view('home'); diff --git a/application/controllers/Office.php b/application/controllers/Office.php new file mode 100644 index 000000000..ec140a731 --- /dev/null +++ b/application/controllers/Office.php @@ -0,0 +1,24 @@ +load->view('office'); + } + + public function logout() + { + $this->track_page('logout', 'logout'); + + $this->Employee->logout(); + } +} +?> diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 426d510f2..1ffcc3ddd 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -358,6 +358,7 @@ class Reports extends Secure_Controller $stock_locations['all'] = $this->lang->line('reports_all'); $data['stock_locations'] = array_reverse($stock_locations, TRUE); $data['mode'] = 'sale'; + $data['sale_type_options'] = $this->get_sale_type_options(); $this->load->view('reports/date_input', $data); } @@ -370,6 +371,7 @@ class Reports extends Secure_Controller $stock_locations['all'] = $this->lang->line('reports_all'); $data['stock_locations'] = array_reverse($stock_locations, TRUE); $data['mode'] = 'sale'; + $data['sale_type_options'] = $this->get_sale_type_options(); $this->load->view('reports/date_input', $data); } @@ -711,6 +713,7 @@ class Reports extends Secure_Controller $customers[$customer->person_id] = $this->xss_clean($customer->first_name . ' ' . $customer->last_name); } $data['specific_input_data'] = $customers; + $data['sale_type_options'] = $this->get_sale_type_options(); $this->load->view('reports/specific_input', $data); } @@ -735,6 +738,7 @@ class Reports extends Secure_Controller { $summary_data[] = $this->xss_clean(array( 'id' => anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), + 'type_code' => $row['type_code'], 'sale_date' => $row['sale_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), 'employee_name' => $row['employee_name'], @@ -796,6 +800,7 @@ class Reports extends Secure_Controller $employees[$employee->person_id] = $this->xss_clean($employee->first_name . ' ' . $employee->last_name); } $data['specific_input_data'] = $employees; + $data['sale_type_options'] = $this->get_sale_type_options(); $this->load->view('reports/specific_input', $data); } @@ -820,6 +825,7 @@ class Reports extends Secure_Controller { $summary_data[] = $this->xss_clean(array( 'id' => anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), + 'type_code' => $row['type_code'], 'sale_date' => $row['sale_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), 'customer_name' => $row['customer_name'], @@ -881,7 +887,8 @@ class Reports extends Secure_Controller $discounts[$i] = $i . '%'; } $data['specific_input_data'] = $discounts; - + $data['sale_type_options'] = $this->get_sale_type_options(); + $data = $this->xss_clean($data); $this->load->view('reports/specific_input', $data); @@ -907,6 +914,7 @@ class Reports extends Secure_Controller { $summary_data[] = $this->xss_clean(array( 'id' => anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), + 'type_code' => $row['type_code'], 'sale_date' => $row['sale_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), 'customer_name' => $row['customer_name'], @@ -987,6 +995,24 @@ class Reports extends Secure_Controller echo json_encode(array($sale_id => $summary_data)); } + public function get_sale_type_options() + { + $sale_type_options = array(); + $sale_type_options['complete'] = $this->lang->line('reports_complete'); + $sale_type_options['sales'] = $this->lang->line('reports_completed_sales'); + if($this->config->item('invoice_enable') == '1') + { + $sale_type_options['quotes'] = $this->lang->line('reports_quotes'); + if($this->config->item('work_order_enable') == '1') + { + $sale_type_options['work_orders'] = $this->lang->line('reports_work_orders'); + $sale_type_options['canceled'] = $this->lang->line('reports_canceled'); + } + } + $sale_type_options['returns'] = $this->lang->line('reports_returns'); + return $sale_type_options; + } + public function detailed_sales($start_date, $end_date, $sale_type, $location_id = 'all') { $inputs = array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id); @@ -1010,6 +1036,7 @@ class Reports extends Secure_Controller { $summary_data[] = $this->xss_clean(array( 'id' => $row['sale_id'], + 'type_code' => $row['type_code'], 'sale_date' => $row['sale_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), 'employee_name' => $row['employee_name'], diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 46cabc6d5..c10c9c061 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -147,13 +147,36 @@ class Sales extends Secure_Controller public function change_mode() { + $mode = $this->input->post('mode'); + $this->sale_lib->set_mode($mode); + + if($mode == 'sale') + { + $this->sale_lib->set_sale_type(SALE_TYPE_POS); + } + else if($mode == 'sale_quote') + { + $this->sale_lib->set_sale_type(SALE_TYPE_QUOTE); + } + else if($mode == 'sale_work_order') + { + $this->sale_lib->set_sale_type(SALE_TYPE_WORK_ORDER); + } + else if($mode == 'sale_invoice') + { + $this->sale_lib->set_sale_type(SALE_TYPE_INVOICE); + } + else + { + $this->sale_lib->set_sale_type(SALE_SALE); + } + $stock_location = $this->input->post('stock_location'); if(!$stock_location || $stock_location == $this->sale_lib->get_sale_location()) { - $mode = $this->input->post('mode'); - $this->sale_lib->set_mode($mode); $dinner_table = $this->input->post('dinner_table'); $this->sale_lib->set_dinner_table($dinner_table); + } elseif($this->Stock_location->is_allowed_location($stock_location, 'sales')) { @@ -163,6 +186,34 @@ class Sales extends Secure_Controller $this->_reload(); } + public function change_register_mode($sale_type) + { + if($sale_type == SALE_TYPE_POS) + { + $this->sale_lib->set_mode('sale'); + } + elseif($sale_type == SALE_TYPE_QUOTE) + { + $this->sale_lib->set_mode('sale_quote'); + } + elseif($sale_type == SALE_TYPE_WORK_ORDER) + { + $this->sale_lib->set_mode('sale_work_order'); + } + elseif($sale_type == SALE_TYPE_INVOICE) + { + $this->sale_lib->set_mode('sale_invoice'); + } + elseif($sale_type == SALE_TYPE_RETURN) + { + $this->sale_lib->set_mode('return'); + } + else + { + $this->sale_lib->set_mode('sale'); + } + } + public function set_comment() { $this->sale_lib->set_comment($this->input->post('comment')); @@ -189,6 +240,11 @@ class Sales extends Secure_Controller $this->sale_lib->set_print_after_sale($this->input->post('sales_print_after_sale')); } + public function set_price_work_orders() + { + $this->sale_lib->set_price_work_orders($this->input->post('price_work_orders')); + } + public function set_email_receipt() { $this->sale_lib->set_email_receipt($this->input->post('email_receipt')); @@ -443,6 +499,8 @@ class Sales extends Secure_Controller public function complete() { + $sale_id = $this->sale_lib->get_sale_id(); + $sale_type = $this->sale_lib->get_sale_type(); $data = array(); $data['dinner_table'] = $this->sale_lib->get_dinner_table(); $data['cart'] = $this->sale_lib->get_cart(); @@ -463,10 +521,15 @@ class Sales extends Secure_Controller $data['cur_giftcard_value'] = $this->sale_lib->get_giftcard_remainder(); $data['cur_rewards_value'] = $this->sale_lib->get_rewards_remainder(); $data['print_after_sale'] = $this->sale_lib->is_print_after_sale(); + $data['price_work_orders'] = $this->sale_lib->is_price_work_orders(); $data['email_receipt'] = $this->sale_lib->get_email_receipt(); $customer_id = $this->sale_lib->get_customer(); - $data["invoice_number"] = $this->sale_lib->get_invoice_number(); - $data["quote_number"] = $this->sale_lib->get_quote_number(); + $invoice_number = $this->sale_lib->get_invoice_number(); + $data["invoice_number"] = $invoice_number; + $work_order_number = $this->sale_lib->get_work_order_number(); + $data["work_order_number"] = $work_order_number; + $quote_number = $this->sale_lib->get_quote_number(); + $data["quote_number"] = $quote_number; $customer_info = $this->_load_customer_data($customer_id, $data); if($customer_info != NULL) { @@ -501,13 +564,26 @@ class Sales extends Secure_Controller } $data['amount_change'] = $data['amount_due'] * -1; - if($this->sale_lib->is_invoice_mode() || $data['invoice_number_enabled'] == TRUE) + $data['print_price_info'] = TRUE; + + if($this->sale_lib->is_sale_by_receipt_mode() && $this->input->post('sales_invoice_enable') == '1' ) + { + $pos_invoice = TRUE; + } + else + { + $pos_invoice = FALSE; + } + + if($this->sale_lib->is_invoice_mode() || $pos_invoice) { // generate final invoice number (if using the invoice in sales by receipt mode then the invoice number can be manually entered or altered in some way - if($this->sale_lib->is_sale_by_receipt_mode()) + if($pos_invoice) { + // The user can retain the default encoded format or can manually override it. It still passes through the rendering step. $this->sale_lib->set_invoice_number($this->input->post('invoice_number'), $keep_custom = TRUE); $invoice_format = $this->sale_lib->get_invoice_number(); + // If the user blanks out the invoice number and doesn't put anything in there then revert back to the default format encoding if(empty($invoice_format)) { $invoice_format = $this->config->item('sales_invoice_format'); @@ -517,10 +593,11 @@ class Sales extends Secure_Controller { $invoice_format = $this->config->item('sales_invoice_format'); } - $invoice_number = $this->token_lib->render($invoice_format); - // TODO If duplicate invoice then determine the number of employees and repeat until until success or tried the number of employees (if QSEQ was used). - if($this->Sale->check_invoice_number_exists($invoice_number)) + $invoice_number = $this->token_lib->render($invoice_format); + $data['invoice_number'] = $invoice_number; + + if($sale_id == -1 && $this->Sale->check_invoice_number_exists($invoice_number)) { $data['error'] = $this->lang->line('sales_invoice_number_duplicate'); $this->_reload($data); @@ -529,9 +606,10 @@ class Sales extends Secure_Controller { $data['invoice_number'] = $invoice_number; $data['sale_status'] = COMPLETED; + $sale_type = SALE_TYPE_INVOICE; // 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']); + $data['sale_id_num'] = $this->Sale->save($sale_id, $data['sale_status'], $data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $work_order_number, $quote_number, $sale_type, $data['payments'], $data['dinner_table'], $data['taxes']); $data['sale_id'] = 'POS ' . $data['sale_id_num']; // Resort and filter cart lines for printing @@ -551,10 +629,53 @@ class Sales extends Secure_Controller } } } + elseif($this->sale_lib->is_work_order_mode()) + { + + if(!($data['price_work_orders'] == 1)) + { + $data['print_price_info'] = FALSE; + } + + $data['sales_work_order'] = $this->lang->line('sales_work_order'); + $data['work_order_number_label'] = $this->lang->line('sales_work_order_number'); + + if($work_order_number == NULL) + { + // generate work order number + $work_order_format = $this->config->item('work_order_format'); + $work_order_number = $this->token_lib->render($work_order_format); + } + + if($sale_id == -1 && $this->Sale->check_work_order_number_exists($work_order_number)) + { + $data['error'] = $this->lang->line('sales_work_order_number_duplicate'); + $this->_reload($data); + } + else + { + $data['work_order_number'] = $work_order_number; + $data['sale_status'] = SUSPENDED; + $sale_type = SALE_TYPE_WORK_ORDER; + + $data['sale_id_num'] = $this->Sale->save($sale_id, $data['sale_status'], $data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $work_order_number, $quote_number, $sale_type, $data['payments'], $data['dinner_table'], $data['taxes']); + $this->sale_lib->set_suspended_id($data['sale_id_num']); + + $data['cart'] = $this->sale_lib->sort_and_filter_cart($data['cart']); + + $data = $this->xss_clean($data); + + $data['barcode'] = NULL; + + $this->load->view('sales/work_order', $data); + $this->sale_lib->clear_mode(); + $this->sale_lib->clear_all(); + } + } elseif($this->sale_lib->is_quote_mode()) { - $invoice_number = NULL; - $quote_number = $this->sale_lib->get_quote_number(); + $data['sales_quote'] = $this->lang->line('sales_quote'); + $data['quote_number_label'] = $this->lang->line('sales_quote_number'); if($quote_number == NULL) { @@ -563,19 +684,18 @@ class Sales extends Secure_Controller $quote_number = $this->token_lib->render($quote_format); } - // TODO If duplicate quote then determine the number of employees and repeat until until success or tried the number of employees (if QSEQ was used). - if($this->Sale->check_quote_number_exists($quote_number)) + if($sale_id == -1 && $this->Sale->check_quote_number_exists($quote_number)) { $data['error'] = $this->lang->line('sales_quote_number_duplicate'); $this->_reload($data); } else { - $data['invoice_number'] = $invoice_number; $data['quote_number'] = $quote_number; $data['sale_status'] = SUSPENDED; + $sale_type = SALE_TYPE_QUOTE; - $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']); + $data['sale_id_num'] = $this->Sale->save($sale_id, $data['sale_status'], $data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $work_order_number, $quote_number, $sale_type, $data['payments'], $data['dinner_table'], $data['taxes']); $this->sale_lib->set_suspended_id($data['sale_id_num']); $data['cart'] = $this->sale_lib->sort_and_filter_cart($data['cart']); @@ -592,8 +712,17 @@ class Sales extends Secure_Controller else { // Save the data to the sales table - $data['sale_status'] = '0'; // Complete - $data['sale_id_num'] = $this->Sale->save($data['sale_status'], $data['cart'], $customer_id, $employee_id, $data['comments'], NULL, NULL, $data['payments'], $data['dinner_table'], $data['taxes']); + $data['sale_status'] = COMPLETED; + if($this->sale_lib->is_return_mode()) + { + $sale_type = SALE_TYPE_RETURN; + } + else + { + $sale_type = SALE_TYPE_POS; + } + + $data['sale_id_num'] = $this->Sale->save($sale_id, $data['sale_status'], $data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $work_order_number, $quote_number, $sale_type, $data['payments'], $data['dinner_table'], $data['taxes']); $data['sale_id'] = 'POS ' . $data['sale_id_num']; @@ -801,6 +930,8 @@ class Sales extends Secure_Controller )); $data['barcode'] = $this->barcode_lib->generate_receipt_barcode($data['sale_id']); $data['print_after_sale'] = FALSE; + $data['price_work_orders'] = FALSE; + if($this->sale_lib->get_mode() == 'sale_invoice') { $data['mode_label'] = $this->lang->line('sales_invoice'); @@ -809,29 +940,26 @@ class Sales extends Secure_Controller { $data['mode_label'] = $this->lang->line('sales_quote'); } + elseif($this->sale_lib->get_mode() == 'sale_work_order') + { + $data['mode_label'] = $this->lang->line('sales_work_order'); + } return $this->xss_clean($data); } private function _reload($data = array()) { + $sale_id = $this->session->userdata('sale_id'); + if($sale_id == '') + { + $sale_id = -1; + $this->session->set_userdata('sale_id', -1); + } $data['cart'] = $this->sale_lib->get_cart(); $customer_info = $this->_load_customer_data($this->sale_lib->get_customer(), $data, TRUE); - if($this->config->item('invoice_enable') == '0') - { - $data['modes'] = array( - 'sale' => $this->lang->line('sales_sale'), - 'return' => $this->lang->line('sales_return')); - } - else - { - $data['modes'] = array( - 'sale' => $this->lang->line('sales_sale'), - 'sale_invoice' => $this->lang->line('sales_sale_by_invoice'), - 'sale_quote' => $this->lang->line('sales_quote'), - 'return' => $this->lang->line('sales_return')); - } + $data['modes'] = $this->sale_lib->get_register_mode_options(); $data['mode'] = $this->sale_lib->get_mode(); $data['empty_tables'] = $this->sale_lib->get_empty_tables(); $data['selected_table'] = $this->sale_lib->get_dinner_table(); @@ -841,6 +969,8 @@ class Sales extends Secure_Controller $data['taxes'] = $this->sale_lib->get_taxes(); $data['discount'] = $this->sale_lib->get_discount(); $data['payments'] = $this->sale_lib->get_payments(); + // sale_type (0=pos, 1=invoice, 2=work order, 3=quote, 4=return + $sale_type = $this->sale_lib->get_sale_type(); // Returns 'subtotal', 'total', 'cash_total', 'payment_total', 'amount_due', 'cash_amount_due', 'payments_cover_total' $totals = $this->sale_lib->get_totals(); @@ -878,11 +1008,6 @@ class Sales extends Secure_Controller { $data['payment_options'] = $this->Sale->get_payment_options(); } - $quote_number = $this->sale_lib->get_quote_number(); - if($quote_number != NULL) - { - $data['quote_number'] = $quote_number; - } $data['items_module_allowed'] = $this->Employee->has_grant('items', $this->Employee->get_logged_in_employee_info()->person_id); @@ -894,8 +1019,13 @@ class Sales extends Secure_Controller $data['invoice_number_enabled'] = $this->sale_lib->is_invoice_mode(); $data['print_after_sale'] = $this->sale_lib->is_print_after_sale(); - $data['quote_or_invoice_mode'] = $data['mode'] == 'sale_invoice' || $data['mode'] == 'sale_quote'; - $data['sales_or_return_mode'] = $data['mode'] == 'sale' || $data['mode'] == 'return'; + $data['price_work_orders'] = $this->sale_lib->is_price_work_orders(); + + $data['pos_mode'] = $data['mode'] == 'sale' || $data['mode'] == 'return'; + + $data['quote_number'] = $this->sale_lib->get_quote_number(); + $data['work_order_number'] = $this->sale_lib->get_work_order_number(); + if($this->sale_lib->get_mode() == 'sale_invoice') { $data['mode_label'] = $this->lang->line('sales_invoice'); @@ -904,6 +1034,10 @@ class Sales extends Secure_Controller { $data['mode_label'] = $this->lang->line('sales_quote'); } + elseif($this->sale_lib->get_mode() == 'sale_work_order') + { + $data['mode_label'] = $this->lang->line('sales_work_order'); + } else { $data['mode_label'] = $this->lang->line('sales_receipt'); @@ -978,70 +1112,33 @@ class Sales extends Secure_Controller } } - public function save($sale_id = -1) + /** + * This is used to cancel a suspended pos sale, quote. + * Completed sales (POS Sales or Invoiced Sales) can not be removed from the system + * Work orders can be canceled but are not physically removed from the sales history + */ + public function cancel() { - $newdate = $this->input->post('date'); - $date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $newdate); - $sale_data = array( - 'sale_time' => $date_formatter->format('Y-m-d H:i:s'), - 'customer_id' => $this->input->post('customer_id') != '' ? $this->input->post('customer_id') : NULL, - 'employee_id' => $this->input->post('employee_id'), - 'comment' => $this->input->post('comment'), - 'invoice_number' => $this->input->post('invoice_number') != '' ? $this->input->post('invoice_number') : NULL - ); - - // go through all the payment type input from the form, make sure the form matches the name and iterator number - $payments = array(); - $number_of_payments = $this->input->post('number_of_payments'); - for($i = 0; $i < $number_of_payments; ++$i) + $sale_id = $this->sale_lib->get_sale_id(); + if($sale_id != -1 && $sale_id != '') { - $payment_amount = $this->input->post('payment_amount_' . $i); - $payment_type = $this->input->post('payment_type_' . $i); - // remove any 0 payment if by mistake any was introduced at sale time - if($payment_amount != 0) + $sale_type = $this->sale_lib->get_sale_type(); + if($sale_type == SALE_TYPE_WORK_ORDER) { - // search for any payment of the same type that was already added, if that's the case add up the new payment amount - $key = FALSE; - if(!empty($payments)) - { - // search in the multi array the key of the entry containing the current payment_type - // NOTE: in PHP5.5 the array_map could be replaced by an array_column - $key = array_search($payment_type, array_map(function ($v) - { - return $v['payment_type']; - }, $payments)); - } - - // if no previous payment is found add a new one - if($key === FALSE) - { - $payments[] = array('payment_type' => $payment_type, 'payment_amount' => $payment_amount); - } - else - { - // add up the new payment amount to an existing payment type - $payments[$key]['payment_amount'] += $payment_amount; - } + $this->Sale->update_sale_status($sale_id, CANCELED); + } + else + { + $this->Sale->delete($sale_id, FALSE); + $this->session->set_userdata('sale_id', -1); } } - if($this->Sale->update($sale_id, $sale_data, $payments)) - { - echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('sales_successfully_updated'), 'id' => $sale_id)); - } - else - { - echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('sales_unsuccessfully_updated'), 'id' => $sale_id)); - } - } - - public function cancel() - { $this->sale_lib->clear_all(); $this->_reload(); } - public function discard_quote() + public function discard_suspended_sale() { $suspended_id = $this->sale_lib->get_suspended_id(); $this->sale_lib->clear_all(); @@ -1049,8 +1146,15 @@ class Sales extends Secure_Controller $this->_reload(); } + /** + * Suspend the current sale. + * If the current sale is already suspended then update the existing suspended sale. + * Otherwise create it as a new suspended sale + */ public function suspend() { + $mode = $this->sale_lib->get_mode(); + $sale_id = $this->sale_lib->get_sale_id(); $dinner_table = $this->sale_lib->get_dinner_table(); $cart = $this->sale_lib->get_cart(); $payments = $this->sale_lib->get_payments(); @@ -1058,13 +1162,20 @@ class Sales extends Secure_Controller $customer_id = $this->sale_lib->get_customer(); $customer_info = $this->Customer->get_info($customer_id); $invoice_number = $this->sale_lib->get_invoice_number(); + $work_order_number = $this->sale_lib->get_work_order_number(); $quote_number = $this->sale_lib->get_quote_number(); + $sale_id = $this->sale_lib->get_sale_id(); + $sale_type = $this->sale_lib->get_sale_type(); + if($sale_type == '') + { + $sale_type = SALE_TYPE_POS; + } $comment = $this->sale_lib->get_comment(); - $sale_status = $this->sale_lib->is_quote_mode() ? QUOTE : SUSPENDED; + $sale_status = SUSPENDED; $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') + if($this->Sale->save($sale_id, $sale_status, $cart, $customer_id, $employee_id, $comment, $invoice_number, $work_order_number, $quote_number, $sale_type, $payments, $dinner_table, $sales_taxes) == '-1') { $data['error'] = $this->lang->line('sales_unsuccessfully_suspended_sale'); } @@ -1077,6 +1188,9 @@ class Sales extends Secure_Controller $this->_reload($data); } + /** + * List suspended sales + */ public function suspended() { $customer_id = $this->sale_lib->get_customer(); @@ -1087,8 +1201,8 @@ class Sales extends Secure_Controller } /* - * We will eventually drop the current set of "suspended" tables since suspended sales - * are now stored in the sales tables with a sale_status value of suspended. + * Unsuspended sales are now left in the tables and are only removed + * when they are intentionally cancelled. */ public function unsuspend() { @@ -1098,9 +1212,11 @@ class Sales extends Secure_Controller if($sale_id > 0) { $this->sale_lib->copy_entire_sale($sale_id); - $this->Sale->delete_suspended_sale($sale_id); } + // Set current register mode to reflect that of unsuspended order type + $this->change_register_mode($this->sale_lib->get_sale_type()); + $this->_reload(); } diff --git a/application/controllers/Secure_Controller.php b/application/controllers/Secure_Controller.php index ad7f18e20..3125ae518 100644 --- a/application/controllers/Secure_Controller.php +++ b/application/controllers/Secure_Controller.php @@ -6,7 +6,7 @@ class Secure_Controller extends CI_Controller * Controllers that are considered secure extend Secure_Controller, optionally a $module_id can * be set to also check if a user can access a particular module in the system. */ - public function __construct($module_id = NULL, $submodule_id = NULL) + public function __construct($module_id = NULL, $submodule_id = NULL, $menu_group = NULL) { parent::__construct(); @@ -28,7 +28,24 @@ class Secure_Controller extends CI_Controller } // load up global data visible to all the loaded views - $data['allowed_modules'] = $this->Module->get_allowed_modules($logged_in_employee_info->person_id); + + $this->load->library('session'); + if($menu_group == NULL) + { + $menu_group = $this->session->userdata('menu_group'); + } + else + { + $this->session->set_userdata('menu_group', $menu_group); + } + if($menu_group == 'home') + { + $data['allowed_modules'] = $this->Module->get_allowed_home_modules($logged_in_employee_info->person_id); + } + else + { + $data['allowed_modules'] = $this->Module->get_allowed_office_modules($logged_in_employee_info->person_id); + } $data['user_info'] = $logged_in_employee_info; $data['controller_name'] = $module_id; diff --git a/application/language/en-GB/config_lang.php b/application/language/en-GB/config_lang.php index e500d2423..1457f97a7 100644 --- a/application/language/en-GB/config_lang.php +++ b/application/language/en-GB/config_lang.php @@ -140,8 +140,9 @@ $lang["config_invoice_enable"] = "Enable Invoicing"; $lang["config_invoice_printer"] = "Invoice Printer"; $lang["config_jsprintsetup_required"] = "Warning! This disabled functionality will only work if you have the FireFox jsPrintSetup addon installed. Save anyway?"; $lang["config_language"] = "Language"; -$lang["config_last_used_invoice_number"] = "Last Used Invoice Number"; -$lang["config_last_used_quote_number"] = "Last Used Quote Number"; +$lang["config_last_used_invoice_number"] = "Last used Invoice Number"; +$lang["config_last_used_quote_number"] = "Last used Quote Number"; +$lang["config_last_used_work_order_number"] = "Last used W/O Number"; $lang["config_left"] = "Left"; $lang["config_license"] = "License"; $lang["config_license_configuration"] = "License Statement"; @@ -225,6 +226,7 @@ $lang["config_sales_invoice_format"] = "Sales Invoice Format"; $lang["config_sales_quote_format"] = "Sales Quote Format"; $lang["config_saved_successfully"] = "Configuration saved successfully"; $lang["config_saved_unsuccessfully"] = "Configuration saved unsuccessfully"; +$lang["config_show_office_group"] = "Show office icon"; $lang["config_statistics"] = "Send Statistics"; $lang["config_statistics_tooltip"] = "Send statistics for development and feature improvement purposes"; $lang["config_stock_location"] = "Stock location"; @@ -245,3 +247,5 @@ $lang["config_thousands_separator"] = "Thousands Separator"; $lang["config_timezone"] = "Timezone"; $lang["config_top"] = "Top"; $lang["config_website"] = "Website"; +$lang["config_work_order_enable"] = "Work Order Support"; +$lang["config_work_order_format"] = "Work Order Format"; diff --git a/application/language/en-GB/module_lang.php b/application/language/en-GB/module_lang.php index fc6b555f7..8ef821048 100644 --- a/application/language/en-GB/module_lang.php +++ b/application/language/en-GB/module_lang.php @@ -1,5 +1,6 @@ $this->CI->lang->line('sales_receipt'), - 'sale_invoice' => $this->CI->lang->line('sales_invoice'), - 'sale_quote' => $this->CI->lang->line('sales_quote') - ); + $register_modes = array(); + if($this->CI->config->item('invoice_enable') == '0') + { + $register_modes['sale'] = $this->CI->lang->line('sales_sale'); + } + else + { + $register_modes['sale'] = $this->CI->lang->line('sales_receipt'); + $register_modes['sale_quote'] = $this->CI->lang->line('sales_quote'); + if($this->CI->config->item('work_order_enable') == '1') + { + $register_modes['sale_work_order'] = $this->CI->lang->line('sales_work_order'); + } + $register_modes['sale_invoice'] = $this->CI->lang->line('sales_invoice'); + } + $register_modes['return'] = $this->CI->lang->line('sales_return'); + return $register_modes; } public function get_cart() @@ -148,6 +160,16 @@ class Sale_lib return $this->CI->session->userdata('sales_quote_number'); } + public function get_work_order_number() + { + return $this->CI->session->userdata('sales_work_order_number'); + } + + public function get_sale_type() + { + return $this->CI->session->userdata('sale_type'); + } + public function set_invoice_number($invoice_number, $keep_custom = FALSE) { $current_invoice_number = $this->CI->session->userdata('sales_invoice_number'); @@ -166,6 +188,24 @@ class Sale_lib } } + public function set_work_order_number($work_order_number, $keep_custom = FALSE) + { + $current_work_order_number = $this->CI->session->userdata('sales_work_order_number'); + if(!$keep_custom || empty($current_work_order_number)) + { + $this->CI->session->set_userdata('sales_work_order_number', $work_order_number); + } + } + + public function set_sale_type($sale_type, $keep_custom = FALSE) + { + $current_sale_type = $this->CI->session->userdata('sale_type'); + if(!$keep_custom || empty($current_sale_type)) + { + $this->CI->session->set_userdata('sale_type', $sale_type); + } + } + public function clear_invoice_number() { $this->CI->session->unset_userdata('sales_invoice_number'); @@ -176,6 +216,11 @@ class Sale_lib $this->CI->session->unset_userdata('sales_quote_number'); } + public function clear_sale_type() + { + $this->CI->session->unset_userdata('sale_type'); + } + public function set_suspended_id($suspended_id) { $this->CI->session->set_userdata('suspended_id', $suspended_id); @@ -204,6 +249,16 @@ class Sale_lib return ($this->CI->session->userdata('sales_mode') == 'sale_quote'); } + public function is_return_mode() + { + return ($this->CI->session->userdata('sales_mode') == 'return'); + } + + public function is_work_order_mode() + { + return ($this->CI->session->userdata('sales_mode') == 'sale_work_order'); + } + public function set_invoice_number_enabled($invoice_number_enabled) { return $this->CI->session->set_userdata('sales_invoice_number_enabled', $invoice_number_enabled); @@ -215,11 +270,22 @@ class Sale_lib $this->CI->session->userdata('sales_print_after_sale') == '1'); } + public function is_price_work_orders() + { + return ($this->CI->session->userdata('sales_price_work_orders') == 'true' || + $this->CI->session->userdata('sales_price_work_orders') == '1'); + } + public function set_print_after_sale($print_after_sale) { return $this->CI->session->set_userdata('sales_print_after_sale', $print_after_sale); } + public function set_price_work_orders($price_work_orders) + { + return $this->CI->session->set_userdata('sales_price_work_orders', $price_work_orders); + } + public function get_email_receipt() { return $this->CI->session->userdata('sales_email_receipt'); @@ -380,7 +446,6 @@ class Sale_lib { $cash_total = $total; $totals['cash_total'] = $cash_total; - } $payment_total = $this->get_payments_total(); @@ -862,8 +927,14 @@ class Sale_lib $this->set_customer($this->CI->Sale->get_customer($sale_id)->person_id); $this->set_employee($this->CI->Sale->get_employee($sale_id)->person_id); $this->set_quote_number($this->CI->Sale->get_quote_number($sale_id)); + $this->set_sale_type($this->CI->Sale->get_sale_type($sale_id)); $this->set_comment($this->CI->Sale->get_comment($sale_id)); $this->set_dinner_table($this->CI->Sale->get_dinner_table($sale_id)); + $this->CI->session->set_userdata('sale_id', $sale_id); + } + + public function get_sale_id() { + return $this->CI->session->userdata('sale_id'); } public function get_cart_reordered($sale_id) @@ -880,6 +951,7 @@ class Sale_lib public function clear_all() { + $this->CI->session->set_userdata('sale_id', -1); $this->set_invoice_number_enabled(FALSE); $this->clear_table(); $this->empty_cart(); @@ -887,6 +959,7 @@ class Sale_lib $this->clear_email_receipt(); $this->clear_invoice_number(); $this->clear_quote_number(); + $this->clear_sale_type(); $this->clear_giftcard_remainder(); $this->empty_payments(); $this->remove_customer(); diff --git a/application/libraries/tokens/Token.php b/application/libraries/tokens/Token.php index 06697e712..2d4874409 100644 --- a/application/libraries/tokens/Token.php +++ b/application/libraries/tokens/Token.php @@ -5,6 +5,7 @@ require_once(APPPATH . 'libraries/tokens/Token_customer.php'); require_once(APPPATH . 'libraries/tokens/Token_invoice_count.php'); require_once(APPPATH . 'libraries/tokens/Token_invoice_sequence.php'); require_once(APPPATH . 'libraries/tokens/Token_quote_sequence.php'); +require_once(APPPATH . 'libraries/tokens/Token_work_order_sequence.php'); require_once(APPPATH . 'libraries/tokens/Token_suspended_invoice_count.php'); require_once(APPPATH . 'libraries/tokens/Token_year_invoice_count.php'); @@ -27,7 +28,8 @@ abstract class Token static function get_tokens() { return array(new Token_customer(), new Token_invoice_count(), new Token_invoice_sequence(), - new Token_quote_sequence(), new Token_suspended_invoice_count(), new Token_quote_sequence(), new Token_year_invoice_count()); + new Token_quote_sequence(), new Token_suspended_invoice_count(), new Token_quote_sequence(), + new Token_work_order_sequence(), new Token_year_invoice_count()); } abstract public function token_id(); diff --git a/application/libraries/tokens/Token_work_order_sequence.php b/application/libraries/tokens/Token_work_order_sequence.php new file mode 100644 index 000000000..9405902bf --- /dev/null +++ b/application/libraries/tokens/Token_work_order_sequence.php @@ -0,0 +1,19 @@ +CI->Appconfig->acquire_save_next_work_order_sequence(); + } +} +?> diff --git a/application/models/Appconfig.php b/application/models/Appconfig.php index 58d01604d..09cfef6ef 100644 --- a/application/models/Appconfig.php +++ b/application/models/Appconfig.php @@ -93,5 +93,12 @@ class Appconfig extends CI_Model $this->save('last_used_quote_number', $last_used); return $last_used; } + + public function acquire_save_next_work_order_sequence() + { + $last_used = $this->get('last_used_work_order_number') + 1; + $this->save('last_used_work_order_number', $last_used); + return $last_used; + } } ?> diff --git a/application/models/Employee.php b/application/models/Employee.php index b51d9689d..213521d4d 100644 --- a/application/models/Employee.php +++ b/application/models/Employee.php @@ -119,9 +119,11 @@ class Employee extends Person //Now insert the new grants if($success) { - foreach($grants_data as $permission_id) + $count = 0; + foreach($grants_data as $grant) { - $success = $this->db->insert('grants', array('permission_id' => $permission_id, 'person_id' => $employee_id)); + $success = $this->db->insert('grants', array('permission_id' => $grant['permission_id'], 'person_id' => $employee_id, 'menu_group' => $grant['menu_group'])); + $count = $count+ 1; } } } @@ -390,9 +392,9 @@ class Employee extends Person return ($this->db->get()->num_rows() == 0); } - /* - Determines whether the employee specified employee has access the specific module. - */ + /** + * Determines whether the employee specified employee has access the specific module. + */ public function has_grant($permission_id, $person_id) { //if no module_id is null, allow access @@ -406,9 +408,32 @@ class Employee extends Person return ($query->num_rows() == 1); } - /* - Gets employee permission grants - */ + /** + * Returns the menu group designation that this module is to appear in + */ + public function get_menu_group($permission_id, $person_id) + { + $this->db->select('menu_group'); + $this->db->from('grants'); + $this->db->where('permission_id', $permission_id); + $this->db->where('person_id', $person_id); + + $row = $this->db->get()->row(); + + // If no grants are assigned yet then set the default to 'home' + if ($row == null) + { + return "home"; + } + else + { + return $row->menu_group; + } + } + + /* + Gets employee permission grants + */ public function get_employee_grants($person_id) { $this->db->from('grants'); diff --git a/application/models/Module.php b/application/models/Module.php index 09edd4d6a..1b95375c7 100644 --- a/application/models/Module.php +++ b/application/models/Module.php @@ -6,6 +6,11 @@ class Module extends CI_Model { + function __construct() + { + parent::__construct(); + } + public function get_module_name($module_id) { $query = $this->db->get_where('modules', array('module_id' => $module_id), 1); @@ -55,19 +60,69 @@ class Module extends CI_Model { $this->db->from('modules'); $this->db->order_by('sort', 'asc'); - return $this->db->get(); } - public function get_allowed_modules($person_id) + public function get_allowed_home_modules($person_id) { + $menus = array('home', 'both'); $this->db->from('modules'); $this->db->join('permissions', 'permissions.permission_id = modules.module_id'); $this->db->join('grants', 'permissions.permission_id = grants.permission_id'); $this->db->where('person_id', $person_id); + $this->db->where_in('menu_group', $menus); + $this->db->where('sort !=', 0); $this->db->order_by('sort', 'asc'); - return $this->db->get(); } + + public function get_allowed_office_modules($person_id) + { + $menus = array('office', 'both'); + $this->db->from('modules'); + $this->db->join('permissions', 'permissions.permission_id = modules.module_id'); + $this->db->join('grants', 'permissions.permission_id = grants.permission_id'); + $this->db->where('person_id', $person_id); + $this->db->where_in('menu_group', $menus); + $this->db->where('sort !=', 0); + $this->db->order_by('sort', 'asc'); + return $this->db->get(); + } + + /** + * This method is used to set the show the office navigation icon on the home page + * which happens when the sort value is greater than zero + */ + public function set_show_office_group($show_office_group) + { + if($show_office_group) + { + $sort = 1; + } + else + { + $sort = 0; + } + + $modules_data = array( + 'sort' => $sort + ); + $this->db->where('module_id', 'office'); + $this->db->update('modules', $modules_data); + } + + /** + * This method is used to show the office navigation icon on the home page + * which happens when the sort value is greater than zero + */ + public function get_show_office_group() + { + $this->db->select('sort'); + $this->db->from('grants'); + $this->db->where('module_id', 'office'); + $this->db->from('modules'); + return $this->db->get()->row()->sort; + } + } ?> diff --git a/application/models/Sale.php b/application/models/Sale.php index 52378f889..3cab08104 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -2,7 +2,13 @@ define('COMPLETED', 0); define('SUSPENDED', 1); -define('QUOTE', 2); +define('CANCELED', 2); + +define('SALE_TYPE_POS', 0); +define('SALE_TYPE_INVOICE', 1); +define('SALE_TYPE_WORK_ORDER', 2); +define('SALE_TYPE_QUOTE', 3); +define('SALE_TYPE_RETURN', 4); /** * Sale class @@ -537,8 +543,13 @@ class Sale extends CI_Model * Save the sale information after the sales is complete but before the final document is printed * The sales_taxes variable needs to be initialized to an empty array before calling */ - public function save(&$sale_status, &$items, $customer_id, $employee_id, $comment, $invoice_number, $quote_number, $payments, $dinner_table, &$sales_taxes, $sale_id = FALSE) + public function save($sale_id, &$sale_status, &$items, $customer_id, $employee_id, $comment, $invoice_number, $work_order_number, $quote_number, $sale_type, $payments, $dinner_table, &$sales_taxes) { + if($sale_id != -1) + { + $this->clear_suspended_sale_detail($sale_id); + } + $tax_decimals = tax_decimals(); if(count($items) == 0) @@ -549,22 +560,32 @@ class Sale extends CI_Model $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, - 'sale_status' => $sale_status + '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, + 'work_order_number' => $work_order_number, + 'dinner_table_id' => $dinner_table, + 'sale_status' => $sale_status, + 'sale_type' => $sale_type ); // Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); - $this->db->insert('sales', $sales_data); - $sale_id = $this->db->insert_id(); + if($sale_id == -1) + { + $this->db->insert('sales', $sales_data); + $sale_id = $this->db->insert_id(); + } + else + { + $this->db->where('sale_id', $sale_id); + $this->db->update('sales', $sales_data); + } $total_amount = 0; $total_amount_used = 0; foreach($payments as $payment_id=>$payment) @@ -800,19 +821,16 @@ class Sale extends CI_Model } /** - * Delete sale + * Delete sale. Hard deletes are not supported for sales transactions. + * When a sale is "deleted" it is simply changed to a status of canceled. + * However, if applicable the inventory still needs to be updated */ public function delete($sale_id, $employee_id, $update_inventory = TRUE) { // start a transaction to assure data integrity $this->db->trans_start(); - // first delete all payments - $this->db->delete('sales_payments', array('sale_id' => $sale_id)); - // then delete all taxes on items - $this->db->delete('sales_items_taxes', array('sale_id' => $sale_id)); - - if($update_inventory) + if($update_inventory && $sale_status = $this->get_sale_status($sale_id) == COMPLETED) { // defect, not all item deletions will be undone?? // get array with all the items involved in the sale to update the inventory tracking @@ -840,10 +858,8 @@ class Sale extends CI_Model } } - // delete all items - $this->db->delete('sales_items', array('sale_id' => $sale_id)); - // delete sale itself - $this->db->delete('sales', array('sale_id' => $sale_id)); + // Set the status of the sale to canceled + $this->update_sale_status($sale_id, CANCELED); // execute transaction $this->db->trans_complete(); @@ -965,6 +981,12 @@ class Sale extends CI_Model $payments[$this->lang->line('sales_rewards')] = $this->lang->line('sales_rewards'); } + if($this->sale_lib->get_mode() == 'sale_work_order') + { + $payments[$this->lang->line('sales_cash_deposit')] = $this->lang->line('sales_cash_deposit'); + $payments[$this->lang->line('sales_credit_deposit')] = $this->lang->line('sales_credit_deposit'); + } + return $payments; } @@ -1021,6 +1043,21 @@ class Sale extends CI_Model return ($this->db->get()->num_rows() == 1); } + /** + * Checks if work order number exists + */ + public function check_work_order_number_exists($work_order_number, $sale_id = '') + { + $this->db->from('sales'); + $this->db->where('invoice_number', $work_order_number); + if(!empty($sale_id)) + { + $this->db->where('sale_id !=', $sale_id); + } + + return ($this->db->get()->num_rows() == 1); + } + /** * Gets Giftcard value */ @@ -1117,6 +1154,7 @@ class Sale extends CI_Model MAX(sales.sale_time) AS sale_time, sales.sale_id AS sale_id, MAX(sales.sale_status) AS sale_status, + MAX(sales.sale_type) AS sale_type, MAX(sales.comment) AS comment, MAX(sales.invoice_number) AS invoice_number, MAX(sales.quote_number) AS quote_number, @@ -1184,12 +1222,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 ' + $query = $this->db->query("select sale_id, case when sale_type = '".SALE_TYPE_QUOTE."' then quote_number when sale_type = '".SALE_TYPE_WORK_ORDER."' then work_order_number else sale_id end as doc_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 = ' . SUSPENDED); } else { - $query = $this->db->query('select sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from ' + $query = $this->db->query("select sale_id, case when sale_type = '".SALE_TYPE_QUOTE."' then quote_number when sale_type = '".SALE_TYPE_WORK_ORDER."' then work_order_number else sale_id end as doc_id, sale_status, sale_time, dinner_table_id, customer_id, comment from " . $this->db->dbprefix('sales') . ' where sale_status = '. SUSPENDED .' AND customer_id = ' . $customer_id); } @@ -1202,12 +1240,45 @@ class Sale extends CI_Model */ public function get_dinner_table($sale_id) { + if($sale_id == -1) + { + return NULL; + } $this->db->from('sales'); $this->db->where('sale_id', $sale_id); return $this->db->get()->row()->dinner_table_id; } + /** + * Gets the sale type for the selected sale + */ + public function get_sale_type($sale_id) + { + $this->db->from('sales'); + $this->db->where('sale_id', $sale_id); + + return $this->db->get()->row()->sale_type; + } + + /** + * Gets the sale status for the selected sale + */ + public function get_sale_status($sale_id) + { + $this->db->from('sales'); + $this->db->where('sale_id', $sale_id); + + return $this->db->get()->row()->sale_status; + } + + public function update_sale_status($sale_id, $sale_status) + { + $this->db->where('sale_id', $sale_id); + $this->db->update('sales', array('sale_status'=>$sale_status)); + } + + /** * Gets the quote_number for the selected sale */ @@ -1277,17 +1348,38 @@ class Sale extends CI_Model $this->db->where('dinner_table_id',$dinner_table); $this->db->update('dinner_tables', $dinner_table_data); - $this->db->delete('sales_payments', array('sale_id' => $sale_id)); - $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' => SUSPENDED)); + $this->update_sale_status($sale_id, CANCELED); $this->db->trans_complete(); return $this->db->trans_status(); } + /** + * This clears the sales detail for a given sale_id before the detail is resaved. + * This allows us to reuse the same sale_id + */ + public function clear_suspended_sale_detail($sale_id) + { + $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_payments', array('sale_id' => $sale_id)); + $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->trans_complete(); + + return $this->db->trans_status(); + } /** * Gets suspended sale info */ diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index d295ef10d..e247ae9c1 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -15,6 +15,7 @@ class Detailed_sales extends Report return array( 'summary' => array( array('id' => $this->lang->line('reports_sale_id')), + array('type_code' => $this->lang->line('reports_code_type')), array('sale_date' => $this->lang->line('reports_date')), array('quantity' => $this->lang->line('reports_quantity')), array('employee_name' => $this->lang->line('reports_sold_by')), @@ -66,7 +67,15 @@ class Detailed_sales extends Report public function getData(array $inputs) { - $this->db->select('sale_id, + $this->db->select('sale_id, + MAX(CASE + WHEN sale_type = ' . SALE_TYPE_INVOICE . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_invoice') . '\' + WHEN sale_type = ' . SALE_TYPE_WORK_ORDER . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_work_order') . '\' + WHEN sale_type = ' . SALE_TYPE_QUOTE . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_quote') . '\' + WHEN sale_type = ' . SALE_TYPE_RETURN . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_return') . '\' + WHEN sale_status = ' . CANCELED . ' THEN \'' . $this->lang->line('reports_code_canceled') . '\' + ELSE \'\' + END) AS type_code, MAX(sale_status) as sale_status, MAX(sale_date) AS sale_date, SUM(quantity_purchased) AS items_purchased, @@ -86,21 +95,41 @@ class Detailed_sales extends Report $this->db->where('item_location', $inputs['location_id']); } - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = '. COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } $this->db->group_by('sale_id'); @@ -136,21 +165,41 @@ class Detailed_sales extends Report $this->db->where('item_location', $inputs['location_id']); } - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Specific_customer.php b/application/models/reports/Specific_customer.php index 2ce8e31e9..ba33c3933 100644 --- a/application/models/reports/Specific_customer.php +++ b/application/models/reports/Specific_customer.php @@ -15,6 +15,7 @@ class Specific_customer extends Report return array( 'summary' => array( array('id' => $this->lang->line('reports_sale_id')), + array('type_code' => $this->lang->line('reports_code_type')), array('sale_date' => $this->lang->line('reports_date')), array('quantity' => $this->lang->line('reports_quantity')), array('employee_name' => $this->lang->line('reports_sold_by')), @@ -46,6 +47,14 @@ class Specific_customer extends Report public function getData(array $inputs) { $this->db->select('sale_id, + MAX(CASE + WHEN sale_type = ' . SALE_TYPE_INVOICE . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_invoice') . '\' + WHEN sale_type = ' . SALE_TYPE_WORK_ORDER . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_work_order') . '\' + WHEN sale_type = ' . SALE_TYPE_QUOTE . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_quote') . '\' + WHEN sale_type = ' . SALE_TYPE_RETURN . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_return') . '\' + WHEN sale_status = ' . CANCELED . ' THEN \'' . $this->lang->line('reports_code_canceled') . '\' + ELSE \'\' + END) AS type_code, MAX(sale_date) AS sale_date, SUM(quantity_purchased) AS items_purchased, MAX(employee_name) AS employee_name, @@ -59,21 +68,41 @@ class Specific_customer extends Report $this->db->from('sales_items_temp'); $this->db->where('customer_id', $inputs['customer_id']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } $this->db->group_by('sale_id'); @@ -105,21 +134,41 @@ class Specific_customer extends Report $this->db->from('sales_items_temp'); $this->db->where('customer_id', $inputs['customer_id']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index d42ba8055..c2291ebb5 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -15,6 +15,7 @@ class Specific_discount extends Report return array( 'summary' => array( array('id' => $this->lang->line('reports_sale_id')), + array('type_code' => $this->lang->line('reports_code_type')), array('sale_date' => $this->lang->line('reports_date')), array('quantity' => $this->lang->line('reports_quantity')), array('customer_name' => $this->lang->line('reports_sold_to')), @@ -44,6 +45,14 @@ class Specific_discount extends Report public function getData(array $inputs) { $this->db->select('sale_id, + MAX(CASE + WHEN sale_type = ' . SALE_TYPE_INVOICE . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_invoice') . '\' + WHEN sale_type = ' . SALE_TYPE_WORK_ORDER . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_work_order') . '\' + WHEN sale_type = ' . SALE_TYPE_QUOTE . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_quote') . '\' + WHEN sale_type = ' . SALE_TYPE_RETURN . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_return') . '\' + WHEN sale_status = ' . CANCELED . ' THEN \'' . $this->lang->line('reports_code_canceled') . '\' + ELSE \'\' + END) AS type_code, MAX(sale_date) AS sale_date, SUM(quantity_purchased) AS items_purchased, MAX(customer_name) AS customer_name, @@ -57,21 +66,41 @@ class Specific_discount extends Report $this->db->from('sales_items_temp'); $this->db->where('discount_percent >=', $inputs['discount']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } $this->db->group_by('sale_id'); @@ -103,21 +132,41 @@ class Specific_discount extends Report $this->db->from('sales_items_temp'); $this->db->where('discount_percent >=', $inputs['discount']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 5eace2d21..f0e83f80f 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -15,6 +15,7 @@ class Specific_employee extends Report return array( 'summary' => array( array('id' => $this->lang->line('reports_sale_id')), + array('type_code' => $this->lang->line('reports_code_type')), array('sale_date' => $this->lang->line('reports_date')), array('quantity' => $this->lang->line('reports_quantity')), array('customer_name' => $this->lang->line('reports_sold_to')), @@ -46,6 +47,14 @@ class Specific_employee extends Report public function getData(array $inputs) { $this->db->select('sale_id, + MAX(CASE + WHEN sale_type = ' . SALE_TYPE_INVOICE . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_invoice') . '\' + WHEN sale_type = ' . SALE_TYPE_WORK_ORDER . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_work_order') . '\' + WHEN sale_type = ' . SALE_TYPE_QUOTE . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_quote') . '\' + WHEN sale_type = ' . SALE_TYPE_RETURN . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_return') . '\' + WHEN sale_status = ' . CANCELED . ' THEN \'' . $this->lang->line('reports_code_canceled') . '\' + ELSE \'\' + END) AS type_code, MAX(sale_date) AS sale_date, SUM(quantity_purchased) AS items_purchased, MAX(customer_name) AS customer_name, @@ -59,21 +68,41 @@ class Specific_employee extends Report $this->db->from('sales_items_temp'); $this->db->where('employee_id', $inputs['employee_id']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } $this->db->group_by('sale_id'); @@ -105,21 +134,41 @@ class Specific_employee extends Report $this->db->from('sales_items_temp'); $this->db->where('employee_id', $inputs['employee_id']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Summary_report.php b/application/models/reports/Summary_report.php index 1dd464edd..92392a15c 100644 --- a/application/models/reports/Summary_report.php +++ b/application/models/reports/Summary_report.php @@ -90,21 +90,41 @@ abstract class Summary_report extends Report $this->db->where('sales_items.item_location', $inputs['location_id']); } - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } diff --git a/application/views/configs/general_config.php b/application/views/configs/general_config.php index 1b179cf5c..86bc5a8c0 100644 --- a/application/views/configs/general_config.php +++ b/application/views/configs/general_config.php @@ -94,7 +94,7 @@
| lang->line('sales_suspended_sale_id'); ?> | +lang->line('sales_suspended_doc_id'); ?> | lang->line('sales_date'); ?> | config->item('dinner_table_enable') == TRUE) @@ -22,7 +22,7 @@ { ?>||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| + | config->item('dateformat'), strtotime($suspended_sale['sale_time']));?> | config->item('dinner_table_enable') == TRUE) @@ -50,7 +50,7 @@
diff --git a/application/views/sales/work_order.php b/application/views/sales/work_order.php
new file mode 100644
index 000000000..6dc578a5c
--- /dev/null
+++ b/application/views/sales/work_order.php
@@ -0,0 +1,213 @@
+load->view("partial/header"); ?>
+
+".$error_message."";
+ exit;
+}
+?>
+
+
+
+
+
+load->view('partial/print_receipt', array('print_after_sale'=>$print_after_sale, 'selected_printer'=>'invoice_printer')); ?>
+
+
+
+
+ ' . $this->lang->line('common_print'); ?>
+  ' . $this->lang->line('common_print'), array('class'=>'btn btn-info btn-sm', 'id'=>'show_print_button', 'onclick'=>'window.print();')); */ ?>
+
+  ' . $this->lang->line('sales_send_work_order'); ?>
+
+  ' . $this->lang->line('sales_register'), array('class'=>'btn btn-info btn-sm', 'id'=>'show_sales_button')); ?>
+  ' . $this->lang->line('sales_discard'), array('class'=>'btn btn-danger btn-sm', 'id'=>'discard_work_order_button')); ?>
+
+
+
+
+
+
+load->view("partial/footer"); ?>
diff --git a/application/views/sales/work_order_email.php b/application/views/sales/work_order_email.php
new file mode 100644
index 000000000..39c920609
--- /dev/null
+++ b/application/views/sales/work_order_email.php
@@ -0,0 +1,128 @@
+
+
+
+
+
+
+
+
+".$error_message."";
+ exit;
+}
+?>
+
+
+
+
+
+
+
+
+
+
+
+ Appconfig->get('company_logo') != '')
+ {
+ ?>
+
+  
+ Appconfig->get('receipt_show_company_name'))
+ {
+ ?>
+ config->item('company'); ?>
+
+
+
+
+
+
+
+
+
+
diff --git a/bower.json b/bower.json
index d96839b54..ee7a94a98 100644
--- a/bower.json
+++ b/bower.json
@@ -1,7 +1,7 @@
{
"name": "opensourcepos",
"description": "Open Source Point of Sale is a web based POS system written in the PHP language. It uses MySQL as backend and has a simple user interface",
- "version": "3.1.1",
+ "version": "3.2.0",
"license": "MIT",
"authors": [
"jekkos lang->line('sales_work_order'); ?>
+
+
+
+
+
+
+ config->item('return_policy')); ?>
+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||