diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 426d510f2..1ffcc3ddd 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -358,6 +358,7 @@ class Reports extends Secure_Controller $stock_locations['all'] = $this->lang->line('reports_all'); $data['stock_locations'] = array_reverse($stock_locations, TRUE); $data['mode'] = 'sale'; + $data['sale_type_options'] = $this->get_sale_type_options(); $this->load->view('reports/date_input', $data); } @@ -370,6 +371,7 @@ class Reports extends Secure_Controller $stock_locations['all'] = $this->lang->line('reports_all'); $data['stock_locations'] = array_reverse($stock_locations, TRUE); $data['mode'] = 'sale'; + $data['sale_type_options'] = $this->get_sale_type_options(); $this->load->view('reports/date_input', $data); } @@ -711,6 +713,7 @@ class Reports extends Secure_Controller $customers[$customer->person_id] = $this->xss_clean($customer->first_name . ' ' . $customer->last_name); } $data['specific_input_data'] = $customers; + $data['sale_type_options'] = $this->get_sale_type_options(); $this->load->view('reports/specific_input', $data); } @@ -735,6 +738,7 @@ class Reports extends Secure_Controller { $summary_data[] = $this->xss_clean(array( 'id' => anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), + 'type_code' => $row['type_code'], 'sale_date' => $row['sale_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), 'employee_name' => $row['employee_name'], @@ -796,6 +800,7 @@ class Reports extends Secure_Controller $employees[$employee->person_id] = $this->xss_clean($employee->first_name . ' ' . $employee->last_name); } $data['specific_input_data'] = $employees; + $data['sale_type_options'] = $this->get_sale_type_options(); $this->load->view('reports/specific_input', $data); } @@ -820,6 +825,7 @@ class Reports extends Secure_Controller { $summary_data[] = $this->xss_clean(array( 'id' => anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), + 'type_code' => $row['type_code'], 'sale_date' => $row['sale_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), 'customer_name' => $row['customer_name'], @@ -881,7 +887,8 @@ class Reports extends Secure_Controller $discounts[$i] = $i . '%'; } $data['specific_input_data'] = $discounts; - + $data['sale_type_options'] = $this->get_sale_type_options(); + $data = $this->xss_clean($data); $this->load->view('reports/specific_input', $data); @@ -907,6 +914,7 @@ class Reports extends Secure_Controller { $summary_data[] = $this->xss_clean(array( 'id' => anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), + 'type_code' => $row['type_code'], 'sale_date' => $row['sale_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), 'customer_name' => $row['customer_name'], @@ -987,6 +995,24 @@ class Reports extends Secure_Controller echo json_encode(array($sale_id => $summary_data)); } + public function get_sale_type_options() + { + $sale_type_options = array(); + $sale_type_options['complete'] = $this->lang->line('reports_complete'); + $sale_type_options['sales'] = $this->lang->line('reports_completed_sales'); + if($this->config->item('invoice_enable') == '1') + { + $sale_type_options['quotes'] = $this->lang->line('reports_quotes'); + if($this->config->item('work_order_enable') == '1') + { + $sale_type_options['work_orders'] = $this->lang->line('reports_work_orders'); + $sale_type_options['canceled'] = $this->lang->line('reports_canceled'); + } + } + $sale_type_options['returns'] = $this->lang->line('reports_returns'); + return $sale_type_options; + } + public function detailed_sales($start_date, $end_date, $sale_type, $location_id = 'all') { $inputs = array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id); @@ -1010,6 +1036,7 @@ class Reports extends Secure_Controller { $summary_data[] = $this->xss_clean(array( 'id' => $row['sale_id'], + 'type_code' => $row['type_code'], 'sale_date' => $row['sale_date'], 'quantity' => to_quantity_decimals($row['items_purchased']), 'employee_name' => $row['employee_name'], diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 98f5ab48c..c10c9c061 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -204,6 +204,10 @@ class Sales extends Secure_Controller { $this->sale_lib->set_mode('sale_invoice'); } + elseif($sale_type == SALE_TYPE_RETURN) + { + $this->sale_lib->set_mode('return'); + } else { $this->sale_lib->set_mode('sale'); @@ -709,7 +713,14 @@ class Sales extends Secure_Controller { // Save the data to the sales table $data['sale_status'] = COMPLETED; - $sale_type = SALE_TYPE_POS; + if($this->sale_lib->is_return_mode()) + { + $sale_type = SALE_TYPE_RETURN; + } + else + { + $sale_type = SALE_TYPE_POS; + } $data['sale_id_num'] = $this->Sale->save($sale_id, $data['sale_status'], $data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $work_order_number, $quote_number, $sale_type, $data['payments'], $data['dinner_table'], $data['taxes']); diff --git a/application/language/en-US/config_lang.php b/application/language/en-US/config_lang.php index 7ad7bcbf8..15d996f81 100644 --- a/application/language/en-US/config_lang.php +++ b/application/language/en-US/config_lang.php @@ -142,7 +142,7 @@ $lang["config_jsprintsetup_required"] = "Warning: This functionality will only w $lang["config_language"] = "Language"; $lang["config_last_used_invoice_number"] = "Last used Invoice Number"; $lang["config_last_used_quote_number"] = "Last used Quote Number"; -$lang["config_last_used_work_order_number"] = "Last Used W/O Number"; +$lang["config_last_used_work_order_number"] = "Last used W/O Number"; $lang["config_left"] = "Left"; $lang["config_license"] = "License"; $lang["config_license_configuration"] = "License Statement"; diff --git a/application/language/en-US/reports_lang.php b/application/language/en-US/reports_lang.php index 127e4c03e..81dcf34d0 100644 --- a/application/language/en-US/reports_lang.php +++ b/application/language/en-US/reports_lang.php @@ -1,9 +1,16 @@ CI->session->userdata('sales_mode') == 'sale_quote'); } + public function is_return_mode() + { + return ($this->CI->session->userdata('sales_mode') == 'return'); + } + public function is_work_order_mode() { return ($this->CI->session->userdata('sales_mode') == 'sale_work_order'); diff --git a/application/models/Sale.php b/application/models/Sale.php index 39d3ee513..3cab08104 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -545,8 +545,6 @@ class Sale extends CI_Model */ public function save($sale_id, &$sale_status, &$items, $customer_id, $employee_id, $comment, $invoice_number, $work_order_number, $quote_number, $sale_type, $payments, $dinner_table, &$sales_taxes) { - - error_log('>>>save sale_id-' . $sale_id . ', sale_type-' . $sale_type); if($sale_id != -1) { $this->clear_suspended_sale_detail($sale_id); @@ -578,8 +576,6 @@ class Sale extends CI_Model // Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); - error_log('>>> sales_data-' . print_r($sales_data, true)); - error_log('>>> sales_id-' . $sale_id); if($sale_id == -1) { $this->db->insert('sales', $sales_data); @@ -1158,6 +1154,7 @@ class Sale extends CI_Model MAX(sales.sale_time) AS sale_time, sales.sale_id AS sale_id, MAX(sales.sale_status) AS sale_status, + MAX(sales.sale_type) AS sale_type, MAX(sales.comment) AS comment, MAX(sales.invoice_number) AS invoice_number, MAX(sales.quote_number) AS quote_number, @@ -1247,7 +1244,6 @@ class Sale extends CI_Model { return NULL; } - error_log('>>>get_dinner_table sale_id-'.$sale_id); $this->db->from('sales'); $this->db->where('sale_id', $sale_id); diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index d295ef10d..e247ae9c1 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -15,6 +15,7 @@ class Detailed_sales extends Report return array( 'summary' => array( array('id' => $this->lang->line('reports_sale_id')), + array('type_code' => $this->lang->line('reports_code_type')), array('sale_date' => $this->lang->line('reports_date')), array('quantity' => $this->lang->line('reports_quantity')), array('employee_name' => $this->lang->line('reports_sold_by')), @@ -66,7 +67,15 @@ class Detailed_sales extends Report public function getData(array $inputs) { - $this->db->select('sale_id, + $this->db->select('sale_id, + MAX(CASE + WHEN sale_type = ' . SALE_TYPE_INVOICE . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_invoice') . '\' + WHEN sale_type = ' . SALE_TYPE_WORK_ORDER . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_work_order') . '\' + WHEN sale_type = ' . SALE_TYPE_QUOTE . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_quote') . '\' + WHEN sale_type = ' . SALE_TYPE_RETURN . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_return') . '\' + WHEN sale_status = ' . CANCELED . ' THEN \'' . $this->lang->line('reports_code_canceled') . '\' + ELSE \'\' + END) AS type_code, MAX(sale_status) as sale_status, MAX(sale_date) AS sale_date, SUM(quantity_purchased) AS items_purchased, @@ -86,21 +95,41 @@ class Detailed_sales extends Report $this->db->where('item_location', $inputs['location_id']); } - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = '. COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } $this->db->group_by('sale_id'); @@ -136,21 +165,41 @@ class Detailed_sales extends Report $this->db->where('item_location', $inputs['location_id']); } - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Specific_customer.php b/application/models/reports/Specific_customer.php index 2ce8e31e9..ba33c3933 100644 --- a/application/models/reports/Specific_customer.php +++ b/application/models/reports/Specific_customer.php @@ -15,6 +15,7 @@ class Specific_customer extends Report return array( 'summary' => array( array('id' => $this->lang->line('reports_sale_id')), + array('type_code' => $this->lang->line('reports_code_type')), array('sale_date' => $this->lang->line('reports_date')), array('quantity' => $this->lang->line('reports_quantity')), array('employee_name' => $this->lang->line('reports_sold_by')), @@ -46,6 +47,14 @@ class Specific_customer extends Report public function getData(array $inputs) { $this->db->select('sale_id, + MAX(CASE + WHEN sale_type = ' . SALE_TYPE_INVOICE . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_invoice') . '\' + WHEN sale_type = ' . SALE_TYPE_WORK_ORDER . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_work_order') . '\' + WHEN sale_type = ' . SALE_TYPE_QUOTE . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_quote') . '\' + WHEN sale_type = ' . SALE_TYPE_RETURN . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_return') . '\' + WHEN sale_status = ' . CANCELED . ' THEN \'' . $this->lang->line('reports_code_canceled') . '\' + ELSE \'\' + END) AS type_code, MAX(sale_date) AS sale_date, SUM(quantity_purchased) AS items_purchased, MAX(employee_name) AS employee_name, @@ -59,21 +68,41 @@ class Specific_customer extends Report $this->db->from('sales_items_temp'); $this->db->where('customer_id', $inputs['customer_id']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } $this->db->group_by('sale_id'); @@ -105,21 +134,41 @@ class Specific_customer extends Report $this->db->from('sales_items_temp'); $this->db->where('customer_id', $inputs['customer_id']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index d42ba8055..c2291ebb5 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -15,6 +15,7 @@ class Specific_discount extends Report return array( 'summary' => array( array('id' => $this->lang->line('reports_sale_id')), + array('type_code' => $this->lang->line('reports_code_type')), array('sale_date' => $this->lang->line('reports_date')), array('quantity' => $this->lang->line('reports_quantity')), array('customer_name' => $this->lang->line('reports_sold_to')), @@ -44,6 +45,14 @@ class Specific_discount extends Report public function getData(array $inputs) { $this->db->select('sale_id, + MAX(CASE + WHEN sale_type = ' . SALE_TYPE_INVOICE . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_invoice') . '\' + WHEN sale_type = ' . SALE_TYPE_WORK_ORDER . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_work_order') . '\' + WHEN sale_type = ' . SALE_TYPE_QUOTE . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_quote') . '\' + WHEN sale_type = ' . SALE_TYPE_RETURN . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_return') . '\' + WHEN sale_status = ' . CANCELED . ' THEN \'' . $this->lang->line('reports_code_canceled') . '\' + ELSE \'\' + END) AS type_code, MAX(sale_date) AS sale_date, SUM(quantity_purchased) AS items_purchased, MAX(customer_name) AS customer_name, @@ -57,21 +66,41 @@ class Specific_discount extends Report $this->db->from('sales_items_temp'); $this->db->where('discount_percent >=', $inputs['discount']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } $this->db->group_by('sale_id'); @@ -103,21 +132,41 @@ class Specific_discount extends Report $this->db->from('sales_items_temp'); $this->db->where('discount_percent >=', $inputs['discount']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 5eace2d21..f0e83f80f 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -15,6 +15,7 @@ class Specific_employee extends Report return array( 'summary' => array( array('id' => $this->lang->line('reports_sale_id')), + array('type_code' => $this->lang->line('reports_code_type')), array('sale_date' => $this->lang->line('reports_date')), array('quantity' => $this->lang->line('reports_quantity')), array('customer_name' => $this->lang->line('reports_sold_to')), @@ -46,6 +47,14 @@ class Specific_employee extends Report public function getData(array $inputs) { $this->db->select('sale_id, + MAX(CASE + WHEN sale_type = ' . SALE_TYPE_INVOICE . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_invoice') . '\' + WHEN sale_type = ' . SALE_TYPE_WORK_ORDER . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_work_order') . '\' + WHEN sale_type = ' . SALE_TYPE_QUOTE . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_quote') . '\' + WHEN sale_type = ' . SALE_TYPE_RETURN . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_return') . '\' + WHEN sale_status = ' . CANCELED . ' THEN \'' . $this->lang->line('reports_code_canceled') . '\' + ELSE \'\' + END) AS type_code, MAX(sale_date) AS sale_date, SUM(quantity_purchased) AS items_purchased, MAX(customer_name) AS customer_name, @@ -59,21 +68,41 @@ class Specific_employee extends Report $this->db->from('sales_items_temp'); $this->db->where('employee_id', $inputs['employee_id']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } $this->db->group_by('sale_id'); @@ -105,21 +134,41 @@ class Specific_employee extends Report $this->db->from('sales_items_temp'); $this->db->where('employee_id', $inputs['employee_id']); - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } return $this->db->get()->row_array(); diff --git a/application/models/reports/Summary_report.php b/application/models/reports/Summary_report.php index 1dd464edd..92392a15c 100644 --- a/application/models/reports/Summary_report.php +++ b/application/models/reports/Summary_report.php @@ -90,21 +90,41 @@ abstract class Summary_report extends Report $this->db->where('sales_items.item_location', $inputs['location_id']); } - if($inputs['sale_type'] == 'sales') + if($inputs['sale_type'] == 'complete') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased > 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->group_end(); } - elseif($inputs['sale_type'] == 'all') + elseif($inputs['sale_type'] == 'sales') { - $this->db->where('sale_status = ' . COMPLETED); + $this->db->where('sale_status', COMPLETED); + $this->db->group_start(); + $this->db->where('sale_type', SALE_TYPE_POS); + $this->db->or_where('sale_type', SALE_TYPE_INVOICE); + $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') { - $this->db->where('sale_status = ' . SUSPENDED . ' and quote_number IS NOT NULL'); + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_QUOTE); + } + elseif($inputs['sale_type'] == 'work_orders') + { + $this->db->where('sale_status', SUSPENDED); + $this->db->where('sale_type', SALE_TYPE_WORK_ORDER); + } + elseif($inputs['sale_type'] == 'canceled') + { + $this->db->where('sale_status', CANCELED); } elseif($inputs['sale_type'] == 'returns') { - $this->db->where('sale_status = ' . COMPLETED . ' and quantity_purchased < 0'); + $this->db->where('sale_status', COMPLETED); + $this->db->where('sale_type', SALE_TYPE_RETURN); } diff --git a/application/views/reports/date_input.php b/application/views/reports/date_input.php index 42db42037..4874314d7 100644 --- a/application/views/reports/date_input.php +++ b/application/views/reports/date_input.php @@ -29,10 +29,7 @@ if(isset($error)) ?> lang->line('reports_sale_type'), 'reports_sale_type_label', array('class'=>'required control-label col-xs-2')); ?>
- $this->lang->line('reports_all'), - 'sales' => $this->lang->line('reports_sales'), - 'quotes' => $this->lang->line('reports_quotes'), - 'returns' => $this->lang->line('reports_returns')), 'all', array('id'=>'input_type', 'class'=>'form-control')); ?> + 'input_type', 'class'=>'form-control')); ?>
lang->line('reports_sale_type'), 'reports_sale_type_label', array('class'=>'required control-label col-xs-2')); ?>
- $this->lang->line('reports_all'), - 'sales' => $this->lang->line('reports_sales'), - 'quotes' => $this->lang->line('reports_quotes'), - 'returns' => $this->lang->line('reports_returns')), 'all', 'id="input_type" class="form-control"'); ?> +
diff --git a/database/3.1.0_work_orders.sql b/database/3.1.0_work_orders.sql index a9aa675f1..9b69edafe 100644 --- a/database/3.1.0_work_orders.sql +++ b/database/3.1.0_work_orders.sql @@ -9,14 +9,25 @@ ALTER TABLE `ospos_sales` ADD COLUMN `work_order_number` varchar(32) DEFAULT NULL, ADD COLUMN `sale_type` tinyint(2) NOT NULL DEFAULT 0; --- sale_type (0=pos, 1=invoice, 2=work order, 3=quote) +-- sale_type (0=pos, 1=invoice, 2=work order, 3=quote, 4=return) -update `ospos_sales` - set `sale_type` = '3' where quote_number IS NOT NULL; +UPDATE `ospos_sales` + SET `sale_type` = 0; -update `ospos_sales` - set `sale_type` = '2', `work_order_number` = `quote_number` - where quote_number IS NOT NULL; +UPDATE ospos_sales t1 + SET sale_type = 4 +WHERE EXISTS (SELECT t2.sale_id FROM ospos_sales_items t2 WHERE t1.sale_id = t2.sale_id AND t2.quantity_purchased < 0); -update `ospos_sales` - set `sale_type` = '1' where invoice_number IS NOT NULL; +UPDATE `ospos_sales` + SET `sale_type` = 3 +WHERE `quote_number` IS NOT NULL; + +-- The following is needed only if quotes were being treated as work orders. +-- UPDATE `ospos_sales` +-- SET `sale_type` = 2, `work_order_number` = `quote_number` +-- WHERE quote_number IS NOT NULL; + +-- Identify invoices +UPDATE `ospos_sales` + SET `sale_type` = 1 +WHERE `invoice_number` IS NOT NULL;