示例#1
0
 public function donation_report_download($year = null, $county_id = null, $district_id = null, $facility_code = null)
 {
     //reset the values here
     $year = $year == "NULL" ? date('Y') : $year;
     $county_id = $this->session->userdata('county_id');
     $banner = $this->session->userdata('banner_name');
     $pieces = explode(",", $banner);
     //echo "<pre>";var_dump($pieces[0]);echo "</pre>";exit;
     $district_id = $district_id == "NULL" ? null : $this->session->userdata('district_id');
     $facility_code = $facility_code == "NULL" ? null : $facility_code;
     $redistribute_array = redistribution_data::get_redistribution_data($facility_code, $district_id, $county_id, $year);
     //echo "<pre>";print_r($redistribute_array);echo "</pre>";exit;
     $excel_data = array('doc_creator' => $county_id, 'doc_title' => 'Redistribution Summary ', 'file_name' => 'Redistribution Summary For ' . $pieces[0] . ' by ' . $pieces[1] . ' ' . '(' . $year . ')');
     $row_data = array();
     $column_data = array("Facility From", "Facility To", "Subcounty To", "Commodity Name", "Unit Size", "Batch No", "Expiry Date", "Manufacturer", "Quantity Sent", "Quantity Received", "Date Sent", "Date Received", "Status");
     $excel_data['column_data'] = $column_data;
     foreach ($redistribute_array as $column) {
         array_push($row_data, array($column["source_facility_name"], $column["receiver_facility_name"], $column['receiver_district'] == "" ? $column['source_district'] : $column['receiver_district'], $column["commodity_name"], $column["unit_size"], $column["batch_no"], $column["expiry_date"], $column["manufacturer"], $column["quantity_sent"], $column["quantity_received"], $column["date_sent"], $column["date_received"], $column["status"] == 1 ? 'Delivered' : $column["status"] == 2 ? 'Non HCMP' : 'Pending'));
         $facility['Date Last Ordered'] != 0 ? date('j M, Y', strtotime($facility['Date Last Ordered'])) : "No Data Available";
     }
     $excel_data['row_data'] = $row_data;
     $this->hcmp_functions->create_excel($excel_data);
 }
示例#2
0
 public function get_facility_dashboard_notifications_graph_data()
 {
     //format the graph here
     $facility_code = $this->session->userdata('facility_id');
     $facility_stock_ = facility_stocks::get_facility_stock_amc($facility_code);
     $facility_stock_count = count($facility_stock_);
     $graph_data = array();
     $graph_data = array_merge($graph_data, array("graph_id" => 'container'));
     $graph_data = array_merge($graph_data, array("graph_title" => 'Facility stock level'));
     $graph_data = array_merge($graph_data, array("color" => "['#4b0082','#FFF263', '#6AF9C4']"));
     $graph_data = array_merge($graph_data, array("graph_type" => 'bar'));
     $graph_data = array_merge($graph_data, array("graph_yaxis_title" => 'Total stock level  (values in packs)'));
     $graph_data = array_merge($graph_data, array("graph_categories" => array()));
     $graph_data = array_merge($graph_data, array("series_data" => array("Current Balance" => array(), "AMC" => array())));
     $graph_data['stacking'] = 'normal';
     foreach ($facility_stock_ as $facility_stock_) {
         $graph_data['graph_categories'] = array_merge($graph_data['graph_categories'], array($facility_stock_['commodity_name']));
         $graph_data['series_data']['Current Balance'] = array_merge($graph_data['series_data']['Current Balance'], array((double) $facility_stock_['pack_balance']));
         $graph_data['series_data']['AMC'] = array_merge($graph_data['series_data']['AMC'], array((double) $facility_stock_['amc']));
     }
     //echo "<pre>";print_r($facility_stock_);echo "</pre>";exit;
     //create the graph here
     $faciliy_stock_data = $this->hcmp_functions->create_high_chart_graph($graph_data);
     $loading_icon = base_url('assets/img/no-record-found.png');
     $faciliy_stock_data = $facility_stock_count > 0 ? $faciliy_stock_data : "\$('#container').html('<img src={$loading_icon}>');";
     //compute stocked out items
     $items_stocked_out_in_facility = count(facility_stocks::get_items_that_have_stock_out_in_facility($facility_code));
     //get order information from the db
     $facility_order_count_ = facility_orders::get_facility_order_summary_count($facility_code);
     //echo "<pre>";print_r($facility_order_count_);echo "<pre>";exit;
     $facility_order_count = array();
     foreach ($facility_order_count_ as $facility_order_count_) {
         $facility_order_count[$facility_order_count_['status']] = $facility_order_count_['total'];
     }
     //get potential expiries infor here
     $potential_expiries = Facility_stocks::potential_expiries($facility_code)->count();
     //get actual Expiries infor here
     $actual_expiries = count(Facility_stocks::All_expiries($facility_code));
     //get items they have been donated for
     $facility_donations = redistribution_data::get_all_active($facility_code, "to-me")->count();
     //get items they have been donated and are pending
     $facility_donations_pending = redistribution_data::get_all_active($facility_code)->count();
     //get stocks from v1
     $stocks_from_v1 = 0;
     if ($facility_stock_count == 0 && $facility_donations == 0 && $facility_donations_pending == 0) {
         $stocks_from_v1 = count(facility_stocks::import_stock_from_v1($facility_code));
     }
     return array('facility_stock_count' => $facility_stock_count, 'faciliy_stock_graph' => $faciliy_stock_data, 'items_stocked_out_in_facility' => $items_stocked_out_in_facility, 'facility_order_count' => $facility_order_count, 'potential_expiries' => $potential_expiries, 'actual_expiries' => $actual_expiries, 'facility_donations' => $facility_donations, 'facility_donations_pending' => $facility_donations_pending, 'stocks_from_v1' => $stocks_from_v1);
 }
