Преглед изворни кода

Ore viaggio e attività da completare

Roberto Santini пре 3 година
родитељ
комит
67ac4e01f9

+ 33
- 14
app/Http/Controllers/IssueController.php Прегледај датотеку

@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Log;
11 11
 use App\DataTables\IssueDataTable;
12 12
 use App\Models\Issue;
13 13
 use App\Models\User;
14
+use App\Models\Config;
14 15
 use Carbon\Carbon;
15 16
 use PDF;
16 17
 use Storage;
@@ -69,23 +70,19 @@ class IssueController extends Controller
69 70
 
70 71
     // Sede del cliente
71 72
     $sedeCliente = null;
72
-    foreach($issue->custom_fields as $custom_field){
73
-      if(str_starts_with($custom_field->name, 'Sede')){
74
-        $sedeCliente = $custom_field->value;
75
-        break;
73
+    try{
74
+      foreach($issue->custom_fields as $custom_field){
75
+        if(str_starts_with($custom_field->name, 'Sede')){
76
+          $sedeCliente = $custom_field->value;
77
+          break;
78
+        }
76 79
       }
80
+    }catch(\Exception $e){
81
+      $sedeCliente = null;
77 82
     }
78 83
 
79 84
     // Activity
80
-    $response = Http::get(session('azienda')->redmine_url.'/enumerations/time_entry_activities.json', [
81
-      'key' => $redmineUser->api_key,
82
-    ]);
83
-
84
-    $attivita = array();
85
-    foreach($response->object()->time_entry_activities as $time_entry_activities){
86
-      if(!$time_entry_activities->active) continue;
87
-      $attivita[$time_entry_activities->id] = $time_entry_activities->name;
88
-    }
85
+    $attivita = Issue::getAttivita();
89 86
 
90 87
     // issueStatus
91 88
     $issueStatus = Issue::getStati();
@@ -307,16 +304,38 @@ class IssueController extends Controller
307 304
 
308 305
     // Time entry
309 306
     foreach($tecnici as $key => $value){
307
+      // ore intervento
308
+      if($key == $redmineUser->id){
309
+        $activity_id = $request->activity_id;
310
+      }else{
311
+        $activity_id = Config::getValue(Config::ATTIVITA_TECNICO_AGGIUNTIVO);
312
+      }
313
+
310 314
       $response = Http::post("https://".$redmineUser->api_key."@".session('azienda')->redmine_url.'/time_entries.xml', [
311 315
         'time_entry' => [
312 316
           'issue_id' => $request->issue_id,
313 317
           'spent_on' => $dataIntervento->toDateString(),
314 318
           'hours' => $durata.'m',
315 319
           'comments' => $request->note,
316
-          'activity_id' => $request->activity_id,
320
+          'activity_id' => $activity_id,
317 321
           'user_id' => $key
318 322
         ]
319 323
       ]);
324
+
325
+      // Ore viaggio
326
+      if($request->has('ore_viaggio') && is_numeric($request->ore_viaggio)){
327
+        $response = Http::post("https://".$redmineUser->api_key."@".session('azienda')->redmine_url.'/time_entries.xml', [
328
+          'time_entry' => [
329
+            'issue_id' => $request->issue_id,
330
+            'spent_on' => $dataIntervento->toDateString(),
331
+            'hours' => $request->ore_viaggio,
332
+            'comments' => '',
333
+            'activity_id' => Config::getValue(Config::ATTIVITA_VIAGGIO),
334
+            'user_id' => $key
335
+          ]
336
+        ]);
337
+
338
+      }
320 339
     }
321 340
 
322 341
 

+ 6
- 0
app/Models/Config.php Прегледај датотеку

@@ -6,12 +6,18 @@ class Config extends \App\Models\AbstractModels\AbstractConfig
6 6
 {
7 7
   const STATI_SEGNALAZIONI_HOME = 'stati_segnalazioni_home';
8 8
   const TESTO_PRIVACY = 'testo_privacy';
9
+  const STATO_DA_COMPLETARE = 'stato_da_completare';
10
+  const ATTIVITA_VIAGGIO = 'attivita_viaggio';
11
+  const ATTIVITA_TECNICO_AGGIUNTIVO = 'attivita_tecnico_aggiuntivo';
9 12
 
10 13
   public static function getConfig(){
11 14
     $config = [];
12 15
     $config['Generale'] = [
13 16
       ['key' => self::STATI_SEGNALAZIONI_HOME, 'value' => null, 'display_name' => 'Stati delle segnalazioni da mostrare nella home', 'type' => 'array_status'],
17
+      ['key' => self::STATO_DA_COMPLETARE, 'value' => null, 'display_name' => 'Stato "da completare"', 'type' => 'select_status'],
14 18
       ['key' => self::TESTO_PRIVACY, 'value' => null, 'display_name' => 'Testo privacy in calce al pdf', 'type' => 'textarea'],
19
+      ['key' => self::ATTIVITA_VIAGGIO, 'value' => null, 'display_name' => 'Attività "Viaggio"', 'type' => 'activity'],
20
+      ['key' => self::ATTIVITA_TECNICO_AGGIUNTIVO, 'value' => null, 'display_name' => 'Attività "tecnico aggiuntivo"', 'type' => 'activity'],
15 21
     ];
16 22
 
17 23
 

+ 17
- 0
app/Models/Issue.php Прегледај датотеку

@@ -70,4 +70,21 @@ class Issue{
70 70
     return $issueStatus;
71 71
   }
72 72
 
73
+  public static function getAttivita(){
74
+    $redmineUser = session('redmine_user');
75
+
76
+    // Activity
77
+    $response = Http::get(session('azienda')->redmine_url.'/enumerations/time_entry_activities.json', [
78
+      'key' => $redmineUser->api_key,
79
+    ]);
80
+
81
+    $attivita = array();
82
+    foreach($response->object()->time_entry_activities as $time_entry_activities){
83
+      if(!$time_entry_activities->active) continue;
84
+      $attivita[$time_entry_activities->id] = $time_entry_activities->name;
85
+    }
86
+
87
+    return $attivita;
88
+  }
89
+
73 90
 }

+ 8
- 0
resources/views/config/index.blade.php Прегледај датотеку

@@ -68,6 +68,14 @@ thead select{
68 68
               ?>
69 69
               @break
70 70
 
71
+              @case('select_status')
72
+              {!! Form::select('value['.$config->id.']', Issue::getStati(), $config->value, ['class' => 'form-control']) !!}
73
+              @break
74
+
75
+              @case('activity')
76
+              {!! Form::select('value['.$config->id.']', Issue::getAttivita(), $config->value, ['class' => 'form-control']) !!}
77
+              @break
78
+
71 79
               @case('file')
72 80
               <div class="form-row">
73 81
                 <div class="form-group col">

+ 33
- 4
resources/views/issue/firma.blade.php Прегледај датотеку

@@ -1,5 +1,6 @@
1 1
 <?php
2 2
 use Carbon\Carbon;
3
+use App\Models\Config;
3 4
 ?>
4 5
 <style>
5 6
 [type="file"] {
@@ -41,7 +42,7 @@ use Carbon\Carbon;
41 42
     </h2>
42 43
   </x-slot>
43 44
 
44
-  {!! Form::open(['route' => 'issue.firma_rapporto', 'files' => true]) !!}
45
+  {!! Form::open(['route' => 'issue.firma_rapporto', 'files' => true, 'id' => 'form_firma']) !!}
45 46
   {!! Form::hidden('issue_id', $issue->id) !!}
46 47
 
47 48
   <div class="row justify-content-center mb-4">
@@ -62,9 +63,9 @@ use Carbon\Carbon;
62 63
               {!! Form::select('activity_id', $attivita, null, ['class' => 'form-control']) !!}
63 64
             </div>
64 65
 
65
-            <div class="form-group col-md">
66
+            <div class="form-group col-md" id="div_stato_segnalazione" style="display: none">
66 67
               {!! Form::label('status_id', 'Stato segnalazione') !!}
67
-              {!! Form::select('status_id', $issueStatus, $issue->status->id, ['class' => 'form-control']) !!}
68
+              {!! Form::select('status_id', $issueStatus, Config::getValue(Config::STATO_DA_COMPLETARE), ['class' => 'form-control']) !!}
68 69
             </div>
69 70
           </div>
70 71
 
@@ -93,6 +94,15 @@ use Carbon\Carbon;
93 94
               {!! Form::label('ora_fine', 'Fine') !!}
94 95
               {!! Form::text('ora_fine', Carbon::now()->addMinutes(15)->format('H:i'), ['class' => 'form-control']) !!}
95 96
             </div>
97
+
98
+            <div class="form-group col-md" id="div_button_ore_viaggio">
99
+              <button class="btn btn-primary" onclick="imputa_ore_viaggio()" type="button">Imputa ore viaggio</button>
100
+            </div>
101
+
102
+            <div class="form-group col-md" id="div_ore_viaggio" style="display: none">
103
+              {!! Form::label('ore_viaggio', 'Ore viaggio') !!}
104
+              {!! Form::number('ore_viaggio', null, ['class' => 'form-control', 'min' => 0, 'step' => 0,01]) !!}
105
+            </div>
96 106
           </div>
97 107
 
98 108
           <div class="form-row">
@@ -225,7 +235,7 @@ use Carbon\Carbon;
225 235
 
226 236
           <div class="form-row">
227 237
             <div class="form-group col-md">
228
-              <button type="submit" class="btn btn-primary">Salva</button>
238
+              <button type="button" onclick="submitForm()" class="btn btn-primary">Salva</button>
229 239
             </div>
230 240
           </div>
231 241
 
@@ -348,4 +358,23 @@ function file_selezionato(input){
348 358
   }
349 359
 }
350 360
 
361
+function imputa_ore_viaggio(){
362
+  $('#div_stato_segnalazione').show();
363
+  $('#div_button_ore_viaggio').hide();
364
+  $('#div_ore_viaggio').show();
365
+}
366
+
367
+function submitForm(){
368
+  // controllo se le ore del viaggio sono state imputate
369
+  if($("#div_ore_viaggio").is(":visible") && isNaN(parseInt($('#ore_viaggio').val()))){
370
+    bootbox.alert("Devi imputare le ore di viaggio!");
371
+    return;
372
+  }
373
+
374
+  if($('#signature_image_cliente').val() == ''){
375
+    bootbox.alert("Manca la firma del cliente!");
376
+    return;
377
+  }
378
+  $('#form_firma').submit();
379
+}
351 380
 </script>

Loading…
Откажи
Сачувај