Explorar el Código

firma remota ciack 2

Roberto Santini hace 1 año
padre
commit
1324f36348

+ 53
- 1
app/Http/Controllers/IssueController.php Ver fichero

@@ -566,7 +566,9 @@ class IssueController extends Controller
566 566
 
567 567
   public function firma_remota(Request $request, $token){
568 568
     $issue = Issue::where('token', $token)->first();
569
-    if($issue == null) return;
569
+    if($issue == null){
570
+      return view('issue.error_remoto');
571
+    }
570 572
 
571 573
     return view('issue.firma_remota')->with(['issue' => json_decode($issue->campi), 'user' => $issue->user, 'token' => $issue->token]);
572 574
   }
@@ -586,4 +588,54 @@ class IssueController extends Controller
586 588
       return redirect()->route('home');
587 589
     }
588 590
   }
591
+
592
+  // public function pdf($id){
593
+  //   $redmineUser = session('redmine_user');
594
+  //   $user = User::where('redmine_id', $redmineUser->id)->first();
595
+  //   // dd($user->getFirma());
596
+  //
597
+  //   $response_issue = Http::get(session('azienda')->redmine_url.'/issues/'.$id.'.json?include=attachments,relations,custom_fields', [
598
+  //     'key' => $redmineUser->api_key,
599
+  //     'include' => 'journals'
600
+  //   ]);
601
+  //   $issue = $response_issue->object()->issue;
602
+  //
603
+  //   // return view('issue.pdf', [
604
+  //   //   'issue' => $issue,
605
+  //   //   'dataIntervento' => Carbon::now(),
606
+  //   //   'note' => null,
607
+  //   //   'firmaCliente' => null,
608
+  //   //   'materiale_utilizzato' => '',
609
+  //   //   'merce_ritirata' => '',
610
+  //   //   'merce_consegnata' => '',
611
+  //   //   'tecnici' => ['Roberto'],
612
+  //   //   'inizio' => Carbon::now(),
613
+  //   //   'fine' => Carbon::now(),
614
+  //   //   'persona_riferimento' => '',
615
+  //   //   'cliente' => '',
616
+  //   //   'user' => $user,
617
+  //   //   'sedeCliente' => '',
618
+  //   //   'durata' => ''
619
+  //   // ]);
620
+  //
621
+  //   $pdf = PDF::loadView('issue.pdf', [
622
+  //     'issue' => $issue,
623
+  //     'dataIntervento' => Carbon::now(),
624
+  //     'note' => null,
625
+  //     'firmaCliente' => null,
626
+  //     'materiale_utilizzato' => '',
627
+  //     'merce_ritirata' => '',
628
+  //     'merce_consegnata' => '',
629
+  //     'tecnici' => ['Roberto'],
630
+  //     'inizio' => Carbon::now(),
631
+  //     'fine' => Carbon::now(),
632
+  //     'persona_riferimento' => '',
633
+  //     'cliente' => '',
634
+  //     'user' => $user,
635
+  //     'sedeCliente' => '',
636
+  //     'durata' => ''
637
+  //   ]);
638
+  //
639
+  //   return $pdf->stream();
640
+  // }
589 641
 }

+ 25
- 6
app/Http/Controllers/UserController.php Ver fichero

@@ -5,7 +5,10 @@ namespace App\Http\Controllers;
5 5
 use Illuminate\Http\Request;
6 6
 use App\Models\Config;
7 7
 use App\Models\User;
8
+use App\Models\Issue;
8 9
 use Session;
10
+use Storage;
11
+use Auth;
9 12
 
