public function getBalances($region_name, $from, $district_or_region)
 {
     $this->load->database();
     $start_date = "";
     $data_buffer = "";
     $end_date = "";
     @$start_date == date('m/d/y', strtotime('-30 days'));
     @($end_date = date('m/d/y'));
     $population = 0;
     $closing_balance = 0;
     $sql_consumption = "";
     $vaccines = Vaccines::getAll_Minified();
     //gets consumption as per every vaccine
     foreach ($vaccines as $vaccine) {
         $population = Regional_Populations::getRegionalPopulation($district_or_region, date('Y'));
         $closing_balance = Disbursements::getRegionalPeriodBalance($district_or_region, $vaccine->id, strtotime($end_date));
         $owner = "R" . $district_or_region;
         $sql_consumption = "select (SELECT date_format(max(str_to_date(Date_Issued,'%m/%d/%Y')),'%d-%b-%Y')  FROM `disbursements` where Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_Region = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\nstr_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_Region = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\nstr_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received";
         $query = $this->db->query($sql_consumption);
         $vaccine_data = $query->row();
         $monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12);
         $space1 = urldecode("++++");
         $space2 = urldecode("++");
         $newline = urldecode("%0A");
         $brace = urldecode('(');
         $brace2 = urldecode(')');
         $messsage = urlencode($data_buffer .= $newline . $vaccine->Name . $space2 . number_format($closing_balance + 0) . $space1 . $brace . number_format($closing_balance / $monthly_requirement, 1) . 'MOS' . $brace2);
     }
     $this->get_phone_number($messsage, $region_name, $district_or_region);
 }
