| 
				
			 | 
			
			
				
				@@ -12,19 +12,24 @@ class ExportService 
			 | 
		
		
	
		
			
			| 
				12
			 | 
			
				12
			 | 
			
			
				
				 { 
			 | 
		
		
	
		
			
			| 
				13
			 | 
			
				13
			 | 
			
			
				
				     public function exportToCsv(Company $company, ExportableReport $report, string $startDate, string $endDate): StreamedResponse 
			 | 
		
		
	
		
			
			| 
				14
			 | 
			
				14
			 | 
			
			
				
				     { 
			 | 
		
		
	
		
			
			| 
				15
			 | 
			
				
			 | 
			
			
				
				-        $filename = $company->name . ' ' . $report->getTitle() . ' ' . $startDate . ' to ' . $endDate . '.csv'; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				15
			 | 
			
			
				
				+        $formattedStartDate = Carbon::parse($startDate)->format('Y-m-d'); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				
				+        $formattedEndDate = Carbon::parse($endDate)->format('Y-m-d'); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				
				+        $timestamp = Carbon::now()->format('Y-m-d-H_i'); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				
				+        $filename = $company->name . ' ' . $report->getTitle() . ' ' . $formattedStartDate . ' to ' . $formattedEndDate . ' ' . $timestamp . '.csv'; 
			 | 
		
		
	
		
			
			| 
				16
			 | 
			
				21
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				17
			 | 
			
				22
			 | 
			
			
				
				         $headers = [ 
			 | 
		
		
	
		
			
			| 
				18
			 | 
			
				23
			 | 
			
			
				
				             'Content-Type' => 'text/csv', 
			 | 
		
		
	
		
			
			| 
				19
			 | 
			
				24
			 | 
			
			
				
				             'Content-Disposition' => 'attachment; filename="' . $filename . '"', 
			 | 
		
		
	
		
			
			| 
				20
			 | 
			
				25
			 | 
			
			
				
				         ]; 
			 | 
		
		
	
		
			
			| 
				21
			 | 
			
				26
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				22
			 | 
			
				
			 | 
			
			
				
				-        $callback = function () use ($report, $company, $startDate, $endDate) { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				
				+        $callback = function () use ($report, $company, $formattedStartDate, $formattedEndDate) { 
			 | 
		
		
	
		
			
			| 
				23
			 | 
			
				28
			 | 
			
			
				
				             $file = fopen('php://output', 'wb'); 
			 | 
		
		
	
		
			
			| 
				24
			 | 
			
				29
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				25
			 | 
			
				30
			 | 
			
			
				
				             fputcsv($file, [$report->getTitle()]); 
			 | 
		
		
	
		
			
			| 
				26
			 | 
			
				31
			 | 
			
			
				
				             fputcsv($file, [$company->name]); 
			 | 
		
		
	
		
			
			| 
				27
			 | 
			
				
			 | 
			
			
				
				-            fputcsv($file, ['Date Range: ' . $startDate . ' to ' . $endDate]); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				
				+            fputcsv($file, ['Date Range: ' . $formattedStartDate . ' to ' . $formattedEndDate]); 
			 | 
		
		
	
		
			
			| 
				28
			 | 
			
				33
			 | 
			
			
				
				             fputcsv($file, []); 
			 | 
		
		
	
		
			
			| 
				29
			 | 
			
				34
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				30
			 | 
			
				35
			 | 
			
			
				
				             fputcsv($file, $report->getHeaders()); 
			 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			
				
				@@ -50,15 +55,22 @@ class ExportService 
			 | 
		
		
	
		
			
			| 
				50
			 | 
			
				55
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				51
			 | 
			
				56
			 | 
			
			
				
				     public function exportToPdf(Company $company, ExportableReport $report, string $startDate, string $endDate): StreamedResponse 
			 | 
		
		
	
		
			
			| 
				52
			 | 
			
				57
			 | 
			
			
				
				     { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				
				+        $formattedStartDate = Carbon::parse($startDate)->format('Y-m-d'); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				
				+        $formattedEndDate = Carbon::parse($endDate)->format('Y-m-d'); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				
				+        $timestamp = Carbon::now()->format('Y-m-d-H_i'); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				
				+        $filename = $company->name . ' ' . $report->getTitle() . ' ' . $formattedStartDate . ' to ' . $formattedEndDate . ' ' . $timestamp . '.pdf'; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				53
			 | 
			
				65
			 | 
			
			
				
				         $pdf = Pdf::loadView('components.company.reports.report-pdf', [ 
			 | 
		
		
	
		
			
			| 
				54
			 | 
			
				66
			 | 
			
			
				
				             'company' => $company, 
			 | 
		
		
	
		
			
			| 
				55
			 | 
			
				67
			 | 
			
			
				
				             'report' => $report, 
			 | 
		
		
	
		
			
			| 
				56
			 | 
			
				68
			 | 
			
			
				
				             'startDate' => Carbon::parse($startDate)->format('M d, Y'), 
			 | 
		
		
	
		
			
			| 
				57
			 | 
			
				69
			 | 
			
			
				
				             'endDate' => Carbon::parse($endDate)->format('M d, Y'), 
			 | 
		
		
	
		
			
			| 
				58
			 | 
			
				
			 | 
			
			
				
				-        ])->setPaper('a4'); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				
				+        ])->setPaper('letter'); 
			 | 
		
		
	
		
			
			| 
				59
			 | 
			
				71
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				60
			 | 
			
				72
			 | 
			
			
				
				         return response()->streamDownload(function () use ($pdf) { 
			 | 
		
		
	
		
			
			| 
				61
			 | 
			
				73
			 | 
			
			
				
				             echo $pdf->stream(); 
			 | 
		
		
	
		
			
			| 
				62
			 | 
			
				
			 | 
			
			
				
				-        }, strtolower(str_replace(' ', '-', $company->name . '-' . $report->getTitle())) . '.pdf'); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				
				+        }, $filename); 
			 | 
		
		
	
		
			
			| 
				63
			 | 
			
				75
			 | 
			
			
				
				     } 
			 | 
		
		
	
		
			
			| 
				64
			 | 
			
				76
			 | 
			
			
				
				 } 
			 |