Ejemplo n.º 1
0
 public function add_recipient($data = null)
 {
     $data['title'] = "District Stock Outs";
     $data['quick_link'] = "district_stock_out";
     $data['districts'] = Districts::getAllDistricts();
     $data['report'] = "add_stock_out_recipient_view";
     $this->base_params($data);
 }
Ejemplo n.º 2
0
	public function edit_user($id) {
		$user = User::getUser($id);
		$data['user'] = $user;
		$data['title'] = "User Management::Edit " . $user -> Full_Name . "'s Details";
		$data['title'] = "User Management::Add New User";
		$data['module_view'] = "add_user_view";
		$data['groups'] = User_Groups::getAllGroups();
		$data['districts'] = Districts::getAllDistricts();
		$data['regions'] = Regions::getAllRegions();
		$this -> base_params($data);
	}
	public function view_ledger($type, $id, $paged_vaccine = null, $date_from = null, $date_to = null, $offset = 0, $default_offset = 0) {
		$data['type'] = $type;
		//get current district/region
		$district_or_province = $this -> session -> userdata('district_province_id');
		//get current level
		$identifier = $this -> session -> userdata('user_identifier');
		$dummy_identifier = "";
		//Determine if the user is trying to view the ledger for his/her own store
		//Type 0 means we are drilling down to a region
		if ($type == 0) {
			if ($identifier == "provincial_officer" && $district_or_province == $id) {
				redirect("disbursement_management/view_disbursements");
			}
			$dummy_identifier = "provincial_officer";
		}
		//Type 1 means we are drilling down to a district
		else if ($type == 1) {
			if ($identifier == "district_officer" && $district_or_province == $id) {
				redirect("disbursement_management/view_disbursements");
			}
			$dummy_identifier = "district_officer";
		}
		//Type 2 means we are drilling down to the whole country
		else if ($type == 2) {
			if ($identifier == "national_officer") {
				redirect("disbursement_management/view_disbursements");
			}
			$dummy_identifier = "national_officer";
		}
		$data['identifier'] = $dummy_identifier;
		$data['district_or_province'] = $id;

		$district_or_province = $id;
		//Now display the 'foreign' ledger
		$to = $this -> input -> post('to');
		$from = $this -> input -> post('from');
		$store = $this -> input -> post('selected_store_id');
		$order_by = $this -> input -> post('order_by');
		$order = $this -> input -> post('order');
		$per_page = $this -> input -> post('per_page');
		if ($to == false) {
			$to = date("U", mktime(0, 0, 0, 1, 1, date("Y") + 1));
		} else if ($to == true) {
			$to = strtotime($to);
		}
		if ($from == false) {
			$from = date("U", mktime(0, 0, 0, 1, 1, date('Y')));
		} else if ($from == true) {
			$from = strtotime($from);
		}

		if ($date_from != null) {
			$from = $date_from;
		} else if ($date_to != null) {
			$to = $date_to;
		}

		//Check if the user has specified how many items he/she wants per page. If not, default to 10 items per page.
		if ($per_page > 0) {
			$this -> session -> set_userdata(array("external_from" => $from, "external_to" => $to, "external_per_page" => $per_page, "external_order_by" => $order_by, "external_order" => $order));
		} else {
			$temp = $this -> session -> userdata('external_per_page');
			if ($temp == false) {
				$this -> session -> set_userdata(array("external_from" => $from, "external_to" => $to, "external_per_page" => 10, "external_order_by" => "Date_Issued_Timestamp", "external_order" => "DESC"));
			}
		}
		$items_per_page = $this -> session -> userdata('external_per_page');
		$order_by = $this -> session -> userdata('external_order_by');
		$order = $this -> session -> userdata('external_order');

		$region = 0;
		$district = 0;
		if ($store != null) {
			$split_parts = explode("_", $store);
			$type = $split_parts[0];
			$id = $split_parts[1];
			if ($type == "district") {
				$district = $id;
				$this -> session -> set_userdata(array("external_region" => ""));
				$this -> session -> set_userdata(array("external_district" => $district));
			} else if ($type == "region") {
				$region = $id;
				$this -> session -> set_userdata(array("external_district" => ""));
				$this -> session -> set_userdata(array("external_region" => $region));
			} else if ($type == "national") {
				$this -> session -> set_userdata(array("external_district" => ""));
				$this -> session -> set_userdata(array("external_region" => ""));
			}
		}
		$district = $this -> session -> userdata('external_district');
		$region = $this -> session -> userdata('external_region');
		$data['vaccines'] = Vaccines::getAll_Minified();
		$return_array = array();
		$balances = array();

		if ($type == 2) {//National Level
			$recipient = "Central Vaccines Store";
			foreach ($data['vaccines'] as $vaccine) {
				//skip the vaccine that is currently being browsed through
				if ($vaccine -> id == $paged_vaccine) {
					continue;
				}
				$total_disbursements = Disbursements::getTotalNationalDisbursements($vaccine -> id, $from, $to, $district, $region);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "external_ledger_management/view_ledger/" . $type . "/" . $id . "/" . $vaccine -> id . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 9;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$vaccine -> id] = $this -> pagination -> create_links();
				}
				if ($order == "ASC") {
					$balances[$vaccine -> id] = Disbursements::getNationalPeriodBalance($vaccine -> id, $from);
				} else if ($order == "DESC") {
					$balances[$vaccine -> id] = Disbursements::getNationalPeriodBalance($vaccine -> id, $to);
				}

				$return_array[$vaccine -> id] = Disbursements::getNationalDisbursements($vaccine -> id, $from, $to, $default_offset, $items_per_page, $district, $region, $order_by, $order, $balances[$vaccine -> id]);

			}

			if ($paged_vaccine != null) {
				$data['paged_vaccine'] = $paged_vaccine;
				$total_disbursements = Disbursements::getTotalNationalDisbursements($paged_vaccine, $from, $to, $district, $region);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "external_ledger_management/view_ledger/" . $type . "/" . $id . "/" . $paged_vaccine . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 8;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$paged_vaccine] = $this -> pagination -> create_links();
				}
				if ($order == "ASC") {
					$balances[$paged_vaccine] = Disbursements::getNationalPeriodBalance($paged_vaccine, $from);
				} else if ($order == "DESC") {
					$balances[$paged_vaccine] = Disbursements::getNationalPeriodBalance($paged_vaccine, $to);
				}
				$return_array[$paged_vaccine] = Disbursements::getNationalDisbursements($paged_vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balances[$paged_vaccine]);

			}
		} else if ($type == 0) {//Regional Store Level
			$recipient = Regions::getRegionName($district_or_province);
			foreach ($data['vaccines'] as $vaccine) {
				if ($vaccine -> id == $paged_vaccine) {
					continue;
				}
				$total_disbursements = Disbursements::getTotalRegionalDisbursements($district_or_province, $vaccine -> id, $from, $to, $district, $region);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "external_ledger_management/view_ledger/" . $type . "/" . $id . "/" . $vaccine -> id . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 9;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$vaccine -> id] = $this -> pagination -> create_links();
				}
				if ($order == "ASC") {
					$balances[$vaccine -> id] = Disbursements::getRegionalPeriodBalance($district_or_province, $vaccine -> id, $from);
				} else if ($order == "DESC") {
					$balances[$vaccine -> id] = Disbursements::getRegionalPeriodBalance($district_or_province, $vaccine -> id, $to);
				}
				$return_array[$vaccine -> id] = Disbursements::getRegionalDisbursements($district_or_province, $vaccine -> id, $from, $to, $default_offset, $items_per_page, $district, $region, $order_by, $order, $balances[$vaccine -> id]);

			}

			if ($paged_vaccine != null) {
				$data['paged_vaccine'] = $paged_vaccine;
				$total_disbursements = Disbursements::getTotalRegionalDisbursements($district_or_province, $paged_vaccine, $from, $to, $district, $region);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "external_ledger_management/view_ledger/" . $type . "/" . $id . "/" . $paged_vaccine . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 8;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$paged_vaccine] = $this -> pagination -> create_links();
				}
				if ($order == "ASC") {
					$balances[$paged_vaccine] = Disbursements::getRegionalPeriodBalance($district_or_province, $paged_vaccine, $from);
				} else if ($order == "DESC") {
					$balances[$paged_vaccine] = Disbursements::getRegionalPeriodBalance($district_or_province, $paged_vaccine, $to);
				}
				$return_array[$paged_vaccine] = Disbursements::getRegionalDisbursements($district_or_province, $paged_vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balances[$paged_vaccine]);

			}
		} else if ($type == 1) {//District Store Level
			$recipient = Districts::getDistrictName($district_or_province);
			foreach ($data['vaccines'] as $vaccine) {
				if ($vaccine -> id == $paged_vaccine) {
					continue;
				}
				$total_disbursements = Disbursements::getTotalDistrictDisbursements($district_or_province, $vaccine -> id, $from, $to, $district);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "external_ledger_management/view_ledger/" . $type . "/" . $id . "/" . $vaccine -> id . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 9;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$vaccine -> id] = $this -> pagination -> create_links();
				}
				if ($order == "ASC") {
					$balances[$vaccine -> id] = Disbursements::getDistrictPeriodBalance($district_or_province, $vaccine -> id, $from);
				} else if ($order == "DESC") {
					$balances[$vaccine -> id] = Disbursements::getDistrictPeriodBalance($district_or_province, $vaccine -> id, $to);
				}
				$return_array[$vaccine -> id] = Disbursements::getDistrictDisbursements($district_or_province, $vaccine -> id, $from, $to, $default_offset, $items_per_page, $order_by, $order, $district, $balances[$vaccine -> id]);

			}

			if ($paged_vaccine != null) {
				$data['paged_vaccine'] = $paged_vaccine;
				$total_disbursements = Disbursements::getTotalDistrictDisbursements($district_or_province, $paged_vaccine, $from, $to, $district);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "external_ledger_management/view_ledger/" . $type . "/" . $id . "/" . $paged_vaccine . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 8;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$paged_vaccine] = $this -> pagination -> create_links();
				}
				if ($order == "ASC") {
					$balances[$paged_vaccine] = Disbursements::getDistrictPeriodBalance($district_or_province, $paged_vaccine, $from);
				} else if ($order == "DESC") {
					$balances[$paged_vaccine] = Disbursements::getDistrictPeriodBalance($district_or_province, $paged_vaccine, $to);
				}
				$return_array[$paged_vaccine] = Disbursements::getDistrictDisbursements($district_or_province, $paged_vaccine, $from, $to, $offset, $items_per_page, $order_by, $order, $district, $balances[$paged_vaccine]);

			}
		}
		$data['title'] = $recipient . " Stock Ledger For The Period Between " . date('d/m/Y', $from) . " to " . date('d/m/Y', $to);
		$data['recipient'] = $recipient;
		$data['content_view'] = "view_external_ledger";

		$data['disbursements'] = $return_array;
		//$data['balances'] = $balances;
		$data['stylesheets'] = array("pagination.css");
		//Get all the districts and regions so as to enable drilling down to a particular store
		$data['districts'] = Districts::getAllDistricts();
		$data['regions'] = Regions::getAllRegions();
		$this -> base_params_min($data);
	}
