function search() { $only_invoices = $this->input->post('only_invoices', TRUE); $only_cash = $this->input->post('only_cash', TRUE); $lines_per_page = $this->Appconfig->get('lines_per_page'); $limit_from = $this->input->post('limit_from', TRUE); $search = $this->input->post('search', TRUE); $sale_type = 'all'; $today = date($this->config->item('dateformat')); $start_date = $this->input->post('start_date') != NULL ? $this->input->post('start_date', TRUE) : $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', TRUE) : $today; $end_date_formatter = date_create_from_format($this->config->item('dateformat'), $end_date); $is_valid_receipt = isset($search) ? $this->sale_lib->is_valid_receipt($search) : FALSE; $location_id = 'all'; $inputs = 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'), 'only_invoices' => $only_invoices, 'search' => $search, 'only_cash' => $only_cash, 'lines_per_page' => $lines_per_page, 'limit_from' => $limit_from, 'is_valid_receipt' => $is_valid_receipt); $sales = $this->Sale->get_all($inputs); $payments = $this->Sale->get_payments_summary($inputs); $total_rows = count($sales); $links = $this->_initialize_pagination($this->Sale, $lines_per_page, $limit_from, $total_rows, 'search', $only_invoices); $sale_rows = get_sales_manage_table_data_rows($sales, $this); $payment_summary = get_sales_manage_payments_summary($payments, $sales, $this); echo json_encode(array('total_rows' => $total_rows, 'rows' => $sale_rows, 'pagination' => $links, 'payment_summary' => $payment_summary)); $this->_remove_duplicate_cookies(); }
public function search() { $this->Sale->create_temp_table(); $search = $this->input->get('search'); $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); $sort = $this->input->get('sort'); $order = $this->input->get('order'); $is_valid_receipt = !empty($search) ? $this->sale_lib->is_valid_receipt($search) : FALSE; $filters = array('sale_type' => 'all', 'location_id' => 'all', 'start_date' => $this->input->get('start_date'), 'end_date' => $this->input->get('end_date'), 'only_cash' => FALSE, 'only_invoices' => $this->config->item('invoice_enable') && $this->input->get('only_invoices'), 'is_valid_receipt' => $is_valid_receipt); // check if any filter is set in the multiselect dropdown $filledup = array_fill_keys($this->input->get('filters'), TRUE); $filters = array_merge($filters, $filledup); $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 = $this->xss_clean(get_sales_manage_payments_summary($payments, $sales, $this)); $data_rows = array(); foreach ($sales->result() as $sale) { $data_rows[] = $this->xss_clean(get_sale_data_row($sale, $this)); } if ($total_rows > 0) { $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)); }