public function getBalances($from, $district_or_region, $region_name) #
	{
		$this -> load -> database();
		$start_date = "";
		$number = "";
		@$end_date = date('m/d/y');
		$closing_balance = 0;
		//calls the following function from the vaccines model.
		//the function c=selects data from the vaccines table then stores them in an array
		//the array is stored in the $vaccines variable
		$vaccines = Vaccines::getAll_Minified();

		//gets consumption as per every vaccine
		@$message = "";
		
		foreach ($vaccines as $vaccine) 
		{
			//$district_or_region is the regions id number
			$region_object = Regions::getRegion($district_or_region);
			$name = urlencode($vaccine['Name']);
			$store = urlencode($region_object -> name);
			$closing_balance = Disbursements::getRegionalPeriodBalance($district_or_region, $vaccine -> id, strtotime($end_date));
			$closing_balance_formatted = number_format($closing_balance);

			if ($closing_balance_formatted == 0) 
			{
				//	echo @$message.= "VACCINES+STOCK+OUTS++AT++%0A+*+DVI+-+SMT*";
				$this -> get_phones($name,$district_or_region,$store);

			}

		}

	}
Beispiel #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 plot($vaccine)
 {
     // Initiate class
     $xml = new MY_Xml_writer();
     $xml->setRootName('markers');
     $xml->initiate();
     $year = date('U');
     $mapped_districts = Districts::getMappedDistricts();
     $mapped_regions = Regions::getAllRegions();
     foreach ($mapped_districts as $mapped_district) {
         //$stock = Disbursements::getDistrictStockAtHand($mapped_district->id,$vaccine);
         $stock = Disbursements::getDistrictPeriodBalance($mapped_district->id, $vaccine, $year);
         $xml->startBranch('marker', array('name' => $mapped_district->name . " District Store", 'lat' => $mapped_district->latitude, 'lng' => $mapped_district->longitude, 'facility_id' => $mapped_district->id, 'stock' => $stock));
         // start branch 1-1
         $xml->endBranch();
     }
     foreach ($mapped_regions as $mapped_region) {
         // $stock = Disbursements::getRegionalStockAtHand($mapped_region->id,$vaccine);
         $stock = Disbursements::getRegionalPeriodBalance($mapped_region->id, $vaccine, $year);
         $xml->startBranch('marker', array('name' => $mapped_region->name, 'lat' => $mapped_region->latitude, 'lng' => $mapped_region->longitude, 'facility_id' => $mapped_region->id, 'stock' => $stock));
         // start branch 1-1
         $xml->endBranch();
     }
     //$stock = Disbursements::getNationalStockAtHand($vaccine);
     $stock = Disbursements::getNationalPeriodBalance($vaccine, $year);
     $xml->startBranch('marker', array('name' => "Central Vaccine Store", 'lat' => "-1.304507", 'lng' => "36.806191", 'facility_id' => 0, 'stock' => $stock));
     // start branch 1-1
     $xml->endBranch();
     // Print the XML to screen
     $xml->getXml(true);
 }
 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);
 }
 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();
     }
 }
 public function getBalances($from, $district_or_region, $region_name)
 {
     $this->load->database();
     $start_date = "";
     $number = "";
     @($end_date = date('m/d/y'));
     $closing_balance = 0;
     $vaccines = Vaccines::getAll_Minified();
     //gets consumption as per every vaccine
     @($message = "");
     foreach ($vaccines as $vaccine) {
         $region_object = Regions::getRegion($district_or_region);
         $name = urlencode($vaccine['Name']);
         $store = urlencode($region_object->name);
         $closing_balance = Disbursements::getRegionalPeriodBalance($district_or_region, $vaccine->id, strtotime($end_date));
         $closing_balance_formatted = number_format($closing_balance);
         if ($closing_balance_formatted == 0) {
             //	echo @$message.= "VACCINES+STOCK+OUTS++AT++%0A+*+DVI+-+SMT*";
             $this->get_phones($name, $district_or_region, $store);
         }
     }
 }
	public function export($type, $id, $vaccine) {
		//Retrieve the user identifier
		$from = $this -> session -> userdata('external_from');
		$to = $this -> session -> userdata('external_to');
		if ($to == false) {
			$to = date("U", mktime(0, 0, 0, 1, 1, date("Y") + 1));
		}
		if ($from == false) {
			$from = date("U", mktime(0, 0, 0, 1, 1, date('Y')));
		}

		$offset = 0;
		$items_per_page = 1000;
		$district = $this -> session -> userdata('external_district');
		$region = $this -> session -> userdata('external_region');
		$order_by = $this -> session -> userdata('external_order_by');
		$order = $this -> session -> userdata('external_order');
		$origin_region = $id;
		$origin_district = $id;
		$disbursements = null;

		$data = null;
		if ($type == "national_officer") {//National Level

			if ($order == 2) {
				$balance = Disbursements::getNationalPeriodBalance($vaccine, $from);
			} else if ($order == "DESC") {
				$balance = Disbursements::getNationalPeriodBalance($vaccine, $to);
			}
			$disbursements = Disbursements::getNationalDisbursements($vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balance);
		} else if ($type == 0) {//Regional Level
			if ($order == "ASC") {
				$balance = Disbursements::getRegionalPeriodBalance($origin_region, $vaccine, $from);
			} else if ($order == "DESC") {
				$balance = Disbursements::getRegionalPeriodBalance($origin_region, $vaccine, $to);
			}
			$disbursements = Disbursements::getRegionalDisbursements($origin_region, $vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balance);

		} else if ($type == 1) {//District Level
			if ($order == "ASC") {
				$balance = Disbursements::getDistrictPeriodBalance($origin_district, $vaccine, $from);
			} else if ($order == "DESC") {
				$balance = Disbursements::getDistrictPeriodBalance($origin_district, $vaccine, $to);
			}
			$disbursements = Disbursements::getDistrictDisbursements($origin_district, $vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balance);

		}

		$reducing_balance = $balance;
		$headers = "Balance From Previous Period: " . $balance . "\t\nDate Issued\t Vaccines To/From \t Amount Received\t Amount Issued \tStore Balance\t Voucher Number\t Batch Number\t Vaccine Expiry Date\t Recorded By\t\n";
		foreach ($disbursements as $disbursement) {
			$data .= $disbursement -> Date_Issued . "\t";
			//If the vaccines were issued to a Region, display the name
			if ($disbursement -> Issued_To_Region != null && $disbursement -> Issued_To_Region != $origin_region) {
				$data .= $disbursement -> Region_Issued_To -> name . "\t";
				$data .= " \t" . $disbursement -> Quantity . "\t";
			}
			//If the vaccines were received from a region (apart from ourselves ofcourse) display the name
			if ($disbursement -> Issued_By_Region != null && $disbursement -> Issued_By_Region != $origin_region) {
				$data .= $disbursement -> Region_Issued_By -> name . "\t";
				$data .= $disbursement -> Quantity . "\t\t";
			}

			//If the vaccines were issued to a District other than ourselves, display the name
			if ($disbursement -> Issued_To_District != null && $disbursement -> Issued_To_District != $origin_district) {
				$data .= $disbursement -> District_Issued_To -> name . "\t";
				$data .= " \t" . $disbursement -> Quantity . "\t";
			}
			//If the vaccines were received from a district (apart from ourselves ofcourse) display the name
			if ($disbursement -> Issued_By_District != null && $disbursement -> Issued_By_District != $origin_district) {
				$data .= $disbursement -> District_Issued_By -> name . "\t";
				$data .= $disbursement -> Quantity . "\t\t";
			}

			//If the vaccines were issued the Central store, Display UNICEF as the source
			if ($disbursement -> Issued_To_National == "0") {
				$data .= "UNICEF\t";
				$data .= $disbursement -> Quantity . "\t\t";
			}

			//If the vaccines were issued by Central store and if this is not the national store, Display National Store as the source
			if ($disbursement -> Issued_By_National == "0" && $type != 2) {
				$data .= "Central Vaccine Stores\t";
				$data .= $disbursement -> Quantity . "\t\t";
			}
			$data .= $disbursement -> Total_Stock_Balance . "\t";
			$data .= $disbursement -> Voucher_Number . "\t";
			$data .= $disbursement -> Batch_Number . "\t";
			$data .= $disbursement -> Batch -> Expiry_Date . "\t";
			$data .= $disbursement -> User -> Full_Name . "\t";
			$data .= "\n";
		}

		header("Content-type: application/vnd.ms-excel; name='excel'");
		header("Content-Disposition: filename=stock_ledger_export.xls");
		// Fix for crappy IE bug in download.
		header("Pragma: ");
		header("Cache-Control: ");
		echo $headers . $data;

	}
