From 9f1485cfe562010d60d9203d892f1bfa1fd0834e Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Mon, 17 Aug 2015 11:13:04 +0100 Subject: [PATCH] Added Cost & Count to reports, improved Items suggest, added copyrights and some fixes Added cost and count to reports - Added cost in temp table, reports at bottom of page and in each summary and detailed report - Added count in all the reports - Renamed some report fields name to make it generic and consistent across views - Fixed few issues here and there - Adjusted some code indentation NOTE: Proper translation of word Cost is required in all the languages but English Improved Items suggestion - Added select to restrict results fields - Added distinct in suppliers instead of the array match - Added $is_deleted in model part but is not still effective Add copyright statements in COPYING license file - Added jekkos and FrancescoUK / daN4cat Other people that contributed should add their statements. --- COPYING | 2 + application/controllers/items.php | 4 +- application/controllers/reports.php | 39 +++++++++++-------- application/language/en/reports_lang.php | 1 + application/language/es/reports_lang.php | 1 + application/language/fr/reports_lang.php | 1 + application/language/id/reports_lang.php | 1 + application/language/nl-BE/reports_lang.php | 1 + application/language/ru/reports_lang.php | 1 + application/language/th/reports_lang.php | 1 + application/language/tr/reports_lang.php | 1 + application/language/zh/reports_lang.php | 1 + application/models/item.php | 39 ++++++++++++------- application/models/receiving.php | 3 +- .../models/reports/detailed_receivings.php | 8 ++-- application/models/reports/detailed_sales.php | 24 +++++++----- application/models/reports/inventory_low.php | 10 ++--- .../models/reports/inventory_summary.php | 14 +++---- .../models/reports/specific_customer.php | 20 ++++++---- .../models/reports/specific_discount.php | 14 +++---- .../models/reports/specific_employee.php | 14 ++++--- .../models/reports/summary_categories.php | 11 ++++-- .../models/reports/summary_customers.php | 14 ++++--- .../models/reports/summary_discounts.php | 13 +++++-- .../models/reports/summary_employees.php | 11 ++++-- application/models/reports/summary_items.php | 14 ++++--- .../models/reports/summary_payments.php | 15 ++++--- application/models/reports/summary_sales.php | 12 ++++-- .../models/reports/summary_suppliers.php | 14 ++++--- application/models/reports/summary_taxes.php | 11 +++--- application/models/sale.php | 6 ++- translations/reports_lang.csv | 1 + 32 files changed, 196 insertions(+), 126 deletions(-) diff --git a/COPYING b/COPYING index 4d5c26d40..fe83d1350 100644 --- a/COPYING +++ b/COPYING @@ -1,6 +1,8 @@ The MIT License (MIT) Copyright (c) 2014 pappastech +Copyright (c) 2014-2015 jekkos +Copyright (c) 2015 FrancescoUK aka daN4cat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/application/controllers/items.php b/application/controllers/items.php index d126fec64..a2ce4507a 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -88,13 +88,13 @@ class Items extends Secure_area implements iData_controller */ function suggest() { - $suggestions = $this->Item->get_search_suggestions($this->input->post('q'),$this->input->post('limit')); + $suggestions = $this->Item->get_search_suggestions($this->input->post('q'), $this->input->post('limit')/*, $this->input->post('is_deleted')*/); // TODO: is_deleted doesn't seem to be effective... echo implode("\n",$suggestions); } function item_search() { - $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit'),'warehouse'); + $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'), $this->input->post('limit')); echo implode("\n",$suggestions); } diff --git a/application/controllers/reports.php b/application/controllers/reports.php index 462ec1576..6f029808d 100644 --- a/application/controllers/reports.php +++ b/application/controllers/reports.php @@ -69,6 +69,7 @@ class Reports extends Secure_area to_currency($report_data['subtotal']), to_currency($report_data['total']), to_currency($report_data['tax']), + to_currency($report_data['cost']), to_currency($report_data['profit']), $report_data['payment_type'], $report_data['comment']); @@ -118,7 +119,7 @@ class Reports extends Secure_area foreach($report_data as $row) { - $tabular_data[] = array($row['sale_date'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),to_currency($row['profit'])); + $tabular_data[] = array($row['sale_date'], $row['quantity_purchased'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), to_currency($row['profit'])); } $data = array( @@ -143,7 +144,7 @@ class Reports extends Secure_area foreach($report_data as $row) { - $tabular_data[] = array($row['category'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),to_currency($row['profit'])); + $tabular_data[] = array($row['category'], $row['quantity_purchased'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), to_currency($row['profit'])); } $data = array( @@ -168,7 +169,7 @@ class Reports extends Secure_area foreach($report_data as $row) { - $tabular_data[] = array($row['customer'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),to_currency($row['profit'])); + $tabular_data[] = array($row['customer'], $row['quantity_purchased'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), to_currency($row['profit'])); } $data = array( @@ -193,7 +194,7 @@ class Reports extends Secure_area foreach($report_data as $row) { - $tabular_data[] = array($row['supplier'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),to_currency($row['profit'])); + $tabular_data[] = array($row['supplier'], $row['quantity_purchased'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), to_currency($row['profit'])); } $data = array( @@ -218,7 +219,7 @@ class Reports extends Secure_area foreach($report_data as $row) { - $tabular_data[] = array(character_limiter($row['name'], 16), $row['quantity_purchased'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),to_currency($row['profit'])); + $tabular_data[] = array(character_limiter($row['name'], 40), $row['quantity_purchased'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), to_currency($row['profit'])); } $data = array( @@ -243,7 +244,7 @@ class Reports extends Secure_area foreach($report_data as $row) { - $tabular_data[] = array($row['employee'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),to_currency($row['profit'])); + $tabular_data[] = array($row['employee'], $row['quantity_purchased'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), to_currency($row['profit'])); } $data = array( @@ -268,7 +269,7 @@ class Reports extends Secure_area foreach($report_data as $row) { - $tabular_data[] = array($row['percent'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax'])); + $tabular_data[] = array($row['percent'], $row['count'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax'])); } $data = array( @@ -293,7 +294,7 @@ class Reports extends Secure_area foreach($report_data as $row) { - $tabular_data[] = array($row['discount_percent'],$row['count']); + $tabular_data[] = array($row['discount_percent'], $row['count']); } $data = array( @@ -308,6 +309,7 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } + //Summary payments report function summary_payments($start_date, $end_date, $sale_type, $export_excel=0) { $this->load->model('reports/Summary_payments'); @@ -317,7 +319,7 @@ class Reports extends Secure_area foreach($report_data as $row) { - $tabular_data[] = array($row['payment_type'],to_currency($row['payment_amount'])); + $tabular_data[] = array($row['payment_type'], $row['count'], to_currency($row['payment_amount'])); } $data = array( @@ -477,6 +479,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/pie",$data); } + //Graphical summary suppliers report function graphical_summary_suppliers($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_suppliers'); @@ -513,6 +516,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/pie",$data); } + //Graphical summary employees report function graphical_summary_employees($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_employees'); @@ -549,6 +553,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/pie",$data); } + //Graphical summary taxes report function graphical_summary_taxes($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_taxes'); @@ -663,6 +668,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/bar",$data); } + //Graphical summary payments report function graphical_summary_payments($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_payments'); @@ -700,6 +706,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/pie",$data); } + function specific_customer_input() { $data = $this->_get_common_report_data(); @@ -727,11 +734,11 @@ class Reports extends Secure_area 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['employee_name'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),to_currency($row['profit']), $row['payment_type'], $row['comment']); + $summary_data[] = array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target' => '_blank')), $row['sale_date'], $row['items_purchased'], $row['employee_name'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), 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['serialnumber'], $drow['description'], $drow['quantity_purchased'], to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']),to_currency($drow['profit']), $drow['discount_percent'].'%'); + $details_data[$key][] = array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], $drow['quantity_purchased'], to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%'); } } @@ -777,11 +784,11 @@ class Reports extends Secure_area 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']); + $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['cost']), 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['serialnumber'], $drow['description'], $drow['quantity_purchased'], to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']),to_currency($drow['profit']), $drow['discount_percent'].'%'); + $details_data[$key][] = array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], $drow['quantity_purchased'], to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%'); } } @@ -831,7 +838,7 @@ class Reports extends Secure_area foreach($report_data['details'][$key] as $drow) { - $details_data[$key][] = array($drow['name'], $drow['description'], $drow['quantity_purchased'], to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']),/*to_currency($drow['profit']),*/ $drow['discount_percent'].'%'); + $details_data[$key][] = array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], $drow['quantity_purchased'], to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']),/*to_currency($drow['profit']),*/ $drow['discount_percent'].'%'); } } @@ -865,7 +872,7 @@ class Reports extends Secure_area foreach($report_data['summary'] as $key=>$row) { - $summary_data[] = array(anchor('sales/edit/'.$row['sale_id'] . '/width:'.FORM_WIDTH, 'POS '.$row['sale_id'], array('class' => 'thickbox')), $row['sale_date'], $row['items_purchased'], $row['employee_name'], $row['customer_name'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),to_currency($row['profit']), $row['payment_type'], $row['comment']); + $summary_data[] = array(anchor('sales/edit/'.$row['sale_id'] . '/width:'.FORM_WIDTH, 'POS '.$row['sale_id'], array('class' => 'thickbox')), $row['sale_date'], $row['items_purchased'], $row['employee_name'], $row['customer_name'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), to_currency($row['profit']), $row['payment_type'], $row['comment']); foreach($report_data['details'][$key] as $drow) { @@ -874,7 +881,7 @@ class Reports extends Secure_area { $quantity_purchased .= ' [' . $this->Stock_locations->get_location_name($drow['item_location']) . ']'; } - $details_data[$key][] = array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], $quantity_purchased, to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']),to_currency($drow['profit']), $drow['discount_percent'].'%'); + $details_data[$key][] = array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], $quantity_purchased, to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%'); } } diff --git a/application/language/en/reports_lang.php b/application/language/en/reports_lang.php index 36ec9bd38..4886f1ff9 100644 --- a/application/language/en/reports_lang.php +++ b/application/language/en/reports_lang.php @@ -48,6 +48,7 @@ $lang["reports_payment_type"] = "Payment Type"; $lang["reports_payments"] = "Payments"; $lang["reports_payments_summary_report"] = "Payments Summary Report"; $lang["reports_profit"] = "Profit"; +$lang["reports_cost"] = "Cost"; $lang["reports_quantity_purchased"] = "Quantity Purchased"; $lang["reports_received_by"] = "Received By"; $lang["reports_receiving_id"] = "Receiving ID"; diff --git a/application/language/es/reports_lang.php b/application/language/es/reports_lang.php index 5d3ecb151..f80c834ed 100644 --- a/application/language/es/reports_lang.php +++ b/application/language/es/reports_lang.php @@ -48,6 +48,7 @@ $lang["reports_payment_type"] = "Tipo de Pago"; $lang["reports_payments"] = "Pagos"; $lang["reports_payments_summary_report"] = "Reporte de Resumen de Pagos"; $lang["reports_profit"] = "Ganancia"; +$lang["reports_cost"] = "Cost"; $lang["reports_quantity_purchased"] = "Cantidad Comprada"; $lang["reports_received_by"] = "Recibido por"; $lang["reports_receiving_id"] = "ID de Recepción"; diff --git a/application/language/fr/reports_lang.php b/application/language/fr/reports_lang.php index 5a270574b..6c35f4dda 100644 --- a/application/language/fr/reports_lang.php +++ b/application/language/fr/reports_lang.php @@ -48,6 +48,7 @@ $lang["reports_payment_type"] = "Type Paiement"; $lang["reports_payments"] = "Paiements"; $lang["reports_payments_summary_report"] = "Rapport: Résumé des Paiements"; $lang["reports_profit"] = "Bénéfice"; +$lang["reports_cost"] = "Cost"; $lang["reports_quantity_purchased"] = "Quantité Achetée"; $lang["reports_received_by"] = "Recu par"; $lang["reports_receiving_id"] = ""; diff --git a/application/language/id/reports_lang.php b/application/language/id/reports_lang.php index b6c4f2f91..0bd2d2cc5 100644 --- a/application/language/id/reports_lang.php +++ b/application/language/id/reports_lang.php @@ -48,6 +48,7 @@ $lang["reports_payment_type"] = "Tipe Pembayaran"; $lang["reports_payments"] = "Pembayaran"; $lang["reports_payments_summary_report"] = "Laporan Ringkasan Pembayaran"; $lang["reports_profit"] = "Keuntungan/Laba"; +$lang["reports_cost"] = "Cost"; $lang["reports_quantity_purchased"] = "Jumlah Dibeli"; $lang["reports_received_by"] = "Diterima Oleh"; $lang["reports_receiving_id"] = "Id Penerima"; diff --git a/application/language/nl-BE/reports_lang.php b/application/language/nl-BE/reports_lang.php index 723635ec1..29ac3dd48 100755 --- a/application/language/nl-BE/reports_lang.php +++ b/application/language/nl-BE/reports_lang.php @@ -48,6 +48,7 @@ $lang["reports_payment_type"] = "Betaald"; $lang["reports_payments"] = "Betalingen"; $lang["reports_payments_summary_report"] = "Overzicht Betalingen"; $lang["reports_profit"] = "Winst"; +$lang["reports_cost"] = "Cost"; $lang["reports_quantity_purchased"] = "Aangekochte Hoeveelheid"; $lang["reports_received_by"] = "Ontvangen door"; $lang["reports_receiving_id"] = ""; diff --git a/application/language/ru/reports_lang.php b/application/language/ru/reports_lang.php index 69d99b8f0..85816ff57 100644 --- a/application/language/ru/reports_lang.php +++ b/application/language/ru/reports_lang.php @@ -48,6 +48,7 @@ $lang["reports_payment_type"] = "Вид оплаты"; $lang["reports_payments"] = "Оплаты"; $lang["reports_payments_summary_report"] = "Платежей Сводный отчет"; $lang["reports_profit"] = "прибыль"; +$lang["reports_cost"] = "Cost"; $lang["reports_quantity_purchased"] = "купенный количество"; $lang["reports_received_by"] = "получило за"; $lang["reports_receiving_id"] = ""; diff --git a/application/language/th/reports_lang.php b/application/language/th/reports_lang.php index e190fd4dd..8ff3a0186 100644 --- a/application/language/th/reports_lang.php +++ b/application/language/th/reports_lang.php @@ -48,6 +48,7 @@ $lang["reports_payment_type"] = "ชนิดของการจ่าย"; $lang["reports_payments"] = "รายจ่าย"; $lang["reports_payments_summary_report"] = "รายงานสรุปการจ่าย"; $lang["reports_profit"] = "กำไร"; +$lang["reports_cost"] = "Cost"; $lang["reports_quantity_purchased"] = "จำนวนการช์้อ"; $lang["reports_received_by"] = "รับโดย"; $lang["reports_receiving_id"] = "IDรับสินค้า"; diff --git a/application/language/tr/reports_lang.php b/application/language/tr/reports_lang.php index 7ed27f776..9b7fbb883 100644 --- a/application/language/tr/reports_lang.php +++ b/application/language/tr/reports_lang.php @@ -48,6 +48,7 @@ $lang["reports_payment_type"] = "Ödeme Türü"; $lang["reports_payments"] = "Ödemeler"; $lang["reports_payments_summary_report"] = "Ödeme Özet Raporu"; $lang["reports_profit"] = "Kâr"; +$lang["reports_cost"] = "Cost"; $lang["reports_quantity_purchased"] = "Satın Alınan Adet"; $lang["reports_received_by"] = "Alım Yapan"; $lang["reports_receiving_id"] = "Alım No"; diff --git a/application/language/zh/reports_lang.php b/application/language/zh/reports_lang.php index db59a306f..5be9049c0 100755 --- a/application/language/zh/reports_lang.php +++ b/application/language/zh/reports_lang.php @@ -48,6 +48,7 @@ $lang["reports_payment_type"] = "付款方式"; $lang["reports_payments"] = "付款"; $lang["reports_payments_summary_report"] = "收入報告摘要"; $lang["reports_profit"] = "利潤"; +$lang["reports_cost"] = "Cost"; $lang["reports_quantity_purchased"] = "銷售金額"; $lang["reports_received_by"] = "收款人"; $lang["reports_receiving_id"] = ""; diff --git a/application/models/item.php b/application/models/item.php index 8de98d0d4..a602a19a3 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -141,7 +141,7 @@ class Item extends CI_Model $this->db->from('items'); $this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left'); $this->db->where('item_number',$item_number); - $this->db->where('items.deleted',0); // Parq 131226 + $this->db->where('items.deleted',0); // Parq 131226 $query = $this->db->get(); @@ -214,13 +214,14 @@ class Item extends CI_Model /* Get search suggestions to find items */ - function get_search_suggestions($search,$limit=25) + function get_search_suggestions($search, $limit=25, $is_deleted=0) { $suggestions = array(); + $this->db->select('name'); $this->db->from('items'); $this->db->like('name', $search); - $this->db->where('deleted',0); + $this->db->where('deleted', $is_deleted); $this->db->order_by("name", "asc"); $by_name = $this->db->get(); foreach($by_name->result() as $row) @@ -230,7 +231,7 @@ class Item extends CI_Model $this->db->select('category'); $this->db->from('items'); - $this->db->where('deleted',0); + $this->db->where('deleted', $is_deleted); $this->db->distinct(); $this->db->like('category', $search); $this->db->order_by("category", "asc"); @@ -240,9 +241,10 @@ class Item extends CI_Model $suggestions[]=$row->category; } + $this->db->select('item_number'); $this->db->from('items'); $this->db->like('item_number', $search); - $this->db->where('deleted',0); + $this->db->where('deleted', $is_deleted); $this->db->order_by("item_number", "asc"); $by_item_number = $this->db->get(); foreach($by_item_number->result() as $row) @@ -250,9 +252,11 @@ class Item extends CI_Model $suggestions[]=$row->item_number; } + $this->db->select('company_name'); $this->db->from('suppliers'); $this->db->like('company_name', $search); - $this->db->where('deleted', 0); + $this->db->where('deleted', $is_deleted); + $this->db->distinct(); $this->db->order_by("company_name", "asc"); $by_company_name = $this->db->get(); foreach($by_company_name->result() as $row) @@ -264,9 +268,10 @@ class Item extends CI_Model /** GARRISON ADDED 4/21/2013 **/ //Search by description + $this->db->select('name, description'); $this->db->from('items'); $this->db->like('description', $search); - $this->db->where('deleted',0); + $this->db->where('deleted', $is_deleted); $this->db->order_by("description", "asc"); $by_name = $this->db->get(); foreach($by_name->result() as $row) @@ -291,7 +296,7 @@ class Item extends CI_Model $this->db->or_like('custom8', $search); $this->db->or_like('custom9', $search); $this->db->or_like('custom10', $search); - $this->db->where('deleted',0); + $this->db->where('deleted', $is_deleted); $this->db->order_by("name", "asc"); $by_name = $this->db->get(); foreach($by_name->result() as $row) @@ -303,18 +308,19 @@ class Item extends CI_Model //only return $limit suggestions if(count($suggestions > $limit)) { - $suggestions = array_slice($suggestions, 0,$limit); + $suggestions = array_slice($suggestions, 0, $limit); } - return $suggestions; + return $suggestions; } - function get_item_search_suggestions($search,$limit=25) + function get_item_search_suggestions($search, $limit=25, $is_deleted=0) { $suggestions = array(); + $this->db->select('item_id, name'); $this->db->from('items'); - $this->db->where('deleted',0); + $this->db->where('deleted', $is_deleted); $this->db->like('name', $search); $this->db->order_by("name", "asc"); $by_name = $this->db->get(); @@ -323,8 +329,9 @@ class Item extends CI_Model $suggestions[]=$row->item_id.'|'.$row->name; } + $this->db->select('item_id, item_number'); $this->db->from('items'); - $this->db->where('deleted',0); + $this->db->where('deleted', $is_deleted); $this->db->like('item_number', $search); $this->db->order_by("item_number", "asc"); $by_item_number = $this->db->get(); @@ -334,8 +341,9 @@ class Item extends CI_Model } /** GARRISON ADDED 4/21/2013 **/ //Search by description + $this->db->select('item_id, name, description'); $this->db->from('items'); - $this->db->where('deleted',0); + $this->db->where('deleted', $is_deleted); $this->db->like('description', $search); $this->db->order_by("description", "asc"); $by_description = $this->db->get(); @@ -352,7 +360,7 @@ class Item extends CI_Model /** GARRISON ADDED 4/22/2013 **/ //Search by custom fields /* $this->db->from('items'); - $this->db->where('deleted',0); + $this->db->where('deleted', $is_deleted); $this->db->like('custom1', $search); $this->db->or_like('custom2', $search); $this->db->or_like('custom3', $search); @@ -376,6 +384,7 @@ class Item extends CI_Model { $suggestions = array_slice($suggestions, 0,$limit); } + return $suggestions; } diff --git a/application/models/receiving.php b/application/models/receiving.php index b6ee9c13f..00585041d 100644 --- a/application/models/receiving.php +++ b/application/models/receiving.php @@ -219,7 +219,8 @@ class Receiving extends CI_Model item_cost_price, item_unit_price, discount_percent, (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) as subtotal, ".$this->db->dbprefix('receivings_items').".line as line, serialnumber, ".$this->db->dbprefix('receivings_items').".description as description, (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) as total, - (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) - (item_cost_price*quantity_purchased) as profit + (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) - (item_cost_price*quantity_purchased) as profit, + (item_cost_price*quantity_purchased) as cost FROM ".$this->db->dbprefix('receivings_items')." INNER JOIN ".$this->db->dbprefix('receivings')." ON ".$this->db->dbprefix('receivings_items').'.receiving_id='.$this->db->dbprefix('receivings').'.receiving_id'." INNER JOIN ".$this->db->dbprefix('items')." ON ".$this->db->dbprefix('receivings_items').'.item_id='.$this->db->dbprefix('items').'.item_id'." diff --git a/application/models/reports/detailed_receivings.php b/application/models/reports/detailed_receivings.php index b4dba031e..aab318156 100644 --- a/application/models/reports/detailed_receivings.php +++ b/application/models/reports/detailed_receivings.php @@ -9,18 +9,19 @@ class Detailed_receivings extends Report public function getDataColumns() { - return array('summary' => array($this->lang->line('reports_receiving_id'), $this->lang->line('reports_date'), $this->lang->line('reports_items_received'), $this->lang->line('reports_received_by'), $this->lang->line('reports_supplied_by'), $this->lang->line('reports_total'), $this->lang->line('reports_payment_type'), $this->lang->line('recvs_invoice_number'), $this->lang->line('reports_comments')), - 'details' => array($this->lang->line('reports_item_number'), $this->lang->line('reports_name'), $this->lang->line('reports_category'), $this->lang->line('reports_quantity_purchased'), $this->lang->line('reports_total'), $this->lang->line('reports_discount')) + return array('summary' => array($this->lang->line('reports_receiving_id'), $this->lang->line('reports_date'), $this->lang->line('reports_count'), $this->lang->line('reports_received_by'), $this->lang->line('reports_supplied_by'), $this->lang->line('reports_total'), $this->lang->line('reports_payment_type'), $this->lang->line('recvs_invoice_number'), $this->lang->line('reports_comments')), + 'details' => array($this->lang->line('reports_item_number'), $this->lang->line('reports_name'), $this->lang->line('reports_category'), $this->lang->line('reports_count'), $this->lang->line('reports_total'), $this->lang->line('reports_discount')) ); } public function getDataByReceivingId($receiving_id) { - $this->db->select('receiving_id, DATE_FORMAT(receiving_date, "%d-%m-%Y") AS receiving_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, suppliers.company_name as supplier_name, sum(subtotal) as subtotal, sum(total) as total, sum(profit) as profit, payment_type, comment, invoice_number', false); + $this->db->select('receiving_id, DATE_FORMAT(receiving_date, "%d-%m-%Y") AS receiving_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name, " ", employee.last_name) as employee_name, suppliers.company_name as supplier_name, sum(subtotal) as subtotal, sum(total) as total, sum(profit) as profit, payment_type, comment, invoice_number', false); $this->db->from('receivings_items_temp'); $this->db->join('people as employee', 'receivings_items_temp.employee_id = employee.person_id'); $this->db->join('suppliers as suppliers', 'receivings_items_temp.supplier_id = suppliers.person_id', 'left'); $this->db->where('receiving_id', $receiving_id); + return $this->db->get()->row_array(); } @@ -72,6 +73,7 @@ class Detailed_receivings extends Report $this->db->select('sum(total) as total'); $this->db->from('receivings_items_temp'); $this->db->where('receiving_date BETWEEN '. $this->db->escape($inputs['start_date']). ' and '. $this->db->escape($inputs['end_date'])); + if ($inputs['location_id'] != 'all') { $this->db->where('item_location', $inputs['location_id']); diff --git a/application/models/reports/detailed_sales.php b/application/models/reports/detailed_sales.php index f59035933..f428f19f2 100644 --- a/application/models/reports/detailed_sales.php +++ b/application/models/reports/detailed_sales.php @@ -9,32 +9,35 @@ class Detailed_sales extends Report public function getDataColumns() { - return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_items_purchased'), $this->lang->line('reports_sold_by'), $this->lang->line('reports_sold_to'), $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_serial_number'), $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')) + return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_count'), $this->lang->line('reports_sold_by'), $this->lang->line('reports_sold_to'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $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_serial_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'), $this->lang->line('reports_discount')) ); } public function getDataBySaleId($sale_id) { - $this->db->select('sale_id, DATE_FORMAT(sale_time, "%d-%m-%Y") AS sale_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, CONCAT(customer.first_name," ",customer.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->select('sale_id, DATE_FORMAT(sale_time, "%d-%m-%Y") AS sale_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name, " ", employee.last_name) as employee_name, CONCAT(customer.first_name," ",customer.last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit, payment_type, comment', false); $this->db->from('sales_items_temp'); $this->db->join('people as employee', 'sales_items_temp.employee_id = employee.person_id'); $this->db->join('people as customer', 'sales_items_temp.customer_id = customer.person_id', 'left'); $this->db->where('sale_id', $sale_id); + return $this->db->get()->row_array(); } public function getData(array $inputs) { - $this->db->select('sale_id, sale_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, CONCAT(customer.first_name," ",customer.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->select('sale_id, sale_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, CONCAT(customer.first_name," ",customer.last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit, payment_type, comment', false); $this->db->from('sales_items_temp'); $this->db->join('people as employee', 'sales_items_temp.employee_id = employee.person_id'); $this->db->join('people as customer', 'sales_items_temp.customer_id = customer.person_id', 'left'); $this->db->where('sale_date BETWEEN '. $this->db->escape($inputs['start_date']). ' and '. $this->db->escape($inputs['end_date'])); + if ($inputs['location_id'] != 'all') { $this->db->where('item_location', $inputs['location_id']); } + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -42,7 +45,8 @@ class Detailed_sales extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + $this->db->group_by('sale_id'); $this->db->order_by('sale_date'); @@ -52,7 +56,7 @@ class Detailed_sales extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, quantity_purchased, item_location, serialnumber, sales_items_temp.description, subtotal,total, tax, profit, discount_percent'); + $this->db->select('name, category, quantity_purchased, item_location, serialnumber, sales_items_temp.description, subtotal, total, tax, cost, 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']); @@ -64,13 +68,15 @@ class Detailed_sales extends Report 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN '. $this->db->escape($inputs['start_date']). ' and '. $this->db->escape($inputs['end_date'])); + if ($inputs['location_id'] != 'all') { $this->db->where('item_location', $inputs['location_id']); } + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -78,8 +84,8 @@ class Detailed_sales extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } - + } + return $this->db->get()->row_array(); } } diff --git a/application/models/reports/inventory_low.php b/application/models/reports/inventory_low.php index 3c460a7b8..1d409d715 100644 --- a/application/models/reports/inventory_low.php +++ b/application/models/reports/inventory_low.php @@ -17,16 +17,12 @@ class Inventory_low extends Report $this->db->from('items'); $this->db->join('item_quantities','items.item_id=item_quantities.item_id'); $this->db->join('stock_locations','item_quantities.location_id=stock_locations.location_id'); - - $this->db->select('name, item_number, reorder_level, item_quantities.quantity,description,location_name'); - + $this->db->select('name, item_number, reorder_level, item_quantities.quantity, description, location_name'); $this->db->where('item_quantities.quantity <= reorder_level'); - $this->db->where('items.deleted = 0'); - + $this->db->where('items.deleted', 0); $this->db->order_by('name'); - + return $this->db->get()->result_array(); - } public function getSummaryData(array $inputs) diff --git a/application/models/reports/inventory_summary.php b/application/models/reports/inventory_summary.php index 4525f1255..e0591f6a3 100644 --- a/application/models/reports/inventory_summary.php +++ b/application/models/reports/inventory_summary.php @@ -9,21 +9,19 @@ class Inventory_summary extends Report public function getDataColumns() { - return array($this->lang->line('reports_item_name'), $this->lang->line('reports_item_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_reorder_level'),$this->lang->line('reports_stock_location')); + return array($this->lang->line('reports_item_name'), $this->lang->line('reports_item_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_reorder_level'), $this->lang->line('reports_stock_location')); } public function getData(array $inputs) { - $this->db->from('items'); + $this->db->from('items'); $this->db->join('item_quantities','items.item_id=item_quantities.item_id'); $this->db->join('stock_locations','item_quantities.location_id=stock_locations.location_id'); - - $this->db->select('name, item_number, reorder_level, item_quantities.quantity, description,location_name'); - $this->db->where('items.deleted', 0); - $this->db->order_by('items.name'); - - return $this->db->get()->result_array(); + $this->db->select('name, item_number, reorder_level, item_quantities.quantity, description, location_name'); + $this->db->where('items.deleted', 0); + $this->db->order_by('name'); + return $this->db->get()->result_array(); } public function getSummaryData(array $inputs) diff --git a/application/models/reports/specific_customer.php b/application/models/reports/specific_customer.php index 5a9d93907..744d1109a 100644 --- a/application/models/reports/specific_customer.php +++ b/application/models/reports/specific_customer.php @@ -9,17 +9,18 @@ class Specific_customer extends Report public function getDataColumns() { - return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_items_purchased'), $this->lang->line('reports_sold_by'), $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_serial_number'), $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')) + return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_count'), $this->lang->line('reports_sold_by'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $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_serial_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'), $this->lang->line('reports_discount')) ); } public function getData(array $inputs) { - $this->db->select('sale_id, sale_date, sum(quantity_purchased) as items_purchased, CONCAT(first_name," ",last_name) as employee_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit, payment_type, comment', false); + $this->db->select('sale_id, sale_date, sum(quantity_purchased) as items_purchased, CONCAT(first_name, " ", last_name) as employee_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit, payment_type, comment', false); $this->db->from('sales_items_temp'); $this->db->join('people', 'sales_items_temp.employee_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and customer_id='.$inputs['customer_id']); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -27,7 +28,8 @@ class Specific_customer extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + $this->db->group_by('sale_id'); $this->db->order_by('sale_date'); @@ -37,21 +39,22 @@ class Specific_customer extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, serialnumber, sales_items_temp.description, quantity_purchased, subtotal,total, tax, profit, discount_percent'); + $this->db->select('name, category, serialnumber, sales_items_temp.description, quantity_purchased, subtotal, total, tax, cost, 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']); $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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and customer_id='.$inputs['customer_id']); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -59,7 +62,8 @@ class Specific_customer extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + return $this->db->get()->row_array(); } } diff --git a/application/models/reports/specific_discount.php b/application/models/reports/specific_discount.php index 31656eca4..fbfd6657d 100755 --- a/application/models/reports/specific_discount.php +++ b/application/models/reports/specific_discount.php @@ -9,14 +9,14 @@ class Specific_discount extends Report public function getDataColumns() { - return array('summary' => 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')) + return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_count'), $this->lang->line('reports_sold_to'), $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_serial_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $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->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(cost) as cost, 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']); @@ -39,19 +39,19 @@ class Specific_discount extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, serialnumber, category, sales_items_temp.description, quantity_purchased, subtotal,total, tax, profit, discount_percent'); + $this->db->select('name, serialnumber, category, sales_items_temp.description, quantity_purchased, subtotal, total, tax, cost, 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, 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']); @@ -63,7 +63,7 @@ class Specific_discount extends Report { $this->db->where('quantity_purchased < 0'); } - + return $this->db->get()->row_array(); } } diff --git a/application/models/reports/specific_employee.php b/application/models/reports/specific_employee.php index 80b1cef39..0bab62cff 100644 --- a/application/models/reports/specific_employee.php +++ b/application/models/reports/specific_employee.php @@ -9,14 +9,14 @@ class Specific_employee extends Report public function getDataColumns() { - return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_items_purchased'), $this->lang->line('reports_sold_to'), $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_serial_number'), $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')) + return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_count'), $this->lang->line('reports_sold_to'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $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_serial_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'), $this->lang->line('reports_discount')) ); } public function getData(array $inputs) { - $this->db->select('sale_id, 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->select('sale_id, 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(cost) as cost, sum(profit) as profit, payment_type, comment', false); $this->db->from('sales_items_temp'); $this->db->join('people', 'sales_items_temp.customer_id = people.person_id', 'left'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and employee_id='.$inputs['employee_id']); @@ -39,7 +39,7 @@ class Specific_employee extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, serialnumber, sales_items_temp.description, quantity_purchased, subtotal,total, tax, profit, discount_percent'); + $this->db->select('name, category, serialnumber, sales_items_temp.description, quantity_purchased, subtotal, total, tax, cost, 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']); @@ -51,9 +51,10 @@ class Specific_employee extends Report 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and employee_id='.$inputs['employee_id']); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -61,7 +62,8 @@ class Specific_employee extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_categories.php b/application/models/reports/summary_categories.php index bf00bb974..5e0411a31 100644 --- a/application/models/reports/summary_categories.php +++ b/application/models/reports/summary_categories.php @@ -9,15 +9,16 @@ class Summary_categories extends Report public function getDataColumns() { - return array($this->lang->line('reports_category'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_category'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } public function getData(array $inputs) { - $this->db->select('category, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit'); + $this->db->select('category, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -25,7 +26,8 @@ class Summary_categories extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + $this->db->group_by('category'); $this->db->order_by('category'); @@ -34,10 +36,11 @@ class Summary_categories extends Report 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); diff --git a/application/models/reports/summary_customers.php b/application/models/reports/summary_customers.php index 0e500be0c..3eef68678 100644 --- a/application/models/reports/summary_customers.php +++ b/application/models/reports/summary_customers.php @@ -9,16 +9,17 @@ class Summary_customers extends Report public function getDataColumns() { - return array($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')); + return array($this->lang->line('reports_customer'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } public function getData(array $inputs) { - $this->db->select('CONCAT(first_name, " ",last_name) as customer, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax,sum(profit) as profit', false); + $this->db->select('CONCAT(first_name, " ",last_name) as customer, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit', false); $this->db->from('sales_items_temp'); $this->db->join('customers', 'customers.person_id = sales_items_temp.customer_id'); $this->db->join('people', 'customers.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -26,7 +27,8 @@ class Summary_customers extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + $this->db->group_by('customer_id'); $this->db->order_by('last_name'); @@ -35,11 +37,12 @@ class Summary_customers extends Report 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->join('customers', 'customers.person_id = sales_items_temp.customer_id'); $this->db->join('people', 'customers.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -47,7 +50,8 @@ class Summary_customers extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_discounts.php b/application/models/reports/summary_discounts.php index 0b98450a8..615fe4c65 100644 --- a/application/models/reports/summary_discounts.php +++ b/application/models/reports/summary_discounts.php @@ -9,7 +9,7 @@ class Summary_discounts extends Report public function getDataColumns() { - return array($this->lang->line('reports_discount_percent'),$this->lang->line('reports_count')); + return array($this->lang->line('reports_discount_percent'), $this->lang->line('reports_count')); } public function getData(array $inputs) @@ -17,6 +17,7 @@ class Summary_discounts extends Report $this->db->select('CONCAT(discount_percent, "%") as discount_percent, count(*) as count', false); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and discount_percent > 0'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -24,17 +25,20 @@ class Summary_discounts extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + $this->db->group_by('sales_items_temp.discount_percent'); $this->db->order_by('discount_percent'); + return $this->db->get()->result_array(); } 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -42,7 +46,8 @@ class Summary_discounts extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_employees.php b/application/models/reports/summary_employees.php index 214293f8e..8db239275 100644 --- a/application/models/reports/summary_employees.php +++ b/application/models/reports/summary_employees.php @@ -9,16 +9,17 @@ class Summary_employees extends Report public function getDataColumns() { - return array($this->lang->line('reports_employee'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_employee'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } public function getData(array $inputs) { - $this->db->select('CONCAT(first_name, " ",last_name) as employee, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit', false); + $this->db->select('CONCAT(first_name, " ", last_name) as employee, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit', false); $this->db->from('sales_items_temp'); $this->db->join('employees', 'employees.person_id = sales_items_temp.employee_id'); $this->db->join('people', 'employees.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -26,7 +27,8 @@ class Summary_employees extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + $this->db->group_by('employee_id'); $this->db->order_by('last_name'); @@ -35,11 +37,12 @@ class Summary_employees extends Report 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->join('employees', 'employees.person_id = sales_items_temp.employee_id'); $this->db->join('people', 'employees.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); diff --git a/application/models/reports/summary_items.php b/application/models/reports/summary_items.php index e1d08ad3d..7910792b4 100644 --- a/application/models/reports/summary_items.php +++ b/application/models/reports/summary_items.php @@ -9,15 +9,16 @@ class Summary_items extends Report public function getDataColumns() { - return array($this->lang->line('reports_item'),$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')); + return array($this->lang->line('reports_item'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } public function getData(array $inputs) { - $this->db->select('name, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit'); + $this->db->select('name, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -25,7 +26,8 @@ class Summary_items extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + $this->db->group_by('items.item_id'); $this->db->order_by('name'); @@ -34,10 +36,11 @@ class Summary_items extends Report 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -45,7 +48,8 @@ class Summary_items extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_payments.php b/application/models/reports/summary_payments.php index 4670b9127..23e2c5021 100644 --- a/application/models/reports/summary_payments.php +++ b/application/models/reports/summary_payments.php @@ -9,15 +9,16 @@ class Summary_payments extends Report public function getDataColumns() { - return array($this->lang->line('reports_payment_type'), $this->lang->line('reports_total')); + return array($this->lang->line('reports_payment_type'), $this->lang->line('reports_count'), $this->lang->line('reports_total')); } public function getData(array $inputs) { - $this->db->select('sales_payments.payment_type, SUM(payment_amount) as payment_amount', false); + $this->db->select('sales_payments.payment_type, count(*) as count, sum(payment_amount) as payment_amount', false); $this->db->from('sales_payments'); $this->db->join('sales', 'sales.sale_id=sales_payments.sale_id'); $this->db->where('date(sale_time) BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('payment_amount > 0'); @@ -25,17 +26,20 @@ class Summary_payments extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('payment_amount < 0'); - } + } + $this->db->group_by("payment_type"); + return $this->db->get()->result_array(); } 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -43,7 +47,8 @@ class Summary_payments extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_sales.php b/application/models/reports/summary_sales.php index 97c90757b..24517d680 100644 --- a/application/models/reports/summary_sales.php +++ b/application/models/reports/summary_sales.php @@ -9,13 +9,14 @@ class Summary_sales extends Report public function getDataColumns() { - return array($this->lang->line('reports_date'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_date'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } public function getData(array $inputs) { - $this->db->select('sale_date, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax,sum(profit) as profit'); + $this->db->select('sale_date, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -28,14 +29,16 @@ class Summary_sales extends Report $this->db->group_by('sale_date'); $this->db->having('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); $this->db->order_by('sale_date'); + return $this->db->get()->result_array(); } 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -43,7 +46,8 @@ class Summary_sales extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + return $this->db->get()->row_array(); } diff --git a/application/models/reports/summary_suppliers.php b/application/models/reports/summary_suppliers.php index d65c73ddc..757aa1f20 100644 --- a/application/models/reports/summary_suppliers.php +++ b/application/models/reports/summary_suppliers.php @@ -9,16 +9,17 @@ class Summary_suppliers extends Report public function getDataColumns() { - return array($this->lang->line('reports_supplier'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_supplier'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } public function getData(array $inputs) { - $this->db->select('CONCAT(company_name, " (", first_name, " ",last_name, ")") as supplier, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax,sum(profit) as profit', false); + $this->db->select('CONCAT(company_name, " (", first_name, " ",last_name, ")") as supplier, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit', false); $this->db->from('sales_items_temp'); $this->db->join('suppliers', 'suppliers.person_id = sales_items_temp.supplier_id'); $this->db->join('people', 'suppliers.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -26,7 +27,8 @@ class Summary_suppliers extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + $this->db->group_by('supplier_id'); $this->db->order_by('last_name'); @@ -35,11 +37,12 @@ class Summary_suppliers extends Report 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->join('suppliers', 'suppliers.person_id = sales_items_temp.supplier_id'); $this->db->join('people', 'suppliers.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); @@ -47,7 +50,8 @@ class Summary_suppliers extends Report elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_taxes.php b/application/models/reports/summary_taxes.php index 276da2836..bfc3a6daa 100644 --- a/application/models/reports/summary_taxes.php +++ b/application/models/reports/summary_taxes.php @@ -9,12 +9,11 @@ class Summary_taxes extends Report public function getDataColumns() { - return array($this->lang->line('reports_tax_percent'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax')); + return array($this->lang->line('reports_tax_percent'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax')); } public function getData(array $inputs) { - $quantity_cond = ''; if ($inputs['sale_type'] == 'sales') { @@ -38,7 +37,7 @@ class Summary_taxes extends Report $subtotal = "1"; } - $query = $this->db->query("SELECT percent, SUM(subtotal) as subtotal, sum(total) as total, sum(tax) as tax + $query = $this->db->query("SELECT percent, count(*) as count, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax FROM (SELECT name, CONCAT( percent, '%' ) AS percent, ROUND((item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100) * $subtotal, 2) AS subtotal, ROUND((item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100) * $total, 2) AS total, @@ -51,12 +50,13 @@ class Summary_taxes extends Report ." JOIN ".$this->db->dbprefix('sales')." ON ".$this->db->dbprefix('sales_items_taxes').".sale_id=".$this->db->dbprefix('sales').".sale_id WHERE date(sale_time) BETWEEN '".$inputs['start_date']."' and '".$inputs['end_date']."' $quantity_cond) as temp_taxes GROUP BY percent"); + return $query->result_array(); } 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->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); @@ -69,8 +69,7 @@ class Summary_taxes extends Report { $this->db->where('quantity_purchased < 0'); } - - + return $this->db->get()->row_array(); } } diff --git a/application/models/sale.php b/application/models/sale.php index ad4e6fc33..8d46818b6 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -402,7 +402,8 @@ class Sale extends CI_Model ".$this->db->dbprefix('sales_items').".line as line, serialnumber, ".$this->db->dbprefix('sales_items').".description as description, ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*$total, 2) as total, ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*$tax, 2) as tax, - ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)- (item_cost_price*quantity_purchased), 2) as profit + ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)- (item_cost_price*quantity_purchased), 2) as profit, + (item_cost_price*quantity_purchased) as cost 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'." @@ -416,7 +417,8 @@ class Sale extends CI_Model .$this->db->dbprefix('sales_items').'.line='.$this->db->dbprefix('sales_items_taxes').'.line'." GROUP BY sale_id, item_id, line)"); - //Update null item_tax_percents to be 0 instead of null$this->db->where('item_tax_percent IS NULL'); + //Update null item_tax_percents to be 0 instead of null + $this->db->where('item_tax_percent IS NULL'); $this->db->update('sales_items_temp', array('item_tax_percent' => 0)); //Update null tax to be 0 instead of null diff --git a/translations/reports_lang.csv b/translations/reports_lang.csv index e87ea27b1..345e63820 100644 --- a/translations/reports_lang.csv +++ b/translations/reports_lang.csv @@ -47,6 +47,7 @@ reports_payment_type,Betaald,Tipo de Pago,Payment Type,Type Paiement,付款方 reports_payments,Betalingen,Pagos,Payments,Paiements,付款,Оплаты,รายจ่าย,Ödemeler,Pembayaran reports_payments_summary_report,Overzicht Betalingen,Reporte de Resumen de Pagos,Payments Summary Report,Rapport: Résumé des Paiements,收入報告摘要,Платежей Сводный отчет,รายงานสรุปการจ่าย,Ödeme Özet Raporu,Laporan Ringkasan Pembayaran reports_profit,Winst,Ganancia,Profit,Bénéfice,利潤,прибыль,กำไร,Kâr,Keuntungan/Laba +reports_cost,Cost,Cost,Cost,Cost,Cost,Cost,Cost reports_quantity_purchased,Aangekochte Hoeveelheid,Cantidad Comprada,Quantity Purchased,Quantité Achetée,銷售金額,купенный количество,จำนวนการช์้อ,Satın Alınan Adet,Jumlah Dibeli reports_received_by,Ontvangen door,Recibido por,Received By,Recu par,收款人,получило за,รับโดย,Alım Yapan,Diterima Oleh reports_receiving_id,,ID de Recepción,Receiving ID,,,,IDรับสินค้า,Alım No,Id Penerima