Esempio n. 2
0
 public function dashboard($dashboard = "country_stock_view")
 {
     $year = date('Y');
     $data['title'] = "Home Page::Dashboards";
     $data['content_view'] = "home_view";
     $data['vaccines'] = Vaccines::getAll();
     $data['styles'] = array("jquery-ui.css", "tab.css");
     $data['script_urls'] = array("http://maps.google.com/maps/api/js?sensor=false");
     $data['scripts'] = array("FusionCharts/FusionCharts.js", "markerclusterer/src/markerclusterer.js", "markerclusterer/src/jsapi.js", "jquery-ui.js", "tab.js");
     $data['dashboard'] = $dashboard;
     $from = date('U');
     $national_balances = array();
     $regional_balances = array();
     $regional_stores = Regions::getAllRegions();
     //Get Statistics for each of the vaccines.
     foreach ($data['vaccines'] as $vaccine) {
         $national_balances[$vaccine->id] = array(Disbursements::getNationalPeriodBalance($vaccine->id, $from), Regional_Populations::getNationalPopulation(date('Y')));
         foreach ($regional_stores as $regional_store) {
             $regional_balances[$vaccine->id][$regional_store->id] = array(Disbursements::getRegionalPeriodBalance($regional_store->id, $vaccine->id, $from), Regional_Populations::getRegionalPopulation($regional_store->id, date('Y')));
         }
     }
     $data['national_stocks'] = $national_balances;
     $data['regional_stocks'] = $regional_balances;
     $data['regional_stores'] = $regional_stores;
     $data['link'] = "home";
     $this->load->view('template', $data);
 }
 public function download()
 {
     $this->load->database();
     $valid = $this->validate_form();
     if ($valid) {
         $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.right{\n\t\t\t\ttext-align: right !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</style> \n\t\t\t";
         $start_date = $this->input->post("start_date");
         $end_date = $this->input->post("end_date");
         $data_buffer .= "<table class='data-table'>";
         $data_buffer .= $this->echoTitles();
         $district_or_region = $this->session->userdata('district_province_id');
         $identifier = $this->session->userdata('user_identifier');
         $population = 0;
         $opening_balance = 0;
         $closing_balance = 0;
         $sql_consumption = "";
         $store = "";
         $vaccines = Vaccines::getAll_Minified();
         foreach ($vaccines as $vaccine) {
             if ($identifier == 'provincial_officer') {
                 $region_object = Regions::getRegion($district_or_region);
                 $store = $region_object->name;
                 $population = Regional_Populations::getRegionalPopulation($district_or_region, date('Y'));
                 $opening_balance = Disbursements::getRegionalPeriodBalance($district_or_region, $vaccine->id, strtotime($start_date));
                 $closing_balance = Disbursements::getRegionalPeriodBalance($district_or_region, $vaccine->id, strtotime($end_date));
                 $owner = "R" . $district_or_region;
                 $sql_consumption = "select (SELECT date_format(max(str_to_date(Date_Issued,'%m/%d/%Y')),'%d-%b-%Y')  FROM `disbursements` where Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_Region = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\nstr_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_Region = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\nstr_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received";
             } else {
                 if ($identifier == 'district_officer') {
                     $district_object = Districts::getDistrict($district_or_region);
                     $store = $district_object->name;
                     $population = District_Populations::getDistrictPopulation($district_or_region, date('Y'));
                     $opening_balance = Disbursements::getDistrictPeriodBalance($district_or_region, $vaccine->id, strtotime($start_date));
                     $closing_balance = Disbursements::getDistrictPeriodBalance($district_or_region, $vaccine->id, strtotime($end_date));
                     $owner = "D" . $district_or_region;
                     $sql_consumption = "select (SELECT date_format(max(str_to_date(Date_Issued,'%m/%d/%Y')),'%d-%b-%Y')  FROM `disbursements` where Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_District = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\nstr_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_District = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\nstr_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received";
                 } else {
                     if ($identifier == 'national_officer') {
                         $store = "Central Vaccines Store";
                         $population = Regional_Populations::getNationalPopulation(date('Y'));
                         $opening_balance = Disbursements::getNationalPeriodBalance($vaccine->id, strtotime($start_date));
                         $closing_balance = Disbursements::getNationalPeriodBalance($vaccine->id, strtotime($end_date));
                         $sql_consumption = "select (SELECT date_format(max(str_to_date(Date_Issued,'%m/%d/%Y')),'%d-%b-%Y')  FROM `disbursements` where Owner = 'N0' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_National = '0' and Owner = 'N0' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\nstr_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_National = '0' and Owner = 'N0' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\nstr_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received";
                     }
                 }
             }
             $query = $this->db->query($sql_consumption);
             $vaccine_data = $query->row();
             $monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12);
             $data_buffer .= "<tr><td style='text-align:left;'>" . $vaccine->Name . "</td><td class='right'>" . number_format($opening_balance + 0) . "</td><td  class='right'>" . number_format($vaccine_data->total_received + 0) . "</td><td class='right'>" . number_format($vaccine_data->total_issued + 0) . "</td><td class='right'>" . number_format($closing_balance - ($opening_balance + $vaccine_data->total_received - $vaccine_data->total_issued) + 0) . "</td><td class='right'>" . number_format($closing_balance + 0) . "</td><td class='center'>" . number_format($closing_balance / $monthly_requirement, 1) . "</td><td class='center'>" . $vaccine_data->last_stock_count . "</td></tr>";
         }
         $data_buffer .= "</table>";
         $this->generatePDF($data_buffer, $start_date, $end_date, $store);
     } else {
         $this->view_transactions_interface();
     }
 }
