public function export($type, $id, $vaccine) { //Retrieve the user identifier $from = $this -> session -> userdata('external_from'); $to = $this -> session -> userdata('external_to'); if ($to == false) { $to = date("U", mktime(0, 0, 0, 1, 1, date("Y") + 1)); } if ($from == false) { $from = date("U", mktime(0, 0, 0, 1, 1, date('Y'))); } $offset = 0; $items_per_page = 1000; $district = $this -> session -> userdata('external_district'); $region = $this -> session -> userdata('external_region'); $order_by = $this -> session -> userdata('external_order_by'); $order = $this -> session -> userdata('external_order'); $origin_region = $id; $origin_district = $id; $disbursements = null; $data = null; if ($type == "national_officer") {//National Level if ($order == 2) { $balance = Disbursements::getNationalPeriodBalance($vaccine, $from); } else if ($order == "DESC") { $balance = Disbursements::getNationalPeriodBalance($vaccine, $to); } $disbursements = Disbursements::getNationalDisbursements($vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balance); } else if ($type == 0) {//Regional Level if ($order == "ASC") { $balance = Disbursements::getRegionalPeriodBalance($origin_region, $vaccine, $from); } else if ($order == "DESC") { $balance = Disbursements::getRegionalPeriodBalance($origin_region, $vaccine, $to); } $disbursements = Disbursements::getRegionalDisbursements($origin_region, $vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balance); } else if ($type == 1) {//District Level if ($order == "ASC") { $balance = Disbursements::getDistrictPeriodBalance($origin_district, $vaccine, $from); } else if ($order == "DESC") { $balance = Disbursements::getDistrictPeriodBalance($origin_district, $vaccine, $to); } $disbursements = Disbursements::getDistrictDisbursements($origin_district, $vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order, $balance); } $reducing_balance = $balance; $headers = "Balance From Previous Period: " . $balance . "\t\nDate Issued\t Vaccines To/From \t Amount Received\t Amount Issued \tStore Balance\t Voucher Number\t Batch Number\t Vaccine Expiry Date\t Recorded By\t\n"; foreach ($disbursements as $disbursement) { $data .= $disbursement -> Date_Issued . "\t"; //If the vaccines were issued to a Region, display the name if ($disbursement -> Issued_To_Region != null && $disbursement -> Issued_To_Region != $origin_region) { $data .= $disbursement -> Region_Issued_To -> name . "\t"; $data .= " \t" . $disbursement -> Quantity . "\t"; } //If the vaccines were received from a region (apart from ourselves ofcourse) display the name if ($disbursement -> Issued_By_Region != null && $disbursement -> Issued_By_Region != $origin_region) { $data .= $disbursement -> Region_Issued_By -> name . "\t"; $data .= $disbursement -> Quantity . "\t\t"; } //If the vaccines were issued to a District other than ourselves, display the name if ($disbursement -> Issued_To_District != null && $disbursement -> Issued_To_District != $origin_district) { $data .= $disbursement -> District_Issued_To -> name . "\t"; $data .= " \t" . $disbursement -> Quantity . "\t"; } //If the vaccines were received from a district (apart from ourselves ofcourse) display the name if ($disbursement -> Issued_By_District != null && $disbursement -> Issued_By_District != $origin_district) { $data .= $disbursement -> District_Issued_By -> name . "\t"; $data .= $disbursement -> Quantity . "\t\t"; } //If the vaccines were issued the Central store, Display UNICEF as the source if ($disbursement -> Issued_To_National == "0") { $data .= "UNICEF\t"; $data .= $disbursement -> Quantity . "\t\t"; } //If the vaccines were issued by Central store and if this is not the national store, Display National Store as the source if ($disbursement -> Issued_By_National == "0" && $type != 2) { $data .= "Central Vaccine Stores\t"; $data .= $disbursement -> Quantity . "\t\t"; } $data .= $disbursement -> Total_Stock_Balance . "\t"; $data .= $disbursement -> Voucher_Number . "\t"; $data .= $disbursement -> Batch_Number . "\t"; $data .= $disbursement -> Batch -> Expiry_Date . "\t"; $data .= $disbursement -> User -> Full_Name . "\t"; $data .= "\n"; } header("Content-type: application/vnd.ms-excel; name='excel'"); header("Content-Disposition: filename=stock_ledger_export.xls"); // Fix for crappy IE bug in download. header("Pragma: "); header("Cache-Control: "); echo $headers . $data; }
public function export($vaccine) { //Retrieve the user identifier $level = $this->session->userdata('user_identifier'); $from = $this->session->userdata('from'); $to = $this->session->userdata('to'); $offset = 0; $items_per_page = 100; $district = $this->session->userdata('district'); $region = $this->session->userdata('region'); $order_by = $this->session->userdata('order_by'); $order = $this->session->userdata('order'); $region = $this->session->userdata('district_province_id'); $disbursements = null; $data = null; if ($level == "national_officer") { //National Level $disbursements = Disbursements::getNationalDisbursements($vaccine, $from, $to, $offset, $items_per_page, $district, $region, $order_by, $order); $balance = Disbursements::getNationalPeriodBalance($vaccine, $from); } else { if ($level == "provincial_officer") { //Regional Level $disbursements = Disbursements::getRegionalDisbursements($region, $vaccine, $from, $to, $offset, $items_per_page, $district, $region); $balance = Disbursements::getRegionalPeriodBalance($region, $vaccine, $from); } } $reducing_balance = $balance; $headers = "Balance From Previous Period: " . $balance . "\t\nDate Issued\t Vaccines To/From \t Amount Received\t Amount Issued \t Store Balance\t Voucher Number\t Batch Number\t Vaccine Expiry Date\t Recorded By\t\n"; foreach ($disbursements as $disbursement) { $data .= $disbursement->Date_Issued . "\t"; //If the vaccines were issued to a Region, display the name if ($disbursement->Issued_To_Region != null) { $data .= $disbursement->Region_Issued_To->name . "\t"; $data .= " \t" . $disbursement->Quantity . "\t"; $reducing_balance -= $disbursement->Quantity; } //If the vaccines were received from a region (apart from ourselves ofcourse) display the name if ($disbursement->Issued_By_Region != null && $disbursement->Issued_By_Region != $region) { $data .= $disbursement->Region_Issued_By->name . "\t"; $data .= $disbursement->Quantity . "\t\t"; $reducing_balance += $disbursement->Quantity; } //If the vaccines were issued to a Region, display the name if ($disbursement->Issued_To_District != null) { $data .= $disbursement->District_Issued_To->name . "\t"; $data .= " \t" . $disbursement->Quantity . "\t"; $reducing_balance -= $disbursement->Quantity; } //If the vaccines were issued the Central store, Display UNICEF as the source if ($disbursement->Issued_To_National == "0") { $data .= "UNICEF\t"; $data .= $disbursement->Quantity . "\t\t"; $reducing_balance += $disbursement->Quantity; } //If the vaccines were issued by Central store and if this is not the national store, Display National Store as the source if ($disbursement->Issued_By_National == "0" && $level != 1) { $data .= "Central Vaccine Stores\t"; $data .= $disbursement->Quantity . "\t\t"; $reducing_balance += $disbursement->Quantity; } $data .= $reducing_balance . "\t"; $data .= $disbursement->Voucher_Number . "\t"; $data .= $disbursement->Batch_Number . "\t"; $data .= $disbursement->Batch->Expiry_Date . "\t"; $data .= $disbursement->User->Full_Name . "\t"; $data .= "\n"; } header("Content-type: application/vnd.ms-excel; name='excel'"); header("Content-Disposition: filename=export.xls"); // Fix for crappy IE bug in download. header("Pragma: "); header("Cache-Control: "); echo $headers . $data; }