Ejemplo n.º 4
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
 }
Ejemplo n.º 5
0
	public function view_disbursements($paged_vaccine = null, $date_from = null, $date_to = null, $offset = 0, $default_offset = 0) {
		$district_or_province = $this -> session -> userdata('district_province_id');
		$this -> load -> helper('to_excel');
		$to = $this -> input -> post('to');
		$from = $this -> input -> post('from');
		$store = $this -> input -> post('selected_store_id');
		$order_by = $this -> input -> post('order_by');
		$order = $this -> input -> post('order');
		$per_page = $this -> input -> post('per_page');

		if ($to == false) {
			$to = date("U", mktime(0, 0, 0, 1, 1, date("Y") + 1));
		} else if ($to == true) {
			$to = strtotime($to);
		}
		if ($from == false) {
			$from = date("U", mktime(0, 0, 0, 1, 1, date('Y')));
		} else if ($from == true) {
			$from = strtotime($from);
		}

		if ($date_from != null) {
			$from = $date_from;
		} else if ($date_to != null) {
			$to = $date_to;
		}

		//Check if the user has specified how many items he/she wants per page. If not, default to 10 items per page.
		if ($per_page > 0) {
			$this -> session -> set_userdata(array("from" => $from, "to" => $to, "per_page" => $per_page, "order_by" => $order_by, "order" => $order));
		} else {
			$temp = $this -> session -> userdata('per_page');
			if ($temp == false) {
				$this -> session -> set_userdata(array("from" => $from, "to" => $to, "per_page" => 10, "order_by" => "Unix_Timestamp(str_to_date(Date_Issued,'%m/%d/%Y'))", "order" => "DESC"));
			}

		}
		$items_per_page = $this -> session -> userdata('per_page');
		$order_by = $this -> session -> userdata('order_by');
		$order = $this -> session -> userdata('order');

		$region = 0;
		$district = 0;
		if ($store != null) {
			$split_parts = explode("_", $store);
			$type = $split_parts[0];
			$id = $split_parts[1];
			if ($type == "district") {
				$district = $id;
				$this -> session -> set_userdata(array("region" => ""));
				$this -> session -> set_userdata(array("district" => $district));
			} else if ($type == "region") {
				$region = $id;
				$this -> session -> set_userdata(array("district" => ""));
				$this -> session -> set_userdata(array("region" => $region));
			} else if ($type == "national") {
				$this -> session -> set_userdata(array("district" => ""));
				$this -> session -> set_userdata(array("region" => ""));
			}
		}
		$district = $this -> session -> userdata('district');
		$region = $this -> session -> userdata('region');

		$data['title'] = "Disbursement Management::Vaccine Stock Ledger For The Period Between " . date('d/m/Y', $from) . " to " . date('d/m/Y', $to);
		$data['content_view'] = "view_ledger_view";
		$data['vaccines'] = Vaccines::getAll_Minified();
		$return_array = array();
		$balances = array();

		//Retrieve the user identifier from the session
		$identifier = $this -> session -> userdata('user_identifier');

		if ($identifier == "national_officer") {//National Level

			foreach ($data['vaccines'] as $vaccine) {
				//skip the vaccine that is currently being browsed through
				if ($vaccine -> id == $paged_vaccine) {
					continue;
				}
				$total_disbursements = Disbursements::getTotalNationalDisbursements($vaccine -> id, $from, $to, $district, $region);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "disbursement_management/view_disbursements/" . $vaccine -> id . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 7;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$vaccine -> id] = $this -> pagination -> create_links();
				}
				$balances[$vaccine -> id] = Disbursements::getNationalPeriodBalance($vaccine -> id, $from);
				$return_array[$vaccine -> id] = Disbursements::getNationalDisbursements($vaccine -> id, $from, $to, $default_offset, $items_per_page, $district, $region, $order_by, $order, $balances[$vaccine -> id]);

			}

			if ($paged_vaccine != null) {
				$data['paged_vaccine'] = $paged_vaccine;
				$total_disbursements = Disbursements::getTotalNationalDisbursements($paged_vaccine, $from, $to, $district, $region);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "disbursement_management/view_disbursements/" . $paged_vaccine . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 6;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$paged_vaccine] = $this -> pagination -> create_links();
				}
				$balances[$paged_vaccine] = Disbursements::getNationalPeriodBalance($paged_vaccine, $from);
				$return_array[$paged_vaccine] = Disbursements::getNationalDisbursements($paged_vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balances[$paged_vaccine]);

			}
		} else if ($identifier == "provincial_officer") {//Regional Store Level
			foreach ($data['vaccines'] as $vaccine) {
				if ($vaccine -> id == $paged_vaccine) {
					continue;
				}
				$total_disbursements = Disbursements::getTotalRegionalDisbursements($district_or_province, $vaccine -> id, $from, $to, $district, $region);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "disbursement_management/view_disbursements/" . $vaccine -> id . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 7;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$vaccine -> id] = $this -> pagination -> create_links();
				}
				$balances[$vaccine -> id] = Disbursements::getRegionalPeriodBalance($district_or_province, $vaccine -> id, $from);
				$return_array[$vaccine -> id] = Disbursements::getRegionalDisbursements($district_or_province, $vaccine -> id, $from, $to, $default_offset, $items_per_page, $district, $region, $order_by, $order, $balances[$vaccine -> id]);

			}

			if ($paged_vaccine != null) {
				$data['paged_vaccine'] = $paged_vaccine;
				$total_disbursements = Disbursements::getTotalRegionalDisbursements($district_or_province, $paged_vaccine, $from, $to, $district, $region);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "disbursement_management/view_disbursements/" . $paged_vaccine . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 6;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$paged_vaccine] = $this -> pagination -> create_links();
				}
				$balances[$paged_vaccine] = Disbursements::getRegionalPeriodBalance($district_or_province, $paged_vaccine, $from);
				$return_array[$paged_vaccine] = Disbursements::getRegionalDisbursements($district_or_province, $paged_vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balances[$paged_vaccine]);

			}
		} else if ($identifier == "district_officer") {//District Store Level
			foreach ($data['vaccines'] as $vaccine) {
				if ($vaccine -> id == $paged_vaccine) {
					continue;
				}
				$total_disbursements = Disbursements::getTotalDistrictDisbursements($district_or_province, $vaccine -> id, $from, $to, $district);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "disbursement_management/view_disbursements/" . $vaccine -> id . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 7;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$vaccine -> id] = $this -> pagination -> create_links();
				}
				$balances[$vaccine -> id] = Disbursements::getDistrictPeriodBalance($district_or_province, $vaccine -> id, $from);
				$return_array[$vaccine -> id] = Disbursements::getDistrictDisbursements($district_or_province, $vaccine -> id, $from, $to, $default_offset, $items_per_page, $district, $order_by, $order, $balances[$vaccine -> id]);

			}

			if ($paged_vaccine != null) {
				$data['paged_vaccine'] = $paged_vaccine;
				$total_disbursements = Disbursements::getTotalDistrictDisbursements($district_or_province, $paged_vaccine, $from, $to, $district);

				if ($total_disbursements > $items_per_page) {
					$config['base_url'] = base_url() . "disbursement_management/view_disbursements/" . $paged_vaccine . "/" . $from . "/" . $to;
					$config['total_rows'] = $total_disbursements;
					$config['per_page'] = $items_per_page;
					$config['uri_segment'] = 6;
					$config['num_links'] = 5;
					$this -> pagination -> initialize($config);
					$data['pagination'][$paged_vaccine] = $this -> pagination -> create_links();
				}
				$balances[$paged_vaccine] = Disbursements::getDistrictPeriodBalance($district_or_province, $paged_vaccine, $from);
				$return_array[$paged_vaccine] = Disbursements::getDistrictDisbursements($district_or_province, $paged_vaccine, $from, $to, $offset, $items_per_page, $district, $order_by, $order, $balances[$paged_vaccine]);

			}
		}

		$data['disbursements'] = $return_array;
		$data['balances'] = $balances;
		$data['stylesheets'] = array("pagination.css");
		//Get all the districts and regions so as to enable drilling down to a particular store
		$data['districts'] = Districts::getAllDistricts();
		$data['regions'] = Regions::getAllRegions();
		$this -> base_params_min($data);
	}
