public function clone_excel_order_template($order_id, $report_type, $file_name = null)
 {
     $user_indicator = $this->session->userdata('user_indicator');
     if ($user_indicator == 'county') {
         $col = 'cty_qty';
     } else {
         if ($user_indicator == 'district') {
             $col = 'scp_qty';
         } else {
             $col = 'quantity_ordered_pack';
         }
     }
     $inputFileName = 'print_docs/excel/excel_template/KEMSA Customer Order Form.xls';
     $facility_details = facility_orders::get_facility_order_details($order_id);
     if (count($facility_details) == 1) {
         $facility_stock_data_item = facility_order_details::get_order_details($order_id);
         // echo "<pre>";print_r($facility_stock_data_item);echo "<pre>";exit;
         $file_name = isset($file_name) ? $file_name . '.xls' : time() . '.xls';
         $excel2 = PHPExcel_IOFactory::createReader('Excel5');
         $excel2 = $objPHPExcel = $excel2->load($inputFileName);
         // Empty Sheet
         $sheet = $objPHPExcel->getSheet(0);
         $highestRow = $sheet->getHighestRow();
         $highestColumn = $sheet->getHighestColumn();
         $excel2->setActiveSheetIndex(0);
         $excel2->getActiveSheet()->setCellValue('H4', $facility_details[0]['facility_code'])->setCellValue('H5', $facility_details[0]['facility_name'])->setCellValue('H6', '')->setCellValue('H7', $facility_details[0]['county'])->setCellValue('H8', $facility_details[0]['order_date']);
         //  Loop through each row of the worksheet in turn
         for ($row = 17; $row <= $highestRow; $row++) {
             //  Read a row of data into an array
             $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
             if (isset($rowData[0][2]) && $rowData[0][2] != '') {
                 foreach ($facility_stock_data_item as $facility_stock_data_item_) {
                     if (in_array($rowData[0][2], $facility_stock_data_item_)) {
                         $key = array_search($rowData[0][2], $facility_stock_data_item_);
                         //echo "<pre>";print_r($facility_stock_data_item_);echo "<pre>";
                         $excel2->getActiveSheet()->setCellValue("H{$row}", $facility_stock_data_item_["{$col}"]);
                     }
                 }
             }
         }
         $objWriter = PHPExcel_IOFactory::createWriter($excel2, 'Excel5');
         if ($report_type == 'download_file') {
             // We'll be outputting an excel file
             header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
             header("Cache-Control: no-store, no-cache, must-revalidate");
             header("Cache-Control: post-check=0, pre-check=0", false);
             header("Pragma: no-cache");
             // It will be called file.xls
             header("Content-Disposition: attachment; filename={$file_name}");
             // Write file to the browser
             $objWriter->save('php://output');
             $objPHPExcel->disconnectWorksheets();
             unset($objPHPExcel);
         } elseif ($report_type == 'save_file') {
             $objWriter->save("./print_docs/excel/excel_files/" . $file_name);
         }
     }
 }