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);
 }
Beispiel #2
0
 public function printReport($from, $to)
 {
     @$this->load->database();
     @($user_groups = User_groups::getAllGroups());
     foreach ($user_groups as $user_group) {
         @($identifier = $user_group["Identifier"]);
         @($population = 0);
         @($opening_balance = 0);
         @($closing_balance = 0);
         @($sql_consumption = "");
         @($store = "");
         @($vaccines = Vaccines::getAll_Minified());
         if ($identifier == 'provincial_officer') {
             @($provinces = Provinces::getAllProvinces());
             foreach ($provinces as $province) {
                 @($data_buffer = "\n\t\t\t   <style>\n\t\t\ttable.data-table {\n\t\t\ttable-layout: fixed;\n\t\t\twidth: 700px;\n\t\t\tborder-collapse:collapse;\n\t\t\tborder:1px solid black;\n\t\t\t}\n\t\t\ttable.data-table td, th {\n\t\t\twidth: 100px;\n\t\t\tborder: 1px solid black;\n\t\t\t}\n\t\t\t.leftie{\n\t\t\t\ttext-align: left !important;\n\t\t\t}\n\t\t\t.right{\n\t\t\t\ttext-align: right !important;\n\t\t\t}\n\t\t\t.center{\n\t\t\t\ttext-align: center !important;\n\t\t\t}\n\t\t\t</style>\n\t\t\t  ");
                 @($start_date = $from);
                 @($end_date = $to);
                 @($data_buffer .= "<table class='data-table'>");
                 @($data_buffer .= $this->echoTitles());
                 foreach ($vaccines as $vaccine) {
                     @($district_or_region = $province["id"]);
                     @($region_object = Regions::getRegion($district_or_region));
                     @($store = $region_object->name);
                     @($population = Regional_Populations::getRegionalPopulation($district_or_region, date('Y')));
                     @($opening_balance = Disbursements::getRegionalPeriodBalance($district_or_region, $vaccine->id, strtotime($start_date)));
                     @($closing_balance = Disbursements::getRegionalPeriodBalance($district_or_region, $vaccine->id, strtotime($end_date)));
                     @($owner = "R" . $district_or_region);
                     @($sql_consumption = "select (SELECT max(str_to_date(Date_Issued,'%m/%d/%Y'))  FROM `disbursements` where Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_Region = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_Region = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received");
                     @($query = $this->db->query($sql_consumption));
                     @($vaccine_data = $query->row());
                     @($monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12));
                     @($data_buffer .= "<tr><td>" . $vaccine->Name . "</td><td>" . number_format($opening_balance + 0) . "</td><td>" . number_format($vaccine_data->total_received + 0) . "</td><td>" . number_format($vaccine_data->total_issued + 0) . "</td><td>" . number_format($closing_balance - ($opening_balance + $vaccine_data->total_received - $vaccine_data->total_issued) + 0) . "</td><td>" . number_format($closing_balance + 0) . "</td><td>" . number_format($closing_balance / $monthly_requirement, 1) . "</td><td>" . $vaccine_data->last_stock_count . "</td></tr>");
                 }
                 //end of foreach vaccines
                 @($vals = 1);
                 @($data_buffer .= "</table>");
                 @$this->generatePDF($data_buffer, $start_date, $end_date, $store, $district_or_region, $vals, $store);
                 @($data_buffer = "");
             }
         }
         if ($identifier == 'district_officer') {
             @($districts = Districts::getAllDistricts());
             foreach ($districts as $district) {
                 @($data_buffer = "\n\t\t\t    <style>\n\t\t\ttable.data-table {\n\t\t\ttable-layout: fixed;\n\t\t\twidth: 700px;\n\t\t\tborder-collapse:collapse;\n\t\t\tborder:1px solid black;\n\t\t\t}\n\t\t\ttable.data-table td, th {\n\t\t\twidth: 100px;\n\t\t\tborder: 1px solid black;\n\t\t\t}\n\t\t\t.leftie{\n\t\t\t\ttext-align: left !important;\n\t\t\t}\n\t\t\t.right{\n\t\t\t\ttext-align: right !important;\n\t\t\t}\n\t\t\t.center{\n\t\t\t\ttext-align: center !important;\n\t\t\t}\n\t\t\t</style>\n\t\t\t  ");
                 @($start_date = $from);
                 @($end_date = $to);
                 @($data_buffer .= "<table class='data-table'>");
                 @($data_buffer .= $this->echoTitles());
                 foreach ($vaccines as $vaccine) {
                     @($district_or_region = $district["id"]);
                     @($district_object = Districts::getDistrict($district_or_region));
                     @($store = $district_object->name);
                     @($population = District_Populations::getDistrictPopulation($district_or_region, date('Y')));
                     @($opening_balance = Disbursements::getDistrictPeriodBalance($district_or_region, $vaccine->id, strtotime($start_date)));
                     @($closing_balance = Disbursements::getDistrictPeriodBalance($district_or_region, $vaccine->id, strtotime($end_date)));
                     @($owner = "D" . $district_or_region);
                     @($sql_consumption = "select (SELECT max(str_to_date(Date_Issued,'%m/%d/%Y'))  FROM `disbursements` where Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_District = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_District = '" . $district_or_region . "' and Owner = '" . $owner . "' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received");
                     @($query = $this->db->query($sql_consumption));
                     @($vaccine_data = $query->row());
                     @($monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12));
                     @($data_buffer .= "<tr><td>" . $vaccine->Name . "</td><td>" . number_format($opening_balance + 0) . "</td><td>" . number_format($vaccine_data->total_received + 0) . "</td><td>" . number_format($vaccine_data->total_issued + 0) . "</td><td>" . number_format($closing_balance - ($opening_balance + $vaccine_data->total_received - $vaccine_data->total_issued) + 0) . "</td><td>" . number_format($closing_balance + 0) . "</td><td>" . number_format($closing_balance / $monthly_requirement, 1) . "</td><td>" . $vaccine_data->last_stock_count . "</td></tr>");
                 }
                 //end of foreach vaccines
                 @($vals = 2);
                 @($data_buffer .= "</table>");
                 @$this->generatePDF($data_buffer, $start_date, $end_date, $store, $district_or_region, $vals, $store);
                 @($data_buffer = "");
             }
         }
         if ($identifier == 'national_officer') {
             @($data_buffer = "\n\t\t\t    <style>\n\t\t\ttable.data-table {\n\t\t\ttable-layout: fixed;\n\t\t\twidth: 700px;\n\t\t\tborder-collapse:collapse;\n\t\t\tborder:1px solid black;\n\t\t\t}\n\t\t\ttable.data-table td, th {\n\t\t\twidth: 100px;\n\t\t\tborder: 1px solid black;\n\t\t\t}\n\t\t\t.leftie{\n\t\t\t\ttext-align: left !important;\n\t\t\t}\n\t\t\t.right{\n\t\t\t\ttext-align: right !important;\n\t\t\t}\n\t\t\t.center{\n\t\t\t\ttext-align: center !important;\n\t\t\t}\n\t\t\t</style>\n\t\t\t  ");
             @($start_date = $from);
             @($end_date = $to);
             @($data_buffer .= "<table class='data-table'>");
             @($data_buffer .= $this->echoTitles());
             @($store = "Central Vaccines Store");
             foreach ($vaccines as $vaccine) {
                 @($population = Regional_Populations::getNationalPopulation(date('Y')));
                 @($opening_balance = Disbursements::getNationalPeriodBalance($vaccine->id, strtotime($start_date)));
                 @($closing_balance = Disbursements::getNationalPeriodBalance($vaccine->id, strtotime($end_date)));
                 @($sql_consumption = "select (SELECT max(str_to_date(Date_Issued,'%m/%d/%Y'))  FROM `disbursements` where Owner = 'N0' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "' and total_stock_balance>0)as last_stock_count,(SELECT sum(Quantity)FROM `disbursements` where Issued_By_National = '0' and Owner = 'N0' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_issued,(SELECT sum(Quantity) FROM `disbursements` where Issued_To_National = '0' and Owner = 'N0' and str_to_date(Date_Issued,'%m/%d/%Y') between str_to_date('" . $start_date . "','%m/%d/%Y') and\n  str_to_date('" . $end_date . "','%m/%d/%Y') and Vaccine_Id = '" . $vaccine->id . "')as total_received");
                 @($query = $this->db->query($sql_consumption));
                 @($vaccine_data = $query->row());
                 @($monthly_requirement = ceil($vaccine->Doses_Required * $population * $vaccine->Wastage_Factor / 12));
                 @($data_buffer .= "<tr><td>" . $vaccine->Name . "</td><td>" . number_format($opening_balance + 0) . "</td><td>" . number_format($vaccine_data->total_received + 0) . "</td><td>" . number_format($vaccine_data->total_issued + 0) . "</td><td>" . number_format($closing_balance - ($opening_balance + $vaccine_data->total_received - $vaccine_data->total_issued) + 0) . "</td><td>" . number_format($closing_balance + 0) . "</td><td>" . number_format($closing_balance / $monthly_requirement, 1) . "</td><td>" . $vaccine_data->last_stock_count . "</td></tr>");
             }
             //end of foreach vaccines
             @($vals = 3);
             @($data_buffer .= "</table>");
             @($district_or_region = "");
             @$this->generatePDF($data_buffer, $start_date, $end_date, $store, $district_or_region, $vals, $store);
             @($data_buffer = "");
         }
     }
     //end of foreach user_group
 }