Esempio n. 4
0
 public function download_mos_trend($selected_year = 0, $national = "", $region = "", $district = "")
 {
     $year = date('Y');
     if ($selected_year != "0") {
         $year = $selected_year;
     }
     $counter = 2;
     $vaccine_objects = Vaccines::getAll();
     $population = 0;
     $title = "";
     if ($national > 0) {
         $title = "MOS Balance Trend at Central Vaccine Store";
         $population = Regional_Populations::getNationalPopulation($year);
     }
     if ($region > 0) {
         $region_object = Regions::getRegion($region);
         $title = "MOS Balance Trend at " . $region_object->name;
         $population = Regional_Populations::getRegionalPopulation($region, $year);
     }
     if ($district > 0) {
         $district_object = Districts::getDistrict($district);
         $title = "MOS Balance Trend at " . $district_object->name . " District Store";
         $population = District_Populations::getDistrictPopulation($district, $year);
     }
     $population = str_replace(",", "", $population);
     foreach ($vaccine_objects as $vaccine_object) {
         $monthly_requirement = ceil($vaccine_object->Doses_Required * $population * $vaccine_object->Wastage_Factor / 12);
         for ($month = 1; $month <= 36; $month++) {
             $mos_balance = 0;
             //Get the month
             $month_number = ceil($month / 3);
             //If it is an even number, get values for the 21st, if it's odd, get values for the 7th
             if ($month % 3 == 0) {
                 $month_date = 28;
             } else {
                 if ($month % 3 == 1) {
                     $month_date = 7;
                 } else {
                     if ($month % 3 == 2) {
                         $month_date = 21;
                     }
                 }
             }
             $to = date("U", mktime(0, 0, 0, $month_number, $month_date, $year));
             $stock_balance = 0;
             if ($national > 0) {
                 $stock_balance = Disbursements::getNationalPeriodBalance($vaccine_object->id, $to);
             }
             if ($region > 0) {
                 $stock_balance = Disbursements::getRegionalPeriodBalance($region, $vaccine_object->id, $to);
             }
             if ($district > 0) {
                 $stock_balance = Disbursements::getDistrictPeriodBalance($district, $vaccine_object->id, $to);
             }
             //$stock_balance = 0;
             if ($stock_balance > 0) {
                 $mos_balance = number_format($stock_balance / $monthly_requirement, 2);
             }
             $monthly_opening_stocks[$month][$vaccine_object->id]['stock_balance'] = number_format($stock_balance + 0);
             $monthly_opening_stocks[$month][$vaccine_object->id]['mos_balance'] = $mos_balance;
             $counter += 2;
         }
     }
     $data_buffer = "\n\t\t\t<style>\n\t\t\ttable.data-table {\n\t\t\ttable-layout: fixed;\n\t\t\twidth: 1000px;\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'>";
     $counter = 2;
     $data_buffer .= $this->echoTitles($vaccine_objects);
     for ($month = 1; $month <= 36; $month++) {
         $data_buffer .= "<tr>";
         $month_number = ceil($month / 3);
         //If it is an even number, get values for the 21st, if it's odd, get values for the 7th
         if ($month % 3 == 0) {
             $month_date = 28;
         } else {
             if ($month % 3 == 1) {
                 $month_date = 7;
             } else {
                 if ($month % 3 == 2) {
                     $month_date = 21;
                 }
             }
         }
         $date = date("M-d", mktime(0, 0, 0, $month_number, $month_date, $year));
         $data_buffer .= "<td>" . $date . "</td>";
         foreach ($vaccine_objects as $vaccine_object) {
             $data_buffer .= "<td class='center'>" . $monthly_opening_stocks[$month][$vaccine_object->id]['mos_balance'] . "</td><td class='right'>" . $monthly_opening_stocks[$month][$vaccine_object->id]['stock_balance'] . "</td>";
         }
         $data_buffer .= "</tr>";
         $counter += 2;
     }
     $data_buffer .= "</table>";
     $this->generatePDF($data_buffer, $year, $title);
     //	var_dump($monthly_opening_stocks);
 }
 public function download()
 {
     $this->load->database();
     $valid = $this->validate_form();
     if ($valid) {
         $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";
         $start_date = $this->input->post("start_date");
         $end_date = $this->input->post("end_date");
         $data_buffer .= "<table class='data-table'>";
         $vaccines = Vaccines::getAll_Minified();
         $data_buffer .= $this->echoTitles($vaccines);
         $population = 0;
         $store = "";
         $district_or_region = $this->session->userdata('district_province_id');
         $identifier = $this->session->userdata('user_identifier');
         $sql_issues = "";
         if ($identifier == 'provincial_officer') {
             $region_object = Regions::getRegion($district_or_region);
             $store = $region_object->name;
             $owner = "R" . $district_or_region;
             $sql_issues = "select vaccine_summaries.*,group_concat(vaccine_id,'-',quantity) as vaccine_issues from (SELECT vaccine_id,sum(Quantity) as quantity,issued_to_region,issued_to_district,issued_to_facility FROM `disbursements` where owner = '" . $owner . "' and Issued_By_Region = '" . $district_or_region . "'  and vaccine_id != '' and str_to_date(date_issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y')  group by vaccine_id,issued_to_region,issued_to_district,issued_to_facility) vaccine_summaries group by issued_to_region,issued_to_district,issued_to_facility";
         } else {
             if ($identifier == 'district_officer') {
                 $district_object = Districts::getDistrict($district_or_region);
                 $store = $district_object->name;
                 $owner = "D" . $district_or_region;
                 $sql_issues = "select vaccine_summaries.*,group_concat(vaccine_id,'-',quantity) as vaccine_issues from (SELECT vaccine_id,sum(Quantity) as quantity,issued_to_region,issued_to_district,issued_to_facility FROM `disbursements` where owner = '" . $owner . "' and Issued_By_Region = '" . $district_or_region . "'  and vaccine_id != '' and str_to_date(date_issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y')  group by vaccine_id,issued_to_region,issued_to_district,issued_to_facility) vaccine_summaries group by issued_to_region,issued_to_district,issued_to_facility";
             } else {
                 if ($identifier == 'national_officer') {
                     $store = "Central Vaccines Store";
                     $sql_issues = "select vaccine_summaries.*,group_concat(vaccine_id,'-',quantity) as vaccine_issues from (SELECT vaccine_id,sum(Quantity) as quantity,issued_to_region,issued_to_district,issued_to_facility FROM `disbursements` where owner = 'N0' and Issued_By_National = '0'  and vaccine_id != '' and str_to_date(date_issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y')  group by vaccine_id,issued_to_region,issued_to_district,issued_to_facility) vaccine_summaries group by issued_to_region,issued_to_district,issued_to_facility";
                 }
             }
         }
         $query = $this->db->query($sql_issues);
         $issues_data = $query->result_array();
         foreach ($issues_data as $recipient_data) {
             $population = 0;
             $recipient = "";
             if (isset($recipient_data['issued_to_region'])) {
                 $population = Regional_Populations::getRegionalPopulation($recipient_data['issued_to_region'], date('Y'));
                 $recipient = Regions::getRegionName($recipient_data['issued_to_region']);
             } else {
                 if (isset($recipient_data['issued_to_district'])) {
                     $population = District_Populations::getDistrictPopulation($recipient_data['issued_to_district'], date('Y'));
                     $recipient = Districts::getDistrictName($recipient_data['issued_to_district']);
                 } else {
                     if (isset($recipient_data['issued_to_facility'])) {
                         $recipient = $recipient_data['issued_to_facility'];
                     }
                 }
             }
             $data_buffer .= "<tr><td style='text-align:left;'>" . $recipient . "</td><td class='right'>" . number_format($population + 0) . "</td>";
             //Get the vaccine data
             $vaccine_data = $recipient_data['vaccine_issues'];
             $separated_data = explode(',', $vaccine_data);
             $final_vaccine_data = array();
             foreach ($separated_data as $vaccine_issue) {
                 $further_separation = explode("-", $vaccine_issue);
                 $final_vaccine_data[$further_separation[0]] = $further_separation[1];
             }
             foreach ($vaccines as $vaccine) {
                 $doses = 0;
                 $mos = 0;
                 $population = str_replace(',', '', $population);
                 if (isset($final_vaccine_data[$vaccine->id])) {
                     $doses = $final_vaccine_data[$vaccine->id];
                 }
                 if ($population != 0 && $doses != 0) {
                     $monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12);
                     $mos = number_format($doses / $monthly_requirement, 1);
                 }
                 $data_buffer .= "<td class='right'>" . number_format($doses + 0) . "</td><td class='center'>" . $mos . "</td>";
             }
             $data_buffer .= "</tr>";
         }
         $data_buffer .= "</table>";
         $this->generatePDF($data_buffer, $start_date, $end_date, $store);
     } else {
         $this->view_transactions_interface();
     }
 }
