Browse Source

bug azienda

Roberto Santini 3 years ago
parent
commit
0d3ee0af27

+ 1
- 0
app/Http/Controllers/LoginController.php View File

43
         if($user == null){
43
         if($user == null){
44
           $user = new User;
44
           $user = new User;
45
           $user->redmine_id = $redmineUser->id;
45
           $user->redmine_id = $redmineUser->id;
46
+          $user->azienda()->associate($azienda);
46
           $user->save();
47
           $user->save();
47
         }
48
         }
48
 
49
 

+ 10
- 0
app/Models/AbstractModels/AbstractAzienda.php View File

57
         'created_at',
57
         'created_at',
58
         'updated_at'
58
         'updated_at'
59
     ];
59
     ];
60
+    
61
+    public function configs()
62
+    {
63
+        return $this->hasMany('\App\Models\Config', 'azienda_id', 'id');
64
+    }
65
+    
66
+    public function users()
67
+    {
68
+        return $this->hasMany('\App\Models\User', 'azienda_id', 'id');
69
+    }
60
 }
70
 }

+ 10
- 15
app/Models/AbstractModels/AbstractConfig.php View File

17
      */
17
      */
18
     protected $table = 'config';
18
     protected $table = 'config';
19
     
19
     
20
-    /**  
21
-     * Primary key name.
22
-     * 
23
-     * @var string
24
-     */
25
-    public $primaryKey = 'key';
26
-    
27
     /**  
20
     /**  
28
      * Primary key type.
21
      * Primary key type.
29
      * 
22
      * 
30
      * @var string
23
      * @var string
31
      */
24
      */
32
-    protected $keyType = 'string';
33
-    
34
-    /**  
35
-     * Primary key is non-autoincrementing.
36
-     * 
37
-     * @var bool
38
-     */
39
-    public $incrementing = false;
25
+    protected $keyType = 'bigInteger';
40
     
26
     
41
     /**  
27
     /**  
42
      * The attributes that should be cast to native types.
28
      * The attributes that should be cast to native types.
44
      * @var array
30
      * @var array
45
      */
31
      */
46
     protected $casts = [
32
     protected $casts = [
33
+        'id' => 'integer',
34
+        'azienda_id' => 'integer',
47
         'key' => 'string',
35
         'key' => 'string',
48
         'group' => 'string',
36
         'group' => 'string',
49
         'display_name' => 'string',
37
         'display_name' => 'string',
60
      * @var array
48
      * @var array
61
      */
49
      */
62
     protected $fillable = [
50
     protected $fillable = [
51
+        'id',
52
+        'azienda_id',
63
         'key',
53
         'key',
64
         'group',
54
         'group',
65
         'display_name',
55
         'display_name',
69
         'created_at',
59
         'created_at',
70
         'updated_at'
60
         'updated_at'
71
     ];
61
     ];
62
+    
63
+    public function azienda()
64
+    {
65
+        return $this->belongsTo('\App\Models\Azienda', 'azienda_id', 'id');
66
+    }
72
 }
67
 }

+ 7
- 0
app/Models/AbstractModels/AbstractUser.php View File

32
     protected $casts = [
32
     protected $casts = [
33
         'id' => 'integer',
33
         'id' => 'integer',
34
         'redmine_id' => 'integer',
34
         'redmine_id' => 'integer',
35
+        'azienda_id' => 'integer',
35
         'firma' => 'string',
36
         'firma' => 'string',
36
         'created_at' => 'datetime',
37
         'created_at' => 'datetime',
37
         'updated_at' => 'datetime'
38
         'updated_at' => 'datetime'
45
     protected $fillable = [
46
     protected $fillable = [
46
         'id',
47
         'id',
47
         'redmine_id',
48
         'redmine_id',
49
+        'azienda_id',
48
         'firma',
50
         'firma',
49
         'created_at',
51
         'created_at',
50
         'updated_at'
52
         'updated_at'
51
     ];
53
     ];
54
+    
55
+    public function azienda()
56
+    {
57
+        return $this->belongsTo('\App\Models\Azienda', 'azienda_id', 'id');
58
+    }
52
 }
59
 }

+ 1
- 1
app/Models/Config.php View File

18
 
18
 
