From 0f773001316f4aaeb02102c6d12094dc44940758 Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Fri, 20 Feb 2015 15:54:13 +0100 Subject: [PATCH] Sales overview added to register screen Add pagination to default search routine Remove payment_type column from sales table (was redundant) Fix search spinner location (just toggle ac_loading class) Complete sale labels --- application/controllers/sales.php | 80 +++++++++- application/controllers/secure_area.php | 8 + application/helpers/table_helper.php | 73 +++++++++ application/language/en/common_lang.php | 1 + application/language/en/sales_lang.php | 9 ++ application/language/es/common_lang.php | 1 + application/language/es/sales_lang.php | 11 +- application/language/fr/common_lang.php | 1 + application/language/fr/sales_lang.php | 9 ++ application/language/id/common_lang.php | 1 + application/language/id/sales_lang.php | 9 ++ application/language/nl-BE/common_lang.php | 1 + application/language/nl-BE/sales_lang.php | 9 ++ application/language/ru/common_lang.php | 1 + application/language/ru/sales_lang.php | 9 ++ application/language/th/common_lang.php | 1 + application/language/th/sales_lang.php | 9 ++ application/language/tr/common_lang.php | 1 + application/language/tr/sales_lang.php | 9 ++ application/language/zh/common_lang.php | 1 + application/language/zh/sales_lang.php | 9 ++ application/models/sale.php | 149 +++++++++++++++-- application/views/items/manage.php | 2 +- application/views/sales/manage.php | 176 +++++++++++++++++++++ application/views/sales/receipt.php | 2 +- application/views/sales/register.php | 3 + css/invoice.css | 2 +- css/register.css | 6 + database/2.3.1_to_2.3.2.sql | 6 +- database/database.sql | 3 +- js/manage_tables.js | 77 ++++++--- translations/common_lang.csv | 1 + translations/sales_lang.csv | 11 +- 33 files changed, 637 insertions(+), 54 deletions(-) create mode 100755 application/views/sales/manage.php diff --git a/application/controllers/sales.php b/application/controllers/sales.php index cc078cc48..cec3b0bcc 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -13,6 +13,72 @@ class Sales extends Secure_area { $this->_reload(); } + + function manage($payment_type = 0, $limit_from = 0) + { + $data['controller_name']=strtolower($this->uri->segment(1)); + $data['payment_types'] = array($this->lang->line('sales_no_filter'), $this->lang->line('sales_invoice')); + $data['search_section_state']=$this->input->post('search_section_state'); + + $lines_per_page = $this->Appconfig->get('lines_per_page'); + $sales = $this->Sale->get_all($payment_type,$lines_per_page,$limit_from); + $total_rows = $this->Sale->get_found_rows($payment_type); + $data['payment_type'] = $payment_type; + $data['links'] = $this->_initialize_pagination($payment_type, $lines_per_page, $limit_from, $total_rows); + + $data['manage_table']=get_sales_manage_table($sales,$this); + $this->load->view($data['controller_name'] . '/manage',$data); + $this->_remove_duplicate_cookies(); + } + + function get_row() + { + $sale_id = $this->input->post('row_id'); + $sale_info = $this->Sale->get_info($sale_id)->result_array(); + $data_row=get_sale_data_row($sale_info[0],$this); + echo $data_row; + } + + function _initialize_pagination($payment_type, $lines_per_page, $limit_from = 0, $total_rows = 0) + { + $this->load->library('pagination'); + $config['base_url'] = site_url($this->get_controller_name() . '/manage/' . $payment_type); + $config['total_rows'] = $total_rows; + $config['per_page'] = $lines_per_page; + $config['num_links'] = 2; + $config['last_link'] = $this->lang->line('common_last_page'); + $config['first_link'] = $this->lang->line('common_first_page'); + // page is calculated here instead of in pagination lib + $config['cur_page'] = $limit_from > 0 ? $limit_from : 0; + $config['page_query_string'] = FALSE; + $config['uri_segment'] = 0; + $this->pagination->initialize($config); + return $this->pagination->create_links(); + } + + /** + * + * Get the width for the add/edit form. + * @return number The form width + */ + function get_form_width() + { + return 400; + } + + function search() + { + $payment_type = $this->input->post('payment_type', TRUE); + $limit_from = $this->input->post('limit_from', TRUE); + $search = $this->input->post('search', TRUE); + $lines_per_page = $this->Appconfig->get('lines_per_page'); + $sales = $this->Sale->search($search, $payment_type, $lines_per_page, $limit_from, $search); + $total_rows = $this->Sale->get_found_rows($search); + $links = $this->_initialize_pagination($payment_type, $lines_per_page, $limit_from, $total_rows); + $data_rows=get_sales_manage_table_data_rows($sales,$this); + echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links)); + $this->_remove_duplicate_cookies(); + } function item_search() { @@ -26,6 +92,14 @@ class Sales extends Secure_area $suggestions = $this->Customer->get_customer_search_suggestions($this->input->post('q'),$this->input->post('limit')); echo implode("\n",$suggestions); } + + function suggest() + { + $search = $this->input->post('q', TRUE); + $limit = $this->input->post('limit', TRUE); + $suggestions = $this->Sale->get_search_suggestions($search, $limit); + echo implode("\n",$suggestions); + } function select_customer() { @@ -487,12 +561,6 @@ class Sales extends Secure_area { $data = array(); - $data['customers'] = array('' => 'No Customer'); - foreach ($this->Customer->get_all()->result() as $customer) - { - $data['customers'][$customer->person_id] = $customer->first_name . ' '. $customer->last_name; - } - $data['employees'] = array(); foreach ($this->Employee->get_all()->result() as $employee) { diff --git a/application/controllers/secure_area.php b/application/controllers/secure_area.php index bbf6bf2d7..ebbe6416a 100644 --- a/application/controllers/secure_area.php +++ b/application/controllers/secure_area.php @@ -1,6 +1,9 @@ controller_name=$module_id; $this->load->vars($data); } + function get_controller_name() { + return strtolower($this->controller_name); + } + function _remove_duplicate_cookies () { //php < 5.3 doesn't have header remove so this function will fatal error otherwise diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index d62ec78d7..d4468c8df 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -1,4 +1,77 @@ '; + + $headers = array(' ', + $CI->lang->line('sales_sale_time'), + $CI->lang->line('customers_customer'), + $CI->lang->line('sales_amount_tendered'), + $CI->lang->line('sales_amount_due'), + $CI->lang->line('sales_receipt_number'), + $CI->lang->line('sales_invoice_number'), + ' '); + + $table.=''; + foreach($headers as $header) + { + $table.="$header"; + } + $table.=''; + $table.=get_sales_manage_table_data_rows($sales,$controller); + $table.=''; + return $table; +} + +/* + Gets the html data rows for the people. + */ +function get_sales_manage_table_data_rows($sales,$controller) +{ + $CI =& get_instance(); + $table_data_rows=''; + + foreach($sales->result_array() as $sale) + { + $table_data_rows.=get_sale_data_row($sale,$controller); + } + + if($sales->num_rows()==0) + { + $table_data_rows.="
".$CI->lang->line('sales_no_sales_to_display')."
"; + } + + return $table_data_rows; +} + +function get_sale_data_row($sale,$controller) +{ + $CI =& get_instance(); + $controller_name=$CI->uri->segment(1); + $width = $controller->get_form_width(); + + $table_data_row=''; + $table_data_row.=''; + $table_data_row.=''.date('d/m/Y H:i' , strtotime($sale[ 'sale_time' ])).''; + $table_data_row.=''.character_limiter( $sale[ 'last_name' ] . " " . $sale[ 'first_name' ] ,25).''; + $table_data_row.=''.to_currency( $sale[ 'amount_tendered' ] ).''; + $table_data_row.=''.to_currency( $sale[ 'amount_due' ] ).''; + $table_data_row.=''.'Ticket ' . $sale[ 'sale_id' ]. ''; + $table_data_row.=''.$sale[ 'invoice_number' ].''; + $table_data_row.=''; + $table_data_row.=anchor($controller_name."/edit/" . $sale[ 'sale_id' ] . "/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))); + $table_data_row.='    '; + $table_data_row.='' . $CI->lang->line('sales_show_receipt') . ''; + $table_data_row.='    '; + $table_data_row.='' . $CI->lang->line('sales_show_invoice') . ''; + $table_data_row.=''; + $table_data_row.=''; + + return $table_data_row; +} + /* Gets the html table to manage people. */ diff --git a/application/language/en/common_lang.php b/application/language/en/common_lang.php index 2cb9fb549..9cb720418 100644 --- a/application/language/en/common_lang.php +++ b/application/language/en/common_lang.php @@ -44,3 +44,4 @@ $lang["common_gender"] = "Gender"; $lang["common_gender_male"] = "M"; $lang["common_gender_female"] = "F"; $lang["common_date"] = "Date"; +$lang["common_search_options"] = "Search options"; diff --git a/application/language/en/sales_lang.php b/application/language/en/sales_lang.php index 2888f9ae7..11b9b4901 100644 --- a/application/language/en/sales_lang.php +++ b/application/language/en/sales_lang.php @@ -99,3 +99,12 @@ $lang["sales_invoice_confirm"] = "This invoice will be sent to"; $lang["sales_invoice_no_email"] = "This customer does not have a valid email address"; $lang["sales_invoice_sent"] = "Invoice sent to"; $lang["sales_invoice_unsent"] = "Invoice failed to be sent to"; +$lang["sales_invoice_filter"] = "Invoices"; +$lang["sales_no_filter"] = "All"; +$lang["sales_no_sales_to_display"] = "No sales to display"; +$lang["sales_show_invoice"] = "invoice"; +$lang["sales_show_receipt"] = "receipt"; +$lang["sales_invoice_filter"] = "Filter sales for "; +$lang["sales_overview"] = "Overview"; +$lang["sales_update"] = "Edit Sale"; +$lang["sales_confirm_delete"] = "Are you sure you want to delete the selected sales?"; diff --git a/application/language/es/common_lang.php b/application/language/es/common_lang.php index a9c39fb36..f0c2e8587 100644 --- a/application/language/es/common_lang.php +++ b/application/language/es/common_lang.php @@ -44,3 +44,4 @@ $lang["common_gender"] = "Gender"; $lang["common_gender_male"] = "M"; $lang["common_gender_female"] = "F"; $lang["common_date"] = "Date"; +$lang["common_search_options"] = "Search options"; diff --git a/application/language/es/sales_lang.php b/application/language/es/sales_lang.php index f22d86477..075af16e7 100644 --- a/application/language/es/sales_lang.php +++ b/application/language/es/sales_lang.php @@ -92,10 +92,19 @@ $lang["sales_unsuspend_and_delete"] = "Retomar y Borrar"; $lang["sales_giftcard_balance"] = "Giftcard Balance"; $lang["sales_discount_included"] = "% discount included"; $lang["sales_print_after_sale"] = "Imprimir recibo después de una venta"; -$lang["sales_invoice"] = "Invoice"; +$lang["sales_invoice"] = "tarjeta de Crédito"; $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_send_invoice"] = "Send Invoice"; $lang["sales_invoice_confirm"] = "This invoice will be sent to"; $lang["sales_invoice_no_email"] = "This customer does not have a valid email address"; $lang["sales_invoice_sent"] = "Invoice sent to"; $lang["sales_invoice_unsent"] = "Invoice failed to be sent to"; +$lang["sales_invoice_filter"] = "Invoices"; +$lang["sales_no_filter"] = "All"; +$lang["sales_no_sales_to_display"] = "No sales to display"; +$lang["sales_show_invoice"] = "invoice"; +$lang["sales_show_receipt"] = "receipt"; +$lang["sales_invoice_filter"] = "Filter sales for "; +$lang["sales_overview"] = "Overview"; +$lang["sales_update"] = "Edit Sale"; +$lang["sales_confirm_delete"] = "Are you sure you want to delete the selected sales?"; diff --git a/application/language/fr/common_lang.php b/application/language/fr/common_lang.php index 302fafc37..c791a5b49 100644 --- a/application/language/fr/common_lang.php +++ b/application/language/fr/common_lang.php @@ -44,3 +44,4 @@ $lang["common_gender"] = "Gender"; $lang["common_gender_male"] = "M"; $lang["common_gender_female"] = "F"; $lang["common_date"] = "Date"; +$lang["common_search_options"] = "Search options"; diff --git a/application/language/fr/sales_lang.php b/application/language/fr/sales_lang.php index 2eccd781a..e9ee395f0 100644 --- a/application/language/fr/sales_lang.php +++ b/application/language/fr/sales_lang.php @@ -99,3 +99,12 @@ $lang["sales_invoice_confirm"] = "This invoice will be sent to"; $lang["sales_invoice_no_email"] = "This customer does not have a valid email address"; $lang["sales_invoice_sent"] = "Invoice sent to"; $lang["sales_invoice_unsent"] = "Invoice failed to be sent to"; +$lang["sales_invoice_filter"] = "Invoices"; +$lang["sales_no_filter"] = "All"; +$lang["sales_no_sales_to_display"] = "No sales to display"; +$lang["sales_show_invoice"] = "invoice"; +$lang["sales_show_receipt"] = "receipt"; +$lang["sales_invoice_filter"] = "Filter sales for "; +$lang["sales_overview"] = "Overview"; +$lang["sales_update"] = "Edit Sale"; +$lang["sales_confirm_delete"] = "Are you sure you want to delete the selected sales?"; diff --git a/application/language/id/common_lang.php b/application/language/id/common_lang.php index e6d132d61..f039403cd 100644 --- a/application/language/id/common_lang.php +++ b/application/language/id/common_lang.php @@ -44,3 +44,4 @@ $lang["common_gender"] = "Gender"; $lang["common_gender_male"] = "M"; $lang["common_gender_female"] = "V"; $lang["common_date"] = "Date"; +$lang["common_search_options"] = "Search options"; diff --git a/application/language/id/sales_lang.php b/application/language/id/sales_lang.php index 854c7670c..73e2824d9 100644 --- a/application/language/id/sales_lang.php +++ b/application/language/id/sales_lang.php @@ -99,3 +99,12 @@ $lang["sales_invoice_confirm"] = "This invoice will be sent to"; $lang["sales_invoice_no_email"] = "This customer does not have a valid email address"; $lang["sales_invoice_sent"] = "Invoice sent to"; $lang["sales_invoice_unsent"] = "Invoice failed to be sent to"; +$lang["sales_invoice_filter"] = "Invoices"; +$lang["sales_no_filter"] = "All"; +$lang["sales_no_sales_to_display"] = "No sales to display"; +$lang["sales_show_invoice"] = "invoice"; +$lang["sales_show_receipt"] = "receipt"; +$lang["sales_invoice_filter"] = "Filter sales for "; +$lang["sales_overview"] = "Overview"; +$lang["sales_update"] = "Edit Sale"; +$lang["sales_confirm_delete"] = "Are you sure you want to delete the selected sales?"; diff --git a/application/language/nl-BE/common_lang.php b/application/language/nl-BE/common_lang.php index 234647a7a..e447e7cce 100755 --- a/application/language/nl-BE/common_lang.php +++ b/application/language/nl-BE/common_lang.php @@ -44,3 +44,4 @@ $lang["common_gender"] = "Geslacht"; $lang["common_gender_male"] = "M"; $lang["common_gender_female"] = "V"; $lang["common_date"] = "Datum"; +$lang["common_search_options"] = "Zoek criteria"; diff --git a/application/language/nl-BE/sales_lang.php b/application/language/nl-BE/sales_lang.php index 77bd7be5d..123452277 100755 --- a/application/language/nl-BE/sales_lang.php +++ b/application/language/nl-BE/sales_lang.php @@ -99,3 +99,12 @@ $lang["sales_invoice_confirm"] = "Deze factuur zal verstuurd worden naar"; $lang["sales_invoice_no_email"] = "Er werd geen email adres gevonden voor deze klant"; $lang["sales_invoice_sent"] = "Factuur verstuurd naar"; $lang["sales_invoice_unsent"] = "Fout bij het versturen van factuur naar"; +$lang["sales_invoice_filter"] = "Facturen"; +$lang["sales_no_filter"] = "Alle"; +$lang["sales_no_sales_to_display"] = "Er werden geen aankopen gevonden"; +$lang["sales_show_invoice"] = "factuur"; +$lang["sales_show_receipt"] = "ticket"; +$lang["sales_invoice_filter"] = "Filter tickets op "; +$lang["sales_overview"] = "Overzicht"; +$lang["sales_update"] = "Bewerk Ticket"; +$lang["sales_confirm_delete"] = "Bent u zeker dat u de geselecteerde aankopen wil verwijderen?"; diff --git a/application/language/ru/common_lang.php b/application/language/ru/common_lang.php index 865dca95a..489bfe239 100644 --- a/application/language/ru/common_lang.php +++ b/application/language/ru/common_lang.php @@ -44,3 +44,4 @@ $lang["common_gender"] = "Gender"; $lang["common_gender_male"] = "M"; $lang["common_gender_female"] = "V"; $lang["common_date"] = "Date"; +$lang["common_search_options"] = "Search options"; diff --git a/application/language/ru/sales_lang.php b/application/language/ru/sales_lang.php index fadbea031..2e208dc0e 100644 --- a/application/language/ru/sales_lang.php +++ b/application/language/ru/sales_lang.php @@ -99,3 +99,12 @@ $lang["sales_invoice_confirm"] = "This invoice will be sent to"; $lang["sales_invoice_no_email"] = "This customer does not have a valid email address"; $lang["sales_invoice_sent"] = "Invoice sent to"; $lang["sales_invoice_unsent"] = "Invoice failed to be sent to"; +$lang["sales_invoice_filter"] = "Invoices"; +$lang["sales_no_filter"] = "All"; +$lang["sales_no_sales_to_display"] = "No sales to display"; +$lang["sales_show_invoice"] = "invoice"; +$lang["sales_show_receipt"] = "receipt"; +$lang["sales_invoice_filter"] = "Filter sales for "; +$lang["sales_overview"] = "Overview"; +$lang["sales_update"] = "Edit Sale"; +$lang["sales_confirm_delete"] = "Are you sure you want to delete the selected sales?"; diff --git a/application/language/th/common_lang.php b/application/language/th/common_lang.php index 7ea6c488c..f9be337c0 100644 --- a/application/language/th/common_lang.php +++ b/application/language/th/common_lang.php @@ -44,3 +44,4 @@ $lang["common_gender"] = "Gender"; $lang["common_gender_male"] = "M"; $lang["common_gender_female"] = "V"; $lang["common_date"] = "Date"; +$lang["common_search_options"] = "Search options"; diff --git a/application/language/th/sales_lang.php b/application/language/th/sales_lang.php index c1015515b..3294932f7 100644 --- a/application/language/th/sales_lang.php +++ b/application/language/th/sales_lang.php @@ -99,3 +99,12 @@ $lang["sales_invoice_confirm"] = "This invoice will be sent to"; $lang["sales_invoice_no_email"] = "This customer does not have a valid email address"; $lang["sales_invoice_sent"] = "Invoice sent to"; $lang["sales_invoice_unsent"] = "Invoice failed to be sent to"; +$lang["sales_invoice_filter"] = "Invoices"; +$lang["sales_no_filter"] = "All"; +$lang["sales_no_sales_to_display"] = "No sales to display"; +$lang["sales_show_invoice"] = "invoice"; +$lang["sales_show_receipt"] = "receipt"; +$lang["sales_invoice_filter"] = "Filter sales for "; +$lang["sales_overview"] = "Overview"; +$lang["sales_update"] = "Edit Sale"; +$lang["sales_confirm_delete"] = "Are you sure you want to delete the selected sales?"; diff --git a/application/language/tr/common_lang.php b/application/language/tr/common_lang.php index bdf66d6d0..f1cd67a61 100644 --- a/application/language/tr/common_lang.php +++ b/application/language/tr/common_lang.php @@ -44,3 +44,4 @@ $lang["common_gender"] = "Gender"; $lang["common_gender_male"] = "M"; $lang["common_gender_female"] = "V"; $lang["common_date"] = "Date"; +$lang["common_search_options"] = "Search options"; diff --git a/application/language/tr/sales_lang.php b/application/language/tr/sales_lang.php index 45736b99a..590fab234 100644 --- a/application/language/tr/sales_lang.php +++ b/application/language/tr/sales_lang.php @@ -99,3 +99,12 @@ $lang["sales_invoice_confirm"] = "This invoice will be sent to"; $lang["sales_invoice_no_email"] = "This customer does not have a valid email address"; $lang["sales_invoice_sent"] = "Invoice sent to"; $lang["sales_invoice_unsent"] = "Invoice failed to be sent to"; +$lang["sales_invoice_filter"] = "Invoices"; +$lang["sales_no_filter"] = "All"; +$lang["sales_no_sales_to_display"] = "No sales to display"; +$lang["sales_show_invoice"] = "invoice"; +$lang["sales_show_receipt"] = "receipt"; +$lang["sales_invoice_filter"] = "Filter sales for "; +$lang["sales_overview"] = "Overview"; +$lang["sales_update"] = "Edit Sale"; +$lang["sales_confirm_delete"] = "Are you sure you want to delete the selected sales?"; diff --git a/application/language/zh/common_lang.php b/application/language/zh/common_lang.php index ec0b067d4..e30666405 100755 --- a/application/language/zh/common_lang.php +++ b/application/language/zh/common_lang.php @@ -44,3 +44,4 @@ $lang["common_gender"] = "Gender"; $lang["common_gender_male"] = "M"; $lang["common_gender_female"] = "V"; $lang["common_date"] = "Date"; +$lang["common_search_options"] = "Search options"; diff --git a/application/language/zh/sales_lang.php b/application/language/zh/sales_lang.php index 191e9f6da..f36ad537b 100755 --- a/application/language/zh/sales_lang.php +++ b/application/language/zh/sales_lang.php @@ -99,3 +99,12 @@ $lang["sales_invoice_confirm"] = "This invoice will be sent to"; $lang["sales_invoice_no_email"] = "This customer does not have a valid email address"; $lang["sales_invoice_sent"] = "Invoice sent to"; $lang["sales_invoice_unsent"] = "Invoice failed to be sent to"; +$lang["sales_invoice_filter"] = "Invoices"; +$lang["sales_no_filter"] = "All"; +$lang["sales_no_sales_to_display"] = "No sales to display"; +$lang["sales_show_invoice"] = "invoice"; +$lang["sales_show_receipt"] = "receipt"; +$lang["sales_invoice_filter"] = "Filter sales for "; +$lang["sales_overview"] = "Overview"; +$lang["sales_update"] = "Edit Sale"; +$lang["sales_confirm_delete"] = "Are you sure you want to delete the selected sales?"; diff --git a/application/models/sale.php b/application/models/sale.php index da295e323..85cc85dbe 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -3,12 +3,139 @@ class Sale extends CI_Model { public function get_info($sale_id) { + $this->db->select('first_name, last_name, email, comment, invoice_number, amount_tendered, ' . + 'sale_time, employee_id, customer_id, comments'); + $this->db->select("DATE_FORMAT( sale_time, '%d-%m-%Y' ) AS sale_date", FALSE); + $this->db->select("sales.sale_id AS sale_id"); + $this->db->select("SUM(item_unit_price * quantity_purchased * (1 - discount_percent / 100)) AS amount_due"); $this->db->from('sales'); - $this->db->join('people', 'people.person_id = sales.customer_id', 'LEFT'); - $this->db->where('sale_id',$sale_id); + $this->db->join('people', 'people.person_id = sales.customer_id', 'left'); + $this->db->join('sales_items', 'sales_items.sale_id = sales.sale_id'); + $this->db->join("(SELECT sale_id, SUM(payment_amount) AS amount_tendered " . + " FROM " . $this->db->dbprefix('sales_payments') ." WHERE payment_type <> '" . + $this->lang->line('sales_check') . "' GROUP BY sale_id) AS payments", + "payments.sale_id = sales.sale_id", 'left'); + $this->db->where('sales.sale_id',$sale_id); + $this->db->order_by('sale_time', 'desc'); + $this->db->group_by('sale_id'); return $this->db->get(); } + function get_all($only_invoices = 0, $rows = 0, $limit_from = 0) + { + $this->db->select('first_name, last_name, invoice_number, amount_tendered, sale_time'); + $this->db->select("DATE_FORMAT( sale_time, '%d-%m-%Y' ) AS sale_date", FALSE); + $this->db->select("sales.sale_id AS sale_id"); + $this->db->select("SUM(item_unit_price * quantity_purchased * (1 - discount_percent / 100)) AS amount_due"); + $this->db->from('sales'); + $this->db->join('people', 'people.person_id = sales.customer_id', 'left'); + $this->db->join('sales_items', 'sales_items.sale_id = sales.sale_id'); + $this->db->join("(SELECT sale_id, SUM(payment_amount) AS amount_tendered " . + " FROM " . $this->db->dbprefix('sales_payments') ." WHERE payment_type <> '" . + $this->lang->line('sales_check') . "' GROUP BY sale_id) AS payments", + "payments.sale_id = sales.sale_id", 'left'); + $this->db->order_by('sale_time', 'desc'); + $this->db->group_by('sale_id'); + if ($rows > 0) { + $this->db->limit($rows, $limit_from); + } + if ($only_invoices != 0) { + $this->db->where('invoice_number <> ', 'NULL'); + } + return $this->db->get(); + } + + function search($search, $only_invoices = FALSE, $rows = 0, $limit_from = 0) + { + $valid_receipt = $this->sale_lib->is_valid_receipt($search); + $this->db->select('first_name, last_name, invoice_number, amount_tendered, sale_time'); + $this->db->select("DATE_FORMAT( sale_time, '%d-%m-%Y' ) AS sale_date", FALSE); + $this->db->select("sales.sale_id AS sale_id"); + $this->db->select("SUM(item_unit_price * quantity_purchased * (1 - discount_percent / 100)) AS amount_due"); + $this->db->from('sales'); + $this->db->join('people', 'people.person_id = sales.customer_id', 'left'); + $this->db->join('sales_items', 'sales_items.sale_id = sales.sale_id'); + $this->db->join("(SELECT sale_id, SUM(payment_amount) AS amount_tendered " . + " FROM " . $this->db->dbprefix('sales_payments') ." WHERE payment_type <> '" . + $this->lang->line('sales_check') . "' GROUP BY sale_id) AS payments", + "payments.sale_id = sales.sale_id", 'left'); + $this->db->group_by('sale_id'); + if (!empty($search)) { + // if barcode scanned, explode and search for second term which will be the id + if ($valid_receipt) { + $pieces = explode(' ',$search); + $this->db->where('sales.sale_id', $pieces[1]); + } else { + // open parentheses + $this->db->where("( last_name LIKE '%" . $search . "%' OR ". + "first_name LIKE '%" . $search . "%' OR " . + "CONCAT( first_name,' ',last_name ) LIKE '%" . $search . "%')"); + // close parentheses + } + } + if ($only_invoices != 0) { + $this->db->where('invoice_number <> ', 'NULL'); + } + $this->db->order_by('sale_time DESC'); + if ($rows > 0) { + $this->db->limit($rows, $limit_from); + } + return $this->db->get(); + } + + function get_search_suggestions($search,$limit=25) + { + $suggestions = array(); + + if (!$this->sale_lib->is_valid_receipt($search)) { + $this->db->distinct(); + $this->db->select('first_name, last_name, invoice_number, sale_time'); + $this->db->select("DATE_FORMAT( sale_time, '%d-%m-%Y' ) AS sale_date", FALSE); + $this->db->select("sales.sale_id AS sale_id"); + $this->db->from('sales'); + $this->db->join('people', 'people.person_id = sales.customer_id', 'left'); + $this->db->where("( last_name LIKE '%" . $search . "%' OR ". + "first_name LIKE '%" . $search . "%' OR " . + "CONCAT( first_name, last_name ))"); + $this->db->order_by('last_name', "asc"); + + foreach($this->db->get()->result_array() as $result) + { + $suggestions[]=$result[ 'first_name' ].' '.$result[ 'last_name' ]; + } + + } else { + $suggestions[]=$search; + } + return $suggestions; + } + + function get_found_rows($search, $only_invoices = FALSE) + { + $valid_receipt = $this->sale_lib->is_valid_receipt($search); + $this->db->from('sales'); + $this->db->join('sales_items', 'sales_items.sale_id = sales.sale_id'); + $this->db->join('people', 'people.person_id = sales.customer_id', 'left'); + $this->db->group_by('sales.sale_id'); + if (!empty($search)) { + // if barcode scanned, explode and search for second term which will be the id + if ($valid_receipt) { + $pieces = explode(' ',$search); + $this->db->where('sales.sale_id', $pieces[1]); + } else { + // open parentheses + $this->db->where("( last_name LIKE '%" . $search . "%' OR ". + "first_name LIKE '%" . $search . "%' OR " . + "CONCAT( first_name,' ',last_name ) LIKE '%" . $search . "%')"); + // close parentheses + } + } + if ($only_invoices != 0) { + $this->db->where('invoice_number <> ', 'NULL'); + } + return $this->db->get()->num_rows(); + } + function get_invoice_count() { $this->db->from('sales'); @@ -56,19 +183,10 @@ class Sale extends CI_Model if(count($items)==0) return -1; - //Alain Multiple payments - //Build payment types string - $payment_types=''; - foreach($payments as $payment_id=>$payment) - { - $payment_types=$payment_types.$payment['payment_type'].': '.to_currency($payment['payment_amount']).'
'; - } - $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, - 'payment_type'=>$payment_types, 'comment'=>$comment, 'invoice_number'=>$invoice_number ); @@ -183,6 +301,10 @@ class Sale extends CI_Model $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)); + // 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)); if ($update_inventory) { // defect, not all item deletions will be undone?? // get array with all the items involved in the sale to update the inventory tracking @@ -208,10 +330,6 @@ class Sale extends CI_Model $item['quantity_purchased']); } } - // 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)); // execute transaction $this->db->trans_complete(); @@ -254,7 +372,6 @@ class Sale extends CI_Model //We create a temp table that allows us to do easy report/sales queries public function create_sales_items_temp_table() { - $this->db->query("DROP TABLE IF EXISTS phppos_sales_items_temp"); $this->db->query("CREATE TEMPORARY TABLE ".$this->db->dbprefix('sales_items_temp')." (SELECT date(sale_time) as sale_date, sale_time, ".$this->db->dbprefix('sales_items').".sale_id, comment,payments.payment_type, customer_id, employee_id, ".$this->db->dbprefix('items').".item_id, supplier_id, quantity_purchased, item_cost_price, item_unit_price, SUM(percent) as item_tax_percent, diff --git a/application/views/items/manage.php b/application/views/items/manage.php index f088da55b..16dd039e8 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -133,7 +133,7 @@ function show_hide_search_filter(search_filter_section, switchImgTag) {
-
Search Options :
+
lang->line('common_search_options'); ?> :
diff --git a/application/views/sales/manage.php b/application/views/sales/manage.php new file mode 100755 index 000000000..ad41edb28 --- /dev/null +++ b/application/views/sales/manage.php @@ -0,0 +1,176 @@ +load->view("partial/header"); ?> + + +
+
lang->line('common_list_of').' '.$this->lang->line('sales_receipt_number'); ?>
+
+ +
+
lang->line('common_search_options'). ': '; ?>
+ + +
+'search_form')); ?> +
+ lang->line('sales_invoice_filter').' '.':', 'invoices_filter');?> +   + + +
+
+
    +
  • lang->line("common_delete"),array('id'=>'delete')); ?>
  • + +
  • + spinner + + +
  • +
