Exemplo n.º 1
0
 function download_forecast($vaccine = 0, $year = "0", $national = 0, $region = 0, $district = 0)
 {
     $population = 0;
     if ($year == "0") {
         $year = date('Y');
     }
     $title = "";
     if ($national > 0) {
         $title = "Consumption vs. Forecast at Central Vaccine Store";
         $population = regional_populations::getNationalPopulation($year);
     }
     if ($region > 0) {
         $region_object = Regions::getRegion($region);
         $title = "Consumption vs. Forecast at " . $region_object->name;
         $population = Regional_Populations::getRegionalPopulation($region, $year);
     }
     if ($district > 0) {
         $district_object = Districts::getDistrict($district);
         $title = "Consumption vs. Forecast at " . $district_object->name . " District Store";
         $population = District_Populations::getDistrictPopulation($district, $year);
     }
     $population = str_replace(",", "", $population);
     $vaccines = Vaccines::getAll_Minified();
     $date = date("m/d/Y");
     $months_required = array();
     $data_buffer = "\n\t\t\t<style>\n\t\t\ttable.data-table {\n\t\t\ttable-layout: fixed;\n\t\t\twidth: 700px;\n\t\t\tborder-collapse:collapse;\n\t\t\tborder:1px solid black;\n\t\t\t}\n\t\t\ttable.data-table td, th {\n\t\t\twidth: 100px;\n\t\t\tborder: 1px solid black;\n\t\t\t}\n\t\t\t.leftie{\n\t\t\t\ttext-align: left !important;\n\t\t\t}\n\t\t\t.center{\n\t\t\t\ttext-align: center !important;\n\t\t\t}\n\t\t\t.right{\n\t\t\t\ttext-align: right !important;\n\t\t\t}\n\t\t\t</style> \n\t\t\t";
     $data_buffer .= "<table class='data-table'>";
     $data_buffer .= $this->echoTitles();
     //Get the start and end dates for all the quarters
     $quarter_one_start = date("U", mktime(0, 0, 0, 1, 1, $year));
     $quarter_one_end = date("U", mktime(0, 0, 0, 3, 31, $year));
     $quarter_two_start = date("U", mktime(0, 0, 0, 4, 1, $year));
     $quarter_two_end = date("U", mktime(0, 0, 0, 6, 30, $year));
     $quarter_three_start = date("U", mktime(0, 0, 0, 7, 1, $year));
     $quarter_three_end = date("U", mktime(0, 0, 0, 9, 30, $year));
     $quarter_four_start = date("U", mktime(0, 0, 0, 10, 1, $year));
     $quarter_four_end = date("U", mktime(0, 0, 0, 12, 31, $year));
     foreach ($vaccines as $vaccine_object) {
         $months_of_stock = array();
         $now = date('U');
         //Get the consumption for each of the quarters
         //Set the maximum value
         $max_value = 0;
         //Get the consumption for each of the quarters
         if ($national > 0) {
             $quarter_one_consumption = Disbursements::getNationalIssuesTotals($vaccine_object->id, $quarter_one_start, $quarter_one_end);
             $quarter_two_consumption = Disbursements::getNationalIssuesTotals($vaccine_object->id, $quarter_two_start, $quarter_two_end);
             $quarter_three_consumption = Disbursements::getNationalIssuesTotals($vaccine_object->id, $quarter_three_start, $quarter_three_end);
             $quarter_four_consumption = Disbursements::getNationalIssuesTotals($vaccine_object->id, $quarter_four_start, $quarter_four_end);
         }
         if ($region > 0) {
             $quarter_one_consumption = Disbursements::getRegionalIssuesTotals($vaccine_object->id, $quarter_one_start, $quarter_one_end, $region);
             $quarter_two_consumption = Disbursements::getRegionalIssuesTotals($vaccine_object->id, $quarter_two_start, $quarter_two_end, $region);
             $quarter_three_consumption = Disbursements::getRegionalIssuesTotals($vaccine_object->id, $quarter_three_start, $quarter_three_end, $region);
             $quarter_four_consumption = Disbursements::getRegionalIssuesTotals($vaccine_object->id, $quarter_four_start, $quarter_four_end, $region);
         }
         if ($district > 0) {
             $quarter_one_consumption = Disbursements::getDistrictIssuesTotals($district, $vaccine_object->id, $quarter_one_start, $quarter_one_end);
             $quarter_two_consumption = Disbursements::getDistrictIssuesTotals($district, $vaccine_object->id, $quarter_two_start, $quarter_two_end);
             $quarter_three_consumption = Disbursements::getDistrictIssuesTotals($district, $vaccine_object->id, $quarter_three_start, $quarter_three_end);
             $quarter_four_consumption = Disbursements::getDistrictIssuesTotals($district, $vaccine_object->id, $quarter_four_start, $quarter_four_end);
         }
         $monthly_requirement = ceil($vaccine_object->Doses_Required * $population * $vaccine_object->Wastage_Factor / 12);
         $quarterly_consumption = $monthly_requirement * 3;
         $data_buffer .= "<tr><td class='leftie'>" . $vaccine_object->Name . "</td><td class='right'>" . number_format($quarterly_consumption) . "</td><td class='right'>" . number_format($quarter_one_consumption) . "</td><td class='right'>" . number_format($quarterly_consumption - $quarter_one_consumption) . "</td><td class='right'>" . number_format($quarter_two_consumption) . "</td><td class='right'>" . number_format($quarterly_consumption - $quarter_two_consumption) . "</td><td class='right'>" . number_format($quarter_three_consumption) . "</td><td class='right'>" . number_format($quarterly_consumption - $quarter_three_consumption) . "</td><td class='right'>" . number_format($quarter_four_consumption) . "</td><td class='right'>" . number_format($quarterly_consumption - $quarter_four_consumption) . "</td></tr>";
     }
     $data_buffer .= "</table>";
     $this->generatePDF($data_buffer, $year, $title);
     echo $data_buffer;
 }