Browse Source

nome report xlsx

Roberto Santini 2 years ago
parent
commit
d67d3549bd

+ 75
- 64
app/Http/Controllers/IssueController.php View File

@@ -314,84 +314,95 @@ class IssueController extends Controller
314 314
     $from = Carbon::createFromFormat('d/m/Y', $request->data_inizio)->toDateString();
315 315
     $to = Carbon::createFromFormat('d/m/Y', $request->data_fine)->toDateString();
316 316
 
317
-    foreach($request->progetto as $project_id){
318
-      $timeEntries = Http::get(config('redmine.url').'/time_entries.json', [
319
-        'key' => $redmineUser->api_key,
320
-        'from' => $from,
321
-        'to' => $to,
322
-        'project_id' => $project_id,
323
-        'limit' => 100,
324
-        'cf_'.Config::getValue(Config::CAMPO_FATTURARE) => 'Sì', // Custom fields "fatturare"
325
-      ]);
317
+    if($request->has('progetto') && count($request->progetto) > 0){
318
+      foreach($request->progetto as $project_id => $project_label){
319
+        $timeEntries = Http::get(config('redmine.url').'/time_entries.json', [
320
+          'key' => $redmineUser->api_key,
321
+          'from' => $from,
322
+          'to' => $to,
323
+          'project_id' => $project_id,
324
+          'limit' => 100,
325
+          'cf_'.Config::getValue(Config::CAMPO_FATTURARE) => 'Sì', // Custom fields "fatturare"
326
+        ]);
326 327
 
327
-      // dd($project_id);
328
+        // dd($project_id);
328 329
 
329
-      $arrayIssues = [];
330
-      foreach($timeEntries->object()->time_entries as $timeEntry){
331
-        try{
332
-          $arrayIssues[] = $timeEntry->issue->id;
333
-        }catch(\Exception $e){
330
+        $arrayIssues = [];
331
+        foreach($timeEntries->object()->time_entries as $timeEntry){
332
+          try{
333
+            $arrayIssues[] = $timeEntry->issue->id;
334
+          }catch(\Exception $e){
335
+          }
334 336
         }
335
-      }
336
-      $arrayIssues = array_unique($arrayIssues);
337
-      // dd($arrayIssues);
337
+        $arrayIssues = array_unique($arrayIssues);
338
+        // dd($arrayIssues);
339
+
340
+        foreach($arrayIssues as $issue_id){
341
+          $issueResponse = Http::get(config('redmine.url').'/issues/'.$issue_id.'.json?include=custom_fields,project', [
342
+            'key' => $redmineUser->api_key,
343
+          ]);
344
+
345
+          $issue = $issueResponse->object()->issue;
346
+          try{
347
+            foreach($issue->custom_fields as $customField){
348
+              if(substr($customField->name, 0, 4) == 'Sede'){
349
+                $sedeCliente = explode('(', $customField->value)[0];
350
+                break;
351
+              }else{
352
+                $sedeCliente = "";
353
+              }
354
+            }
355
+          }catch(\Exception $e){
356
+            $sedeCliente = "";
357
+          }
338 358
 
339
-      foreach($arrayIssues as $issue_id){
340
-        $issueResponse = Http::get(config('redmine.url').'/issues/'.$issue_id.'.json?include=custom_fields,project', [
341
-          'key' => $redmineUser->api_key,
342
-        ]);
359
+          // Tempo onsite o viaggio
360
+          $tempoImpiegatoOnSite = Issue::getTempoImpiegato($issue->id, [Config::getValue(Config::ATTIVITA_ON_SITE), Config::TECNICO_AGGIUNTIVO], $from, $to, 'Sì');
361
+          $tempoImpiegatoRemota = Issue::getTempoImpiegato($issue->id, [Config::getValue(Config::ATTIVITA_REMOTA)], $from, $to, 'Sì');
343 362
 
344
-        $issue = $issueResponse->object()->issue;
345
-        try{
346
-          foreach($issue->custom_fields as $customField){
347
-            if(substr($customField->name, 0, 4) == 'Sede'){
348
-              $sedeCliente = explode('(', $customField->value)[0];
349
-              break;
363
+          foreach($tempoImpiegatoOnSite as $tempo){
364
+            // arrotondamento tempo
365
+            $ore = $tempo->hours;
366
+            if($ore < 1){
367
+              $ore = 1;
350 368
             }else{
351
-              $sedeCliente = "";
369
+              $ore = round($ore*2)/2;
352 370
             }
353
-          }
354
-        }catch(\Exception $e){
355
-          $sedeCliente = "";
356
-        }
357 371
 
358
-        // Tempo onsite o viaggio
359
-        $tempoImpiegatoOnSite = Issue::getTempoImpiegato($issue->id, [Config::getValue(Config::ATTIVITA_ON_SITE), Config::TECNICO_AGGIUNTIVO], $from, $to, 'Sì');
360
-        $tempoImpiegatoRemota = Issue::getTempoImpiegato($issue->id, [Config::getValue(Config::ATTIVITA_REMOTA)], $from, $to, 'Sì');
361
-
362
-        foreach($tempoImpiegatoOnSite as $tempo){
363
-          // arrotondamento tempo
364
-          $ore = $tempo->hours;
365
-          if($ore < 1){
366
-            $ore = 1;
367
-          }else{
368
-            $ore = round($ore*2)/2;
372
+            $data = Carbon::parse($tempo->spent_on)->format('d/m/Y');
373
+            $collectionIssue->push([
374
+              'nome' => "Intervento Tecnico #".$issue->id." ".$issue->subject." - ".$data,
375
+              'codice' => 'INT-ORE',
376
+              'quantita' => $ore]
377
+            );
378
+            $collectionIssue->push([
379
+              'nome' => "Diritto fisso di uscita - #".$issue->id." - ".$sedeCliente." - ".$data,
380
+              'codice' => 'INT-USC',
381
+              'quantita' => 1]
382
+            );
369 383
           }
370 384
 
371
-          $data = Carbon::parse($tempo->spent_on)->format('d/m/Y');
372
-          $collectionIssue->push([
373
-            'nome' => "Intervento Tecnico #".$issue->id." ".$issue->subject." - ".$data,
374
-            'codice' => 'INT-ORE',
375
-            'quantita' => $ore]
376
-          );
377
-          $collectionIssue->push([
378
-            'nome' => "Diritto fisso di uscita - #".$issue->id." - ".$sedeCliente." - ".$data,
379
-            'codice' => 'INT-USC',
380
-            'quantita' => 1]
381
-          );
385
+          foreach($tempoImpiegatoRemota as $tempo){
386
+            $collectionIssue->push([
387
+              'nome' => "Intervento Tecnico #".$issue->id." ".$issue->subject." - ".Carbon::parse($tempo->spent_on)->format('d/m/Y'),
388
+              'codice' => 'INT-ORE',
389
+              'quantita' => $tempo->hours]
390
+            );
391
+          }
382 392
         }
383 393
 
384
-        foreach($tempoImpiegatoRemota as $tempo){
385
-          $collectionIssue->push([
386
-            'nome' => "Intervento Tecnico #".$issue->id." ".$issue->subject." - ".Carbon::parse($tempo->spent_on)->format('d/m/Y'),
387
-            'codice' => 'INT-ORE',
388
-            'quantita' => $tempo->hours]
389
-          );
390
-        }
391 394
       }
392 395
 
393
-    }
396
+      if(count($request->progetto) == 1){
397
+        $filename = $project_label;
398
+      }else{
399
+        $filename = 'issues';
400
+      }
394 401
 
395
-    return Excel::download(new IssueExport($collectionIssue), 'issue.xlsx');
402
+      return Excel::download(new IssueExport($collectionIssue), $filename.'.xlsx');
403
+    }else{
404
+      Session::flash('flash_message', "Nessun progetto selezionato!");
405
+      return redirect()->route('issue.admin_report');
406
+    }
396 407
   }
397 408
 }

+ 11
- 1
resources/views/issue/componi_admin_report.blade.php View File

@@ -50,6 +50,16 @@ foreach(range(0, $totalProjects) as $index){
50 50
       <div class="card">
51 51
         <div class="card-body">
52 52
 
53
+          @if(Session::has('flash_message'))
54
+          <div class="row justify-content-center mb-4">
55
+            <div class="col">
56
+              <div class="card alert alert-success text-center">
57
+                {{ Session::get('flash_message') }}
58
+              </div>
59
+            </div>
60
+          </div>
61
+          @endif
62
+
53 63
           <x-auth-validation-errors class="mb-4" :errors="$errors" />
54 64
 
55 65
 
@@ -81,7 +91,7 @@ foreach(range(0, $totalProjects) as $index){
81 91
       <div class="card">
82 92
         <div class="card-body">
83 93
           @foreach($collectionProject as $project)
84
-          {!! Form::checkbox('progetto[]', $project->id, false, ['class' => '']) !!} {{ $project->name }}<br>
94
+          {!! Form::checkbox('progetto['.$project->id.']', $project->name, false, ['class' => '']) !!} {{ $project->name }}<br>
85 95
           @endforeach
86 96
           </div>
87 97
           </div>

Loading…
Cancel
Save