diff --git a/application/controllers/items.php b/application/controllers/items.php index 80edcefa2..ccf235f9e 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -97,7 +97,7 @@ class Items extends Secure_area implements iData_controller $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit'),'warehouse'); echo implode("\n",$suggestions); } - + /* Gives search suggestions based on what is being searched for */ diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index b42df50e4..ac52abead 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -45,7 +45,7 @@ class Receivings extends Secure_area $mode = $this->input->post("mode"); $this->receiving_lib->set_mode($mode); } - else + else if ($this->Stock_locations->is_allowed_location($stock_source, 'receivings')) { $this->receiving_lib->set_stock_source($stock_source); $this->receiving_lib->set_stock_destination($stock_destination); @@ -183,8 +183,7 @@ class Receivings extends Secure_area $data['receipt_title']=$this->lang->line('recvs_receipt'); $data['transaction_time']= date('m/d/Y h:i:s a'); $data['mode']=$this->receiving_lib->get_mode(); - $stock_locations = $this->Stock_locations->get_undeleted_all('receivings')->result_array(); - $data['show_stock_locations'] = count($stock_locations) > 1; + $data['show_stock_locations']=$this->Stock_locations->show_locations('receivings'); $supplier_id=$this->receiving_lib->get_supplier(); $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; $comment = $this->input->post('comment'); @@ -308,8 +307,7 @@ class Receivings extends Secure_area $data['mode']=$this->receiving_lib->get_mode(); $data['receipt_title']=$this->lang->line('recvs_receipt'); $data['transaction_time']= date('m/d/Y h:i:s a', strtotime($receiving_info['receiving_time'])); - $stock_locations = $this->Stock_locations->get_undeleted_all('receivings')->result_array(); - $data['show_stock_locations'] = count($stock_locations) > 1; + $data['show_stock_locations']=$this->Stock_locations->show_locations('receivings'); $supplier_id=$this->receiving_lib->get_supplier(); $emp_info=$this->Employee->get_info($receiving_info['employee_id']); $data['payment_type']=$receiving_info['payment_type']; @@ -336,7 +334,7 @@ class Receivings extends Secure_area $data['cart']=$this->receiving_lib->get_cart(); $data['modes']=array('receive'=>$this->lang->line('recvs_receiving'),'return'=>$this->lang->line('recvs_return')); $data['mode']=$this->receiving_lib->get_mode(); - + $data['stock_locations']=$this->Stock_locations->get_allowed_locations('receivings'); $show_stock_locations = count($data['stock_locations']) > 1; if ($show_stock_locations) diff --git a/application/controllers/reports.php b/application/controllers/reports.php index c64e6db83..8d78cb39e 100644 --- a/application/controllers/reports.php +++ b/application/controllers/reports.php @@ -4,9 +4,9 @@ require_once (APPPATH."libraries/ofc-library/open-flash-chart.php"); define("FORM_WIDTH", "400"); -class Reports extends Secure_area -{ - +class Reports extends Secure_area +{ + function __construct() { parent::__construct('reports'); @@ -21,16 +21,16 @@ class Reports extends Secure_area { redirect('no_access/reports/reports_' . $submodule_id); } - $this->load->helper('report'); + $this->load->helper('report'); } - + //Initial report listing screen function index() { $data['grants']=$this->Employee->get_employee_grants($this->session->userdata('person_id')); - $this->load->view("reports/listing",$data); + $this->load->view("reports/listing",$data); } - + function _get_common_report_data() { $data = array(); @@ -40,48 +40,48 @@ class Reports extends Secure_area $data['years'] = get_years(); $data['selected_month']=date('n'); $data['selected_day']=date('d'); - $data['selected_year']=date('Y'); - + $data['selected_year']=date('Y'); + return $data; } - + //Input for reports that require only a date range and an export to excel. (see routes.php to see that all summary reports route here) function date_input_excel_export() { $data = $this->_get_common_report_data(); - $this->load->view("reports/date_input_excel_export",$data); + $this->load->view("reports/date_input_excel_export",$data); } - + function get_detailed_sales_row($sale_id) { $this->load->model('reports/Detailed_sales'); $model = $this->Detailed_sales; - + $report_data = $model->getDataBySaleId($sale_id); - - $summary_data = array(anchor('sales/edit/'.$report_data['sale_id'] . '/width:'.FORM_WIDTH, - 'POS '.$report_data['sale_id'], - array('class' => 'thickbox')), - $report_data['sale_date'], - $report_data['items_purchased'], - $report_data['employee_name'], - $report_data['customer_name'], - to_currency($report_data['subtotal']), - to_currency($report_data['total']), + + $summary_data = array(anchor('sales/edit/'.$report_data['sale_id'] . '/width:'.FORM_WIDTH, + 'POS '.$report_data['sale_id'], + array('class' => 'thickbox')), + $report_data['sale_date'], + $report_data['items_purchased'], + $report_data['employee_name'], + $report_data['customer_name'], + to_currency($report_data['subtotal']), + to_currency($report_data['total']), to_currency($report_data['tax']), - to_currency($report_data['profit']), - $report_data['payment_type'], + to_currency($report_data['profit']), + $report_data['payment_type'], $report_data['comment']); echo get_detailed_data_row($summary_data, $this); } - + function get_detailed_receivings_row($receiving_id) { $this->load->model('reports/Detailed_receivings'); $model = $this->Detailed_receivings; - + $report_data = $model->getDataByReceivingId($receiving_id); - + $summary_data = array(anchor('receivings/edit/'.$report_data['receiving_id'] . '/width:'.FORM_WIDTH, 'RECV '.$report_data['receiving_id'], array('class' => 'thickbox')), @@ -95,19 +95,19 @@ class Reports extends Secure_area $report_data['comment']); echo get_detailed_data_row($summary_data, $this); } - - function get_summary_data($start_date, $end_date = NULL, $sale_type=0) + + function get_summary_data($start_date, $end_date = NULL, $sale_type=0) { $end_date = $end_date ?: $start_date; $this->load->model('reports/Summary_sales'); $model = $this->Summary_sales; $summary = $model->getSummaryData(array( - 'start_date'=>$start_date, - 'end_date'=>$end_date, + 'start_date'=>$start_date, + 'end_date'=>$end_date, 'sale_type' => $sale_type)); echo get_sales_summary_totals($summary, $this); } - + //Summary sales report function summary_sales($start_date, $end_date, $sale_type, $export_excel=0) { @@ -115,7 +115,7 @@ class Reports extends Secure_area $model = $this->Summary_sales; $tabular_data = array(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + 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'])); @@ -132,7 +132,7 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } - + //Summary categories report function summary_categories($start_date, $end_date, $sale_type, $export_excel=0) { @@ -140,7 +140,7 @@ class Reports extends Secure_area $model = $this->Summary_categories; $tabular_data = array(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + 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'])); @@ -157,7 +157,7 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } - + //Summary customers report function summary_customers($start_date, $end_date, $sale_type, $export_excel=0) { @@ -165,7 +165,7 @@ class Reports extends Secure_area $model = $this->Summary_customers; $tabular_data = array(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + 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'])); @@ -182,7 +182,7 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } - + //Summary suppliers report function summary_suppliers($start_date, $end_date, $sale_type, $export_excel=0) { @@ -190,7 +190,7 @@ class Reports extends Secure_area $model = $this->Summary_suppliers; $tabular_data = array(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + 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'])); @@ -207,7 +207,7 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } - + //Summary items report function summary_items($start_date, $end_date, $sale_type, $export_excel=0) { @@ -215,7 +215,7 @@ class Reports extends Secure_area $model = $this->Summary_items; $tabular_data = array(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + 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'])); @@ -229,10 +229,10 @@ class Reports extends Secure_area "summary_data" => $model->getSummaryData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)), "export_excel" => $export_excel ); - + $this->load->view("reports/tabular",$data); } - + //Summary employees report function summary_employees($start_date, $end_date, $sale_type, $export_excel=0) { @@ -240,7 +240,7 @@ class Reports extends Secure_area $model = $this->Summary_employees; $tabular_data = array(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + 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'])); @@ -257,7 +257,7 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } - + //Summary taxes report function summary_taxes($start_date, $end_date, $sale_type, $export_excel=0) { @@ -265,7 +265,7 @@ class Reports extends Secure_area $model = $this->Summary_taxes; $tabular_data = array(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + foreach($report_data as $row) { $tabular_data[] = array($row['percent'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax'])); @@ -282,7 +282,7 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } - + //Summary discounts report function summary_discounts($start_date, $end_date, $sale_type, $export_excel=0) { @@ -290,7 +290,7 @@ class Reports extends Secure_area $model = $this->Summary_discounts; $tabular_data = array(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + foreach($report_data as $row) { $tabular_data[] = array($row['discount_percent'],$row['count']); @@ -307,14 +307,14 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } - + function summary_payments($start_date, $end_date, $sale_type, $export_excel=0) { $this->load->model('reports/Summary_payments'); $model = $this->Summary_payments; $tabular_data = array(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + foreach($report_data as $row) { $tabular_data[] = array($row['payment_type'],to_currency($row['payment_amount'])); @@ -331,29 +331,29 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } - + //Input for reports that require only a date range. (see routes.php to see that all graphical summary reports route here) function date_input() { $data = $this->_get_common_report_data(); $data['mode'] = 'sale'; - $this->load->view("reports/date_input",$data); + $this->load->view("reports/date_input",$data); } - + function date_input_recv() { $data = $this->_get_common_report_data(); $data['mode'] = 'receiving'; - $this->load->view("reports/date_input",$data); + $this->load->view("reports/date_input",$data); } - + function date_input_reqs() { $data = $this->_get_common_report_data(); $data['mode'] = 'requisition'; - $this->load->view("reports/date_input",$data); + $this->load->view("reports/date_input",$data); } - + //Graphical summary sales report function graphical_summary_sales($start_date, $end_date, $sale_type) { @@ -369,14 +369,14 @@ class Reports extends Secure_area $this->load->view("reports/graphical",$data); } - + //The actual graph data function graphical_summary_sales_graph($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_sales'); $model = $this->Summary_sales; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $graph_data = array(); foreach($report_data as $row) { @@ -393,7 +393,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/line",$data); } - + //Graphical summary items report function graphical_summary_items($start_date, $end_date, $sale_type) { @@ -409,14 +409,14 @@ class Reports extends Secure_area $this->load->view("reports/graphical",$data); } - + //The actual graph data function graphical_summary_items_graph($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_items'); $model = $this->Summary_items; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $graph_data = array(); foreach($report_data as $row) { @@ -432,7 +432,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/hbar",$data); } - + //Graphical summary customers report function graphical_summary_categories($start_date, $end_date, $sale_type) { @@ -448,20 +448,20 @@ class Reports extends Secure_area $this->load->view("reports/graphical",$data); } - + //The actual graph data function graphical_summary_categories_graph($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_categories'); $model = $this->Summary_categories; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $graph_data = array(); foreach($report_data as $row) { $graph_data[$row['category']] = $row['total']; } - + $data = array( "title" => $this->lang->line('reports_categories_summary_report'), "data" => $graph_data @@ -469,7 +469,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/pie",$data); } - + function graphical_summary_suppliers($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_suppliers'); @@ -484,20 +484,20 @@ class Reports extends Secure_area $this->load->view("reports/graphical",$data); } - + //The actual graph data function graphical_summary_suppliers_graph($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_suppliers'); $model = $this->Summary_suppliers; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $graph_data = array(); foreach($report_data as $row) { $graph_data[$row['supplier']] = $row['total']; } - + $data = array( "title" => $this->lang->line('reports_suppliers_summary_report'), "data" => $graph_data @@ -505,7 +505,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/pie",$data); } - + function graphical_summary_employees($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_employees'); @@ -520,20 +520,20 @@ class Reports extends Secure_area $this->load->view("reports/graphical",$data); } - + //The actual graph data function graphical_summary_employees_graph($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_employees'); $model = $this->Summary_employees; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $graph_data = array(); foreach($report_data as $row) { $graph_data[$row['employee']] = $row['total']; } - + $data = array( "title" => $this->lang->line('reports_employees_summary_report'), "data" => $graph_data @@ -541,7 +541,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/pie",$data); } - + function graphical_summary_taxes($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_taxes'); @@ -556,20 +556,20 @@ class Reports extends Secure_area $this->load->view("reports/graphical",$data); } - + //The actual graph data function graphical_summary_taxes_graph($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_taxes'); $model = $this->Summary_taxes; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $graph_data = array(); foreach($report_data as $row) { $graph_data[$row['percent']] = $row['total']; } - + $data = array( "title" => $this->lang->line('reports_taxes_summary_report'), "data" => $graph_data @@ -577,7 +577,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/pie",$data); } - + //Graphical summary customers report function graphical_summary_customers($start_date, $end_date, $sale_type) { @@ -593,20 +593,20 @@ class Reports extends Secure_area $this->load->view("reports/graphical",$data); } - + //The actual graph data function graphical_summary_customers_graph($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_customers'); $model = $this->Summary_customers; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $graph_data = array(); foreach($report_data as $row) { $graph_data[$row['customer']] = $row['total']; } - + $data = array( "title" => $this->lang->line('reports_customers_summary_report'), "xaxis_label"=>$this->lang->line('reports_revenue'), @@ -616,7 +616,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/hbar",$data); } - + //Graphical summary discounts report function graphical_summary_discounts($start_date, $end_date, $sale_type) { @@ -632,20 +632,20 @@ class Reports extends Secure_area $this->load->view("reports/graphical",$data); } - + //The actual graph data function graphical_summary_discounts_graph($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_discounts'); $model = $this->Summary_discounts; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $graph_data = array(); foreach($report_data as $row) { $graph_data[$row['discount_percent']] = $row['count']; } - + $data = array( "title" => $this->lang->line('reports_discounts_summary_report'), "yaxis_label"=>$this->lang->line('reports_count'), @@ -655,7 +655,7 @@ class Reports extends Secure_area $this->load->view("reports/graphs/bar",$data); } - + function graphical_summary_payments($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_payments'); @@ -670,20 +670,20 @@ class Reports extends Secure_area $this->load->view("reports/graphical",$data); } - + //The actual graph data function graphical_summary_payments_graph($start_date, $end_date, $sale_type) { $this->load->model('reports/Summary_payments'); $model = $this->Summary_payments; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $graph_data = array(); foreach($report_data as $row) { $graph_data[$row['payment_type']] = $row['payment_amount']; } - + $data = array( "title" => $this->lang->line('reports_payments_summary_report'), "yaxis_label"=>$this->lang->line('reports_revenue'), @@ -697,31 +697,31 @@ class Reports extends Secure_area { $data = $this->_get_common_report_data(); $data['specific_input_name'] = $this->lang->line('reports_customer'); - + $customers = array(); foreach($this->Customer->get_all()->result() as $customer) { $customers[$customer->person_id] = $customer->first_name .' '.$customer->last_name; } $data['specific_input_data'] = $customers; - $this->load->view("reports/specific_input",$data); + $this->load->view("reports/specific_input",$data); } function specific_customer($start_date, $end_date, $customer_id, $sale_type, $export_excel=0) { $this->load->model('reports/Specific_customer'); $model = $this->Specific_customer; - + $headers = $model->getDataColumns(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'customer_id' =>$customer_id, '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['employee_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['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'].'%'); @@ -742,36 +742,36 @@ class Reports extends Secure_area $this->load->view("reports/tabular_details",$data); } - + function specific_employee_input() { $data = $this->_get_common_report_data(); $data['specific_input_name'] = $this->lang->line('reports_employee'); - + $employees = array(); foreach($this->Employee->get_all()->result() as $employee) { $employees[$employee->person_id] = $employee->first_name .' '.$employee->last_name; } $data['specific_input_data'] = $employees; - $this->load->view("reports/specific_input",$data); + $this->load->view("reports/specific_input",$data); } function specific_employee($start_date, $end_date, $employee_id, $sale_type, $export_excel=0) { $this->load->model('reports/Specific_employee'); $model = $this->Specific_employee; - + $headers = $model->getDataColumns(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'employee_id' =>$employee_id, '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['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'].'%'); @@ -797,7 +797,7 @@ class Reports extends Secure_area { $data = $this->_get_common_report_data(); $data['specific_input_name'] = $this->lang->line('reports_discount'); - + $discounts = array(); for($i = 0; $i <= 100; $i += 10) { @@ -806,28 +806,28 @@ class Reports extends Secure_area $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) + + 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['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)), @@ -838,29 +838,36 @@ class Reports extends Secure_area "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) { $this->load->model('reports/Detailed_sales'); $model = $this->Detailed_sales; - + $headers = $model->getDataColumns(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); - + $summary_data = array(); $details_data = array(); - + + $show_locations = $this->Stock_locations->multiple_locations(); + 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']); - + 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'].'%'); + $quantity_purchased = $drow['quantity_purchased']; + if ($show_locations) + { + $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'].'%'); } } @@ -868,35 +875,41 @@ class Reports extends Secure_area "title" =>$this->lang->line('reports_detailed_sales_report'), "subtitle" => date('m/d/Y', strtotime($start_date)) .'-'.date('m/d/Y', strtotime($end_date)), "headers" => $model->getDataColumns(), - "editable" => "sales", + "editable" => "sales", "summary_data" => $summary_data, "details_data" => $details_data, - "header_width" => intval(100 / count($headers['summary'])), + "header_width" => intval(100 / count($headers['summary'])), "overall_summary_data" => $model->getSummaryData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)), "export_excel" => $export_excel ); $this->load->view("reports/tabular_details",$data); } - + function detailed_receivings($start_date, $end_date, $receiving_type, $export_excel=0) { $this->load->model('reports/Detailed_receivings'); $model = $this->Detailed_receivings; - + $headers = $model->getDataColumns(); $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'receiving_type'=>$receiving_type)); - + $summary_data = array(); $details_data = array(); - + + $show_locations = $this->Stock_locations->multiple_locations(); + foreach($report_data['summary'] as $key=>$row) { $summary_data[] = array(anchor('receivings/edit/'.$row['receiving_id'].'/width:'.FORM_WIDTH, 'RECV '.$row['receiving_id'], array('class' => 'thickbox')), $row['receiving_date'], $row['items_purchased'], $row['employee_name'], $row['supplier_name'], to_currency($row['total']), $row['payment_type'], $row['invoice_number'], $row['comment']); - + foreach($report_data['details'][$key] as $drow) { $quantity_purchased = $drow['receiving_quantity'] > 1 ? $drow['quantity_purchased'] . ' x ' . $drow['receiving_quantity'] : $drow['quantity_purchased']; + if ($show_locations) + { + $quantity_purchased .= ' [' . $this->Stock_locations->get_location_name($drow['item_location']) . ']'; + } $details_data[$key][] = array($drow['item_number'], $drow['name'], $drow['category'], $quantity_purchased, to_currency($drow['total']), $drow['discount_percent'].'%'); } } @@ -916,28 +929,28 @@ class Reports extends Secure_area $this->load->view("reports/tabular_details",$data); } - + function detailed_requisition($start_date, $end_date , $export_excel=0) { $this->load->model('reports/Detailed_requisition'); $model = $this->Detailed_requisition; $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date)); - + $summary_data = array(); $details_data = array(); - + foreach($report_data['summary'] as $key=>$row) { $summary_data[] = array(anchor('receivings/requisition_receipt/'.$row['requisition_id'], 'REQS '.$row['requisition_id'], array('target' => '_blank')), $row['requisition_date'], $row['employee_name'], $row['comment']); - + foreach($report_data['details'][$key] as $drow) { - $details_data[$key][] = array($drow['name'], $drow['requisition_quantity'], + $details_data[$key][] = array($drow['name'], $drow['requisition_quantity'], $drow['related_item_id'], $drow['related_item_quantity'], $drow['related_item_total_quantity']); } } - + $data = array( "title" =>$this->lang->line('reports_detailed_requisition_report'), "subtitle" => date('m/d/Y', strtotime($start_date)) .'-'.date('m/d/Y', strtotime($end_date)), @@ -949,12 +962,12 @@ class Reports extends Secure_area ); $this->load->view("reports/tabular_details",$data); } - + function excel_export() { - $this->load->view("reports/excel_export",array()); + $this->load->view("reports/excel_export",array()); } - + function inventory_low($export_excel=0) { $this->load->model('reports/Inventory_low'); @@ -975,9 +988,9 @@ class Reports extends Secure_area "export_excel" => $export_excel ); - $this->load->view("reports/tabular",$data); + $this->load->view("reports/tabular",$data); } - + function inventory_summary($export_excel=0) { $this->load->model('reports/Inventory_summary'); @@ -998,8 +1011,8 @@ class Reports extends Secure_area "export_excel" => $export_excel ); - $this->load->view("reports/tabular",$data); + $this->load->view("reports/tabular",$data); } - + } ?> \ No newline at end of file diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 37520de05..7274652ae 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -99,12 +99,12 @@ class Sales extends Secure_area function change_mode() { $stock_location = $this->input->post("stock_location"); - if (!$stock_location || $stock_location == $this->sale_lib->get_sale_location()) + if (!$stock_location || $stock_location == $this->sale_lib->get_sale_location()) { $mode = $this->input->post("mode"); $this->sale_lib->set_mode($mode); } - else + else if ($this->Stock_locations->is_allowed_location($stock_location, 'sales')) { $this->sale_lib->set_sale_location($stock_location); } @@ -234,6 +234,7 @@ class Sales extends Secure_area $this->form_validation->set_rules('price', 'lang:items_price', 'required|numeric'); $this->form_validation->set_rules('quantity', 'lang:items_quantity', 'required|numeric'); + $this->form_validation->set_rules('discount', 'lang:items_discount', 'required|numeric'); $description = $this->input->post("description"); $serialnumber = $this->input->post("serialnumber"); @@ -287,8 +288,7 @@ class Sales extends Secure_area $data['receipt_title']=$this->lang->line('sales_receipt'); $data['transaction_time']= date('m/d/Y h:i:s a'); $data['transaction_date']= date('d/m/Y', strtotime($data['transaction_time'])); - $stock_locations=$this->Stock_locations->get_undeleted_all('sales')->result_array(); - $data['show_stock_locations']=count($stock_locations) > 1; + $data['show_stock_locations']=$this->Stock_locations->show_locations('sales'); $customer_id=$this->sale_lib->get_customer(); $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; $comment=$this->sale_lib->get_comment(); @@ -500,8 +500,7 @@ class Sales extends Secure_area $data['discount']=$this->sale_lib->get_discount(); $data['receipt_title']=$this->lang->line('sales_receipt'); $data['transaction_time']= date('d/m/Y H:i:s', strtotime($sale_info['sale_time'])); - $stock_locations=$this->Stock_locations->get_undeleted_all('sales')->result_array(); - $data['show_stock_locations']=count($stock_locations) > 1; + $data['show_stock_locations']=$this->Stock_locations->show_locations('sales'); $data['transaction_date']= date('d/m/Y', strtotime($sale_info['sale_time'])); $customer_id=$this->sale_lib->get_customer(); $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; @@ -653,7 +652,7 @@ class Sales extends Secure_area $data['cart']=$this->sale_lib->get_cart(); $data['modes']=array('sale'=>$this->lang->line('sales_sale'),'return'=>$this->lang->line('sales_return')); $data['mode']=$this->sale_lib->get_mode(); - + $data['stock_locations']=$this->Stock_locations->get_allowed_locations('sales'); $data['stock_location']=$this->sale_lib->get_sale_location(); diff --git a/application/models/item.php b/application/models/item.php index f69c14ce7..72b5f661a 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -252,7 +252,10 @@ class Item extends CI_Model $by_name = $this->db->get(); foreach($by_name->result() as $row) { - $suggestions[]=$row->name; + if (!in_array($row->name, $suggestions)) + { + $suggestions[]=$row->name; + } } /** END GARRISON ADDED **/ @@ -276,8 +279,8 @@ class Item extends CI_Model { $suggestions[]=$row->name; } */ -/** END GARRISON ADDED **/ - +/** END GARRISON ADDED **/ + //only return $limit suggestions if(count($suggestions > $limit)) { @@ -319,10 +322,15 @@ class Item extends CI_Model $by_description = $this->db->get(); foreach($by_description->result() as $row) { - $suggestions[]=$row->item_id.'|'.$row->name; + $entry=$row->item_id.'|'.$row->name; + if (!in_array($entry, $suggestions)) + { + $suggestions[]=$entry; + } + } -/** END GARRISON ADDED **/ - /** GARRISON ADDED 4/22/2013 **/ +/** END GARRISON ADDED **/ + /** GARRISON ADDED 4/22/2013 **/ //Search by custom fields /* $this->db->from('items'); $this->db->where('deleted',0); @@ -343,7 +351,7 @@ class Item extends CI_Model $suggestions[]=$row->item_id.'|'.$row->name; } */ /** END GARRISON ADDED **/ - + //only return $limit suggestions if(count($suggestions > $limit)) { diff --git a/application/models/receiving.php b/application/models/receiving.php index 63aacd351..7b7ac409c 100644 --- a/application/models/receiving.php +++ b/application/models/receiving.php @@ -214,7 +214,7 @@ class Receiving extends CI_Model public function create_receivings_items_temp_table() { $this->db->query("CREATE TEMPORARY TABLE ".$this->db->dbprefix('receivings_items_temp')." - (SELECT date(receiving_time) as receiving_date, ".$this->db->dbprefix('receivings_items').".receiving_id, comment, invoice_number, payment_type, employee_id, + (SELECT date(receiving_time) as receiving_date, ".$this->db->dbprefix('receivings_items').".receiving_id, comment, item_location, invoice_number, payment_type, employee_id, ".$this->db->dbprefix('items').".item_id, ".$this->db->dbprefix('receivings').".supplier_id, quantity_purchased, ".$this->db->dbprefix('receivings_items').".receiving_quantity, 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, diff --git a/application/models/reports/detailed_receivings.php b/application/models/reports/detailed_receivings.php index 9eae82478..2179e91af 100644 --- a/application/models/reports/detailed_receivings.php +++ b/application/models/reports/detailed_receivings.php @@ -52,7 +52,7 @@ class Detailed_receivings extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, item_number, category, quantity_purchased, serialnumber,total, discount_percent'); + $this->db->select('name, item_number, category, quantity_purchased, serialnumber,total, discount_percent, item_location'); $this->db->select($this->db->dbprefix('receivings_items_temp').".receiving_quantity"); $this->db->from('receivings_items_temp'); $this->db->join('items', 'receivings_items_temp.item_id = items.item_id'); diff --git a/application/models/reports/detailed_sales.php b/application/models/reports/detailed_sales.php index 34408778a..1a30fe10a 100644 --- a/application/models/reports/detailed_sales.php +++ b/application/models/reports/detailed_sales.php @@ -48,7 +48,7 @@ class Detailed_sales extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, quantity_purchased, 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, 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']); diff --git a/application/models/sale.php b/application/models/sale.php index bca12fb9e..fe0c63d19 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -396,7 +396,7 @@ class Sale extends CI_Model } $this->db->query("CREATE TEMPORARY TABLE ".$this->db->dbprefix('sales_items_temp')." - (SELECT date(sale_time) as sale_date, sale_time, ".$this->db->dbprefix('sales_items').".sale_id, comment,payments.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, item_location, 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, ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*$subtotal,2) as subtotal, ".$this->db->dbprefix('sales_items').".line as line, serialnumber, ".$this->db->dbprefix('sales_items').".description as description, diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php index 6eb5203ca..6962016ca 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_locations.php @@ -28,6 +28,17 @@ class Stock_locations extends CI_Model $this->db->where('deleted',0); return $this->db->get(); } + + function show_locations($module_id='items') + { + $stock_locations = $this->get_allowed_locations($module_id); + return count($stock_locations) > 1; + } + + function multiple_locations() + { + return $this->get_all()->num_rows() > 1; + } function get_allowed_locations($module_id='items') { @@ -39,6 +50,19 @@ class Stock_locations extends CI_Model } return $stock_locations; } + + function is_allowed_location($location_id, $module_id='items') + { + $this->db->from('stock_locations'); + $this->db->join('permissions','permissions.location_id=stock_locations.location_id'); + $this->db->join('grants','grants.permission_id=permissions.permission_id'); + $this->db->where('person_id', $this->session->userdata('person_id')); + $this->db->like('permissions.permission_id', $module_id, 'after'); + $this->db->where('deleted',0); + $this->db->where('stock_locations.location_id', $location_id); + $query = $this->db->get(); + return ($query->num_rows()==1); + } function get_default_location_id() {