Ejemplo n.º 6
0
 public function edit_task($id)
 {
     $tasks = Shipments::get_all($id);
     $data['tasks'] = $tasks;
     $data['title'] = "Task Management::Edit Task";
     $data['module_view'] = "add_user_view";
     $data['groups'] = User_Groups::getAllGroups();
     $data['districts'] = Districts::getAllDistricts();
     $data['regions'] = Regions::getAllRegions();
     $this->base_params($data);
     echo $id;
 }
Ejemplo n.º 7
0
 public function index()
 {
     //Get the Earliest Disbursement Date and the Earliest Archive Date. Do the neccesary!
     $earliest_disbursement_date = Disbursements::getEarliestDisbursement();
     $earliest_archive_date = Archive_Logs::getEarliestArchive();
     if ($earliest_archive_date == null) {
         $earliest_archive_date = date('m/d/Y');
     }
     $split_disbursement_date = explode('/', $earliest_disbursement_date);
     $split_archive_date = explode('/', $earliest_archive_date);
     var_dump($split_disbursement_date);
     var_dump($split_archive_date);
     $total_months = $split_archive_date[0] - $split_disbursement_date[0] + ($split_archive_date[2] - $split_disbursement_date[2]) * 12;
     $dates_to_archive = array();
     for ($archive_month = 0; $archive_month < $total_months; $archive_month++) {
         $expected_month = $archive_month + $split_disbursement_date[0];
         $year = $split_disbursement_date[2];
         //echo $expected_month." and ".$year;
         if ($expected_month > 12) {
             $year += ceil(($expected_month - 12) / 12);
             $expected_month -= 12;
         }
         $archive_date = $expected_month . "/15/" . $year;
         $dates_to_archive[$archive_month] = $archive_date;
     }
     var_dump($dates_to_archive);
     //foreach($dates_to_archive as $date_to_archive){
     //Check if this date's archive has been done. If not do it now!
     $expected_archive_date = "6/15/2011";
     $expected_archive_timestamp = strtotime($expected_archive_date);
     $archive_exists = Archive_Logs::archiveExists($expected_archive_date);
     if (!$archive_exists) {
         echo "Creating Archive!";
         //Loop through all vaccines
         $vaccines = Vaccines::getAll();
         $regions = Regions::getAllRegions();
         $districts = Districts::getAllDistricts();
         foreach ($vaccines as $vaccine) {
             //National Archive First
             $national_archive = new Archives();
             $national_archive->National_Store = "0";
             $national_archive->Stock_At_Hand = Disbursements::getNationalStockAtHand($vaccine->id, $expected_archive_timestamp);
             $national_archive->Date_Of_Archive = $expected_archive_date;
             $national_archive->Vaccine_Id = $vaccine->id;
             $national_archive->save();
             //Do archives for all the regions
             foreach ($regions as $region) {
                 $regional_archive = new Archives();
                 $regional_archive->Regional_Store_Id = $region->id;
                 $regional_archive->Stock_At_Hand = Disbursements::getRegionalStockAtHand($region->id, $vaccine->id, $expected_archive_timestamp);
                 $regional_archive->Date_Of_Archive = $expected_archive_date;
                 $regional_archive->Vaccine_Id = $vaccine->id;
                 $regional_archive->save();
             }
             //Do archives for all the districts. :-(
             foreach ($districts as $district) {
                 $district_archive = new Archives();
                 $district_archive->District_Store_Id = $district->id;
                 $district_archive->Stock_At_Hand = Disbursements::getDistrictStockAtHand($district->id, $vaccine->id, $expected_archive_timestamp);
                 $district_archive->Date_Of_Archive = $expected_archive_date;
                 $district_archive->Vaccine_Id = $vaccine->id;
                 $district_archive->save();
             }
         }
         $archive_log = new Archive_Logs();
         $archive_log->Archive_Date = $expected_archive_date;
         $archive_log->Timestamp = date('U');
         $archive_log->Save();
     } else {
         echo "This archive already exists!";
     }
     //}
 }
Ejemplo n.º 8
0
 public function dashboard()
 {
     $identifier = $this->session->userdata('user_identifier');
     if ($this->session->userdata('user_identifier') == 'national_officer') {
         $data['districts'] = Districts::getAllDistricts();
         $data['content_view'] = "national_immunization_dashboard_view";
         $data['title'] = "National Immunization Data";
     }
     if ($this->session->userdata('user_identifier') == 'district_officer') {
         $data['content_view'] = "regional_immunization_dashboard_view";
         $data['title'] = "Regional Immunization Data";
     }
     if ($this->session->userdata('user_identifier') == 'provincial_officer') {
         $data['content_view'] = "district_immunization_dashboard_view";
         $data['title'] = "District Immunization Data";
     }
     $data['scripts'] = array("FusionCharts/FusionCharts.js", "jquery-ui.js", "tab.js");
     $data['styles'] = array("jquery-ui.css", "tab.css");
     $data['link'] = "vaccination_management";
     $this->load->view('template', $data);
 }