mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-02-18 14:48:42 -05:00
Enance reporting to accomodate work orders and canceled transactions.
This commit is contained in:
@@ -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'],
|
||||
|
||||
@@ -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']);
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
<?php
|
||||
|
||||
$lang["reports_all"] = "All";
|
||||
$lang["reports_canceled"] = "Canceled";
|
||||
$lang["reports_categories"] = "Categories";
|
||||
$lang["reports_categories_summary_report"] = "Categories Summary Report";
|
||||
$lang["reports_category"] = "Category";
|
||||
$lang["reports_code_canceled"] = "CNL";
|
||||
$lang["reports_code_invoice"] = "INV";
|
||||
$lang["reports_code_quote"] = "Q";
|
||||
$lang["reports_code_return"] = "RET";
|
||||
$lang["reports_code_type"] = "Type";
|
||||
$lang["reports_code_work_order"] = "W/O";
|
||||
$lang["reports_comments"] = "Comments";
|
||||
$lang["reports_cost"] = "Wholesale";
|
||||
$lang["reports_cost_price"] = "Wholesale Price";
|
||||
@@ -97,4 +104,5 @@ $lang["reports_total_inventory_value"] = "Total Inventory Value";
|
||||
$lang["reports_type"] = "Type";
|
||||
$lang["reports_unit_price"] = "Retail Price";
|
||||
$lang["reports_used"] = "Points Used";
|
||||
$lang["reports_work_orders"] = "Work Orders";
|
||||
$lang["reports_zero_and_less"] = "Zero and less";
|
||||
|
||||
@@ -149,6 +149,6 @@ $lang["sales_unsuspend_and_delete"] = "Action";
|
||||
$lang["sales_update"] = "Update";
|
||||
$lang["sales_work_order"] = "Work Order";
|
||||
$lang["sales_work_order_number"] = "Work Order Number";
|
||||
$lang["sales_work_order_number_duplicate"] = "The Work Order Number is a duplicate";
|
||||
$lang["sales_work_order_number_duplicate"] = "Work Order Number must be unique.";
|
||||
$lang["sales_work_order_sent"] = "Work Order sent to";
|
||||
$lang["sales_work_order_unsent"] = "Work Order failed to be sent to";
|
||||
|
||||
@@ -249,6 +249,11 @@ class Sale_lib
|
||||
return ($this->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');
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,10 +29,7 @@ if(isset($error))
|
||||
?>
|
||||
<?php echo form_label($this->lang->line('reports_sale_type'), 'reports_sale_type_label', array('class'=>'required control-label col-xs-2')); ?>
|
||||
<div id='report_sale_type' class="col-xs-3">
|
||||
<?php echo form_dropdown('sale_type', array('all' => $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')); ?>
|
||||
<?php echo form_dropdown('sale_type', $sale_type_options, 'complete', array('id'=>'input_type', 'class'=>'form-control')); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -32,10 +32,7 @@ if(isset($error))
|
||||
<div class="form-group form-group-sm">
|
||||
<?php echo form_label($this->lang->line('reports_sale_type'), 'reports_sale_type_label', array('class'=>'required control-label col-xs-2')); ?>
|
||||
<div id='report_sale_type' class="col-xs-3">
|
||||
<?php echo form_dropdown('sale_type', array('all' => $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"'); ?>
|
||||
<?php echo form_dropdown('sale_type',$sale_type_options, 'complete', 'id="input_type" class="form-control"'); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user