Beispiel #8
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;
	}
 public function view_report($report = "consumption")
 {
     $data['title'] = "System Reports";
     $data['content_view'] = "reports_view";
     if ($report == "consumption") {
         redirect("consumption_management");
     }
     if ($report == "issues") {
         redirect("vaccine_issues_management");
     }
     if ($report == "district_stock_outs") {
         redirect("district_stock_out");
     }
     //Code for getting the Store summaries at the various vaccine store around the country
     if ($report == "store_summaries") {
         $data['quick_link'] = "store_summaries";
         $regions = Regions::getAllRegions();
         $vaccines = Vaccines::getAll_Minified();
         $national_values = array();
         $regional_values = array();
         $this_month = date('m');
         for ($month = 1; $month <= $this_month; $month++) {
             foreach ($vaccines as $vaccine) {
                 $timestamp = date("U", mktime(0, 0, 0, $month, 1, date("Y")));
                 $national_balance = Disbursements::getNationalPeriodBalance($vaccine->id, $timestamp);
                 $national_values[$month][$vaccine->id] = $national_balance;
                 //Get the balance at that time
                 foreach ($regions as $region) {
                     $regional_balance = Disbursements::getRegionalPeriodBalance($region->id, $vaccine->id, $timestamp);
                     $regional_values[$month][$region->id][$vaccine->id] = $regional_balance;
                     //Get the Balance at that time
                 }
             }
         }
         $data['national_values'] = $national_values;
         $data['regional_values'] = $regional_values;
         $data['regional_stores'] = $regions;
     } else {
         if ($report == "store_tallies") {
             $post = $this->input->post();
             if ($post) {
                 $login_level = $this->session->userdata('user_group');
                 $vaccines = Vaccines::getAll_Minified();
                 $from = strtotime($this->input->post('from'));
                 $to = strtotime($this->input->post('to'));
                 $this->session->set_userdata(array("store_tallies_from" => $from, "store_tallies_to" => $to));
                 $items = 20;
                 $order_by = "Quantity";
                 $order = "DESC";
                 $offset = 0;
                 $district_or_region_id = $this->session->userdata('district_province_id');
                 $tallies = null;
                 if ($login_level == 1) {
                     //National Level
                     foreach ($vaccines as $vaccine) {
                         $tallies[$vaccine->id] = Disbursements::getNationalRecipientTally($vaccine->id, $from, $to, $offset, $items, $order_by, $order);
                     }
                 }
                 if ($login_level == 2) {
                     //Regional Level
                     foreach ($vaccines as $vaccine) {
                         $tallies[$vaccine->id] = Disbursements::getRegionalRecipientTally($district_or_region_id, $vaccine->id, $from, $to, $offset, $items, $order_by, $order);
                     }
                 }
                 $data['tallies'] = $tallies;
             }
             $data['quick_link'] = "store_tallies";
         } else {
             if ($report == "vaccine_movement") {
                 $post = $this->input->post();
                 if ($post) {
                     $login_level = $this->session->userdata('user_group');
                     $vaccines = Vaccines::getAll_Minified();
                     $from = strtotime($this->input->post('from'));
                     $to = strtotime($this->input->post('to'));
                     $items = 20;
                     $order_by = "Quantity";
                     $order = "DESC";
                     $offset = 0;
                     $district_or_region_id = $this->session->userdata('district_province_id');
                     $received = null;
                     $issued = null;
                     $beginning_balance = null;
                     $current_balance = null;
                     if ($login_level == 1) {
                         //National Level
                         foreach ($vaccines as $vaccine) {
                             $received[$vaccine->id] = Disbursements::getNationalReceiptsTotals($vaccine->id, $from, $to);
                             $issued[$vaccine->id] = Disbursements::getNationalIssuesTotals($vaccine->id, $from, $to);
                             $beginning_balance[$vaccine->id] = Disbursements::getNationalPeriodBalance($vaccine->id, $from);
                             $current_balance[$vaccine->id] = Disbursements::getNationalPeriodBalance($vaccine->id, $to);
                         }
                     }
                     if ($login_level == 2) {
                         //Regional Level
                         /*foreach($vaccines as $vaccine){
                         	 $tallies[$vaccine->id] = Disbursements::getRegionalRecipientTally($district_or_region_id,$vaccine->id,$from,$to,$offset,$items,$order_by,$order);
                         	 }*/
                     }
                     $data['received'] = $received;
                     $data['issued'] = $issued;
                     $data['beginning_balance'] = $beginning_balance;
                     $data['current_balance'] = $current_balance;
                 }
                 $data['quick_link'] = "vaccine_movement";
             }
         }
     }
     $data['report'] = $report;
     $this->base_params($data);
 }
