예제 #1
0
 /**
  * Inserts New Report
  *
  * @return object
  */
 public static function addReportFileSheet($data = array())
 {
     $report = new ReportFileSheets();
     $report->version_id = $data['version_id'];
     $report->worksheet_number = $data['worksheet_number'];
     $report->data_table = $data['data_table'];
     $report->data_table_columns = $data['data_table_columns'];
     $report->excel_info = $data['excel_info'];
     $report->save();
     return $report;
 }
예제 #2
0
 public function savereport()
 {
     Session::flush('reportSheetData');
     $allfiles = Input::get('allfiles');
     $allfiles = explode(',', $allfiles);
     // get config
     $config = Configuration::getById(Input::get('config_id'));
     // get config sheets
     $configSheets = ConfigurationSheet::getArrangedSheets($config->config_id);
     // create the report first
     $report = Reports::addNewReport();
     foreach ($allfiles as $currentFile) {
         if ($currentFile != '') {
             // save file
             $reporfileData = array();
             //$reporfileData['flag_current_version'] = 1;
             //$reporfileData['report_filename'] = $currentFile;
             $reporfileData['report_id'] = $report->report_id;
             $reportFile = ReportFile::addReportFile($reporfileData);
             // save file version
             $reportFileVersionData = array();
             $reportFileVersionData['file_id'] = $reportFile->file_id;
             $reportFileVersionData['flag_current_version'] = 1;
             $reportFileVersionData['report_filename'] = $currentFile;
             $reportVersion = ReportFileVersion::addReportFileVersion($reportFileVersionData);
             // save each sheet
             $file = "uploads/{$currentFile}";
             Excel::load($file, function ($reader) use($reportFile, $reportVersion, $config, $configSheets) {
                 foreach ($reader->getWorksheetIterator() as $worksheetNbr => $worksheet) {
                     //echo 'Worksheet number - ', $worksheetNbr, PHP_EOL;
                     $currentWorksheet = $worksheetNbr + 1;
                     if (isset($configSheets["sheet{$currentWorksheet}"])) {
                         $currentConfig = $configSheets["sheet{$currentWorksheet}"];
                         // data table columns
                         $data_table_columns = $worksheet->rangeToArray($currentConfig['data_table_columns']);
                         $data_table_columns = json_encode($data_table_columns);
                         // data table
                         //$data_table = $worksheet->rangeToArray($currentConfig['data_table']);
                         $data_table = $worksheet->rangeToArray($currentConfig['data_table'], false, true, true, true);
                         Reports::prepareFileSheetSession($data_table);
                         $data_table = json_encode($data_table);
                         // excel info
                         if ($currentConfig['configuration_string'] != '') {
                             $config_string = json_decode($currentConfig['configuration_string']);
                             $new_config_string = array();
                             for ($i = 0; $i < count($config_string); $i++) {
                                 $currentCell = $worksheet->getCell("{$config_string[$i]->column}{$config_string[$i]->row}")->getValue();
                                 $currentCellColor = $worksheet->getStyle("{$config_string[$i]->column}{$config_string[$i]->row}")->getFill()->getStartColor()->getARGB();
                                 $new_config_string[$i] = $config_string[$i];
                                 $new_config_string[$i]->cell_value = $currentCell;
                                 $new_config_string[$i]->cell_color = $currentCellColor;
                             }
                             $new_config_string = json_encode($new_config_string);
                         } else {
                             $new_config_string = '';
                         }
                         // insert sheet
                         $reportSheetData = array();
                         $reportSheetData['version_id'] = $reportVersion->version_id;
                         $reportSheetData['worksheet_number'] = $worksheetNbr;
                         $reportSheetData['data_table'] = $data_table;
                         $reportSheetData['data_table_columns'] = $data_table_columns;
                         $reportSheetData['excel_info'] = $new_config_string;
                         ReportFileSheets::addReportFileSheet($reportSheetData);
                     }
                 }
             });
         }
     }
     // get previous incident's data
     $previousIncidentData = Reports::getPreviousIncidentData();
     // get current incident's data
     $reportSheets = Reports::retrieveFileSheetSession();
     $newIncidenData = Reports::rearrangeSheetSession($reportSheets);
     $incidentComparison = Reports::compareIncidentData($previousIncidentData, $newIncidenData);
     if (count($incidentComparison) > 0) {
         Session::put('incidentReportErrors' . $report->report_id, $incidentComparison);
         /*$sessionErrors = Session::get('reportSheetData');
         		exit;*/
         Session::flash('incident_warning', 'There are errors in your report. Please see below.');
         return Redirect::to('reports/view1/' . $report->report_id);
     } else {
         Session::flash('success', 'Your report(s) has been successfully added.');
         return Redirect::to('reports/list');
     }
     exit;
     Session::flash('success', 'Your report(s) has been successfully added.');
     return Redirect::to('reports/list');
 }
