예제 #1
0
파일: sms.php 프로젝트: HCMPKenya/RTK_TEST
 public function weekly_potential_expiries_report()
 {
     //Set the current year
     $year = date("Y");
     $picurl = base_url() . 'assets/img/coat_of_arms-resized1.png';
     //get the facilities in the district
     $counties = Facilities::get_counties_all_using_HCMP();
     foreach ($counties as $counties) {
         //holds the dat for the entire county
         //once it is done executing for one county it is reset to zero
         $county_total = array();
         //pick the county nae and county ID accordingly
         $county_id = $counties['county'];
         $county_name = $counties['county_name'];
         //Get all the ddistricts in that  particular county
         $districts = Facilities::get_all_using_HCMP($county_id);
         //holds the data for all the districts in a particular county
         $district_total = array();
         foreach ($districts as $districts) {
             $district_id = $districts['district'];
             $district_name = $districts['name'];
             //get all facilities in that district
             $facilities = Facilities::getFacilities_for_email($district_id);
             //holds all the data for all facilities in a particular district
             $facility_total = array();
             foreach ($facilities as $facilities_) {
                 //holds the total value of expiries for that particular facility in that district
                 $facility_potential_expiries_total = 0;
                 //$facility_potential_expiries = array();
                 $facility_code = $facilities_->facility_code;
                 $facility_name = Facilities::get_facility_name2($facility_code);
                 $facility_name = $facility_name['facility_name'];
                 //get potential expiries in that particular facility
                 $facility_potential_expiries = Facility_stocks::potential_expiries_email($district_id, $facility_code);
                 //push the result into another array that will be used by the distrct
                 array_key_exists($facility_name, $facility_total) ? $facility_total[$facility_name] = array_merge($facility_total[$facility_name], array($facility_potential_expiries)) : ($facility_total = array_merge($facility_total, array($facility_name => array($facility_potential_expiries))));
                 //Start buliding the excel file
                 $excel_data = array();
                 $excel_data = array('doc_creator' => $facility_name, 'doc_title' => 'facility potential expiries weekly report ', 'file_name' => 'facility weekly report');
                 $row_data = array();
                 $column_data = array("County", "Subcounty", "Facility Code", "Facility Name", "Commodity Name", "Manufacturer", "Expiry Date", "Unit Cost", "Unit Size", "Units", "Packs", "Total KSH");
                 $excel_data['column_data'] = $column_data;
                 foreach ($facility_potential_expiries as $facility_potential_expiries) {
                     array_push($row_data, array($facility_potential_expiries["county"], $facility_potential_expiries["subcounty"], $facility_potential_expiries["facility_code"], $facility_potential_expiries["facility_name"], $facility_potential_expiries["commodity_name"], $facility_potential_expiries["manufacture"], $facility_potential_expiries["expiry_date"], $facility_potential_expiries["unit_cost"], $facility_potential_expiries["unit_size"], $facility_potential_expiries["units"], $facility_potential_expiries["packs"], $facility_potential_expiries["total_ksh"]));
                     $facility_potential_expiries_total += $facility_potential_expiries["total_ksh"];
                 }
                 if (empty($row_data)) {
                     //do nothing
                 } else {
                     $excel_data['row_data'] = $row_data;
                     $excel_data['report_type'] = "download_file";
                     $excel_data['file_name'] = $facility_name . "_Potential_Expiries_Report";
                     $subject = "Potential Expiries: " . $facility_name . " (Next 3 Months)";
                     $message = $facility_name . "'s Weekly Potential Expiries Report.";
                     $message .= " Find attached an excel sheet with the breakdown for the Potential Expiries for " . $facility_name;
                     $this->hcmp_functions->create_excel($excel_data);
                     $handler = "./print_docs/excel/excel_files/" . $excel_data['file_name'] . ".xls";
                     //$email_address = $this->get_facility_email($facility_code);
                     $email_address = "*****@*****.**";
                     $this->hcmp_functions->send_email($email_address, $message, $subject, $handler);
                 }
                 //End foreach for facility
             }
             array_key_exists($district_name, $district_total) ? $district_total[$district_name] = array_merge($district_total[$district_name], array($facility_total)) : ($district_total = array_merge($district_total, array($district_name => array($facility_total))));
             //Building the excel sheet to be sent to the district admin
             $excel_data = array();
             $excel_data = array('doc_creator' => $district_name, 'doc_title' => 'district potential expiries weekly report ', 'file_name' => 'district weekly report');
             $row_data = array();
             $column_data = array("County", "Subcounty", "Facility Code", "Facility Name", "Commodity Name", "Manufacturer", "Expiry Date", "Unit Cost", "Unit Size", "Units", "Packs", "Total KSH");
             $excel_data['column_data'] = $column_data;
             foreach ($facility_total as $facility_total_1) {
                 foreach ($facility_total_1 as $facility_total_2) {
                     foreach ($facility_total_2 as $facility_total1) {
                         array_push($row_data, array($facility_total1["county"], $facility_total1["subcounty"], $facility_total1["facility_code"], $facility_total1["facility_name"], $facility_total1["commodity_name"], $facility_total1["manufacture"], $facility_total1["expiry_date"], $facility_total1["unit_cost"], $facility_total1["unit_size"], $facility_total1["units"], $facility_total1["packs"], $facility_total1["total_ksh"]));
                         //$facility_potential_expiries_total += $facility_potential_expiries["total_ksh"];
                     }
                 }
             }
             if (empty($row_data)) {
                 //do nothing
             } else {
                 $excel_data['row_data'] = $row_data;
                 $excel_data['report_type'] = "download_file";
                 $excel_data['file_name'] = $district_name . "_Weekly_District_Potential_Expiries_Report";
                 $this->hcmp_functions->create_excel($excel_data);
                 $handler = "./print_docs/excel/excel_files/" . $excel_data['file_name'] . ".xls";
                 $subject = "Potential Expiries: " . $district_name . " Sub County (Next 3 Months)";
                 $message = $district_name . "'s Weekly Potential Expiries Report. ";
                 $message .= " Find attached an excel sheet with the breakdown for the Potential Expiries for " . $district_name . " Sub County";
                 //$email_address = "*****@*****.**";
                 $email_address = $this->get_ddp_email($district_id);
                 $this->hcmp_functions->send_email($email_address, $message, $subject, $handler);
             }
         }
         //Building the excel sheet to be sent to the district admin
         $excel_data = array();
         $excel_data = array('doc_creator' => $district_name, 'doc_title' => 'district potential expiries weekly report ', 'file_name' => 'district weekly report');
         $row_data = array();
         $column_data = array("County", "Subcounty", "Facility Code", "Facility Name", "Commodity Name", "Manufacturer", "Expiry Date", "Unit Cost", "Unit Size", "Units", "Packs", "Total KSH");
         $excel_data['column_data'] = $column_data;
         foreach ($district_total as $facility_total_1) {
             foreach ($facility_total_1 as $facility_total_2) {
                 foreach ($facility_total_2 as $facility_total_3) {
                     foreach ($facility_total_3 as $facility_total_4) {
                         foreach ($facility_total_4 as $facility_total1) {
                             array_push($row_data, array($facility_total1["county"], $facility_total1["subcounty"], $facility_total1["facility_code"], $facility_total1["facility_name"], $facility_total1["commodity_name"], $facility_total1["manufacture"], $facility_total1["expiry_date"], $facility_total1["unit_cost"], $facility_total1["unit_size"], $facility_total1["units"], $facility_total1["packs"], $facility_total1["total_ksh"]));
                         }
                     }
                 }
             }
         }
         if (empty($row_data)) {
             //do nothing
         } else {
             $excel_data['row_data'] = $row_data;
             $excel_data['report_type'] = "download_file";
             $excel_data['file_name'] = $county_name . "_Weekly_County_Potential_Expiries_Report";
             $this->hcmp_functions->create_excel($excel_data);
             $handler = "./print_docs/excel/excel_files/" . $excel_data['file_name'] . ".xls";
             $subject = "Potential Expiries: " . $county_name . " County (Next 3 Months)";
             $message = $county_name . "'s Weekly Potential Expiries Report.";
             $message .= " Find attached an excel sheet with the breakdown for the Potential Expiries for " . $county_name . " County";
             //$email_address = "collinsojenge@gmail.com,smutheu@clintonfoundation.org,kelvinmwas@gmail.com,smutheu@gmail.com";
             $email_address = $this->get_county_email($county_id);
             $bcc = $this->get_bcc_notifications();
             //$cc_email = "";
             $this->hcmp_functions->send_email($email_address, $message, $subject, $handler, $bcc, $cc_email);
         }
     }
 }
