diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index eb100ac3a..4b8307e9d 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -30,12 +30,13 @@ class Sales extends Secure_area $data['controller_name'] = $this->get_controller_name(); $lines_per_page = $this->Appconfig->get('lines_per_page'); - $today = date($this->config->item('dateformat')); - - $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date') : $today; - $start_date_formatter = date_create_from_format($this->config->item('dateformat'), $start_date); - $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date') : $today; - $end_date_formatter = date_create_from_format($this->config->item('dateformat'), $end_date); + $today_start = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), mktime(0, 0, 0)); + $today_end = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), mktime(23, 59, 59)); + + $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date') : $today_start; + $start_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $start_date); + $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date') : $today_end; + $end_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $end_date); $sale_type = 'all'; $location_id = 'all'; @@ -44,8 +45,8 @@ class Sales extends Secure_area $filters = array('sale_type' => $sale_type, 'location_id' => $location_id, - 'start_date' => $start_date_formatter->format('Y-m-d'), - 'end_date' => $end_date_formatter->format('Y-m-d'), + 'start_date' => $start_date_formatter->format('Y-m-d H:i:s'), + 'end_date' => $end_date_formatter->format('Y-m-d H:i:s'), 'only_invoices' => $only_invoices, 'only_cash' => $only_cash, 'is_valid_receipt' => $is_valid_receipt); @@ -55,8 +56,8 @@ class Sales extends Secure_area $total_rows = $this->Sale->get_found_rows($search, $filters); $data['only_invoices'] = $only_invoices; $data['only_cash '] = $only_cash; - $data['start_date'] = $start_date_formatter->format($this->config->item('dateformat')); - $data['end_date'] = $end_date_formatter->format($this->config->item('dateformat')); + $data['start_date'] = $start_date; + $data['end_date'] = $end_date; $data['links'] = $this->_initialize_pagination($this->Sale, $lines_per_page, $limit_from, $total_rows, 'manage', $only_invoices); $data['manage_table'] = get_sales_manage_table($sales, $this); $data['payments_summary'] = get_sales_manage_payments_summary($payments, $sales, $this); @@ -99,12 +100,12 @@ class Sales extends Secure_area $limit_from = $this->input->post('limit_from'); $lines_per_page = $this->Appconfig->get('lines_per_page'); - $today = date($this->config->item('dateformat')); + $today = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat')); $start_date = $this->input->post('start_date') != null ? $this->input->post('start_date') : $today; - $start_date_formatter = date_create_from_format($this->config->item('dateformat'), $start_date); + $start_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $start_date); $end_date = $this->input->post('end_date') != null ? $this->input->post('end_date') : $today; - $end_date_formatter = date_create_from_format($this->config->item('dateformat'), $end_date); + $end_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $end_date); $is_valid_receipt = isset($search) ? $this->sale_lib->is_valid_receipt($search) : FALSE; @@ -115,8 +116,8 @@ class Sales extends Secure_area $filters = array('sale_type' => $sale_type, 'location_id' => $location_id, - 'start_date' => $start_date_formatter->format('Y-m-d'), - 'end_date' => $end_date_formatter->format('Y-m-d'), + 'start_date' => $start_date_formatter->format('Y-m-d H:i:s'), + 'end_date' => $end_date_formatter->format('Y-m-d H:i:s'), 'only_invoices' => $only_invoices, 'only_cash' => $only_cash, 'is_valid_receipt' => $is_valid_receipt); @@ -573,7 +574,7 @@ class Sales extends Secure_area $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_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'); $customer_id = $this->sale_lib->get_customer(); @@ -670,7 +671,7 @@ class Sales extends Secure_area } else { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('sales_unsuccessfully_deleted'))); + echo json_encode(array('success'=>false, 'message'=>$this->lang->line('sales_unsuccessfully_deleted'))); } } @@ -683,23 +684,17 @@ class Sales extends Secure_area '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') + 'invoice_number' => $this->input->post('invoice_number') != '' ? $this->input->post('invoice_number') : null ); if ($this->Sale->update($sale_data, $sale_id)) { - echo json_encode(array( - 'success'=>true, - 'message'=>$this->lang->line('sales_successfully_updated'), - 'id'=>$sale_id) + 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) + echo json_encode(array('success'=>false, 'message'=>$this->lang->line('sales_unsuccessfully_updated'), 'id'=>$sale_id) ); } } diff --git a/application/models/Sale.php b/application/models/Sale.php index 0a30adc3e..0062e290a 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -41,7 +41,7 @@ class Sale extends CI_Model if (empty($search)) { - $this->db->where('sale_date BETWEEN '. $this->db->escape($filters['start_date']). ' AND '. $this->db->escape($filters['end_date'])); + $this->db->where('sale_time BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date'])); } else { @@ -107,11 +107,11 @@ class Sale extends CI_Model if (empty($search)) { - $this->db->where('DATE(sale_time) BETWEEN '. $this->db->escape($filters['start_date']). ' AND '. $this->db->escape($filters['end_date'])); + $this->db->where('sale_time BETWEEN '. $this->db->escape($filters['start_date']). ' AND '. $this->db->escape($filters['end_date'])); } else { - if ($filters['is_valid_receipt']) + if ($filters['is_valid_receipt'] != FALSE) { $pieces = explode(' ',$search); $this->db->where('sales.sale_id', $pieces[1]); diff --git a/application/views/sales/form.php b/application/views/sales/form.php index af22cd462..2730bbe27 100755 --- a/application/views/sales/form.php +++ b/application/views/sales/form.php @@ -108,8 +108,13 @@ $(document).ready(function() }, 'lang->line("sales_invoice_number_duplicate"); ?>'); $('#datetime').datetimepicker({ - dateFormat: 'config->item("dateformat"));?>', - timeFormat: 'config->item("timeformat"));?>' + format: "config->item("dateformat")) . ' ' . dateformat_bootstrap($this->config->item("timeformat"));?>", + startDate: '01/01/2010 00:00:00', + minuteStep: 1, + autoclose: true, + todayBtn: true, + todayHighlight: true, + language: "config->item('language'); ?>" }); var format_item = function(row) diff --git a/application/views/sales/manage.php b/application/views/sales/manage.php index d8d2c9be9..543b1c042 100755 --- a/application/views/sales/manage.php +++ b/application/views/sales/manage.php @@ -48,8 +48,8 @@ $(document).ready(function() // initialise the datetime picker and trigger a search on any change date $(".date_filter").datetimepicker({ - format: "config->item('dateformat'))?>", - startDate: '01/01/2010', + format: "config->item("dateformat")) . ' ' . dateformat_bootstrap($this->config->item("timeformat"));?>", + startDate: '01/01/2010 00:00:00', autoclose: true, todayBtn: true, todayHighlight: true, @@ -193,9 +193,9 @@ function init_table_sorting() 'only_cash','id'=>'only_cash','value'=>1,'checked'=> isset($only_cash)? ( ($only_cash)? 1 : 0) : 0)) . ' | ';?> lang->line('sales_date_range').' :', 'start_date');?> - 'start_date', 'value'=>$start_date, 'class'=>'date_filter', 'size' => '15'));?> + 'start_date', 'value'=>$start_date, 'class'=>'date_filter', 'size' => '18'));?> - 'end_date', 'value'=>$end_date, 'class'=>'date_filter', 'size' => '15'));?> + 'end_date', 'value'=>$end_date, 'class'=>'date_filter', 'size' => '18'));?>