示例#3
0
 public function confirm_external_issue($editable = null)
 {
     $facility_code = $this->session->userdata('facility_id');
     $data['title'] = "Confirm Redistribution";
     $data['banner_text'] = "Confirm Redistribution";
     $data['redistribution_data'] = redistribution_data::get_all_active($facility_code, $editable);
     $data['editable'] = $editable;
     $data['content_view'] = "facility/facility_issues/facility_redistribute_items_confirmation_v";
     $this->load->view("shared_files/template/template", $data);
 }
示例#4
0
 public function confirm_external_issue_edit($editable = null)
 {
     $facility_code = $this->session->userdata('facility_id');
     $subcounty_id = $this->session->userdata('district_id');
     $data['title'] = "Edit Redistribution";
     $data['banner_text'] = "Edit Redistribution";
     $data['redistribution_data'] = redistribution_data::get_all_active_edit($facility_code, $editable);
     // $data['redistribution_data'] = redistribution_data::get_all_active($facility_code, $editable);
     $districts_data = districts::get_district_name($subcounty_id);
     $district_name = '';
     foreach ($districts_data as $value) {
         $district_name = $value->district;
     }
     $data['district_name'] = $district_name;
     $data['district_id'] = $subcounty_id;
     $data['editable'] = $editable;
     $data['subcounties'] = districts::getAll();
     $data['content_view'] = "facility/facility_issues/facility_redistribute_items_confirmation_edit_v";
     $this->load->view("shared_files/template/template", $data);
 }
