diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 70689945b..679f949fa 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -4,7 +4,7 @@ require_once("Secure_Controller.php"); class Sales extends Secure_Controller { - function __construct() + public function __construct() { parent::__construct('sales'); @@ -12,16 +12,16 @@ class Sales extends Secure_Controller $this->load->library('barcode_lib'); } - function index() + public function index() { $this->_reload(); } - function manage() + public function manage() { $person_id = $this->session->userdata('person_id'); - if (!$this->Employee->has_grant('reports_sales', $person_id)) + if(!$this->Employee->has_grant('reports_sales', $person_id)) { redirect('no_access/sales/reports_sales'); } @@ -44,25 +44,25 @@ class Sales extends Secure_Controller } } - function get_row($row_id) + public function get_row($row_id) { $this->Sale->create_sales_items_temp_table(); $sale_info = $this->Sale->get_info($row_id)->row(); - $data_row = get_sale_data_row($sale_info, $this); + $data_row = $this->xss_clean(get_sale_data_row($sale_info, $this)); echo json_encode($data_row); } - function search() + public function search() { $this->Sale->create_sales_items_temp_table(); $search = $this->input->get('search'); - $limit = $this->input->get('limit'); + $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); - $sort = $this->input->get('sort'); - $order = $this->input->get('order'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); $is_valid_receipt = isset($search) ? $this->sale_lib->is_valid_receipt($search) : FALSE; @@ -81,59 +81,61 @@ class Sales extends Secure_Controller $sales = $this->Sale->search($search, $filters, $limit, $offset, $sort, $order); $total_rows = $this->Sale->get_found_rows($search, $filters); $payments = $this->Sale->get_payments_summary($search, $filters); - $payment_summary = get_sales_manage_payments_summary($payments, $sales, $this); + $payment_summary = $this->xss_clean(get_sales_manage_payments_summary($payments, $sales, $this)); $data_rows = array(); foreach($sales->result() as $sale) { - $data_rows[] = get_sale_data_row($sale, $this); + $data_rows[] = $this->xss_clean(get_sale_data_row($sale, $this)); } - if ($total_rows > 0) + if($total_rows > 0) { $total_rows++; - $data_rows[] = get_sale_data_last_row($sales, $this); + $data_rows[] = $this->xss_clean(get_sale_data_last_row($sales, $this)); } echo json_encode(array('total' => $total_rows, 'rows' => $data_rows,'payment_summary' => $payment_summary)); } - function item_search() + public function item_search() { $suggestions = array(); - $receipt = $search = $this->input->get('term') != '' ? $this->input->get('term') : null; + $receipt = $search = $this->input->get('term') != '' ? $this->input->get('term') : NULL; - if ($this->sale_lib->get_mode() == 'return' && $this->sale_lib->is_valid_receipt($receipt) ) + if($this->sale_lib->get_mode() == 'return' && $this->sale_lib->is_valid_receipt($receipt)) { // if a valid receipt or invoice was found the search term will be replaced with a receipt number (POS #) $suggestions[] = $receipt; } $suggestions = array_merge($suggestions, $this->Item->get_search_suggestions($search, array('search_custom' => FALSE, 'is_deleted' => FALSE), TRUE)); $suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($search)); + + $suggestions = $this->xss_clean($suggestions); echo json_encode($suggestions); } - function suggest_search() + public function suggest_search() { - $search = $this->input->post('term') != '' ? $this->input->post('term') : null; + $search = $this->input->post('term') != '' ? $this->input->post('term') : NULL; - $suggestions = $this->Sale->get_search_suggestions($search); + $suggestions = $this->xss_clean($this->Sale->get_search_suggestions($search)); echo json_encode($suggestions); } - function select_customer() + public function select_customer() { $customer_id = $this->input->post('customer'); - if ($this->Customer->exists($customer_id)) + if($this->Customer->exists($customer_id)) { $this->sale_lib->set_customer($customer_id); } $this->_reload(); } - function change_mode() + public function change_mode() { $stock_location = $this->input->post('stock_location'); if (!$stock_location || $stock_location == $this->sale_lib->get_sale_location()) @@ -141,7 +143,7 @@ class Sales extends Secure_Controller $mode = $this->input->post('mode'); $this->sale_lib->set_mode($mode); } - else if ($this->Stock_location->is_allowed_location($stock_location, 'sales')) + else if($this->Stock_location->is_allowed_location($stock_location, 'sales')) { $this->sale_lib->set_sale_location($stock_location); } @@ -149,71 +151,72 @@ class Sales extends Secure_Controller $this->_reload(); } - function set_comment() + public function set_comment() { $this->sale_lib->set_comment($this->input->post('comment')); } - function set_invoice_number() + public function set_invoice_number() { $this->sale_lib->set_invoice_number($this->input->post('sales_invoice_number')); } - function set_invoice_number_enabled() + public function set_invoice_number_enabled() { $this->sale_lib->set_invoice_number_enabled($this->input->post('sales_invoice_number_enabled')); } - function set_print_after_sale() + public function set_print_after_sale() { $this->sale_lib->set_print_after_sale($this->input->post('sales_print_after_sale')); } - function set_email_receipt() + public function set_email_receipt() { $this->sale_lib->set_email_receipt($this->input->post('email_receipt')); } // Multiple Payments - function add_payment() + public function add_payment() { $data = array(); $this->form_validation->set_rules('amount_tendered', 'lang:sales_amount_tendered', 'trim|required|numeric'); - if ( $this->form_validation->run() == FALSE ) + if($this->form_validation->run() == FALSE) { - if ( $this->input->post('payment_type') == $this->lang->line('sales_gift_card') ) + if($this->input->post('payment_type') == $this->lang->line('sales_gift_card')) { - $data['error']=$this->lang->line('sales_must_enter_numeric_giftcard'); + $data['error'] = $this->lang->line('sales_must_enter_numeric_giftcard'); } else { - $data['error']=$this->lang->line('sales_must_enter_numeric'); + $data['error'] = $this->lang->line('sales_must_enter_numeric'); } - $this->_reload( $data ); + $this->_reload($data); return; } $payment_type = $this->input->post('payment_type'); - if ( $payment_type == $this->lang->line('sales_giftcard') ) + if($payment_type == $this->lang->line('sales_giftcard')) { $payments = $this->sale_lib->get_payments(); $payment_type = $this->input->post('payment_type') . ':' . $payment_amount = $this->input->post('amount_tendered'); $current_payments_with_giftcard = isset($payments[$payment_type]) ? $payments[$payment_type]['payment_amount'] : 0; $cur_giftcard_value = $this->Giftcard->get_giftcard_value($this->input->post('amount_tendered')) - $current_payments_with_giftcard; - if ( $cur_giftcard_value <= 0 ) + if($cur_giftcard_value <= 0) { $data['error'] = $this->lang->line('giftcards_remaining_balance', $this->input->post('amount_tendered'), to_currency( $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered')))); - $this->_reload( $data ); + $this->_reload($data); + return; } $new_giftcard_value = $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) - $this->sale_lib->get_amount_due(); - $new_giftcard_value = ( $new_giftcard_value >= 0 ) ? $new_giftcard_value : 0; + $new_giftcard_value = ($new_giftcard_value >= 0) ? $new_giftcard_value : 0; $this->sale_lib->set_giftcard_remainder($new_giftcard_value); - $data['warning'] = $this->lang->line('giftcards_remaining_balance', $this->input->post('amount_tendered'), to_currency( $new_giftcard_value, TRUE )); + $data['warning'] = $this->lang->line('giftcards_remaining_balance', $this->input->post('amount_tendered'), to_currency($new_giftcard_value, TRUE)); $payment_amount = min( $this->sale_lib->get_amount_due(), $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) ); } else @@ -221,7 +224,7 @@ class Sales extends Secure_Controller $payment_amount = $this->input->post('amount_tendered'); } - if( !$this->sale_lib->add_payment( $payment_type, $payment_amount ) ) + if(!$this->sale_lib->add_payment($payment_type, $payment_amount)) { $data['error'] = 'Unable to Add Payment! Please try again!'; } @@ -230,14 +233,14 @@ class Sales extends Secure_Controller } // Multiple Payments - function delete_payment( $payment_id ) + public function delete_payment($payment_id) { - $this->sale_lib->delete_payment( $payment_id ); + $this->sale_lib->delete_payment($payment_id); $this->_reload(); } - function add() + public function add() { $data = array(); @@ -280,7 +283,7 @@ class Sales extends Secure_Controller $this->_reload($data); } - function edit_item($line) + public function edit_item($line) { $data = array(); @@ -295,7 +298,7 @@ class Sales extends Secure_Controller $discount = $this->input->post('discount'); $item_location = $this->input->post('location'); - if ($this->form_validation->run() != FALSE) + if($this->form_validation->run() != FALSE) { $this->sale_lib->edit_item($line, $description, $serialnumber, $quantity, $discount, $price); } @@ -303,19 +306,20 @@ class Sales extends Secure_Controller { $data['error'] = $this->lang->line('sales_error_editing_item'); } - $data['warning'] = $this->sale_lib->out_of_stock($this->sale_lib->get_item_id($line),$item_location); + + $data['warning'] = $this->sale_lib->out_of_stock($this->sale_lib->get_item_id($line), $item_location); $this->_reload($data); } - function delete_item($item_number) + public function delete_item($item_number) { $this->sale_lib->delete_item($item_number); $this->_reload(); } - function remove_customer() + public function remove_customer() { $this->sale_lib->clear_giftcard_remainder(); $this->sale_lib->clear_invoice_number(); @@ -324,8 +328,10 @@ class Sales extends Secure_Controller $this->_reload(); } - function complete() + public function complete() { + $data = array(); + $data['cart'] = $this->sale_lib->get_cart(); $data['subtotal'] = $this->sale_lib->get_subtotal(); $data['discounted_subtotal'] = $this->sale_lib->get_subtotal(TRUE); @@ -342,64 +348,46 @@ class Sales extends Secure_Controller $data['amount_change'] = $this->sale_lib->get_amount_due() * -1; $data['amount_due'] = $this->sale_lib->get_amount_due(); $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; - $emp_info = $this->Employee->get_info($employee_id); - $data['employee'] = $emp_info->first_name . ' ' . $emp_info->last_name; + $employee_info = $this->Employee->get_info($employee_id); + $data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name; $data['company_info'] = implode("\n", array( $this->config->item('address'), $this->config->item('phone'), $this->config->item('account_number') )); $customer_id = $this->sale_lib->get_customer(); - $cust_info = $this->_load_customer_data($customer_id, $data); - $invoice_number = $this->_substitute_invoice_number($cust_info); - if ($this->sale_lib->is_invoice_number_enabled() && $this->Sale->invoice_number_exists($invoice_number)) + $customer_info = $this->_load_customer_data($customer_id, $data); + $invoice_number = $this->_substitute_invoice_number($customer_info); + + if($this->sale_lib->is_invoice_number_enabled() && $this->Sale->invoice_number_exists($invoice_number)) { $data['error'] = $this->lang->line('sales_invoice_number_duplicate'); + $this->_reload($data); } else { - $invoice_number = $this->sale_lib->is_invoice_number_enabled() ? $invoice_number : null; + $invoice_number = $this->sale_lib->is_invoice_number_enabled() ? $invoice_number : NULL; $data['invoice_number'] = $invoice_number; - $data['sale_id'] = 'POS ' . $this->Sale->save($data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $data['payments']); - if ($data['sale_id'] == 'POS -1') + $data['sale_id_num'] = $this->Sale->save($data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $data['payments']); + $data['sale_id'] = 'POS ' . $data['sale_id_num']; + + $data = $this->xss_clean($data); + + if($data['sale_id_num'] == -1) { $data['error_message'] = $this->lang->line('sales_transaction_failed'); } else { $data['barcode'] = $this->barcode_lib->generate_receipt_barcode($data['sale_id']); - // if we want to email. .. just attach the pdf in there? - if ($this->sale_lib->get_email_receipt() && !empty($cust_info->email)) - { - $this->load->library('email'); - $config['mailtype'] = 'html'; - $this->email->initialize($config); - $this->email->from($this->config->item('email'), $this->config->item('company')); - $this->email->to($cust_info->email); - - $this->email->subject($this->lang->line('sales_receipt')); - if ($this->config->item('use_invoice_template') && $this->sale_lib->is_invoice_number_enabled()) - { - $data['image_prefix'] = ""; - $filename = $this->_invoice_email_pdf($data); - $this->email->attach($filename); - $text = $this->config->item('invoice_email_message'); - $text = str_replace('$INV', $invoice_number, $text); - $text = str_replace('$CO', $data['sale_id'], $text); - $text = $this->_substitute_customer($text, $cust_info); - $this->email->message($text); - } - else - { - $this->email->message($this->load->view('sales/receipt_email', $data, true)); - } - $this->email->send(); - } } + $data['cur_giftcard_value'] = $this->sale_lib->get_giftcard_remainder(); $data['print_after_sale'] = $this->sale_lib->is_print_after_sale(); - if ($this->sale_lib->is_invoice_number_enabled() && $this->config->item('use_invoice_template')) + $data['email_receipt'] = $this->sale_lib->get_email_receipt(); + + if($this->sale_lib->is_invoice_number_enabled()) { $this->load->view('sales/invoice', $data); } @@ -411,56 +399,83 @@ class Sales extends Secure_Controller $this->sale_lib->clear_all(); } } - - private function _invoice_email_pdf($data) - { - $data['image_prefix'] = ""; - $html = $this->load->view('sales/invoice_email', $data, true); - // load pdf helper - $this->load->helper(array('dompdf', 'file')); - $file_content = pdf_create($html, '', false); - $filename = sys_get_temp_dir() . '/'. $this->lang->line('sales_invoice') . '-' . str_replace('/', '-' , $data["invoice_number"]) . '.pdf'; - write_file($filename, $file_content); - return $filename; - } - - function invoice_email($sale_id) + public function invoice_email($sale_id) { $sale_data = $this->_load_sale_data($sale_id); - $sale_data['image_prefix'] = base_url(); + $this->load->view('sales/invoice_email', $sale_data); $this->sale_lib->clear_all(); } - - function send_invoice($sale_id) + + public function send_invoice($sale_id) { $sale_data = $this->_load_sale_data($sale_id); - $text = $this->config->item('invoice_email_message'); - $text = str_replace('$INV', $sale_data['invoice_number'], $text); - $text = str_replace('$CO', 'POS ' . $sale_data['sale_id'], $text); - $text = $this->_substitute_customer($text,(object) $sale_data); + $result = FALSE; $message = $this->lang->line('sales_invoice_no_email'); - if (isset($sale_data["customer_email"]) && !empty( $sale_data["customer_email"])) { + if(isset($sale_data["customer_email"]) && !empty($sale_data["customer_email"])) + { $this->load->library('email'); $this->email->from($this->config->item('email'), $this->config->item('company')); $this->email->to($sale_data['customer_email']); $this->email->subject($this->lang->line('sales_invoice') . ' ' . $sale_data['invoice_number']); + $text = $this->config->item('invoice_email_message'); + $text = str_replace('$INV', $sale_data['invoice_number'], $text); + $text = str_replace('$CO', 'POS ' . $sale_data['sale_id'], $text); + $text = $this->_substitute_customer($text,(object) $sale_data); $this->email->message($text); - $filename = $this->_invoice_email_pdf($sale_data); + + // generate email attachment: invoice in pdf format + $html = $this->load->view('sales/invoice_email', $sale_data, TRUE); + // load pdf helper + $this->load->helper(array('dompdf', 'file')); + $file_content = pdf_create($html, '', FALSE); + $filename = sys_get_temp_dir() . '/'. $this->lang->line('sales_invoice') . '-' . str_replace('/', '-' , $sale_data["invoice_number"]) . '.pdf'; + write_file($filename, $file_content); + $this->email->attach($filename); $result = $this->email->send(); $message = $this->lang->line($result ? 'sales_invoice_sent' : 'sales_invoice_unsent') . ' ' . $sale_data["customer_email"]; } - echo json_encode(array('success'=>$result, 'message'=>$message, 'id'=>$sale_id)); + + echo json_encode(array('success' => $result, 'message' => $message, 'id' => $sale_id)); $this->sale_lib->clear_all(); + + return $result; } - + + public function send_receipt($sale_id) + { + $sale_data = $this->_load_sale_data($sale_id); + + $result = FALSE; + $message = $this->lang->line('sales_receipt_no_email'); + if(isset($sale_data["customer_email"]) && !empty( $sale_data["customer_email"])) + { + $sale_data['barcode'] = $this->barcode_lib->generate_receipt_barcode($sale_data['sale_id']); + + $this->load->library('email'); + $config['mailtype'] = 'html'; + $this->email->initialize($config); + $this->email->from($this->config->item('email'), $this->config->item('company')); + $this->email->to($sale_data['customer_email']); + $this->email->subject($this->lang->line('sales_receipt')); + $this->email->message($this->load->view('sales/receipt_email', $sale_data, TRUE)); + $result = $this->email->send(); + $message = $this->lang->line($result ? 'sales_receipt_sent' : 'sales_receipt_unsent') . ' ' . $sale_data["customer_email"]; + } + + echo json_encode(array('success' => $result, 'message' => $message, 'id' => $sale_id)); + $this->sale_lib->clear_all(); + + return $result; + } + private function _substitute_variable($text, $variable, $object, $function) { // don't query if this variable isn't used - if (strstr($text, $variable)) + if(strstr($text, $variable)) { $value = call_user_func(array($object, $function)); $text = str_replace($variable, $value, $text); @@ -468,17 +483,17 @@ class Sales extends Secure_Controller return $text; } - - private function _substitute_customer($text, $cust_info) + + private function _substitute_customer($text, $customer_info) { // substitute customer info $customer_id = $this->sale_lib->get_customer(); - if($customer_id != -1 && $cust_info != '') + if($customer_id != -1 && $customer_info != '') { - $text = str_replace('$CU',$cust_info->first_name . ' ' . $cust_info->last_name,$text); - $words = preg_split("/\s+/", trim($cust_info->first_name . ' ' . $cust_info->last_name)); - $acronym = ""; - foreach ($words as $w) + $text = str_replace('$CU', $customer_info->first_name . ' ' . $customer_info->last_name, $text); + $words = preg_split("/\s+/", trim($customer_info->first_name . ' ' . $customer_info->last_name)); + $acronym = ''; + foreach($words as $w) { $acronym .= $w[0]; } @@ -488,269 +503,82 @@ class Sales extends Secure_Controller return $text; } - private function _is_custom_invoice_number($cust_info) + private function _is_custom_invoice_number($customer_info) { $invoice_number = $this->config->config['sales_invoice_format']; - $invoice_number = $this->_substitute_variables($invoice_number, $cust_info); + $invoice_number = $this->_substitute_variables($invoice_number, $customer_info); return $this->sale_lib->get_invoice_number() != $invoice_number; } - - private function _substitute_variables($text, $cust_info) + + private function _substitute_variables($text, $customer_info) { $text = $this->_substitute_variable($text, '$YCO', $this->Sale, 'get_invoice_number_for_year'); $text = $this->_substitute_variable($text, '$CO', $this->Sale , 'get_invoice_count'); $text = $this->_substitute_variable($text, '$SCO', $this->Sale_suspended, 'get_invoice_count'); $text = strftime($text); - $text = $this->_substitute_customer($text, $cust_info); + $text = $this->_substitute_customer($text, $customer_info); return $text; } - - private function _substitute_invoice_number($cust_info) + + private function _substitute_invoice_number($customer_info) { $invoice_number = $this->config->config['sales_invoice_format']; - $invoice_number = $this->_substitute_variables($invoice_number, $cust_info); + $invoice_number = $this->_substitute_variables($invoice_number, $customer_info); $this->sale_lib->set_invoice_number($invoice_number, TRUE); return $this->sale_lib->get_invoice_number(); } - private function _load_sale_data($sale_id) - { - $this->Sale->create_sales_items_temp_table(); - - $this->sale_lib->clear_all(); - $sale_info = $this->Sale->get_info($sale_id)->row_array(); - $this->sale_lib->copy_entire_sale($sale_id); - $data['cart'] = $this->sale_lib->get_cart(); - $data['payments'] = $this->sale_lib->get_payments(); - $data['subtotal'] = $this->sale_lib->get_subtotal(); - $data['discounted_subtotal'] = $this->sale_lib->get_subtotal(TRUE); - $data['tax_exclusive_subtotal'] = $this->sale_lib->get_subtotal(TRUE, TRUE); - $data['taxes'] = $this->sale_lib->get_taxes(); - $data['total'] = $this->sale_lib->get_total(); - $data['discount'] = $this->sale_lib->get_discount(); - $data['receipt_title'] = $this->lang->line('sales_receipt'); - $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($sale_info['sale_time'])); - $data['transaction_date'] = date($this->config->item('dateformat'), strtotime($sale_info['sale_time'])); - $data['show_stock_locations'] = $this->Stock_location->show_locations('sales'); - $data['amount_change'] = $this->sale_lib->get_amount_due() * -1; - $data['amount_due'] = $this->sale_lib->get_amount_due(); - $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; - $emp_info = $this->Employee->get_info($employee_id); - $data['employee'] = $emp_info->first_name . ' ' . $emp_info->last_name; - - $customer_id = $this->sale_lib->get_customer(); - $cust_info = $this->_load_customer_data($customer_id, $data); - - $data['sale_id'] = 'POS ' . $sale_id; - $data['comments'] = $sale_info['comment']; - $data['invoice_number'] = $sale_info['invoice_number']; - $data['company_info'] = implode("\n", array( - $this->config->item('address'), - $this->config->item('phone'), - $this->config->item('account_number') - )); - $data['barcode'] = $this->barcode_lib->generate_receipt_barcode($data['sale_id']); - $data['print_after_sale'] = FALSE; - - return $data; - } - - function receipt($sale_id) - { - $data = $this->_load_sale_data($sale_id); - $this->load->view('sales/receipt', $data); - $this->sale_lib->clear_all(); - } - - function invoice($sale_id, $sale_info='') - { - if($sale_info == '') - { - $sale_info = $this->_load_sale_data($sale_id); - } - - $this->load->view('sales/invoice', $sale_info); - $this->sale_lib->clear_all(); - } - - function edit($sale_id) - { - $data = array(); - - $data['employees'] = array(); - foreach ($this->Employee->get_all()->result() as $employee) - { - $data['employees'][$employee->person_id] = $employee->first_name . ' '. $employee->last_name; - } - $this->Sale->create_sales_items_temp_table(); - - $sale_info = $this->Sale->get_info($sale_id)->row_array(); - $person_name = $sale_info['first_name'] . " " . $sale_info['last_name']; - $data['selected_customer_name'] = !empty($sale_info['customer_id']) ? $person_name : ''; - $data['selected_customer_id'] = $sale_info['customer_id']; - $data['sale_info'] = $sale_info; - $data['payments'] = $this->Sale->get_sale_payments($sale_id); - // don't allow gift card to be a payment option in a sale transaction edit because it's a complex change - $data['payment_options'] = $this->Sale->get_payment_options(false); - - $this->load->view('sales/form', $data); - } - - function delete($sale_id = -1, $update_inventory=TRUE) - { - $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; - $sale_ids = $sale_id == -1 ? $this->input->post('ids') : array($sale_id); - - if($this->Sale->delete_list($sale_ids, $employee_id, $update_inventory)) - { - echo json_encode(array('success'=>true, 'message'=>$this->lang->line('sales_successfully_deleted').' '. - count($sale_ids).' '.$this->lang->line('sales_one_or_multiple'), 'ids'=>$sale_ids)); - } - else - { - echo json_encode(array('success'=>false, 'message'=>$this->lang->line('sales_unsuccessfully_deleted'))); - } - } - - function save($sale_id = -1) - { - $newdate = $this->input->post('date'); - - $start_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $newdate); - - $sale_data = array( - 'sale_time' => $start_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(); - for($i = 0; $i < $this->input->post('number_of_payments'); $i++) - { - $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) - { - // 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; - } - } - } - - 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)); - } - } - private function _payments_cover_total() { // Changed the conditional to account for floating point rounding // "sale" amount due needs to be <=0 to state it's fine - if( ($this->sale_lib->get_mode() == 'sale') && $this->sale_lib->get_amount_due() > 1e-6 ) + if(($this->sale_lib->get_mode() == 'sale') && $this->sale_lib->get_amount_due() > 1e-6) { - return false; + return FALSE; } // "return" amount due needs to be >=0 to state it's fine - if( ($this->sale_lib->get_mode() == 'return') && $this->sale_lib->get_amount_due() < -(1e-6) ) + if(($this->sale_lib->get_mode() == 'return') && $this->sale_lib->get_amount_due() < -(1e-6)) { - return false; + return FALSE; } - return true; + return TRUE; } - - private function _reload($data=array()) - { - $person_info = $this->Employee->get_logged_in_employee_info(); - $data['cart'] = $this->sale_lib->get_cart(); - $data['modes'] = array('sale'=>$this->lang->line('sales_sale'), 'return'=>$this->lang->line('sales_return')); - $data['mode'] = $this->sale_lib->get_mode(); - $data['stock_locations'] = $this->Stock_location->get_allowed_locations('sales'); - $data['stock_location'] = $this->sale_lib->get_sale_location(); - - $data['subtotal'] = $this->sale_lib->get_subtotal(TRUE); - $data['tax_exclusive_subtotal'] = $this->sale_lib->get_subtotal(TRUE, TRUE); - $data['taxes'] = $this->sale_lib->get_taxes(); - $data['discount'] = $this->sale_lib->get_discount(); - $data['total'] = $this->sale_lib->get_total(); - $data['items_module_allowed'] = $this->Employee->has_grant('items', $person_info->person_id); - $data['comment'] = $this->sale_lib->get_comment(); - $data['email_receipt'] = $this->sale_lib->get_email_receipt(); - $data['payments_total'] = $this->sale_lib->get_payments_total(); - $data['amount_due'] = $this->sale_lib->get_amount_due(); - $data['payments'] = $this->sale_lib->get_payments(); - $data['payment_options'] = $this->Sale->get_payment_options(); - - $customer_id = $this->sale_lib->get_customer(); - $cust_info = $this->_load_customer_data($customer_id, $data, true); - - $data['invoice_number'] = $this->_substitute_invoice_number($cust_info); - $data['invoice_number_enabled'] = $this->sale_lib->is_invoice_number_enabled(); - $data['print_after_sale'] = $this->sale_lib->is_print_after_sale(); - $data['payments_cover_total'] = $this->_payments_cover_total(); - - $this->load->view("sales/register", $data); - } - - private function _load_customer_data($customer_id, &$data, $totals=false) + private function _load_customer_data($customer_id, &$data, $totals = FALSE) { - $cust_info = ''; + $customer_info = ''; if($customer_id != -1) { - $cust_info = $this->Customer->get_info($customer_id); - if(isset($cust_info->company_name)) + $customer_info = $this->Customer->get_info($customer_id); + if(isset($customer_info->company_name)) { - $data['customer'] = $cust_info->company_name; + $data['customer'] = $customer_info->company_name; } else { - $data['customer'] = $cust_info->first_name . ' ' . $cust_info->last_name; + $data['customer'] = $customer_info->first_name . ' ' . $customer_info->last_name; } - $data['first_name'] = $cust_info->first_name; - $data['last_name'] = $cust_info->last_name; - $data['customer_email'] = $cust_info->email; - $data['customer_address'] = $cust_info->address_1; - if(!empty($cust_info->zip) or !empty($cust_info->city)) + $data['first_name'] = $customer_info->first_name; + $data['last_name'] = $customer_info->last_name; + $data['customer_email'] = $customer_info->email; + $data['customer_address'] = $customer_info->address_1; + if(!empty($customer_info->zip) or !empty($customer_info->city)) { - $data['customer_location'] = $cust_info->zip . ' ' . $cust_info->city; + $data['customer_location'] = $customer_info->zip . ' ' . $customer_info->city; } else { $data['customer_location'] = ''; } - $data['customer_account_number'] = $cust_info->account_number; - $data['customer_discount_percent'] = $cust_info->discount_percent; + $data['customer_account_number'] = $customer_info->account_number; + $data['customer_discount_percent'] = $customer_info->discount_percent; if($totals) { $cust_totals = $this->Customer->get_totals($customer_id); @@ -765,72 +593,253 @@ class Sales extends Secure_Controller )); } - return $cust_info; + return $customer_info; } - function cancel() + private function _load_sale_data($sale_id) + { + $this->Sale->create_sales_items_temp_table(); + + $this->sale_lib->clear_all(); + $sale_info = $this->Sale->get_info($sale_id)->row_array(); + $this->sale_lib->copy_entire_sale($sale_id); + $data = array(); + $data['cart'] = $this->sale_lib->get_cart(); + $data['payments'] = $this->sale_lib->get_payments(); + $data['subtotal'] = $this->sale_lib->get_subtotal(); + $data['discounted_subtotal'] = $this->sale_lib->get_subtotal(TRUE); + $data['tax_exclusive_subtotal'] = $this->sale_lib->get_subtotal(TRUE, TRUE); + $data['taxes'] = $this->sale_lib->get_taxes(); + $data['total'] = $this->sale_lib->get_total(); + $data['discount'] = $this->sale_lib->get_discount(); + $data['receipt_title'] = $this->lang->line('sales_receipt'); + $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($sale_info['sale_time'])); + $data['transaction_date'] = date($this->config->item('dateformat'), strtotime($sale_info['sale_time'])); + $data['show_stock_locations'] = $this->Stock_location->show_locations('sales'); + $data['amount_change'] = $this->sale_lib->get_amount_due() * -1; + $data['amount_due'] = $this->sale_lib->get_amount_due(); + $employee_info = $this->Employee->get_info($this->Employee->get_logged_in_employee_info()->person_id); + $data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name; + $customer_info = $this->_load_customer_data($this->sale_lib->get_customer(), $data); + + $data['sale_id_num'] = $sale_id; + $data['sale_id'] = 'POS ' . $sale_id; + $data['comments'] = $sale_info['comment']; + $data['invoice_number'] = $sale_info['invoice_number']; + $data['company_info'] = implode("\n", array( + $this->config->item('address'), + $this->config->item('phone'), + $this->config->item('account_number') + )); + $data['barcode'] = $this->barcode_lib->generate_receipt_barcode($data['sale_id']); + $data['print_after_sale'] = FALSE; + + return $this->xss_clean($data); + } + + private function _reload($data = array()) + { + $data['cart'] = $this->sale_lib->get_cart(); + $data['modes'] = array('sale' => $this->lang->line('sales_sale'), 'return' => $this->lang->line('sales_return')); + $data['mode'] = $this->sale_lib->get_mode(); + $data['stock_locations'] = $this->Stock_location->get_allowed_locations('sales'); + $data['stock_location'] = $this->sale_lib->get_sale_location(); + $data['subtotal'] = $this->sale_lib->get_subtotal(TRUE); + $data['tax_exclusive_subtotal'] = $this->sale_lib->get_subtotal(TRUE, TRUE); + $data['taxes'] = $this->sale_lib->get_taxes(); + $data['discount'] = $this->sale_lib->get_discount(); + $data['total'] = $this->sale_lib->get_total(); + $data['comment'] = $this->sale_lib->get_comment(); + $data['email_receipt'] = $this->sale_lib->get_email_receipt(); + $data['payments_total'] = $this->sale_lib->get_payments_total(); + $data['amount_due'] = $this->sale_lib->get_amount_due(); + $data['payments'] = $this->sale_lib->get_payments(); + $data['payment_options'] = $this->Sale->get_payment_options(); + + $data['items_module_allowed'] = $this->Employee->has_grant('items', $this->Employee->get_logged_in_employee_info()->person_id); + + $customer_info = $this->_load_customer_data($this->sale_lib->get_customer(), $data, TRUE); + $data['invoice_number'] = $this->_substitute_invoice_number($customer_info); + $data['invoice_number_enabled'] = $this->sale_lib->is_invoice_number_enabled(); + $data['print_after_sale'] = $this->sale_lib->is_print_after_sale(); + $data['payments_cover_total'] = $this->_payments_cover_total(); + + $data = $this->xss_clean($data); + + $this->load->view("sales/register", $data); + } + + public function receipt($sale_id) + { + $sale_data = $this->_load_sale_data($sale_id); + + $this->load->view('sales/receipt', $sale_data); + $this->sale_lib->clear_all(); + } + + public function invoice($sale_id) + { + $sale_data = $this->_load_sale_data($sale_id); + + $this->load->view('sales/invoice', $sale_data); + $this->sale_lib->clear_all(); + } + + public function edit($sale_id) + { + $data = array(); + $data['employees'] = array(); + foreach($this->Employee->get_all()->result() as $employee) + { + foreach(get_object_vars($employee) as $property => $value) + { + $employee->$property = $this->xss_clean($value); + } + + $data['employees'][$employee->person_id] = $employee->first_name . ' '. $employee->last_name; + } + + $this->Sale->create_sales_items_temp_table(); + + $sale_info = $this->xss_clean($this->Sale->get_info($sale_id)->row_array()); + $person_name = $sale_info['first_name'] . " " . $sale_info['last_name']; + $data['selected_customer_name'] = !empty($sale_info['customer_id']) ? $person_name : ''; + $data['selected_customer_id'] = $sale_info['customer_id']; + $data['sale_info'] = $sale_info; + + $data['payments'] = array(); + foreach($this->Sale->get_sale_payments($sale_id)->result() as $payment) + { + foreach(get_object_vars($payment) as $property => $value) + { + $payment->$property = $this->xss_clean($value); + } + + $data['payments'][] = $payment; + } + + // don't allow gift card to be a payment option in a sale transaction edit because it's a complex change + $data['payment_options'] = $this->xss_clean($this->Sale->get_payment_options(FALSE)); + + $this->load->view('sales/form', $data); + } + + public function delete($sale_id = -1, $update_inventory = TRUE) + { + $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; + $sale_ids = $sale_id == -1 ? $this->input->post('ids') : array($sale_id); + + if($this->Sale->delete_list($sale_ids, $employee_id, $update_inventory)) + { + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('sales_successfully_deleted').' '. + count($sale_ids).' '.$this->lang->line('sales_one_or_multiple'), 'ids' => $sale_ids)); + } + else + { + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('sales_unsuccessfully_deleted'))); + } + } + + public function save($sale_id = -1) + { + $newdate = $this->input->post('date'); + + $start_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $newdate); + + $sale_data = array( + 'sale_time' => $start_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(); + for($i = 0; $i < $this->input->post('number_of_payments'); $i++) + { + $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) + { + // 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; + } + } + } + + 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(); } - function suspend() + public function suspend() { - $data['cart'] = $this->sale_lib->get_cart(); - $data['subtotal'] = $this->sale_lib->get_subtotal(); - $data['taxes'] = $this->sale_lib->get_taxes(); - $data['total'] = $this->sale_lib->get_total(); - $data['receipt_title'] = $this->lang->line('sales_receipt'); - $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat')); - $comment = $this->sale_lib->get_comment(); - $invoice_number = $this->sale_lib->get_invoice_number(); - - $data['payment_type'] = $this->input->post('payment_type'); - // Multiple payments - $data['payments'] = $this->sale_lib->get_payments(); - $data['amount_change'] = to_currency($this->sale_lib->get_amount_due() * -1); - + $cart = $this->sale_lib->get_cart(); + $payments = $this->sale_lib->get_payments(); $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; - $emp_info = $this->Employee->get_info($employee_id); - $data['employee'] = $emp_info->first_name . ' ' . $emp_info->last_name; - $customer_id = $this->sale_lib->get_customer(); - $cust_info = $this->_load_customer_data($customer_id, $data); - - $is_set = $this->_is_custom_invoice_number($cust_info); - $invoice_number = $is_set ? $invoice_number : NULL; - - $total_payments = 0; - - foreach($data['payments'] as $payment) - { - $total_payments = bcadd($total_payments, $payment['payment_amount'], PRECISION); - } + $customer_info = $this->Customer->get_info($customer_id); + $invoice_number = $this->_is_custom_invoice_number($customer_info) ? $this->sale_lib->get_invoice_number() : NULL; + $comment = $this->sale_lib->get_comment(); //SAVE sale to database - $data['sale_id'] = 'POS ' . $this->Sale_suspended->save($data['cart'], $customer_id, $employee_id, $comment, $invoice_number, $data['payments']); - if ($data['sale_id'] == 'POS -1') + $data = array(); + if($this->Sale_suspended->save($cart, $customer_id, $employee_id, $comment, $invoice_number, $payments) == '-1') { - $data['error_message'] = $this->lang->line('sales_transaction_failed'); + $data['error'] = $this->lang->line('sales_unsuccessfully_suspended_sale'); + } + else + { + $data['success'] = $this->lang->line('sales_successfully_suspended_sale'); } $this->sale_lib->clear_all(); - $this->_reload(array('success' => $this->lang->line('sales_successfully_suspended_sale'))); + $this->_reload($data); } - function suspended() + public function suspended() { $data = array(); - $data['suspended_sales'] = $this->Sale_suspended->get_all()->result_array(); + $data['suspended_sales'] = $this->xss_clean($this->Sale_suspended->get_all()->result_array()); $this->load->view('sales/suspended', $data); } - function unsuspend() + public function unsuspend() { $sale_id = $this->input->post('suspended_sale_id'); + $this->sale_lib->clear_all(); $this->sale_lib->copy_entire_suspended_sale($sale_id); $this->Sale_suspended->delete($sale_id); @@ -838,11 +847,12 @@ class Sales extends Secure_Controller $this->_reload(); } - function check_invoice_number() + public function check_invoice_number() { $sale_id = $this->input->post('sale_id'); $invoice_number = $this->input->post('invoice_number'); - $exists = !empty($invoice_number) && $this->Sale->invoice_number_exists($invoice_number,$sale_id); + $exists = !empty($invoice_number) && $this->Sale->invoice_number_exists($invoice_number, $sale_id); + echo !$exists ? 'true' : 'false'; } } diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index 79b199db0..023de8160 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -62,23 +62,24 @@ function get_sale_data_row($sale, $controller) 'amount_tendered' => to_currency( $sale->amount_tendered ), 'amount_due' => to_currency($sale->amount_due), 'change_due' => to_currency($sale->change_due), - 'payment_type' => $sale->payment_type, - 'invoice_number' => $sale->invoice_number, - 'receipt' => anchor($controller_name."/receipt/$sale->sale_id", '', - array('title'=>$CI->lang->line('sales_show_receipt')) - ), - 'edit' => anchor($controller_name."/edit/$sale->sale_id", '', - array('class'=>"modal-dlg modal-btn-delete modal-btn-submit print_hide", 'title'=>$CI->lang->line($controller_name.'_update')) - ) + 'payment_type' => $sale->payment_type ); - if ($CI->config->item('invoice_enable')) + if($CI->config->item('invoice_enable')) { - $row['invoice'] = anchor($controller_name."/invoice/$sale->sale_id", '', + $row['invoice_number'] = $sale->invoice_number; + $row['invoice'] = empty($sale->invoice_number) ? '' : anchor($controller_name."/invoice/$sale->sale_id", '', array('title'=>$CI->lang->line('sales_show_invoice')) - ); + ); } + $row['receipt'] = anchor($controller_name."/receipt/$sale->sale_id", '', + array('title'=>$CI->lang->line('sales_show_receipt')) + ); + $row['edit'] = anchor($controller_name."/edit/$sale->sale_id", '', + array('class'=>"modal-dlg modal-btn-delete modal-btn-submit print_hide", 'title'=>$CI->lang->line($controller_name.'_update')) + ); + return $row; } diff --git a/application/language/de-CH/sales_lang.php b/application/language/de-CH/sales_lang.php index a8f9e8147..daeab3d71 100644 --- a/application/language/de-CH/sales_lang.php +++ b/application/language/de-CH/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Warnung: Gewünschte Menge ist nicht v $lang["sales_quantity_less_than_reorder_level"] = "Warnung: Gewünschte Menge ist nicht verfügbar."; $lang["sales_receipt"] = "Quittung"; $lang["sales_receipt_number"] = "Quittung Nr."; +$lang["sales_receipt_sent"] = "Quittung gesendet an"; +$lang["sales_receipt_unsent"] = "Quittung nicht gesendet"; $lang["sales_register"] = "Kasse"; $lang["sales_remove_customer"] = "Entferne Kunde"; $lang["sales_return"] = "Retoure"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Kunde:"; $lang["sales_sale_time"] = "Zeit"; $lang["sales_select_customer"] = "Wähle Kunde (optional)"; $lang["sales_send_invoice"] = "Sende Rechnung"; +$lang["sales_send_receipt"] = "Sende Quittung"; $lang["sales_serial"] = "Seriennummer"; $lang["sales_show_invoice"] = "Rechnung"; $lang["sales_show_receipt"] = "Quittung"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Total exkl. MWSt."; $lang["sales_transaction_failed"] = "Verarbeitung fehlerhaft"; $lang["sales_unable_to_add_item"] = "Kann Artikel nicht zum Auftrag hinzufügen"; $lang["sales_unsuccessfully_deleted"] = "Löschung nicht erfolgreich"; +$lang["sales_unsuccessfully_suspended_sale"] = "Auftrag wurde erfolgreich pendent gehalten"; $lang["sales_unsuccessfully_updated"] = "Änderung nicht erfolgreich"; $lang["sales_unsuspend"] = "Aktivieren"; $lang["sales_unsuspend_and_delete"] = "Aktivieren und löschen"; diff --git a/application/language/en/sales_lang.php b/application/language/en/sales_lang.php index 992ca51c6..a295015e2 100644 --- a/application/language/en/sales_lang.php +++ b/application/language/en/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Warning, Desired Quantity is Insuffici $lang["sales_quantity_less_than_reorder_level"] = "Warning, Desired Quantity is below reorder level"; $lang["sales_receipt"] = "Sales Receipt"; $lang["sales_receipt_number"] = "Sale #"; +$lang["sales_receipt_sent"] = "Receipt sent to"; +$lang["sales_receipt_unsent"] = "Receipt failed to be sent to"; $lang["sales_register"] = "Sales Register"; $lang["sales_remove_customer"] = "Remove Customer"; $lang["sales_return"] = "Return"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Customer:"; $lang["sales_sale_time"] = "Time"; $lang["sales_select_customer"] = "Select Customer (Optional)"; $lang["sales_send_invoice"] = "Send Invoice"; +$lang["sales_send_receipt"] = "Send Receipt"; $lang["sales_serial"] = "Serial"; $lang["sales_show_invoice"] = "Show Invoice"; $lang["sales_show_receipt"] = "Show Receipt"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_transaction_failed"] = "Sales Transaction Failed"; $lang["sales_unable_to_add_item"] = "Unable to add item to sale"; $lang["sales_unsuccessfully_deleted"] = "Sale(s) could not be deleted"; +$lang["sales_unsuccessfully_suspended_sale"] = "Your sale has been unsuccessfully suspended"; $lang["sales_unsuccessfully_updated"] = "Sale unsuccessfully updated"; $lang["sales_unsuspend"] = "Unsuspend"; $lang["sales_unsuspend_and_delete"] = ""; diff --git a/application/language/es/sales_lang.php b/application/language/es/sales_lang.php index 880ae89fa..980b8cf0e 100644 --- a/application/language/es/sales_lang.php +++ b/application/language/es/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Advertencia. La cantidad deseada es in $lang["sales_quantity_less_than_reorder_level"] = "Advertencia. La cantidad deseada es insuficiente"; $lang["sales_receipt"] = "Recibo de Venta"; $lang["sales_receipt_number"] = "POS #"; +$lang["sales_receipt_sent"] = "Recibo enviada a"; +$lang["sales_receipt_unsent"] = "Fallo el envio de la recibo a"; $lang["sales_register"] = "Registro de Ventas"; $lang["sales_remove_customer"] = "Borrar Cliente"; $lang["sales_return"] = "Devolución"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Cliente:"; $lang["sales_sale_time"] = "Hora"; $lang["sales_select_customer"] = "Seleccionar Cliente (Opcional)"; $lang["sales_send_invoice"] = "Enviar Factura"; +$lang["sales_send_receipt"] = "Enviar Recibo"; $lang["sales_serial"] = "Serial"; $lang["sales_show_invoice"] = "Factura"; $lang["sales_show_receipt"] = "Recibo"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "No incluye impuestos"; $lang["sales_transaction_failed"] = "La transacción de venta falló"; $lang["sales_unable_to_add_item"] = "No se puede agregar el artículo a la venta"; $lang["sales_unsuccessfully_deleted"] = "Ha fallado la eliminación de la Venta"; +$lang["sales_unsuccessfully_suspended_sale"] = "La venta ha sido suspendida satisfactoriamente"; $lang["sales_unsuccessfully_updated"] = "Ha fallado la actualización de la venta"; $lang["sales_unsuspend"] = "Retomar"; $lang["sales_unsuspend_and_delete"] = "Retomar y Borrar"; diff --git a/application/language/fr/sales_lang.php b/application/language/fr/sales_lang.php index 9a10740a6..fea1f7ff8 100644 --- a/application/language/fr/sales_lang.php +++ b/application/language/fr/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Avertissement, Quantité Demandée Ins $lang["sales_quantity_less_than_reorder_level"] = "Avertissement, Quantité Demandée Insuffisante"; $lang["sales_receipt"] = "Recu de Ventes"; $lang["sales_receipt_number"] = "# Caisse"; +$lang["sales_receipt_sent"] = "Receipt sent to"; +$lang["sales_receipt_unsent"] = "Receipt failed to be sent to"; $lang["sales_register"] = "Registre des Ventes"; $lang["sales_remove_customer"] = "Enlever Client"; $lang["sales_return"] = "Reprise"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Client:"; $lang["sales_sale_time"] = "Time"; $lang["sales_select_customer"] = "Choisir Client (Facultatif)"; $lang["sales_send_invoice"] = "Send Invoice"; +$lang["sales_send_receipt"] = "Send Receipt"; $lang["sales_serial"] = "Serie"; $lang["sales_show_invoice"] = "Show Invoice"; $lang["sales_show_receipt"] = "Show Receipt"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_transaction_failed"] = "Échec de Transaction de vente"; $lang["sales_unable_to_add_item"] = "Erreur d'ajout à la vente"; $lang["sales_unsuccessfully_deleted"] = "Échec de suppression"; +$lang["sales_unsuccessfully_suspended_sale"] = "Vente suspendue"; $lang["sales_unsuccessfully_updated"] = "Échec d'édition"; $lang["sales_unsuspend"] = "Débloquer"; $lang["sales_unsuspend_and_delete"] = ""; diff --git a/application/language/hr-HR/sales_lang.php b/application/language/hr-HR/sales_lang.php index 24d502e0b..a752961a1 100644 --- a/application/language/hr-HR/sales_lang.php +++ b/application/language/hr-HR/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Upozorenje! Željena količina je nedo $lang["sales_quantity_less_than_reorder_level"] = "Upozorenje! Željena količina je ispod minimalne."; $lang["sales_receipt"] = "Račun"; $lang["sales_receipt_number"] = "Račun br."; +$lang["sales_receipt_sent"] = "Račun poslana"; +$lang["sales_receipt_unsent"] = "Račun nije poslana"; $lang["sales_register"] = "Registracija prodaje"; $lang["sales_remove_customer"] = "Ukloni kupca"; $lang["sales_return"] = "Povrat"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Kupac:"; $lang["sales_sale_time"] = "Vrijeme"; $lang["sales_select_customer"] = "Odaberi kupca(neobaveno)"; $lang["sales_send_invoice"] = "Pošalji fakturu"; +$lang["sales_send_receipt"] = "Pošalji račun"; $lang["sales_serial"] = "Serijski broj"; $lang["sales_show_invoice"] = "Pokaži fakturu"; $lang["sales_show_receipt"] = "Pokaži račun"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Porez nije uključen"; $lang["sales_transaction_failed"] = "Greška kod prodaje"; $lang["sales_unable_to_add_item"] = "Artikal nije moguće dodati"; $lang["sales_unsuccessfully_deleted"] = "Prodaju(e) nije moguće izbrisati"; +$lang["sales_unsuccessfully_suspended_sale"] = "Neuspješno brisanje prodaje"; $lang["sales_unsuccessfully_updated"] = "Prodaju(e) nije moguće ažurirati"; $lang["sales_unsuspend"] = "Ponovno uključeno"; $lang["sales_unsuspend_and_delete"] = "Uključeno i obrisano"; diff --git a/application/language/hu-HU/sales_lang.php b/application/language/hu-HU/sales_lang.php index 711c75b4a..b99f1b9ac 100644 --- a/application/language/hu-HU/sales_lang.php +++ b/application/language/hu-HU/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Figyelem, a megadott mennyiség elégt $lang["sales_quantity_less_than_reorder_level"] = "Figyelem, a megadott mennyiség elégtelen!"; $lang["sales_receipt"] = "Eladási nyugta"; $lang["sales_receipt_number"] = "Értékesítési #"; +$lang["sales_receipt_sent"] = "Nyugta elküldve"; +$lang["sales_receipt_unsent"] = "Nyugta sikertelen küldése"; $lang["sales_register"] = "Értékesitési nyilvántartás"; $lang["sales_remove_customer"] = "Vásárló eltávolítása"; $lang["sales_return"] = "Visszavétel"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Vevő:"; $lang["sales_sale_time"] = "Idő"; $lang["sales_select_customer"] = "Vevő kiválasztása (opcionális)"; $lang["sales_send_invoice"] = "Számla küldése"; +$lang["sales_send_receipt"] = "Nyugta küldése"; $lang["sales_serial"] = "Serial"; $lang["sales_show_invoice"] = "számla"; $lang["sales_show_receipt"] = "nyugta"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Adók nélkül"; $lang["sales_transaction_failed"] = "Tranzakció sikertelen"; $lang["sales_unable_to_add_item"] = "Nem adható termék az értékesitéshez"; $lang["sales_unsuccessfully_deleted"] = "Értékesités(ek) nem törölhető(k)"; +$lang["sales_unsuccessfully_suspended_sale"] = "Értékesitése sikeresen felfüggesztve"; $lang["sales_unsuccessfully_updated"] = "Értékesités sikertelenül frissitve"; $lang["sales_unsuspend"] = "Újraaktivál"; $lang["sales_unsuspend_and_delete"] = "Újraaktivál és töröl"; diff --git a/application/language/id/sales_lang.php b/application/language/id/sales_lang.php index 0488bfa73..782d71c82 100644 --- a/application/language/id/sales_lang.php +++ b/application/language/id/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Peringatan!... Stok Inventori Kosong. $lang["sales_quantity_less_than_reorder_level"] = "Peringatan!... Stok Inventori Kosong."; $lang["sales_receipt"] = "Faktur Penjualan"; $lang["sales_receipt_number"] = "POS #"; +$lang["sales_receipt_sent"] = "Receipt sent to"; +$lang["sales_receipt_unsent"] = "Receipt failed to be sent to"; $lang["sales_register"] = "Transaksi Penjualan"; $lang["sales_remove_customer"] = "Hapus Pelanggan"; $lang["sales_return"] = "Retur"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Pelanggan:"; $lang["sales_sale_time"] = "Waktu"; $lang["sales_select_customer"] = "Pilih Pelanggan (Opsional)"; $lang["sales_send_invoice"] = "Send Invoice"; +$lang["sales_send_receipt"] = "Send Receipt"; $lang["sales_serial"] = "Serial"; $lang["sales_show_invoice"] = "Show Invoice"; $lang["sales_show_receipt"] = "Show Receipt"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_transaction_failed"] = "Transaksi Penjualan Salah"; $lang["sales_unable_to_add_item"] = "Tidak dapat menambahkan item dengan penjualan"; $lang["sales_unsuccessfully_deleted"] = "Transaksi Penjualan tidak berhasil dihapus"; +$lang["sales_unsuccessfully_suspended_sale"] = "Penjualan anda telah berhasil ditangguhkan"; $lang["sales_unsuccessfully_updated"] = "Penjualan tidak berhasil diperbarui"; $lang["sales_unsuspend"] = "Batal Penangguhan"; $lang["sales_unsuspend_and_delete"] = "Batalkan dan hapus penangguhan"; diff --git a/application/language/nl-BE/sales_lang.php b/application/language/nl-BE/sales_lang.php index 52d73d4d7..581ef81e0 100755 --- a/application/language/nl-BE/sales_lang.php +++ b/application/language/nl-BE/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Waarschuwing, de gewenste hoeveelheid $lang["sales_quantity_less_than_reorder_level"] = "Waarschuwing, de gewenste hoeveelheid stock is overgeschreden."; $lang["sales_receipt"] = "Ticket #"; $lang["sales_receipt_number"] = "Ticket #"; +$lang["sales_receipt_sent"] = "Ticket verstuurd naar"; +$lang["sales_receipt_unsent"] = "Fout bij het versturen van ticket naar"; $lang["sales_register"] = "Kassa"; $lang["sales_remove_customer"] = "Verwijder Klant"; $lang["sales_return"] = "Retour"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Klant:"; $lang["sales_sale_time"] = "Datum"; $lang["sales_select_customer"] = "Selecteer Klant (Optioneel)"; $lang["sales_send_invoice"] = "Vestuur Factuur"; +$lang["sales_send_receipt"] = "Vestuur Ticket"; $lang["sales_serial"] = "Nummer"; $lang["sales_show_invoice"] = "Factuur"; $lang["sales_show_receipt"] = "Ticket"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Totaal"; $lang["sales_transaction_failed"] = "Transactie mislukt"; $lang["sales_unable_to_add_item"] = "Onmogelijk om product toe te voegen"; $lang["sales_unsuccessfully_deleted"] = "De aankoop kon niet verwijderd worden"; +$lang["sales_unsuccessfully_suspended_sale"] = "Uw aankoop werd met sucess bewaard"; $lang["sales_unsuccessfully_updated"] = "Fout bij het bewaren van ticket"; $lang["sales_unsuspend"] = "Hervat"; $lang["sales_unsuspend_and_delete"] = ""; diff --git a/application/language/pt-BR/sales_lang.php b/application/language/pt-BR/sales_lang.php index 8cf2ac809..6cace4e2b 100644 --- a/application/language/pt-BR/sales_lang.php +++ b/application/language/pt-BR/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Aviso, Quantidade desejado é insufici $lang["sales_quantity_less_than_reorder_level"] = "Aviso, quantidade desejada está abaixo do nível de reabastecimento"; $lang["sales_receipt"] = "Vendas"; $lang["sales_receipt_number"] = "Venda nº"; +$lang["sales_receipt_sent"] = "Enviar recibo para"; +$lang["sales_receipt_unsent"] = "Recibo não devem ser enviados para"; $lang["sales_register"] = "Registar Venda"; $lang["sales_remove_customer"] = "Remover Cliente"; $lang["sales_return"] = "Devolução"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Cliente:"; $lang["sales_sale_time"] = "Data"; $lang["sales_select_customer"] = "Selecionar Cliente (Opcional)"; $lang["sales_send_invoice"] = "Enviar fatura"; +$lang["sales_send_receipt"] = "Enviar recibo"; $lang["sales_serial"] = "Serial"; $lang["sales_show_invoice"] = "fatura"; $lang["sales_show_receipt"] = "recibo"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "taxas excluídas"; $lang["sales_transaction_failed"] = "Falha na transação Vendas"; $lang["sales_unable_to_add_item"] = "Não é possível adicionar item à venda"; $lang["sales_unsuccessfully_deleted"] = "Venda(s) não pode ser excluído"; +$lang["sales_unsuccessfully_suspended_sale"] = "Suspenso com sucesso"; $lang["sales_unsuccessfully_updated"] = "Venda sem sucesso na atualização"; $lang["sales_unsuspend"] = "Não suspenso"; $lang["sales_unsuspend_and_delete"] = "Retornar e apagar"; diff --git a/application/language/ru/sales_lang.php b/application/language/ru/sales_lang.php index 02dc11e51..66e700a78 100644 --- a/application/language/ru/sales_lang.php +++ b/application/language/ru/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Внимание Желаемое ко $lang["sales_quantity_less_than_reorder_level"] = "Внимание Желаемое количество является недостаточным."; $lang["sales_receipt"] = "товарный чек"; $lang["sales_receipt_number"] = "POS #"; +$lang["sales_receipt_sent"] = "Receipt sent to"; +$lang["sales_receipt_unsent"] = "Receipt failed to be sent to"; $lang["sales_register"] = "Продажи журнала"; $lang["sales_remove_customer"] = "Удалите клиентов"; $lang["sales_return"] = "возвращать"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Клиент:"; $lang["sales_sale_time"] = "Time"; $lang["sales_select_customer"] = "Выберите клиента (необязательно)"; $lang["sales_send_invoice"] = "Send Invoice"; +$lang["sales_send_receipt"] = "Send Receipt"; $lang["sales_serial"] = "серийный номер"; $lang["sales_show_invoice"] = "Show Invoice"; $lang["sales_show_receipt"] = "Show Receipt"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_transaction_failed"] = "Транзакция не удалось"; $lang["sales_unable_to_add_item"] = "Невозможно добавить товар продажи"; $lang["sales_unsuccessfully_deleted"] = "продажи безуспешно удален"; +$lang["sales_unsuccessfully_suspended_sale"] = "Ваши продажи успешно приостановлена"; $lang["sales_unsuccessfully_updated"] = "Продажа безуспешно обновлен"; $lang["sales_unsuspend"] = "Разблокировать"; $lang["sales_unsuspend_and_delete"] = "Разблокировать и удалить"; diff --git a/application/language/th/sales_lang.php b/application/language/th/sales_lang.php index 40c5604f6..ec8d9ec85 100644 --- a/application/language/th/sales_lang.php +++ b/application/language/th/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "คำเตือน ถ้าจำ $lang["sales_quantity_less_than_reorder_level"] = "คำเตือน ถ้าจำนวนของไม่เพียงพอกับความต้องการหรือไม่ตรงกับยอดในบันชี ก็สามารถทำการขายได้ แต่ต้องเชคปริมานสินค้าคงคลัง"; $lang["sales_receipt"] = "บิลขาย"; $lang["sales_receipt_number"] = "จุดขาย#"; +$lang["sales_receipt_sent"] = "Receipt sent to"; +$lang["sales_receipt_unsent"] = "Receipt failed to be sent to"; $lang["sales_register"] = "ลงทะเบียนขาย"; $lang["sales_remove_customer"] = "ลบลูกค้า"; $lang["sales_return"] = "คืน"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "ลูกค้า:"; $lang["sales_sale_time"] = "เวลา"; $lang["sales_select_customer"] = "เลือกลูกค้า (Optional)"; $lang["sales_send_invoice"] = "ส่งใบแจ้งหนี้"; +$lang["sales_send_receipt"] = "Send Receipt"; $lang["sales_serial"] = "Serial"; $lang["sales_show_invoice"] = "ใบแจ้งหนี้"; $lang["sales_show_receipt"] = "ใบเสร็จ"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_transaction_failed"] = "การดำเนินการขายล้มเหลว"; $lang["sales_unable_to_add_item"] = ""; $lang["sales_unsuccessfully_deleted"] = "ลบการขายไม่สำเร็จ"; +$lang["sales_unsuccessfully_suspended_sale"] = "การขายของคุณถูกระงับเรียบร้อย"; $lang["sales_unsuccessfully_updated"] = "อัพเดทการขายไม่สมบูรณ์"; $lang["sales_unsuspend"] = "ยกเลิกการระงับ"; $lang["sales_unsuspend_and_delete"] = "ยกเลิกการระงับ และ ลบ"; diff --git a/application/language/tr/sales_lang.php b/application/language/tr/sales_lang.php index 8f331fec0..ca908495c 100644 --- a/application/language/tr/sales_lang.php +++ b/application/language/tr/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "Dikkat, İstenen stok yetersiz. Satı $lang["sales_quantity_less_than_reorder_level"] = "Dikkat, İstenen stok yetersiz."; $lang["sales_receipt"] = "Satış Faturası"; $lang["sales_receipt_number"] = ""; +$lang["sales_receipt_sent"] = "Receipt sent to"; +$lang["sales_receipt_unsent"] = "Receipt failed to be sent to"; $lang["sales_register"] = "Satış Kaydı"; $lang["sales_remove_customer"] = "Müşteriyi Kaldır"; $lang["sales_return"] = "İade"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "Müşteri:"; $lang["sales_sale_time"] = "Saat"; $lang["sales_select_customer"] = "Müşteri Seç (İsteğe Bağlı)"; $lang["sales_send_invoice"] = "Send Invoice"; +$lang["sales_send_receipt"] = "Send Receipt"; $lang["sales_serial"] = "Seri"; $lang["sales_show_invoice"] = "Show Invoice"; $lang["sales_show_receipt"] = "Show Receipt"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_transaction_failed"] = "Satış işlemi hatası"; $lang["sales_unable_to_add_item"] = "Ürün satışa eklenemedi"; $lang["sales_unsuccessfully_deleted"] = "Satış silinemedi"; +$lang["sales_unsuccessfully_suspended_sale"] = "Satış askıya alındı"; $lang["sales_unsuccessfully_updated"] = "Satış düzenlenemedi"; $lang["sales_unsuspend"] = "Satışa Al"; $lang["sales_unsuspend_and_delete"] = ""; diff --git a/application/language/zh/sales_lang.php b/application/language/zh/sales_lang.php index 39d8c9df9..840f822a4 100755 --- a/application/language/zh/sales_lang.php +++ b/application/language/zh/sales_lang.php @@ -83,6 +83,8 @@ $lang["sales_quantity_less_than_zero"] = "警告!產品的庫存數量是不 $lang["sales_quantity_less_than_reorder_level"] = "警告!產品的庫存數量是不足的。您仍然可以處理銷售,但檢查您的庫存"; $lang["sales_receipt"] = "銷貨單"; $lang["sales_receipt_number"] = "POS #"; +$lang["sales_receipt_sent"] = "Receipt sent to"; +$lang["sales_receipt_unsent"] = "Receipt failed to be sent to"; $lang["sales_register"] = "銷售登記"; $lang["sales_remove_customer"] = "移除客戶"; $lang["sales_return"] = "退貨"; @@ -91,6 +93,7 @@ $lang["sales_sale_for_customer"] = "客戶:"; $lang["sales_sale_time"] = "Time"; $lang["sales_select_customer"] = "選擇客戶 (Optional)"; $lang["sales_send_invoice"] = "Send Invoice"; +$lang["sales_send_receipt"] = "Send Receipt"; $lang["sales_serial"] = "序號"; $lang["sales_show_invoice"] = "Show Invoice"; $lang["sales_show_receipt"] = "Show Receipt"; @@ -111,6 +114,7 @@ $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_transaction_failed"] = "銷售交易失敗"; $lang["sales_unable_to_add_item"] = "無法增加出售產品"; $lang["sales_unsuccessfully_deleted"] = "銷售資料刪除失敗"; +$lang["sales_unsuccessfully_suspended_sale"] = "本銷售資料已經成功暫停"; $lang["sales_unsuccessfully_updated"] = "銷售資料更新失敗"; $lang["sales_unsuspend"] = "取消暫停銷售"; $lang["sales_unsuspend_and_delete"] = "取消暫停銷售並刪除"; diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index c6d03e391..24f51d964 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -20,7 +20,7 @@ class Sale_lib function set_cart($cart_data) { - $this->CI->session->set_userdata('cart',$cart_data); + $this->CI->session->set_userdata('cart', $cart_data); } // Multiple Payments @@ -79,8 +79,9 @@ class Sale_lib function is_invoice_number_enabled() { - return $this->CI->session->userdata('sales_invoice_number_enabled') == 'true' || - $this->CI->session->userdata('sales_invoice_number_enabled') == '1'; + return ($this->CI->session->userdata('sales_invoice_number_enabled') == 'true' || + $this->CI->session->userdata('sales_invoice_number_enabled') == '1') && + $this->CI->config->item('invoice_enable') == TRUE; } function set_invoice_number_enabled($invoice_number_enabled) @@ -90,8 +91,8 @@ class Sale_lib function is_print_after_sale() { - return $this->CI->session->userdata('sales_print_after_sale') == 'true' || - $this->CI->session->userdata('sales_print_after_sale') == '1'; + return ($this->CI->session->userdata('sales_print_after_sale') == 'true' || + $this->CI->session->userdata('sales_print_after_sale') == '1'); } function set_print_after_sale($print_after_sale) @@ -125,7 +126,7 @@ class Sale_lib else { //add to existing array - $payment = array($payment_id=>array('payment_type' => $payment_id, 'payment_amount' => $payment_amount)); + $payment = array($payment_id => array('payment_type' => $payment_id, 'payment_amount' => $payment_amount)); $payments += $payment; } @@ -272,7 +273,7 @@ class Sale_lib $itemalreadyinsale = FALSE; //We did not find the item yet. $insertkey = 0; //Key to use for new entry. $updatekey = 0; //Key to use to update(quantity) - $item_info = $this->CI->Item->get_info($item_id,$item_location); + $item_info = $this->CI->Item->get_info($item_id, $item_location); foreach($items as $item) { //We primed the loop so maxkey is 0 the first time. @@ -283,7 +284,7 @@ class Sale_lib $maxkey = $item['line']; } - if($item['item_id'] == $item_id && $item['item_location']==$item_location) + if($item['item_id'] == $item_id && $item['item_location'] == $item_location) { $itemalreadyinsale = TRUE; $updatekey = $item['line']; @@ -302,8 +303,7 @@ class Sale_lib //Item already exists and is not serialized, add to quantity if(!$itemalreadyinsale || $item_info->is_serialized) { - $item = array(($insertkey)=> - array( + $item = array($insertkey => array( 'item_id'=>$item_id, 'item_location'=>$item_location, 'stock_name'=>$this->CI->Stock_location->get_location_name($item_location), @@ -513,7 +513,7 @@ class Sale_lib function delete_item($line) { - $items=$this->get_cart(); + $items = $this->get_cart(); unset($items[$line]); $this->set_cart($items); } @@ -589,7 +589,7 @@ class Sale_lib $discount = 0; foreach($this->get_cart() as $line=>$item) { - if ($item['discount'] > 0) + if($item['discount'] > 0) { $item_discount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount']); $discount = bcadd($discount, $item_discount, PRECISION); @@ -622,7 +622,7 @@ class Sale_lib function get_item_total($quantity, $price, $discount_percentage, $include_discount=FALSE) { $total = bcmul($quantity, $price, PRECISION); - if ($include_discount) + if($include_discount) { $discount_amount = $this->get_item_discount($quantity, $price, $discount_percentage); @@ -662,7 +662,7 @@ class Sale_lib $subtotal = 0; foreach($this->get_cart() as $item) { - if ($exclude_tax && $this->CI->config->config['tax_included']) + if($exclude_tax && $this->CI->config->config['tax_included']) { $subtotal = bcadd($subtotal, $this->get_item_total_tax_exclusive($item['item_id'], $item['quantity'], $item['price'], $item['discount'], $include_discount), PRECISION); } @@ -678,7 +678,7 @@ class Sale_lib function get_total() { $total = $this->calculate_subtotal(TRUE); - if (!$this->CI->config->config['tax_included']) + if(!$this->CI->config->config['tax_included']) { foreach($this->get_taxes() as $tax) { diff --git a/application/models/Sale.php b/application/models/Sale.php index 2450c607c..1a6d8f377 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -501,7 +501,7 @@ class Sale extends CI_Model $this->db->where('sale_id !=', $sale_id); } - return ($this->db->get()->num_rows()==1); + return ($this->db->get()->num_rows() == 1); } public function get_giftcard_value($giftcardNumber) diff --git a/application/views/sales/form.php b/application/views/sales/form.php index 0a19d6c1c..72f34b27e 100755 --- a/application/views/sales/form.php +++ b/application/views/sales/form.php @@ -38,7 +38,7 @@ result() as $row) + foreach($payments as $row) { ?>
@@ -97,14 +97,14 @@ + load->view('partial/print_receipt', array('print_after_sale'=>$print_after_sale, 'selected_printer'=>'invoice_printer')); ?>
diff --git a/application/views/sales/invoice_email.php b/application/views/sales/invoice_email.php index e48248849..e807e287c 100644 --- a/application/views/sales/invoice_email.php +++ b/application/views/sales/invoice_email.php @@ -19,7 +19,7 @@ if (isset($error_message))