public function save_vaccine() { $vaccine_id = $this->input->post('vaccine_id'); //Check if we are in editing mode first; if so, retrieve the edited record. if not, create a new one! if (strlen($vaccine_id) > 0) { $vaccine = Vaccines::getVaccine($vaccine_id); } else { $vaccine = new Vaccines(); } $vaccine->Name = $this->input->post("name"); $vaccine->Doses_Required = $this->input->post("doses_required"); $vaccine->Wastage_Factor = $this->input->post("wastage_factor"); $vaccine->Designation = $this->input->post("designation"); $vaccine->Formulation = $this->input->post("formulation"); $vaccine->Administration = $this->input->post("administration"); $vaccine->Presentation = $this->input->post("presentation"); $vaccine->Vaccine_Packed_Volume = $this->input->post("vaccine_packed_volume"); $vaccine->Diluents_Packed_Volume = $this->input->post("diluents_packed_volume"); $vaccine->Vaccine_Vial_Price = $this->input->post("vaccine_vial_price"); $vaccine->Vaccine_Dose_Price = $this->input->post("vaccine_dose_price"); $vaccine->Fridge_Compartment = $this->input->post("fridge_compartment"); $vaccine->Added_By = $this->session->userdata('user_id'); $vaccine->Timestamp = date('U'); $vaccine->Tray_Color = $this->input->post("tray_color"); $vaccine->save(); redirect("vaccine_management"); }
public function getRegionCoverage($vaccine) { $months_of_stock = array(); $region = $this -> session -> userdata('district_province_id'); $year = date('Y'); $now = date('U'); $to = date("U", mktime(0, 0, 0, 1, 1, date("Y") + 1)); $from = date("U", mktime(0, 0, 0, 1, 1, date('Y'))); //Get National Data $population = regional_populations::getRegionalPopulation($region,$year); $population = str_replace(",", "", $population); $vaccine_object = Vaccines::getVaccine($vaccine); $yearly_requirement = ceil(($vaccine_object -> Doses_Required * $population * $vaccine_object -> Wastage_Factor)); $stock_receipts = Disbursements::getRegionalReceiptsTotals($region,$vaccine, $from, $to); $percentage_coverage = ceil(($stock_receipts/$yearly_requirement)*100); $chart = ' <chart caption="Estimated Coverage" palette="4" numberSuffix="%" decimals="0" enableSmartLabels="1" enableRotation="0" bgAlpha="40,100" bgRatio="0,100" bgAngle="360" showBorder="0" startingAngle="70"> <set label="Covered" value="' . $percentage_coverage . '" isSliced="1"/> <set label="Pending" value="' . (100-$percentage_coverage) . '"/> </chart>'; echo $chart; }
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; }
public function get($vaccine, $year = "", $national = "", $region = "", $district = "") { 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"; } $monthly_opening_stocks = array(); $vaccine_objects = array(); if ($year == "0") { $year = date('Y'); } if ($vaccine == "0") { $vaccine_object = Vaccines::getFirstVaccine(); $vaccine_objects[0] = $vaccine_object; } else { if (strlen($vaccine) > 0) { $vaccines_array = explode('-', $vaccine); $counter = 0; foreach ($vaccines_array as $vaccines_element) { if (strlen($vaccines_element) > 0) { $vaccine_object = Vaccines::getVaccine($vaccines_element); $vaccine_objects[$counter] = $vaccine_object; } $counter++; } } } $year_start = date("U", mktime(0, 0, 0, 1, 1, $year)); $counter = 2; $population = 0; if ($national > 0) { $population = Regional_Populations::getNationalPopulation($year); } if ($region > 0) { $population = Regional_Populations::getRegionalPopulation($region, $year); } if ($district > 0) { $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++) { $stock_balance = 0; $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)); 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); } if ($stock_balance > 0) { $mos_balance = number_format($stock_balance / $monthly_requirement, 2); } $monthly_opening_stocks[$vaccine_object->id][$month] = $mos_balance; $counter += 2; } } $chart = ' <chart bgColor="FFFFFF" showBorder="0" showAlternateHGridColor="0" divLineAlpha="10" caption="Monthly Stock at Hand Summary" subcaption="For the year ' . $year . '" xAxisName="Month" yAxisName="Months of Stock" showValues="0" > <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="2 Months of Stock (Ideal Stock Level)" color="269600" anchorBorderColor="269600" anchorBgColor="269600">'; for ($x = 1; $x <= 36; $x++) { $chart .= '<set value="2"/>'; } $chart .= '</dataset>'; foreach ($vaccine_objects as $vaccine_object) { $chart .= '<dataset seriesName="' . $vaccine_object->Name . ' Balance"> <set value="' . $monthly_opening_stocks[$vaccine_object->id][1] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][2] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][3] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][4] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][5] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][6] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][7] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][8] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][9] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][10] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][11] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][12] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][13] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][14] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][15] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][16] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][17] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][18] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][19] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][20] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][21] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][22] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][23] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][24] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][25] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][26] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][27] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][28] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][29] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][30] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][31] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][32] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][33] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][34] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][35] . '"/> <set value="' . $monthly_opening_stocks[$vaccine_object->id][36] . '"/> </dataset>'; } $chart .= '<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; }
public function provisional_plan($vaccine) { $plan = Provisional_Plan::getCurrentPlan($vaccine); $data['plans'] = $plan; $data['vaccine'] = Vaccines::getVaccine($vaccine); $data['title'] = "Stock Management:: " . date('Y') . " Provisional Plan For " . $data['vaccine']->Name; $data['content_view'] = "plan_view"; $this->base_params($data); }
public function recipients($vaccine = 0, $selected_year = 0, $selected_quarter = 0, $national = 0, $region = 0, $district = 0) { $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; } if ($vaccine == "0") { $vaccine_object = Vaccines::getFirstVaccine(); } else { if (strlen($vaccine) > 0) { $vaccine_object = Vaccines::getVaccine($vaccine); } } //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)); } //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"; } 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"; } 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"; } //echo $sql_recipients; $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']; $counter++; } //Create the labels for the x axis $x_axis_increments = $max_forecast / 10; $x_axis_increments_counter = 0; $chart = '<chart bgColor="FFFFFF" showAlternateHGridColor="0" divLineAlpha="10" showBorder="0" xAxisLabelMode="auto" caption="Consumption Vs. Forecast for ' . $vaccine_object->Name . '" subCaption="for ' . $periods[$quarter] . ', ' . $year . '" yAxisName="Consumption" xAxisName="Forecast" showLegend="0" xAxisMaxValue="' . $max_forecast . '" xAxisMinValue="0" formatNumberScale="0"> <categories verticalLineColor="666666" verticalLineThickness="1">'; for ($x = 0; $x <= 10; $x++) { $x_axis_increments_counter += $x_axis_increments; $chart .= '<category label="' . number_format($x_axis_increments_counter) . '" x="' . $x_axis_increments_counter . '" showVerticalLine="1"/>'; } $chart .= '</categories>'; $counter = 0; foreach ($districts as $district_data) { $chart .= '<dataSet seriesName="' . $district_data . '" color="009900" anchorSides="3" anchorRadius="4" anchorBgColor="D5FFD5" anchorBorderColor="009900"><set y="' . $consumption[$counter] . '" x="' . $forecast[$counter] . '"/></dataSet> '; $counter++; } $chart .= ' <dataset seriesName="Ideal" color="009900" anchorSides="3" anchorRadius="4" anchorBgColor="D5FFD5" anchorBorderColor="009900" drawLine="1" anchorAlpha="0"><set y="0" x="0" />'; foreach ($forecast as $for_element) { $chart .= '<set y="' . $for_element . '" x="' . $for_element . '" />'; } $chart .= ' </dataset> </chart>'; echo $chart; }
public function get($type,$id,$vaccine) { $monthly_opening_stocks = array(); $year = date('Y'); $year_start = date("U", mktime(0, 0, 0, 1, 1, date('Y'))); $vaccine_object = Vaccines::getVaccine($vaccine); if($type == 0){ //Regional Store $population = regional_populations::getRegionalPopulation($id,$year); for($month = 1; $month<=12; $month++){ $to = date("U", mktime(0, 0, 0, $month, 1, date('Y'))); $monthly_opening_stocks[$month] = Disbursements::getRegionalReceiptsTotals($id, $vaccine,$year_start,$to); } } else if($type == 1){ //District Store $population = district_populations::getDistrictPopulation($id,$year); for($month = 1; $month<=12; $month++){ $to = date("U", mktime(0, 0, 0, $month, 1, date('Y'))); $monthly_opening_stocks[$month] = Disbursements::getDistrictReceiptsTotals($id, $vaccine,$year_start,$to); } } $population = str_replace(",","",$population); $monthly_requirement = ceil(($vaccine_object->Doses_Required*$population*$vaccine_object->Wastage_Factor)/12); $upper_limit = $monthly_requirement*2; $lower_limit = ceil($monthly_requirement/2); $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="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> <dataset seriesName="Upper Limit" color="269600" anchorBorderColor="269600" anchorBgColor="269600">'; for($x=1;$x<=12;$x++){ $cumulative_value = $x * $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].'"/> </dataset> <dataset seriesName="Lower Limit" color="FF0000" anchorBorderColor="FF0000" anchorBgColor="FF0000">'; for($x=1;$x<=12;$x++){ $cumulative_value = $x * $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; }
public function forecast($vaccine = 0, $year = 0, $national = 0, $region = 0, $district = 0) { if ($year == "0") { $year = date('Y'); } if ($vaccine == "0") { $vaccine_object = Vaccines::getFirstVaccine(); } else { if (strlen($vaccine) > 0) { $vaccine_object = Vaccines::getVaccine($vaccine); } } //Get the start and end dates for all the four 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)); //Set the maximum value $max_value = 0; $population = 0; //Get the consumption for each of the quarters if ($national > 0) { $population = regional_populations::getNationalPopulation($year); $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) { $population = Regional_Populations::getRegionalPopulation($region, $year); $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) { $population = District_Populations::getDistrictPopulation($district, $year); $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); } if ($quarter_one_consumption > $max_value) { $max_value = $quarter_one_consumption; } if ($quarter_two_consumption > $max_value) { $max_value = $quarter_two_consumption; } if ($quarter_three_consumption > $max_value) { $max_value = $quarter_three_consumption; } if ($quarter_four_consumption > $max_value) { $max_value = $quarter_four_consumption; } $population = str_replace(",", "", $population); //Get the monthly requirement $monthly_requirement = ceil($vaccine_object->Doses_Required * $population * $vaccine_object->Wastage_Factor / 12); $quarterly_consumption = $monthly_requirement * 3; echo $quarterly_consumption; if ($quarterly_consumption > $max_value) { $max_value = $quarterly_consumption; } $max_value = ceil($max_value / 20000) * 20000; $chart = '<chart bgColor="FFFFFF" plotGradientColor="" showAlternateHGridColor="0" divLineAlpha="10" showBorder="0" caption="Forecast vs. Consumption for ' . $vaccine_object->Name . '" subCaption="at Central Vaccines Store" xAxisName="Quarterly Consumption" yAxisName="Doses" showValues="0" decimals="0" formatNumberScale="0" useRoundEdges="0" yAxisMaxValue="' . $max_value . '"> <set label="Jan - Mar" value="' . $quarter_one_consumption . '"/> <set label="Apr - Jun" value="' . $quarter_two_consumption . '"/> <set label="Jul - Sep" value="' . $quarter_three_consumption . '"/> <set label="Oct - Dec" value="' . $quarter_four_consumption . '"/> <trendLines> <line startValue="' . $quarterly_consumption . '" color="#009933" displayvalue="Forecasted" toolText="Forecasted Quarterly Consumption"/> </trendLines> </chart>'; echo $chart; }