Beispiel #10
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
 }
 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;
 }
Beispiel #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;
 }
 public function export($vaccine)
 {
     //Retrieve the user identifier
     $level = $this->session->userdata('user_identifier');
     $from = $this->session->userdata('from');
     $to = $this->session->userdata('to');
     $offset = 0;
     $items_per_page = 100;
     $district = $this->session->userdata('district');
     $region = $this->session->userdata('region');
     $order_by = $this->session->userdata('order_by');
     $order = $this->session->userdata('order');
     $region = $this->session->userdata('district_province_id');
     $disbursements = null;
     $data = null;
     if ($level == "national_officer") {
         //National Level
         $disbursements = Disbursements::getNationalDisbursements($vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order);
         $balance = Disbursements::getNationalPeriodBalance($vaccine, $from);
     } else {
         if ($level == "provincial_officer") {
             //Regional Level
             $disbursements = Disbursements::getRegionalDisbursements($region, $vaccine, $from, $to, $offset, $items_per_page, $district, $region);
             $balance = Disbursements::getRegionalPeriodBalance($region, $vaccine, $from);
         }
     }
     $reducing_balance = $balance;
     $headers = "Balance From Previous Period: " . $balance . "\t\nDate Issued\t Vaccines To/From \t Amount Received\t Amount Issued \t Store Balance\t Voucher Number\t Batch Number\t Vaccine Expiry Date\t Recorded By\t\n";
     foreach ($disbursements as $disbursement) {
         $data .= $disbursement->Date_Issued . "\t";
         //If the vaccines were issued to a Region, display the name
         if ($disbursement->Issued_To_Region != null) {
             $data .= $disbursement->Region_Issued_To->name . "\t";
             $data .= " \t" . $disbursement->Quantity . "\t";
             $reducing_balance -= $disbursement->Quantity;
         }
         //If the vaccines were received from a region (apart from ourselves ofcourse) display the name
         if ($disbursement->Issued_By_Region != null && $disbursement->Issued_By_Region != $region) {
             $data .= $disbursement->Region_Issued_By->name . "\t";
             $data .= $disbursement->Quantity . "\t\t";
             $reducing_balance += $disbursement->Quantity;
         }
         //If the vaccines were issued to a Region, display the name
         if ($disbursement->Issued_To_District != null) {
             $data .= $disbursement->District_Issued_To->name . "\t";
             $data .= " \t" . $disbursement->Quantity . "\t";
             $reducing_balance -= $disbursement->Quantity;
         }
         //If the vaccines were issued the Central store, Display UNICEF as the source
         if ($disbursement->Issued_To_National == "0") {
             $data .= "UNICEF\t";
             $data .= $disbursement->Quantity . "\t\t";
             $reducing_balance += $disbursement->Quantity;
         }
         //If the vaccines were issued by Central store and if this is not the national store, Display National Store as the source
         if ($disbursement->Issued_By_National == "0" && $level != 1) {
             $data .= "Central Vaccine Stores\t";
             $data .= $disbursement->Quantity . "\t\t";
             $reducing_balance += $disbursement->Quantity;
         }
         $data .= $reducing_balance . "\t";
         $data .= $disbursement->Voucher_Number . "\t";
         $data .= $disbursement->Batch_Number . "\t";
         $data .= $disbursement->Batch->Expiry_Date . "\t";
         $data .= $disbursement->User->Full_Name . "\t";
         $data .= "\n";
     }
     header("Content-type: application/vnd.ms-excel; name='excel'");
     header("Content-Disposition: filename=export.xls");
     // Fix for crappy IE bug in download.
     header("Pragma: ");
     header("Cache-Control: ");
     echo $headers . $data;
 }
    public function utilization($type, $year = "")
    {
        $total_occupied_capacity = array();
        if ($year == "") {
            $year = date('Y');
        }
        $year_start = date("U", mktime(0, 0, 0, 1, 1, $year));
        $vaccines = Fridge_Compartments::getCompartmentVaccines($type);
        $counter = 2;
        $user_identifier = $this->session->userdata("user_identifier");
        $district_province_id = $this->session->userdata("user_identifier");
        $fridges = null;
        if ($user_identifier == "regional_officer") {
            //Regional Store
            for ($month = 1; $month <= 24; $month++) {
                //Get the month
                $month_number = $counter / 2;
                //If it is an even number, get values for the 21st, if it's odd, get values for the 7th
                if ($month % 2 == 0) {
                    $month_date = 21;
                } else {
                    $month_date = 7;
                }
                $to = date("U", mktime(0, 0, 0, $month_number, $month_date, $year));
                //Get the stock balances for each of the vaccines at this point in time
                $total_volume = 0;
                foreach ($vaccines as $vaccine) {
                    $volume = $vaccine->Vaccine_Packed_Volume;
                    $stock_balance = Disbursements::getRegionalPeriodBalance($district_province_id, $vaccine->id, $to);
                    $volume_occupied = $volume * $stock_balance;
                    $total_volume += $volume_occupied;
                }
                $total_occupied_capacity[$month] = $total_volume;
                $counter += 2;
            }
            //Get the Fridges of this store
            $fridges = Regional_Fridges::getRegionFridges($district_province_id);
        } else {
            if ($user_identifier == "district_officer") {
                //District Store
                for ($month = 1; $month <= 24; $month++) {
                    //Get the month
                    $month_number = $counter / 2;
                    //If it is an even number, get values for the 21st, if it's odd, get values for the 7th
                    if ($month % 2 == 0) {
                        $month_date = 21;
                    } else {
                        $month_date = 7;
                    }
                    $to = date("U", mktime(0, 0, 0, $month_number, $month_date, $year));
                    //Get the stock balances for each of the vaccines at this point in time
                    $total_volume = 0;
                    foreach ($vaccines as $vaccine) {
                        $volume = $vaccine->Vaccine_Packed_Volume;
                        $stock_balance = Disbursements::getDistrictPeriodBalance($district_province_id, $vaccine->id, $to);
                        $volume_occupied = $volume * $stock_balance;
                        $total_volume += $volume_occupied;
                    }
                    $total_occupied_capacity[$month] = $total_volume;
                    $counter += 2;
                }
                //Get the Fridges of this store
                $fridges = District_Fridges::getDistrictFridges($district_province_id);
            } else {
                if ($user_identifier == "national_officer") {
                    //National Store
                    for ($month = 1; $month <= 24; $month++) {
                        //Get the month
                        $month_number = $counter / 2;
                        //If it is an even number, get values for the 21st, if it's odd, get values for the 7th
                        if ($month % 2 == 0) {
                            $month_date = 21;
                        } else {
                            $month_date = 7;
                        }
                        $to = date("U", mktime(0, 0, 0, $month_number, $month_date, $year));
                        //Get the stock balances for each of the vaccines at this point in time
                        $total_volume = 0;
                        foreach ($vaccines as $vaccine) {
                            $volume = $vaccine->Vaccine_Packed_Volume;
                            $stock_balance = Disbursements::getNationalPeriodBalance($vaccine->id, $to);
                            $volume_occupied = $volume * $stock_balance;
                            $total_volume += $volume_occupied;
                        }
                        $total_occupied_capacity[$month] = $total_volume;
                        $counter += 2;
                    }
                    //Get the Fridges of this store
                    $fridges = National_Fridges::getNationalFridges();
                }
            }
        }
        $net_volume = 0;
        //loop through all the fridges to get the total capacity
        foreach ($fridges as $fridge) {
            if ($type == "freezer") {
                $net_volume += $fridge->Fridge_Equipment->Net_Vol_Minus_20deg;
            } else {
                if ($type == "fridge") {
                    $net_volume += $fridge->Fridge_Equipment->Net_Vol_4deg;
                }
            }
        }
        //convert from m3 to cm3
        $net_volume /= 1000;
        $chart = '
<chart caption="Annual Capacity Utilization" subcaption="For the year ' . $year . '" xAxisName="Month" yAxisName="Volume"  numberSuffix="m3" showValues="0" alternateHGridColor="FCB541" alternateHGridAlpha="20" divLineColor="FCB541" divLineAlpha="50" canvasBorderColor="666666" baseFontColor="666666" lineColor="FCB541">
<categories>
<category label="Jan"/>
<category label=""/>
<category label="Feb"/>
<category label=""/>
<category label="Mar"/>
<category label=""/>
<category label="Apr"/>
<category label=""/>
<category label="May"/>
<category label=""/>
<category label="Jun"/>
<category label=""/>
<category label="Jul"/>
<category label=""/>
<category label="Aug"/>
<category label=""/>
<category label="Sep"/>
<category label=""/>
<category label="Oct"/>
<category label=""/>
<category label="Nov"/>
<category label=""/>
<category label="Dec"/>
<category label=""/>
</categories> 

<dataset seriesName="Capacity Utilized" color="0008FF" anchorBorderColor="0008FF" anchorBgColor="0008FF">
<set  value="' . $total_occupied_capacity[1] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[2] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[3] / 1000000 . '"/>
<set value="' . $total_occupied_capacity[4] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[5] / 1000000 . '"/>
<set value="' . $total_occupied_capacity[6] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[7] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[8] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[9] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[10] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[11] / 1000000 . '"/>
<set value="' . $total_occupied_capacity[12] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[13] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[14] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[15] / 1000000 . '"/>
<set value="' . $total_occupied_capacity[16] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[17] / 1000000 . '"/>
<set value="' . $total_occupied_capacity[18] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[19] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[20] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[21] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[22] / 1000000 . '"/>
<set  value="' . $total_occupied_capacity[23] / 1000000 . '"/>
<set value="' . $total_occupied_capacity[24] / 1000000 . '"/>
</dataset>
<dataset seriesName="Net Volume" color="FF0000" anchorBorderColor="FF0000" anchorBgColor="FF0000">';
        for ($x = 1; $x <= 24; $x++) {
            $chart .= '<set value="' . $net_volume . '"/>';
        }
        $chart .= '</dataset>
<styles>
<definition>
<style name="Anim1" type="animation" param="_xscale" start="0" duration="1"/>
<style name="Anim2" type="animation" param="_alpha" start="0" duration="0.6"/>
<style name="DataShadow" type="Shadow" alpha="40"/>
</definition>
<application>
<apply toObject="DIVLINES" styles="Anim1"/>
<apply toObject="HGRID" styles="Anim2"/>
<apply toObject="DATALABELS" styles="DataShadow,Anim2"/>
</application>
</styles>
</chart>
';
        echo $chart;
    }