+
+ + +
+ +
+
+load->view("partial/footer"); ?> \ No newline at end of file diff --git a/application/views/sales/receipt.php b/application/views/sales/receipt.php index 5f18d4d81..196d727e6 100644 --- a/application/views/sales/receipt.php +++ b/application/views/sales/receipt.php @@ -134,7 +134,7 @@ if (isset($error_message)) ?> lang->line($amount_change >= 0 ? ($only_sale_check ? 'sales_check_due' : 'sales_change_due') : 'sales_invoice_amount_due') ; ?> - + diff --git a/application/views/sales/register.php b/application/views/sales/register.php index 0822b62ae..7bcb980d5 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -25,6 +25,9 @@ if (isset($success)) lang->line('sales_stock_location') ?> +
".$this->lang->line('sales_suspended_sales')."
", diff --git a/css/invoice.css b/css/invoice.css index 4c9249143..19907fc87 100755 --- a/css/invoice.css +++ b/css/invoice.css @@ -12,7 +12,7 @@ #page-wrap table { border-collapse: collapse; } #page-wrap table td, #page-wrap table th { border: 1px solid black; padding: 5px; } -#header { height: 30px; width: 100%; margin: 20px 0; background: #222; text-align: center; color: white; font: bold 26px Helvetica, Sans-Serif; text-decoration: uppercase; letter-spacing: 4px; padding: 8px 0px; } +#header { height: 30px; width: 100%; margin: 20px 0; background: #222; text-align: center; color: white; font: bold 26px Helvetica, Sans-Serif; text-transform: uppercase; letter-spacing: 4px; padding: 8px 0px; } /* first row */ #logo { text-align: right; margin-top: 15px; float: left; position: relative; border: 1px solid #fff; max-width: 150px; max-height: 150px; overflow: hidden; } diff --git a/css/register.css b/css/register.css index 52425579f..9d5f46e87 100644 --- a/css/register.css +++ b/css/register.css @@ -156,3 +156,9 @@ margin: 0 4px 8px 0; } +#sales_overview +{ + position:absolute; + top:3px; + right:99px; +} \ No newline at end of file diff --git a/database/2.3.1_to_2.3.2.sql b/database/2.3.1_to_2.3.2.sql index bfdda05a6..b2af88413 100644 --- a/database/2.3.1_to_2.3.2.sql +++ b/database/2.3.1_to_2.3.2.sql @@ -31,4 +31,8 @@ ALTER TABLE `ospos_items` ALTER TABLE `ospos_people` ADD COLUMN `gender` int(1) DEFAULT NULL; - + +-- drop redundant payment_type column in sales, add index to sale_time to speed up sorting +ALTER TABLE `ospos_sales` + DROP COLUMN `payment_type`, + ADD INDEX `sale_time` (`sale_time`); diff --git a/database/database.sql b/database/database.sql index 4838ccf92..54de41969 100644 --- a/database/database.sql +++ b/database/database.sql @@ -478,10 +478,10 @@ CREATE TABLE `ospos_sales` ( `comment` text NOT NULL, `invoice_number` varchar(32) DEFAULT NULL, `sale_id` int(10) NOT NULL AUTO_INCREMENT, - `payment_type` varchar(512) DEFAULT NULL, PRIMARY KEY (`sale_id`), KEY `customer_id` (`customer_id`), KEY `employee_id` (`employee_id`), + KEY `sale_time` (`sale_time`), UNIQUE KEY `invoice_number` (`invoice_number`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; @@ -572,7 +572,6 @@ CREATE TABLE `ospos_sales_suspended` ( `comment` text NOT NULL, `invoice_number` varchar(32) DEFAULT NULL, `sale_id` int(10) NOT NULL AUTO_INCREMENT, - `payment_type` varchar(512) DEFAULT NULL, PRIMARY KEY (`sale_id`), KEY `customer_id` (`customer_id`), KEY `employee_id` (`employee_id`), diff --git a/js/manage_tables.js b/js/manage_tables.js index 6147119e4..aae664b6b 100644 --- a/js/manage_tables.js +++ b/js/manage_tables.js @@ -12,8 +12,13 @@ function checkbox_click(event) } } -function enable_search(suggest_url,confirm_search_message) +function enable_search(suggest_url,confirm_search_message,format_item) { + if (!format_item) { + format_item = function(results) { + return results[0]; + }; + } //Keep track of enable_email has been called if(!enable_search.enabled) enable_search.enabled=true; @@ -23,16 +28,19 @@ function enable_search(suggest_url,confirm_search_message) $(this).attr('value',''); }); - $("#search").autocomplete(suggest_url,{max:100,delay:10, selectFirst: false}); + $("#search").autocomplete(suggest_url,{max:100,delay:10, selectFirst: false, formatItem : format_item}); $("#search").result(function(event, data, formatted) { do_search(true); }); + attach_search_listener(); + $('#search_form').submit(function(event) { event.preventDefault(); - + // reset page number when selecting a specific page number + $('#limit_from').val(0); if(get_selected_values().length >0) { if(!confirm(confirm_search_message)) @@ -43,6 +51,21 @@ function enable_search(suggest_url,confirm_search_message) } enable_search.enabled=false; +function attach_search_listener() +{ + // prevent redirecting to link when search enabled + $("#pagination a").click(function(event) { + if ($("#search").val()) { + event.preventDefault(); + // set limit_from to value included in the link + var uri_segments = event.currentTarget.href.split('/'); + var limit_from = uri_segments.pop(); + $('#limit_from').val(limit_from); + do_search(true); + } + }); +} + function do_search(show_feedback,on_complete) { //If search is not enabled, don't do anything @@ -50,21 +73,28 @@ function do_search(show_feedback,on_complete) return; if(show_feedback) - $('#spinner').show(); + $('#search').addClass("ac_loading"); - $('#sortable_table tbody').load($('#search_form').attr('action'),{'search':$('#search').val()},function() - { - if(typeof on_complete=='function') - on_complete(); - - $('#spinner').hide(); - //re-init elements in new table, as table tbody children were replaced - tb_init('#sortable_table a.thickbox'); - update_sortable_table(); - enable_row_selection(); - $('#sortable_table tbody :checkbox').click(checkbox_click); - $("#select_all").attr('checked',false); - }); + $.post( + $('#search_form').attr('action'), + // serialize all the input fields in the form + $('#search_form').serialize(), + function(response) { + $('#sortable_table tbody').html(response.rows); + if(typeof on_complete=='function') + on_complete(); + $('#search').removeClass("ac_loading"); + //$('#spinner').hide(); + //re-init elements in new table, as table tbody children were replaced + tb_init('#sortable_table a.thickbox'); + $('#pagination').html(response.pagination); + $('#sortable_table tbody :checkbox').click(checkbox_click); + $("#select_all").attr('checked',false); + update_sortable_table(); + enable_row_selection(); + attach_search_listener(); + }, "json" + ); } function enable_email(email_url) @@ -108,7 +138,7 @@ function enable_delete(confirm_message,none_selected_message) if(!enable_delete.enabled) enable_delete.enabled=true; - $('#delete').click(function(event) + $("#delete").click(function(event) { event.preventDefault(); if($("#sortable_table tbody :checkbox:checked").length >0) @@ -150,10 +180,9 @@ function do_delete(url) }); }); - // update rows that were affected by this delete - for(index in response.ids) { - update_row(response.ids[index],url.replace(/[^\/]+$/,'get_row')); - } +// for(index in response.ids) { +// update_row(response.ids[index],url.replace(/[^\/]+$/,'get_row')); +// } set_feedback(response.message,'success_message',false); } @@ -277,7 +306,7 @@ function get_table_row(id) { id = id || $("input[name='sale_id']").val(); var $element = $("#sortable_table tbody :checkbox[value='" + id + "']"); if ($element.length === 0) { - $element = $("#sortable_table a.thickbox[href*='" + id + "']"); + $element = $("#sortable_table tbody a[href*='" + id + "']"); } return $element; } @@ -310,7 +339,7 @@ function reinit_row(checkbox_id) function animate_row(row,color) { color = color || "#e1ffdd"; - row.find("td").animate({backgroundColor:color},"slow","linear") + row.find("td").css("backgroundColor", "#ffffff").animate({backgroundColor:color},"slow","linear") .animate({backgroundColor:color},5000) .animate({backgroundColor:"#ffffff"},"slow","linear"); } diff --git a/translations/common_lang.csv b/translations/common_lang.csv index 3194a24d1..ef2b3cc51 100644 --- a/translations/common_lang.csv +++ b/translations/common_lang.csv @@ -43,3 +43,4 @@ common_gender,Geslacht,Gender,Gender,Gender,Gender,Gender,Gender,Gender,Gender common_gender_male,M,M,M,M,M,M,M,M,M common_gender_female,V,F,F,F,V,V,V,V,V common_date,Datum,Date,Date,Date,Date,Date,Date,Date,Date +common_search_options,Zoek criteria,Search options,Search options,Search options,Search options,Search options,Search options,Search options,Search options diff --git a/translations/sales_lang.csv b/translations/sales_lang.csv index 5144ce976..86aa9fb03 100644 --- a/translations/sales_lang.csv +++ b/translations/sales_lang.csv @@ -91,10 +91,19 @@ sales_unsuspend_and_delete,,Retomar y Borrar,,,取消暫停銷售並刪除,Ра sales_giftcard_balance,Waardebon Resterend,Giftcard Balance,Giftcard Balance,Giftcard Balance,Giftcard Balance,Giftcard Balance,Giftcard Balance,Giftcard Balance,Giftcard Balance sales_discount_included,% korting inbegrepen,% discount included,% discount included,% discount included,% discount included,% discount included,% discount included,% discount included,% discount included sales_print_after_sale,Print Ticket,Imprimir recibo después de una venta,Print after sale,Imprimer un recu après vente,出貨時打印收據,Распечатать квитанцию ​​после продажи,พิมพ์บิลหลังการขาย,Satıştan sonra yazdır,Cetak Faktur setelah penjualan -sales_invoice,Factuur,Invoice,Invoice,Invoice,Invoice,Invoice,Invoice,Invoice,Invoice +sales_invoice,Factuur,tarjeta de Crédito,Invoice,Invoice,Invoice,Invoice,Invoice,Invoice,Invoice sales_total_tax_exclusive,Totaal,Tax excluded,Tax excluded,Tax excluded,Tax excluded,Tax excluded,Tax excluded,Tax excluded,Tax excluded sales_send_invoice,Vestuur Factuur,Send Invoice,Send Invoice,Send Invoice,Send Invoice,Send Invoice,Send Invoice,Send Invoice,Send Invoice sales_invoice_confirm,Deze factuur zal verstuurd worden naar,This invoice will be sent to,This invoice will be sent to,This invoice will be sent to,This invoice will be sent to,This invoice will be sent to,This invoice will be sent to,This invoice will be sent to,This invoice will be sent to sales_invoice_no_email,Er werd geen email adres gevonden voor deze klant,This customer does not have a valid email address,This customer does not have a valid email address,This customer does not have a valid email address,This customer does not have a valid email address,This customer does not have a valid email address,This customer does not have a valid email address,This customer does not have a valid email address,This customer does not have a valid email address sales_invoice_sent,Factuur verstuurd naar,Invoice sent to,Invoice sent to,Invoice sent to,Invoice sent to,Invoice sent to,Invoice sent to,Invoice sent to,Invoice sent to sales_invoice_unsent,Fout bij het versturen van factuur naar,Invoice failed to be sent to,Invoice failed to be sent to,Invoice failed to be sent to,Invoice failed to be sent to,Invoice failed to be sent to,Invoice failed to be sent to,Invoice failed to be sent to,Invoice failed to be sent to +sales_invoice_filter,Facturen,Invoices,Invoices,Invoices,Invoices,Invoices,Invoices,Invoices,Invoices +sales_no_filter,Alle,All,All,All,All,All,All,All,All +sales_no_sales_to_display,Er werden geen aankopen gevonden,No sales to display,No sales to display,No sales to display,No sales to display,No sales to display,No sales to display,No sales to display,No sales to display +sales_show_invoice,factuur,invoice,invoice,invoice,invoice,invoice,invoice,invoice,invoice +sales_show_receipt,ticket,receipt,receipt,receipt,receipt,receipt,receipt,receipt,receipt +sales_invoice_filter,Filter tickets op ,Filter sales for ,Filter sales for ,Filter sales for ,Filter sales for ,Filter sales for ,Filter sales for ,Filter sales for ,Filter sales for +sales_overview,Overzicht,Overview,Overview,Overview,Overview,Overview,Overview,Overview,Overview +sales_update,Bewerk Ticket,Edit Sale,Edit Sale,Edit Sale,Edit Sale,Edit Sale,Edit Sale,Edit Sale,Edit Sale +sales_confirm_delete,Bent u zeker dat u de geselecteerde aankopen wil verwijderen?,Are you sure you want to delete the selected sales?,Are you sure you want to delete the selected sales?,Are you sure you want to delete the selected sales?,Are you sure you want to delete the selected sales?,Are you sure you want to delete the selected sales?,Are you sure you want to delete the selected sales?,Are you sure you want to delete the selected sales?,Are you sure you want to delete the selected sales?