10 13
 class UserController extends Controller{
11 14
 
@@ -19,7 +22,9 @@ class UserController extends Controller{
19 22
     $user = User::find($request->user_id);
20 23
 
21 24
     if($request->has('elimina_firma')){
25
+      Storage::disk('tecnici')->delete($user->path_firma);
22 26
       $user->firma = null;
27
+      $user->path_firma = null;
23 28
       $user->save();
24 29
       Session::flash('flash_message', 'Firma eliminata');
25 30
       return redirect()->route('user.profilo');
@@ -28,14 +33,11 @@ class UserController extends Controller{
28 33
     try{
29 34
       $sign_path_tecnico = 'sign_tecnico_'.time().'.png';
30 35
       $encoded_image = explode(",", $request->signature_image_tecnico)[1];
31
-      if(config('database.default') == 'mysql'){
32
-        $user->firma = base64_encode($encoded_image);
33
-      }else{
34
-        $user->firma = pg_escape_bytea($encoded_image);
35
-      }
36
+      $sign_path_padre = Storage::disk('tecnici')->put($sign_path_tecnico, base64_decode($encoded_image));
37
+      $user->path_firma = $sign_path_tecnico;
36 38
       $user->save();
37 39
     }catch(\Exception $e){
38
-      
40
+
39 41
     }
40 42
 
41 43
 
@@ -43,4 +45,21 @@ class UserController extends Controller{
43 45
     return redirect()->route('user.profilo');
44 46
   }
45 47
 
48
+  public function getFirma(Request $request){
49
+    if($request->has('token')){
50
+      $issue = Issue::where('token', $request->token)->first();
51
+      $user = $issue->user;
52
+    }else{
53
+      $redmineUser = session('redmine_user');
54
+      $user = User::where('redmine_id', $redmineUser->id)->first();
55
+    }
56
+
57
+    if(Storage::disk('tecnici')->exists($user->path_firma)){
58
+      $storagePath  = Storage::disk('tecnici')->path($user->path_firma);
59
+      return response()->file($storagePath);
60
+    }else{
61
+      return null;
62
+    }
63
+  }
64
+
46 65
 }

+ 2
- 0
app/Models/AbstractModels/AbstractUser.php Ver fichero

@@ -34,6 +34,7 @@ abstract class AbstractUser extends Model
34 34
         'redmine_id' => 'integer',
35 35
         'azienda_id' => 'integer',
36 36
         'firma' => 'string',
37
+        'path_firma' => 'string',
37 38
         'created_at' => 'datetime',
38 39
         'updated_at' => 'datetime'
39 40
     ];
@@ -48,6 +49,7 @@ abstract class AbstractUser extends Model
48 49
         'redmine_id',
49 50
         'azienda_id',
50 51
         'firma',
52
+        'path_firma',
51 53
         'created_at',
52 54
         'updated_at'
53 55
     ];

+ 2
- 0
app/Models/User.php Ver fichero

@@ -1,6 +1,8 @@
1 1
 <?php
2 2
 namespace App\Models;
3 3
 
4
+use Storage;
5
+
4 6
 class User extends \App\Models\AbstractModels\AbstractUser
5 7
 {
6 8
 }

+ 19
- 18
app/Providers/AppServiceProvider.php Ver fichero

@@ -6,23 +6,24 @@ use Illuminate\Support\ServiceProvider;
6 6
 
7 7
 class AppServiceProvider extends ServiceProvider
8 8
 {
9
-    /**
10
-     * Register any application services.
11
-     *
12
-     * @return void
13
-     */
14
-    public function register()
15
-    {
16
-        //
17
-    }
9
+  /**
10
+  * Register any application services.
11
+  *
12
+  * @return void
13
+  */
14
+  public function register()
15
+  {
16
+    //
17
+  }
18 18
 
19
-    /**
20
-     * Bootstrap any application services.
21
-     *
22
-     * @return void
23
-     */
24
-    public function boot()
25
-    {
26
-        \App\Models\Issue::observe(\App\Observers\IssueObserver::class);
27
-    }
19
+  /**
20
+  * Bootstrap any application services.
21
+  *
22
+  * @return void
23
+  */
24
+  public function boot()
25
+  {
26
+    // \URL::forceScheme('https');
27
+    \App\Models\Issue::observe(\App\Observers\IssueObserver::class);
28
+  }
28 29
 }

+ 6
- 0
config/filesystems.php Ver fichero

@@ -59,6 +59,12 @@ return [
59 59
             'url' => env('APP_URL').'/allegati',
60 60
             'visibility' => 'public',
61 61
         ],
62
+        'tecnici' => [
63
+            'driver' => 'local',
64
+            'root' => storage_path('app/tecnici'),
65
+            'url' => env('APP_URL').'/tecnici',
66
+            'visibility' => 'public',
67
+        ],
62 68
 
63 69
     ],