Beispiel #15
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);
 }
Beispiel #16
0
    public function get($type, $id, $vaccine, $year = "")
    {
        $monthly_opening_stocks = array();
        if ($year == "") {
            $year = date('Y');
        }
        $year_start = date("U", mktime(0, 0, 0, 1, 1, $year));
        $vaccine_object = Vaccines::getVaccine($vaccine);
        $counter = 2;
        if ($type == 0) {
            //Regional Store
            $population = regional_populations::getRegionalPopulation($id, $year);
            $population = str_replace(",", "", $population);
            $monthly_requirement = ceil($vaccine_object->Doses_Required * $population * $vaccine_object->Wastage_Factor / 12);
            for ($month = 1; $month <= 36; $month++) {
                //Get the month
                $month_number = $counter / 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 = 7;
                } else {
                    if ($month % 3 == 1) {
                        $month_date = 21;
                    } else {
                        if ($month % 3 == 2) {
                            $month_date = 28;
                        }
                    }
                }
                $to = date("U", mktime(0, 0, 0, $month_number, $month_date, $year));
                $monthly_opening_stocks[$month] = Disbursements::getRegionalPeriodBalance($id, $vaccine, $to);
                $counter += 3;
            }
            $upper_limit = $monthly_requirement * 4;
            $lower_limit = $monthly_requirement;
        } else {
            if ($type == 1) {
                //District Store
                $population = district_populations::getDistrictPopulation($id, $year);
                $population = str_replace(",", "", $population);
                $monthly_requirement = ceil($vaccine_object->Doses_Required * $population * $vaccine_object->Wastage_Factor / 12);
                for ($month = 1; $month <= 36; $month++) {
                    //Get the month
                    $month_number = $counter / 2;
                    //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 = 7;
                    } else {
                        if ($month % 3 == 1) {
                            $month_date = 21;
                        } else {
                            if ($month % 3 == 2) {
                                $month_date = 28;
                            }
                        }
                    }
                    $to = date("U", mktime(0, 0, 0, $month_number, $month_date, $year));
                    $monthly_opening_stocks[$month] = Disbursements::getDistrictPeriodBalance($id, $vaccine, $to);
                    $counter += 2;
                }
                $upper_limit = $monthly_requirement * 2;
                $lower_limit = ceil($monthly_requirement / 2);
            } else {
                if ($type == 2) {
                    //National Store
                    $population = regional_populations::getNationalPopulation($year);
                    $population = str_replace(",", "", $population);
                    $monthly_requirement = ceil($vaccine_object->Doses_Required * $population * $vaccine_object->Wastage_Factor / 12);
                    for ($month = 1; $month <= 36; $month++) {
                        //Get the month
                        $month_number = $counter / 2;
                        //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 = 7;
                        } else {
                            if ($month % 3 == 1) {
                                $month_date = 21;
                            } else {
                                if ($month % 3 == 2) {
                                    $month_date = 28;
                                }
                            }
                        }
                        $to = date("U", mktime(0, 0, 0, $month_number, $month_date, $year));
                        $monthly_opening_stocks[$month] = Disbursements::getNationalPeriodBalance($vaccine, $to);
                        $counter += 2;
                    }
                    $upper_limit = $monthly_requirement * 4;
                    $lower_limit = $monthly_requirement;
                }
            }
        }
        $chart = '
