Пример #1
0
    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;
    }
Пример #2
0
    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;
    }
Пример #3
0
    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;
    }