19
   public static function getValue($key){
19
   public static function getValue($key){
20
     try{
20
     try{
21
-      return Config::find($key)->value;
21
+      return Config::where([['key', $key], ['azienda_id', session('azienda')->id]])->first()->value;
22
     }catch(\Exception $e){
22
     }catch(\Exception $e){
23
       return 0;
23
       return 0;
24
     }
24
     }

+ 3
- 2
app/Models/Issue.php View File

8
 
8
 
9
 class Issue{
9
 class Issue{
10
 
10
 
11
-  public static function getCollection(array $status = []){
11
+  public static function getCollection($status = []){
12
     $redmineUser = session('redmine_user');
12
     $redmineUser = session('redmine_user');
13
     $collection = new Collection();
13
     $collection = new Collection();
14
 
14
 
16
     $issueResponse = Http::get(session('azienda')->redmine_url.'/issues.json', [
16
     $issueResponse = Http::get(session('azienda')->redmine_url.'/issues.json', [
17
       'key' => $redmineUser->api_key,
17
       'key' => $redmineUser->api_key,
18
       'assigned_to_id' => $redmineUser->id,
18
       'assigned_to_id' => $redmineUser->id,
19
-      'status_id' => count($status)>0?implode('|', $status):'open',
19
+      'status_id' => ($status!=null && count($status)>0)?implode('|', $status):'open',
20
       'limit' => 100,
20
       'limit' => 100,
21
     ]);
21
     ]);
22
 
22
 
40
         $issueResponse = Http::get(session('azienda')->redmine_url.'/issues.json', [
40
         $issueResponse = Http::get(session('azienda')->redmine_url.'/issues.json', [
41
           'key' => $redmineUser->api_key,
41
           'key' => $redmineUser->api_key,
42
           'assigned_to_id' => $group->id,
42
           'assigned_to_id' => $group->id,
43
+          'status_id' => ($status!=null && count($status)>0)?implode('|', $status):'open',
43
           'limit' => 100,
44
           'limit' => 100,
44
         ]);
45
         ]);
45
 
46
 

+ 0
- 42
database/migrations/2022_03_18_100151_skipper_migrations_2022031810015198.php View File

1
-<?php
2
-/* 
3
- * Migrations generated by: Skipper (http://www.skipper18.com)
4
- * Migration id: 389c4dec-5f41-4008-a12d-91fe5ebf4b24
5
- * Migration datetime: 2022-03-18 10:01:51.987239
6
- */ 
7
-
8
-use Illuminate\Support\Facades\Schema;
9
-use Illuminate\Database\Schema\Blueprint;
10
-use Illuminate\Database\Migrations\Migration;
11
-
12
-class SkipperMigrations2022031810015198 extends Migration
13
-{
14
-    /**
15
-     * Run the migrations.
16
-     *
17
-     * @return void
18
-     */
19
-    public function up()
20
-    {
21
-        Schema::create('config', function (Blueprint $table) {
22
-            $table->string('key');
23
-            $table->string('group')->nullable(true);
24
-            $table->string('display_name')->nullable(true);
25
-            $table->longText('value')->nullable(true);
26
-            $table->integer('order')->nullable(true);
27
-            $table->string('type')->nullable(true);
28
-            $table->timestamp('created_at')->nullable(true);
29
-            $table->timestamp('updated_at')->nullable(true);
30
-            $table->primary(['key']);
31
-        });
32
-    }
33
-    /**
34
-     * Reverse the migrations.
35
-     *
36
-     * @return void
37
-     */
38
-    public function down()
39
-    {
40
-        Schema::dropIfExists('config');
41
-    }
42
-}

+ 0
- 38
database/migrations/2022_03_18_104703_skipper_migrations_2022031810470316.php View File

1
-<?php
2
-/* 
3
- * Migrations generated by: Skipper (http://www.skipper18.com)
4
- * Migration id: 81cb22a4-03b7-4566-9925-9af06de59d8c
5
- * Migration datetime: 2022-03-18 10:47:03.168319
6
- */ 
7
-
8
-use Illuminate\Support\Facades\Schema;
9
-use Illuminate\Database\Schema\Blueprint;
10
-use Illuminate\Database\Migrations\Migration;
11
-
12
-class SkipperMigrations2022031810470316 extends Migration
13
-{
14
-    /**
15
-     * Run the migrations.
16
-     *
17
-     * @return void
18
-     */
19
-    public function up()
20
-    {
21
-        Schema::create('user', function (Blueprint $table) {
22
-            $table->bigInteger('id')->autoIncrement()->unsigned();
23
-            $table->integer('redmine_id')->nullable(true);
24
-            $table->text('firma')->nullable(true);
25
-            $table->timestamp('created_at')->nullable(true);
26
-            $table->timestamp('updated_at')->nullable(true);
27
-        });
28
-    }
29
-    /**
30
-     * Reverse the migrations.
31
-     *
32
-     * @return void
33
-     */
34
-    public function down()
35
-    {
36
-        Schema::dropIfExists('user');
37
-    }
38
-}

+ 0
- 36
database/migrations/2022_03_18_122155_skipper_migrations_2022031812215528.php View File

1
-<?php
2
-/* 
3
- * Migrations generated by: Skipper (http://www.skipper18.com)
4
- * Migration id: 4e7662d1-1f4b-45d7-9b1e-50073955d166
5
- * Migration datetime: 2022-03-18 12:21:55.286492
6
- */ 
7
-
8
-use Illuminate\Support\Facades\Schema;
9
-use Illuminate\Database\Schema\Blueprint;
10
-use Illuminate\Database\Migrations\Migration;
11
-
12
-class SkipperMigrations2022031812215528 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->binary('firma')->nullable(true)->after('redmine_id')->change();
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->text('firma')->nullable(true)->after('redmine_id')->change();
34
-        });
35
-    }
36
-}

+ 68
- 0
database/migrations/2022_03_18_142224_skipper_migrations_2022031814222440.php View File

1
+<?php
2
+/* 
3
+ * Migrations generated by: Skipper (http://www.skipper18.com)
4
+ * Migration id: 46c0a901-82c6-46b0-b5b2-c384b35596e4
5
+ * Migration datetime: 2022-03-18 14:22:24.400151
6
+ */ 
7
+
8
+use Illuminate\Support\Facades\Schema;
9
+use Illuminate\Database\Schema\Blueprint;
10
+use Illuminate\Database\Migrations\Migration;
11
+
12
+class SkipperMigrations2022031814222440 extends Migration
13
+{
14
+    /**
15
+     * Run the migrations.
16
+     *
17
+     * @return void
18
+     */
19
+    public function up()
20
+    {
21
+        Schema::create('config', function (Blueprint $table) {
22
+            $table->bigInteger('id')->autoIncrement()->unsigned();
23
+            $table->bigInteger('azienda_id')->nullable(true)->unsigned();
24
+            $table->string('key')->nullable(true);
25
+            $table->string('group')->nullable(true);
26
+            $table->string('display_name')->nullable(true);
27
+            $table->longText('value')->nullable(true);
28
+            $table->integer('order')->nullable(true);
29
+            $table->string('type')->nullable(true);
30
+            $table->timestamp('created_at')->nullable(true);
31
+            $table->timestamp('updated_at')->nullable(true);
32
+        });
33
+        Schema::create('user', function (Blueprint $table) {
34
+            $table->bigInteger('id')->autoIncrement()->unsigned();
35
+            $table->integer('redmine_id')->nullable(true);
36
+            $table->bigInteger('azienda_id')->nullable(true)->unsigned();
37
+            $table->binary('firma')->nullable(true);
38
+            $table->timestamp('created_at')->nullable(true);
39
+            $table->timestamp('updated_at')->nullable(true);
40
+        });
41
+        Schema::table('config', function (Blueprint $table) {
42
+            $table->foreign('azienda_id')->references('id')->on('azienda')->onDelete('cascade');
43
+        });
44
+        Schema::table('user', function (Blueprint $table) {
45
+            $table->foreign('azienda_id')->references('id')->on('azienda')->onDelete('cascade');
46
+        });
47
+    }
48
+    /**
49
+     * Reverse the migrations.
50
+     *
51
+     * @return void
52
+     */
53
+    public function down()
54
+    {
55
+        if (Schema::hasTable('user')) {
56
+            Schema::table('user', function (Blueprint $table) {
57
+                $table->dropForeign(['azienda_id']);
58
+            });
59
+        }
60
+        if (Schema::hasTable('config')) {
61
+            Schema::table('config', function (Blueprint $table) {
62
+                $table->dropForeign(['azienda_id']);
63
+            });
64
+        }
65
+        Schema::dropIfExists('user');
66
+        Schema::dropIfExists('config');
67
+    }
68
+}

+ 16
- 11
database/seeders/ConfigSeeder.php View File

4
 
4
 
5
 use Illuminate\Database\Seeder;
5
 use Illuminate\Database\Seeder;
6
 use App\Models\Config;
6
 use App\Models\Config;
7
+use App\Models\Azienda;
7
 
8
 
8
 class ConfigSeeder extends Seeder
9
 class ConfigSeeder extends Seeder
9
 {
10
 {
15
   public function run()
16
   public function run()
16
   {
17
   {
17
     // Configurazione
18
     // Configurazione
18
-    foreach(Config::getConfig() as $key => $group){
19
-      $order = 1;
20
-      foreach($group as $key2 => $c){
21
-        $config = Config::find($c['key']);
22
-        if($config == null){
23
-          $config = new Config;
24
-          $config->fill($c);
25
-          $config->order = $order;
26
-          $config->group = $key;
27
-          $config->save();
28
-          $order++;
19
+    foreach(Azienda::all() as $azienda){
20
+      foreach(Config::getConfig() as $key => $group){
21
+        $order = 1;
22
+        foreach($group as $key2 => $c){
23
+          $config = Config::where([['key', $c['key']], ['azienda_id', $azienda->id]])->first();
24
+          if($config == null){
25
+            $config = new Config;
26
+            $config->fill($c);
27
+            $config->order = $order;
28
+            $config->group = $key;
29
+            $config->key = $c['key'];
30
+            $config->azienda()->associate($azienda);
31
+            $config->save();
32
+            $order++;
33
+          }
29
         }
34
         }
30
       }
35
       }
31
     }
36
     }

+ 10
- 10
resources/views/config/index.blade.php View File

36
           @foreach(Config::groupBy('group')->pluck('group')->toarray() as $group)
36
           @foreach(Config::groupBy('group')->pluck('group')->toarray() as $group)
37
 
37
 
38
           <h2 style="margin-top: 20px;">{{ $group }}</h2>
38
           <h2 style="margin-top: 20px;">{{ $group }}</h2>
39
-          @foreach(Config::where('group', $group)->orderBy('order', 'ASC')->get() as $config)
39
+          @foreach(Config::where([['group', $group], ['azienda_id', session('azienda')->id]])->orderBy('order', 'ASC')->get() as $config)
40
 
40
 
41
           <div class="form-row">
41
           <div class="form-row">
42
             <div class="form-group col">
42
             <div class="form-group col">
43
-              {!! Form::hidden('key['.$config->key.']', $config->key) !!}
44
-              {!! Form::label('key['.$config->key.']', $config->display_name) !!}
43
+              {!! Form::hidden('key['.$config->id.']', $config->id) !!}
44
+              {!! Form::label('key['.$config->id.']', $config->display_name) !!}
45
               @switch($config->type)
45
               @switch($config->type)
46
               @case('boolean')
46
               @case('boolean')
47
               <br>
47
               <br>
48
-              {!! Form::radio('value['.$config->key.']', 1, $config->value==true, ['class' => '']) !!} SI
49
-              {!! Form::radio('value['.$config->key.']', 0, $config->value==false, ['class' => '']) !!} NO
48
+              {!! Form::radio('value['.$config->id.']', 1, $config->value==true, ['class' => '']) !!} SI
49
+              {!! Form::radio('value['.$config->id.']', 0, $config->value==false, ['class' => '']) !!} NO
50
               @break
50
               @break
51
 
51
 
52
               @case('textarea')
52
               @case('textarea')
53
               <br>
53
               <br>
54
-              {!! Form::textarea('value['.$config->key.']', $config->value, ['class' => 'form-control']) !!}
54
+              {!! Form::textarea('value['.$config->id.']', $config->value, ['class' => 'form-control']) !!}
55
               @break
55
               @break
56
 
56
 
57
               @case('password')
57
               @case('password')
58
-              {!! Form::password('value['.$config->key.']', ['class' => 'form-control']) !!}
58
+              {!! Form::password('value['.$config->id.']', ['class' => 'form-control']) !!}
59
               @break
59
               @break
60
 
60
 
61
               @case('array_status')
61
               @case('array_status')
63
               <?php
63
               <?php
64
               $checked = json_decode($config->value);
64
               $checked = json_decode($config->value);
65
               foreach(Issue::getStati() as $status_id => $status_label){
65
               foreach(Issue::getStati() as $status_id => $status_label){
66
-                echo Form::checkbox('value['.$config->key.'][]', $status_id, $checked!=null?in_array($status_id, $checked):false, [])." ".$status_label."<br>";
66
+                echo Form::checkbox('value['.$config->id.'][]', $status_id, $checked!=null?in_array($status_id, $checked):false, [])." ".$status_label."<br>";
67
               }
67
               }
68
               ?>
68
               ?>
69
               @break
69
               @break
71
               @case('file')
71
               @case('file')
72
               <div class="form-row">
72
               <div class="form-row">
73
                 <div class="form-group col">
73
                 <div class="form-group col">
74
-                  {!! Form::file('value['.$config->key.']', null, ['class' => 'form-control']) !!}
74
+                  {!! Form::file('value['.$config->id.']', null, ['class' => 'form-control']) !!}
75
                 </div>
75
                 </div>
76
                 <div class="form-group col">
76
                 <div class="form-group col">
77
                   <p>Logo attuale</p>
77
                   <p>Logo attuale</p>
85
               @break
85
               @break
86
 
86
 
87
               @default
87
               @default
88
-              {!! Form::text('value['.$config->key.']', $config->value, ['class' => 'form-control']) !!}
88
+              {!! Form::text('value['.$config->id.']', $config->value, ['class' => 'form-control']) !!}
89
               @endswitch
89
               @endswitch
90
             </div>
90
             </div>
91
           </div>
91
           </div>

Loading…
Cancel
Save