<chart caption="Monthly Stock at Hand Summary" subcaption="For the year ' . $year . '" xAxisName="Month" yAxisName="Quantity"  numberSuffix=" doses" showValues="0" alternateHGridColor="FCB541" alternateHGridAlpha="20" divLineColor="FCB541" divLineAlpha="50" canvasBorderColor="666666" baseFontColor="666666" lineColor="FCB541">
<categories>
<category label="Jan"/>
<category label=""/>
<category label=""/>
<category label="Feb"/>
<category label=""/>
<category label=""/>
<category label="Mar"/>
<category label=""/>
<category label=""/>
<category label="Apr"/>
<category label=""/>
<category label=""/>
<category label="May"/>
<category label=""/>
<category label=""/>
<category label="Jun"/>
<category label=""/>
<category label=""/>
<category label="Jul"/>
<category label=""/>
<category label=""/>
<category label="Aug"/>
<category label=""/>
<category label=""/>
<category label="Sep"/>
<category label=""/>
<category label=""/>
<category label="Oct"/>
<category label=""/>
<category label=""/>
<category label="Nov"/>
<category label=""/>
<category label=""/>
<category label="Dec"/>
<category label=""/>
<category label=""/>
</categories> 
<dataset seriesName="Upper Limit" color="269600" anchorBorderColor="269600" anchorBgColor="269600">';
        for ($x = 1; $x <= 36; $x++) {
            $cumulative_value = $upper_limit;
            $chart .= '<set value="' . $cumulative_value . '"/>';
        }
        $chart .= '</dataset>

