Ejemplo n.º 1
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);
 }