64 70
 

+ 36
- 0
database/migrations/2024_02_22_114416_skipper_migrations_2024022211441668.php Ver fichero

@@ -0,0 +1,36 @@
1
+<?php
2
+/* 
3
+ * Migrations generated by: Skipper (http://www.skipper18.com)
4
+ * Migration id: 0ad592d9-d55f-4836-ae7d-33fec1d7c9a2
5
+ * Migration datetime: 2024-02-22 11:44:16.684052
6
+ */ 
7
+
8
+use Illuminate\Support\Facades\Schema;
9
+use Illuminate\Database\Schema\Blueprint;
10
+use Illuminate\Database\Migrations\Migration;
11
+
12
+class SkipperMigrations2024022211441668 extends Migration
13
+{
14
+    /**
15
+     * Run the migrations.
16
+     *
17
+     * @return void
18
+     */
19
+    public function up()
20
+    {
21
+        Schema::table('user', function (Blueprint $table) {
22
+            $table->string('path_firma')->nullable(true)->after('firma');
23
+        });
24
+    }
25
+    /**
26
+     * Reverse the migrations.
27
+     *
28
+     * @return void
29
+     */
30
+    public function down()
31
+    {
32
+        Schema::table('user', function (Blueprint $table) {
33
+            $table->dropColumn('path_firma');
34
+        });
35
+    }
36
+}

+ 32
- 0
resources/views/issue/error_remoto.blade.php Ver fichero

@@ -0,0 +1,32 @@
1
+<?php
2
+use Carbon\Carbon;
3
+use App\Models\Config;
4
+?>
5
+
6
+<style>
7
+</style>
8
+
9
+<x-guest-layout>
10
+  <div class="row justify-content-center mb-4">
11
+    <div class="col-xl-6 col-lg-6 col-md px-md-3 px-2 mt-4">
12
+      <div class="card">
13
+        <div class="card-body" style="text-align: center">
14
+          Il rapportino è già stato firmato
15
+        </div>
16
+      </div>
17
+    </div>
18
+  </div>
19
+
20
+</x-app-layout>
21
+
22
+<script>
23
+$(document).ready(function(){
24
+  $.ajaxSetup({
25
+    headers: {
26
+      'X-CSRF-TOKEN': '{{csrf_token()}}'
27
+    }
28
+  });
29
+
30
+});
31
+
32
+</script>

+ 2
- 6
resources/views/issue/firma.blade.php Ver fichero

@@ -227,13 +227,9 @@ use App\Models\Config;
227 227
             <div class="form-group col-md-6">
228 228
               {!! Form::label('firma_tecnico', 'Firma tecnico') !!}
229 229
 
230
-              @if($user->firma != null)
230
+              @if($user->path_firma != null)
231 231
 
232
-              @if(config('database.default') == 'mysql')
233
-              <img src="data:image/png;base64,{!! base64_decode($user->firma) !!}" />
234
-              @else
235
-              <img src="data:image/png;base64,{!! stream_get_contents($user->firma) !!}" />
236
-              @endif
232
+              <img src="{{ route('user.getFirma') }}" />
237 233
 
238 234
               @endif
239 235
             </div>

+ 2
- 6
resources/views/issue/firma_remota.blade.php Ver fichero