Esempio n. 6
0
	function download($national = "", $region = "", $district = "") {
		$title = "";
		if ($national > 0) {
			$title = "MOS Available at Central Vaccine Store";
		}
		if ($region > 0) {
			$region_object = Regions::getRegion($region);
			$title = "MOS Available at " . $region_object -> name;
		}
		if ($district > 0) {
			$district_object = Districts::getDistrict($district);
			$title = "MOS Available at " . $district_object -> name . " District Store";
		}
		$vaccines = Vaccines::getAll_Minified();
		$date = date("m/d/Y");
		$months_required = array();
		$data_buffer = "
			<style>
			table.data-table {
			table-layout: fixed;
			width: 700px;
			border-collapse:collapse;
			border:1px solid black;
			}
			table.data-table td, th {
			width: 100px;
			border: 1px solid black;
			}
			.leftie{
				text-align: left !important;
			}
			.right{
				text-align: right !important;
			}
			.center{
				text-align: center !important;
			}
			</style> 
			";
		$data_buffer .= "<table class='data-table'>";
		$data_buffer .= $this -> echoTitles();

		foreach ($vaccines as $vaccine_object) {
			$months_of_stock = array();
			$year = date('Y');
			$now = date('U');
			$population = 0;
			$stock_balance = 0;
			if ($national > 0) {
				$population = Regional_Populations::getNationalPopulation($year);
				$stock_balance = Disbursements::getNationalPeriodBalance($vaccine_object -> id, $now);
			}
			if ($region > 0) {
				$population = Regional_Populations::getRegionalPopulation($region, $year);
				$stock_balance = Disbursements::getRegionalPeriodBalance($region, $vaccine_object -> id, $now);
			}
			if ($district > 0) {
				$population = District_Populations::getDistrictPopulation($district, $year);
				$stock_balance = Disbursements::getDistrictPeriodBalance($district, $vaccine_object -> id, $now);
			}
			$population = str_replace(",", "", $population);
			$monthly_requirement = ceil(($vaccine_object -> Doses_Required * $population * $vaccine_object -> Wastage_Factor) / 12);
			$months_till_shipment = 0;
			if ($national > 0) {
				$months_of_stock = array();
				$year = date('Y');
				$now = date('U');
				$expected_delivery = Provisional_Plan::getNextDelivery($vaccine_object -> id);

				if (isset($expected_delivery[0])) {
					$next_shipment = $expected_delivery[0]['next_shipment'];
					$days_till_shipment = $expected_delivery[0]['difference'];
					if (isset($days_till_shipment)) {
						$months_till_shipment = number_format(($days_till_shipment / 30), 1);
					}
				}
			}
			if ($region > 0) {
				$months_till_shipment = 3;
				$next_shipment = "N/A";
			}
			if ($district > 0) {
				$months_till_shipment = 3;
				$next_shipment = "N/A";
			}

			$doses_needed = "N/A";
			if ($stock_balance > 0) {
				$months_left = number_format(($stock_balance / $monthly_requirement), 1);
			}
			if ($months_left > $months_till_shipment) {
				$doses_needed = "None";
			} else {
				$doses_needed = number_format((($months_till_shipment - $months_left) * $monthly_requirement), 2);
			}

			$monthly_requirement = number_format($monthly_requirement + 0);
			$data_buffer .= "<tr><td class='leftie'>" . $vaccine_object -> Name . "</td><td class='right'>" . number_format($stock_balance) . "</td><td class='center'>" . $months_left . "</td><td class='center'>" . $next_shipment . "</td><td class='center'>" . $months_till_shipment . "</td><td class='right'>" . $monthly_requirement . "</td><td class='right'>" . $doses_needed . "</td></tr>";

		}
		$data_buffer .= "</table>";
		$this -> generatePDF($data_buffer, $title);
		//echo $data_buffer;
	}
