From 36d549cb9ba43a46e45a8081bbb7f7b99c2e80dd Mon Sep 17 00:00:00 2001 From: Steve Ireland Date: Sat, 2 Sep 2017 13:31:33 -0400 Subject: [PATCH] Add support for Work Orders --- application/controllers/Config.php | 5 +- application/controllers/Sales.php | 301 ++++++++++++------ application/language/en-US/config_lang.php | 3 + application/language/en-US/sales_lang.php | 13 +- application/libraries/Sale_lib.php | 80 ++++- application/libraries/tokens/Token.php | 4 +- .../tokens/Token_work_order_sequence.php | 19 ++ application/models/Appconfig.php | 7 + application/models/Sale.php | 158 +++++++-- application/views/configs/invoice_config.php | 124 +++++--- application/views/sales/quote.php | 2 +- application/views/sales/register.php | 28 +- application/views/sales/suspended.php | 6 +- application/views/sales/work_order.php | 213 +++++++++++++ application/views/sales/work_order_email.php | 128 ++++++++ database/3.1.0_work_orders.sql | 22 ++ database/database.sql | 9 +- database/tables.sql | 8 +- 18 files changed, 943 insertions(+), 187 deletions(-) create mode 100644 application/libraries/tokens/Token_work_order_sequence.php create mode 100644 application/views/sales/work_order.php create mode 100644 application/views/sales/work_order_email.php create mode 100644 database/3.1.0_work_orders.sql diff --git a/application/controllers/Config.php b/application/controllers/Config.php index fce888253..dc0bc8b17 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -844,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/Sales.php b/application/controllers/Sales.php index 46cabc6d5..98f5ab48c 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,30 @@ 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'); + } + else + { + $this->sale_lib->set_mode('sale'); + } + } + public function set_comment() { $this->sale_lib->set_comment($this->input->post('comment')); @@ -189,6 +236,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 +495,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 +517,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 +560,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 +589,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 +602,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 +625,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 +680,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 +708,10 @@ 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; + $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 +919,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 +929,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 +958,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 +997,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 +1008,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 +1023,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 +1101,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 +1135,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 +1151,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 +1177,9 @@ class Sales extends Secure_Controller $this->_reload($data); } + /** + * List suspended sales + */ public function suspended() { $customer_id = $this->sale_lib->get_customer(); @@ -1087,8 +1190,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 +1201,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/language/en-US/config_lang.php b/application/language/en-US/config_lang.php index 3b028986c..7ad7bcbf8 100644 --- a/application/language/en-US/config_lang.php +++ b/application/language/en-US/config_lang.php @@ -142,6 +142,7 @@ $lang["config_jsprintsetup_required"] = "Warning: This functionality will only w $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_work_order_number"] = "Last Used W/O Number"; $lang["config_left"] = "Left"; $lang["config_license"] = "License"; $lang["config_license_configuration"] = "License Statement"; @@ -222,6 +223,7 @@ $lang["config_reward"] = "Reward"; $lang["config_reward_configuration"] = "Reward Configuration"; $lang["config_right"] = "Right"; $lang["config_sales_invoice_format"] = "Sales Invoice Format"; +$lang["config_work_order_format"] = "Work Order Format"; $lang["config_sales_quote_format"] = "Sales Quote Format"; $lang["config_saved_successfully"] = "Configuration save successful."; $lang["config_saved_unsuccessfully"] = "Configuration save failed."; @@ -246,3 +248,4 @@ $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"; diff --git a/application/language/en-US/sales_lang.php b/application/language/en-US/sales_lang.php index dbb022d4e..2efbe6066 100644 --- a/application/language/en-US/sales_lang.php +++ b/application/language/en-US/sales_lang.php @@ -8,6 +8,7 @@ $lang["sales_amount_due"] = "Amount Due"; $lang["sales_amount_tendered"] = "Amount Tendered"; $lang["sales_cancel_sale"] = "Cancel"; $lang["sales_cash"] = "Cash"; +$lang["sales_cash_deposit"] = "Cash Deposit"; $lang["sales_cash_filter"] = "Cash"; $lang["sales_change_due"] = "Change Due"; $lang["sales_check"] = "Check"; @@ -19,6 +20,7 @@ $lang["sales_complete_sale"] = "Complete"; $lang["sales_confirm_cancel_sale"] = "Are you sure you want to clear this sale? All items will cleared."; $lang["sales_confirm_delete"] = "Are you sure you want to delete the selected Sale(s)?"; $lang["sales_credit"] = "Credit Card"; +$lang["sales_credit_deposit"] = "Credit Deposit"; $lang["sales_customer"] = "Name"; $lang["sales_customer_address"] = "Address"; $lang["sales_customer_discount"] = "Discount"; @@ -36,7 +38,7 @@ $lang["sales_delete_entire_sale"] = "Delete Entire Sale"; $lang["sales_delete_successful"] = "Sale delete successful."; $lang["sales_delete_unsuccessful"] = "Sale delete failed."; $lang["sales_description_abbrv"] = "Desc."; -$lang["sales_discard_quote"] = "Discard"; +$lang["sales_discard"] = "Discard"; $lang["sales_discount"] = "Disc %"; $lang["sales_discount_included"] = "% Discount"; $lang["sales_discount_short"] = "%"; @@ -57,6 +59,7 @@ $lang["sales_giftcard_number"] = "Gift Card Number"; $lang["sales_group_by_category"] = "Group by Category"; $lang["sales_group_by_type"] = "Group by Type"; $lang["sales_id"] = "Sale ID"; +$lang["sales_include_prices"] = "Include Prices?"; $lang["sales_invoice"] = "Invoice"; $lang["sales_invoice_confirm"] = "This invoice will be sent to"; $lang["sales_invoice_enable"] = "Create Invoice"; @@ -94,6 +97,7 @@ $lang["sales_quantity_less_than_reorder_level"] = "Warning: Desired Quantity is $lang["sales_quantity_less_than_zero"] = "Warning: Desired Quantity is insufficient. You can still process the sale, but audit your inventory."; $lang["sales_quote"] = "Quote"; $lang["sales_quote_number"] = "Quote Number"; +$lang["sales_quote_number_duplicate"] = "Quote Number must be unique."; $lang["sales_quote_sent"] = "Quote sent to"; $lang["sales_quote_unsent"] = "Quote failed to be sent to"; $lang["sales_receipt"] = "Sales Receipt"; @@ -114,6 +118,7 @@ $lang["sales_select_customer"] = "Select Customer (Optional)"; $lang["sales_send_invoice"] = "Send Invoice"; $lang["sales_send_quote"] = "Send Quote"; $lang["sales_send_receipt"] = "Send Receipt"; +$lang["sales_send_work_order"] = "Send Work Order"; $lang["sales_serial"] = "Serial"; $lang["sales_show_invoice"] = "Show Invoice"; $lang["sales_show_receipt"] = "Show Receipt"; @@ -125,6 +130,7 @@ $lang["sales_successfully_deleted"] = "You have successfully deleted"; $lang["sales_successfully_suspended_sale"] = "Sale suspend successful."; $lang["sales_successfully_updated"] = "Sale update successful."; $lang["sales_suspend_sale"] = "Suspend"; +$lang["sales_suspended_doc_id"] = "Document"; $lang["sales_suspended_sale_id"] = "ID"; $lang["sales_suspended_sales"] = "Suspended"; $lang["sales_table"] = "Table"; @@ -141,3 +147,8 @@ $lang["sales_unsuccessfully_updated"] = "Sale update failed."; $lang["sales_unsuspend"] = "Unsuspend"; $lang["sales_unsuspend_and_delete"] = "Action"; $lang["sales_update"] = "Update"; +$lang["sales_work_order"] = "Work Order"; +$lang["sales_work_order_number"] = "Work Order Number"; +$lang["sales_work_order_number_duplicate"] = "The Work Order Number is a duplicate"; +$lang["sales_work_order_sent"] = "Work Order sent to"; +$lang["sales_work_order_unsent"] = "Work Order failed to be sent to"; diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 4166f9057..bd58aae77 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -28,11 +28,23 @@ class Sale_lib public function get_register_mode_options() { - return array( - 'sale' => $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,11 @@ class Sale_lib return ($this->CI->session->userdata('sales_mode') == 'sale_quote'); } + 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 +265,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 +441,6 @@ class Sale_lib { $cash_total = $total; $totals['cash_total'] = $cash_total; - } $payment_total = $this->get_payments_total(); @@ -862,8 +922,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 +946,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 +954,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/Sale.php b/application/models/Sale.php index 52378f889..39d3ee513 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,15 @@ 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) { + + error_log('>>>save sale_id-' . $sale_id . ', sale_type-' . $sale_type); + if($sale_id != -1) + { + $this->clear_suspended_sale_detail($sale_id); + } + $tax_decimals = tax_decimals(); if(count($items) == 0) @@ -549,22 +562,34 @@ 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(); + error_log('>>> sales_data-' . print_r($sales_data, true)); + error_log('>>> sales_id-' . $sale_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 +825,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 +862,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 +985,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 +1047,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 */ @@ -1184,12 +1225,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 +1243,46 @@ class Sale extends CI_Model */ public function get_dinner_table($sale_id) { + if($sale_id == -1) + { + return NULL; + } + error_log('>>>get_dinner_table sale_id-'.$sale_id); $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 +1352,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/views/configs/invoice_config.php b/application/views/configs/invoice_config.php index 0a8d71a97..fc7cc20c1 100644 --- a/application/views/configs/invoice_config.php +++ b/application/views/configs/invoice_config.php @@ -15,36 +15,14 @@ -
+
lang->line('config_register_mode_default'), 'default_register_mode', array('class' => 'control-label col-xs-2')); ?> -
- config->item('default_register_mode'), array('class' => 'form-control input-sm')); ?> -
-
- -
- lang->line('config_sales_invoice_format'), 'sales_invoice_format', array('class' => 'control-label col-xs-2')); ?>
- 'sales_invoice_format', - 'id' => 'sales_invoice_format', - 'class' => 'form-control input-sm', - 'value' => $this->config->item('sales_invoice_format'))); ?> + config->item('default_register_mode'), array('class' => 'form-control input-sm')); ?>
-
- lang->line('config_sales_quote_format'), 'sales_quote_format', array('class' => 'control-label col-xs-2')); ?> -
- 'sales_quote_format', - 'id' => 'sales_quote_format', - 'class' => 'form-control input-sm', - 'value' => $this->config->item('sales_quote_format'))); ?> -
-
- -
+
lang->line('config_recv_invoice_format'), 'recv_invoice_format', array('class' => 'control-label col-xs-2')); ?>
-
+
+ lang->line('config_sales_invoice_format'), 'sales_invoice_format', array('class' => 'control-label col-xs-2')); ?> +
+ 'sales_invoice_format', + 'id' => 'sales_invoice_format', + 'class' => 'form-control input-sm', + 'value' => $this->config->item('sales_invoice_format'))); ?> +
+
+ +
lang->line('config_last_used_invoice_number'), 'last_used_invoice_number', array('class' => 'control-label col-xs-2')); ?> -
+
'number', 'name' => 'last_used_invoice_number', 'id' => 'last_used_invoice_number', 'class' => 'form-control input-sm required', 'value'=>$this->config->item('last_used_invoice_number'))); ?> -
-
+
+
-
+
+ lang->line('config_sales_quote_format'), 'sales_quote_format', array('class' => 'control-label col-xs-2')); ?> +
+ 'sales_quote_format', + 'id' => 'sales_quote_format', + 'class' => 'form-control input-sm', + 'value' => $this->config->item('sales_quote_format'))); ?> +
+
+ +
lang->line('config_last_used_quote_number'), 'last_used_quote_number', array('class' => 'control-label col-xs-2')); ?> -
+
'number', 'name' => 'last_used_quote_number', 'id' => 'last_used_quote_number', 'class' => 'form-control input-sm required', 'value'=>$this->config->item('last_used_quote_number'))); ?> -
-
+
+
+ +
+ lang->line('config_work_order_enable'), 'work_order_enable', array('class' => 'control-label col-xs-2')); ?> +
+ 'work_order_enable', + 'value' => 'work_order_enable', + 'id' => 'work_order_enable', + 'checked' => $this->config->item('work_order_enable')));?> +
+
+ +
+ lang->line('config_work_order_format'), 'work_order_format', array('class' => 'control-label col-xs-2')); ?> +
+ 'work_order_format', + 'id' => 'work_order_format', + 'class' => 'form-control input-sm', + 'value' => $this->config->item('work_order_format'))); ?> +
+
+ +
+ lang->line('config_last_used_work_order_number'), 'last_used_work_order_number', array('class' => 'control-label col-xs-2')); ?> +
+ 'number', + 'name' => 'last_used_work_order_number', + 'id' => 'last_used_work_order_number', + 'class' => 'form-control input-sm required', + 'value'=>$this->config->item('last_used_work_order_number'))); ?> +
+
'submit_form', @@ -122,13 +156,30 @@ $(document).ready(function() { var enable_disable_invoice_enable = (function() { - var invoice_enable = $("#invoice_enable").is(":checked"); - $("#sales_invoice_format, #recv_invoice_format, #invoice_default_comments, #invoice_email_message, select[name='default_register_mode'], #sales_quote_format, select[name='line_sequence'], #last_used_invoice_number, #last_used_quote_number").prop("disabled", !invoice_enable); + var invoice_enabled = $("#invoice_enable").is(":checked"); + var work_order_enabled = $("#work_order_enable").is(":checked"); + $("#sales_invoice_format, #recv_invoice_format, #invoice_default_comments, #invoice_email_message, select[name='default_register_mode'], #sales_quote_format, select[name='line_sequence'], #last_used_invoice_number, #last_used_quote_number, #work_order_enable, #work_order_format, #last_used_work_order_number").prop("disabled", !invoice_enabled); + if(invoice_enabled) { + $("#work_order_format, #last_used_work_order_number").prop("disabled", !work_order_enabled); + } else { + $("#work_order_enable").attr('checked', false); + } + return arguments.callee; + })(); + + var enable_disable_work_order_enable = (function() { + var work_order_enabled = $("#work_order_enable").is(":checked"); + var invoice_enabled = $("#invoice_enable").is(":checked"); + if(invoice_enabled) { + $("#work_order_format, #last_used_work_order_number").prop("disabled", !work_order_enabled); + } return arguments.callee; })(); $("#invoice_enable").change(enable_disable_invoice_enable); + $("#work_order_enable").change(enable_disable_work_order_enable); + $("#invoice_config_form").validate($.extend(form_support.handler, { errorLabelContainer: "#invoice_error_message_box", @@ -136,13 +187,14 @@ $(document).ready(function() submitHandler: function(form) { $(form).ajaxSubmit({ beforeSerialize: function(arr, $form, options) { - $("#sales_invoice_format, #sales_quote_format, #recv_invoice_format, #invoice_default_comments, #invoice_email_message, #last_used_invoice_number, #last_used_quote_number").prop("disabled", false); + $("#sales_invoice_format, #sales_quote_format, #recv_invoice_format, #invoice_default_comments, #invoice_email_message, #last_used_invoice_number, #last_used_quote_number, #work_order_enable, #work_order_format, #last_used_work_order_number").prop("disabled", false); return true; }, success: function(response) { $.notify(response.message, { type: response.success ? 'success' : 'danger'} ); // set back disabled state enable_disable_invoice_enable(); + enable_disable_work_order_enable(); }, dataType:'json' }); diff --git a/application/views/sales/quote.php b/application/views/sales/quote.php index d89552725..427ec4b95 100644 --- a/application/views/sales/quote.php +++ b/application/views/sales/quote.php @@ -40,7 +40,7 @@ if (isset($error_message))
 ' . $this->lang->line('sales_send_quote'); ?>
 ' . $this->lang->line('sales_register'), array('class'=>'btn btn-info btn-sm', 'id'=>'show_sales_button')); ?> -  ' . $this->lang->line('sales_discard_quote'), array('class'=>'btn btn-danger btn-sm', 'id'=>'discard_quote_button')); ?> +  ' . $this->lang->line('sales_discard'), array('class'=>'btn btn-danger btn-sm', 'id'=>'discard_quote_button')); ?>
diff --git a/application/views/sales/register.php b/application/views/sales/register.php index c0614da4d..dc272dc7b 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -411,7 +411,7 @@ if(isset($success))
 lang->line('sales_complete_sale'); ?>
@@ -485,7 +485,7 @@ if(isset($success))
 lang->line('sales_suspend_sale'); ?>
 
@@ -500,7 +500,7 @@ if(isset($success))
@@ -535,7 +535,20 @@ if(isset($success)) -
+ +
+ +
+ +
config->item('invoice_enable') == TRUE) @@ -678,7 +691,12 @@ $(document).ready(function() { $.post('', {sales_print_after_sale: $(this).is(":checked")}); }); - + + $("#price_work_orders").change(function() + { + $.post('', {price_work_orders: $(this).is(":checked")}); + }); + $('#email_receipt').change(function() { $.post('', {email_receipt: $('#email_receipt').is(':checked') ? '1' : '0'}); diff --git a/application/views/sales/suspended.php b/application/views/sales/suspended.php index 86200bbfe..5d0f0bf51 100644 --- a/application/views/sales/suspended.php +++ b/application/views/sales/suspended.php @@ -1,7 +1,7 @@ - + config->item('dinner_table_enable') == TRUE) @@ -22,7 +22,7 @@ { ?> - + config->item('dinner_table_enable') == TRUE) @@ -50,7 +50,7 @@
lang->line('sales_suspended_sale_id'); ?>lang->line('sales_suspended_doc_id'); ?> lang->line('sales_date'); ?>
config->item('dateformat'), strtotime($suspended_sale['sale_time']));?> 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')); ?> + + + +
+ +
+
+ + + +
+ + +
+ +
+ + + + + + + + + + + + + + + + +
lang->line('common_date'); ?>
lang->line('sales_amount_due'); ?>
+
+ + + + + + + + + + + $item) + { + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + $sales_tax) + { + ?> + + + + + + + + + + + + + $payment) + { + $only_sale_check |= $payment['payment_type'] == $this->lang->line('sales_check'); + $splitpayment = explode(':', $payment['payment_type']); + $show_giftcard_remainder |= $splitpayment[0] == $this->lang->line('sales_giftcard'); + ?> + + + + + + +
lang->line('sales_item_number'); ?>lang->line('sales_item_name'); ?>lang->line('sales_quantity'); ?>lang->line('sales_price'); ?>lang->line('sales_discount'); ?>lang->line('sales_total'); ?>
+
+ + + +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; +} +?> + +
+ + + + + + + + + + +
+
+
+
config->item('company'); ?>
+
+
+ + + + + + + + + + 0) + { + ?> + + + + + +
lang->line('sales_work_order_number');?>
lang->line('common_date'); ?>
lang->line('sales_amount_due'); ?>
+
+ + + + + + + + + + + + $item) + { + ?> + + + + + + + + + + + + + + + + + + + $value) { ?> + + + + + + + + + + + +
lang->line('sales_item_number'); ?>lang->line('sales_item_name'); ?>lang->line('sales_quantity'); ?>lang->line('sales_price'); ?>lang->line('sales_discount'); ?>lang->line('sales_total'); ?>
lang->line('sales_sub_total'); ?>
lang->line('sales_total'); ?>
+ +
+
+
+
config->item('payment_message')); ?>
+
lang->line('sales_comments'). ': ' . (empty($comments) ? $this->config->item('invoice_default_comments') : $comments); ?>
+
+ config->item('return_policy')); ?> +
+
+
+ +
+
+
+ + + diff --git a/database/3.1.0_work_orders.sql b/database/3.1.0_work_orders.sql new file mode 100644 index 000000000..a9aa675f1 --- /dev/null +++ b/database/3.1.0_work_orders.sql @@ -0,0 +1,22 @@ +-- Add support for Work Orders + +INSERT INTO `ospos_app_config` (`key`, `value`) VALUES +('work_order_enable', '0'), +('work_order_format', 'W%y{WSEQ:6}'), +('last_used_work_order_number', '0'); + +ALTER TABLE `ospos_sales` + ADD COLUMN `work_order_number` varchar(32) DEFAULT NULL, + ADD COLUMN `sale_type` tinyint(2) NOT NULL DEFAULT 0; + +-- sale_type (0=pos, 1=invoice, 2=work order, 3=quote) + +update `ospos_sales` + set `sale_type` = '3' where quote_number IS NOT NULL; + +update `ospos_sales` + set `sale_type` = '2', `work_order_number` = `quote_number` + where quote_number IS NOT NULL; + +update `ospos_sales` + set `sale_type` = '1' where invoice_number IS NOT NULL; diff --git a/database/database.sql b/database/database.sql index a04f1e56f..92268bbd6 100644 --- a/database/database.sql +++ b/database/database.sql @@ -111,9 +111,10 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('gcaptcha_enable', '0'), ('gcaptcha_secret_key', ''), ('gcaptcha_site_key', ''), -('receiving_calculate_average_price', '0'); - - +('receiving_calculate_average_price', '0'), +('work_order_enable', '0'), +('work_order_format', 'W%y{WSEQ:6}'), +('last_used_work_order_number', '0'); -- -------------------------------------------------------- -- @@ -563,6 +564,8 @@ CREATE TABLE `ospos_sales` ( `sale_id` int(10) NOT NULL AUTO_INCREMENT, `sale_status` tinyint(2) NOT NULL DEFAULT 0, `dinner_table_id` int(11) NULL, + `work_order_number` varchar(32) DEFAULT NULL, + `sale_type` tinyint(2) NOT NULL DEFAULT 0, PRIMARY KEY (`sale_id`), KEY `customer_id` (`customer_id`), KEY `employee_id` (`employee_id`), diff --git a/database/tables.sql b/database/tables.sql index a7fffb2a4..bbf4c6e37 100644 --- a/database/tables.sql +++ b/database/tables.sql @@ -111,7 +111,11 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('gcaptcha_enable', '0'), ('gcaptcha_secret_key', ''), ('gcaptcha_site_key', ''), -('receiving_calculate_average_price', '0'); +('receiving_calculate_average_price', '0'), +('work_order_enable', '0'), +('work_order_format', 'W%y{WSEQ:6}'), +('last_used_work_order_number', '0'); + -- -------------------------------------------------------- @@ -565,6 +569,8 @@ CREATE TABLE `ospos_sales` ( `sale_id` int(10) NOT NULL AUTO_INCREMENT, `sale_status` tinyint(2) NOT NULL DEFAULT 0, `dinner_table_id` int(11) NULL, + `work_order_number` varchar(32) DEFAULT NULL, + `sale_type` tinyint(2) NOT NULL DEFAULT 0, PRIMARY KEY (`sale_id`), KEY `customer_id` (`customer_id`), KEY `employee_id` (`employee_id`),