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 getDistrict() { //for ajax $county = $_POST['county']; $districts = Districts::getDistrict($county); $list = ""; foreach ($districts as $districts) { $list .= $districts->id; $list .= "*"; $list .= $districts->district; $list .= "_"; } echo $list; }
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_recipients($selected_year = 0, $selected_quarter = 0, $national = 0, $region = 0, $district = 0) { $title = ""; if ($national > 0) { $title = "Antigen Recipients at Central Vaccine Store"; } if ($region > 0) { $region_object = Regions::getRegion($region); $title = "Antigen Recipients at " . $region_object->name; } if ($district > 0) { $district_object = Districts::getDistrict($district); $title = "Antigen Recipients at " . $district_object->name . " District Store"; } $this->load->database(); $year = date('Y'); $quarter = 1; $quarter_start_date = 0; $quarter_end_date = 0; $periods = array(1 => "Jan - Mar", 2 => "Apr - Jun", 3 => "Jul - Sep", 4 => "Oct - Dec"); if ($selected_year != "0") { $year = $selected_year; } if ($selected_quarter != "0") { $quarter = $selected_quarter; } $vaccines = Vaccines::getAll_Minified(); //Figure out which quarter has been selected and get the start and end dates for that quarter if ($quarter == 1) { $quarter_start_date = date("U", mktime(0, 0, 0, 1, 1, $year)); $quarter_end_date = date("U", mktime(0, 0, 0, 3, 31, $year)); } if ($quarter == 2) { $quarter_start_date = date("U", mktime(0, 0, 0, 4, 1, $year)); $quarter_end_date = date("U", mktime(0, 0, 0, 6, 30, $year)); } if ($quarter == 3) { $quarter_start_date = date("U", mktime(0, 0, 0, 7, 1, $year)); $quarter_end_date = date("U", mktime(0, 0, 0, 9, 30, $year)); } if ($quarter == 4) { $quarter_start_date = date("U", mktime(0, 0, 0, 10, 1, $year)); $quarter_end_date = date("U", mktime(0, 0, 0, 12, 31, $year)); } $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($vaccines); $district_data = array(); foreach ($vaccines as $vaccine_object) { $sql_recipients = ""; //query to get all the districts that received vaccines from the selected store in that period if ($national > 0) { $sql_recipients = "select districts_issued.*,sum(quantity) as total_received,d2.name as district_name from (select distinct issued_to_district as district_id from disbursements where owner = 'N0' and issued_to_district>0 and date_issued_timestamp between '" . $quarter_start_date . "' and '" . $quarter_end_date . "') districts_issued left join disbursements d on district_id = d.issued_to_district left join districts d2 on district_id = d2.ID where date_issued_timestamp between '" . $quarter_start_date . "' and '" . $quarter_end_date . "' and owner != concat('D',district_id) and vaccine_id = '" . $vaccine_object->id . "' group by district_id order by d2.name"; } if ($region > 0) { $sql_recipients = "select districts_issued.*,sum(quantity) as total_received,d2.name as district_name from (select distinct issued_to_district as district_id from disbursements where owner = 'R" . $region . "' and issued_to_district>0 and date_issued_timestamp between '" . $quarter_start_date . "' and '" . $quarter_end_date . "') districts_issued left join disbursements d on district_id = d.issued_to_district left join districts d2 on district_id = d2.ID where date_issued_timestamp between '" . $quarter_start_date . "' and '" . $quarter_end_date . "' and owner != concat('D',district_id) and vaccine_id = '" . $vaccine_object->id . "' group by district_id order by d2.name"; } if ($district > 0) { $sql_recipients = "select districts_issued.*,sum(quantity) as total_received,d2.name as district_name from (select distinct issued_to_district as district_id from disbursements where owner = 'D" . $district . "' and issued_to_district>0 and date_issued_timestamp between '" . $quarter_start_date . "' and '" . $quarter_end_date . "') districts_issued left join disbursements d on district_id = d.issued_to_district left join districts d2 on district_id = d2.ID where date_issued_timestamp between '" . $quarter_start_date . "' and '" . $quarter_end_date . "' and owner != concat('D',district_id) and vaccine_id = '" . $vaccine_object->id . "' group by district_id order by d2.name"; } $query = $this->db->query($sql_recipients); $recipients_data = $query->result_array(); $consumption = array(); $forecast = array(); $districts = array(); $counter = 0; $max_forecast = 0; foreach ($recipients_data as $recipient_district) { $population = District_Populations::getDistrictPopulation($recipient_district['district_id'], date('Y')); $monthly_requirement = 0; if ($population > 0) { $monthly_requirement = ceil($vaccine_object->Doses_Required * $population * $vaccine_object->Wastage_Factor / 12); } $monthly_requirement *= 3; if ($monthly_requirement > $max_forecast) { $max_forecast = $monthly_requirement; } $forecast[$counter] = $monthly_requirement; $consumption[$counter] = $recipient_district['total_received']; $districts[$counter] = $recipient_district['district_name']; $district_data[$recipient_district['district_id']]['district'] = $recipient_district['district_name']; $district_data[$recipient_district['district_id']][$vaccine_object->id] = array('vaccine' => $vaccine_object->id, 'forecast' => $monthly_requirement, 'consumption' => $recipient_district['total_received']); $counter++; } } //var_dump($district_data); foreach ($district_data as $row_data) { $data_buffer .= "<tr><td class='leftie'>" . $row_data['district'] . "</td>"; foreach ($vaccines as $vaccine_object) { if (isset($row_data[$vaccine_object->id])) { $data_buffer .= "<td class='right'>" . number_format($row_data[$vaccine_object->id]['forecast'] + 0) . "</td><td class='right'>" . number_format($row_data[$vaccine_object->id]['consumption'] + 0) . "</td>"; } else { $data_buffer .= "<td class='center'>-</td><td class='center'>-</td>"; } } $data_buffer .= "</tr>"; } $data_buffer .= "</table>"; $this->generatePDF($data_buffer, $periods[$quarter], $year, $title); //echo $data_buffer; }
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(); } }
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 edit_district($code) { $district = Districts::getDistrict($code); $data['district_populations'] = District_Populations::getAllForDistrict($code); $data['district'] = $district; $data['title'] = "District Management::Edit " . $district->name . " District"; $data['module_view'] = "add_district_view"; $data['quick_link'] = "new_district"; $data['provinces'] = Provinces::getAllProvinces(); $this->base_params($data); }
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 download($national = "", $region = "", $district = "") { $title = ""; $store_fridges = ""; if ($national > 0) { $title = "Cold Chain Utilization at Central Vaccine Store"; $store_fridges = National_Fridges::getNationalFridges(); } if ($region > 0) { $region_object = Regions::getRegion($region); $title = "Cold Chain Utilization at " . $region_object->name; $store_fridges = Regional_Fridges::getRegionFridges($region); } if ($district > 0) { $district_object = Districts::getDistrict($district); $title = "Cold Chain Utilization at " . $district_object->name . " District Store"; $store_fridges = District_Fridges::getDistrictFridges($district); } $freezer_vaccines = Fridge_Compartments::getCompartmentVaccines("freezer"); $fridge_vaccines = Fridge_Compartments::getCompartmentVaccines("fridge"); $all_vaccines = Vaccines::getAll_Minified(); $freezer_stock = array(); $fridge_stock = array(); $freezer_capacities = array(); $fridge_capacities = array(); $now = date("U"); $total_net_volume_4deg = 0; $total_net_volume_minus_20deg = 0; $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"; $data_buffer .= "<table class='data-table'>"; $data_buffer .= $this->echoTitles(); //Get the total Capacities of all the fridges foreach ($store_fridges as $fridge) { $total_net_volume_4deg += $fridge->Fridge_Equipment->Net_Vol_4deg; $total_net_volume_minus_20deg += $fridge->Fridge_Equipment->Net_Vol_Minus_20deg; } $freezer_capacity = $total_net_volume_minus_20deg; $fridge_capacity = $total_net_volume_4deg; //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; $stock_balance = 0; 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); } $freezer_stock[$vaccine->id] = $stock_balance; $volume_occupied = $volume * $stock_balance; if ($volume_occupied > 0) { $volume_occupied = $volume_occupied / 1000; $freezer_capacities[$vaccine->id] = $volume_occupied; $total_net_volume_minus_20deg -= $volume_occupied; } else { $freezer_capacities[$vaccine->id] = 0; } } //Get the stock balances for each of the vaccines at this point in time foreach ($fridge_vaccines as $vaccine) { if ($vaccine->Active == "0") { continue; } $volume = $vaccine->Vaccine_Packed_Volume; $stock_balance = 0; 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; $fridge_capacities[$vaccine->id] = $volume_occupied; $total_net_volume_4deg -= $volume_occupied; } else { $fridge_capacities[$vaccine->id] = 0; } $fridge_stock[$vaccine->id] = $stock_balance; } $fridge_totals = 0; $freezer_totals = 0; foreach ($all_vaccines as $vaccine) { $data_buffer .= "<tr><td style='text-align: left;'>" . $vaccine->Name . "</td>"; if (isset($fridge_capacities[$vaccine->id])) { $data_buffer .= "<td class='right'>" . number_format($fridge_stock[$vaccine->id] + 0) . "</td><td class='right'>" . number_format($fridge_capacities[$vaccine->id] + 0) . "</td><td class='right'>N/A</td>"; $fridge_totals += $fridge_capacities[$vaccine->id]; } if (isset($freezer_capacities[$vaccine->id])) { $data_buffer .= "<td class='right'>" . number_format($freezer_stock[$vaccine->id] + 0) . "</td><td class='right'>N/A</td><td class='right'>" . number_format($freezer_capacities[$vaccine->id] + 0) . "</td>"; $freezer_totals += $freezer_capacities[$vaccine->id]; } $data_buffer .= "</tr>"; } $data_buffer .= "<tr><td style='text-align: left;'>Totals</td><td>-</td><td class='right'>" . number_format($fridge_totals + 0) . "</td><td class='right'>" . number_format($freezer_totals + 0) . "</td></tr>"; $data_buffer .= "</table>"; $data_buffer .= "<table class='data-table' style='margin-top:50px;'><tr><th>Statistic</th><th>(+2 to +8)</th><th>(-15 to -25)</th></tr>"; $data_buffer .= "<tr><td style='text-align: left;'>Total Net Volume (Litres)</th><td class='right'>" . number_format($fridge_capacity, 2) . "</td><td class='right'>" . number_format($freezer_capacity, 2) . "</td></tr>"; $data_buffer .= "<tr><td style='text-align: left;'>Total Occupied Capacity (Litres)</td><td class='right'>" . number_format($fridge_capacity - $total_net_volume_4deg, 2) . "</td><td class='right'>" . number_format($freezer_capacity - $total_net_volume_minus_20deg, 2) . "</td></tr>"; $data_buffer .= "<tr><td style='text-align: left;'>Available Capacity (Litres)</td><td class='right'>" . number_format($total_net_volume_4deg, 2) . "</td><td class='right'>" . number_format($total_net_volume_minus_20deg, 2) . "</td></tr></table>"; $this->generatePDF($data_buffer, $title); //echo $data_buffer; }
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; }
function get_cummulative_graph($year = 0, $antigens = 0, $district = 0, $facility = 0) { $graph_sub_title = ""; if ($year == 0) { $year = date('y'); } //Start creating the sql query $sql = "select reporting_period, "; $antigen_count = 0; $antigen_array = array(); $antigen_titles = array("dpt1_admin" => "DPT 1", "dpt2_admin" => "DPT 2", "dpt3_admin" => "DPT 3", "opv1_admin" => "OPV 1", "opv2_admin" => "OPV 2", "opv3_admin" => "OPV 3", "opv_birth_admin" => "OPV Birth", "pn1_admin" => "Pneumococal 1", "pn2_admin" => "Pneumococal 2", "pn3_admin" => "Pneumococal 3", "tt_pregnant" => "TT Pregnant Women", "tt_trauma" => "TT Trauma", "yellow_admin" => "Yellow Fever", "measles_admin" => "Measles", "bcg_admin" => "BCG"); $antigen_data = array(); $selected_antigens = array(); $this->load->database(); //If no antigens have been specified, get data for dpt1 and 3 if (strlen($antigens) == 1) { $selected_antigens = array("dpt1_admin", "dpt3_admin"); } else { $selected_antigens = explode("-", $antigens); array_pop($selected_antigens); } $counter = 1; //For each of the selected antigens, append it's retrieval chunk onto the sql query foreach ($selected_antigens as $selected_antigen) { array_push($antigen_array, $antigen_titles[$selected_antigen]); if (sizeof($selected_antigens) != $counter) { $sql .= "sum(" . $selected_antigen . ") as `" . $antigen_titles[$selected_antigen] . "`, "; } else { $sql .= "sum(" . $selected_antigen . ") as `" . $antigen_titles[$selected_antigen] . "` "; } $counter++; } //Finish creating the query based on whether the user is filtering down to a district or not if ($district == 0) { $graph_sub_title = "Nationwide"; $sql .= " from dhis_data where reporting_period like '%{$year}%' group by reporting_period"; } else { if ($district > 0) { if ($facility == 0) { $district_object = Districts::getDistrict($district); $graph_sub_title = "In " . $district_object->name . " District"; $sql .= " from dhis_data d left join facilities f on d.facility_code = f.facilitycode where reporting_period like '%{$year}%' and f.district = '" . $district . "' group by reporting_period"; } if ($facility > 0) { $facility_name = Facilities::getFacilityName($facility); $graph_sub_title = "In " . $facility_name; $sql .= " from dhis_data where reporting_period like '%{$year}%' and facility_code = '" . $facility . "' group by reporting_period"; } } } $query = $this->db->query($sql); $immunizations = $query->result_array(); foreach ($immunizations as $immunization) { foreach ($antigen_array as $antigen_dataset) { $antigen_data[$antigen_dataset][$immunization['reporting_period']] = $immunization["{$antigen_dataset}"]; } } $chart = '<chart caption="Immunization Data" subcaption="' . $graph_sub_title . ' For \'' . $year . '" connectNullData="1" showValues="0" formatNumberScale="0" lineDashGap="6" xAxisName="Month" yAxisName="Cummulative Immunized" showValues="0" showBorder="0" showAlternateHGridColor="0" divLineAlpha="10" bgColor="FFFFFF" exportEnabled="1" exportHandler="' . base_url() . 'Scripts/FusionCharts/ExportHandlers/PHP/FCExporter.php" exportAtClient="0" exportAction="download"> <categories> <category label="Jan"/> <category label="Feb"/> <category label="Mar"/> <category label="Apr"/> <category label="May"/> <category label="Jun"/> <category label="Jul"/> <category label="Aug"/> <category label="Sep"/> <category label="Oct"/> <category label="Nov"/> <category label="Dec"/> </categories>'; //Loop through all the months in the specified year $str_start = $year . "-01-01"; $str_end = $year . "-12-31"; $start = $month = strtotime($str_start); $end = strtotime($str_end); $loop_from = $str_start; $loop_to = $str_end; $days = array(); $counter = 0; //create an array of the various months while (strtotime($loop_from) <= strtotime($loop_to)) { $days[$counter] = date('M-y', strtotime($loop_from)); $loop_from = date("d-m-Y", strtotime("+1 month", strtotime($loop_from))); $counter++; } foreach ($antigen_array as $antigen_dataset) { $chart .= "<dataset seriesName='{$antigen_dataset}'>"; $antigen_dataset_data = $antigen_data[$antigen_dataset]; //Keep track of the cummulative totals $cummulative = 0; $counter = 0; while ($month < $end) { //get the description of the months $current_month = date('M-y', $month); if (isset($antigen_dataset_data[$current_month])) { //check if the next value is non-existent, if so, display a dotted line, else, display a kawaida line if (sizeof($antigen_dataset_data) != $counter) { $cummulative += $antigen_dataset_data[$current_month]; if (isset($antigen_dataset_data[$days[$counter + 1]])) { $chart .= '<set value="' . $cummulative . '"/>'; } else { $chart .= '<set value="' . $cummulative . '" dashed="1"/>'; } } } else { $chart .= '<set />'; } $counter++; $month = strtotime("+1 month", $month); } $start = $month = strtotime($str_start); $chart .= "</dataset>"; } $chart .= "</chart>"; echo $chart; }