@@ -228,13 +228,9 @@ use App\Models\Config;
228 228
             <div class="form-group col-md-6">
229 229
               {!! Form::label('firma_tecnico', 'Firma tecnico') !!}
230 230
 
231
-              @if($user->firma != null)
231
+              @if($user->path_firma != null)
232 232
 
233
-              @if(config('database.default') == 'mysql')
234
-              <img src="data:image/png;base64,{!! base64_decode($user->firma) !!}" />
235
-              @else
236
-              <img src="data:image/png;base64,{!! stream_get_contents($user->firma) !!}" />
237
-              @endif
233
+              <img src="{{ route('user.getFirma', ['token' => $token]) }}" />
238 234
 
239 235
               @endif
240 236
             </div>

+ 74
- 78
resources/views/issue/pdf.blade.php Ver fichero

@@ -8,7 +8,7 @@
8 8
         @if(session('azienda') != null && session('azienda')->path_logo != null)
9 9
         <img src="{{ Storage::disk('azienda')->url(session('azienda')->path_logo) }}" style="height: 100%"/>
10 10
         @else
11
-        <img src="{{ asset('assets/logo_rm.png') }}" style="height: 100%"/>
11
+        <img src="{{ public_path('assets/logo_rm.png') }}" style="height: 100%"/>
12 12
         @endif
13 13
 
14 14
       </div>
@@ -20,110 +20,106 @@
20 20
 
21 21
     <div style="width: 100%; margin-bottom: 30px">
22 22
       <!-- <div style="width: 100%">
23
-      </div> -->
24
-
25
-      <div style="height: 130px; width: 100%">
26
-        <div class="box_sx">
27
-          <h3 style="font-weight: bold;">Segnalazione n. {{ $issue->id }} </h3>
28
-          <h3 style="font-weight: bold;">Data intervento: {{ $dataIntervento->format('d/m/Y') }}</h3>
29
-        </div>
30
-        <div class="box_dx">
31
-          <h3 style="font-weight: bold;">Cliente</h3>
32
-          {{ $cliente }}
33
-          @if($persona_riferimento != null && $persona_riferimento != '')
34
-          <br>Referente cliente: {{ $persona_riferimento }}
35
-          @endif
36
-
37
-          @if($sedeCliente != null && $sedeCliente != '')
38
-          <br>Sede intervento: {{ $sedeCliente }}
39
-          @endif
40
-        </div>
41
-      </div>
23
+    </div> -->
42 24
 
43
-      <div style="width: 100%; margin-bottom: 20px;">
25
+    <div style="height: 130px; width: 100%">
26
+      <div class="box_sx">
27
+        <h3 style="font-weight: bold;">Segnalazione n. {{ $issue->id }} </h3>
28
+        <h3 style="font-weight: bold;">Data intervento: {{ $dataIntervento->format('d/m/Y') }}</h3>
29
+      </div>
30
+      <div class="box_dx">
31
+        <h3 style="font-weight: bold;">Cliente</h3>
32
+        {{ $cliente }}
33
+        @if($persona_riferimento != null && $persona_riferimento != '')
34
+        <br>Referente cliente: {{ $persona_riferimento }}
35
+        @endif
44 36
 
37
+        @if($sedeCliente != null && $sedeCliente != '')
38
+        <br>Sede intervento: {{ $sedeCliente }}
39
+        @endif
45 40
       </div>
41
+    </div>
42
+
43
+    <div style="width: 100%; margin-bottom: 20px;">
46 44
 
47
-      <div style="width: 100%; margin-top: 20px;">
48
-        <div class="divData">
49
-          Tecnici
50
-        </div>
51
-        @foreach($tecnici as $tecnico)
52
-        {{ $tecnico }}, dalle {{ $inizio->format('H:i') }} alle {{ $fine->format('H:i') }} - Ore lavorate: {{ $durata }}<br>
53
-        @endforeach
45
+    </div>
54 46
 