<dataset seriesName="Receipts" color="0008FF" anchorBorderColor="0008FF" anchorBgColor="0008FF">
<set  value="' . $monthly_opening_stocks[1] . '"/>
<set  value="' . $monthly_opening_stocks[2] . '"/>
<set  value="' . $monthly_opening_stocks[3] . '"/>
<set value="' . $monthly_opening_stocks[4] . '"/>
<set  value="' . $monthly_opening_stocks[5] . '"/>
<set value="' . $monthly_opening_stocks[6] . '"/>
<set  value="' . $monthly_opening_stocks[7] . '"/>
<set  value="' . $monthly_opening_stocks[8] . '"/>
<set  value="' . $monthly_opening_stocks[9] . '"/>
<set  value="' . $monthly_opening_stocks[10] . '"/>
<set  value="' . $monthly_opening_stocks[11] . '"/>
<set value="' . $monthly_opening_stocks[12] . '"/>
<set  value="' . $monthly_opening_stocks[13] . '"/>
<set  value="' . $monthly_opening_stocks[14] . '"/>
<set  value="' . $monthly_opening_stocks[15] . '"/>
<set value="' . $monthly_opening_stocks[16] . '"/>
<set  value="' . $monthly_opening_stocks[17] . '"/>
<set value="' . $monthly_opening_stocks[18] . '"/>
<set  value="' . $monthly_opening_stocks[19] . '"/>
<set  value="' . $monthly_opening_stocks[20] . '"/>
<set  value="' . $monthly_opening_stocks[21] . '"/>
<set  value="' . $monthly_opening_stocks[22] . '"/>
<set  value="' . $monthly_opening_stocks[23] . '"/>
<set value="' . $monthly_opening_stocks[24] . '"/>
<set value="' . $monthly_opening_stocks[25] . '"/>
<set  value="' . $monthly_opening_stocks[26] . '"/>
<set  value="' . $monthly_opening_stocks[27] . '"/>
<set  value="' . $monthly_opening_stocks[28] . '"/>
<set value="' . $monthly_opening_stocks[29] . '"/>
<set  value="' . $monthly_opening_stocks[30] . '"/>
<set value="' . $monthly_opening_stocks[31] . '"/>
<set  value="' . $monthly_opening_stocks[32] . '"/>
<set  value="' . $monthly_opening_stocks[33] . '"/>
<set  value="' . $monthly_opening_stocks[34] . '"/>
<set  value="' . $monthly_opening_stocks[35] . '"/>
<set  value="' . $monthly_opening_stocks[36] . '"/> 
</dataset>
<dataset seriesName="Lower Limit" color="FF0000" anchorBorderColor="FF0000" anchorBgColor="FF0000">';
        for ($x = 1; $x <= 36; $x++) {
            $cumulative_value = $lower_limit;
            $chart .= '<set value="' . $cumulative_value . '"/>';
        }
        $chart .= '</dataset>
