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 view_vaccines() { $data['vaccines'] = Vaccines::getAll(); $data['title'] = "Vaccine Management::All Vaccines"; $data['module_view'] = "view_vaccines_view"; $this->base_params($data); }
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); }
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; }
public function index() { //Get the Earliest Disbursement Date and the Earliest Archive Date. Do the neccesary! $earliest_disbursement_date = Disbursements::getEarliestDisbursement(); $earliest_archive_date = Archive_Logs::getEarliestArchive(); if ($earliest_archive_date == null) { $earliest_archive_date = date('m/d/Y'); } $split_disbursement_date = explode('/', $earliest_disbursement_date); $split_archive_date = explode('/', $earliest_archive_date); var_dump($split_disbursement_date); var_dump($split_archive_date); $total_months = $split_archive_date[0] - $split_disbursement_date[0] + ($split_archive_date[2] - $split_disbursement_date[2]) * 12; $dates_to_archive = array(); for ($archive_month = 0; $archive_month < $total_months; $archive_month++) { $expected_month = $archive_month + $split_disbursement_date[0]; $year = $split_disbursement_date[2]; //echo $expected_month." and ".$year; if ($expected_month > 12) { $year += ceil(($expected_month - 12) / 12); $expected_month -= 12; } $archive_date = $expected_month . "/15/" . $year; $dates_to_archive[$archive_month] = $archive_date; } var_dump($dates_to_archive); //foreach($dates_to_archive as $date_to_archive){ //Check if this date's archive has been done. If not do it now! $expected_archive_date = "6/15/2011"; $expected_archive_timestamp = strtotime($expected_archive_date); $archive_exists = Archive_Logs::archiveExists($expected_archive_date); if (!$archive_exists) { echo "Creating Archive!"; //Loop through all vaccines $vaccines = Vaccines::getAll(); $regions = Regions::getAllRegions(); $districts = Districts::getAllDistricts(); foreach ($vaccines as $vaccine) { //National Archive First $national_archive = new Archives(); $national_archive->National_Store = "0"; $national_archive->Stock_At_Hand = Disbursements::getNationalStockAtHand($vaccine->id, $expected_archive_timestamp); $national_archive->Date_Of_Archive = $expected_archive_date; $national_archive->Vaccine_Id = $vaccine->id; $national_archive->save(); //Do archives for all the regions foreach ($regions as $region) { $regional_archive = new Archives(); $regional_archive->Regional_Store_Id = $region->id; $regional_archive->Stock_At_Hand = Disbursements::getRegionalStockAtHand($region->id, $vaccine->id, $expected_archive_timestamp); $regional_archive->Date_Of_Archive = $expected_archive_date; $regional_archive->Vaccine_Id = $vaccine->id; $regional_archive->save(); } //Do archives for all the districts. :-( foreach ($districts as $district) { $district_archive = new Archives(); $district_archive->District_Store_Id = $district->id; $district_archive->Stock_At_Hand = Disbursements::getDistrictStockAtHand($district->id, $vaccine->id, $expected_archive_timestamp); $district_archive->Date_Of_Archive = $expected_archive_date; $district_archive->Vaccine_Id = $vaccine->id; $district_archive->save(); } } $archive_log = new Archive_Logs(); $archive_log->Archive_Date = $expected_archive_date; $archive_log->Timestamp = date('U'); $archive_log->Save(); } else { echo "This archive already exists!"; } //} }
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 new_order() { $data['title'] = "Orders Management::New Order"; $data['content_view'] = "add_order_view"; $data['quick_link'] = "new_order"; $data['vaccinces'] = Vaccines::getAll(); $this -> base_params($data); }