Esempio n. 1
0
 function create_regional_reports($region)
 {
     $year = date('Y');
     $total_vaccines = Vaccines::getTotalNumber();
     $html = "<table border='2px solid black' class='regionals'>";
     $html .= "<tr ><th rowspan=3>Analytical Areas</th><th style='text-align: center' colspan=" . $total_vaccines . ">Summary Report for Vaccine Status in Kenya</th></tr>";
     $html .= "<tr ><th style='text-align: center' colspan=" . $total_vaccines . ">Depot: " . $region->name . " Reporting Date: " . date("d/m/Y") . "</th></tr>";
     $headers = "Summary Report for Vaccine Status in Kenya\n\t\nDepot: National Store\tReporting Date: " . date("d/m/Y") . "\t\n";
     $data = "Analytical Areas\t";
     $vaccines = Vaccines::getAll();
     $from = date("U", mktime(0, 0, 0, 1, 1, date('Y')));
     //This sets the begining date as the 1st of january of that particular year
     $to = date('U');
     //This sets the end date as the current time when the report is being generated
     //Loop all vaccines and append the vaccine name in the excel sheet content.
     $html .= "<tr>";
     foreach ($vaccines as $vaccine) {
         $html .= "<td  style='background-color:#" . $vaccine->Tray_Color . "'>" . $vaccine->Name . "</td>";
     }
     $html .= "</tr>";
     //New Line!
     //Begin adding data for the areas being analysed!
     $html .= "<tr><td class='title'>Annual Needs Coverage</td>";
     //Loop all vaccines and append the needs coverage for that particular vaccine in that store
     foreach ($vaccines as $vaccine) {
         $population = Regional_Populations::getRegionalPopulation($region->id, $year);
         $yearly_requirement = $population * $vaccine->Doses_Required * $vaccine->Wastage_Factor;
         $vaccine_totals = Disbursements::getRegionalReceiptsTotals($region->id, $vaccine->id, $from, $to);
         $coverage = ceil($vaccine_totals / $yearly_requirement * 100);
         $html .= "<td >" . $coverage . "%</td>";
     }
     $html .= "</tr>";
     //New Line
     $html .= "<tr><td class='title'>Stock Availability (Stock at Hand)</td>";
     //Loop all vaccines and append the stock at hand for that particular vaccine in that store
     foreach ($vaccines as $vaccine) {
         $stock_at_hand = Disbursements::getRegionalPeriodBalance($region->id, $vaccine->id, $to);
         $html .= "<td >" . $stock_at_hand . "</td>";
     }
     $html .= "</tr>";
     //New Line
     $html .= "<tr><td class='title'>Stock at Hand Forecast (In Months)</td>";
     //Loop all vaccines and append the stock at hand forecast for that particular vaccine in that store
     foreach ($vaccines as $vaccine) {
         $population = Regional_Populations::getRegionalPopulation($region->id, $year);
         $population = str_replace(",", "", $population);
         $monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12);
         $stock_at_hand = Disbursements::getRegionalPeriodBalance($region->id, $vaccine->id, $to);
         $forecast = $stock_at_hand / $monthly_requirement;
         $forecast = number_format($forecast, 2, '.', '');
         $html .= "<td>" . $forecast . "</td>";
     }
     $html .= "</tr></table>";
     return $html;
 }