<styles>
<definition>
<style name="Anim1" type="animation" param="_xscale" start="0" duration="1"/>
<style name="Anim2" type="animation" param="_alpha" start="0" duration="0.6"/>
<style name="DataShadow" type="Shadow" alpha="40"/>
</definition>
<application>
<apply toObject="DIVLINES" styles="Anim1"/>
<apply toObject="HGRID" styles="Anim2"/>
<apply toObject="DATALABELS" styles="DataShadow,Anim2"/>
</application>
</styles>
</chart>
';
        echo $chart;
    }
Beispiel #17
0
    public function get_freezer_occupancy($national = "", $region = "", $district = "")
    {
        $title = "";
        $store_fridges = "";
        if ($national > 0) {
            $store_fridges = National_Fridges::getNationalFridges();
        }
        if ($region > 0) {
            $store_fridges = Regional_Fridges::getRegionFridges($region);
        }
        if ($district > 0) {
            $store_fridges = District_Fridges::getDistrictFridges($district);
        }
        $freezer_vaccines = Fridge_Compartments::getCompartmentVaccines("freezer");
        $freezer_capacities = array();
        $now = date("U");
        $total_net_volume_minus_20deg = 0;
        $occupied_capacity = 0;
        foreach ($store_fridges as $fridge) {
            $total_net_volume_minus_20deg += $fridge->Fridge_Equipment->Net_Vol_Minus_20deg;
        }
        //Get the stock balances for each of the vaccines at this point in time
        foreach ($freezer_vaccines as $vaccine) {
            if ($vaccine->Active == "0") {
                continue;
            }
            $volume = $vaccine->Vaccine_Packed_Volume;
            if ($national > 0) {
                $stock_balance = Disbursements::getNationalPeriodBalance($vaccine->id, $now);
            }
            if ($region > 0) {
                $stock_balance = Disbursements::getRegionalPeriodBalance($region, $vaccine->id, $now);
            }
            if ($district > 0) {
                $stock_balance = Disbursements::getDistrictPeriodBalance($district, $vaccine->id, $now);
            }
            $volume_occupied = $volume * $stock_balance;
            if ($volume_occupied > 0) {
                $volume_occupied = $volume_occupied / 1000;
                $occupied_capacity += $volume_occupied;
            }
        }
        $percentage_occupied = number_format($occupied_capacity / $total_net_volume_minus_20deg, 3) * 100;
        $chart = '<chart bgColor="FFFFFF"';
        if ($percentage_occupied >= 75) {
            $chart .= ' cylFillColor="EB0000"';
        } else {
            $chart .= ' cylFillColor="07E007"';
        }
        $chart .= ' showBorder="0" showCanvasBase="1"  cylRadius="20" upperLimit="100" lowerLimit="0" tickMarkGap="5" numberSuffix="%" caption="% of Fridge Occupied">
<value>' . $percentage_occupied . '</value>
<annotations>
<annotationGroup>
<annotation type="text" label="Freezer" font="Verdana" xPos="10" yPos="285" align="left" vAlign="left" fontcolor="333333" fontSize="10"/>
</annotationGroup>

</annotations>
</chart>';
        echo $chart;
    }