示例#5
0
 public function ors_zinc_redistribution_report()
 {
     //Set the current year
     $year = date("Y");
     $county_total = array();
     $excel_data = array();
     $column_data = array();
     $excel_data = array('doc_creator' => "HCMP", 'doc_title' => 'ors zinc redistribution report ', 'file_name' => 'ors zinc redistribution report');
     $row_data = array();
     $column_data = array("Sender Name", "Receiver Name", "Source Facility Code", "Source Facility Name", "Source Sub County", "Receiver Facility Name", "Receiver Facility Code", "Receiver Sub County", "Commodity Name", "Commodity Code", "Unit Size", "Unit Cost(KES)", "Quantity Sent(Units)", "Quantity Sent(Packs)", "Quantity Received(Units)", "Quantity Received(Packs)", "Manufacturer", "Batch Number", "Expiry Date", "Status", "Date Sent", "HCMP Supported Facility", "Date Received");
     $excel_data['column_data'] = $column_data;
     //the commodities variable will hold the values for the three commodities ie ORS and Zinc
     $commodities = array(51, 267, 36, 456);
     foreach ($commodities as $commodities) {
         $commodity_stock_level = array();
         //holds the data for the entire county
         //once it is done executing for one commodity it will reset to zero
         $commodity_total = array();
         //pick the commodity names and details
         //get the redistribution report for the specified commodities
         $commodity_redistribution = redistribution_data::get_redistribution_data_ors_zinc($commodities);
         //Start building the excel file
         foreach ($commodity_redistribution as $commodity_redistribution) {
             //format the names for the receiver and sender accordingly
             $sender = $commodity_redistribution["sender_name_fname"] . " " . $commodity_redistribution["sender_name_lname"];
             $receiver = $commodity_redistribution["receiver_name_fname"] . " " . $commodity_redistribution["receiver_name_lname"];
             //then get the quantity of the commodities in packs
             $total_commodity_units = "";
             $total_commodity_units = Commodities::get_commodity_unit($commodities);
             $total_commodity_units = $total_commodity_units[0]['total_commodity_units'];
             //get the quantity received in packs
             $quantity_sent_packs = $commodity_redistribution["quantity_sent"] / $total_commodity_units;
             $quantity_received_packs = $commodity_redistribution["quantity_received"] / $total_commodity_units;
             //now let us set the the status
             $status = "";
             $status = $commodity_redistribution["status"] != 0 ? "Received" : "Not Received";
             //check if the facility is supported facility
             $active = "";
             $active = Facilities::check_active_facility($commodity_redistribution["receiver_facility_code"]);
             $active = $active[0]["HCMP Supported"];
             //format the date received
             $date_received = "";
             $date_received = $commodity_redistribution["date_received"] != 0 ? $commodity_redistribution["date_received"] : "Not Received";
             //echo "<pre>";print_r($date_received);exit;
             //pick the facility code from the data
             /*$facility_code = $commodity_redistribution["facility_code"];
               //get the last date of issue from the database
               $date_last_issue = Facilities::get_last_redistribution($facility_code);
               //ensure that if the date is null change the message
               $date_of_last_issue = ($date_last_issue[0]['Date Last Redistributed']!=0) ? date('j M, Y', strtotime($date_last_issue[0]['Date Last Redistributed'])) : "No Data Found";
               $days_since_last_issue = ($date_last_issue[0]['Days From Last Redistribution']!=0) ? $date_last_issue[0]['Days From Last Redistribution'] : 0;
               */
             //"Date Sent","HCMP Supported Facility","Date Received");
             //push the result from the array into row data that will be dumped into the excel file
             array_push($row_data, array($sender, $receiver, $commodity_redistribution["source_facility_code"], $commodity_redistribution["source_facility_name"], $commodity_redistribution["source_district"], $commodity_redistribution["receiver_facility_name"], $commodity_redistribution["receiver_facility_code"], $commodity_redistribution["receiver_district"], $commodity_redistribution["commodity_name"], $commodity_redistribution["commodity_code"], $commodity_redistribution["unit_size"], $commodity_redistribution["unit_cost"], $commodity_redistribution["quantity_sent"], $quantity_sent_packs, $commodity_redistribution["quantity_received"], $quantity_received_packs, $commodity_redistribution["manufacturer"], $commodity_redistribution["batch_no"], $commodity_redistribution["expiry_date"], $status, $commodity_redistribution["date_sent"], $active, $date_received));
             //echo "<pre>";print_r($row_data);exit;
         }
     }
     $excel_data['row_data'] = $row_data;
     $excel_data['report_type'] = "download_file";
     $excel_data['file_name'] = "Zinc ORS Redistribution Report";
     $excel_data['excel_title'] = "Redistribution Report for Zinc sulphate Tablets  20mg and ORS sachet (for 500ml) low osmolality (100) & (50) for the year " . date("Y");
     //Start the email section of the report
     //Get the number of facilities using HCMP
     $no_of_facilities = Facilities::get_all_on_HCMP();
     $subject = "Redistribution Report: Zinc sulphate Tablets  20mg and ORS sachet (for 500ml) low osmolality ";
     $message = "<p>Find attached an excel sheet with a Redistribution Report for\nZinc Sulphate 20mg, ORS sachet (for 500ml) low osmolality (100 & 50) and ORS 4 Satchets & Zinc 10 Tablets 20 Mg as at " . date("jS F Y") . "</p>";
     $message .= "<p>Number of facilities using HCMP: " . $no_of_facilities . "</p>";
     $message .= $message_body;
     $message .= "\n<p>You may log onto health-cmp.or.ke for follow up.</p>\n\n<p>----</p>\n\n<p>HCMP</p>\n\n<p>This email was automatically generated. Please do not respond to this email address or it will be ignored.</p>";
     $report_type = "ors_report";
     $this->create_excel($excel_data, $report_type);
     //exit;
     //path for windows
     $handler = "./print_docs/excel/excel_files/" . $excel_data['file_name'] . ".xls";
     //path for Mac
     //$handler = "/Applications/XAMPP/xamppfiles/htdocs/hcmp/print_docs/excel/excel_files/" . $excel_data['file_name'] . ".xls";
     $email_address = "*****@*****.**";
     $bcc = "karsanrichard@gmail.com,kelvinmwas@gmail.com";
     $this->hcmp_functions->send_email($email_address, $message, $subject, $handler, $bcc);
 }