47
+    <div style="width: 100%; margin-top: 20px;">
48
+      <div class="divData">
49
+        Tecnici
55 50
       </div>
51
+      @foreach($tecnici as $tecnico)
52
+      {{ $tecnico }}, dalle {{ $inizio->format('H:i') }} alle {{ $fine->format('H:i') }} - Ore lavorate: {{ $durata }}<br>
53
+      @endforeach
54
+
55
+    </div>
56 56
 
57 57
 
58
-      @if($note != '' && $note != null)
59
-      <div style="width: 100%; margin-top: 20px;">
60
-        <div class="divData">
61
-          Descrizione
62
-        </div>
63
-        {!! $note !!}
58
+    @if($note != '' && $note != null)
59
+    <div style="width: 100%; margin-top: 20px;">
60
+      <div class="divData">
61
+        Descrizione
64 62
       </div>
65
-      @endif
66
-
67
-      @if($materiale_utilizzato != '' && $materiale_utilizzato != null)
68
-      <div style="width: 100%; margin-top: 20px;">
69
-        <div class="divData">
70
-          Materiale utilizzato
71
-        </div>
72
-        {!! $materiale_utilizzato !!}
63
+      {!! $note !!}
64
+    </div>
65
+    @endif
66
+
67
+    @if($materiale_utilizzato != '' && $materiale_utilizzato != null)
68
+    <div style="width: 100%; margin-top: 20px;">
69
+      <div class="divData">
70
+        Materiale utilizzato
73 71
       </div>
74
-      @endif
75
-
76
-      @if($merce_ritirata != '' && $merce_ritirata != null)
77
-      <div style="width: 100%; margin-top: 20px;">
78
-        <div class="divData">
79
-          Merce ritirata
80
-        </div>
81
-        {!! $merce_ritirata !!}
72
+      {!! $materiale_utilizzato !!}
73
+    </div>
74
+    @endif
75
+
76
+    @if($merce_ritirata != '' && $merce_ritirata != null)
77
+    <div style="width: 100%; margin-top: 20px;">
78
+      <div class="divData">
79
+        Merce ritirata
82 80
       </div>
83
-      @endif
84
-
85
-      @if($merce_consegnata != '' && $merce_consegnata != null)
86
-      <div style="width: 100%; margin-top: 20px;">
87
-        <div class="divData">
88
-          Merce consegnata
89
-        </div>
90
-        {!! $merce_consegnata !!}
81
+      {!! $merce_ritirata !!}
82
+    </div>
83
+    @endif
84
+
85
+    @if($merce_consegnata != '' && $merce_consegnata != null)
86
+    <div style="width: 100%; margin-top: 20px;">
87
+      <div class="divData">
88
+        Merce consegnata
91 89
       </div>
92
-      @endif
90
+      {!! $merce_consegnata !!}
91
+    </div>
92
+    @endif
93
+
93 94
 
94 95
 
96
+    <div style="height: 130px; width: 100%; position: fixed; left: 0; bottom: 130px;">
97
+      <div class="box_sx">
98
+        <h2>Firma tecnico</h2>
99
+        @if($user->path_firma != null)
95 100
 
96
-      <div style="height: 130px; width: 100%; position: fixed; left: 0; bottom: 130px;">
97
-        <div class="box_sx">
98
-          <h2>Firma tecnico</h2>
99
-          @if($user->firma != null)
100
-          <!-- Firma nel db -->
101
-          @if(config('database.default') == 'mysql')
102
-          <img src="data:image/png;base64,{!! base64_decode($user->firma) !!}" style="width: 80%"/>
103
-          @else
104
-          <img src="data:image/png;base64,{!! stream_get_contents($user->firma) !!}" style="width: 80%"/>
105
-          @endif
101
+        <img src="{{ storage_path('app/tecnici/'.$user->path_firma) }}" width="100%"/>
106 102
 