Esempio n. 7
0
 public function printReport($from, $to)
 {
     @$this->load->database();
     @($user_groups = User_groups::getAllGroups());
     foreach ($user_groups as $user_group) {
         @($identifier = $user_group["Identifier"]);
         @($population = 0);
         @($opening_balance = 0);
         @($closing_balance = 0);
         @($sql_consumption = "");
         @($store = "");
         @($vaccines = Vaccines::getAll_Minified());
         if ($identifier == 'provincial_officer') {
             @($provinces = Provinces::getAllProvinces());
             foreach ($provinces as $province) {
                 @($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.right{\n\t\t\t\ttext-align: right !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</style>\n\t\t\t  ");
                 @($start_date = $from);
                 @($end_date = $to);
                 @($data_buffer .= "<table class='data-table'>");
                 @($data_buffer .= $this->echoTitles());
                 foreach ($vaccines as $vaccine) {
                     @($district_or_region = $province["id"]);
                     @($region_object = Regions::getRegion($district_or_region));
                     @($store = $region_object->name);
                     @($population = Regional_Populations::getRegionalPopulation($district_or_region, date('Y')));
                     @($opening_balance = Disbursements::getRegionalPeriodBalance($district_or_region, $vaccine->id, strtotime($start_date)));
                     @($closing_balance = Disbursements::getRegionalPeriodBalance($district_or_region, $vaccine->id, strtotime($end_date)));
                     @($owner = "R" . $district_or_region);
                     @($sql_consumption = "select (SELECT max(str_to_date(Date_Issued,'%m/%d/%Y'))  FROM `disbursements` where Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_Region = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_Region = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received");
                     @($query = $this->db->query($sql_consumption));
                     @($vaccine_data = $query->row());
                     @($monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12));
                     @($data_buffer .= "<tr><td>" . $vaccine->Name . "</td><td>" . number_format($opening_balance + 0) . "</td><td>" . number_format($vaccine_data->total_received + 0) . "</td><td>" . number_format($vaccine_data->total_issued + 0) . "</td><td>" . number_format($closing_balance - ($opening_balance + $vaccine_data->total_received - $vaccine_data->total_issued) + 0) . "</td><td>" . number_format($closing_balance + 0) . "</td><td>" . number_format($closing_balance / $monthly_requirement, 1) . "</td><td>" . $vaccine_data->last_stock_count . "</td></tr>");
                 }
                 //end of foreach vaccines
                 @($vals = 1);
                 @($data_buffer .= "</table>");
                 @$this->generatePDF($data_buffer, $start_date, $end_date, $store, $district_or_region, $vals, $store);
                 @($data_buffer = "");
             }
         }
         if ($identifier == 'district_officer') {
             @($districts = Districts::getAllDistricts());
             foreach ($districts as $district) {
                 @($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.right{\n\t\t\t\ttext-align: right !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</style>\n\t\t\t  ");
                 @($start_date = $from);
                 @($end_date = $to);
                 @($data_buffer .= "<table class='data-table'>");
                 @($data_buffer .= $this->echoTitles());
                 foreach ($vaccines as $vaccine) {
                     @($district_or_region = $district["id"]);
                     @($district_object = Districts::getDistrict($district_or_region));
                     @($store = $district_object->name);
                     @($population = District_Populations::getDistrictPopulation($district_or_region, date('Y')));
                     @($opening_balance = Disbursements::getDistrictPeriodBalance($district_or_region, $vaccine->id, strtotime($start_date)));
                     @($closing_balance = Disbursements::getDistrictPeriodBalance($district_or_region, $vaccine->id, strtotime($end_date)));
                     @($owner = "D" . $district_or_region);
                     @($sql_consumption = "select (SELECT max(str_to_date(Date_Issued,'%m/%d/%Y'))  FROM `disbursements` where Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_District = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_District = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received");
                     @($query = $this->db->query($sql_consumption));
                     @($vaccine_data = $query->row());
                     @($monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12));
                     @($data_buffer .= "<tr><td>" . $vaccine->Name . "</td><td>" . number_format($opening_balance + 0) . "</td><td>" . number_format($vaccine_data->total_received + 0) . "</td><td>" . number_format($vaccine_data->total_issued + 0) . "</td><td>" . number_format($closing_balance - ($opening_balance + $vaccine_data->total_received - $vaccine_data->total_issued) + 0) . "</td><td>" . number_format($closing_balance + 0) . "</td><td>" . number_format($closing_balance / $monthly_requirement, 1) . "</td><td>" . $vaccine_data->last_stock_count . "</td></tr>");
                 }
                 //end of foreach vaccines
                 @($vals = 2);
                 @($data_buffer .= "</table>");
                 @$this->generatePDF($data_buffer, $start_date, $end_date, $store, $district_or_region, $vals, $store);
                 @($data_buffer = "");
             }
         }
         if ($identifier == 'national_officer') {
             @($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.right{\n\t\t\t\ttext-align: right !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</style>\n\t\t\t  ");
             @($start_date = $from);
             @($end_date = $to);
             @($data_buffer .= "<table class='data-table'>");
             @($data_buffer .= $this->echoTitles());
             @($store = "Central Vaccines Store");
             foreach ($vaccines as $vaccine) {
                 @($population = Regional_Populations::getNationalPopulation(date('Y')));
                 @($opening_balance = Disbursements::getNationalPeriodBalance($vaccine->id, strtotime($start_date)));
                 @($closing_balance = Disbursements::getNationalPeriodBalance($vaccine->id, strtotime($end_date)));
                 @($sql_consumption = "select (SELECT max(str_to_date(Date_Issued,'%m/%d/%Y'))  FROM `disbursements` where Owner = 'N0' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_National = '0' and Owner = 'N0' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_National = '0' and Owner = 'N0' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received");
                 @($query = $this->db->query($sql_consumption));
                 @($vaccine_data = $query->row());
                 @($monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12));
                 @($data_buffer .= "<tr><td>" . $vaccine->Name . "</td><td>" . number_format($opening_balance + 0) . "</td><td>" . number_format($vaccine_data->total_received + 0) . "</td><td>" . number_format($vaccine_data->total_issued + 0) . "</td><td>" . number_format($closing_balance - ($opening_balance + $vaccine_data->total_received - $vaccine_data->total_issued) + 0) . "</td><td>" . number_format($closing_balance + 0) . "</td><td>" . number_format($closing_balance / $monthly_requirement, 1) . "</td><td>" . $vaccine_data->last_stock_count . "</td></tr>");
             }
             //end of foreach vaccines
             @($vals = 3);
             @($data_buffer .= "</table>");
             @($district_or_region = "");
             @$this->generatePDF($data_buffer, $start_date, $end_date, $store, $district_or_region, $vals, $store);
             @($data_buffer = "");
         }
     }
     //end of foreach user_group
 }
	public function drill_down($type, $id) {

		$to = $this -> input -> post('to');
		$from = $this -> input -> post('from');

		if ($to == false) {
			$to = date("U", mktime(0, 0, 0, 1, 1, date("Y") + 1));
		} else if ($to == true) {
			$to = strtotime($to);
		}
		if ($from == false) {
			$from = date("U", mktime(0, 0, 0, 1, 1, date('Y')));
		} else if ($from == true) {
			$from = strtotime($from);
		}

		$data['type'] = $type;
		$data['id'] = $id;
		$data['title'] = "Disbursement Management::Receipts Log For The Period Between " . date('d/m/Y', $from) . " to " . date('d/m/Y', $to);
		$data['content_view'] = "view_receipts_view";
		$data['vaccines'] = Vaccines::getAll_Minified();
		$return_array = array();
		$current_stock = array();
		$population = 0;
		$year = date('Y');
		$balances = array();
		$archive_date = date('U');
		//Type 0 means we are drilling down to a region
		if ($type == 0) {
			$data['recipient'] = Regions::getRegionName($id);
			$data['type'] = 0;
			$data['store_id'] = $id;
			foreach ($data['vaccines'] as $vaccine) {
				$return_array[$vaccine -> id] = Disbursements::getRegionalReceipts($id, $vaccine -> id, $from, $to);
				$current_stock[$vaccine -> id] = Disbursements::getRegionalPeriodBalance($id, $vaccine -> id, $archive_date);
			}
			$population = Regional_Populations::getRegionalPopulation($id, $year);
		}
		//Type 1 means we are drilling down to a district
		else if ($type == 1) {
			$data['recipient'] = Districts::getDistrictName($id);
			$data['type'] = 1;
			$data['store_id'] = $id;
			foreach ($data['vaccines'] as $vaccine) {
				$return_array[$vaccine -> id] = Disbursements::getDistrictReceipts($id, $vaccine -> id, $from, $to);
				//$current_stock[$vaccine->id] = Disbursements::getDistrictStockAtHand($id,$vaccine->id);
				$current_stock[$vaccine -> id] = Disbursements::getDistrictPeriodBalance($id, $vaccine -> id, $archive_date);

			}
			$population = District_Populations::getDistrictPopulation($id, $year);

		}
		//Type 2 means we are drilling down to the whole country
		if ($type == 2) {
			$data['recipient'] = "National Store";
			$data['type'] = 2;
			$data['store_id'] = "0";
			foreach ($data['vaccines'] as $vaccine) {
				$return_array[$vaccine -> id] = Disbursements::getNationalReceived($vaccine -> id, $from, $to);
				$current_stock[$vaccine -> id] = Disbursements::getNationalPeriodBalance($vaccine -> id, $archive_date);
			}
			$population = Regional_Populations::getNationalPopulation($year);
		}

		$data['population'] = $population;
		$data['disbursements'] = $return_array;
		$data['current_stocks'] = $current_stock;
		$this -> base_params_min_graph($data);
	}
Esempio n. 9
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;
 }
Esempio n. 10
0
		<td>National Store</td>
		<td style="color: green"><?php $vaccine_totals +=$disbursement->Quantity; echo number_format($disbursement->Quantity)?></td>
		<td></td>
		<?php }
		else if($disbursement->Issued_By_District != null){
		$population = Regional_Populations::getRegionalPopulation($disbursement->Issued_To_Region,date('Y'));
		$received = true;
		?>
		<td><?php echo $disbursement->District_Issued_By->name?></td>
		<td style="color: green"><?php $vaccine_totals +=$disbursement->Quantity; echo number_format($disbursement->Quantity)?></td>
		<td></td>
		<?php }
		}
		if($disbursement->Issued_By_Region == $this->session->userdata('district_province_id')){
		if($disbursement->Issued_To_Region != null){
			$population = Regional_Populations::getRegionalPopulation($disbursement->Issued_To_Region,date('Y'));
			?>
		<td><a class="link" href="<?php echo site_url("disbursement_management/drill_down/0/".$disbursement->Issued_To_Region);?>"><?php echo $disbursement->Region_Issued_To->name?></a></td>
		<td></td>
		<td style="color: red"><?php $vaccine_totals -=$disbursement->Quantity; echo number_format($disbursement->Quantity)?></td>
		<?php }
		else if( $disbursement->Issued_To_District != null){
			$population = District_Populations::getDistrictPopulation($disbursement->Issued_To_District,date('Y'));
			?>
		<td><a class="link" href="<?php echo site_url("disbursement_management/drill_down/1/".$disbursement->Issued_To_District);?>"><?php echo $disbursement->District_Issued_To->name?></a></td>
		<td></td>
		<td style="color: red"><?php $vaccine_totals -=$disbursement->Quantity; echo number_format($disbursement->Quantity)?></td>
		<?php }
		}
		}
		else if($identifier== "district_officer"){
Esempio n. 11
0
 function create_regional_reports($region)
 {
     $year = date('Y');
     $headers = "Summary Report for Vaccine Status in Kenya\n\t\nDepot: " . $region->name . "\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.
     foreach ($vaccines as $vaccine) {
         $data .= $vaccine->Name . "\t";
     }
     $data .= "\n";
     //New Line!
     //Begin adding data for the areas being analysed!
     $data .= "Annual Needs Coverage\t";
     //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);
         $data .= $coverage . "%\t";
     }
     $data .= "\n";
     //New Line
     $data .= "Stock Availability (Stock at Hand)\t";
     //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);
         $data .= $stock_at_hand . "\t";
     }
     $data .= "\n";
     //New Line
     $data .= "Stock at Hand Forecast (In Months)\t";
     //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;
         $data .= $forecast . "\t";
     }
     $data .= "\n";
     $result = $headers . $data;
     return $result;
 }
Esempio n. 12
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;
 }