예제 #3
0
 public static function getAllReportRowsByReportId($report_id = 0, $fileIds = array())
 {
     $excelSheets = array();
     $currentReport = self::where('report_id', $report_id)->first();
     if ($currentReport && count($currentReport) > 0) {
         # get all files under this report
         $reportFiles = ReportFile::getReportFilesById($currentReport->report_id, $fileIds);
         # get all version and sheets under this report
         for ($i = 0; $i < count($reportFiles); $i++) {
             // get current version
             $currentFileVersion = ReportFileVersion::getCurrentVersion($reportFiles[$i]->file_id);
             $reportFiles[$i]->currentFileVersion = $currentFileVersion;
             // get all file versions
             $allFileVersion = ReportFileVersion::getAllVersion($reportFiles[$i]->file_id);
             $reportFiles[$i]->allFileVersion = $allFileVersion;
             // get sheets
             $reportSheets = ReportFileSheets::getSheetsByVersionId($currentFileVersion->version_id);
             $reportFiles[$i]->reportSheets = $reportSheets;
             //self::print_this($reportSheets, '$reportSheets');
             foreach ($reportSheets as $sheet) {
                 $currentDataTable = (array) json_decode($sheet->data_table);
                 //self::print_this($currentDataTable, '$currentDataTable');
                 foreach ($currentDataTable as $row) {
                     //self::print_this($row, '$row');
                     if (isset($row->A) && $row->A != '') {
                         $excelSheets[$row->A] = (array) $row;
                     } elseif (isset($row->B) && $row->B != '') {
                         $excelSheets[$row->B] = (array) $row;
                     } elseif (isset($row[0]) && $row[0] != '') {
                         $excelSheets[$row[0]] = (array) $row;
                     } elseif (isset($row[1]) && $row[1] != '') {
                         $excelSheets[$row[1]] = (array) $row;
                     }
                 }
             }
         }
         //self::print_this($excelSheets, '$excelSheets');
     }
     return $excelSheets;
 }
 public function download($id = 0)
 {
     $currentReport = ConsolidatedReports::getById($id);
     $version = ConsolidatedReportsVersion::getById($id);
     # get table headers
     $originalReport = Reports::getReportById($currentReport->report_id);
     $reportFiles = ReportFile::getReportFilesById($originalReport->report_id);
     $reportColumns = array();
     if (isset($reportFiles[0])) {
         $currentOriginalFile = $reportFiles[0];
         $currentFileVersion = ReportFileVersion::getCurrentVersion($currentOriginalFile->file_id);
         // get sheets
         $reportColumns = ReportFileSheets::getFirstSheetByVersionId($currentFileVersion->version_id);
         $reportColumns = json_decode($reportColumns);
         $reportColumns = json_decode($reportColumns->data_table_columns);
     }
     # get table data
     $dataTable = json_decode($version->table_data);
     $report = ExcelExporter::formatFileArrays($dataTable);
     # combine headers and data
     $finalDataTable = array_merge($reportColumns, $report);
     # file name here
     $filename = "{$originalReport->incident_name} - Incident Number {$originalReport->incident_number}";
     ExcelExporter::exportFileTest($finalDataTable, $filename);
     //$reformattedReport =
 }