예제 #2
0
파일: sms.php 프로젝트: HCMPKenya/hcmp_demo
 public function weekly_potential_expiries_report()
 {
     //Set the current year
     $year = date("Y");
     $picurl = base_url() . 'assets/img/coat_of_arms-resized1.png';
     //get the facilities in the district
     //$counties = Facilities::get_Taita();
     $counties = Facilities::get_counties_all_using_HCMP();
     foreach ($counties as $counties) {
         //holds the data for the entire county
         //once it is done executing for one county it is reset to zero
         $county_total = array();
         //pick the county name and county ID accordingly
         $county_id = $counties['county'];
         $county_name = $counties['county_name'];
         //Get all the districts in that  particular county
         $districts = Facilities::get_all_using_HCMP($county_id);
         //holds the data for all the districts in a particular county
         //echo "<pre>";print_r($districts);exit;
         $district_total = array();
         foreach ($districts as $districts) {
             $district_id = $districts['district'];
             $district_name = $districts['name'];
             //get all facilities in that district
             $facilities = Facilities::getFacilities_for_email($district_id);
             //holds all the data for all facilities in a particular district
             $facility_total = array();
             foreach ($facilities as $facilities_) {
                 //holds the total value of expiries for that particular facility in that district
                 $facility_potential_expiries_total = 0;
                 //$facility_potential_expiries = array();
                 $facility_code = $facilities_->facility_code;
                 $facility_name = Facilities::get_facility_name2($facility_code);
                 $facility_name = $facility_name['facility_name'];
                 //get potential expiries in that particular facility
                 $facility_potential_expiries = Facility_stocks::potential_expiries_email($facility_code);
                 //echo "<pre>";print_r($facility_potential_expiries);exit;
                 //push the result into another array that will be used by the distrct
                 array_key_exists($facility_name, $facility_total) ? $facility_total[$facility_name] = array_merge($facility_total[$facility_name], array($facility_potential_expiries)) : ($facility_total = array_merge($facility_total, array($facility_name => array($facility_potential_expiries))));
                 //Start buliding the excel file
                 $excel_data = array();
                 $excel_data = array('doc_creator' => $facility_name, 'doc_title' => 'facility potential expiries weekly report ', 'file_name' => 'facility weekly report');
                 $row_data = array();
                 $column_data = array("Commodity Name", "Unit Size", "Quantity (units)", "Quantity (packs)", "Unit Cost(KSH)", "Total Cost(KSH)", "Date of Expiry", "Supplier", "Date Added", "Manufacturer", "Facility Name", "MFL Code", "Sub County", "County");
                 $excel_data['column_data'] = $column_data;
                 foreach ($facility_potential_expiries as $facility_potential_expiries) {
                     array_push($row_data, array($facility_potential_expiries["commodity_name"], $facility_potential_expiries["unit_size"], $facility_potential_expiries["units"], $facility_potential_expiries["packs"], $facility_potential_expiries["unit_cost"], $facility_potential_expiries["total_ksh"], $facility_potential_expiries["expiry_date"], $facility_potential_expiries["source_name"], $facility_potential_expiries["date_added"], $facility_potential_expiries["manufacture"], $facility_potential_expiries["facility_name"], $facility_potential_expiries["facility_code"], $facility_potential_expiries["subcounty"], $facility_potential_expiries["county"]));
                     $facility_potential_expiries_total += $facility_potential_expiries["total_ksh"];
                 }
                 if (empty($row_data)) {
                     //do nothing
                 } else {
                     $excel_data['row_data'] = $row_data;
                     $excel_data['report_type'] = "download_file";
                     $excel_data['file_name'] = $facility_name . "_Potential_Expiries_Report";
                     $excel_data['excel_title'] = "Potential Expiries Report for " . $facility_name . " as at " . date("jS F Y");
                     $subject = "Potential Expiries: " . $facility_name . " (Next 3 Months)";
                     $message = "Dear " . $facility_name . ",\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>Find attached an excel sheet with the " . $facility_name . " breakdown of the Potential Expiries.\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\tKindly sensitize the need to re-distribute these short expiry commodities.</p>\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>You may log onto health-cmp.or.ke for follow up.</p>\n\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>----</p>\n\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>HCMP</p>\n\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>This email was automatically generated. Please do not respond to this email address or it will be ignored.</p>";
                     $report_type = "potential_expiries";
                     $this->create_excel($excel_data, $report_type);
                     $handler = "./print_docs/excel/excel_files/" . $excel_data['file_name'] . ".xls";
                     $email_address = $this->get_facility_email($facility_code);
                     $this->hcmp_functions->send_email($email_address, $message, $subject, $handler);
                 }
                 //End foreach for facility
             }
             array_key_exists($district_name, $district_total) ? $district_total[$district_name] = array_merge($district_total[$district_name], array($facility_total)) : ($district_total = array_merge($district_total, array($district_name => array($facility_total))));
             //Building the excel sheet to be sent to the district admin
             $excel_data = array();
             $excel_data = array('doc_creator' => $district_name, 'doc_title' => 'district potential expiries weekly report ', 'file_name' => 'district weekly report');
             $row_data = array();
             $column_data = array("Commodity Name", "Unit Size", "Quantity (units)", "Quantity (packs)", "Unit Cost(KSH)", "Total Cost(KSH)", "Date of Expiry", "Supplier", "Date Added", "Manufacturer", "Facility Name", "MFL Code", "Sub County", "County");
             $excel_data['column_data'] = $column_data;
             foreach ($facility_total as $facility_total_1) {
                 foreach ($facility_total_1 as $facility_total_2) {
                     foreach ($facility_total_2 as $facility_total1) {
                         array_push($row_data, array($facility_total1["commodity_name"], $facility_total1["unit_size"], $facility_total1["units"], $facility_total1["packs"], $facility_total1["unit_cost"], $facility_total1["total_ksh"], $facility_total1["expiry_date"], $facility_total1["source_name"], $facility_total1["date_added"], $facility_total1["manufacture"], $facility_total1["facility_name"], $facility_total1["facility_code"], $facility_total1["subcounty"], $facility_total1["county"]));
                     }
                 }
             }
             if (empty($row_data)) {
                 //do nothing
             } else {
                 $excel_data['row_data'] = $row_data;
                 $excel_data['report_type'] = "download_file";
                 $excel_data['file_name'] = $district_name . "_Weekly_Sub_County_Potential_Expiries_Report";
                 $excel_data['excel_title'] = "Potential Expiries Report for " . $district_name . " Sub County as at " . date("jS F Y");
                 //Create the excel file here
                 $report_type = "potential_expiries";
                 $this->create_excel($excel_data, $report_type);
                 $handler = "./print_docs/excel/excel_files/" . $excel_data['file_name'] . ".xls";
                 $subject = "Potential Expiries: " . $district_name . " Sub County (Next 3 Months)";
                 $message = "<p>Dear " . $district_name . " Sub County,</p>\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>Find attached an excel sheet with the " . $district_name . " Sub County's breakdown of Potential Expiries.\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tKindly sensitize the need to re-distribute these short expiry commodities.</p>\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>You may log onto health-cmp.or.ke for follow up.</p>\n\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>----</p>\n\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>HCMP</p>\n\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>This email was automatically generated. Please do not respond to this email address or it will be ignored.</p>";
                 $email_address = $this->get_ddp_email($district_id);
                 $this->hcmp_functions->send_email($email_address, $message, $subject, $handler);
             }
         }
         //Building the excel sheet to be sent to the district admin
         $excel_data = array();
         $excel_data = array('doc_creator' => $district_name, 'doc_title' => 'district potential expiries weekly report ', 'file_name' => 'district weekly report');
         $row_data = array();
         $column_data = array("Commodity Name", "Unit Size", "Quantity (units)", "Quantity (packs)", "Unit Cost(KSH)", "Total Cost(KSH)", "Date of Expiry", "Supplier", "Date Added", "Manufacturer", "Facility Name", "MFL Code", "Sub County", "County");
         $excel_data['column_data'] = $column_data;
         foreach ($district_total as $facility_total_1) {
             foreach ($facility_total_1 as $facility_total_2) {
                 foreach ($facility_total_2 as $facility_total_3) {
                     foreach ($facility_total_3 as $facility_total_4) {
                         foreach ($facility_total_4 as $facility_total1) {
                             array_push($row_data, array($facility_total1["commodity_name"], $facility_total1["unit_size"], $facility_total1["units"], $facility_total1["packs"], $facility_total1["unit_cost"], $facility_total1["total_ksh"], $facility_total1["expiry_date"], $facility_total1["source_name"], $facility_total1["date_added"], $facility_total1["manufacture"], $facility_total1["facility_name"], $facility_total1["facility_code"], $facility_total1["subcounty"], $facility_total1["county"]));
                         }
                     }
                 }
             }
         }
         if (empty($row_data)) {
             //do nothing
         } else {
             $excel_data['row_data'] = $row_data;
             $excel_data['report_type'] = "download_file";
             $excel_data['file_name'] = $county_name . "_Weekly_County_Potential_Expiries_Report";
             $excel_data['excel_title'] = "Potential Expiries Report for " . $county_name . " County as at " . date("jS F Y");
             //create the excel file
             $report_type = "potential_expiries";
             $this->create_excel($excel_data, $report_type);
             $handler = "./print_docs/excel/excel_files/" . $excel_data['file_name'] . ".xls";
             $subject = "Potential Expiries: " . $county_name . " County (Next 3 Months)";
             $message = "<p>Dear " . $county_name . " County,</p>\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>Find attached an excel sheet with the " . $county_name . " County's breakdown of Potential Expiries.\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tKindly sensitize the need to re-distribute these short expiry commodities.</p>\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>You may log onto health-cmp.or.ke for follow up.</p>\n\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>----</p>\n\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>HCMP</p>\n\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>This email was automatically generated. Please do not respond to this email address or it will be ignored.</p>";
             $email_address = $this->get_ddp_email_county($county_id);
             $bcc = $this->get_bcc_notifications();
             $cc = $this->get_county_email($county_id);
             $this->hcmp_functions->send_email($email_address, $message, $subject, $handler, $bcc, $cc);
         }
     }
 }