107
-          @endif
103
+        @endif
108 104
 
109
-        </div>
110
-        <div class="box_dx">
111
-          <h2>Firma cliente per presa visione</h2>
112
-          <img src="data:image/png;base64,{{ base64_encode($firmaCliente) }}" style="width: 80%"/>
113
-        </div>
114 105
       </div>
106
+      <div class="box_dx">
107
+        <h2>Firma cliente per presa visione</h2>
108
+        <img src="data:image/png;base64,{{ base64_encode($firmaCliente) }}" style="width: 80%"/>
109
+      </div>
110
+    </div>
115 111
 
116 112
 
117 113
 
118 114
 
119 115
 
120
-    </div>
116
+  </div>
121 117
 
122 118
 
123 119
 
124 120
 
125
-  </div>
121
+</div>
126 122
 
127
-  @include('footer_pdf')
123
+@include('footer_pdf')
128 124
 </body>
129 125
 </html>

+ 3
- 7
resources/views/user/profilo.blade.php Ver fichero

@@ -40,7 +40,7 @@ use App\Models\Issue;
40 40
 
41 41
           <div class="form-row">
42 42
             <div class="form-group col">
43
-              @if($user->firma == null)
43
+              @if($user->path_firma == null)
44 44
               {!! Form::label('', 'Nuova firma') !!}
45 45
               <canvas id="signature-pad_tecnico" class="signature-pad"></canvas>
46 46
               {!! Form::hidden('signature_image_tecnico', null, ['id' => 'signature_image_tecnico']) !!}
@@ -48,12 +48,8 @@ use App\Models\Issue;
48 48
               {!! Form::label('', 'Firma salvata', ['style' => 'display: inline']) !!}
49 49
               <button type="submit" class="btn btn-sm btn-danger" name='elimina_firma'><i class="fas fa-trash"></i>Elimina</button>
50 50
 
51
-              @if(config('database.default') == 'mysql')
52
-              <img src="data:image/png;base64,{!! base64_decode($user->firma) !!}" />
53
-              @else
54
-              <img src="data:image/png;base64,{!! stream_get_contents($user->firma) !!}" />
55
-              @endif
56
-
51
+              <img src="{{ route('user.getFirma') }}" />
52
+              
57 53
               @endif
58 54
             </div>
59 55
           </div>

+ 2
- 0
routes/web.php Ver fichero

@@ -32,6 +32,7 @@ Route::get('issue/{token}/firma_remota', [IssueController::class, 'firma_remota'
32 32
 Route::post('issue/firma_rapporto', [IssueController::class, 'firma_rapporto'])->name('issue.firma_rapporto');
33 33
 Route::get('issue/success_remoto', [IssueController::class, 'success_remoto'])->name('issue.success_remoto');
34 34
 Route::get('issue/download_allegato', [IssueController::class, 'download_allegato'])->name('issue.download_allegato');
35
+Route::get('user/getFirma', [UserController::class, 'getFirma'])->name('user.getFirma');
35 36
 
36 37
 Route::middleware(['redmine_auth'])->group(function () {
37 38
   Route::get('home', [HomeController::class, 'home'])->name('home');
@@ -39,6 +40,7 @@ Route::middleware(['redmine_auth'])->group(function () {
39 40
   Route::get('issue/show', [IssueController::class, 'show'])->name('issue.show');
40 41
   Route::get('issue/{id}/firma', [IssueController::class, 'firma'])->name('issue.firma');
41 42
   Route::get('issue/success', [IssueController::class, 'success'])->name('issue.success');
43
+  // Route::get('issue/{id}/pdf', [IssueController::class, 'pdf'])->name('issue.pdf');
42 44
 
43 45
 
44 46
   Route::resource('azienda', AziendaController::class, ['only' => ['index', 'store']]);

Loading…
Cancelar
Guardar