diff --git a/application/config/routes.php b/application/config/routes.php index 7ee9fa45d..3ba3f7aa0 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -54,6 +54,7 @@ $route['reports/detailed_receivings'] = "reports/date_input"; $route['reports/(specific_:any)/(:any)/(:any)/(:any)'] = "reports/$1/$2/$3/$4"; $route['reports/specific_customer'] = "reports/specific_customer_input"; $route['reports/specific_employee'] = "reports/specific_employee_input"; +$route['reports/specific_discount'] = "reports/specific_discount_input"; $route['404_override'] = 'errors/page_missing'; diff --git a/application/controllers/reports.php b/application/controllers/reports.php index ed759f047..560f16c76 100644 --- a/application/controllers/reports.php +++ b/application/controllers/reports.php @@ -703,6 +703,56 @@ class Reports extends Secure_area $this->load->view("reports/tabular_details",$data); } + + function specific_discount_input() + { + $data = $this->_get_common_report_data(); + $data['specific_input_name'] = $this->lang->line('reports_discount'); + + $discounts = array(); + for($i = 0; $i <= 100; $i += 10) + { + $discounts[$i] = $i . '%'; + } + $data['specific_input_data'] = $discounts; + $this->load->view("reports/specific_input",$data); + } + + function specific_discount($start_date, $end_date, $discount, $sale_type, $export_excel = 0) + { + $this->load->model('reports/Specific_discount'); + $model = $this->Specific_discount; + + $headers = $model->getDataColumns(); + $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'discount' =>$discount, 'sale_type' => $sale_type)); + + $summary_data = array(); + $details_data = array(); + + foreach($report_data['summary'] as $key=>$row) + { + $summary_data[] = array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target' => '_blank')), $row['sale_date'], $row['items_purchased'], $row['customer_name'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),/*to_currency($row['profit']),*/ $row['payment_type'], $row['comment']); + + foreach($report_data['details'][$key] as $drow) + { + $details_data[$key][] = array($drow['name'], $drow['category'], $drow['description'], $drow['quantity_purchased'], to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']),/*to_currency($drow['profit']),*/ $drow['discount_percent'].'%'); + } + } + + $data = array( + "title" => $discount. '% '.$this->lang->line('reports_discount') . ' ' . $this->lang->line('reports_report'), + "subtitle" => date('m/d/Y', strtotime($start_date)) .'-'.date('m/d/Y', strtotime($end_date)), + "headers" => $headers, + "summary_data" => $summary_data, + "details_data" => $details_data, + "header_width" => intval(100 / count($headers['summary'])), + "overall_summary_data" => $model->getSummaryData(array('start_date'=>$start_date, 'end_date'=>$end_date,'discount' =>$discount, 'sale_type' => $sale_type)), + "export_excel" => $export_excel + ); + + $this->load->view("reports/tabular_details",$data); + + } function detailed_sales($start_date, $end_date, $sale_type, $export_excel=0) { @@ -737,7 +787,7 @@ class Reports extends Secure_area $this->load->view("reports/tabular_details",$data); } - + function detailed_receivings($start_date, $end_date, $sale_type, $export_excel=0) { $this->load->model('reports/Detailed_receivings'); diff --git a/application/language/english/reports_lang.php b/application/language/english/reports_lang.php index 12e1f3598..e41d34242 100644 --- a/application/language/english/reports_lang.php +++ b/application/language/english/reports_lang.php @@ -28,7 +28,9 @@ $lang['reports_total'] = 'Total'; $lang['reports_tax'] = 'Tax'; $lang['reports_profit'] = 'Profit'; $lang['reports_report_input'] = 'Report Input'; +$lang['reports_discount'] = 'Discount'; $lang['reports_type'] = 'Type'; +$lang['reports_discount'] = 'A discount greater than '; $lang['reports_date_range'] = 'Date Range'; $lang['reports_today'] = 'Today'; $lang['reports_yesterday'] = 'Yesterday'; diff --git a/application/language/english/sales_lang.php b/application/language/english/sales_lang.php index 836446372..dc39c937f 100644 --- a/application/language/english/sales_lang.php +++ b/application/language/english/sales_lang.php @@ -14,7 +14,11 @@ $lang['sales_tax_percent']='Tax %'; $lang['sales_price']='Price'; $lang['sales_quantity']='Qty.'; $lang['sales_discount']='Disc %'; +$lang['sales_discount_short']='%'; +$lang["sales_discount_included"]='% korting inbegrepen'; +$lang['sales_sale_time']='Tijdstip'; $lang['sales_edit']='Edit'; +$lang['sales_sale_time']='Time'; $lang['sales_payment']='Payment Type'; $lang['sales_edit_item']='Edit Item'; $lang['sales_find_or_scan_item']='Find/Scan Item'; diff --git a/application/models/reports/specific_discount.php b/application/models/reports/specific_discount.php new file mode 100755 index 000000000..679275756 --- /dev/null +++ b/application/models/reports/specific_discount.php @@ -0,0 +1,70 @@ + array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_items_purchased'), $this->lang->line('reports_customer'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), /*$this->lang->line('reports_profit'),*/ $this->lang->line('reports_payment_type'), $this->lang->line('reports_comments')), + 'details' => array($this->lang->line('reports_name'), $this->lang->line('reports_category'), $this->lang->line('reports_description'), $this->lang->line('reports_quantity_purchased'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), /*$this->lang->line('reports_profit'),*/$this->lang->line('reports_discount')) + ); + } + + public function getData(array $inputs) + { + $this->db->select('sale_id, DATE_FORMAT(sale_time, "%d-%m-%Y") AS sale_date, sum(quantity_purchased) as items_purchased, CONCAT(first_name," ",last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit, payment_type, comment', false); + $this->db->from('sales_items_temp'); + $this->db->join('people as customer', 'sales_items_temp.customer_id = customer.person_id', 'left'); + $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and discount_percent >='.$inputs['discount']); + + if ($inputs['sale_type'] == 'sales') + { + $this->db->where('quantity_purchased > 0'); + } + elseif ($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } + + $this->db->group_by('sale_id'); + $this->db->order_by('sale_date'); + + $data = array(); + $data['summary'] = $this->db->get()->result_array(); + $data['details'] = array(); + + foreach($data['summary'] as $key=>$value) + { + $this->db->select('name, serialnumber, sales_items_temp.description, quantity_purchased, subtotal,total, tax, profit, discount_percent'); + $this->db->from('sales_items_temp'); + $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); + $this->db->where('sale_id = '.$value['sale_id'] . " AND discount_percent >= " . $inputs['discount']); + $data['details'][$key] = $this->db->get()->result_array(); + } + + return $data; + } + + public function getSummaryData(array $inputs) + { + $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit'); + $this->db->from('sales_items_temp'); + $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and discount_percent >= '.$inputs['discount']); + + if ($inputs['sale_type'] == 'sales') + { + $this->db->where('quantity_purchased > 0'); + } + elseif ($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } + + return $this->db->get()->row_array(); + } +} +?> \ No newline at end of file diff --git a/application/models/sale.php b/application/models/sale.php index 66af0a43c..493644111 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -176,8 +176,9 @@ 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, ".$this->db->dbprefix('sales_items').".sale_id, comment,payment_type, customer_id, employee_id, + (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, discount_percent, (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) as subtotal, ".$this->db->dbprefix('sales_items').".line as line, serialnumber, ".$this->db->dbprefix('sales_items').".description as description, @@ -187,6 +188,10 @@ class Sale extends CI_Model FROM ".$this->db->dbprefix('sales_items')." INNER JOIN ".$this->db->dbprefix('sales')." ON ".$this->db->dbprefix('sales_items').'.sale_id='.$this->db->dbprefix('sales').'.sale_id'." INNER JOIN ".$this->db->dbprefix('items')." ON ".$this->db->dbprefix('sales_items').'.item_id='.$this->db->dbprefix('items').'.item_id'." + INNER JOIN (SELECT sale_id, SUM(payment_amount) AS sale_payment_amount, + GROUP_CONCAT(payment_type SEPARATOR ', ') AS payment_type FROM " .$this->db->dbprefix('sales_payments') . " + WHERE payment_type <> '" . $this->lang->line('sales_check') . "' GROUP BY sale_id) AS payments + ON " . $this->db->dbprefix('sales_items') . '.sale_id'. "=" . "payments.sale_id LEFT OUTER JOIN ".$this->db->dbprefix('suppliers')." ON ".$this->db->dbprefix('items').'.supplier_id='.$this->db->dbprefix('suppliers').'.person_id'." LEFT OUTER JOIN ".$this->db->dbprefix('sales_items_taxes')." ON " .$this->db->dbprefix('sales_items').'.sale_id='.$this->db->dbprefix('sales_items_taxes').'.sale_id'." and " diff --git a/application/views/reports/date_input.php b/application/views/reports/date_input.php index 7e98c9bed..3f2095ad2 100644 --- a/application/views/reports/date_input.php +++ b/application/views/reports/date_input.php @@ -14,6 +14,7 @@ if(isset($error))