示例#6
0
 public function donation_reports($year = null, $district_id = null, $facility_code = null)
 {
     //reset the values here
     $year = $year == "NULL" ? date('Y') : $year;
     $district_id = $district_id == "NULL" ? null : $district_id;
     $facility_code = $facility_code == "NULL" ? null : $facility_code;
     $county_id = $this->session->userdata('county_id');
     $expiries_array = redistribution_data::get_redistribution_data($facility_code, $district_id, $county_id, $year);
     $graph_data = $series_data = array();
     //echo "<pre>";print_r($expiries_array);echo "</pre>";
     foreach ($expiries_array as $facility_expiry_data) {
         $total_units = $facility_expiry_data['total_commodity_units'];
         $sent_units = $facility_expiry_data['quantity_sent'];
         $received_units = $facility_expiry_data['quantity_received'];
         $total_sent = round($sent_units / $total_units, 1);
         $total_received = round($received_units / $total_units, 1);
         ///date_sent
         $date_received = strtotime($facility_expiry_data['date_received']) ? date('d M, Y', strtotime($facility_expiry_data['date_received'])) : "N/A";
         $status = $facility_expiry_data['status'] == 0 ? "<span class='label label-danger'>Pending</span>" : ($facility_expiry_data['status'] == 1 ? "<span class='label label-success'>Received</span>" : null);
         array_push($series_data, array($facility_expiry_data['source_facility_name'] . " :" . $facility_expiry_data['source_facility_code'], $facility_expiry_data['receiver_facility_name'] . " :" . $facility_expiry_data['receiver_facility_code'], $facility_expiry_data['commodity_name'], $facility_expiry_data['commodity_code'], $facility_expiry_data['unit_size'], $facility_expiry_data['batch_no'], date('d M, Y', strtotime($facility_expiry_data['expiry_date'])), $facility_expiry_data['manufacturer'], $total_sent, $sent_units, $total_received, $received_units, date('d M, Y', strtotime($facility_expiry_data['date_sent'])), $date_received, $status));
     }
     $total_expiry = number_format($total_expiry, 2, '.', ',');
     // array_push($series_data, array("","","Total for the next $year months",$total_expiry,''));
     $category_data = array(array("From", 'To', "Commodity Name", "Commodity Code", "Unit Size", 'Batch No', 'Expiry Date', 'Manufacturer', 'Quantity Sent(units)', 'Quantity Sent(packs)', 'Quantity Received (units)', 'Quantity Received (packs)', 'Date sent', 'Date Received', 'status'));
     $graph_data = array_merge($graph_data, array("table_id" => 'dem_graph_1'));
     $graph_data = array_merge($graph_data, array("table_header" => $category_data));
     $graph_data = array_merge($graph_data, array("table_body" => $series_data));
     $data['table'] = $this->hcmp_functions->create_data_table($graph_data);
     $data['table_id'] = "dem_graph_1";
     return $this->load->view("shared_files/report_templates/data_table_template_v", $data);
 }