소스 검색

first Commit

marcofalabretti 2 달 전
커밋
3e11ae8dc1
100개의 변경된 파일11970개의 추가작업 그리고 0개의 파일을 삭제
  1. 18
    0
      .editorconfig
  2. 61
    0
      .env
  3. 65
    0
      .env.example
  4. 2
    0
      .eslintignore
  5. 24
    0
      .eslintrc.json
  6. 11
    0
      .gitattributes
  7. 47
    0
      .gitignore
  8. 2
    0
      .npmrc
  9. 127
    0
      .php-cs-fixer.php
  10. 3
    0
      .prettierignore
  11. 29
    0
      .prettierrc.json
  12. 4
    0
      .stylelintignore
  13. 133
    0
      .stylelintrc.json
  14. BIN
      Editor.zip
  15. 1079
    0
      Eventi.skipper
  16. 1569
    0
      GestioneManutenzioni.skipper
  17. 66
    0
      README.md
  18. 1
    0
      Untitled
  19. 35
    0
      app/Actions/Fortify/CreateNewUser.php
  20. 18
    0
      app/Actions/Fortify/PasswordValidationRules.php
  21. 29
    0
      app/Actions/Fortify/ResetUserPassword.php
  22. 32
    0
      app/Actions/Fortify/UpdateUserPassword.php
  23. 56
    0
      app/Actions/Fortify/UpdateUserProfileInformation.php
  24. 19
    0
      app/Actions/Jetstream/DeleteUser.php
  25. 112
    0
      app/DataTables/AllergeneDataTable.php
  26. 90
    0
      app/DataTables/AllergeneDataTableEditor.php
  27. 118
    0
      app/DataTables/AttivitaDataTable.php
  28. 102
    0
      app/DataTables/AttivitaDataTableEditor.php
  29. 119
    0
      app/DataTables/BachecaDataTable.php
  30. 96
    0
      app/DataTables/BachecaDataTableEditor.php
  31. 113
    0
      app/DataTables/ContenutoBachecaDataTable.php
  32. 150
    0
      app/DataTables/ContenutoBachecaDataTableEditor.php
  33. 136
    0
      app/DataTables/CucinaDataTable.php
  34. 96
    0
      app/DataTables/CucinaDataTableEditor.php
  35. 131
    0
      app/DataTables/DispositivoDataTable.php
  36. 126
    0
      app/DataTables/DispositivoDataTableEditor.php
  37. 131
    0
      app/DataTables/EndpointDataTable.php
  38. 165
    0
      app/DataTables/EventoDataTable.php
  39. 261
    0
      app/DataTables/EventoDataTableEditor.php
  40. 119
    0
      app/DataTables/FornitoreDataTable.php
  41. 106
    0
      app/DataTables/FornitoreDataTableEditor.php
  42. 119
    0
      app/DataTables/MetodoPagamentoDataTable.php
  43. 108
    0
      app/DataTables/MetodoPagamentoDataTableEditor.php
  44. 121
    0
      app/DataTables/MonitorDataTable.php
  45. 126
    0
      app/DataTables/MonitorDataTableEditor.php
  46. 160
    0
      app/DataTables/OrdineDataTable.php
  47. 109
    0
      app/DataTables/OrdineDataTableEditor.php
  48. 144
    0
      app/DataTables/PagamentoDataTable.php
  49. 173
    0
      app/DataTables/PiattoDataTable.php
  50. 169
    0
      app/DataTables/PiattoDataTableEditor.php
  51. 167
    0
      app/DataTables/PrenotazioneDataTable.php
  52. 110
    0
      app/DataTables/PrenotazioneDataTableEditor.php
  53. 122
    0
      app/DataTables/PrimaNotaDataTable.php
  54. 123
    0
      app/DataTables/PrintJobDataTable.php
  55. 142
    0
      app/DataTables/PuntoVenditaDataTable.php
  56. 126
    0
      app/DataTables/PuntoVenditaDataTableEditor.php
  57. 160
    0
      app/DataTables/RigaOrdineDataTable.php
  58. 132
    0
      app/DataTables/RoleDataTable.php
  59. 73
    0
      app/DataTables/RoleDataTableEditor.php
  60. 143
    0
      app/DataTables/StampanteDataTable.php
  61. 126
    0
      app/DataTables/StampanteDataTableEditor.php
  62. 126
    0
      app/DataTables/UserDataTable.php
  63. 94
    0
      app/DataTables/UserDataTableEditor.php
  64. 311
    0
      app/Helpers/Helpers.php
  65. 55
    0
      app/Http/Controllers/AllergeneController.php
  66. 72
    0
      app/Http/Controllers/Api/TokenAuthController.php
  67. 89
    0
      app/Http/Controllers/AttivitaController.php
  68. 61
    0
      app/Http/Controllers/BachecaController.php
  69. 56
    0
      app/Http/Controllers/BachecaHasContenutoController.php
  70. 31
    0
      app/Http/Controllers/BilancioController.php
  71. 312
    0
      app/Http/Controllers/CarrelloController.php
  72. 33
    0
      app/Http/Controllers/ConsultaController.php
  73. 62
    0
      app/Http/Controllers/ContenutoBachecaController.php
  74. 8
    0
      app/Http/Controllers/Controller.php
  75. 56
    0
      app/Http/Controllers/CucinaController.php
  76. 53
    0
      app/Http/Controllers/DispositivoController.php
  77. 230
    0
      app/Http/Controllers/EndpointController.php
  78. 86
    0
      app/Http/Controllers/EventoController.php
  79. 53
    0
      app/Http/Controllers/FornitoreController.php
  80. 389
    0
      app/Http/Controllers/HomePageController.php
  81. 10
    0
      app/Http/Controllers/LicenzaController.php
  82. 209
    0
      app/Http/Controllers/MappaDispositiviController.php
  83. 53
    0
      app/Http/Controllers/MetodoPagamentoController.php
  84. 57
    0
      app/Http/Controllers/MonitorController.php
  85. 60
    0
      app/Http/Controllers/OrdineController.php
  86. 63
    0
      app/Http/Controllers/PagamentoController.php
  87. 118
    0
      app/Http/Controllers/PiattoController.php
  88. 68
    0
      app/Http/Controllers/PrenotazioneController.php
  89. 59
    0
      app/Http/Controllers/PrimaNotaController.php
  90. 57
    0
      app/Http/Controllers/PrintJobController.php
  91. 170
    0
      app/Http/Controllers/PuntovenditaController.php
  92. 43
    0
      app/Http/Controllers/RigaOrdineController.php
  93. 130
    0
      app/Http/Controllers/RoleController.php
  94. 52
    0
      app/Http/Controllers/StampanteController.php
  95. 166
    0
      app/Http/Controllers/UserController.php
  96. 26
    0
      app/Http/Middleware/AttivitaMiddleware.php
  97. 85
    0
      app/Jobs/ElaboraJobStampa.php
  98. 45
    0
      app/Listeners/InviaNotificaSegnalazione.php
  99. 68
    0
      app/Models/AbstractModels/AbstractAllergene.php
  100. 0
    0
      app/Models/AbstractModels/AbstractAttivita.php

+ 18
- 0
.editorconfig 파일 보기

@@ -0,0 +1,18 @@
1
+root = true
2
+
3
+[*]
4
+charset = utf-8
5
+end_of_line = lf
6
+indent_size = 2
7
+indent_style = space
8
+insert_final_newline = true
9
+trim_trailing_whitespace = true
10
+
11
+[*.md]
12
+trim_trailing_whitespace = false
13
+
14
+[*.{yml,yaml}]
15
+indent_size = 2
16
+
17
+[docker-compose.yml]
18
+indent_size = 4

+ 61
- 0
.env 파일 보기

@@ -0,0 +1,61 @@
1
+APP_NAME="SegrestaFest"
2
+APP_ENV=local
3
+APP_KEY=base64:LpyZj196ZCEQkXhkaTSZ4Dy1uIjO/KhcXBJ4cGUrYg4=
4
+APP_DEBUG=true
5
+APP_URL=http://fest.test
6
+#APP_URL=http://localhost:8000
7
+APP_LOCALE=it
8
+
9
+# REDMINE_URL=assistenza.elephantech.it
10
+# REDMINE_USER=segresta
11
+# REDMINE_PWD=8Z9qDUNnKQm8NVy
12
+# REDMINE_PROJECT=15
13
+
14
+LOG_CHANNEL=daily
15
+LOG_LEVEL=debug
16
+
17
+DB_CONNECTION=mysql
18
+DB_HOST=localhost
19
+DB_PORT=3306
20
+DB_DATABASE=segresta_fest
21
+DB_USERNAME=root
22
+DB_PASSWORD=
23
+
24
+ADMIN_PASSWORD=fest2026
25
+
26
+
27
+BROADCAST_DRIVER=log
28
+CACHE_DRIVER=redis
29
+QUEUE_CONNECTION=redis
30
+SESSION_DRIVER=file
31
+SESSION_LIFETIME=120
32
+
33
+MEMCACHED_HOST=127.0.0.1
34
+
35
+REDIS_URL=localhost
36
+REDIS_HOST=localhost
37
+REDIS_PASSWORD=
38
+REDIS_PORT=6379
39
+REDIS_CLIENT=predis
40
+REDIS_DB=0
41
+
42
+# MAIL_MAILER=smtp
43
+# MAIL_HOST=vsmtp.segresta.it
44
+# MAIL_PORT=465
45
+# MAIL_USERNAME=futuranetwork@vsmtp.segresta.it
46
+# MAIL_PASSWORD=bdF01sEzPOHNYyKgX
47
+# MAIL_ENCRYPTION=ssl
48
+# MAIL_FROM_ADDRESS=futuranetwork@vsmtp.segresta.it
49
+# MAIL_FROM_NAME="Futura"
50
+# MAIL_REPLY_TO=info@elephantech.it
51
+
52
+# GOOGLE_CLIENT_ID=222725687752-rdues2edc7rabretqhv605olg8rmre2v.apps.googleusercontent.com
53
+# GOOGLE_CLIENT_SECRET=X6JdT4TAWHhSM8sPUU49wLUr
54
+# GOOGLE_REDIRECT=/auth/google/callback
55
+
56
+# FACEBOOK_APP_ID=573215073574741
57
+# FACEBOOK_APP_SECRET=008679dea9d7b630780b53413aca90d3
58
+# FACEBOOK_REDIRECT=/auth/facebook/callback
59
+
60
+# PAYPAL_MODE=sandbox
61
+# PAYPAL_CURRENCY=CHF

+ 65
- 0
.env.example 파일 보기

@@ -0,0 +1,65 @@
1
+APP_NAME=Laravel
2
+APP_ENV=local
3
+APP_KEY=
4
+APP_DEBUG=true
5
+APP_URL=http://localhost
6
+
7
+APP_LOCALE=en
8
+APP_FALLBACK_LOCALE=en
9
+APP_FAKER_LOCALE=en_US
10
+
11
+APP_MAINTENANCE_DRIVER=file
12
+# APP_MAINTENANCE_STORE=database
13
+
14
+PHP_CLI_SERVER_WORKERS=4
15
+
16
+BCRYPT_ROUNDS=12
17
+
18
+LOG_CHANNEL=stack
19
+LOG_STACK=single
20
+LOG_DEPRECATIONS_CHANNEL=null
21
+LOG_LEVEL=debug
22
+
23
+DB_CONNECTION=sqlite
24
+# DB_HOST=127.0.0.1
25
+# DB_PORT=3306
26
+# DB_DATABASE=laravel
27
+# DB_USERNAME=root
28
+# DB_PASSWORD=
29
+
30
+SESSION_DRIVER=database
31
+SESSION_LIFETIME=120
32
+SESSION_ENCRYPT=false
33
+SESSION_PATH=/
34
+SESSION_DOMAIN=null
35
+
36
+BROADCAST_CONNECTION=log
37
+FILESYSTEM_DISK=local
38
+QUEUE_CONNECTION=database
39
+
40
+CACHE_STORE=database
41
+# CACHE_PREFIX=
42
+
43
+MEMCACHED_HOST=127.0.0.1
44
+
45
+REDIS_CLIENT=phpredis
46
+REDIS_HOST=127.0.0.1
47
+REDIS_PASSWORD=null
48
+REDIS_PORT=6379
49
+
50
+MAIL_MAILER=log
51
+MAIL_SCHEME=null
52
+MAIL_HOST=127.0.0.1
53
+MAIL_PORT=2525
54
+MAIL_USERNAME=null
55
+MAIL_PASSWORD=null
56
+MAIL_FROM_ADDRESS="hello@example.com"
57
+MAIL_FROM_NAME="${APP_NAME}"
58
+
59
+AWS_ACCESS_KEY_ID=
60
+AWS_SECRET_ACCESS_KEY=
61
+AWS_DEFAULT_REGION=us-east-1
62
+AWS_BUCKET=
63
+AWS_USE_PATH_STYLE_ENDPOINT=false
64
+
65
+VITE_APP_NAME="${APP_NAME}"

+ 2
- 0
.eslintignore 파일 보기

@@ -0,0 +1,2 @@
1
+**/*.*
2
+!resources/assets/vendor/js/*.js

+ 24
- 0
.eslintrc.json 파일 보기

@@ -0,0 +1,24 @@
1
+{
2
+  "env": {
3
+    "browser": true,
4
+    "commonjs": true,
5
+    "es6": true,
6
+    "jquery": true
7
+  },
8
+  "plugins": ["prettier"],
9
+  "extends": ["airbnb-base", "plugin:prettier/recommended"],
10
+  "rules": {
11
+    "prettier/prettier": "error",
12
+    "no-underscore-dangle": "off",
13
+    "semi": ["error", "never"],
14
+    "arrow-parens": ["error", "as-needed"],
15
+    "no-param-reassign": "off",
16
+    "no-plusplus": [
17
+      "error",
18
+      {
19
+        "allowForLoopAfterthoughts": true
20
+      }
21
+    ],
22
+    "no-cond-assign": ["error", "except-parens"]
23
+  }
24
+}

+ 11
- 0
.gitattributes 파일 보기

@@ -0,0 +1,11 @@
1
+* text=auto eol=lf
2
+
3
+*.blade.php diff=html
4
+*.css diff=css
5
+*.html diff=html
6
+*.md diff=markdown
7
+*.php diff=php
8
+
9
+/.github export-ignore
10
+CHANGELOG.md export-ignore
11
+.styleci.yml export-ignore

+ 47
- 0
.gitignore 파일 보기

@@ -0,0 +1,47 @@
1
+/.phpunit.cache
2
+/node_modules
3
+/public/build
4
+/public/hot
5
+/public/storage
6
+/storage/*.key
7
+/storage/pail
8
+/vendor
9
+
10
+# .env
11
+.env.backup
12
+.env.production
13
+.phpactor.json
14
+.phpunit.result.cache
15
+
16
+docker-compose.override.yml
17
+
18
+Homestead.json
19
+Homestead.yaml
20
+npm-debug.log
21
+yarn-error.log
22
+/auth.json
23
+/.fleet
24
+/.idea
25
+/.nova
26
+/.vscode
27
+/.zed
28
+
29
+!/public/assets
30
+!/public/assets/*
31
+/resources/assets/vendor/fonts/flags/**
32
+/resources/assets/vendor/fonts/fontawesome/**
33
+/public/css
34
+/public/js
35
+/public/mix-manifest.json
36
+# /public/assets/*
37
+# But not these files...
38
+# !/public/assets/json
39
+# /public/assets/json/*
40
+# !/public/assets/json/search-vertical.json
41
+# !/public/assets/json/search-horizontal.json
42
+
43
+/resources/assets/vendor/fonts/flags/**
44
+/resources/assets/vendor/fonts/fontawesome/**
45
+
46
+# Except for 'template-customizer.js' inside 'resources/assets/vendor/js/'
47
+!/resources/assets/vendor/js/template-customizer.js

+ 2
- 0
.npmrc 파일 보기

@@ -0,0 +1,2 @@
1
+@datatables.net:registry=https://npm.datatables.net/
2
+//npm.datatables.net/:_authToken=45B0E017CC327B09B34FD9FFAA8400AA0251AE9B13A2ED66F1AE5FA27978438F

+ 127
- 0
.php-cs-fixer.php 파일 보기

@@ -0,0 +1,127 @@
1
+<?php
2
+return (new PhpCsFixer\Config())
3
+    ->setRules(
4
+    [
5
+    'array_syntax' => ['syntax' => 'short'],
6
+    'binary_operator_spaces' => [
7
+        'default' => 'single_space',
8
+        'operators' => ['=>' => null],
9
+    ],
10
+    'blank_line_after_namespace' => true,
11
+    'blank_line_after_opening_tag' => true,
12
+    'blank_line_before_statement' => [
13
+        'statements' => ['return'],
14
+    ],
15
+    'cast_spaces' => true,
16
+    'class_attributes_separation' => [
17
+        'elements' =>['const' => 'one', 'method' => 'one', 'property' => 'one', 'trait_import' => 'none', 'case' => 'none']
18
+    ],
19
+    'class_definition' => true,
20
+    'concat_space' => [
21
+        'spacing' => 'one',
22
+    ],
23
+    'declare_equal_normalize' => true,
24
+    'elseif' => true,
25
+    'encoding' => true,
26
+    'full_opening_tag' => true,
27
+    'fully_qualified_strict_types' => true,
28
+    'function_declaration' => true,
29
+    'type_declaration_spaces' => true,
30
+    'heredoc_to_nowdoc' => true,
31
+    'include' => true,
32
+    'increment_style' => ['style' => 'post'],
33
+    'indentation_type' => true,
34
+    'linebreak_after_opening_tag' => true,
35
+    'line_ending' => true,
36
+    'lowercase_cast' => true,
37
+    'constant_case' => true,
38
+    'lowercase_keywords' => true,
39
+    'lowercase_static_reference' => true,
40
+    'magic_method_casing' => true,
41
+    'magic_constant_casing' => true,
42
+    'method_argument_space' => true,
43
+    'native_function_casing' => true,
44
+    'no_alias_functions' => true,
45
+    'no_blank_lines_after_class_opening' => true,
46
+    'no_blank_lines_after_phpdoc' => true,
47
+    'no_closing_tag' => true,
48
+    'no_empty_phpdoc' => true,
49
+    'no_empty_statement' => true,
50
+    'no_leading_import_slash' => true,
51
+    'no_leading_namespace_whitespace' => true,
52
+    'no_mixed_echo_print' => [
53
+        'use' => 'echo',
54
+    ],
55
+    'no_multiline_whitespace_around_double_arrow' => true,
56
+    'multiline_whitespace_before_semicolons' => [
57
+        'strategy' => 'no_multi_line',
58
+    ],
59
+    'no_short_bool_cast' => true,
60
+    'no_singleline_whitespace_before_semicolons' => true,
61
+    'no_spaces_after_function_name' => true,
62
+    'no_spaces_around_offset' => true,
63
+    'spaces_inside_parentheses' => true,
64
+    'no_trailing_comma_in_singleline' => true,
65
+    'no_trailing_whitespace' => true,
66
+    'no_trailing_whitespace_in_comment' => true,
67
+    'no_unneeded_control_parentheses' => true,
68
+    'no_unreachable_default_argument_value' => true,
69
+    'no_useless_return' => true,
70
+    'no_whitespace_before_comma_in_array' => true,
71
+    'no_whitespace_in_blank_line' => true,
72
+    'normalize_index_brace' => true,
73
+    'not_operator_with_successor_space' => false,
74
+    'object_operator_without_whitespace' => true,
75
+    'ordered_imports' => ['sort_algorithm' => 'alpha'],
76
+    'phpdoc_indent' => true,
77
+    'general_phpdoc_tag_rename' => true,
78
+    'phpdoc_inline_tag_normalizer' => true,
79
+    'phpdoc_tag_type' => true,
80
+    'phpdoc_no_access' => true,
81
+    'phpdoc_no_package' => true,
82
+    'phpdoc_no_useless_inheritdoc' => true,
83
+    'phpdoc_scalar' => true,
84
+    'phpdoc_single_line_var_spacing' => true,
85
+    'phpdoc_summary' => true,
86
+    'phpdoc_to_comment' => true,
87
+    'phpdoc_trim' => true,
88
+    'phpdoc_types' => true,
89
+    'phpdoc_var_without_name' => true,
90
+    'psr_autoloading' => true,
91
+    'self_accessor' => true,
92
+    'short_scalar_cast' => true,
93
+    'simplified_null_return' => false,
94
+    'single_blank_line_at_eof' => true,
95
+    'blank_lines_before_namespace' => true,
96
+    'single_class_element_per_statement' => true,
97
+    'single_import_per_statement' => true,
98
+    'single_line_after_imports' => true,
99
+    'single_line_comment_style' => [
100
+        'comment_types' => ['hash'],
101
+    ],
102
+    'space_after_semicolon' => true,
103
+    'standardize_not_equals' => true,
104
+    'switch_case_semicolon_to_colon' => true,
105
+    'switch_case_space' => true,
106
+    'ternary_operator_spaces' => true,
107
+    'trailing_comma_in_multiline' => true,
108
+    'trim_array_spaces' => true,
109
+    'unary_operator_spaces' => true,
110
+    'visibility_required' => [
111
+        'elements' => ['method', 'property'],
112
+    ],
113
+    'whitespace_after_comma_in_array' => true,
114
+    'no_unused_imports' => true,
115
+])
116
+    ->setFinder(
117
+        PhpCsFixer\Finder::create()
118
+            ->name('*.php')
119
+    ->notName('*.blade.php')
120
+    ->ignoreDotFiles(true)
121
+    ->ignoreVCS(true)
122
+            ->exclude('vendor')
123
+            ->exclude('node_modules')
124
+            ->exclude('storage')
125
+            ->exclude('bootstrap/cache')
126
+            ->exclude('.git')
127
+    );

+ 3
- 0
.prettierignore 파일 보기

@@ -0,0 +1,3 @@
1
+dist
2
+node_modules
3
+build

+ 29
- 0
.prettierrc.json 파일 보기

@@ -0,0 +1,29 @@
1
+{
2
+  "arrowParens": "avoid",
3
+  "bracketSpacing": true,
4
+  "bracketSameLine": true,
5
+  "htmlWhitespaceSensitivity": "css",
6
+  "insertPragma": false,
7
+  "jsxSingleQuote": true,
8
+  "printWidth": 120,
9
+  "proseWrap": "preserve",
10
+  "quoteProps": "as-needed",
11
+  "requirePragma": false,
12
+  "semi": true,
13
+  "singleQuote": true,
14
+  "tabWidth": 2,
15
+  "trailingComma": "none",
16
+  "useTabs": false,
17
+  "endOfLine": "lf",
18
+  "embeddedLanguageFormatting": "auto",
19
+  "overrides": [
20
+    {
21
+      "files": [
22
+        "resources/assets/vendor/js/*.js"
23
+      ],
24
+      "options": {
25
+        "semi": false
26
+      }
27
+    }
28
+  ]
29
+}

+ 4
- 0
.stylelintignore 파일 보기

@@ -0,0 +1,4 @@
1
+dist
2
+node_modules
3
+build
4
+_temp/

+ 133
- 0
.stylelintrc.json 파일 보기

@@ -0,0 +1,133 @@
1
+{
2
+  "extends": [
3
+    "stylelint-config-standard-scss",
4
+    "stylelint-config-idiomatic-order",
5
+    "@stylistic/stylelint-config"
6
+  ],
7
+  "plugins": [
8
+    "stylelint-use-logical-spec",
9
+    "@stylistic/stylelint-plugin"
10
+  ],
11
+  "rules": {
12
+    "alpha-value-notation": null,
13
+    "at-rule-empty-line-before": null,
14
+    "block-no-empty": null,
15
+    "color-function-notation": null,
16
+    "color-named": "never",
17
+    "custom-property-empty-line-before": null,
18
+    "custom-property-pattern": null,
19
+    "declaration-block-no-redundant-longhand-properties": null,
20
+    "declaration-empty-line-before": null,
21
+    "declaration-no-important": null,
22
+    "font-family-no-missing-generic-family-keyword": [
23
+      true,
24
+      {
25
+        "ignoreFontFamilies": [
26
+          "boxicons",
27
+          "tabler-icons",
28
+          "remix-icons"
29
+        ]
30
+      }
31
+    ],
32
+    "font-weight-notation": [
33
+      "numeric",
34
+      {
35
+        "ignore": [
36
+          "relative"
37
+        ]
38
+      }
39
+    ],
40
+    "function-url-no-scheme-relative": true,
41
+    "liberty/use-logical-spec": true,
42
+    "media-feature-range-notation": null,
43
+    "media-query-no-invalid": null,
44
+    "no-descending-specificity": null,
45
+    "no-invalid-double-slash-comments": true,
46
+    "no-invalid-position-at-import-rule": null,
47
+    "number-max-precision": null,
48
+    "rule-empty-line-before": null,
49
+    "selector-class-pattern": null,
50
+    "selector-id-pattern": null,
51
+    "selector-max-attribute": 2,
52
+    "selector-max-id": 1,
53
+    "selector-max-specificity": null,
54
+    "selector-not-notation": null,
55
+    "scss/at-extend-no-missing-placeholder": null,
56
+    "scss/at-function-named-arguments": "never",
57
+    "scss/at-if-closing-brace-newline-after": null,
58
+    "scss/at-if-closing-brace-space-after": null,
59
+    "scss/at-if-no-null": null,
60
+    "scss/at-mixin-pattern": null,
61
+    "scss/at-mixin-argumentless-call-parentheses": "always",
62
+    "scss/at-rule-conditional-no-parentheses": null,
63
+    "scss/comment-no-empty": null,
64
+    "scss/dimension-no-non-numeric-values": true,
65
+    "scss/dollar-variable-empty-line-before": null,
66
+    "scss/dollar-variable-pattern": null,
67
+    "scss/double-slash-comment-empty-line-before": null,
68
+    "scss/double-slash-comment-whitespace-inside": null,
69
+    "scss/function-quote-no-quoted-strings-inside": null,
70
+    "scss/media-feature-value-dollar-variable": null,
71
+    "scss/no-global-function-names": null,
72
+    "@stylistic/at-rule-name-space-after": "always",
73
+    "@stylistic/at-rule-semicolon-space-before": "never",
74
+    "@stylistic/block-closing-brace-empty-line-before": null,
75
+    "@stylistic/block-closing-brace-newline-after": [
76
+      "always",
77
+      {
78
+        "ignoreAtRules": [
79
+          "if",
80
+          "else"
81
+        ]
82
+      }
83
+    ],
84
+    "@stylistic/block-opening-brace-space-before": null,
85
+    "@stylistic/declaration-block-semicolon-newline-before": "never-multi-line",
86
+    "@stylistic/indentation": 2,
87
+    "@stylistic/max-empty-lines": 2,
88
+    "@stylistic/max-line-length": [
89
+      220,
90
+      {
91
+        "ignore": "comments"
92
+      }
93
+    ],
94
+    "@stylistic/no-eol-whitespace": true,
95
+    "@stylistic/number-leading-zero": "never",
96
+    "@stylistic/selector-list-comma-newline-before": "never-multi-line",
97
+    "@stylistic/selector-list-comma-space-after": "always-single-line",
98
+    "@stylistic/selector-list-comma-space-before": "never-single-line",
99
+    "@stylistic/unicode-bom": "never"
100
+  },
101
+  "overrides": [
102
+    {
103
+      "files": [
104
+        "**/_bootstrap-extended/**/*.scss"
105
+      ],
106
+      "rules": {
107
+        "declaration-property-value-disallowed-list": {
108
+          "border": "none",
109
+          "outline": "none"
110
+        },
111
+        "function-disallowed-list": [
112
+          "lighten",
113
+          "darken"
114
+        ],
115
+        "property-disallowed-list": [
116
+          "border-radius",
117
+          "border-top-left-radius",
118
+          "border-top-right-radius",
119
+          "border-bottom-right-radius",
120
+          "border-bottom-left-radius",
121
+          "transition"
122
+        ],
123
+        "scss/dollar-variable-default": [
124
+          true,
125
+          {
126
+            "ignore": "local"
127
+          }
128
+        ],
129
+        "scss/selector-no-union-class-name": true
130
+      }
131
+    }
132
+  ]
133
+}

BIN
Editor.zip 파일 보기


+ 1079
- 0
Eventi.skipper
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 1569
- 0
GestioneManutenzioni.skipper
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 66
- 0
README.md 파일 보기

@@ -0,0 +1,66 @@
1
+<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
2
+
3
+<p align="center">
4
+<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
5
+<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
6
+<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
7
+<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
8
+</p>
9
+
10
+## About Laravel
11
+
12
+Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
13
+
14
+- [Simple, fast routing engine](https://laravel.com/docs/routing).
15
+- [Powerful dependency injection container](https://laravel.com/docs/container).
16
+- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
17
+- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
18
+- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
19
+- [Robust background job processing](https://laravel.com/docs/queues).
20
+- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
21
+
22
+Laravel is accessible, powerful, and provides tools required for large, robust applications.
23
+
24
+## Learning Laravel
25
+
26
+Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
27
+
28
+You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
29
+
30
+If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
31
+
32
+## Laravel Sponsors
33
+
34
+We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
35
+
36
+### Premium Partners
37
+
38
+- **[Vehikl](https://vehikl.com/)**
39
+- **[Tighten Co.](https://tighten.co)**
40
+- **[WebReinvent](https://webreinvent.com/)**
41
+- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
42
+- **[64 Robots](https://64robots.com)**
43
+- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
44
+- **[Cyber-Duck](https://cyber-duck.co.uk)**
45
+- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
46
+- **[Jump24](https://jump24.co.uk)**
47
+- **[Redberry](https://redberry.international/laravel/)**
48
+- **[Active Logic](https://activelogic.com)**
49
+- **[byte5](https://byte5.de)**
50
+- **[OP.GG](https://op.gg)**
51
+
52
+## Contributing
53
+
54
+Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
55
+
56
+## Code of Conduct
57
+
58
+In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
59
+
60
+## Security Vulnerabilities
61
+
62
+If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
63
+
64
+## License
65
+
66
+The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

+ 1
- 0
Untitled 파일 보기

@@ -0,0 +1 @@
1
+REDIS_CLIENT

+ 35
- 0
app/Actions/Fortify/CreateNewUser.php 파일 보기

@@ -0,0 +1,35 @@
1
+<?php
2
+
3
+namespace App\Actions\Fortify;
4
+
5
+use App\Models\User;
6
+use Illuminate\Support\Facades\Hash;
7
+use Illuminate\Support\Facades\Validator;
8
+use Laravel\Fortify\Contracts\CreatesNewUsers;
9
+use Laravel\Jetstream\Jetstream;
10
+
11
+class CreateNewUser implements CreatesNewUsers
12
+{
13
+    use PasswordValidationRules;
14
+
15
+    /**
16
+     * Validate and create a newly registered user.
17
+     *
18
+     * @param  array<string, string>  $input
19
+     */
20
+    public function create(array $input): User
21
+    {
22
+        Validator::make($input, [
23
+            'name' => ['required', 'string', 'max:255'],
24
+            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
25
+            'password' => $this->passwordRules(),
26
+            'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
27
+        ])->validate();
28
+
29
+        return User::create([
30
+            'name' => $input['name'],
31
+            'email' => $input['email'],
32
+            'password' => Hash::make($input['password']),
33
+        ]);
34
+    }
35
+}

+ 18
- 0
app/Actions/Fortify/PasswordValidationRules.php 파일 보기

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace App\Actions\Fortify;
4
+
5
+use Illuminate\Validation\Rules\Password;
6
+
7
+trait PasswordValidationRules
8
+{
9
+    /**
10
+     * Get the validation rules used to validate passwords.
11
+     *
12
+     * @return array<int, \Illuminate\Contracts\Validation\Rule|array<mixed>|string>
13
+     */
14
+    protected function passwordRules(): array
15
+    {
16
+        return ['required', 'string', Password::default(), 'confirmed'];
17
+    }
18
+}

+ 29
- 0
app/Actions/Fortify/ResetUserPassword.php 파일 보기

@@ -0,0 +1,29 @@
1
+<?php
2
+
3
+namespace App\Actions\Fortify;
4
+
5
+use App\Models\User;
6
+use Illuminate\Support\Facades\Hash;
7
+use Illuminate\Support\Facades\Validator;
8
+use Laravel\Fortify\Contracts\ResetsUserPasswords;
9
+
10
+class ResetUserPassword implements ResetsUserPasswords
11
+{
12
+    use PasswordValidationRules;
13
+
14
+    /**
15
+     * Validate and reset the user's forgotten password.
16
+     *
17
+     * @param  array<string, string>  $input
18
+     */
19
+    public function reset(User $user, array $input): void
20
+    {
21
+        Validator::make($input, [
22
+            'password' => $this->passwordRules(),
23
+        ])->validate();
24
+
25
+        $user->forceFill([
26
+            'password' => Hash::make($input['password']),
27
+        ])->save();
28
+    }
29
+}

+ 32
- 0
app/Actions/Fortify/UpdateUserPassword.php 파일 보기

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+namespace App\Actions\Fortify;
4
+
5
+use App\Models\User;
6
+use Illuminate\Support\Facades\Hash;
7
+use Illuminate\Support\Facades\Validator;
8
+use Laravel\Fortify\Contracts\UpdatesUserPasswords;
9
+
10
+class UpdateUserPassword implements UpdatesUserPasswords
11
+{
12
+    use PasswordValidationRules;
13
+
14
+    /**
15
+     * Validate and update the user's password.
16
+     *
17
+     * @param  array<string, string>  $input
18
+     */
19
+    public function update(User $user, array $input): void
20
+    {
21
+        Validator::make($input, [
22
+            'current_password' => ['required', 'string', 'current_password:web'],
23
+            'password' => $this->passwordRules(),
24
+        ], [
25
+            'current_password.current_password' => __('The provided password does not match your current password.'),
26
+        ])->validateWithBag('updatePassword');
27
+
28
+        $user->forceFill([
29
+            'password' => Hash::make($input['password']),
30
+        ])->save();
31
+    }
32
+}

+ 56
- 0
app/Actions/Fortify/UpdateUserProfileInformation.php 파일 보기

@@ -0,0 +1,56 @@
1
+<?php
2
+
3
+namespace App\Actions\Fortify;
4
+
5
+use App\Models\User;
6
+use Illuminate\Contracts\Auth\MustVerifyEmail;
7
+use Illuminate\Support\Facades\Validator;
8
+use Illuminate\Validation\Rule;
9
+use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
10
+
11
+class UpdateUserProfileInformation implements UpdatesUserProfileInformation
12
+{
13
+    /**
14
+     * Validate and update the given user's profile information.
15
+     *
16
+     * @param  array<string, mixed>  $input
17
+     */
18
+    public function update(User $user, array $input): void
19
+    {
20
+        Validator::make($input, [
21
+            'name' => ['required', 'string', 'max:255'],
22
+            'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
23
+            'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
24
+        ])->validateWithBag('updateProfileInformation');
25
+
26
+        if (isset($input['photo'])) {
27
+            $user->updateProfilePhoto($input['photo']);
28
+        }
29
+
30
+        if ($input['email'] !== $user->email &&
31
+            $user instanceof MustVerifyEmail) {
32
+            $this->updateVerifiedUser($user, $input);
33
+        } else {
34
+            $user->forceFill([
35
+                'name' => $input['name'],
36
+                'email' => $input['email'],
37
+            ])->save();
38
+        }
39
+    }
40
+
41
+    /**
42
+     * Update the given verified user's profile information.
43
+     *
44
+     * @param  array<string, string>  $input
45
+     */
46
+    protected function updateVerifiedUser(User $user, array $input): void
47
+    {
48
+        $user->forceFill([
49
+            'name' => $input['name'],
50
+            'email' => $input['email'],
51
+            'email_verified_at' => null,
52
+        ])->save();
53
+
54
+        $user->sendEmailVerificationNotification();
55
+    }
56
+}

+ 19
- 0
app/Actions/Jetstream/DeleteUser.php 파일 보기

@@ -0,0 +1,19 @@
1
+<?php
2
+
3
+namespace App\Actions\Jetstream;
4
+
5
+use App\Models\User;
6
+use Laravel\Jetstream\Contracts\DeletesUsers;
7
+
8
+class DeleteUser implements DeletesUsers
9
+{
10
+    /**
11
+     * Delete the given user.
12
+     */
13
+    public function delete(User $user): void
14
+    {
15
+        $user->deleteProfilePhoto();
16
+        $user->tokens->each->delete();
17
+        $user->delete();
18
+    }
19
+}

+ 112
- 0
app/DataTables/AllergeneDataTable.php 파일 보기

@@ -0,0 +1,112 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Allergene;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+
16
+class AllergeneDataTable extends DataTable
17
+{
18
+    public function __construct(){
19
+        $this->dataTableVariable = 'dataTable_allergene';
20
+    }
21
+    /**
22
+     * Build the DataTable class.
23
+     *
24
+     * @param QueryBuilder<Allergene> $query Results from query() method.
25
+     */
26
+    public function dataTable(QueryBuilder $query): EloquentDataTable
27
+    {
28
+        return (new EloquentDataTable($query))
29
+            ->addColumn('action', function($entity){
30
+                return view('allergene.menu', ['entity' => $entity]);
31
+            })
32
+            ->addColumn('disponibile_display', function($entity){
33
+                return view('_partials.available', ['available' => $entity->disponibile]);
34
+            })
35
+            // ->addColumn('icona_display', function($entity){
36
+            //     return view('allergene._partials.icone', ['allergeni' => [$entity->nome]]);
37
+            // })
38
+            ->setRowId('id');
39
+    }
40
+
41
+    /**
42
+     * Get the query source of dataTable.
43
+     *
44
+     * @return QueryBuilder<Allergene>
45
+     */
46
+    public function query(Allergene $model): QueryBuilder
47
+    {
48
+        return $model->newQuery();
49
+    }
50
+
51
+    /**
52
+     * Optional method if you want to use the html builder.
53
+     */
54
+    public function html(): HtmlBuilder
55
+    {
56
+        $buttons = [];
57
+        if(Auth::user()->can('create-allergene')){
58
+            array_push($buttons, Button::make('create')
59
+            ->editor('editor')
60
+            ->formTitle('Crea nuovo allergene')
61
+            ->className('btn btn-sm btn-primary mb-4')
62
+            ->text('<i class="fas fa-plus"></i> Nuovo allergene'));
63
+        }
64
+        return $this->builder()
65
+                    ->setTableId($this->dataTableVariable)
66
+                    ->columns($this->getColumns())
67
+                    ->minifiedAjax()
68
+                    ->orderBy(1)
69
+                    ->selectStyleSingle()
70
+                    ->buttons($buttons)
71
+                    ->editor(
72
+                        Editor::make()
73
+                        ->fields([
74
+                            Fields\Text::make('nome')->label('Nome'),
75
+                            Fields\Text::make('icona')->label('Icona'),
76
+                            Fields\Text::make('colore')->label('Colore'),
77
+                            Fields\Boolean::make('disponibile')->label('Disponibile')->default(true),
78
+                        ])
79
+                    )
80
+                    ->initComplete("function(settings, json){
81
+                        initComplete_allergene();
82
+                    }")
83
+                    ->language(asset('assets/Italian.json'))
84
+                    ->dom(count($buttons)==0?'rtip':'Bfrtip')
85
+                    ->responsive()
86
+                    ->selectStyleSingle();
87
+    }
88
+
89
+    /**
90
+     * Get the dataTable columns definition.
91
+     */
92
+    public function getColumns(): array
93
+    {
94
+        return [
95
+            Column::make('id')->title('ID')->width('10%')->visible(false),
96
+            // Column::make('icona_display')->title('Icona')->width('10%'),
97
+            Column::computed('disponibile_display')->title('Disponibile')->addClass('text-center'), // icona in tabella
98
+            Column::make('nome')->title('Nome'),
99
+            Column::make('descrizione')->title('Descrizione'),
100
+            Column::make('disponibile')->title('Disponibile')->visible(false)->addClass('text-center'), // valore grezzo per l'editor
101
+            Column::computed('action')->title('')->width('10%')->addClass('text-center'),
102
+        ];
103
+    }
104
+
105
+    /**
106
+     * Get the filename for export.
107
+     */
108
+    protected function filename(): string
109
+    {
110
+        return 'Allergene_' . date('YmdHis');
111
+    }
112
+}

+ 90
- 0
app/DataTables/AllergeneDataTableEditor.php 파일 보기

@@ -0,0 +1,90 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Allergene;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class AllergeneDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Allergene::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'disponibile.required' => 'Indicare una delle due opzioni',
23
+  ];
24
+
25
+  /**
26
+  * Get create action validation rules.
27
+  *
28
+  * @return array
29
+  */
30
+  public function createRules(): array
31
+  {
32
+    return [
33
+      'nome'  => 'required',
34
+      'disponibile' => 'boolean', // unchecked = non inviato; normalizzato a false in creating()
35
+    ];
36
+  }
37
+
38
+  public function createMessages(): array{
39
+    return $this->messages;
40
+  }
41
+
42
+  /**
43
+  * Get edit action validation rules.
44
+  *
45
+  * @param Model $model
46
+  * @return array
47
+  */
48
+  public function editRules(Model $model): array
49
+  {
50
+    return [
51
+      'nome'  => 'required',
52
+      'disponibile' => 'boolean', // unchecked = non inviato; normalizzato a false in updating()
53
+    ];
54
+  }
55
+
56
+  public function editMessages(): array{
57
+    return $this->messages;
58
+  }
59
+
60
+  /**
61
+  * Get remove action validation rules.
62
+  *
63
+  * @param Model $model
64
+  * @return array
65
+  */
66
+  public function removeRules(Model $model): array
67
+  {
68
+    return [];
69
+  }
70
+
71
+  public function creating(Model $model, array $data): array
72
+  {
73
+    // $model->roles()->sync([$data['ruolo_id']]);
74
+    $data['disponibile'] = isset($data['disponibile']) ? true : false;
75
+    return $data;
76
+  }
77
+
78
+  public function updating(Model $model, array $data): array
79
+  {
80
+    // dd($data['ruolo']);
81
+    // $model->roles()->sync([$data['ruolo_id']]);
82
+    $data['disponibile'] = isset($data['disponibile']) ? true : false;
83
+    return $data;
84
+  }
85
+  public function messages(): array
86
+  {
87
+    return $this->messages;
88
+  }
89
+
90
+}

+ 118
- 0
app/DataTables/AttivitaDataTable.php 파일 보기

@@ -0,0 +1,118 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Attivita;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+
16
+class AttivitaDataTable extends DataTable
17
+{
18
+    public function __construct(){
19
+        $this->dataTableVariable = 'dataTable_attivita';
20
+    }
21
+    /**
22
+     * Build the DataTable class.
23
+     *
24
+     * @param QueryBuilder<Attivitum> $query Results from query() method.
25
+     */
26
+    public function dataTable(QueryBuilder $query): EloquentDataTable
27
+    {
28
+        return (new EloquentDataTable($query))
29
+            ->addColumn('action', function($entity){
30
+              return view('attivita.menu', ['entity' => $entity]);
31
+            })
32
+            ->addColumn('is_attiva_display', function($entity){
33
+              return view('_partials.available', ['available' => $entity->is_attiva]);
34
+            })
35
+            ->setRowId('id');
36
+    }
37
+
38
+    /**
39
+     * Get the query source of dataTable.
40
+     *
41
+     * @return QueryBuilder<Attivitum>
42
+     */
43
+    public function query(Attivita $model): QueryBuilder
44
+    {
45
+        return $model->newQuery()->where('user_id', Auth::user()->id);
46
+    }
47
+
48
+    /**
49
+     * Optional method if you want to use the html builder.
50
+     */
51
+    public function html(): HtmlBuilder
52
+    {
53
+        $buttons = [];
54
+        if(Auth::user()->can('create-attivita')){
55
+            array_push($buttons, Button::make('create')
56
+                ->editor('editor')
57
+                ->className('btn btn-sm btn-primary mb-4')
58
+                ->formTitle('Crea nuova attività')
59
+                ->formButtons([
60
+                    Button::raw('Annulla')
61
+                        ->className('btn btn-secondary ml-2')
62
+                        ->actionClose(),
63
+                    Button::raw('Salva')
64
+                        ->className('btn btn-success ml-2')
65
+                        ->actionHandler('create')
66
+                ])
67
+                ->text('<i class="fas fa-plus"></i> Nuova attività'));
68
+        }
69
+        return $this->builder()
70
+                    ->setTableId($this->dataTableVariable)
71
+                    ->columns($this->getColumns())
72
+                    ->minifiedAjax()
73
+                    ->orderBy(1)
74
+                    ->selectStyleSingle()
75
+                    ->language(asset('assets/Italian.json'))
76
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
77
+                    ->buttons($buttons)
78
+                    ->editor(
79
+                        Editor::make()
80
+                            ->fields([
81
+                                Fields\Text::make('nome')->label('Nome'),
82
+                                Fields\Text::make('descrizione')->label('Descrizione'),
83
+                                Fields\Image::make('path_logo')->label('Logo'),
84
+                                Fields\Image::make('path_icon')->label('Icona'),
85
+                                Fields\Image::make('path_image')->label('Immagine'),
86
+                                Fields\Boolean::make('is_attiva')->label('Attiva')->default(true),
87
+                            ])
88
+                    )
89
+                    ->initComplete("function(settings, json){
90
+                        initComplete_attivita();
91
+                    }");
92
+    }
93
+
94
+    /**
95
+     * Get the dataTable columns definition.
96
+     */
97
+    public function getColumns(): array
98
+    {
99
+        return [
100
+            Column::make('id')->visible(false),
101
+            Column::make('is_attiva_display')->title('Disponibile')->addClass('text-center'),
102
+            Column::make('nome'),
103
+            Column::make('descrizione'),
104
+            Column::make('path_logo'),
105
+            Column::make('path_icon'),
106
+            Column::make('path_image'),
107
+            Column::computed('action')->title('')->width('10%')->addClass('text-center'),
108
+        ];
109
+    }
110
+
111
+    /**
112
+     * Get the filename for export.
113
+     */
114
+    protected function filename(): string
115
+    {
116
+        return 'Attivita_' . date('YmdHis');
117
+    }
118
+}

+ 102
- 0
app/DataTables/AttivitaDataTableEditor.php 파일 보기

@@ -0,0 +1,102 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Attivita;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class AttivitaDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Attivita::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'descrizione.required' => 'La descrizione è richiesta',
23
+    'icona.required' => 'L\'icona è richiesta',
24
+    'colore.required' => 'Il colore è richiesto',
25
+    'tipo.required' => 'Il tipo è richiesto',
26
+    'is_attiva.required' => 'Indicare una delle due opzioni',
27
+  ];
28
+
29
+  /**
30
+  * Get create action validation rules.
31
+  *
32
+  * @return array
33
+  */
34
+  public function createRules(): array
35
+  {
36
+    return [
37
+      'nome'  => 'required',
38
+      'descrizione' => 'nullable',
39
+      'icona' => 'nullable|string',
40
+      'colore' => 'nullable|string',
41
+      'tipo' => 'nullable|string',
42
+      'is_attiva' => 'boolean',
43
+    ];
44
+  }
45
+
46
+  public function createMessages(): array{
47
+    return $this->messages;
48
+  }
49
+
50
+  /**
51
+  * Get edit action validation rules.
52
+  *
53
+  * @param Model $model
54
+  * @return array
55
+  */
56
+  public function editRules(Model $model): array
57
+  {
58
+    return [
59
+      'nome'  => 'required',
60
+      'descrizione' => 'nullable',
61
+      'icona' => 'nullable|string',
62
+      'colore' => 'nullable|string',
63
+      'tipo' => 'nullable|string',
64
+      'is_attiva' => 'boolean',
65
+    ];
66
+  }
67
+
68
+  public function editMessages(): array{
69
+    return $this->messages;
70
+  }
71
+
72
+  /**
73
+  * Get remove action validation rules.
74
+  *
75
+  * @param Model $model
76
+  * @return array
77
+  */
78
+  public function removeRules(Model $model): array
79
+  {
80
+    return [];
81
+  }
82
+
83
+  public function creating(Model $model, array $data): array
84
+  {
85
+    // $model->roles()->sync([$data['ruolo_id']]);
86
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
87
+    return $data;
88
+  }
89
+
90
+  public function updating(Model $model, array $data): array
91
+  {
92
+    // dd($data['ruolo']);
93
+    // $model->roles()->sync([$data['ruolo_id']]);
94
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
95
+    return $data;
96
+  }
97
+  public function messages(): array
98
+  {
99
+    return $this->messages;
100
+  }
101
+
102
+}

+ 119
- 0
app/DataTables/BachecaDataTable.php 파일 보기

@@ -0,0 +1,119 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Bacheca;
6
+use App\Models\Attivita;
7
+use App\DataTables\BachecaDataTableEditor;
8
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
9
+use Yajra\DataTables\EloquentDataTable;
10
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
11
+use Yajra\DataTables\Html\Button;
12
+use Yajra\DataTables\Html\Column;
13
+use Yajra\DataTables\Html\Editor\Editor;
14
+use Yajra\DataTables\Html\Editor\Fields;
15
+use Yajra\DataTables\Services\DataTable;
16
+use Illuminate\Support\Facades\Auth;
17
+use Illuminate\Support\Facades\Session;
18
+
19
+class BachecaDataTable extends DataTable
20
+{
21
+    public function __construct()
22
+    {
23
+        $this->dataTableVariable = 'dataTable_bacheca';
24
+    }
25
+    /**
26
+     * Build the DataTable class.
27
+     *
28
+     * @param QueryBuilder<Bacheca> $query Results from query() method.
29
+     */
30
+    public function dataTable(QueryBuilder $query): EloquentDataTable
31
+    {
32
+        return (new EloquentDataTable($query))
33
+            ->addColumn('action', function($entity){
34
+                return view('bacheca.menu', ['entity' => $entity]);
35
+            })
36
+            ->setRowId('id');
37
+    }
38
+
39
+    /**
40
+     * Get the query source of dataTable.
41
+     *
42
+     * @return QueryBuilder<Bacheca>
43
+     */
44
+    public function query(Bacheca $model): QueryBuilder
45
+    {
46
+        return $model->newQuery()->where('attivita_id', session()->get('attivita_attuale'));
47
+    }
48
+
49
+    /**
50
+     * Optional method if you want to use the html builder.
51
+     */
52
+    public function html(): HtmlBuilder
53
+    {
54
+        $buttons = [];
55
+        if(Auth::user()->can('create-bacheca')){
56
+            array_push($buttons, Button::make('create')
57
+                ->editor('editor')
58
+                ->formTitle('Crea nuovo bacheca')
59
+                ->className('btn btn-sm btn-primary mb-4')
60
+                ->text('<i class="fas fa-plus"></i> Nuovo bacheca'));
61
+        }
62
+
63
+        return $this->builder()
64
+                    ->setTableId($this->dataTableVariable)
65
+                    ->columns($this->getColumns())
66
+                    ->minifiedAjax()
67
+                    ->orderBy(1)
68
+                    ->responsive()
69
+                    ->selectStyleSingle()
70
+                    ->language(asset('assets/Italian.json'))
71
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
72
+                    ->buttons($buttons)
73
+                    ->initComplete("function(settings, json){
74
+                        initComplete_bacheca();
75
+                    }")
76
+                    ->editor(
77
+                        Editor::make()
78
+                            ->fields([
79
+                                Fields\Select2::make('attivita_id')->label('Attività')
80
+                                ->options(Attivita::all()->pluck('id', 'nome'))
81
+                                ->default(session()->get('attivita_attuale')),
82
+                                Fields\Text::make('nome')->label('Nome'),
83
+                                Fields\Text::make('descrizione')->label('Descrizione'),
84
+                                Fields\Image::make('immagine')->label('Immagine'),
85
+                                Fields\Boolean::make('is_attiva')->label('Attiva')->default(true),
86
+
87
+                            ])
88
+                    );
89
+    }
90
+
91
+    /**
92
+     * Get the dataTable columns definition.
93
+     */
94
+    public function getColumns(): array
95
+    {
96
+        return [
97
+            Column::make('id')->visible(false),
98
+            Column::make('nome')->title('Nome'),
99
+            Column::make('descrizione')->title('Descrizione'),
100
+            Column::make('colore')->title('Colore'),
101
+            Column::make('tipo')->title('Tipo'),
102
+            Column::make('info')->title('Info'),
103
+            Column::computed('action')
104
+                  ->title('')
105
+                  ->exportable(false)
106
+                  ->printable(false)
107
+                  ->width(60)
108
+                  ->addClass('text-center'),
109
+        ];
110
+    }
111
+
112
+    /**
113
+     * Get the filename for export.
114
+     */
115
+    protected function filename(): string
116
+    {
117
+        return 'Bacheca_' . date('YmdHis');
118
+    }
119
+}

+ 96
- 0
app/DataTables/BachecaDataTableEditor.php 파일 보기

@@ -0,0 +1,96 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Bacheca;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class BachecaDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Bacheca::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'descrizione.required' => 'La descrizione è richiesta',
23
+    'icona.required' => 'L\'icona è richiesta',
24
+    'is_attiva.required' => 'Indicare una delle due opzioni',
25
+  ];
26
+
27
+  /**
28
+  * Get create action validation rules.
29
+  *
30
+  * @return array
31
+  */
32
+  public function createRules(): array
33
+  {
34
+    return [
35
+      'nome'  => 'required',
36
+      'descrizione' => 'nullable',
37
+      'icona' => 'nullable|string',
38
+      'is_attiva' => 'boolean',
39
+    ];
40
+  }
41
+
42
+  public function createMessages(): array{
43
+    return $this->messages;
44
+  }
45
+
46
+  /**
47
+  * Get edit action validation rules.
48
+  *
49
+  * @param Model $model
50
+  * @return array
51
+  */
52
+  public function editRules(Model $model): array
53
+  {
54
+    return [
55
+      'nome'  => 'required',
56
+      'descrizione' => 'nullable',
57
+      'icona' => 'nullable|string',
58
+      'is_attiva' => 'boolean',
59
+    ];
60
+  }
61
+
62
+  public function editMessages(): array{
63
+    return $this->messages;
64
+  }
65
+
66
+  /**
67
+  * Get remove action validation rules.
68
+  *
69
+  * @param Model $model
70
+  * @return array
71
+  */
72
+  public function removeRules(Model $model): array
73
+  {
74
+    return [];
75
+  }
76
+
77
+  public function creating(Model $model, array $data): array
78
+  {
79
+    // $model->roles()->sync([$data['ruolo_id']]);
80
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
81
+    return $data;
82
+  }
83
+
84
+  public function updating(Model $model, array $data): array
85
+  {
86
+    // dd($data['ruolo']);
87
+    // $model->roles()->sync([$data['ruolo_id']]);
88
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
89
+    return $data;
90
+  }
91
+  public function messages(): array
92
+  {
93
+    return $this->messages;
94
+  }
95
+
96
+}

+ 113
- 0
app/DataTables/ContenutoBachecaDataTable.php 파일 보기

@@ -0,0 +1,113 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\ContenutoBacheca;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+use Illuminate\Support\Facades\Session;
16
+use Illuminate\Support\Facades\Storage;
17
+
18
+class ContenutoBachecaDataTable extends DataTable
19
+{
20
+    public function __construct()
21
+    {
22
+        $this->dataTableVariable = 'dataTable_contenuto_bacheca';
23
+    }
24
+    /**
25
+     * Build the DataTable class.
26
+     *
27
+     * @param QueryBuilder<ContenutoBacheca> $query Results from query() method.
28
+     */
29
+    public function dataTable(QueryBuilder $query): EloquentDataTable
30
+    {
31
+        return (new EloquentDataTable($query))
32
+            ->addColumn('action', function($query){
33
+                return view('contenuto_bacheca.menu', ['entity' => $query]);
34
+            })
35
+            ->addColumn('immagine', function($query){
36
+                return '<img src="'.Storage::disk('contenuti_bacheca')->url($query->immagine).'" alt="Immagine" class="img-fluid rounded-5 w-50">';
37
+            })
38
+            ->rawColumns(['immagine'])
39
+            ->setRowId('id');
40
+    }
41
+
42
+    /**
43
+     * Get the query source of dataTable.
44
+     *
45
+     * @return QueryBuilder<ContenutoBacheca>
46
+     */
47
+    public function query(ContenutoBacheca $model): QueryBuilder
48
+    {
49
+        if($this->bacheca_id){
50
+            return $model->newQuery()->join('bacheca_has_contenuto', 'contenuto_bacheca.id', '=', 'bacheca_has_contenuto.contenuto_id')->where('bacheca_has_contenuto.bacheca_id', $this->bacheca_id);
51
+        }
52
+        return $model->newQuery();
53
+    }
54
+
55
+    /**
56
+     * Optional method if you want to use the html builder.
57
+     */
58
+    public function html(): HtmlBuilder
59
+    {
60
+        $buttons = [];
61
+        if(Auth::user()->can('create-contenuto_bacheca')){
62
+            array_push($buttons, Button::make('create')
63
+                ->editor('editor')
64
+                ->className('btn btn-sm btn-primary mb-4')
65
+                ->formTitle('Crea nuovo contenuto bacheca')
66
+                ->text('<i class="fas fa-plus"></i> Nuovo contenuto bacheca'));
67
+        }
68
+        return $this->builder()
69
+                    ->setTableId($this->dataTableVariable)
70
+                    ->columns($this->getColumns())
71
+                    ->language(asset('assets/Italian.json'))
72
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
73
+                    ->buttons($buttons)
74
+                    ->initComplete("function(settings, json){
75
+                        initComplete_contenuto_bacheca();
76
+                    }")
77
+                    ->editor(
78
+                        Editor::make()
79
+                            ->fields([
80
+                                Fields\Text::make('nome')->label('Nome'),
81
+                                Fields\Text::make('descrizione')->label('Descrizione'),
82
+                                Fields\File::make('immagine')->label('Immagine'),
83
+                            ])
84
+                    );
85
+    }
86
+
87
+    /**
88
+     * Get the dataTable columns definition.
89
+     */
90
+    public function getColumns(): array
91
+    {
92
+        return [
93
+            Column::make('id')->visible(false),
94
+            Column::make('immagine')->title('Immagine'),
95
+            Column::make('nome')->title('Nome'),
96
+            Column::make('descrizione')->title('Descrizione'),
97
+            Column::computed('action')
98
+                  ->title('')
99
+                  ->exportable(false)
100
+                  ->printable(false)
101
+                  ->width(60)
102
+                  ->addClass('text-center'),
103
+        ];
104
+    }
105
+
106
+    /**
107
+     * Get the filename for export.
108
+     */
109
+    protected function filename(): string
110
+    {
111
+        return 'ContenutoBacheca_' . date('YmdHis');
112
+    }
113
+}

+ 150
- 0
app/DataTables/ContenutoBachecaDataTableEditor.php 파일 보기

@@ -0,0 +1,150 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\ContenutoBacheca;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class ContenutoBachecaDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = ContenutoBacheca::class;
17
+  protected string $uploadDir = '';
18
+  protected string $disk = 'contenuti_bacheca';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome dell\'elemento è richiesto',
22
+    'descrizione.nullable' => 'La descrizione dell\'elemento è facoltativa',
23
+    'immagine.nullable' => 'L\'immagine dell\'elemento è facoltativa',
24
+    // 'immagine.image' => 'L\'immagine dell\'elemento deve essere un\'immagine',
25
+    // 'immagine.mimes' => 'L\'immagine dell\'elemento deve essere un\'immagine in formato jpeg, png, jpg, gif, svg',
26
+    'immagine.max' => 'L\'immagine dell\'elemento deve essere minore di 2MB',
27
+    ];
28
+
29
+  /**
30
+  * Get create action validation rules.
31
+  *
32
+  * @return array
33
+  */
34
+  public function createRules(): array
35
+  {
36
+    return [
37
+      'nome'  => 'required',
38
+      'descrizione' => 'nullable',
39
+      // 'immagine' => 'nullable|mimes:jpeg,png,jpg,gif,svg|max:2048',
40
+      'immagine' => 'nullable|max:2048',
41
+    ];
42
+  }
43
+
44
+  public function createMessages(): array{
45
+    return $this->messages;
46
+  }
47
+
48
+  /**
49
+  * Get edit action validation rules.
50
+  *
51
+  * @param Model $model
52
+  * @return array
53
+  */
54
+  public function editRules(Model $model): array
55
+  {
56
+    return [
57
+      'nome'  => 'required',
58
+      'descrizione' => 'nullable',
59
+      // 'immagine' => 'nullable|mimes:jpeg,png,jpg,gif,svg|max:2048',
60
+      'immagine' => 'nullable|max:2048',
61
+    ];
62
+  }
63
+
64
+  public function editMessages(): array{
65
+    return $this->messages;
66
+  }
67
+
68
+  /**
69
+  * Get remove action validation rules.
70
+  *
71
+  * @param Model $model
72
+  * @return array
73
+  */
74
+  public function removeRules(Model $model): array
75
+  {
76
+    return [];
77
+  }
78
+
79
+  public function creating(Model $model, array $data): array
80
+  {
81
+    return $data;
82
+  }
83
+
84
+  public function updating(Model $model, array $data): array
85
+  {
86
+
87
+    return $data;
88
+  }
89
+  public function messages(): array
90
+  {
91
+    return $this->messages;
92
+  }
93
+
94
+  public function updaload()
95
+  
96
+  
97
+  {
98
+    $this->action = 'upload';
99
+
100
+    $field   = $request->input('uploadField');
101
+    $storage = Storage::disk($this->disk);
102
+
103
+    try {
104
+      $rules      = $this->uploadRules();
105
+      $fieldRules = ['upload' => data_get($rules, $field, [])];
106
+
107
+      $this->validate($request, $fieldRules, $this->messages(), $this->attributes());
108
+
109
+      $uploadedFile = $request->file('upload');
110
+      $filename     = $this->getUploadedFilename($field, $uploadedFile);
111
+      $id           = $storage->putFileAs($request->id, $uploadedFile, $filename);
112
+
113
+      if (method_exists($this, 'uploaded')) {
114
+        $id = $this->uploaded($id);
115
+      }
116
+
117
+      return response()->json([
118
+        'action' => $this->action,
119
+        'data'   => [],
120
+        'files'  => [
121
+          'files' => [
122
+            $id => [
123
+              'filename'      => $id,
124
+              'original_name' => $uploadedFile->getClientOriginalName(),
125
+              'size'          => $uploadedFile->getSize(),
126
+              'directory'     => $request->id,
127
+              'disk'          => $this->disk,
128
+              'url'           => $storage->url($id),
129
+            ],
130
+          ],
131
+        ],
132
+        'upload' => [
133
+          'id' => $id,
134
+        ],
135
+      ]);
136
+    } catch (ValidationException $exception) {
137
+      return response()->json([
138
+        'action'      => $this->action,
139
+        'data'        => [],
140
+        'fieldErrors' => [
141
+          [
142
+            'name'   => $field,
143
+            'status' => str_replace('upload', $field, $exception->errors()['upload'][0]),
144
+          ],
145
+        ],
146
+      ]);
147
+    }
148
+  }
149
+
150
+}

+ 136
- 0
app/DataTables/CucinaDataTable.php 파일 보기

@@ -0,0 +1,136 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Cucina;
6
+use App\Models\Dispositivo;
7
+use App\Models\Attivita;
8
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
9
+use Illuminate\Support\Facades\Auth;
10
+use Yajra\DataTables\EloquentDataTable;
11
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
12
+use Yajra\DataTables\Html\Button;
13
+use Yajra\DataTables\Html\Column;
14
+use Yajra\DataTables\Html\Editor\Editor;
15
+use Yajra\DataTables\Html\Editor\Fields;
16
+use Yajra\DataTables\Services\DataTable;
17
+use App\DataTables\CucinaDataTableEditor;
18
+use Illuminate\Support\Facades\Session;
19
+
20
+class CucinaDataTable extends DataTable
21
+{
22
+    public function __construct(){
23
+        $this->dataTableVariable = 'dataTable_cucina';
24
+    }
25
+    /**
26
+     * Build the DataTable class.
27
+     *
28
+     * @param QueryBuilder<Cucina> $query Results from query() method.
29
+     */
30
+    public function dataTable(QueryBuilder $query): EloquentDataTable
31
+    {
32
+        return (new EloquentDataTable($query))
33
+            ->addColumn('action', function($entity){
34
+              return view('cucina.menu', ['entity' => $entity]);
35
+            })
36
+            ->addColumn('is_attiva_display', function($entity){
37
+              return view('_partials.available', ['available' => $entity->is_attiva]);
38
+            })
39
+            ->addColumn('piatti_count', function($entity){
40
+              return $entity->piatti->count();
41
+            })
42
+            ->addColumn('attivita_id_display', function($entity){
43
+              return $entity->attivita->nome;
44
+            })
45
+            ->addColumn('stampante_display', function($entity){
46
+              return $entity->stampante ? $entity->stampante->nome : '';
47
+            })
48
+            // ->addColumn('cucina_id_display', function($entity){
49
+            //   return $entity->cucina->nome;
50
+            // })
51
+            ->addColumn('stampante_id_display', function($entity){
52
+              return $entity->stampante ? $entity->stampante->nome : '';
53
+            })
54
+            ->setRowId('id');
55
+    }
56
+
57
+    /**
58
+     * Get the query source of dataTable.
59
+     *
60
+     * @return QueryBuilder<Cucina>
61
+     */
62
+    public function query(Cucina $model): QueryBuilder
63
+    {
64
+        return $model->newQuery()->where('attivita_id', session()->get('attivita_attuale'));
65
+    }
66
+
67
+    /**
68
+     * Optional method if you want to use the html builder.
69
+     */
70
+    public function html(): HtmlBuilder
71
+    {
72
+        $buttons = [];
73
+        if(Auth::user()->can('create-cucina')){
74
+            array_push($buttons, Button::make('create')
75
+            ->editor('editor')
76
+            ->formTitle('Crea nuovo cucina')
77
+            ->className('btn btn-sm btn-primary mb-4')
78
+            ->text('<i class="fas fa-plus"></i> Nuovo cucina'));
79
+        }
80
+
81
+        return $this->builder()
82
+                    ->setTableId($this->dataTableVariable)
83
+                    ->columns($this->getColumns())
84
+                    ->minifiedAjax()
85
+                    ->initComplete("function(settings, json){
86
+                        initComplete_cucina();
87
+                    }")
88
+                    ->language(asset('assets/Italian.json'))
89
+                    ->dom(count($buttons)==0?'rtip':'Bfrtip')
90
+                    ->responsive()
91
+                    ->orderBy(1)
92
+                    ->selectStyleSingle()
93
+                    ->buttons($buttons)
94
+                    ->editor(
95
+                        Editor::make()
96
+                        ->fields([
97
+                            Fields\Text::make('nome')->label('Nome'),
98
+                            Fields\Text::make('descrizione')->label('Descrizione'),
99
+                            Fields\Image::make('immagine')->label('Immagine'),
100
+                            Fields\Boolean::make('is_attiva')->label('Attiva')->default(true),  
101
+                            Fields\Select2::make('attivita_id')->label('Attività')->options(Attivita::where('is_attiva', true)->pluck('id', 'nome')),
102
+                            Fields\Select2::make('cucina_id')->label('Cucina')->options(Cucina::where('is_attiva', true)->pluck('id', 'nome')),
103
+                            Fields\Select2::make('stampante_id')->label('Stampante')->options(Dispositivo::where('tipo', Dispositivo::STAMPANTE)->pluck('id', 'nome')),
104
+                        ])
105
+                    )
106
+                    ->buttons($buttons)
107
+                    ->orderBy(1);
108
+    }
109
+
110
+    /**
111
+     * Get the dataTable columns definition.
112
+     */
113
+    public function getColumns(): array
114
+    {
115
+        return [
116
+            Column::make('id')->visible(false),
117
+            Column::make('is_attiva_display')->title('Disponibile')->addClass('text-center'),
118
+            Column::make('nome'),
119
+            Column::make('descrizione'),
120
+            Column::computed('piatti_count')->title('Piatti')->addClass('text-center'),
121
+            // Column::make('immagine'),
122
+            Column::make('attivita_id')->data('attivita_id_display')->title('Attività')->addClass('text-center'),
123
+            Column::make('stampante_id')->data('stampante_display')->title('Stampante')->addClass('text-center'),
124
+            // Column::make('cucina_id')->data('cucina_id_display')->title('Cucina')->addClass('text-center'),
125
+            Column::make('action'),
126
+        ];
127
+    }
128
+
129
+    /**
130
+     * Get the filename for export.
131
+     */
132
+    protected function filename(): string
133
+    {
134
+        return 'Cucina_' . date('YmdHis');
135
+    }
136
+}

+ 96
- 0
app/DataTables/CucinaDataTableEditor.php 파일 보기

@@ -0,0 +1,96 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Cucina;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class CucinaDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Cucina::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'descrizione.required' => 'La descrizione è richiesta',
23
+    'immagine.required' => 'L\'immagine è richiesta',
24
+    'is_attiva.required' => 'Indicare una delle due opzioni',
25
+  ];
26
+
27
+  /**
28
+  * Get create action validation rules.
29
+  *
30
+  * @return array
31
+  */
32
+  public function createRules(): array
33
+  {
34
+    return [
35
+      'nome'  => 'required',
36
+      'descrizione' => 'nullable',
37
+      'immagine' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
38
+      'is_attiva' => 'boolean',
39
+    ];
40
+  }
41
+
42
+  public function createMessages(): array{
43
+    return $this->messages;
44
+  }
45
+
46
+  /**
47
+  * Get edit action validation rules.
48
+  *
49
+  * @param Model $model
50
+  * @return array
51
+  */
52
+  public function editRules(Model $model): array
53
+  {
54
+    return [
55
+      'nome'  => 'required',
56
+      'descrizione' => 'nullable',
57
+      'immagine' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
58
+      'is_attiva' => 'boolean',
59
+    ];
60
+  }
61
+
62
+  public function editMessages(): array{
63
+    return $this->messages;
64
+  }
65
+
66
+  /**
67
+  * Get remove action validation rules.
68
+  *
69
+  * @param Model $model
70
+  * @return array
71
+  */
72
+  public function removeRules(Model $model): array
73
+  {
74
+    return [];
75
+  }
76
+
77
+  public function creating(Model $model, array $data): array
78
+  {
79
+    // $model->roles()->sync([$data['ruolo_id']]);
80
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
81
+    return $data;
82
+  }
83
+
84
+  public function updating(Model $model, array $data): array
85
+  {
86
+    // dd($data['ruolo']);
87
+    // $model->roles()->sync([$data['ruolo_id']]);
88
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
89
+    return $data;
90
+  }
91
+  public function messages(): array
92
+  {
93
+    return $this->messages;
94
+  }
95
+
96
+}

+ 131
- 0
app/DataTables/DispositivoDataTable.php 파일 보기

@@ -0,0 +1,131 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Dispositivo;
6
+use App\Models\Attivita;
7
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
8
+use Yajra\DataTables\EloquentDataTable;
9
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
10
+use Yajra\DataTables\Html\Button;
11
+use Yajra\DataTables\Html\Column;
12
+use Yajra\DataTables\Html\Editor\Editor;
13
+use Yajra\DataTables\Html\Editor\Fields;
14
+use Yajra\DataTables\Services\DataTable;
15
+use Illuminate\Support\Facades\Auth;
16
+
17
+class DispositivoDataTable extends DataTable
18
+{
19
+    public function __construct()
20
+    {
21
+        $this->dataTableVariable = 'dataTable_dispositivo';
22
+    }
23
+    /**
24
+     * Build the DataTable class.
25
+     *
26
+     * @param QueryBuilder<Dispositivo> $query Results from query() method.
27
+     */
28
+    public function dataTable(QueryBuilder $query): EloquentDataTable
29
+    {
30
+        return (new EloquentDataTable($query))
31
+            ->addColumn('action', function($entity){
32
+                return view('dispositivo.menu', ['entity' => $entity]);
33
+            })
34
+            ->addColumn('is_attivo_display', function($entity){
35
+                return view('_partials.available', ['available' => $entity->is_attivo]);
36
+            })
37
+            ->addColumn('attivita_id_display', function($entity){
38
+                return $entity->attivita ? $entity->attivita->nome : 'ND';
39
+            })
40
+            ->setRowId('id');
41
+    }
42
+
43
+    /**
44
+     * Get the query source of dataTable.
45
+     *
46
+     * @return QueryBuilder<Dispositivo>
47
+     */
48
+    public function query(Dispositivo $model): QueryBuilder
49
+    {
50
+        return $model->newQuery();
51
+    }
52
+
53
+    /**
54
+     * Optional method if you want to use the html builder.
55
+     */
56
+    public function html(): HtmlBuilder
57
+    {
58
+        $buttons = [];
59
+        if(Auth::user()->can('create-dispositivo')){
60
+            array_push($buttons, Button::make('create')
61
+                ->editor('editor')
62
+                ->className('btn btn-sm btn-primary mb-4')
63
+                ->formTitle('Crea nuovo dispositivo')
64
+                ->text('<i class="fas fa-plus"></i> Nuovo dispositivo'));
65
+        }
66
+        return $this->builder()
67
+                    ->setTableId($this->dataTableVariable)
68
+                    ->columns($this->getColumns())
69
+                    ->minifiedAjax()
70
+                    ->language(asset('assets/Italian.json'))
71
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
72
+                    ->buttons($buttons)
73
+                    ->orderBy(1)
74
+                    ->editor(
75
+                        Editor::make()
76
+                            ->fields([
77
+                                Fields\Hidden::make('endpoint_id')->label('Endpoint ID'),
78
+                                Fields\Text::make('nome')->label('Nome'),
79
+                                Fields\Select2::make('tipo')->label('Tipo')->options(Dispositivo::getTipoDispositivo()->pluck('value', 'label')),
80
+                                Fields\Select2::make('attivita_id')->label('Attività')->options(Attivita::where('is_attiva', true)->pluck('id', 'nome')),
81
+                                Fields\Text::make('licenza')->label('Licenza'),
82
+                                Fields\Text::make('url_stampante')->label('URL della stampante'),
83
+                                Fields\Text::make('ubicazione')->label('Ubicazione'),
84
+                                Fields\Text::make('note')->label('Note'),
85
+                                Fields\Boolean::make('is_attivo')->label('Attivo')->default(true),
86
+                                Fields\Text::make('pin_sblocco')->label('Pin di sblocco'),
87
+                                Fields\DateTime::make('data_apertura_dispositivo')->label('Data di apertura del dispositivo'),
88
+                                Fields\DateTime::make('data_chiusura_dispositivo')->label('Data di chiusura del dispositivo'),
89
+                            ])
90
+                    )
91
+                    ->initComplete("function(settings, json){
92
+                        initComplete_dispositivo();
93
+                    }")
94
+                    ->selectStyleSingle();
95
+    }
96
+
97
+    /**
98
+     * Get the dataTable columns definition.
99
+     */
100
+    public function getColumns(): array
101
+    {
102
+        return [
103
+            Column::make('id')->visible(false),
104
+            Column::make('is_attivo')->data('is_attivo_display')->title('Disponibile'),
105
+            Column::make('nome')->title('Nome'),
106
+            Column::make('attivita_id')->title('Attività'),
107
+            Column::make('tipo')->title('Tipo'),
108
+            Column::make('licenza')->title('Licenza'),
109
+            Column::make('url_stampante')->title('URL della stampante'),
110
+            Column::make('ubicazione')->title('Ubicazione'),
111
+            // Column::make('note')->title('Note'),
112
+            Column::make('pin_sblocco')->title('Pin di sblocco'),
113
+            // Column::make('data_apertura_dispositivo')->title('Data di apertura del dispositivo'),
114
+            // Column::make('data_chiusura_dispositivo')->title('Data di chiusura del dispositivo'),
115
+            Column::computed('action')
116
+                  ->title('')
117
+                  ->exportable(false)
118
+                  ->printable(false)
119
+                  ->width(60)
120
+                  ->addClass('text-center'),
121
+        ];
122
+    }
123
+
124
+    /**
125
+     * Get the filename for export.
126
+     */
127
+    protected function filename(): string
128
+    {
129
+        return 'Dispositivo_' . date('YmdHis');
130
+    }
131
+}

+ 126
- 0
app/DataTables/DispositivoDataTableEditor.php 파일 보기

@@ -0,0 +1,126 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Dispositivo;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class DispositivoDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Dispositivo::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'tipo.required' => 'Il tipo è richiesto',
23
+    'attivita_id.required' => 'La attività è richiesta',
24
+    'licenza.required' => 'La licenza è richiesta',
25
+    'url_stampante.required' => 'L\'URL della stampante è richiesta',
26
+    'ubicazione.required' => 'L\'ubicazione è richiesta',
27
+    'note.required' => 'La note è richiesta',
28
+    'is_attivo.required' => 'Indicare una delle due opzioni',
29
+    'pin_sblocco.required' => 'Il pin di sblocco è richiesto',
30
+    'data_apertura_dispositivo.required' => 'La data di apertura del dispositivo è richiesta',
31
+    'data_chiusura_dispositivo.required' => 'La data di chiusura del dispositivo è richiesta',
32
+    'data_apertura_dispositivo.date' => 'La data di apertura del dispositivo deve essere una data valida',
33
+    'data_chiusura_dispositivo.date' => 'La data di chiusura del dispositivo deve essere una data valida',
34
+    'is_attivo.boolean' => 'Indicare una delle due opzioni',
35
+    'pin_sblocco.string' => 'Il pin di sblocco deve essere una stringa',
36
+    'pin_sblocco.required' => 'Il pin di sblocco è richiesto',
37
+    'pin_sblocco.min' => 'Il pin di sblocco deve essere lungo almeno 4 caratteri',
38
+    'pin_sblocco.max' => 'Il pin di sblocco deve essere lungo al massimo 4 caratteri',
39
+    'pin_sblocco.regex' => 'Il pin di sblocco deve contenere solo numeri',
40
+    'pin_sblocco.unique' => 'Il pin di sblocco deve essere unico',
41
+  ];
42
+
43
+  /**
44
+  * Get create action validation rules.
45
+  *
46
+  * @return array
47
+  */
48
+  public function createRules(): array
49
+  {
50
+    return [
51
+      'nome'  => 'required',
52
+      'tipo' => 'required',
53
+      'attivita_id' => 'required|exists:attivita,id',
54
+      'licenza' => 'nullable',
55
+      'url_stampante' => 'nullable',
56
+      'ubicazione' => 'nullable',
57
+      'note' => 'nullable',
58
+      'is_attivo' => 'boolean',
59
+      'pin_sblocco' => 'nullable',
60
+      'data_apertura_dispositivo' => 'nullable|date',
61
+      'data_chiusura_dispositivo' => 'nullable|date',
62
+    ];
63
+  }
64
+
65
+  public function createMessages(): array{
66
+    return $this->messages;
67
+  }
68
+
69
+  /**
70
+  * Get edit action validation rules.
71
+  *
72
+  * @param Model $model
73
+  * @return array
74
+  */
75
+  public function editRules(Model $model): array
76
+  {
77
+    return [
78
+      'nome'  => 'required',
79
+      'tipo' => 'required',
80
+      'attivita_id' => 'required|exists:attivita,id',
81
+      'licenza' => 'nullable',
82
+      'url_stampante' => 'nullable',
83
+      'ubicazione' => 'nullable',
84
+      'note' => 'nullable',
85
+      'is_attivo' => 'boolean',
86
+      'pin_sblocco' => 'nullable',
87
+      'data_apertura_dispositivo' => 'nullable|date',
88
+      'data_chiusura_dispositivo' => 'nullable|date',
89
+    ];
90
+  }
91
+
92
+  public function editMessages(): array{
93
+    return $this->messages;
94
+  }
95
+
96
+  /**
97
+  * Get remove action validation rules.
98
+  *
99
+  * @param Model $model
100
+  * @return array
101
+  */
102
+  public function removeRules(Model $model): array
103
+  {
104
+    return [];
105
+  }
106
+
107
+  public function creating(Model $model, array $data): array
108
+  {
109
+    // $model->roles()->sync([$data['ruolo_id']]);
110
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
111
+    return $data;
112
+  }
113
+
114
+  public function updating(Model $model, array $data): array
115
+  {
116
+    // dd($data['ruolo']);
117
+    // $model->roles()->sync([$data['ruolo_id']]);
118
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
119
+    return $data;
120
+  }
121
+  public function messages(): array
122
+  {
123
+    return $this->messages;
124
+  }
125
+
126
+}

+ 131
- 0
app/DataTables/EndpointDataTable.php 파일 보기

@@ -0,0 +1,131 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Endpoint;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+
16
+class EndpointDataTable extends DataTable
17
+{
18
+    public function __construct()
19
+    {
20
+        $this->dataTableVariable = 'dataTable_endpoint';
21
+    }
22
+    /**
23
+     * Build the DataTable class.
24
+     *
25
+     * @param QueryBuilder<Endpoint> $query Results from query() method.
26
+     */
27
+    public function dataTable(QueryBuilder $query): EloquentDataTable
28
+    {
29
+        return (new EloquentDataTable($query))
30
+            ->addColumn('action', function($entity){
31
+                return view('endpoint.menu', ['entity' => $entity]);
32
+            })
33
+            ->addColumn('stampanti_count', function($entity){
34
+                // return print_r([count($entity->info['stampanti']) , Endpoint::find($entity->id)->stampanti->count()], true);
35
+                return Endpoint::find($entity->id)->stampanti()->count();
36
+            })
37
+            ->addColumn('stampanti_display', function($entity){
38
+                return Endpoint::find($entity->id)->stampanti->pluck('nome')->implode(', ');
39
+            })
40
+            ->setRowId('id');
41
+    }
42
+
43
+    /**
44
+     * Get the query source of dataTable.
45
+     *
46
+     * @return QueryBuilder<Endpoint>
47
+     */
48
+    public function query(Endpoint $model): QueryBuilder
49
+    {
50
+        return $model->newQuery()->where('attivita_id', session()->get('attivita_attuale'));
51
+    }
52
+
53
+    /**
54
+     * Optional method if you want to use the html builder.
55
+     */
56
+    public function html(): HtmlBuilder
57
+    {
58
+        $buttons = [];
59
+        if(Auth::user()->can('create-endpoint')){
60
+            array_push($buttons, Button::make('create')
61
+                ->editor('editor')
62
+                ->className('btn btn-sm btn-primary mb-4')
63
+                ->formTitle('Crea nuovo endpoint')
64
+                ->text('<i class="fas fa-plus"></i> Nuovo endpoint'));
65
+        }
66
+        return $this->builder()
67
+                    ->setTableId($this->dataTableVariable)
68
+                    ->columns($this->getColumns())
69
+                    ->minifiedAjax()
70
+                    ->language(asset('assets/Italian.json'))
71
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
72
+                    ->buttons($buttons)
73
+                    ->orderBy(1)
74
+                    ->responsive(true)
75
+                    ->editor(
76
+                        Editor::make()
77
+                            ->fields([
78
+                                Fields\Text::make('label')->label('Label'),
79
+                                Fields\Text::make('descrizione')->label('Descrizione'),
80
+                                Fields\Text::make('ubicazione')->label('Ubicazione'),
81
+                                Fields\Text::make('url')->label('URL'),
82
+                            ])
83
+                    )
84
+                    ->initComplete("function(settings, json){
85
+                        initComplete_endpoint();
86
+                    }")
87
+                    ->selectStyleSingle()
88
+                    ->buttons($buttons);
89
+    }
90
+
91
+    /**
92
+     * Get the dataTable columns definition.
93
+     */
94
+    public function getColumns(): array
95
+    {
96
+        return [
97
+            Column::make('id')->title('ID')->addClass('text-center w-10'),
98
+            Column::make('label')->title('Label'),
99
+            Column::make('descrizione')->title('Descrizione'),
100
+            Column::make('ubicazione')->title('Ubicazione'),
101
+            Column::make('stampanti_display')->title('Stampanti'),
102
+            Column::make('url')->title('URL'),
103
+            Column::make('user_id')->title('User ID'),
104
+            Column::make('token')->title('Token'),
105
+            Column::make('secret')->title('Secret'),
106
+            Column::make('status')->title('Status'),
107
+            Column::make('type')->title('Type'),
108
+            Column::make('version')->title('Version'),
109
+            Column::make('licenza_id')->title('Licenza ID'),
110
+            Column::make('stampanti_count')->title('Stampanti'),
111
+            Column::make('last_heartbeat')->title('Last Heartbeat'),
112
+            Column::make('last_activity')->title('Last Activity'),
113
+            // Column::make('created_at')->title('Created At'),
114
+            // Column::make('updated_at')->title('Updated At'),
115
+            Column::computed('action')
116
+                  ->title('')
117
+                  ->exportable(false)
118
+                  ->printable(false)
119
+                  ->width(60)
120
+                  ->addClass('text-center'),
121
+        ];
122
+    }
123
+
124
+    /**
125
+     * Get the filename for export.
126
+     */
127
+    protected function filename(): string
128
+    {
129
+        return 'Endpoint_' . date('YmdHis');
130
+    }
131
+}

+ 165
- 0
app/DataTables/EventoDataTable.php 파일 보기

@@ -0,0 +1,165 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Evento;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+use App\DataTables\EventoDataTableEditor;
16
+use Carbon\Carbon;
17
+
18
+class EventoDataTable extends DataTable
19
+{
20
+    public function __construct(){
21
+        $this->dataTableVariable = 'dataTable_evento';
22
+    }
23
+    /**
24
+     * Build the DataTable class.
25
+     *
26
+     * @param QueryBuilder<Evento> $query Results from query() method.
27
+     */
28
+    public function dataTable(QueryBuilder $query): EloquentDataTable
29
+    {
30
+        return (new EloquentDataTable($query))
31
+            ->addColumn('action', function($entity){
32
+              return view('evento.menu', ['entity' => $entity]);
33
+            })
34
+            ->addColumn('stato_display', function($entity){
35
+              return view('_partials.available', ['available' => $entity->is_attivo]);
36
+            })
37
+            ->addColumn('data_inizio_display', function($entity){
38
+              return Carbon::parse($entity->data_inizio)->format('d/m/Y');
39
+            })
40
+            ->addColumn('data_fine_display', function($entity){
41
+              return Carbon::parse($entity->data_fine)->format('d/m/Y');
42
+            })
43
+            ->addColumn('prezzo_display', function($entity){
44
+              return '€ ' . number_format($entity->prezzo, 2, ',', '.');
45
+            })
46
+            ->addColumn('apertura_prenotazione_display', function($entity){
47
+              return Carbon::parse($entity->apertura_prenotazione)->format('d/m/Y H:i');
48
+            })
49
+            ->addColumn('chiusura_prenotazione_display', function($entity){
50
+              return Carbon::parse($entity->chiusura_prenotazione)->format('d/m/Y H:i');
51
+            })
52
+            ->addColumn('periodo_evento_display', function($entity){
53
+              return Carbon::parse($entity->data_inizio)->format('d/m/Y') . ' - ' . Carbon::parse($entity->data_fine)->format('d/m/Y');
54
+            })
55
+            ->addColumn('periodo_prenotazioni_display', function($entity){
56
+              return Carbon::parse($entity->apertura_prenotazione)->format('d/m/Y') . ' - ' . Carbon::parse($entity->chiusura_prenotazione)->format('d/m/Y');
57
+            })
58
+            ->addColumn('prezzo_fisso_display', function($entity){
59
+              return view('_partials.available', ['available' => $entity->prezzo_fisso]);
60
+            })
61
+            ->setRowId('id');
62
+    }
63
+
64
+    /**
65
+     * Get the query source of dataTable.
66
+     *
67
+     * @return QueryBuilder<Evento>
68
+     */
69
+    public function query(Evento $model): QueryBuilder
70
+    {
71
+        return $model->newQuery();
72
+    }
73
+
74
+    /**
75
+     * Optional method if you want to use the html builder.
76
+     */
77
+    public function html(): HtmlBuilder
78
+    {
79
+        $buttons = [];
80
+        if(Auth::user()->can('create-evento')){
81
+            array_push($buttons, Button::make('create')
82
+                ->editor('editor')
83
+                ->className('btn btn-sm btn-primary mb-4')
84
+                ->formTitle('Crea nuovo evento')
85
+                ->formButtons([
86
+                    Button::raw('Annulla')
87
+                        ->className('btn btn-secondary ml-2')
88
+                        ->actionClose(),
89
+                    Button::raw('Salva')
90
+                        ->className('btn btn-success ml-2')
91
+                        ->actionHandler('create')
92
+                ])
93
+                ->text('<i class="fas fa-plus"></i> Nuovo evento'));
94
+        }
95
+        return $this->builder()
96
+                    ->setTableId($this->dataTableVariable)
97
+                    ->columns($this->getColumns())
98
+                    ->minifiedAjax()
99
+                    ->orderBy(1)
100
+                    ->selectStyleSingle()
101
+                    ->language(asset('assets/Italian.json'))
102
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
103
+                    ->buttons($buttons)
104
+                    ->searchPanes(true)
105
+                    ->responsive(true)
106
+                    ->editor(
107
+                        Editor::make()
108
+                            ->fields([
109
+                                Fields\File::make('immagine')->label('Locandina'),
110
+                                Fields\File::make('copertina')->label('Copertina'),
111
+                                Fields\Text::make('nome')->label('Nome'),
112
+                                Fields\TextArea::make('descrizione')->label('Descrizione'),
113
+                                Fields\Number::make('posti')->label('Posti'),
114
+                                Fields\DateTime::make('data_inizio')->label('Data inizio'),
115
+                                Fields\DateTime::make('data_fine')->label('Data fine'),
116
+                                Fields\DateTime::make('apertura_prenotazione')->label('Apertura prenotazione'),
117
+                                Fields\DateTime::make('chiusura_prenotazione')->label('Chiusura prenotazione'),
118
+                                Fields\Boolean::make('prezzo_fisso')->label('Prezzo fisso'),
119
+                                Fields\Number::make('prezzo')->label('Prezzo'),
120
+                                Fields\Select::make('stato')->label('Stato'),
121
+                                // ->options(Evento::STATI),
122
+                                Fields\Text::make('note')->label('Note'),
123
+                            ])
124
+                    )
125
+                    ->initComplete("function(settings, json){
126
+                        initComplete_evento();
127
+                    }");
128
+    }
129
+
130
+    /**
131
+     * Get the dataTable columns definition.
132
+     */
133
+    public function getColumns(): array
134
+    {
135
+        return [
136
+            Column::make('id')->title('ID')->width('10%')->visible(false),
137
+            Column::make('stato')->data('stato_display')->title('Stato')->addClass('text-center'),
138
+            Column::make('nome')->title('Nome'),
139
+            // Column::make('descrizione')->title('Descrizione'),
140
+            Column::computed('periodo_evento_display')->title('Periodo evento'),
141
+            Column::computed('periodo_prenotazioni_display')->title('Periodo prenotazioni'),
142
+            Column::make('data_inizio')->title('Data inizio')->data('data_inizio_display')->visible(false),
143
+            Column::make('data_fine')->title('Data fine')->data('data_fine_display')->visible(false),
144
+            Column::make('apertura_prenotazione')->title('Apertura prenotazione')->data('apertura_prenotazione_display')->visible(false),
145
+            Column::make('chiusura_prenotazione')->title('Chiusura prenotazione')->data('chiusura_prenotazione_display')->visible(false),
146
+            Column::make('prezzo_fisso')->title('Prezzo fisso')->data('prezzo_fisso_display')->addClass('text-center'),
147
+            Column::make('prezzo')->title('Prezzo')->data('prezzo_display')->addClass('text-center'),
148
+            Column::make('note')->title('Note')->visible(false),
149
+            Column::computed('action')
150
+                  ->title('')
151
+                  ->exportable(false)
152
+                  ->printable(false)
153
+                  ->width(60)
154
+                  ->addClass('text-center'),
155
+        ];
156
+    }
157
+
158
+    /**
159
+     * Get the filename for export.
160
+     */
161
+    protected function filename(): string
162
+    {
163
+        return 'Evento_' . date('YmdHis');
164
+    }
165
+}

+ 261
- 0
app/DataTables/EventoDataTableEditor.php 파일 보기

@@ -0,0 +1,261 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Evento;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Http\JsonResponse;
8
+use Illuminate\Http\UploadedFile;
9
+use Yajra\DataTables\DataTablesEditor;
10
+use Illuminate\Http\Request;
11
+use Illuminate\Validation\ValidationException;
12
+use Illuminate\Support\Facades\Storage;
13
+use Illuminate\Support\Str;
14
+
15
+class EventoDataTableEditor extends DataTablesEditor
16
+{
17
+  protected $model = Evento::class;
18
+
19
+  /** Disco per le locandine (storage/app/public/eventi/...) */
20
+  protected string $disk = 'eventi';
21
+
22
+  protected string $uploadDir = ''; //'eventi';
23
+
24
+  protected $messages = [
25
+    'nome.required' => 'Il nome è richiesto',
26
+    'descrizione.required' => 'La descrizione è richiesta',
27
+    'data_inizio.required' => 'La data inizio è richiesta',
28
+    'data_fine.required' => 'La data fine è richiesta',
29
+    'apertura_prenotazione.required' => 'La data apertura prenotazione è richiesta',
30
+    'chiusura_prenotazione.required' => 'La data chiusura prenotazione è richiesta',
31
+    'prezzo_fisso.required' => 'Il prezzo fisso è richiesto',
32
+    'prezzo.required' => 'Il prezzo è richiesto',
33
+    'stato.required' => 'Il stato è richiesto',
34
+    'note.required' => 'La note è richiesta',
35
+    'is_attiva.required' => 'Indicare una delle due opzioni',
36
+    'posti.required' => 'Il numero di posti è richiesto',
37
+    'posti.integer' => 'Il numero di posti deve essere un numero intero',
38
+    'copertina.required' => 'La copertina è richiesta',
39
+    'copertina.string' => 'La copertina deve essere una stringa',
40
+    'copertina.max' => 'La copertina deve essere lunga al massimo 2048 caratteri',
41
+  ];
42
+
43
+  /**
44
+  * Get create action validation rules.
45
+  *
46
+  * @return array
47
+  */
48
+  public function createRules(): array
49
+  {
50
+    return [
51
+      'nome'  => 'required',
52
+      'descrizione' => 'nullable',
53
+      'data_inizio' => 'required|date',
54
+      'data_fine' => 'required|date',
55
+      'apertura_prenotazione' => 'nullable|date',
56
+      'chiusura_prenotazione' => 'nullable|date',
57
+      'prezzo_fisso' => 'nullable|boolean',
58
+      'prezzo' => 'nullable|numeric',
59
+      'stato' => 'nullable|string',
60
+      'note' => 'nullable',
61
+      'immagine' => 'nullable|string|max:2048',
62
+      'posti' => 'nullable|integer',
63
+      'copertina' => 'nullable|string|max:2048',
64
+    ];
65
+  }
66
+
67
+  public function createMessages(): array{
68
+    return $this->messages;
69
+  }
70
+
71
+  /**
72
+  * Get edit action validation rules.
73
+  *
74
+  * @param Model $model
75
+  * @return array
76
+  */
77
+  public function editRules(Model $model): array
78
+  {
79
+    return [
80
+      'nome'  => 'required',
81
+      'descrizione' => 'nullable',
82
+      'data_inizio' => 'required|date',
83
+      'data_fine' => 'required|date',
84
+      'apertura_prenotazione' => 'nullable|date',
85
+      'chiusura_prenotazione' => 'nullable|date',
86
+      'prezzo_fisso' => 'nullable|boolean',
87
+      'prezzo' => 'nullable|numeric',
88
+      'stato' => 'nullable|string',
89
+      'note' => 'nullable',
90
+      'immagine' => 'nullable|string|max:2048',
91
+      'posti' => 'nullable|integer',
92
+      'copertina' => 'nullable|string|max:2048',
93
+    ];
94
+  }
95
+
96
+  public function editMessages(): array{
97
+    return $this->messages;
98
+  }
99
+
100
+  /**
101
+  * Get remove action validation rules.
102
+  *
103
+  * @param Model $model
104
+  * @return array
105
+  */
106
+  public function removeRules(Model $model): array
107
+  {
108
+    return [];
109
+  }
110
+
111
+  public function creating(Model $model, array $data): array
112
+  {
113
+    // $model->roles()->sync([$data['ruolo_id']]);
114
+    return $data;
115
+  }
116
+
117
+  public function updating(Model $model, array $data): array
118
+  {
119
+    // dd($data['ruolo']);
120
+    // $model->roles()->sync([$data['ruolo_id']]);
121
+    return $data;
122
+  }
123
+
124
+  /**
125
+   * Dopo il salvataggio: se la locandina era in tmp (nuovo evento), spostala sotto eventi/{id}.
126
+   */
127
+  public function saved(Model $model, array $data): Model
128
+  {
129
+    if (! $model instanceof Evento) {
130
+      return $model;
131
+    }
132
+
133
+    $path = $model->immagine;
134
+    if (! is_string($path) || $path === '') {
135
+      return $model;
136
+    }
137
+
138
+    $tmpPrefix = $this->uploadDir; //$this->uploadDir.'/tmp/';
139
+    if (! str_starts_with($path, $tmpPrefix)) {
140
+      return $model;
141
+    }
142
+
143
+    $storage = Storage::disk($this->disk);
144
+    if (! $storage->exists($path)) {
145
+      return $model;
146
+    }
147
+
148
+    $basename = basename($path);
149
+    $destDir = $this->uploadDir.'/'.$model->getKey();
150
+    $destPath = $destDir.'/'.$basename;
151
+
152
+    $storage->makeDirectory($destDir);
153
+    if ($storage->exists($destPath)) {
154
+      $storage->delete($destPath);
155
+    }
156
+    $storage->move($path, $destPath);
157
+
158
+    $model->immagine = $destPath;
159
+    $model->saveQuietly();
160
+
161
+    return $model;
162
+  }
163
+
164
+  public function messages(): array
165
+  {
166
+    return $this->messages;
167
+  }
168
+
169
+  /**
170
+   * Regole validazione upload (campo Editor: immagine).
171
+   */
172
+  public function uploadRules(): array
173
+  {
174
+    return [
175
+      'immagine' => ['required', 'file', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:5120'],
176
+    ];
177
+  }
178
+
179
+  public function upload(Request $request): JsonResponse
180
+  {
181
+    $this->action = 'upload';
182
+
183
+    $field = $request->input('uploadField');
184
+    if (! $field || ! is_string($field)) {
185
+      $field = 'file';
186
+    }
187
+
188
+    try {
189
+      $storage = Storage::disk($this->disk);
190
+      $rules = $this->uploadRules();
191
+      $fieldRules = ['upload' => $rules[$field] ?? []];
192
+
193
+      $this->validate($request, $fieldRules, $this->messages(), $this->attributes());
194
+
195
+      /** @var UploadedFile $uploadedFile */
196
+      $uploadedFile = $request->file('upload');
197
+      $directory = $this->resolveUploadDirectory($request);
198
+      $filename = $this->getUploadedFilename($field, $uploadedFile);
199
+      $id = $storage->putFileAs($directory, $uploadedFile, $filename);
200
+
201
+      if (! is_string($id)) {
202
+        throw ValidationException::withMessages([
203
+          'upload' => 'Impossibile salvare il file caricato.',
204
+        ]);
205
+      }
206
+
207
+      $id = $this->uploaded($id);
208
+
209
+      return response()->json([
210
+        'action' => $this->action,
211
+        'data' => [],
212
+        'files' => [
213
+          'files' => [
214
+            $id => [
215
+              'filename' => $id,
216
+              'original_name' => $uploadedFile->getClientOriginalName(),
217
+              'size' => $uploadedFile->getSize(),
218
+              'directory' => $directory,
219
+              'disk' => $this->disk,
220
+              'url' => $storage->url($id),
221
+            ],
222
+          ],
223
+        ],
224
+        'upload' => [
225
+          'id' => $id,
226
+        ],
227
+      ]);
228
+    } catch (ValidationException $exception) {
229
+      return response()->json([
230
+        'action' => $this->action,
231
+        'data' => [],
232
+        'fieldErrors' => [
233
+          [
234
+            'name' => $field,
235
+            'status' => str_replace('upload', $field, (string) ($exception->errors()['upload'][0] ?? 'Errore di validazione')),
236
+          ],
237
+        ],
238
+      ]);
239
+    }
240
+  }
241
+
242
+  /**
243
+   * Sottocartella per riga (edit) o temporanea per nuovo evento.
244
+   */
245
+  protected function resolveUploadDirectory(Request $request): string
246
+  {
247
+    $id = $request->input('id');
248
+    if ($id !== null && $id !== '' && is_numeric($id)) {
249
+      return $this->uploadDir.'/'.(int) $id;
250
+    }
251
+
252
+    return $this->uploadDir; //$this->uploadDir.'/tmp';
253
+  }
254
+
255
+  protected function getUploadedFilename(string $field, UploadedFile $uploadedFile): string
256
+  {
257
+    $ext = $uploadedFile->getClientOriginalExtension();
258
+
259
+    return $field.'_'.time().'_'.Str::random(4).($ext !== '' ? '.'.$ext : '');
260
+  }
261
+}

+ 119
- 0
app/DataTables/FornitoreDataTable.php 파일 보기

@@ -0,0 +1,119 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Fornitore;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+use Illuminate\Support\Facades\Session;
16
+
17
+class FornitoreDataTable extends DataTable
18
+{
19
+    public function __construct()
20
+    {
21
+        $this->dataTableVariable = 'dataTable_fornitore';
22
+    }
23
+    /**
24
+     * Build the DataTable class.
25
+     *
26
+     * @param QueryBuilder<Fornitore> $query Results from query() method.
27
+     */
28
+    public function dataTable(QueryBuilder $query): EloquentDataTable
29
+    {
30
+        return (new EloquentDataTable($query))
31
+            ->addColumn('action', function($entity){
32
+              return view('fornitore.menu', ['entity' => $entity]);
33
+            })
34
+            ->setRowId('id');
35
+    }
36
+
37
+    /**
38
+     * Get the query source of dataTable.
39
+     *
40
+     * @return QueryBuilder<Fornitore>
41
+     */
42
+    public function query(Fornitore $model): QueryBuilder
43
+    {
44
+        return $model->newQuery()->where('attivita_id', session()->get('attivita_attuale'));
45
+    }
46
+
47
+    /**
48
+     * Optional method if you want to use the html builder.
49
+     */
50
+    public function html(): HtmlBuilder
51
+    {
52
+        $buttons = [];
53
+        if(Auth::user()->can('create-fornitore')){
54
+            array_push($buttons, Button::make('create')
55
+                ->editor('editor')
56
+                ->formTitle('Crea nuovo fornitore')
57
+                ->className('btn btn-sm btn-primary mb-4')
58
+                ->text('<i class="fas fa-plus"></i> Nuovo fornitore'));
59
+        }
60
+        return $this->builder()
61
+                    ->setTableId($this->dataTableVariable)
62
+                    ->columns($this->getColumns())
63
+                    ->minifiedAjax()
64
+                    ->orderBy(1)
65
+                    ->selectStyleSingle()
66
+                    ->language(asset('assets/Italian.json'))
67
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
68
+                    ->buttons($buttons)
69
+                    ->searchPanes(true)
70
+                    ->editor(
71
+                        Editor::make()
72
+                            ->fields([
73
+                                Fields\Text::make('nome')->label('Nome'),
74
+                                Fields\Text::make('email')->label('Email'),
75
+                                Fields\Text::make('telefono')->label('Telefono'),
76
+                                Fields\Text::make('indirizzo')->label('Indirizzo'),
77
+                                Fields\Text::make('citta')->label('Città'),
78
+                                Fields\Text::make('provincia')->label('Provincia'),
79
+                                Fields\Text::make('cap')->label('CAP'),
80
+                                Fields\Text::make('paese')->label('Paese'),
81
+                            ])
82
+                    )
83
+                    ->initComplete("function(settings, json){
84
+                        initComplete_fornitore();
85
+                    }");
86
+    }
87
+
88
+    /**
89
+     * Get the dataTable columns definition.
90
+     */
91
+    public function getColumns(): array
92
+    {
93
+        return [
94
+            Column::make('id')->visible(false),
95
+            Column::make('nome'),
96
+            Column::make('email'),
97
+            Column::make('telefono'),
98
+            Column::make('indirizzo'),
99
+            Column::make('citta'),
100
+            Column::make('provincia'),
101
+            Column::make('cap'),
102
+            Column::make('paese'),
103
+            Column::computed('action')
104
+                ->title('')
105
+                ->exportable(false)
106
+                ->printable(false)
107
+                ->width(60)
108
+                ->addClass('text-center'),
109
+        ];
110
+    }
111
+
112
+    /**
113
+     * Get the filename for export.
114
+     */
115
+    protected function filename(): string
116
+    {
117
+        return 'Fornitore_' . date('YmdHis');
118
+    }
119
+}

+ 106
- 0
app/DataTables/FornitoreDataTableEditor.php 파일 보기

@@ -0,0 +1,106 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Fornitore;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class FornitoreDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Fornitore::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'email.required' => 'L\'email è richiesta',
23
+    'telefono.required' => 'Il telefono è richiesto',
24
+    'indirizzo.required' => 'L\'indirizzo è richiesto',
25
+    'citta.required' => 'La città è richiesta',
26
+    'provincia.required' => 'La provincia è richiesta',
27
+    'cap.required' => 'Il CAP è richiesto',
28
+    'paese.required' => 'Il paese è richiesto',
29
+  ];
30
+
31
+  /**
32
+  * Get create action validation rules.
33
+  *
34
+  * @return array
35
+  */
36
+  public function createRules(): array
37
+  {
38
+    return [
39
+      'nome'  => 'required',
40
+      'email' => 'required|email',
41
+      'telefono' => 'required',
42
+      'indirizzo' => 'required',
43
+      'citta' => 'required',
44
+      'provincia' => 'required',
45
+      'cap' => 'required',
46
+      'paese' => 'required',
47
+    ];
48
+  }
49
+
50
+  public function createMessages(): array{
51
+    return $this->messages;
52
+  }
53
+
54
+  /**
55
+  * Get edit action validation rules.
56
+  *
57
+  * @param Model $model
58
+  * @return array
59
+  */
60
+  public function editRules(Model $model): array
61
+  {
62
+    return [
63
+      'nome'  => 'required',
64
+      'email' => 'nullable|email',
65
+      'telefono' => 'nullable',
66
+      'indirizzo' => 'required',
67
+      'citta' => 'nullable',
68
+      'provincia' => 'nullable',
69
+      'cap' => 'nullable',
70
+      'paese' => 'nullable',
71
+    ];
72
+  }
73
+
74
+  public function editMessages(): array{
75
+    return $this->messages;
76
+  }
77
+
78
+  /**
79
+  * Get remove action validation rules.
80
+  *
81
+  * @param Model $model
82
+  * @return array
83
+  */
84
+  public function removeRules(Model $model): array
85
+  {
86
+    return [];
87
+  }
88
+
89
+  public function creating(Model $model, array $data): array
90
+  {
91
+    // $model->roles()->sync([$data['ruolo_id']]);
92
+    return $data;
93
+  }
94
+
95
+  public function updating(Model $model, array $data): array
96
+  {
97
+    // dd($data['ruolo']);
98
+    // $model->roles()->sync([$data['ruolo_id']]);
99
+    return $data;
100
+  }
101
+  public function messages(): array
102
+  {
103
+    return $this->messages;
104
+  }
105
+
106
+}

+ 119
- 0
app/DataTables/MetodoPagamentoDataTable.php 파일 보기

@@ -0,0 +1,119 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\MetodoPagamento;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+use App\Models\Attivita;
16
+
17
+
18
+class MetodoPagamentoDataTable extends DataTable
19
+{
20
+    public function __construct()
21
+    {
22
+        $this->dataTableVariable = 'dataTable_metodo_pagamento';
23
+    }
24
+    /**
25
+     * Build the DataTable class.
26
+     *
27
+     * @param QueryBuilder<MetodoPagamento> $query Results from query() method.
28
+     */
29
+    public function dataTable(QueryBuilder $query): EloquentDataTable
30
+    {
31
+        return (new EloquentDataTable($query))
32
+            ->addColumn('action', function($entity){
33
+                return view('metodo_pagamento.menu', ['entity' => $entity]);
34
+            })
35
+            ->addColumn('is_attivo_display', function($entity){
36
+                return view('_partials.available', ['available' => $entity->is_attivo]);
37
+            })
38
+            ->addColumn('is_pubblico_display', function($entity){
39
+                return view('_partials.available', ['available' => $entity->is_pubblico]);
40
+            })
41
+            ->setRowId('id');
42
+    }
43
+
44
+    /**
45
+     * Get the query source of dataTable.
46
+     *
47
+     * @return QueryBuilder<MetodoPagamento>
48
+     */
49
+    public function query(MetodoPagamento $model): QueryBuilder
50
+    {
51
+        return $model->newQuery();
52
+    }
53
+
54
+    /**
55
+     * Optional method if you want to use the html builder.
56
+     */
57
+    public function html(): HtmlBuilder
58
+    {
59
+        $buttons = [];
60
+        if(Auth::user()->can('create-metodo_pagamento')){
61
+            array_push($buttons, Button::make('create')
62
+                ->editor('editor')
63
+                ->className('btn btn-sm btn-primary mb-4')
64
+                ->formTitle('Crea nuovo metodo di pagamento')
65
+                ->text('<i class="fas fa-plus"></i> Nuovo metodo di pagamento'));
66
+        }
67
+
68
+        return $this->builder()
69
+                    ->setTableId($this->dataTableVariable)
70
+                    ->columns($this->getColumns())
71
+                    ->minifiedAjax()
72
+                    ->language(asset('assets/Italian.json'))
73
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
74
+                    ->buttons($buttons)
75
+                    ->orderBy(1)
76
+                    ->selectStyleSingle()
77
+                    ->editor(
78
+                        Editor::make()
79
+                            ->fields([
80
+                                Fields\Select2::make('tipo')->label('Tipo')->options(MetodoPagamento::getTipiPagamento()->pluck('value' ,'label')->sortBy('label')),
81
+                                Fields\Text::make('nome')->label('Nome'),
82
+                                Fields\Text::make('descrizione')->label('Descrizione'),
83
+                                Fields\Boolean::make('is_attivo')->label('Attivo')->default(true),
84
+                                Fields\Boolean::make('is_pubblico')->label('Pubblico')->default(false),
85
+                                Fields\Text::make('key')->label('Key'),
86
+                                Fields\Text::make('secret')->label('Secret'),
87
+                                Fields\Text::make('path_img')->label('Path immagine'),
88
+                                Fields\Text::make('info')->label('Info'),
89
+                                Fields\Select2::make('attivita_id')->label('Attività')->options(Attivita::all()->pluck('id', 'nome')),
90
+                            ])
91
+                    )
92
+                    ->initComplete("function(settings, json){
93
+                        initComplete_metodo_pagamento();
94
+                    }");
95
+    }
96
+
97
+    /**
98
+     * Get the dataTable columns definition.
99
+     */
100
+    public function getColumns(): array
101
+    {
102
+        return [
103
+            Column::make('id')->title('ID')->width('10%')->visible(false),
104
+            Column::make('is_attivo')->data('is_attivo_display')->title('Attivo')->addClass('text-center w-10'),
105
+            Column::make('is_pubblico')->data('is_pubblico_display')->title('Pubblico')->addClass('text-center w-10'),
106
+            Column::make('nome')->title('Nome'),
107
+            Column::make('descrizione')->title('Descrizione'),
108
+            Column::computed('action')->title('')->width('10%')->addClass('text-center'),   
109
+        ];
110
+    }
111
+
112
+    /**
113
+     * Get the filename for export.
114
+     */
115
+    protected function filename(): string
116
+    {
117
+        return 'MetodoPagamento_' . date('YmdHis');
118
+    }
119
+}

+ 108
- 0
app/DataTables/MetodoPagamentoDataTableEditor.php 파일 보기

@@ -0,0 +1,108 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\MetodoPagamento;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class  MetodoPagamentoDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = MetodoPagamento::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'tipo.required' => 'Il tipo è richiesto',
23
+    'is_attivo.required' => 'Indicare una delle due opzioni',
24
+    'is_pubblico.required' => 'Indicare una delle due opzioni',
25
+  ];
26
+
27
+  /**
28
+  * Get create action validation rules.
29
+  *
30
+  * @return array
31
+  */
32
+  public function createRules(): array
33
+  {
34
+    return [
35
+      'nome'  => 'required',
36
+      'tipo' => 'required|in:'.MetodoPagamento::getTipiPagamento()->pluck('value')->implode(','),
37
+      // 'is_attivo' => 'boolean',
38
+      // 'is_pubblico' => 'boolean',
39
+      'key' => 'nullable',
40
+      'secret' => 'nullable',
41
+      'path_img' => 'nullable',
42
+      'info' => 'nullable',
43
+    ];
44
+  }
45
+
46
+  public function createMessages(): array{
47
+    return $this->messages;
48
+  }
49
+
50
+  /**
51
+  * Get edit action validation rules.
52
+  *
53
+  * @param Model $model
54
+  * @return array
55
+  */
56
+  public function editRules(Model $model): array
57
+  {
58
+    return [
59
+      'nome'  => 'required',
60
+      'tipo' => 'required|in:'.MetodoPagamento::getTipiPagamento()->pluck('value')->implode(','),
61
+      'attivita_id' => 'required|exists:attivita,id',
62
+      // 'is_attivo' => 'boolean',
63
+      // 'is_pubblico' => 'boolean',
64
+      'key' => 'nullable',
65
+      'secret' => 'nullable',
66
+      'path_img' => 'nullable',
67
+      'info' => 'nullable',
68
+    ];
69
+  }
70
+
71
+  public function editMessages(): array{
72
+    return $this->messages;
73
+  }
74
+
75
+  /**
76
+  * Get remove action validation rules.
77
+  *
78
+  * @param Model $model
79
+  * @return array
80
+  */
81
+  public function removeRules(Model $model): array
82
+  {
83
+    return [];
84
+  }
85
+
86
+  public function creating(Model $model, array $data): array
87
+  {
88
+    // $model->roles()->sync([$data['ruolo_id']]);
89
+    $data['is_attivo'] = isset($data['is_attivo']) ? true : false;
90
+    $data['is_pubblico'] = isset($data['is_pubblico']) ? true : false;
91
+    return $data;
92
+  }
93
+
94
+  public function updating(Model $model, array $data): array
95
+  {
96
+    // dd($data['ruolo']);
97
+    // $model->roles()->sync([$data['ruolo_id']]);
98
+    $data['is_attivo'] = isset($data['is_attivo']) ? true : false;
99
+    $data['is_pubblico'] = isset($data['is_pubblico']) ? true : false;
100
+    return $data;
101
+  }
102
+
103
+  public function messages(): array
104
+  {
105
+    return $this->messages;
106
+  }
107
+
108
+}

+ 121
- 0
app/DataTables/MonitorDataTable.php 파일 보기

@@ -0,0 +1,121 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Dispositivo;
6
+use App\Models\Attivita;
7
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
8
+use Yajra\DataTables\EloquentDataTable;
9
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
10
+use Yajra\DataTables\Html\Button;
11
+use Yajra\DataTables\Html\Column;
12
+use Yajra\DataTables\Html\Editor\Editor;
13
+use Yajra\DataTables\Html\Editor\Fields;
14
+use Yajra\DataTables\Services\DataTable;
15
+use Illuminate\Support\Facades\Auth;
16
+use Illuminate\Support\Facades\Session;
17
+
18
+class MonitorDataTable extends DataTable
19
+{
20
+    public function __construct()
21
+    {
22
+        $this->dataTableVariable = 'dataTable_monitor';
23
+    }
24
+    /**
25
+     * Build the DataTable class.
26
+     *
27
+     * @param QueryBuilder<Monitor> $query Results from query() method.
28
+     */
29
+    public function dataTable(QueryBuilder $query): EloquentDataTable
30
+    {
31
+        return (new EloquentDataTable($query))
32
+            ->addColumn('action', function($entity){
33
+                return view('monitor.menu', ['entity' => $entity]);
34
+            })
35
+            ->addColumn('is_attivo_display', function($entity){
36
+                return view('_partials.available', ['available' => $entity->is_attivo]);
37
+            })
38
+            ->addColumn('attivita_id_display', function($entity){
39
+                return $entity->attivita ? $entity->attivita->nome : 'ND';
40
+            })
41
+            ->setRowId('id');
42
+    }
43
+
44
+    /**
45
+     * Get the query source of dataTable.
46
+     *
47
+     * @return QueryBuilder<Monitor>
48
+     */
49
+    public function query(Dispositivo $model): QueryBuilder
50
+    {
51
+        return $model->newQuery()->where('tipo', Dispositivo::MONITOR);
52
+    }
53
+
54
+    /**
55
+     * Optional method if you want to use the html builder.
56
+     */
57
+    public function html(): HtmlBuilder
58
+    {
59
+        $buttons = [];
60
+        if(Auth::user()->can('create-monitor')){
61
+            array_push($buttons, Button::make('create')
62
+                ->editor('editor')
63
+                ->formTitle('Crea nuovo monitor')
64
+                ->className('btn btn-sm btn-primary mb-4')
65
+                ->text('<i class="fas fa-plus"></i> Nuovo monitor'));
66
+        }
67
+        return $this->builder()
68
+                    ->setTableId($this->dataTableVariable)
69
+                    ->columns($this->getColumns())
70
+                    ->minifiedAjax()
71
+                    ->language(asset('assets/Italian.json'))
72
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
73
+                    ->buttons($buttons)
74
+                    ->editor(
75
+                        Editor::make()
76
+                            ->fields([
77
+                                Fields\Text::make('nome')->label('Nome'),
78
+                                Fields\Boolean::make('is_attivo')->label('Attivo')->default(true),
79
+                                Fields\Hidden::make('tipo')->label('Tipo')->default(Dispositivo::MONITOR),
80
+                                Fields\Select2::make('attivita_id')->label('Attività')->options(Attivita::where('is_attiva', true)->pluck('id', 'nome')),
81
+                                Fields\Text::make('licenza')->label('Licenza'),
82
+                                Fields\Text::make('ubicazione')->label('Ubicazione'),
83
+                                Fields\Text::make('note')->label('Note'),
84
+                                // Fields\Text::make('pin_sblocco')->label('Pin di sblocco'),
85
+                                // Fields\DateTime::make('data_apertura_dispositivo')->label('Data di apertura del dispositivo'),
86
+                                // Fields\DateTime::make('data_chiusura_dispositivo')->label('Data di chiusura del dispositivo'),
87
+                            ])
88
+                    )
89
+                    ->responsive(true)
90
+                    ->orderBy(1)
91
+                    ->selectStyleSingle()
92
+                    ->initComplete("function(settings, json){
93
+                        initComplete_monitor();
94
+                    }");
95
+    }
96
+
97
+    /**
98
+     * Get the dataTable columns definition.
99
+     */
100
+    public function getColumns(): array
101
+    {
102
+        return [
103
+            Column::make('id')->visible(false),
104
+            Column::make('is_attivo')->data('is_attivo_display')->title('Disponibile'),
105
+            Column::make('attivita_id')->title('Attività')->data('attivita_id_display'),
106
+            Column::make('nome'),
107
+            Column::make('licenza'),
108
+            Column::make('ubicazione'),
109
+            Column::make('note')->visible(false),
110
+            Column::computed('action')->title('')->width('10%')->addClass('text-center'),
111
+        ];
112
+    }
113
+
114
+    /**
115
+     * Get the filename for export.
116
+     */
117
+    protected function filename(): string
118
+    {
119
+        return 'Monitor_' . date('YmdHis');
120
+    }
121
+}

+ 126
- 0
app/DataTables/MonitorDataTableEditor.php 파일 보기

@@ -0,0 +1,126 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Dispositivo;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class MonitorDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Dispositivo::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'tipo.required' => 'Il tipo è richiesto',
23
+    'attivita_id.required' => 'La attività è richiesta',
24
+    'licenza.required' => 'La licenza è richiesta',
25
+    'url_stampante.required' => 'L\'URL della stampante è richiesta',
26
+    'ubicazione.required' => 'L\'ubicazione è richiesta',
27
+    'note.required' => 'La note è richiesta',
28
+    'is_attivo.required' => 'Indicare una delle due opzioni',
29
+    'pin_sblocco.required' => 'Il pin di sblocco è richiesto',
30
+    'data_apertura_dispositivo.required' => 'La data di apertura del dispositivo è richiesta',
31
+    'data_chiusura_dispositivo.required' => 'La data di chiusura del dispositivo è richiesta',
32
+    'data_apertura_dispositivo.date' => 'La data di apertura del dispositivo deve essere una data valida',
33
+    'data_chiusura_dispositivo.date' => 'La data di chiusura del dispositivo deve essere una data valida',
34
+    'is_attivo.boolean' => 'Indicare una delle due opzioni',
35
+    'pin_sblocco.string' => 'Il pin di sblocco deve essere una stringa',
36
+    'pin_sblocco.required' => 'Il pin di sblocco è richiesto',
37
+    'pin_sblocco.min' => 'Il pin di sblocco deve essere lungo almeno 4 caratteri',
38
+    'pin_sblocco.max' => 'Il pin di sblocco deve essere lungo al massimo 4 caratteri',
39
+    'pin_sblocco.regex' => 'Il pin di sblocco deve contenere solo numeri',
40
+    'pin_sblocco.unique' => 'Il pin di sblocco deve essere unico',
41
+  ];
42
+
43
+  /**
44
+  * Get create action validation rules.
45
+  *
46
+  * @return array
47
+  */
48
+  public function createRules(): array
49
+  {
50
+    return [
51
+      'nome'  => 'required',
52
+      'tipo' => 'required|in:'.Dispositivo::MONITOR,
53
+      'attivita_id' => 'required|exists:attivita,id',
54
+      'licenza' => 'nullable',
55
+      'url_stampante' => 'nullable',
56
+      'ubicazione' => 'nullable',
57
+      'note' => 'nullable',
58
+      'is_attivo' => 'boolean',
59
+      'pin_sblocco' => 'nullable',
60
+      'data_apertura_dispositivo' => 'nullable|date',
61
+      'data_chiusura_dispositivo' => 'nullable|date',
62
+    ];
63
+  }
64
+
65
+  public function createMessages(): array{
66
+    return $this->messages;
67
+  }
68
+
69
+  /**
70
+  * Get edit action validation rules.
71
+  *
72
+  * @param Model $model
73
+  * @return array
74
+  */
75
+  public function editRules(Model $model): array
76
+  {
77
+    return [
78
+      'nome'  => 'required',
79
+      'tipo' => 'required|in:'.Dispositivo::MONITOR,
80
+      'attivita_id' => 'required|exists:attivita,id',
81
+      'licenza' => 'nullable',
82
+      'url_stampante' => 'nullable',
83
+      'ubicazione' => 'nullable',
84
+      'note' => 'nullable',
85
+      'is_attivo' => 'boolean',
86
+      'pin_sblocco' => 'nullable',
87
+      'data_apertura_dispositivo' => 'nullable|date',
88
+      'data_chiusura_dispositivo' => 'nullable|date',
89
+    ];
90
+  }
91
+
92
+  public function editMessages(): array{
93
+    return $this->messages;
94
+  }
95
+
96
+  /**
97
+  * Get remove action validation rules.
98
+  *
99
+  * @param Model $model
100
+  * @return array
101
+  */
102
+  public function removeRules(Model $model): array
103
+  {
104
+    return [];
105
+  }
106
+
107
+  public function creating(Model $model, array $data): array
108
+  {
109
+    // $model->roles()->sync([$data['ruolo_id']]);
110
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
111
+    return $data;
112
+  }
113
+
114
+  public function updating(Model $model, array $data): array
115
+  {
116
+    // dd($data['ruolo']);
117
+    // $model->roles()->sync([$data['ruolo_id']]);
118
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
119
+    return $data;
120
+  }
121
+  public function messages(): array
122
+  {
123
+    return $this->messages;
124
+  }
125
+
126
+}

+ 160
- 0
app/DataTables/OrdineDataTable.php 파일 보기

@@ -0,0 +1,160 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Ordine;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+
16
+class OrdineDataTable extends DataTable
17
+{
18
+    public function __construct()
19
+    {
20
+        $this->dataTableVariable = 'dataTable_ordine';
21
+    }
22
+    /**
23
+     * Build the DataTable class.
24
+     *
25
+     * @param QueryBuilder<Ordine> $query Results from query() method.
26
+     */
27
+    public function dataTable(QueryBuilder $query): EloquentDataTable
28
+    {
29
+        return (new EloquentDataTable($query))
30
+            ->addColumn('action', function($entity){
31
+                return view('ordine.menu', ['entity' => $entity]);
32
+            })
33
+            ->addColumn('prenotazione_id_display', function($entity){
34
+
35
+                if(isset($entity->prenotazione)){
36
+                    return view('prenotazione._partials.btn-link', ['prenotazione' => $entity->prenotazione]);
37
+                } else {
38
+                    return view('_partials.available', ['available' => false]);
39
+                }
40
+            })
41
+            ->addColumn('stato_display', function($entity){
42
+                return view('prenotazione._partials.stato-prenotazione', ['stato' => $entity->stato]);
43
+            })
44
+            ->addColumn('totale', function($entity){
45
+                return $entity->totale;
46
+            })
47
+            ->addColumn('note', function($entity){
48
+                return $entity->note;
49
+            })
50
+            ->addColumn('prezzo_display', function($entity){
51
+                return '€ ' . number_format($entity->prezzo, 2, ',', '.');
52
+            })
53
+            ->addColumn('info_display', function($entity){
54
+                if($entity->info == null){
55
+                    return 'ND';
56
+                }
57
+                $info = json_encode($entity->info);
58
+                $infoArr = json_decode($info, true);
59
+                $cliente = $infoArr['cliente'] ?? 'ND';
60
+                $tavolo = $infoArr['tavolo'] ?? 'ND';
61
+                return 'Cliente: ' . $cliente . ' - Tavolo: ' . $tavolo;
62
+            })
63
+            ->setRowId('id');
64
+    }
65
+
66
+    /**
67
+     * Get the query source of dataTable.
68
+     *
69
+     * @return QueryBuilder<Ordine>
70
+     */
71
+    public function query(Ordine $model): QueryBuilder
72
+    {
73
+       if(request()->has('carrelli_aperti')){
74
+        $query = $model->newQuery()
75
+        ->where('attivita_id' , session()->get('attivita_attuale'))
76
+        ->where('stato', Ordine::CARRELLO)
77
+        ->orderBy('created_at', 'desc');
78
+    // dd($query->get());
79
+    return $query;
80
+       }else{
81
+        $query = $model->newQuery()
82
+        ->where('attivita_id' , session()->get('attivita_attuale'))
83
+        ->where('stato', '!=', Ordine::CARRELLO)
84
+        ->orderBy('created_at', 'desc');
85
+    // dd($query->get());
86
+    return $query;
87
+    }
88
+    }
89
+
90
+    /**
91
+     * Optional method if you want to use the html builder.
92
+     */
93
+    public function html(): HtmlBuilder
94
+    {
95
+        $buttons = [];
96
+        if(Auth::user()->can('create-ordine')){
97
+            array_push($buttons, Button::make('create')
98
+                ->editor('editor')
99
+                ->className('btn btn-sm btn-primary mb-4')
100
+                ->formTitle('Crea nuovo ordine')
101
+                ->text('<i class="fas fa-plus"></i> Nuovo ordine'));
102
+        }
103
+        return $this->builder()
104
+                    ->setTableId($this->dataTableVariable)
105
+                    ->columns($this->getColumns())
106
+                    ->minifiedAjax()
107
+                    ->orderBy(2, 'asc')
108
+                    ->language(asset('assets/Italian.json'))
109
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
110
+                    ->selectStyleSingle()
111
+                    ->buttons($buttons)
112
+                    ->editor(
113
+                        Editor::make()
114
+                            ->fields([
115
+                                Fields\Text::make('riferimento')->label('Riferimento'),
116
+                                Fields\Text::make('prenotazione_id')->label('Prenotazione'),
117
+                                Fields\Select::make('tipo')->label('Tipo')->options(Ordine::getTipi()->pluck('value', 'label')),
118
+                                Fields\Select::make('stato')->label('Stato')->options(Ordine::getStati()->pluck('value', 'label')),
119
+                                Fields\Text::make('prezzo')->label('Prezzo'),
120
+                                Fields\Text::make('note')->label('Note'),
121
+                                Fields\Text::make('codice')->label('Codice'),
122
+                                // Fields\Select::make('pagamento_id')->label('Pagamento')->options(Pagamento::all()->pluck('nome', 'id')),
123
+                                Fields\Text::make('info')->label('Info'),
124
+                            ])
125
+                    )
126
+                    ->initComplete("function(settings, json){
127
+                        initComplete_ordine();
128
+                    }");
129
+    }
130
+
131
+    /**
132
+     * Get the dataTable columns definition.
133
+     */
134
+    public function getColumns(): array
135
+    {
136
+        return [
137
+            Column::make('id')->title('ID')->addClass('text-center w-10'),
138
+            Column::make('stato')->data('stato_display')->title('Stato'),
139
+            Column::make('riferimento')->title('Riferimento'),
140
+            Column::make('prenotazione_id')->data('prenotazione_id_display')->title('Prenotazione'),
141
+            Column::make('prezzo')->title('Totale')->data('prezzo_display'),
142
+            Column::make('note')->title('Note'),
143
+            Column::make('info')->title('Info')->data('info_display'),
144
+            Column::computed('action')
145
+                  ->title('')
146
+                  ->exportable(false)
147
+                  ->printable(false)
148
+                  ->width(60)
149
+                  ->addClass('text-center')
150
+        ];
151
+    }
152
+
153
+    /**
154
+     * Get the filename for export.
155
+     */
156
+    protected function filename(): string
157
+    {
158
+        return 'Ordine_' . date('YmdHis');
159
+    }
160
+}

+ 109
- 0
app/DataTables/OrdineDataTableEditor.php 파일 보기

@@ -0,0 +1,109 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Ordine;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class OrdineDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Ordine::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'riferimento.required' => 'Il riferimento è richiesto',
22
+    'prenotazione_id.required' => 'La prenotazione è richiesta',
23
+    'stato.required' => 'Il stato è richiesto',
24
+    'prezzo.required' => 'Il prezzo è richiesto',
25
+    'note.required' => 'La note è richiesta',
26
+    'codice.required' => 'Il codice è richiesto',
27
+    'stato_pagamento.required' => 'Il stato pagamento è richiesto',
28
+    'metodo_pagamento.required' => 'Il metodo pagamento è richiesto',
29
+    'info.required' => 'L\'info è richiesta',
30
+  ];
31
+
32
+  /**
33
+  * Get create action validation rules.
34
+  *
35
+  * @return array
36
+  */
37
+  public function createRules(): array
38
+  {
39
+    return [
40
+      'riferimento'  => 'required',
41
+      'prenotazione_id' => 'required|exists:prenotazione,id',
42
+      'stato' => 'required|string',
43
+      'prezzo' => 'required|numeric',
44
+      'note' => 'nullable',
45
+      'codice' => 'required|unique:ordine,codice',
46
+      'stato_pagamento' => 'nullable|string',
47
+      'metodo_pagamento' => 'nullable|string',
48
+      'info' => 'nullable|json',
49
+    ];
50
+  }
51
+
52
+  public function createMessages(): array{
53
+    return $this->messages;
54
+  }
55
+
56
+  /**
57
+  * Get edit action validation rules.
58
+  *
59
+  * @param Model $model
60
+  * @return array
61
+  */
62
+  public function editRules(Model $model): array
63
+  {
64
+    return [
65
+      'riferimento'  => 'required',
66
+      'prenotazione_id' => 'required|exists:prenotazione,id',
67
+      'stato' => 'required|string',
68
+      'prezzo' => 'required|numeric',
69
+      'note' => 'nullable',
70
+      'codice' => 'required|unique:ordine,codice',
71
+      'stato_pagamento' => 'nullable|string',
72
+      'metodo_pagamento' => 'nullable|string',
73
+      'info' => 'nullable|json',
74
+    ];
75
+  }
76
+
77
+  public function editMessages(): array{
78
+    return $this->messages;
79
+  }
80
+
81
+  /**
82
+  * Get remove action validation rules.
83
+  *
84
+  * @param Model $model
85
+  * @return array
86
+  */
87
+  public function removeRules(Model $model): array
88
+  {
89
+    return [];
90
+  }
91
+
92
+  public function creating(Model $model, array $data): array
93
+  {
94
+    // $model->roles()->sync([$data['ruolo_id']]);
95
+    return $data;
96
+  }
97
+
98
+  public function updating(Model $model, array $data): array
99
+  {
100
+    // dd($data['ruolo']);
101
+    // $model->roles()->sync([$data['ruolo_id']]);
102
+    return $data;
103
+  }
104
+  public function messages(): array
105
+  {
106
+    return $this->messages;
107
+  }
108
+
109
+}

+ 144
- 0
app/DataTables/PagamentoDataTable.php 파일 보기

@@ -0,0 +1,144 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Pagamento;
6
+use App\Models\Ordine;
7
+use App\Models\Prenotazione;
8
+use App\Models\MetodoPagamento;
9
+use App\Models\Attivita;
10
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
11
+use Yajra\DataTables\EloquentDataTable;
12
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
13
+use Yajra\DataTables\Html\Button;
14
+use Yajra\DataTables\Html\Column;
15
+use Yajra\DataTables\Html\Editor\Editor;
16
+use Yajra\DataTables\Html\Editor\Fields;
17
+use Yajra\DataTables\Services\DataTable;
18
+use Illuminate\Support\Facades\Auth;
19
+use Illuminate\Support\Facades\Session;
20
+
21
+class PagamentoDataTable extends DataTable
22
+{
23
+    public function __construct()
24
+    {
25
+        $this->dataTableVariable = 'dataTable_pagamento';
26
+    }
27
+    /**
28
+     * Build the DataTable class.
29
+     *
30
+     * @param QueryBuilder<Pagamento> $query Results from query() method.
31
+     */
32
+    public function dataTable(QueryBuilder $query): EloquentDataTable
33
+    {
34
+        return (new EloquentDataTable($query))
35
+            ->addColumn('action', function($entity){
36
+                return view('pagamento.menu', ['entity' => $entity]);
37
+            })
38
+            ->addColumn('ordine_id_display', function($entity){
39
+                return $entity->ordine->id;
40
+            })
41
+            ->addColumn('prenotazione_id_display', function($entity){
42
+                return $entity->prenotazione->id ?? '-';
43
+            })  
44
+            ->addColumn('importo_display', function($entity){
45
+                return '€ ' . number_format($entity->importo, 2, ',', '.');
46
+            })
47
+            ->addColumn('attivita_id_display', function($entity){
48
+                return $entity->attivita->nome;
49
+            })
50
+            ->addColumn('metodo_pagamento_id_display', function($entity){
51
+                return $entity->metodo_pagamento->nome;
52
+            })
53
+            ->addColumn('stato_display', function($entity){
54
+                // return $entity->stato;
55
+                return view('prenotazione._partials.stato-prenotazione', ['stato' => $entity->stato]);
56
+            })
57
+            ->setRowId('id');
58
+    }
59
+
60
+    /**
61
+     * Get the query source of dataTable.
62
+     *
63
+     * @return QueryBuilder<Pagamento>
64
+     */
65
+    public function query(Pagamento $model): QueryBuilder
66
+    {
67
+        return $model->newQuery()->where('attivita_id', session()->get('attivita_attuale'));
68
+    }
69
+
70
+    /**
71
+     * Optional method if you want to use the html builder.
72
+     */
73
+    public function html(): HtmlBuilder
74
+    {
75
+        $buttons = [];
76
+        if(Auth::user()->can('create-pagamento')){
77
+            array_push($buttons, Button::make('create')
78
+                ->editor('editor')
79
+                ->className('btn btn-sm btn-primary mb-4')
80
+                ->formTitle('Crea nuovo pagamento')
81
+                ->text('<i class="fas fa-plus"></i> Nuovo pagamento'));
82
+        }
83
+
84
+        return $this->builder()
85
+                    ->setTableId($this->dataTableVariable)
86
+                    ->columns($this->getColumns())
87
+                    ->minifiedAjax()
88
+                    ->language(asset('assets/Italian.json'))
89
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
90
+                    ->buttons($buttons)
91
+                    ->orderBy(1)
92
+                    ->selectStyleSingle()
93
+                    ->buttons($buttons)
94
+                    ->editor(
95
+                        Editor::make()
96
+                            ->fields([
97
+                                Fields\Text::make('attivita_id')->label('Attività')->options(Attivita::all()->pluck('nome', 'id')),
98
+                                Fields\Select2::make('ordine_id')->label('Ordine')->options(Ordine::all()->pluck('id', 'nome')),
99
+                                Fields\Select2::make('prenotazione_id')->label('Prenotazione')->options(Prenotazione::all()->pluck('id', 'nome')),
100
+                                Fields\Text::make('importo')->label('Importo'),
101
+                                Fields\Text::make('causale')->label('Causale'),
102
+                                Fields\Select2::make('stato')->label('Stato')->options(Pagamento::getStati()->pluck('value', 'label')),
103
+                                Fields\Select2::make('metodo_pagamento_id')->label('Metodo pagamento')->options(MetodoPagamento::all()->pluck('id', 'nome')),
104
+                                Fields\Text::make('note')->label('Note'),
105
+                                Fields\Text::make('info')->label('Info'),
106
+                            ])
107
+                    )
108
+                    ->initComplete("function(settings, json){
109
+                        initComplete_pagamento();
110
+                    }");
111
+    }
112
+
113
+    /**
114
+     * Get the dataTable columns definition.
115
+     */
116
+    public function getColumns(): array
117
+    {
118
+        return [
119
+            Column::make('id')->title('ID')->width('10%')->visible(false),
120
+            Column::make('stato')->title('Stato')->data('stato_display'),
121
+            Column::make('attivita_id')->title('Attività')->data('attivita_id_display'),
122
+            Column::make('ordine_id')->title('Ordine')->data('ordine_id_display'),
123
+            Column::make('prenotazione_id')->title('Prenotazione')->data('prenotazione_id_display'),
124
+            Column::make('importo')->title('Importo')->data('importo_display'),
125
+            Column::make('causale')->title('Causale'),
126
+            Column::make('metodo_pagamento_id')->title('Metodo pagamento')->data('metodo_pagamento_id_display'),
127
+            Column::make('note')->title('Note'),
128
+            Column::computed('action')
129
+                  ->title('')
130
+                  ->exportable(false)
131
+                  ->printable(false)
132
+                  ->width(60)
133
+                  ->addClass('text-center'),
134
+        ];
135
+    }
136
+
137
+    /**
138
+     * Get the filename for export.
139
+     */
140
+    protected function filename(): string
141
+    {
142
+        return 'Pagamento_' . date('YmdHis');
143
+    }
144
+}

+ 173
- 0
app/DataTables/PiattoDataTable.php 파일 보기

@@ -0,0 +1,173 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Piatto;
6
+use App\Models\Cucina;
7
+use App\Models\Menu;
8
+use App\Models\Allergene;
9
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
10
+use Yajra\DataTables\EloquentDataTable;
11
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
12
+use Yajra\DataTables\Html\Button;
13
+use Yajra\DataTables\Html\Column;
14
+use Yajra\DataTables\Html\Editor\Editor;
15
+use Yajra\DataTables\Html\Editor\Fields;
16
+use Yajra\DataTables\Services\DataTable;
17
+use Illuminate\Support\Facades\Auth;
18
+use Illuminate\Support\Facades\Session;
19
+
20
+class PiattoDataTable extends DataTable
21
+{
22
+    public function __construct()
23
+    {
24
+        $this->dataTableVariable = 'dataTable_piatto';
25
+    }
26
+    /**
27
+     * Build the DataTable class.
28
+     *
29
+     * @param QueryBuilder<Piatto> $query Results from query() method.
30
+     */
31
+    public function dataTable(QueryBuilder $query): EloquentDataTable
32
+    {
33
+        return (new EloquentDataTable($query))
34
+            ->addColumn('action', function ($entity) {
35
+                return view('piatto.menu', ['entity' => $entity]);
36
+            })
37
+            ->addColumn('is_attivo_display', function ($entity) {
38
+                return view('_partials.available', ['available' => $entity->is_attivo]);
39
+            })
40
+            ->addColumn('allergeni', function ($entity) {
41
+                // Serve all'Editor per precompilare `Fields\Tags` con array di ID.
42
+                return $entity->elencoAllergeni?->pluck('id')->values()->all() ?? [];
43
+            })
44
+            ->addColumn('allergeni_display', function ($entity) {
45
+                return $entity->elencoAllergeni->pluck('nome')->implode(', ');
46
+            })
47
+            ->addColumn('bacheca_id_display', function ($entity) {
48
+                return view('_partials.available', ['available' => $entity->bacheca_id]);
49
+            })
50
+            ->addColumn('in_evidenza_display', function ($entity) {
51
+                return view('_partials.available', ['available' => $entity->in_evidenza]);
52
+            })
53
+            ->addColumn('cucina_id_display', function ($entity) {
54
+                return $entity->cucina ? $entity->cucina->nome : '';
55
+            })
56
+            ->addColumn('prezzo_display', function ($entity) {
57
+                return '€ ' . number_format($entity->prezzo, 2, ',', '.');
58
+            })
59
+            ->setRowId('id');
60
+    }
61
+
62
+    /**
63
+     * Get the query source of dataTable.
64
+     *
65
+     * @return QueryBuilder<Piatto>
66
+     */
67
+    public function query(Piatto $model): QueryBuilder
68
+    {
69
+        if (isset($this->menu_id)) {
70
+
71
+            if (isset($this->cucina_id)) {
72
+                return $model->newQuery()
73
+                    // ->where('menu_id', $this->menu_id)
74
+                    ->where('cucina_id', $this->cucina_id)
75
+                    ->with('cucina', 'elencoAllergeni');
76
+            }
77
+            return $model->newQuery()
78
+                // ->where('menu_id', $this->menu_id)
79
+                ->with('cucina', 'elencoAllergeni');
80
+        }
81
+        return $model->newQuery()->where('attivita_id', session()->get('attivita_attuale'))->with('cucina', 'elencoAllergeni');
82
+    }
83
+
84
+    /**
85
+     * Optional method if you want to use the html builder.
86
+     */
87
+    public function html(): HtmlBuilder
88
+    {
89
+        $buttons = [];
90
+        if (Auth::user()->can('create-piatto')) {
91
+            array_push($buttons, Button::make('create')
92
+                ->editor('editor')
93
+                ->formTitle('Crea nuovo piatto')
94
+                ->className('btn btn-sm btn-primary mb-4')
95
+                ->text('<i class="fas fa-plus"></i> Nuovo piatto'));
96
+        }
97
+        if (isset($this->cucina_id)) {
98
+            array_push($buttons, Button::raw('<button class="btn btn-sm btn-secondary ml-2 mb-4" onclick="GoToAllPiatti()">
99
+                <i class="bx bx-dish"></i> Tutti i piatti
100
+            </button>'));
101
+        }
102
+        return $this->builder()
103
+            ->setTableId($this->dataTableVariable)
104
+            ->columns($this->getColumns())
105
+            ->minifiedAjax()
106
+            ->orderBy(1)
107
+            ->responsive()
108
+            // ->searchable(true)
109
+            ->selectStyleSingle()
110
+            ->language(asset('assets/Italian.json'))
111
+            ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
112
+            ->buttons($buttons)
113
+            ->searchPanes(true)
114
+            // ->ajax(route('piatto.store'))
115
+            ->editor(
116
+                Editor::make()
117
+                    ->fields([
118
+                        Fields\Text::make('nome')->label('Nome'),
119
+                        Fields\Text::make('descrizione')->label('Descrizione'),
120
+                        Fields\Select2::make('cucina_id')->label('cucina')->options(Cucina::where('is_attiva', true)->pluck('id', 'nome')),
121
+                        Fields\Text::make('prezzo')->label('Prezzo (€)'),
122
+                        Fields\Image::make('immagine')->label('Immagine'),
123
+                        Fields\Boolean::make('is_attivo')->label('Disponibile')->default(true),
124
+                        Fields\Select2::make('allergeni')->label('Allergeni')->multiple(true)
125
+                            ->options(Allergene::where('disponibile', true)->pluck('id', 'nome'))
126
+                            ->placeholder('Seleziona allergeni'),
127
+                        Fields\Boolean::make('bacheca_id')->label('Bacheca')->default(false),
128
+                        Fields\Boolean::make('in_evidenza')->label('In evidenza')->default(false),
129
+                    ])
130
+            )
131
+            ->initComplete("function(settings, json){
132
+                        initComplete_piatto();
133
+                    }");
134
+    }
135
+
136
+    /**
137
+     * Get the dataTable columns definition.
138
+     */
139
+    public function getColumns(): array
140
+    {
141
+        $columns = [
142
+            Column::make('id')->title('ID')->width('10%')->visible(false),
143
+            Column::make('is_attivo')->data('is_attivo_display')->title('Disponibile')->width('10%'),
144
+            // ID grezzi per Editor Select2 (stesso schema di disponibile vs disponibile_display)
145
+            Column::make('cucina_id')->data('cucina_id_display')->title('cucina')->addClass('text-center'),
146
+        ];
147
+
148
+
149
+        $columns = array_merge($columns, [
150
+
151
+            Column::make('nome')->title('Nome')->searchable(),
152
+            Column::computed('prezzo_display')->title('Prezzo')->addClass('text-center'),
153
+            Column::computed('cucina_id')->data('cucina_id_display')->title('Cucina')->addClass('text-center'), // icona in tabella
154
+            Column::computed('allergeni')->title('Allergeni')->visible(false), // valore grezzo per l'editor (array ID)
155
+            Column::computed('allergeni_display')->title('Allergeni')->visible(true),
156
+            Column::computed('bacheca_id_display')->title('Bacheca')->addClass('text-center'), // icona in tabella
157
+            Column::computed('in_evidenza_display')->title('In evidenza')->addClass('text-center'), // icona in tabella
158
+            Column::computed('action')->title('')->width('10%')->addClass('text-center'),
159
+
160
+        ]);
161
+        // dd($columns);
162
+
163
+        return $columns;
164
+    }
165
+
166
+    /**
167
+     * Get the filename for export.
168
+     */
169
+    protected function filename(): string
170
+    {
171
+        return 'Piatto_' . date('YmdHis');
172
+    }
173
+}

+ 169
- 0
app/DataTables/PiattoDataTableEditor.php 파일 보기

@@ -0,0 +1,169 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Piatto;
6
+use App\Models\PiattoHasAllergene;
7
+use Illuminate\Database\Eloquent\Model;
8
+use Illuminate\Validation\Rule;
9
+use Yajra\DataTables\DataTablesEditor;
10
+use Illuminate\Http\Request;
11
+use Illuminate\Validation\ValidationException;
12
+use Storage;
13
+use Illuminate\Support\Str;
14
+
15
+class PiattoDataTableEditor extends DataTablesEditor
16
+{
17
+  protected $model = Piatto::class;
18
+  // protected $uploadDir = '';
19
+  // protected $disk = 'modelliRicevute';
20
+
21
+  protected $messages = [
22
+    'nome.required' => 'Il nome è richiesto',
23
+    'descrizione.required' => 'La descrizione è richiesta',
24
+    'prezzo.required' => 'Il prezzo è richiesto',
25
+    'immagine.required' => 'L\'immagine è richiesta',
26
+    'disponibile.required' => 'Indicare una delle due opzioni',
27
+    'allergeni.required' => 'Indicare una delle due opzioni',
28
+    'bacheca_id.required' => 'Indicare una delle due opzioni',
29
+    'in_evidenza.required' => 'Indicare una delle due opzioni',
30
+    'cucina_id.required' => 'La cucina è richiesta',
31
+  ];
32
+
33
+  /**
34
+  * Get create action validation rules.
35
+  *
36
+  * @return array
37
+  */
38
+  public function createRules(): array
39
+  {
40
+    return [
41
+      'nome'  => 'required',
42
+      // 'descrizione' => 'required',
43
+      'prezzo' => 'required',
44
+      'cucina_id' => 'required|exists:cucina,id',
45
+      'immagine' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
46
+      'disponibile' => 'nullable|boolean', // unchecked = non inviato → null; normalizzato a false in creating()
47
+      'allergeni' => 'nullable|array',
48
+      'allergeni.*' => 'integer|exists:allergene,id',
49
+      'bacheca_id' => 'nullable|boolean',
50
+      'in_evidenza' => 'nullable|boolean',
51
+    ];
52
+  }
53
+
54
+  public function createMessages(): array{
55
+    return $this->messages;
56
+  }
57
+
58
+  /**
59
+  * Get edit action validation rules.
60
+  *
61
+  * @param Model $model
62
+  * @return array
63
+  */
64
+  public function editRules(Model $model): array
65
+  {
66
+    return [
67
+      'nome'  => 'required',
68
+      'descrizione' => 'nullable',
69
+      'cucina_id' => 'required|exists:cucina,id',
70
+      'prezzo' => 'required',
71
+      'immagine' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
72
+      'disponibile' => 'nullable|boolean',
73
+      'allergeni' => 'nullable|array',
74
+      'allergeni.*' => 'integer|exists:allergene,id',
75
+      'bacheca_id' => 'nullable|boolean',
76
+      'in_evidenza' => 'nullable|boolean',
77
+    ];
78
+  }
79
+
80
+  public function editMessages(): array{
81
+    return $this->messages;
82
+  }
83
+
84
+  /**
85
+  * Get remove action validation rules.
86
+  *
87
+  * @param Model $model
88
+  * @return array
89
+  */
90
+  public function removeRules(Model $model): array
91
+  {
92
+    return [];
93
+  }
94
+
95
+  public function creating(Model $model, array $data): array
96
+  {
97
+    // L'Editor manda `allergeni` come array di ID selezionati:
98
+    // salviamo la relazione nella pivot `piatto_allergene`, non nella colonna `piatto.allergeni`.
99
+    $data['_allergeni_ids'] = $this->normalizeAllergeniIds($data['allergeni'] ?? null);
100
+    unset($data['allergeni']);
101
+
102
+    $data['bacheca_id'] = isset($data['bacheca_id']) ? true : false;
103
+    $data['in_evidenza'] = isset($data['in_evidenza']) ? true : false;
104
+    $data['disponibile'] = isset($data['disponibile']) ? true : false;
105
+    return $data;
106
+  }
107
+
108
+  public function updating(Model $model, array $data): array
109
+  {
110
+    $data['_allergeni_ids'] = $this->normalizeAllergeniIds($data['allergeni'] ?? null);
111
+    unset($data['allergeni']);
112
+
113
+    $data['bacheca_id'] = isset($data['bacheca_id']) ? true : false;
114
+    $data['in_evidenza'] = isset($data['in_evidenza']) ? true : false;
115
+    $data['disponibile'] = isset($data['disponibile']) ? true : false;
116
+
117
+    return $data;
118
+  }
119
+
120
+  protected function normalizeAllergeniIds(null|array|string $value): array
121
+  {
122
+    if (is_null($value)) {
123
+      return [];
124
+    }
125
+
126
+    if (is_string($value)) {
127
+      $value = array_filter(array_map('trim', explode(',', $value)));
128
+    }
129
+
130
+    if (! is_array($value)) {
131
+      return [];
132
+    }
133
+
134
+    // Normalizza a int, rimuove vuoti e duplicati.
135
+    $value = array_values(array_unique(array_map(static fn ($id) => (int) $id, $value)));
136
+
137
+    return array_values(array_filter($value, static fn ($id) => $id > 0));
138
+  }
139
+
140
+  public function saved(Model $model, array $data): Model
141
+  {
142
+    if (! array_key_exists('_allergeni_ids', $data)) {
143
+      return $model;
144
+    }
145
+
146
+    $ids = $this->normalizeAllergeniIds($data['_allergeni_ids']);
147
+
148
+    // Re-sincronizza tutti gli allergeni per questo piatto.
149
+    PiattoHasAllergene::where('piatto_id', $model->id)->delete();
150
+
151
+    if (! empty($ids)) {
152
+      $rows = array_map(static function ($allergeneId) use ($model) {
153
+        return [
154
+          'piatto_id' => $model->id,
155
+          'allergene_id' => $allergeneId,
156
+        ];
157
+      }, $ids);
158
+
159
+      PiattoHasAllergene::insert($rows);
160
+    }
161
+
162
+    return $model;
163
+  }
164
+  public function messages(): array
165
+  {
166
+    return $this->messages;
167
+  }
168
+
169
+}

+ 167
- 0
app/DataTables/PrenotazioneDataTable.php 파일 보기

@@ -0,0 +1,167 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Prenotazione;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable; 
14
+use Illuminate\Support\Facades\Auth;
15
+use App\Models\Evento;
16
+use App\Models\Cucina;
17
+
18
+class PrenotazioneDataTable extends DataTable
19
+{
20
+    public function __construct()
21
+    {
22
+        $this->dataTableVariable = 'dataTable_prenotazione';
23
+ 
24
+    }
25
+    /**
26
+     * Build the DataTable class.
27
+     *
28
+     * @param QueryBuilder<Prenotazione> $query Results from query() method.
29
+     */
30
+    public function dataTable(QueryBuilder $query): EloquentDataTable
31
+    {
32
+        return (new EloquentDataTable($query))
33
+            ->addColumn('action', function($entity){
34
+              return view('prenotazione.menu', ['entity' => $entity]);
35
+            })
36
+            ->addColumn('evento_id_display', function($entity){
37
+              return $entity->evento->nome;
38
+            })
39
+            ->addColumn('cucina_id_display', function($entity){
40
+              return $entity->cucina->nome;
41
+            })
42
+            ->addColumn('stato_display', function($entity){
43
+              return view('prenotazione._partials.stato-prenotazione', ['stato' => $entity->stato]);
44
+            })
45
+            ->setRowId('id');
46
+    }
47
+
48
+    /**
49
+     * Get the query source of dataTable.
50
+     *
51
+     * @return QueryBuilder<Prenotazione>
52
+     */
53
+    public function query(Prenotazione $model): QueryBuilder
54
+    {
55
+        if(isset($this->evento_id)){
56
+            return $model->newQuery()->where('evento_id', $this->evento_id);
57
+        }
58
+        return $model->newQuery();
59
+    }
60
+
61
+    /**
62
+     * Optional method if you want to use the html builder.
63
+     */
64
+    public function html(): HtmlBuilder
65
+    {
66
+        $titoloPrenotazioni = 'Prenotazione';
67
+        if(isset($this->evento_id)){
68
+            $titoloPrenotazioni = 'Prenota per ' . Evento::find($this->evento_id)->nome;
69
+        }
70
+        $buttons = [];
71
+        if(Auth::user()->can('create-prenotazione')){
72
+            array_push($buttons, Button::make('create')
73
+                ->editor('editor')
74
+                ->className('btn btn-sm btn-primary mb-4')
75
+                ->formTitle('Crea nuovo prenotazione')
76
+                ->formButtons([
77
+                    Button::raw('Annulla')
78
+                        ->className('btn btn-secondary ml-2')
79
+                        ->actionClose(),
80
+                    Button::raw('Salva')
81
+                        ->className('btn btn-success ml-2')
82
+                        ->actionHandler('create')
83
+                ])
84
+                ->text('<i class="fas fa-plus"></i> ' . $titoloPrenotazioni));
85
+        };
86
+
87
+        if(Auth::user()->can('edit-prenotazione') || Auth::user()->can('segna-presenza-prenotazione')){
88
+            array_push($buttons, Button::raw('Appello')
89
+                ->className('btn btn-sm btn-warning mb-4')
90
+                ->action('appelloPrenotazioni')
91
+            );
92
+        }
93
+
94
+
95
+        //campi del form
96
+$fields = [
97
+    [
98
+        Fields\Text::make('nome')->label('Nome'),
99
+        Fields\Text::make('cognome')->label('Cognome'),
100
+        Fields\Text::make('email')->label('Email'),
101
+        Fields\Text::make('telefono')->label('Telefono'),
102
+        Fields\Select2::make('evento_id')->label('Evento')
103
+        ->options(Evento::where('is_attivo', true)->pluck('id', 'nome'))
104
+        ->default(isset($this->evento_id) ? $this->evento_id : ''),
105
+        Fields\Select2::make('cucina_id')->label('Cucina')->options(Cucina::all()->pluck('id', 'nome')),
106
+        Fields\Select2::make('stato')->label('Stato')->options(Prenotazione::getStati()->pluck('value', 'label'))->default(Prenotazione::STATO_IN_ATTESA) ,
107
+        Fields\Text::make('note')->label('Note'),
108
+        Fields\Text::make('codice')->label('Codice'),
109
+        Fields\Text::make('stato_pagamento')->label('Stato pagamento'),
110
+        Fields\Text::make('metodo_pagamento')->label('Metodo pagamento'),
111
+    ]
112
+];
113
+        // if(isset($this->evento_id)){
114
+        //     $fields[] = Fields\Select::make('evento_id')->label('Evento')->default($this->evento_id);
115
+        // }
116
+
117
+        return $this->builder()
118
+                    ->setTableId($this->dataTableVariable)
119
+                    ->columns($this->getColumns())
120
+                    ->minifiedAjax()
121
+                    ->orderBy(2, 'asc')
122
+                    ->selectStyleSingle()
123
+                    ->language(asset('assets/Italian.json'))
124
+                    ->dom('<"py-2"<"head-label text-center"><"dt-action-buttons"B>><"d-flex justify-content-between align-items-center row mb-2"<"col-sm-12 col-md-6"l><"col-sm-12 col-md-6"f>>t<"d-flex justify-content-between row"<"col-sm-12 col-md-6"i><"col-sm-12 col-md-6"p>>')
125
+                    // ->dom(count($buttons) == 0?  'rtip' : 'Bfrtip')
126
+                    ->buttons($buttons)
127
+                    ->editor(
128
+                        Editor::make()
129
+                            ->fields($fields)
130
+                    )
131
+                    ->initComplete("function(settings, json){
132
+                        initComplete_prenotazione();
133
+                    }");
134
+    }
135
+
136
+    /**
137
+     * Get the dataTable columns definition.
138
+     */
139
+    public function getColumns(): array
140
+    {
141
+        return [
142
+            Column::make('id')->title('ID')->width('10%')->visible(false),
143
+            Column::make('stato')->data('stato_display')->title('Stato')->searchable(true)->filter(true),
144
+            Column::make('cognome')->title('Cognome'),
145
+            Column::make('nome')->title('Nome'),
146
+            Column::make('email')->title('Email'),
147
+            Column::make('telefono')->title('Telefono'),
148
+            Column::make('evento_id_display')->title('Evento'),
149
+            Column::make('cucina_id_display')->title('Cucina'),
150
+            Column::make('note')->title('Note'),
151
+            Column::computed('action')
152
+                  ->title('')
153
+                  ->exportable(false)
154
+                  ->printable(false)
155
+                  ->width(60)
156
+                  ->addClass('text-center'),
157
+        ];
158
+    }
159
+
160
+    /**
161
+     * Get the filename for export.
162
+     */
163
+    protected function filename(): string
164
+    {
165
+        return 'Prenotazione_' . date('YmdHis');
166
+    }
167
+}

+ 110
- 0
app/DataTables/PrenotazioneDataTableEditor.php 파일 보기

@@ -0,0 +1,110 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Prenotazione;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class PrenotazioneDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Prenotazione::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'cognome.required' => 'Il cognome è richiesto',
23
+    'email.required' => 'L\'email è richiesta',
24
+    'telefono.required' => 'Il telefono è richiesto',
25
+    'evento_id.required' => 'L\'evento è richiesto',
26
+    'cucina_id.required' => 'La cucina è richiesta',
27
+    'stato.required' => 'Il stato è richiesto',
28
+    'note.required' => 'La note è richiesta',
29
+  ];
30
+
31
+  /**
32
+  * Get create action validation rules.
33
+  *
34
+  * @return array
35
+  */
36
+  public function createRules(): array
37
+  {
38
+    return [
39
+      'nome'  => 'required',
40
+      'cognome' => 'required',
41
+      'email' => 'nullable|email',
42
+      'telefono' => 'nullable',
43
+      'evento_id' => 'required|exists:evento,id',
44
+      'cucina_id' => 'required|exists:cucina,id',
45
+      'stato' => 'nullable|string',
46
+      'note' => 'nullable',
47
+      'codice' => 'required|unique:prenotazione,codice',
48
+      'stato_pagamento' => 'nullable|string',
49
+      'metodo_pagamento' => 'nullable|string',
50
+    ];
51
+  }
52
+
53
+  public function createMessages(): array{
54
+    return $this->messages;
55
+  }
56
+
57
+  /**
58
+  * Get edit action validation rules.
59
+  *
60
+  * @param Model $model
61
+  * @return array
62
+  */
63
+  public function editRules(Model $model): array
64
+  {
65
+    return [
66
+      'nome'  => 'required',
67
+      'cognome' => 'required',
68
+      'email' => 'nullable|email',
69
+      'telefono' => 'nullable',
70
+      'evento_id' => 'required|exists:evento,id',
71
+      'cucina_id' => 'required|exists:cucina,id',
72
+      'stato' => 'nullable|string',
73
+      'note' => 'nullable',
74
+      'codice' => 'required|unique:prenotazione,codice',
75
+    ];
76
+  }
77
+
78
+  public function editMessages(): array{
79
+    return $this->messages;
80
+  }
81
+
82
+  /**
83
+  * Get remove action validation rules.
84
+  *
85
+  * @param Model $model
86
+  * @return array
87
+  */
88
+  public function removeRules(Model $model): array
89
+  {
90
+    return [];
91
+  }
92
+
93
+  public function creating(Model $model, array $data): array
94
+  {
95
+    // $model->roles()->sync([$data['ruolo_id']]);
96
+    return $data;
97
+  }
98
+
99
+  public function updating(Model $model, array $data): array
100
+  {
101
+    // dd($data['ruolo']);
102
+    // $model->roles()->sync([$data['ruolo_id']]);
103
+    return $data;
104
+  }
105
+  public function messages(): array
106
+  {
107
+    return $this->messages;
108
+  }
109
+
110
+}

+ 122
- 0
app/DataTables/PrimaNotaDataTable.php 파일 보기

@@ -0,0 +1,122 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\PrimaNota;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+
16
+class PrimaNotaDataTable extends DataTable
17
+{
18
+    public function __construct()
19
+    {
20
+        $this->dataTableVariable = 'dataTable_primanota';
21
+    }
22
+    /**
23
+     * Build the DataTable class.
24
+     *
25
+     * @param QueryBuilder<PrimaNotum> $query Results from query() method.
26
+     */
27
+    public function dataTable(QueryBuilder $query): EloquentDataTable
28
+    {
29
+        return (new EloquentDataTable($query))
30
+            ->addColumn('action', function($entity){
31
+                return view('primanota.menu', ['entity' => $entity]);
32
+            })
33
+            ->setRowId('id');
34
+    }
35
+
36
+    /**
37
+     * Get the query source of dataTable.
38
+     *
39
+     * @return QueryBuilder<PrimaNota>
40
+     */
41
+    public function query(PrimaNota $model): QueryBuilder
42
+    {
43
+        return $model->newQuery();
44
+    }
45
+
46
+    /**
47
+     * Optional method if you want to use the html builder.
48
+     */
49
+    public function html(): HtmlBuilder
50
+    {
51
+        $buttons = [];
52
+        if(Auth::user()->can('create-primanota')){
53
+            array_push($buttons, Button::make('create')
54
+                ->editor('editor')
55
+                ->className('btn btn-sm btn-primary mb-4')
56
+                ->formTitle('Crea nuovo prima nota')
57
+                ->text('<i class="fas fa-plus"></i> Nuova prima nota'));
58
+        }
59
+        return $this->builder()
60
+                    ->setTableId($this->dataTableVariable)
61
+                    ->columns($this->getColumns())
62
+                    ->minifiedAjax()
63
+                    ->language(asset('assets/Italian.json'))
64
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
65
+                    ->buttons($buttons)
66
+                    ->orderBy(1)    
67
+                    ->selectStyleSingle()
68
+                    ->buttons($buttons)
69
+                    ->editor(
70
+                        Editor::make()
71
+                            ->fields([
72
+                                Fields\Text::make('nome')->label('Nome'),
73
+                                Fields\Text::make('descrizione')->label('Descrizione'),
74
+                                // Fields\Select2::make('stato')->label('Stato')->options(PrimNota::getStati()->pluck('value', 'label')),
75
+                                Fields\Select2::make('tipo_movimento')->label('Tipo movimento')->options(PrimaNota::getTipiMovimento()->pluck('value', 'label')),
76
+                                Fields\Text::make('causale')->label('Causale'),
77
+                                Fields\Text::make('note')->label('Note'),
78
+                                Fields\Text::make('stato_pagamento')->label('Stato pagamento'),
79
+                                Fields\Text::make('metodo_pagamento')->label('Metodo pagamento'),
80
+                                Fields\Text::make('info')->label('Info'),
81
+                            ])
82
+                    )
83
+                    ->initComplete("function(settings, json){
84
+                        initComplete_primanota();
85
+                    }");
86
+    }
87
+
88
+    /**
89
+     * Get the dataTable columns definition.
90
+     */
91
+    public function getColumns(): array
92
+    {
93
+        return [
94
+            Column::make('id')->title('ID')->width('10%')->visible(false),
95
+            Column::make('attivita_id')->title('Attività')->data('attivita_id_display'),
96
+            Column::make('pagamento_id')->title('Pagamento')->data('pagamento_id_display'),
97
+            Column::make('ordine_id')->title('Ordine')->data('ordine_id_display'),
98
+            Column::make('prenotazione_id')->title('Prenotazione')->data('prenotazione_id_display'),
99
+            Column::make('evento_id')->title('Evento')->data('evento_id_display'),
100
+            Column::make('fornitore_id')->title('Fornitore')->data('fornitore_id_display'),
101
+            Column::make('riferimento')->title('Riferimento'),
102
+            Column::make('importo')->title('Importo'),
103
+            Column::make('tipo_movimento')->title('Tipo movimento'),
104
+            Column::make('causale')->title('Causale'),
105
+            Column::make('stato')->title('Stato'),
106
+            Column::computed('action')
107
+                  ->title('')
108
+                  ->exportable(false)
109
+                  ->printable(false)
110
+                  ->width(60)
111
+                  ->addClass('text-center'),
112
+        ];
113
+    }
114
+
115
+    /**
116
+     * Get the filename for export.
117
+     */
118
+    protected function filename(): string
119
+    {
120
+        return 'PrimaNota_' . date('YmdHis');
121
+    }
122
+}

+ 123
- 0
app/DataTables/PrintJobDataTable.php 파일 보기

@@ -0,0 +1,123 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\PrintJob;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+
16
+class PrintJobDataTable extends DataTable
17
+{
18
+    public function __construct()
19
+    {
20
+        $this->dataTableVariable = 'dataTable_print_job';
21
+    }
22
+    /**
23
+     * Build the DataTable class.
24
+     *
25
+     * @param QueryBuilder<PrintJob> $query Results from query() method.
26
+     */
27
+    public function dataTable(QueryBuilder $query): EloquentDataTable
28
+    {
29
+        return (new EloquentDataTable($query))
30
+            ->addColumn('action', function($entity){
31
+                return view('print_job.menu', ['entity' => $entity]);
32
+            })
33
+            ->addColumn('stato_display', function($entity){
34
+                // return PrintJob::getStatoLabel($entity->stato);
35
+                return view('prenotazione._partials.stato-prenotazione', ['stato' => $entity->stato]);
36
+            })
37
+            ->addColumn('tipo_display', function($entity){
38
+                return PrintJob::getTipoLabel($entity->tipo);
39
+            })
40
+            ->addColumn('dispositivo_id_display', function($entity){
41
+                return $entity->dispositivo->nome;
42
+            })
43
+            ->addColumn('ordine_id_display', function($entity){
44
+                return $entity->ordine->riferimento??$entity->ordine->id;
45
+            })
46
+            ->addColumn('payload_display', function($entity){
47
+                return $entity->payload;
48
+            })
49
+            ->addColumn('stampante_id_display', function($entity){
50
+                $stampante = $entity->stampante;
51
+                $endpoint = null;
52
+                if($stampante !== null && $stampante->endpoint_id !== null){
53
+                    $endpoint = \App\Models\Endpoint::find($stampante->endpoint_id)->label;
54
+                };
55
+
56
+                return ($stampante->nome ?? 'ND' ). ' (EP: ' . ($endpoint ?? 'ND') .')';
57
+            })
58
+            ->addColumn('created_at_display', function($entity){ return $entity->created_at->format('d/m/Y H:i:s'); })
59
+            ->addColumn('updated_at_display', function($entity){ return $entity->updated_at->format('d/m/Y H:i:s'); })
60
+            ->setRowId('id');
61
+    }
62
+
63
+    /**
64
+     * Get the query source of dataTable.
65
+     *
66
+     * @return QueryBuilder<PrintJob>
67
+     */
68
+    public function query(PrintJob $model): QueryBuilder
69
+    {
70
+        return $model->newQuery()->orderBy('created_at', 'desc');
71
+    }
72
+
73
+    /**
74
+     * Optional method if you want to use the html builder.
75
+     */
76
+    public function html(): HtmlBuilder
77
+    {
78
+        $buttons = [];
79
+
80
+        return $this->builder()
81
+                    ->setTableId($this->dataTableVariable)
82
+                    ->columns($this->getColumns())
83
+                    ->minifiedAjax()
84
+                    ->language(asset('assets/Italian.json'))
85
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
86
+                    ->buttons($buttons)
87
+                    ->responsive(true)
88
+                    ->orderBy(1)
89
+                    ->selectStyleSingle();
90
+                    }
91
+
92
+    /**
93
+     * Get the dataTable columns definition.
94
+     */
95
+    public function getColumns(): array
96
+    {
97
+        return [
98
+            Column::make('id'),
99
+            Column::make('stato_display'),
100
+            Column::make('tipo_display'),
101
+            Column::make('payload'),
102
+            Column::make('dispositivo_id_display'),
103
+            Column::make('ordine_id_display'),
104
+            Column::make('stampante_id_display'),
105
+
106
+            Column::make('created_at_display')->title('Creato il'),
107
+            Column::make('updated_at_display')->title('Aggiornato il'),
108
+            Column::computed('action')
109
+                  ->exportable(false)
110
+                  ->printable(false)
111
+                  ->width(60)
112
+                  ->addClass('text-center'),
113
+        ];
114
+    }
115
+
116
+    /**
117
+     * Get the filename for export.
118
+     */
119
+    protected function filename(): string
120
+    {
121
+        return 'PrintJob_' . date('YmdHis');
122
+    }
123
+}

+ 142
- 0
app/DataTables/PuntoVenditaDataTable.php 파일 보기

@@ -0,0 +1,142 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Dispositivo;
6
+use App\Models\Attivita;
7
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
8
+use Yajra\DataTables\EloquentDataTable;
9
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
10
+use Yajra\DataTables\Html\Button;
11
+use Yajra\DataTables\Html\Column;
12
+use Yajra\DataTables\Html\Editor\Editor;
13
+use Yajra\DataTables\Html\Editor\Fields;
14
+use Yajra\DataTables\Services\DataTable;
15
+use Illuminate\Support\Facades\Auth;
16
+
17
+class PuntoVenditaDataTable extends DataTable
18
+{
19
+    public function __construct()
20
+    {
21
+        $this->dataTableVariable = 'dataTable_punto_vendita';
22
+    }
23
+    /**
24
+     * Build the DataTable class.
25
+     *
26
+     * @param QueryBuilder<Dispositivo> $query Results from query() method.
27
+     */
28
+    public function dataTable(QueryBuilder $query): EloquentDataTable
29
+    {
30
+        return (new EloquentDataTable($query))
31
+            ->addColumn('action', function($entity){
32
+                return view('punto_vendita.menu', ['entity' => $entity]);
33
+            })
34
+            ->addColumn('is_attivo_display', function($entity){
35
+                return view('_partials.available', ['available' => $entity->is_attivo]);
36
+            })
37
+            ->addColumn('attivita_id_display', function($entity){
38
+                return $entity->attivita ? $entity->attivita->nome : 'ND';
39
+            })
40
+            // ->addColumn('punto_vendita_tipo_display', function($entity){
41
+            //     return '<i class="'.Dispositivo::getTipoDispositivo()->get($entity->tipo)['icon'].'"></i> '.Dispositivo::getTipoDispositivo()->get($entity->tipo)['label'];
42
+            // })
43
+            ->addColumn('url_stampante_display', function($entity){
44
+                return $entity->url_stampante ?? 'ND';
45
+            })
46
+            // ->rawColumns(['punto_vendita_tipo_display'])
47
+            ->setRowId('id');
48
+    }
49
+
50
+    /**
51
+     * Get the query source of dataTable.
52
+     *
53
+     * @return QueryBuilder<Dispositivo>
54
+     */
55
+    public function query(Dispositivo $model): QueryBuilder
56
+    {
57
+        return $model->newQuery()
58
+        ->whereIn('tipo', [Dispositivo::KIOSK, Dispositivo::CASSA , Dispositivo::CAMERIERE])
59
+        ->where('attivita_id', session('attivita_attuale'));
60
+    }
61
+
62
+    /**
63
+     * Optional method if you want to use the html builder.
64
+     */
65
+    public function html(): HtmlBuilder
66
+    {
67
+        $buttons = [];
68
+        if(Auth::user()->can('create-punto_vendita')){
69
+            array_push($buttons, Button::make('create')
70
+                ->editor('editor')
71
+                ->className('btn btn-sm btn-primary mb-4')
72
+                ->formTitle('Crea nuovo punto di vendita')
73
+                ->text('<i class="fas fa-plus"></i> Nuovo punto di vendita'));
74
+        }
75
+        return $this->builder()
76
+                    ->setTableId($this->dataTableVariable)
77
+                    ->columns($this->getColumns())
78
+                    ->minifiedAjax()
79
+                    ->language(asset('assets/Italian.json'))
80
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
81
+                    ->buttons($buttons)
82
+                    ->orderBy(1)
83
+                    ->editor(
84
+                        Editor::make()
85
+                            ->fields([
86
+                                Fields\Text::make('nome')->label('Nome'),
87
+                                Fields\Select::make('tipo')->label('Tipo')
88
+                                ->options(Dispositivo::getTipoPuntiVendita()),
89
+                                Fields\Select2::make('attivita_id')->label('Attività')->options(Attivita::where('is_attiva', true)->pluck('id', 'nome')),
90
+                                Fields\Text::make('licenza')->label('Licenza'),
91
+                                Fields\Select2::make('url_stampante')->label('URL della stampante')
92
+                                ->options(Dispositivo::select2_stampante()),
93
+                                Fields\Text::make('ubicazione')->label('Ubicazione'),
94
+                                Fields\Text::make('note')->label('Note'),
95
+                                Fields\Boolean::make('is_attivo')->label('Attivo')->default(true),
96
+                                Fields\Text::make('pin_sblocco')->label('Pin di sblocco'),
97
+                                Fields\DateTime::make('data_apertura_dispositivo')->label('Data di apertura del dispositivo'),
98
+                                Fields\DateTime::make('data_chiusura_dispositivo')->label('Data di chiusura del dispositivo'),
99
+                            ])
100
+                    )
101
+                    ->initComplete("function(settings, json){
102
+                        initComplete_punto_vendita();
103
+                    }")
104
+                    ->selectStyleSingle();
105
+    }
106
+
107
+    /**
108
+     * Get the dataTable columns definition.
109
+     */
110
+    public function getColumns(): array
111
+    {
112
+        return [
113
+            Column::make('id')->visible(false),
114
+            Column::make('is_attivo')->data('is_attivo_display')->title('Disponibile'),
115
+            Column::make('nome')->title('Nome'),
116
+            Column::make('attivita_id')->title('Attività'),
117
+            Column::make('tipo')->title('Tipo')->visible(true),
118
+            // Column::computed('punto_vendita_tipo_display')->title('Tipo'),
119
+            Column::make('licenza')->title('Licenza'),
120
+            Column::make('url_stampante')->title('URL della stampante'),
121
+            Column::make('ubicazione')->title('Ubicazione'),
122
+            // Column::make('note')->title('Note'),
123
+            Column::make('pin_sblocco')->title('Pin di sblocco'),
124
+            // Column::make('data_apertura_dispositivo')->title('Data di apertura del dispositivo'),
125
+            // Column::make('data_chiusura_dispositivo')->title('Data di chiusura del dispositivo'),
126
+            Column::computed('action')
127
+                  ->title('')
128
+                  ->exportable(false)
129
+                  ->printable(false)
130
+                  ->width(60)
131
+                  ->addClass('text-center'),
132
+        ];
133
+    }
134
+
135
+    /**
136
+     * Get the filename for export.
137
+     */
138
+    protected function filename(): string
139
+    {
140
+        return 'PuntoVendita_' . date('YmdHis');
141
+    }
142
+}

+ 126
- 0
app/DataTables/PuntoVenditaDataTableEditor.php 파일 보기

@@ -0,0 +1,126 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Dispositivo;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class PuntoVenditaDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Dispositivo::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'tipo.required' => 'Il tipo è richiesto',
23
+    'attivita_id.required' => 'La attività è richiesta',
24
+    'licenza.required' => 'La licenza è richiesta',
25
+    'url_stampante.required' => 'L\'URL della stampante è richiesta',
26
+    'ubicazione.required' => 'L\'ubicazione è richiesta',
27
+    'note.required' => 'La note è richiesta',
28
+    'is_attivo.required' => 'Indicare una delle due opzioni',
29
+    'pin_sblocco.required' => 'Il pin di sblocco è richiesto',
30
+    'data_apertura_dispositivo.required' => 'La data di apertura del dispositivo è richiesta',
31
+    'data_chiusura_dispositivo.required' => 'La data di chiusura del dispositivo è richiesta',
32
+    'data_apertura_dispositivo.date' => 'La data di apertura del dispositivo deve essere una data valida',
33
+    'data_chiusura_dispositivo.date' => 'La data di chiusura del dispositivo deve essere una data valida',
34
+    'is_attivo.boolean' => 'Indicare una delle due opzioni',
35
+    'pin_sblocco.string' => 'Il pin di sblocco deve essere una stringa',
36
+    'pin_sblocco.required' => 'Il pin di sblocco è richiesto',
37
+    'pin_sblocco.min' => 'Il pin di sblocco deve essere lungo almeno 4 caratteri',
38
+    'pin_sblocco.max' => 'Il pin di sblocco deve essere lungo al massimo 4 caratteri',
39
+    'pin_sblocco.regex' => 'Il pin di sblocco deve contenere solo numeri',
40
+    'pin_sblocco.unique' => 'Il pin di sblocco deve essere unico',
41
+  ];
42
+
43
+  /**
44
+  * Get create action validation rules.
45
+  *
46
+  * @return array
47
+  */
48
+  public function createRules(): array
49
+  {
50
+    return [
51
+      'nome'  => 'required',
52
+      'tipo' => 'required',
53
+      'attivita_id' => 'required|exists:attivita,id',
54
+      'licenza' => 'nullable',
55
+      'url_stampante' => 'nullable',
56
+      'ubicazione' => 'nullable',
57
+      'note' => 'nullable',
58
+      'is_attivo' => 'boolean',
59
+      'pin_sblocco' => 'nullable',
60
+      'data_apertura_dispositivo' => 'nullable|date',
61
+      'data_chiusura_dispositivo' => 'nullable|date',
62
+    ];
63
+  }
64
+
65
+  public function createMessages(): array{
66
+    return $this->messages;
67
+  }
68
+
69
+  /**
70
+  * Get edit action validation rules.
71
+  *
72
+  * @param Model $model
73
+  * @return array
74
+  */
75
+  public function editRules(Model $model): array
76
+  {
77
+    return [
78
+      'nome'  => 'required',
79
+      'tipo' => 'required',
80
+      'attivita_id' => 'required|exists:attivita,id',
81
+      'licenza' => 'nullable',
82
+      'url_stampante' => 'nullable',
83
+      'ubicazione' => 'nullable',
84
+      'note' => 'nullable',
85
+      'is_attivo' => 'boolean',
86
+      'pin_sblocco' => 'nullable',
87
+      'data_apertura_dispositivo' => 'nullable|date',
88
+      'data_chiusura_dispositivo' => 'nullable|date',
89
+    ];
90
+  }
91
+
92
+  public function editMessages(): array{
93
+    return $this->messages;
94
+  }
95
+
96
+  /**
97
+  * Get remove action validation rules.
98
+  *
99
+  * @param Model $model
100
+  * @return array
101
+  */
102
+  public function removeRules(Model $model): array
103
+  {
104
+    return [];
105
+  }
106
+
107
+  public function creating(Model $model, array $data): array
108
+  {
109
+    // $model->roles()->sync([$data['ruolo_id']]);
110
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
111
+    return $data;
112
+  }
113
+
114
+  public function updating(Model $model, array $data): array
115
+  {
116
+    // dd($data['ruolo']);
117
+    // $model->roles()->sync([$data['ruolo_id']]);
118
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
119
+    return $data;
120
+  }
121
+  public function messages(): array
122
+  {
123
+    return $this->messages;
124
+  }
125
+
126
+}

+ 160
- 0
app/DataTables/RigaOrdineDataTable.php 파일 보기

@@ -0,0 +1,160 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\RigaOrdine;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+
15
+class RigaOrdineDataTable extends DataTable
16
+{
17
+    public function __construct()
18
+    {
19
+        $this->dataTableVariable = 'dataTable_rigaordine';
20
+        // $this->ordine_id = $ordine_id;
21
+    }
22
+    /**
23
+     * Build the DataTable class.
24
+     *
25
+     * @param QueryBuilder<RigaOrdine> $query Results from query() method.
26
+     */
27
+    public function dataTable(QueryBuilder $query): EloquentDataTable
28
+    {
29
+        return (new EloquentDataTable($query))
30
+            // ->addColumn('action', 'rigaordine.action')
31
+            ->addColumn('piatto', function ($query) {
32
+                return $query->piatto->nome;
33
+            })
34
+            ->addColumn('quantita', function ($query) {
35
+                return $query->quantita;
36
+            })
37
+            ->addColumn('prezzo', function ($query) {
38
+                return $query->prezzo;
39
+            })
40
+            ->addColumn('note', function ($query) {
41
+                return $query->note;
42
+            })
43
+            ->addColumn('aumenta', function ($query) {
44
+                return view('punto_vendita.cassa._partials.carrello.cmd_carrello', ['cmd' => 'aumenta', 'piatto_id' => $query->piatto_id , 'riga_ordine_id' => $query->id]);
45
+            })
46
+            ->addColumn('diminuisci', function ($query) {
47
+                return view('punto_vendita.cassa._partials.carrello.cmd_carrello', ['cmd' => 'diminuisci', 'piatto_id' => $query->piatto_id , 'riga_ordine_id' => $query->id]);
48
+            })
49
+            ->addColumn('elimina', function ($query) {
50
+                return view('punto_vendita.cassa._partials.carrello.cmd_carrello', ['cmd' => 'elimina', 'piatto_id' => $query->piatto_id , 'riga_ordine_id' => $query->id]);
51
+            })
52
+            ->addColumn('prezzo_display', function ($query) {
53
+                return '€ ' . number_format($query->prezzo, 2, ',', '.');
54
+            })
55
+            ->addColumn('quantita_display', function ($query) {
56
+                return view('punto_vendita.cassa._partials.carrello.cmd_carrello', ['cmd' => 'quantita', 'piatto_id' => $query->piatto_id , 'riga_ordine_id' => $query->id]);
57
+            })
58
+            ->addColumn('piatto_display', function ($query) {
59
+                return view('punto_vendita.cassa._partials.carrello.cmd_carrello', ['cmd' => 'piatto', 'piatto_id' => $query->piatto_id , 'riga_ordine_id' => $query->id]);
60
+            })
61
+            ->addColumn('menu_display', function ($query) {
62
+                return view('punto_vendita.cassa._partials.carrello.cmd_carrello', ['cmd' => 'menu', 'piatto_id' => $query->piatto_id , 'riga_ordine_id' => $query->id]);
63
+            })
64
+            ->addColumn('note_display', function ($query) {
65
+                return view('punto_vendita.cassa._partials.carrello.cmd_carrello', ['cmd' => 'note', 'piatto_id' => $query->piatto_id , 'riga_ordine_id' => $query->id]);
66
+            })
67
+            ->addColumn('riga_ordine', function ($query) {
68
+                return view('punto_vendita.cassa._partials.carrello.piatto_ordinato', ['riga_ordine' => $query]);
69
+            })
70
+            ->setRowId('id')
71
+            // ->rawColumns([
72
+            //     'aumenta',
73
+            //     'diminuisci',
74
+            //     'elimina',
75
+            //     'riga_ordine',
76
+            //     'note_display',
77
+            //     'quantita_display',
78
+            //     'piatto_display',
79
+            //     'menu_display',
80
+            // ]);
81
+            ;
82
+    }
83
+
84
+    /**
85
+     * Get the query source of dataTable.
86
+     *
87
+     * @return QueryBuilder<RigaOrdine>
88
+     */
89
+    public function query(RigaOrdine $model): QueryBuilder
90
+    {
91
+        return $model->newQuery()->where('ordine_id', $this->ordine_id);
92
+        // ->orderBy('created_at', 'desc');
93
+    }
94
+
95
+    /**
96
+     * Optional method if you want to use the html builder.
97
+     */
98
+    public function html(): HtmlBuilder
99
+    {
100
+        $buttons = [];
101
+        
102
+            array_push($buttons, Button::raw('Azzerare carrello')
103
+                ->className('btn btn-sm btn-danger mb-4')
104
+                ->style('margin-bottom: 10px;')
105
+                ->action('function(){
106
+                    azzeraCarrello();
107
+                }'));
108
+        
109
+        return $this->builder()
110
+                    ->setTableId($this->dataTableVariable)
111
+                    ->columns($this->getColumns())
112
+                    ->minifiedAjax()
113
+                    ->language(asset('assets/Italian.json'))
114
+                    // ->dom(count($buttons) == 0 ? 'rtip' : 'Brtip')
115
+                    ->dom('rtip')
116
+                    // ->buttons($buttons)
117
+                    ->orderBy(0, 'asc')
118
+                    ->scrollY("48vh")
119
+                    ->paging(false)
120
+                    ->selectStyleSingle()
121
+                    ->responsive(true)
122
+                    ->editor(
123
+                        Editor::make()
124
+                            ->fields([
125
+                                Fields\Text::make('quantita')->label('Quantità'),
126
+                                Fields\Text::make('note')->label('Note'),
127
+                            ])
128
+                    )
129
+                    ->initComplete("function(settings, json){
130
+                        initComplete_rigaordine();
131
+                    }");
132
+    }
133
+
134
+    /**
135
+     * Get the dataTable columns definition.
136
+     */
137
+    public function getColumns(): array
138
+    {
139
+        return [
140
+            Column::make('id')->visible(false),
141
+            // Column::computed('riga_ordine')->title('')->searchable(true),
142
+            Column::make('piatto')->title('Piatto')->searchable(true)->data('piatto_display')->addClass('text-start col-5 col-sm-5 col-md-5 col-lg-5 col-xl-5 col-xxl-5'),
143
+            // Column::make('diminuisci')->title('')->addClass('text-center')->width('10%'),
144
+            Column::make('quantita')->title('Quantità')->width('10%')->attributes(['class' => 'text-center w-25 w-50 w-md-25 w-sm-50'])->addClass('text-center')->data('quantita_display'),
145
+            // Column::make('aumenta')->title('')->addClass('text-center')->width('10%'),
146
+            Column::make('prezzo')->title('Prezzo')->data('prezzo_display')->addClass('text-center'),
147
+            // Column::make('note')->title('Note')->addClass('text-center')->width('10%')->visible(false),
148
+            // Column::make('elimina')->title('')->addClass('text-center')->width('10%'),
149
+            Column::computed('menu')->title('')->addClass('text-center details-control')->width('10%')->data('menu_display'),
150
+        ];
151
+    }
152
+
153
+    /**
154
+     * Get the filename for export.
155
+     */
156
+    protected function filename(): string
157
+    {
158
+        return 'RigaOrdine_' . date('YmdHis');
159
+    }
160
+}

+ 132
- 0
app/DataTables/RoleDataTable.php 파일 보기

@@ -0,0 +1,132 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use Yajra\DataTables\Services\DataTable;
6
+use Yajra\DataTables\Html\Button;
7
+use Yajra\DataTables\Html\Column;
8
+use Yajra\DataTables\Html\Editor\Editor;
9
+use Yajra\DataTables\Html\Editor\Fields;
10
+use App\Models\Role;
11
+use Illuminate\Support\Facades\Auth;
12
+use Form;
13
+
14
+class RoleDataTable extends DataTable
15
+{
16
+  public function __construct(){
17
+    $this->dataTableVariable = 'dataTable_role';
18
+  }
19
+
20
+  /**
21
+  * Build DataTable class.
22
+  *
23
+  * @param mixed $query Results from query() method.
24
+  * @return \Yajra\DataTables\DataTableAbstract
25
+  */
26
+  public function dataTable($query)
27
+  {
28
+    return datatables()
29
+    ->eloquent($query)
30
+    ->setRowId('id')
31
+    ->addColumn('action', function($entity){
32
+      return view('role.menu', ['entity' => $entity]);
33
+    });
34
+  }
35
+
36
+
37
+  /**
38
+  * Get query source of dataTable.
39
+  *
40
+  * @param \App\Role $model
41
+  * @return \Illuminate\Database\Eloquent\Builder
42
+  */
43
+  public function query(Role $model)
44
+  {
45
+    $builder = $model->newQuery();
46
+
47
+    if(!Auth::user()->hasRole('superadmin')){
48
+      $builder->where('name', '!=', 'superadmin');
49
+    }
50
+
51
+    return $builder;
52
+  }
53
+
54
+  /**
55
+  * Optional method if you want to use html builder.
56
+  *
57
+  * @return \Yajra\DataTables\Html\Builder
58
+  */
59
+  public function html()
60
+  {
61
+    $buttons = [];
62
+    if(Auth::user()->can('create-roles-permissions')){
63
+      array_push($buttons, Button::make('create')
64
+      ->editor('editor')
65
+      ->className('btn btn-sm btn-primary')
66
+      ->formTitle('Crea nuovo ruolo')
67
+      ->formButtons(
68
+        [Button::raw('Annulla')
69
+        ->className('btn btn-secondary ml-2')
70
+        ->actionClose(),
71
+        Button::raw('Salva')
72
+        ->className('btn btn-success ml-2')
73
+        ->actionHandler('create')]
74
+        )
75
+      ->text('<i class="fas fa-plus"></i> Nuovo ruolo'));
76
+    }
77
+
78
+    return $this->builder()
79
+    ->setTableId($this->dataTableVariable)
80
+    ->columns($this->getColumns())
81
+    ->minifiedAjax()
82
+    ->language(asset('assets/Italian.json'))
83
+    ->dom(count($buttons)==0?'rtip':'Brtip')
84
+    ->orderBy(1, 'ASC')
85
+    ->buttons($buttons)
86
+    ->editor(
87
+      Editor::make()
88
+      ->fields([
89
+        Fields\Text::make('display_name', 'Nome'),
90
+        Fields\Hidden::make('guard_name')->default('web'),
91
+        Fields\Hidden::make('name')
92
+      ])
93
+      ->on('preSubmit', "function(e, data, action){
94
+        if(action == 'create'){
95
+          data.data[0]['name'] = convertToSlug(data.data[0]['display_name']);
96
+        }
97
+      }")
98
+      ->on('submitComplete', "function( e, mode, action ){}"
99
+        )
100
+      );
101
+    }
102
+
103
+    /**
104
+    * Get columns.
105
+    *
106
+    * @return array
107
+    */
108
+    protected function getColumns()
109
+    {
110
+      return [
111
+        Column::make('id')->title('ID')->width('10%')->visible(false),
112
+        Column::make('display_name')->title('Nome ruolo'),
113
+        Column::computed('action')
114
+        ->exportable(false)
115
+        ->printable(false)
116
+        ->width('10%')
117
+        ->title(' ')
118
+        ->addClass('text-right'),
119
+      ];
120
+    }
121
+
122
+    /**
123
+     * Get filename for export.
124
+     *
125
+     * @return string
126
+     */
127
+    protected function filename(): string
128
+    {
129
+      return 'Role_' . date('YmdHis');
130
+    }
131
+
132
+  }

+ 73
- 0
app/DataTables/RoleDataTableEditor.php 파일 보기

@@ -0,0 +1,73 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Role;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+
10
+class RoleDataTableEditor extends DataTablesEditor
11
+{
12
+  protected $model = Role::class;
13
+  protected $messages = [
14
+    'display_name.required' => 'Il nome è richiesto',
15
+    'name.unique' => 'Nome non valido'
16
+  ];
17
+
18
+  /**
19
+  * Get create action validation rules.
20
+  *
21
+  * @return array
22
+  */
23
+  public function createRules()
24
+  {
25
+
26
+    return [
27
+      'display_name'  => 'required',
28
+      'name' => 'unique:roles'
29
+    ];
30
+  }
31
+
32
+  public function createMessages(){
33
+    return $this->messages;
34
+  }
35
+
36
+  /**
37
+  * Get edit action validation rules.
38
+  *
39
+  * @param Model $model
40
+  * @return array
41
+  */
42
+  public function editRules(Model $model)
43
+  {
44
+    return [
45
+      'display_name'  => 'required|unique:roles',
46
+    ];
47
+  }
48
+
49
+  public function editMessages(){
50
+    return $this->messages;
51
+  }
52
+
53
+  /**
54
+  * Get remove action validation rules.
55
+  *
56
+  * @param Model $model
57
+  * @return array
58
+  */
59
+  public function removeRules(Model $model)
60
+  {
61
+    return [];
62
+  }
63
+
64
+  public function creating(Model $model, array $data)
65
+  {
66
+    return $data;
67
+  }
68
+
69
+  public function updating(Model $model, array $data)
70
+  {
71
+    return $data;
72
+  }
73
+}

+ 143
- 0
app/DataTables/StampanteDataTable.php 파일 보기

@@ -0,0 +1,143 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Dispositivo;
6
+use App\Models\Attivita;
7
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
8
+use Yajra\DataTables\EloquentDataTable;
9
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
10
+use Yajra\DataTables\Html\Button;
11
+use Yajra\DataTables\Html\Column;
12
+use Yajra\DataTables\Html\Editor\Editor;
13
+use Yajra\DataTables\Html\Editor\Fields;
14
+use Yajra\DataTables\Services\DataTable;
15
+use Illuminate\Support\Facades\Auth;
16
+
17
+class StampanteDataTable extends DataTable
18
+{
19
+    public function __construct()
20
+    {
21
+        $this->dataTableVariable = 'dataTable_stampante';
22
+    }
23
+    /**
24
+     * Build the DataTable class.
25
+     *
26
+     * @param QueryBuilder<Dispositivo> $query Results from query() method.
27
+     */
28
+    public function dataTable(QueryBuilder $query): EloquentDataTable
29
+    {
30
+        return (new EloquentDataTable($query))
31
+            ->addColumn('action', function($entity){
32
+                return view('stampante.menu', ['entity' => $entity]);
33
+            })
34
+            ->addColumn('is_attivo_display', function($entity){
35
+                return view('_partials.available', ['available' => $entity->is_attivo]);
36
+            })
37
+            ->addColumn('attivita_id_display', function($entity){
38
+                return $entity->attivita ? $entity->attivita->nome : 'ND';
39
+            })
40
+            ->addColumn('occupato_display', function($entity){
41
+                return view('_partials.available', ['available' => $entity->occupato()]);
42
+            })
43
+            ->addColumn('tipo_display', function($entity){
44
+                return '<i class="'.Dispositivo::getTipoDispositivo()->get($entity->tipo)['icon'].'"></i> '.Dispositivo::getTipoDispositivo()->get($entity->tipo)['label'];
45
+            })
46
+            ->rawColumns(['tipo_display'])
47
+            ->setRowId('id');
48
+    }
49
+
50
+    /**
51
+     * Get the query source of dataTable.
52
+     *
53
+     * @return QueryBuilder<Dispositivo>
54
+     */
55
+    public function query(Dispositivo $model): QueryBuilder
56
+    {
57
+        return $model->newQuery()->where('tipo', Dispositivo::STAMPANTE);
58
+    }
59
+
60
+    /**
61
+     * Optional method if you want to use the html builder.
62
+     */
63
+    public function html(): HtmlBuilder
64
+    {
65
+        $buttons = [];
66
+        if(Auth::user()->can('create-stampante')){
67
+            array_push($buttons, Button::make('create')
68
+                ->editor('editor')
69
+                ->className('btn btn-sm btn-primary mb-4')
70
+                ->formTitle('Crea nuovo stampante')
71
+                ->text('<i class="fas fa-plus"></i> Nuova stampante'));
72
+        }
73
+
74
+        if(Auth::user()->can('edit-stampante')){
75
+            array_push($buttons, Button::raw('<button class="btn btn-sm btn-warning mb-4" onclick="api_updateStampanti()">Aggiorna stampanti (API)</button>'));
76
+        }
77
+
78
+        return $this->builder()
79
+                    ->setTableId($this->dataTableVariable)
80
+                    ->columns($this->getColumns())
81
+                    ->minifiedAjax()
82
+                    ->language(asset('assets/Italian.json'))
83
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
84
+                    ->buttons($buttons)
85
+                    ->orderBy(1)
86
+                    ->editor(
87
+                        Editor::make()
88
+                            ->fields([
89
+                                Fields\Text::make('nome')->label('Nome'),
90
+                                Fields\Hidden::make('tipo')->label('Tipo')->default(Dispositivo::STAMPANTE),
91
+                                Fields\Select2::make('attivita_id')->label('Attività')->options(Attivita::where('is_attiva', true)->pluck('id', 'nome')),
92
+                                Fields\Text::make('licenza')->label('Licenza'),
93
+                                Fields\Text::make('url_stampante')->label('URL della stampante'),
94
+                                Fields\Text::make('ubicazione')->label('Ubicazione'),
95
+                                Fields\Text::make('note')->label('Note'),
96
+                                Fields\Boolean::make('is_attivo')->label('Attivo')->default(true),
97
+                                Fields\Text::make('pin_sblocco')->label('Pin di sblocco'),
98
+                                Fields\DateTime::make('data_apertura_dispositivo')->label('Data di apertura del dispositivo'),
99
+                                Fields\DateTime::make('data_chiusura_dispositivo')->label('Data di chiusura del dispositivo'),
100
+                            ])
101
+                    )
102
+                    ->initComplete("function(settings, json){
103
+                        initComplete_stampante();
104
+                    }")
105
+                    ->selectStyleSingle();
106
+    }
107
+
108
+    /**
109
+     * Get the dataTable columns definition.
110
+     */
111
+    public function getColumns(): array
112
+    {
113
+        return [
114
+            Column::make('id')->visible(false),
115
+            Column::make('is_attivo')->data('is_attivo_display')->title('Disponibile'),
116
+            Column::make('nome')->title('Nome'),
117
+            Column::make('attivita_id')->title('Attività')->data('attivita_id_display'),
118
+            Column::make('occupato')->data('occupato_display')->title('Occupato'),
119
+            Column::make('tipo')->title('Tipo')->data('tipo_display'),
120
+            Column::make('licenza')->title('Licenza'),
121
+            Column::make('url_stampante')->title('URL della stampante'),
122
+            Column::make('ubicazione')->title('Ubicazione'),
123
+            // Column::make('note')->title('Note'),
124
+            Column::make('pin_sblocco')->title('Pin di sblocco'),
125
+            // Column::make('data_apertura_dispositivo')->title('Data di apertura del dispositivo'),
126
+            // Column::make('data_chiusura_dispositivo')->title('Data di chiusura del dispositivo'),
127
+            Column::computed('action')
128
+                  ->title('')
129
+                  ->exportable(false)
130
+                  ->printable(false)
131
+                  ->width(60)
132
+                  ->addClass('text-center'),
133
+        ];
134
+    }
135
+
136
+    /**
137
+     * Get the filename for export.
138
+     */
139
+    protected function filename(): string
140
+    {
141
+        return 'Dispositivo_' . date('YmdHis');
142
+    }
143
+}

+ 126
- 0
app/DataTables/StampanteDataTableEditor.php 파일 보기

@@ -0,0 +1,126 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Dispositivo;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class StampanteDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = Dispositivo::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'tipo.required' => 'Il tipo è richiesto',
23
+    'attivita_id.required' => 'La attività è richiesta',
24
+    'licenza.required' => 'La licenza è richiesta',
25
+    'url_stampante.required' => 'L\'URL della stampante è richiesta',
26
+    'ubicazione.required' => 'L\'ubicazione è richiesta',
27
+    'note.required' => 'La note è richiesta',
28
+    'is_attiva.required' => 'Indicare una delle due opzioni',
29
+    'pin_sblocco.required' => 'Il pin di sblocco è richiesto',
30
+    'data_apertura_dispositivo.required' => 'La data di apertura del dispositivo è richiesta',
31
+    'data_chiusura_dispositivo.required' => 'La data di chiusura del dispositivo è richiesta',
32
+    'data_apertura_dispositivo.date' => 'La data di apertura del dispositivo deve essere una data valida',
33
+    'data_chiusura_dispositivo.date' => 'La data di chiusura del dispositivo deve essere una data valida',
34
+    'is_attivo.boolean' => 'Indicare una delle due opzioni',
35
+    'pin_sblocco.string' => 'Il pin di sblocco deve essere una stringa',
36
+    'pin_sblocco.required' => 'Il pin di sblocco è richiesto',
37
+    'pin_sblocco.min' => 'Il pin di sblocco deve essere lungo almeno 4 caratteri',
38
+    'pin_sblocco.max' => 'Il pin di sblocco deve essere lungo al massimo 4 caratteri',
39
+    'pin_sblocco.regex' => 'Il pin di sblocco deve contenere solo numeri',
40
+    'pin_sblocco.unique' => 'Il pin di sblocco deve essere unico',
41
+  ];
42
+
43
+  /**
44
+  * Get create action validation rules.
45
+  *
46
+  * @return array
47
+  */
48
+  public function createRules(): array
49
+  {
50
+    return [
51
+      'nome'  => 'required',
52
+      'tipo' => 'required',
53
+      'attivita_id' => 'required|exists:attivita,id',
54
+      'licenza' => 'nullable',
55
+      'url_stampante' => 'nullable',
56
+      'ubicazione' => 'nullable',
57
+      'note' => 'nullable',
58
+      'is_attivo' => 'boolean',
59
+      'pin_sblocco' => 'nullable',
60
+      'data_apertura_dispositivo' => 'nullable|date',
61
+      'data_chiusura_dispositivo' => 'nullable|date',
62
+    ];
63
+  }
64
+
65
+  public function createMessages(): array{
66
+    return $this->messages;
67
+  }
68
+
69
+  /**
70
+  * Get edit action validation rules.
71
+  *
72
+  * @param Model $model
73
+  * @return array
74
+  */
75
+  public function editRules(Model $model): array
76
+  {
77
+    return [
78
+      'nome'  => 'required',
79
+      'tipo' => 'required',
80
+      'attivita_id' => 'required|exists:attivita,id',
81
+      'licenza' => 'nullable',
82
+      'url_stampante' => 'nullable',
83
+      'ubicazione' => 'nullable',
84
+      'note' => 'nullable',
85
+      'is_attivo' => 'boolean',
86
+      'pin_sblocco' => 'nullable',
87
+      'data_apertura_dispositivo' => 'nullable|date',
88
+      'data_chiusura_dispositivo' => 'nullable|date',
89
+    ];
90
+  }
91
+
92
+  public function editMessages(): array{
93
+    return $this->messages;
94
+  }
95
+
96
+  /**
97
+  * Get remove action validation rules.
98
+  *
99
+  * @param Model $model
100
+  * @return array
101
+  */
102
+  public function removeRules(Model $model): array
103
+  {
104
+    return [];
105
+  }
106
+
107
+  public function creating(Model $model, array $data): array
108
+  {
109
+    // $model->roles()->sync([$data['ruolo_id']]);
110
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
111
+    return $data;
112
+  }
113
+
114
+  public function updating(Model $model, array $data): array
115
+  {
116
+    // dd($data['ruolo']);
117
+    // $model->roles()->sync([$data['ruolo_id']]);
118
+    $data['is_attiva'] = isset($data['is_attiva']) ? true : false;
119
+    return $data;
120
+  }
121
+  public function messages(): array
122
+  {
123
+    return $this->messages;
124
+  }
125
+
126
+}

+ 126
- 0
app/DataTables/UserDataTable.php 파일 보기

@@ -0,0 +1,126 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\User;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+use App\Models\Role;
16
+
17
+class UserDataTable extends DataTable
18
+{
19
+  public function __construct(){
20
+    $this->dataTableVariable = 'dataTable_user';
21
+  }
22
+  /**
23
+  * Build the DataTable class.
24
+  *
25
+  * @param QueryBuilder<User> $query Results from query() method.
26
+  */
27
+  public function dataTable(QueryBuilder $query): EloquentDataTable
28
+  {
29
+    return (new EloquentDataTable($query))
30
+    ->addColumn('action', function($entity){
31
+      return view('user.menu', ['entity' => $entity]);
32
+    })
33
+    ->addColumn('ruolo_display', function($entity){
34
+      return $entity->roles->pluck('display_name')->implode(', ');
35
+    })
36
+    ->addColumn('ruolo_id', function($entity){
37
+      return $entity->roles->first()->id;
38
+    })
39
+    ->addColumn('azienda_display', function($entity){
40
+      return $entity->azienda ? $entity->azienda : '';
41
+    })
42
+    ->setRowId('id');
43
+  }
44
+
45
+  /**
46
+  * Get the query source of dataTable.
47
+  *
48
+  * @return QueryBuilder<User>
49
+  */
50
+  public function query(User $model): QueryBuilder
51
+  {
52
+    return $model->newQuery()
53
+    // ->where('is_gruppo', 0)
54
+    ->with('roles');
55
+  }
56
+
57
+  /**
58
+  * Optional method if you want to use the html builder.
59
+  */
60
+  public function html(): HtmlBuilder
61
+  {
62
+    $buttons = [];
63
+    if(Auth::user()->can('create-user')){
64
+      array_push($buttons, Button::make('create')
65
+      ->editor('editor')
66
+      ->formTitle('Crea nuovo utente')
67
+      ->className('btn btn-sm btn-primary mb-4')
68
+      ->text('<i class="fas fa-plus"></i> Nuovo utente'));
69
+    }
70
+
71
+    if(Auth::user()->hasRole('superadmin')){
72
+      $roles = Role::orderBy('display_name', 'asc')->pluck('id', 'display_name');
73
+    }else{
74
+      $roles = Role::whereNotIn('name', ['superadmin'])->orderBy('display_name', 'asc')->pluck('id', 'display_name');
75
+    }
76
+
77
+    $fields = [
78
+      Fields\Text::make('nome')->label('Nome'),
79
+      Fields\Text::make('cognome')->label('Cognome'),
80
+      Fields\Text::make('email')->label('Email'),
81
+      Fields\Text::make('telefono')->label('Telefono'),
82
+      Fields\Select::make('ruolo_id')->label('Ruolo')->options($roles)->default(Role::where('name', 'user')->first()->id),
83
+      Fields\Text::make('azienda')->label('Azienda')
84
+    ];
85
+
86
+    return $this->builder()
87
+    ->setTableId($this->dataTableVariable)
88
+    ->initComplete("function(settings, json){
89
+        initComplete_user();
90
+                    }")
91
+    ->language(asset('assets/Italian.json'))
92
+    ->columns($this->getColumns())
93
+    ->dom('<"py-2"<"head-label text-center"><"dt-action-buttons"B>><"d-flex justify-content-between align-items-center row mb-2"<"col-sm-12 col-md-6"l><"col-sm-12 col-md-6"f>>t<"d-flex justify-content-between row"<"col-sm-12 col-md-6"i><"col-sm-12 col-md-6"p>>')
94
+    ->responsive()
95
+    ->minifiedAjax()
96
+    ->editor(
97
+      Editor::make()
98
+      ->fields($fields)
99
+      )
100
+      ->buttons($buttons)
101
+      ->orderBy(0, 'asc');
102
+    }
103
+
104
+    /**
105
+    * Get the dataTable columns definition.
106
+    */
107
+    public function getColumns(): array
108
+    {
109
+      $columns = [
110
+        Column::make('nome')->title('Nome'),
111
+        Column::make('cognome')->title('Cognome'),
112
+        Column::make('email')->title('Email'),
113
+        Column::make('telefono')->title('Telefono'),
114
+        Column::make('ruolo_id')->title('Ruolo')->searchable(false)->name('ruolo_id')->data('ruolo_display'),
115
+        Column::make('azienda')->title('Azienda')->data('azienda_display')->searchable(false),
116
+        Column::computed('action')
117
+        ->exportable(false)
118
+        ->printable(false)
119
+        ->width('10%')
120
+        ->title(' ')
121
+        ->addClass('text-end')
122
+      ];
123
+
124
+      return $columns;
125
+    }
126
+  }

+ 94
- 0
app/DataTables/UserDataTableEditor.php 파일 보기

@@ -0,0 +1,94 @@
1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\User;
6
+use Illuminate\Database\Eloquent\Model;
7
+use Illuminate\Validation\Rule;
8
+use Yajra\DataTables\DataTablesEditor;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\ValidationException;
11
+use Storage;
12
+use Illuminate\Support\Str;
13
+
14
+class UserDataTableEditor extends DataTablesEditor
15
+{
16
+  protected $model = User::class;
17
+  // protected $uploadDir = '';
18
+  // protected $disk = 'modelliRicevute';
19
+
20
+  protected $messages = [
21
+    'nome.required' => 'Il nome è richiesto',
22
+    'cognome.required' => 'Il cognome è richiesto',
23
+    'email.required' => 'L\'email è richiesta',
24
+    'ruolo.required' => 'Il ruolo è richiesto',
25
+  ];
26
+
27
+  /**
28
+  * Get create action validation rules.
29
+  *
30
+  * @return array
31
+  */
32
+  public function createRules(): array
33
+  {
34
+    return [
35
+      'nome'  => 'required',
36
+      'cognome' => 'required',
37
+      'email' => 'required',
38
+      'ruolo_id' => 'required|exists:roles,id'
39
+    ];
40
+  }
41
+
42
+  public function createMessages(): array{
43
+    return $this->messages;
44
+  }
45
+
46
+  /**
47
+  * Get edit action validation rules.
48
+  *
49
+  * @param Model $model
50
+  * @return array
51
+  */
52
+  public function editRules(Model $model): array
53
+  {
54
+    return [
55
+      'nome'  => 'required',
56
+      'cognome' => 'required',
57
+      'email' => 'required',
58
+      'ruolo_id' => 'required|exists:roles,id'
59
+    ];
60
+  }
61
+
62
+  public function editMessages(): array{
63
+    return $this->messages;
64
+  }
65
+
66
+  /**
67
+  * Get remove action validation rules.
68
+  *
69
+  * @param Model $model
70
+  * @return array
71
+  */
72
+  public function removeRules(Model $model): array
73
+  {
74
+    return [];
75
+  }
76
+
77
+  public function creating(Model $model, array $data): array
78
+  {
79
+    $model->roles()->sync([$data['ruolo_id']]);
80
+    return $data;
81
+  }
82
+
83
+  public function updating(Model $model, array $data): array
84
+  {
85
+    // dd($data['ruolo']);
86
+    $model->roles()->sync([$data['ruolo_id']]);
87
+    return $data;
88
+  }
89
+  public function messages(): array
90
+  {
91
+    return $this->messages;
92
+  }
93
+
94
+}

+ 311
- 0
app/Helpers/Helpers.php 파일 보기

@@ -0,0 +1,311 @@
1
+<?php
2
+
3
+namespace App\Helpers;
4
+
5
+use Illuminate\Support\Facades\Config;
6
+use Illuminate\Support\Str;
7
+
8
+class Helpers
9
+{
10
+  /**
11
+   * Generate menu attributes for semi-dark mode
12
+   *
13
+   * @param bool $semiDarkEnabled Whether semi-dark mode is enabled
14
+   * @return array HTML attributes for the menu element
15
+   */
16
+  public static function getMenuAttributes($semiDarkEnabled)
17
+  {
18
+    $attributes = [];
19
+
20
+    if ($semiDarkEnabled) {
21
+      $attributes['data-bs-theme'] = 'dark';
22
+    }
23
+
24
+    return $attributes;
25
+  }
26
+
27
+  public static function appClasses()
28
+  {
29
+
30
+    $data = config('custom.custom');
31
+
32
+
33
+    // default data array
34
+    $DefaultData = [
35
+      'myLayout' => 'vertical',
36
+      'myTheme' => 'light',
37
+      'mySkins' => 'default',
38
+      'hasSemiDark' => false,
39
+      'myRTLMode' => true,
40
+      'hasCustomizer' => true,
41
+      'showDropdownOnHover' => true,
42
+      'displayCustomizer' => true,
43
+      'contentLayout' => 'compact',
44
+      'headerType' => 'fixed',
45
+      'navbarType' => 'sticky',
46
+      'menuFixed' => true,
47
+      'menuCollapsed' => false,
48
+      'footerFixed' => false,
49
+      'customizerControls' => [
50
+        'color',
51
+        'theme',
52
+        'skins',
53
+        'semiDark',
54
+        'layoutCollapsed',
55
+        'layoutNavbarOptions',
56
+        'headerType',
57
+        'contentLayout',
58
+        'rtl'
59
+      ],
60
+      //   'defaultLanguage'=>'en',
61
+    ];
62
+
63
+    // if any key missing of array from custom.php file it will be merge and set a default value from dataDefault array and store in data variable
64
+    $data = array_merge($DefaultData, $data);
65
+
66
+    // All options available in the template
67
+    $allOptions = [
68
+      'myLayout' => ['vertical', 'horizontal', 'blank', 'front'],
69
+      'menuCollapsed' => [true, false],
70
+      'hasCustomizer' => [true, false],
71
+      'showDropdownOnHover' => [true, false],
72
+      'displayCustomizer' => [true, false],
73
+      'contentLayout' => ['compact', 'wide'],
74
+      'headerType' => ['fixed', 'static'],
75
+      'navbarType' => ['sticky', 'static', 'hidden'],
76
+      'myTheme' => ['light', 'dark', 'system'],
77
+      'mySkins' => ['default', 'bordered', 'raspberry'],
78
+      'hasSemiDark' => [true, false],
79
+      'myRTLMode' => [true, false],
80
+      'menuFixed' => [true, false],
81
+      'footerFixed' => [true, false],
82
+      'customizerControls' => [],
83
+      // 'defaultLanguage'=>array('en'=>'en','fr'=>'fr','de'=>'de','ar'=>'ar'),
84
+    ];
85
+
86
+    //if myLayout value empty or not match with default options in custom.php config file then set a default value
87
+    foreach ($allOptions as $key => $value) {
88
+      if (array_key_exists($key, $DefaultData)) {
89
+        if (gettype($DefaultData[$key]) === gettype($data[$key])) {
90
+          // data key should be string
91
+          if (is_string($data[$key])) {
92
+            // data key should not be empty
93
+            if (isset($data[$key]) && $data[$key] !== null) {
94
+              // data key should not be exist inside allOptions array's sub array
95
+              if (!array_key_exists($data[$key], $value)) {
96
+                // ensure that passed value should be match with any of allOptions array value
97
+                $result = array_search($data[$key], $value, 'strict');
98
+                if (empty($result) && $result !== 0) {
99
+                  $data[$key] = $DefaultData[$key];
100
+                }
101
+              }
102
+            } else {
103
+              // if data key not set or
104
+              $data[$key] = $DefaultData[$key];
105
+            }
106
+          }
107
+        } else {
108
+          $data[$key] = $DefaultData[$key];
109
+        }
110
+      }
111
+    }
112
+    $themeVal = $data['myTheme'] == "dark" ? "dark" : "light";
113
+    $themeUpdatedVal = $data['myTheme'] == "dark" ? "dark" : $data['myTheme'];
114
+
115
+    // Determine if the layout is admin or front based on template name
116
+    $layoutName = $data['myLayout'];
117
+    $isAdmin = !Str::contains($layoutName, 'front');
118
+
119
+    $modeCookieName = $isAdmin ? 'admin-mode' : 'front-mode';
120
+    $colorPrefCookieName = $isAdmin ? 'admin-colorPref' : 'front-colorPref';
121
+    $primaryColorCookieName = $isAdmin ? 'admin-primaryColor' : 'front-primaryColor';
122
+
123
+    // Get primary color from custom.php if explicitly set
124
+    $primaryColor = null;
125
+    if (array_key_exists('primaryColor', $data)) {
126
+      $primaryColor = $data['primaryColor'];
127
+    }
128
+
129
+    // Check for primary color in cookie
130
+    if (isset($_COOKIE[$primaryColorCookieName])) {
131
+      $primaryColor = $_COOKIE[$primaryColorCookieName];
132
+    }
133
+
134
+    // Determine style based on cookies, only if not 'blank-layout'
135
+    if ($layoutName !== 'blank') {
136
+      if (isset($_COOKIE[$modeCookieName])) {
137
+        $themeVal = $_COOKIE[$modeCookieName];
138
+        if ($themeVal === 'system') {
139
+          $themeVal = isset($_COOKIE[$colorPrefCookieName]) ? $_COOKIE[$colorPrefCookieName] : 'light';
140
+        }
141
+        $themeUpdatedVal = $_COOKIE[$modeCookieName];
142
+      }
143
+    }
144
+
145
+    // Define standardized cookie names
146
+    $skinCookieName = 'customize_skin';
147
+    $semiDarkCookieName = 'customize_semi_dark';
148
+
149
+    // Process skin and semi-dark settings only for admin layouts
150
+    if ($isAdmin) {
151
+      // Get skin from cookie or fall back to config
152
+      $skinFromCookie = isset($_COOKIE[$skinCookieName]) ? $_COOKIE[$skinCookieName] : null;
153
+      $configSkin = isset($data['mySkins']) ? $data['mySkins'] : 'default';
154
+      $skinName = $skinFromCookie ?: $configSkin;
155
+
156
+      // Get semi-dark setting from cookie or fall back to config
157
+      $semiDarkFromCookie = isset($_COOKIE[$semiDarkCookieName]) ? $_COOKIE[$semiDarkCookieName] : null;
158
+      // Ensure we have a proper boolean conversion
159
+      $semiDarkEnabled = $semiDarkFromCookie !== null ?
160
+        filter_var($semiDarkFromCookie, FILTER_VALIDATE_BOOLEAN) :
161
+        (bool)$data['hasSemiDark'];
162
+    } else {
163
+      // For front-end layouts, use defaults
164
+      $skinName = 'default';
165
+      $semiDarkEnabled = false;
166
+    }
167
+
168
+    // Get menu Collapsed state from cookie or fall back to config
169
+    $menuCollapsedFromCookie = isset($_COOKIE['LayoutCollapsed']) ? $_COOKIE['LayoutCollapsed'] : $data['menuCollapsed'];
170
+
171
+    // Get content layout from cookie or fall back to config
172
+    $contentLayoutFromCookie = isset($_COOKIE['contentLayout']) ? $_COOKIE['contentLayout'] : $data['contentLayout'];
173
+
174
+    // Get header type from cookie or fall back to config
175
+    $navbarTypeFromCookie = isset($_COOKIE['navbarType']) ? $_COOKIE['navbarType'] : $data['navbarType'];
176
+
177
+    // Get Header type from cookie or fall back to config
178
+    $headerTypeFromCookie = isset($_COOKIE['headerType']) ? $_COOKIE['headerType'] : $data['headerType'];
179
+
180
+    $directionVal = isset($_COOKIE['direction']) ? ($_COOKIE['direction'] === 'true' ? 'rtl' : 'ltr') : $data['myRTLMode'];
181
+
182
+    //layout classes
183
+    $layoutClasses = [
184
+      'layout' => $data['myLayout'],
185
+      'skins' => $data['mySkins'],
186
+      'skinName' => $skinName,
187
+      'semiDark' => $semiDarkEnabled,
188
+      'color' => $primaryColor,
189
+      'theme' => $themeVal,
190
+      'themeOpt' => $data['myTheme'],
191
+      'themeOptVal' => $themeUpdatedVal,
192
+      'rtlMode' => $data['myRTLMode'],
193
+      'textDirection' => $directionVal,
194
+      'menuCollapsed' => $menuCollapsedFromCookie,
195
+      'hasCustomizer' => $data['hasCustomizer'],
196
+      'showDropdownOnHover' => $data['showDropdownOnHover'],
197
+      'displayCustomizer' => $data['displayCustomizer'],
198
+      'contentLayout' => $contentLayoutFromCookie,
199
+      'headerType' => $headerTypeFromCookie,
200
+      'navbarType' => $navbarTypeFromCookie,
201
+      'menuFixed' => $data['menuFixed'],
202
+      'footerFixed' => $data['footerFixed'],
203
+      'customizerControls' => $data['customizerControls'],
204
+      'menuAttributes' => self::getMenuAttributes($semiDarkEnabled),
205
+    ];
206
+
207
+    // sidebar Collapsed
208
+    if ($layoutClasses['menuCollapsed'] === 'true' || $layoutClasses['menuCollapsed'] === true) {
209
+      $layoutClasses['menuCollapsed'] = 'layout-menu-collapsed';
210
+    } else {
211
+      $layoutClasses['menuCollapsed'] = '';
212
+    }
213
+
214
+    // Header Type
215
+    if ($layoutClasses['headerType'] == 'fixed') {
216
+      $layoutClasses['headerType'] = 'layout-menu-fixed';
217
+    }
218
+    // Navbar Type
219
+    if ($layoutClasses['navbarType'] == 'sticky') {
220
+      $layoutClasses['navbarType'] = 'layout-navbar-fixed';
221
+    } elseif ($layoutClasses['navbarType'] == 'static') {
222
+      $layoutClasses['navbarType'] = '';
223
+    } else {
224
+      $layoutClasses['navbarType'] = 'layout-navbar-hidden';
225
+    }
226
+
227
+    // Menu Fixed
228
+    if ($layoutClasses['menuFixed'] == true) {
229
+      $layoutClasses['menuFixed'] = 'layout-menu-fixed';
230
+    }
231
+
232
+
233
+    // Footer Fixed
234
+    if ($layoutClasses['footerFixed'] == true) {
235
+      $layoutClasses['footerFixed'] = 'layout-footer-fixed';
236
+    }
237
+
238
+    // RTL Layout/Mode
239
+    if ($layoutClasses['rtlMode'] == true) {
240
+      $layoutClasses['rtlMode'] = 'rtl';
241
+      $layoutClasses['textDirection'] = isset($_COOKIE['direction']) ? ($_COOKIE['direction'] === 'true' ? 'rtl' : 'ltr') : 'rtl';
242
+    } else {
243
+      $layoutClasses['rtlMode'] = 'ltr';
244
+      $layoutClasses['textDirection'] = isset($_COOKIE['direction']) && $_COOKIE['direction'] === 'true' ? 'rtl' : 'ltr';
245
+    }
246
+
247
+    // Show DropdownOnHover for Horizontal Menu
248
+    if ($layoutClasses['showDropdownOnHover'] == true) {
249
+      $layoutClasses['showDropdownOnHover'] = true;
250
+    } else {
251
+      $layoutClasses['showDropdownOnHover'] = false;
252
+    }
253
+
254
+    // To hide/show display customizer UI, not js
255
+    if ($layoutClasses['displayCustomizer'] == true) {
256
+      $layoutClasses['displayCustomizer'] = true;
257
+    } else {
258
+      $layoutClasses['displayCustomizer'] = false;
259
+    }
260
+
261
+    return $layoutClasses;
262
+  }
263
+
264
+  public static function updatePageConfig($pageConfigs)
265
+  {
266
+    $demo = 'custom';
267
+    if (isset($pageConfigs)) {
268
+      if (count($pageConfigs) > 0) {
269
+        foreach ($pageConfigs as $config => $val) {
270
+          Config::set('custom.' . $demo . '.' . $config, $val);
271
+        }
272
+      }
273
+    }
274
+  }
275
+
276
+  /**
277
+   * Generate CSS for primary color
278
+   *
279
+   * @param string $color Hex color code for primary color
280
+   * @return string CSS for primary color
281
+   */
282
+  public static function generatePrimaryColorCSS($color)
283
+  {
284
+    if (!$color) return '';
285
+
286
+    // Check if the color actually came from a cookie or explicit configuration
287
+    // Don't generate CSS if there's no specific need for a custom color
288
+    $configColor = config('custom.custom.primaryColor', null);
289
+    $isFromCookie = isset($_COOKIE['admin-primaryColor']) || isset($_COOKIE['front-primaryColor']);
290
+
291
+    if (!$configColor && !$isFromCookie) return '';
292
+
293
+    $r = hexdec(substr($color, 1, 2));
294
+    $g = hexdec(substr($color, 3, 2));
295
+    $b = hexdec(substr($color, 5, 2));
296
+
297
+    // Calculate contrast color based on YIQ formula
298
+    $yiq = (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
299
+    $contrastColor = ($yiq >= 150) ? '#000' : '#fff';
300
+
301
+    return <<<CSS
302
+:root, [data-bs-theme=light], [data-bs-theme=dark] {
303
+  --bs-primary: {$color};
304
+  --bs-primary-rgb: {$r}, {$g}, {$b};
305
+  --bs-primary-bg-subtle: rgba({$r}, {$g}, {$b}, 0.1);
306
+  --bs-primary-border-subtle: rgba({$r}, {$g}, {$b}, 0.3);
307
+  --bs-primary-contrast: {$contrastColor};
308
+}
309
+CSS;
310
+  }
311
+}

+ 55
- 0
app/Http/Controllers/AllergeneController.php 파일 보기

@@ -0,0 +1,55 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Allergene;
7
+use App\DataTables\AllergeneDataTable;
8
+use App\DataTables\AllergeneDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+class AllergeneController extends Controller
12
+{
13
+    public static $permission_group = "Allergeni";
14
+    public static $permissions = [
15
+        'view-allergene' => 'Vedi',
16
+        'create-allergene' => 'Crea',
17
+        'edit-allergene' => 'Modifica',
18
+        'delete-allergene' => 'Elimina',
19
+    ];
20
+
21
+    public static function middleware(): array
22
+    {
23
+        return [
24
+            new Middleware('permission:view-allergene', only: ['index']),
25
+            new Middleware('permission:create-allergene|edit-allergene|delete-allergene', only: ['store', 'update', 'destroy']),
26
+        ];
27
+    }
28
+
29
+    public function index(AllergeneDataTable $dataTable){
30
+        return $dataTable->render('allergene.index');
31
+    }
32
+
33
+    public function store(AllergeneDataTableEditor $editor)
34
+    {
35
+        $request = request();
36
+        $input = $request->all();
37
+    
38
+        if($request->has('action')){
39
+          switch($input['action']){
40
+            case 'create':
41
+              if(!Auth::user()->can('create-user')) return;
42
+              break;
43
+    
44
+              case 'edit':
45
+                if(!Auth::user()->can('edit-user')) return;
46
+                break;
47
+    
48
+                case 'remove':
49
+                  if(!Auth::user()->can('remove-user')) return;
50
+                  break;
51
+                }
52
+              }
53
+              return $editor->process($request);
54
+    }
55
+}

+ 72
- 0
app/Http/Controllers/Api/TokenAuthController.php 파일 보기

@@ -0,0 +1,72 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api;
4
+
5
+use App\Http\Controllers\Controller;
6
+use App\Models\User;
7
+use Illuminate\Http\JsonResponse;
8
+use Illuminate\Http\Request;
9
+use Illuminate\Support\Facades\Hash;
10
+use Illuminate\Validation\ValidationException;
11
+
12
+/**
13
+ * Emissione e revoca token Sanctum (vedi documentazione API Token Authentication).
14
+ *
15
+ * @see https://laravel.com/docs/12.x/sanctum#api-token-authentication
16
+ */
17
+class TokenAuthController extends Controller
18
+{
19
+    /**
20
+     * Scambia email/password con un token personale (per agent, app mobili, ecc.).
21
+     */
22
+    public function store(Request $request): JsonResponse
23
+    {
24
+        $data = $request->validate([
25
+            'email' => ['required', 'email'],
26
+            'password' => ['required', 'string'],
27
+            'device_name' => ['required', 'string', 'max:255'],
28
+        ]);
29
+
30
+        $user = User::query()->where('email', $data['email'])->first();
31
+
32
+        if (! $user || ! Hash::check($data['password'], $user->password)) {
33
+            throw ValidationException::withMessages([
34
+                'email' => [__('Credenziali non valide.')],
35
+            ]);
36
+        }
37
+
38
+        // Abilità del token: restringi quando avrai route dedicate (es. solo stampa:poll).
39
+        $abilities = ['stampa'];
40
+
41
+        $token = $user->createToken($data['device_name'], $abilities);
42
+
43
+        return response()->json([
44
+            'token' => $token->plainTextToken,
45
+            'token_type' => 'Bearer',
46
+            'user' => [
47
+                'id' => $user->id,
48
+                'nome' => $user->nome,
49
+                'cognome' => $user->cognome,
50
+                'email' => $user->email,
51
+            ],
52
+        ]);
53
+    }
54
+
55
+    /**
56
+     * Utente corrente (utile per verificare che il Bearer sia valido).
57
+     */
58
+    public function user(Request $request): JsonResponse
59
+    {
60
+        return response()->json($request->user());
61
+    }
62
+
63
+    /**
64
+     * Revoca il token usato per la richiesta corrente.
65
+     */
66
+    public function destroy(Request $request): JsonResponse
67
+    {
68
+        $request->user()->currentAccessToken()?->delete();
69
+
70
+        return response()->json(['message' => 'Token revocato.']);
71
+    }
72
+}

+ 89
- 0
app/Http/Controllers/AttivitaController.php 파일 보기

@@ -0,0 +1,89 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Attivita;
7
+use App\DataTables\AttivitaDataTable;
8
+use App\DataTables\AttivitaDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+use Illuminate\Support\Facades\Session;
11
+
12
+
13
+class AttivitaController extends Controller
14
+{
15
+    public static $permission_group = "Attività";
16
+    public static $permissions = [
17
+        'view-attivita' => 'Vedi',
18
+        'create-attivita' => 'Crea',
19
+        'edit-attivita' => 'Modifica',
20
+        'delete-attivita' => 'Elimina',
21
+        'select-attivita' => 'Seleziona',
22
+    ];
23
+
24
+    public static function middleware(): array
25
+    {
26
+        return [
27
+            new Middleware('permission:view-attivita', only: ['index']),
28
+            new Middleware('permission:create-attivita|edit-attivita|delete-attivita', only: ['store', 'update', 'destroy']),
29
+        ];
30
+    }
31
+
32
+    public function index(AttivitaDataTable $dataTable)
33
+    {
34
+        return $dataTable->render('attivita.index');
35
+    }
36
+
37
+    public function store(AttivitaDataTableEditor $editor)
38
+    {
39
+        $request = request();
40
+        $input = $request->all();
41
+        if($request->has('action')){
42
+            switch($input['action']){
43
+                case 'create':
44
+                    if(!Auth::user()->can('create-attivita')) return;
45
+                    break;
46
+                case 'edit':
47
+                    if(!Auth::user()->can('edit-attivita')) return;
48
+                    break;
49
+                case 'remove':
50
+                    if(!Auth::user()->can('delete-attivita')) return;
51
+                    break;
52
+            }
53
+        }
54
+        return $editor->process($request);
55
+    }
56
+
57
+    public function show($attivita_id)
58
+    {
59
+        $attivita = Attivita::with([
60
+            'dispositivi',
61
+            'eventi',
62
+            'prenotazioni',
63
+            'piatti',
64
+            'fornitori',
65
+        ])->find($attivita_id);
66
+
67
+        return view('attivita.show', ['attivita' => $attivita]);
68
+    }
69
+
70
+    public function select(Request $request)
71
+    {
72
+        $request->validate([
73
+            'attivita_id' => 'required|exists:attivita,id',
74
+        ]);
75
+        Session::put('attivita_attuale', $request->attivita_id);
76
+        return redirect()->route('dashboard')->with('success', 'Attività selezionata con successo');
77
+    }
78
+
79
+    public function list_api()
80
+    {
81
+        $attivita = Attivita::where('is_attiva', true)->where('user_id', Auth::user()->id)->get();
82
+        return response()->json([
83
+            'message' => 'Attività listate con successo',
84
+            'status' => 'success',
85
+            'success' => true,
86
+            'attivita' => $attivita
87
+        ]);
88
+    }
89
+}

+ 61
- 0
app/Http/Controllers/BachecaController.php 파일 보기

@@ -0,0 +1,61 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Bacheca;
7
+use App\DataTables\BachecaDataTable;
8
+use App\DataTables\BachecaDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+use App\DataTables\ContenutoBachecaDataTable;
11
+
12
+class BachecaController extends Controller
13
+{
14
+    public static $permission_group = "Bacheca";
15
+    public static $permissions = [
16
+        'view-bacheca' => 'Vedi',
17
+        'create-bacheca' => 'Crea',
18
+        'edit-bacheca' => 'Modifica',
19
+        'delete-bacheca' => 'Elimina',
20
+    ];
21
+    
22
+    public static function middleware(): array
23
+    {
24
+        return [
25
+            new Middleware('permission:view-bacheca', only: ['index']),
26
+            new Middleware('permission:create-bacheca|edit-bacheca|delete-bacheca', only: ['store', 'update', 'destroy']),
27
+        ];
28
+    }
29
+    
30
+    public function index(BachecaDataTable $dataTable)
31
+    {
32
+        return $dataTable->render('bacheca.index');
33
+    }
34
+    
35
+    public function store(BachecaDataTableEditor $editor)
36
+    {
37
+        $request = request();
38
+        $input = $request->all();
39
+        if($request->has('action')){
40
+            switch($input['action']){
41
+                case 'create':
42
+                    if(!Auth::user()->can('create-bacheca')) return;
43
+                    break;
44
+                case 'edit':
45
+                    if(!Auth::user()->can('edit-bacheca')) return;
46
+                    break;
47
+                case 'remove':
48
+                    if(!Auth::user()->can('delete-bacheca')) return;
49
+                    break;
50
+            }
51
+        }
52
+        return $editor->process($request);
53
+    }
54
+    
55
+    public function show(ContenutoBachecaDataTable $datatable, Request $request)
56
+    {
57
+        $bacheca = Bacheca::find($request->get('bacheca_id'));
58
+        $datatable->bacheca_id = $bacheca->id;
59
+        return $datatable->render('bacheca.show', ['bacheca' => $bacheca]);
60
+    }
61
+}

+ 56
- 0
app/Http/Controllers/BachecaHasContenutoController.php 파일 보기

@@ -0,0 +1,56 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\BachecaHasContenuto;
7
+use App\Models\Bacheca;
8
+use App\Models\ContenutoBacheca;
9
+use Illuminate\Support\Facades\Auth;
10
+use Illuminate\Support\Facades\Session;
11
+
12
+class BachecaHasContenutoController extends Controller
13
+{
14
+    public static $permission_group = "Bacheca Has Contenuto";
15
+    public static $permissions = [
16
+        'view-bacheca_has_contenuto' => 'Vedi',
17
+        'create-bacheca_has_contenuto' => 'Crea',
18
+        'edit-bacheca_has_contenuto' => 'Modifica',
19
+        'delete-bacheca_has_contenuto' => 'Elimina',
20
+    ];
21
+    
22
+    public static function middleware(): array
23
+    {
24
+        return [
25
+            new Middleware('permission:view-bacheca_has_contenuto', only: ['index']),
26
+            new Middleware('permission:create-bacheca_has_contenuto|edit-bacheca_has_contenuto|delete-bacheca_has_contenuto', only: ['store', 'update', 'destroy']),
27
+        ];
28
+    }
29
+    
30
+    public function index(BachecaHasContenutoDataTable $dataTable)
31
+    {
32
+        return $dataTable->render('bacheca_has_contenuto.index');
33
+    }
34
+
35
+    public function associa_contenuto(Request $request)
36
+    {
37
+        $contenuti = ContenutoBacheca::all();
38
+        return view('contenuto_bacheca.associa_contenuto', ['contenuti' => $contenuti]);
39
+    }
40
+
41
+    public function associa_contenuto_bacheca(Request $request)
42
+    {
43
+        $request->validate([
44
+            'bacheca_id' => 'required|exists:bacheca,id',
45
+            'contenuto_id' => 'required|exists:contenuto_bacheca,id',
46
+        ]);
47
+        
48
+        $bacheca = Bacheca::find($request->bacheca_id);
49
+        $contenuto = ContenutoBacheca::find($request->contenuto_id);
50
+        
51
+        $bacheca->contenuti()->attach($contenuto);
52
+        
53
+        return response()->json(['message' => 'Contenuto associato con successo']);
54
+    }
55
+    
56
+}

+ 31
- 0
app/Http/Controllers/BilancioController.php 파일 보기

@@ -0,0 +1,31 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+
7
+class BilancioController extends Controller
8
+{
9
+    public static $permission_group = "Bilancio";
10
+    public static $permissions = [
11
+        'view-bilancio-oggi' => 'Vedi oggi',
12
+        'view-bilancio' => 'Vedi',
13
+        'create-bilancio' => 'Crea',
14
+        'edit-bilancio' => 'Modifica',
15
+        'delete-bilancio' => 'Elimina',
16
+    ];
17
+
18
+    public static function middleware(): array
19
+    {
20
+        return [
21
+            new Middleware('permission:view-bilancio-oggi', only: ['oggi']),
22
+            new Middleware('permission:view-bilancio', only: ['index']),
23
+            new Middleware('permission:create-bilancio|edit-bilancio|delete-bilancio', only: ['store', 'update', 'destroy']),
24
+        ];
25
+    }
26
+
27
+    public function oggi(Request $request)
28
+    {
29
+        return view('bilancio.oggi');
30
+    }
31
+}

+ 312
- 0
app/Http/Controllers/CarrelloController.php 파일 보기

@@ -0,0 +1,312 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Ordine;
7
+use App\Models\PuntoVendita;
8
+use App\Models\Attivita;
9
+use App\Models\Dispositivo;
10
+use App\Models\Pagamento;
11
+use App\Models\MetodoPagamento;
12
+use App\Models\RigaOrdine;
13
+use App\DataTables\RigaOrdineDataTable;
14
+use App\Models\Piatto;
15
+use Illuminate\Support\Facades\Auth;
16
+use Illuminate\Support\Facades\Session;
17
+use App\Http\Controllers\PagamentoController;
18
+
19
+class CarrelloController extends Controller
20
+{
21
+    public function index(){
22
+        // return Ordine::all();
23
+        return Ordine::where('stato', Ordine::CARRELLO)->get();
24
+    }
25
+
26
+
27
+    public function list(Request $request, RigaOrdineDataTable $dataTable){
28
+        $ordine = Ordine::where([
29
+            'stato' => Ordine::CARRELLO, 
30
+            'dispositivo_id' => Session::get('dispositivo_id') || $request->dispositivo_id,
31
+            'attivita_id' => Session::get('attivita_id') || $request->attivita_id,
32
+        ])->orderBy('created_at', 'desc')->first();
33
+    // dd($ordine->count());
34
+        return $dataTable->render('punto_vendita.cassa._partials.carrello.index', ['ordine' => $ordine]);
35
+    }
36
+
37
+
38
+    public function aumenta(Request $request){
39
+        $request->validate([
40
+            'ordine_id' => 'required|integer|exists:ordine,id',
41
+            'piatto_id' => 'required|integer|exists:piatto,id',
42
+            'dispositivo_id' => 'required|integer|exists:dispositivo,id',
43
+            'attivita_id' => 'nullable|integer|exists:attivita,id',
44
+        ]);
45
+
46
+        /** Stesso ordine mostrato in cassa: non usare updateOrCreate con session (crea disallineamenti). */
47
+        $carrello = Ordine::query()
48
+            ->whereKey($request->ordine_id)
49
+            ->where('stato', Ordine::CARRELLO)
50
+            ->where('dispositivo_id', $request->dispositivo_id)
51
+            ->when(
52
+                $request->filled('attivita_id'),
53
+                fn ($q) => $q->where('attivita_id', $request->attivita_id)
54
+            )
55
+            ->firstOrFail();
56
+
57
+        $riga = RigaOrdine::where('ordine_id', $carrello->id)->where('piatto_id', $request->piatto_id)->first();
58
+        if($riga){
59
+            $riga->quantita += 1;
60
+            $riga->prezzo = Piatto::find($request->piatto_id)->prezzo*$riga->quantita;
61
+            $riga->save();
62
+        }else{
63
+            $riga = RigaOrdine::create([
64
+                'ordine_id' => $carrello->id,
65
+                'piatto_id' => $request->piatto_id,
66
+                'quantita' => 1,
67
+                'prezzo' => Piatto::find($request->piatto_id)->prezzo,
68
+            ]);
69
+        }
70
+        // dd($riga);
71
+        return response()->json([
72
+            'success' => true,
73
+            'message' => 'Quantità aumentata',
74
+            'data' => $riga,
75
+        ]);
76
+    }
77
+
78
+    public function diminuisci(Request $request){
79
+        $carrello = Ordine::find($request->ordine_id);
80
+        $riga = RigaOrdine::where('ordine_id', $carrello->id)->where('piatto_id', $request->piatto_id)->first();
81
+        if($riga){
82
+            $riga->quantita -= 1;
83
+            $riga->prezzo = Piatto::find($request->piatto_id)->prezzo*$riga->quantita;
84
+            $riga->save();
85
+        }
86
+        return response()->json([
87
+            'success' => true,
88
+            'message' => 'Quantità diminuita',
89
+            'data' => $riga,
90
+        ]);
91
+    }
92
+
93
+
94
+    public function elimina(Request $request){
95
+        $riga = RigaOrdine::find($request->riga_ordine_id);
96
+        // dd($riga);
97
+        if($riga !== null && $request->has('elimina')){
98
+        $riga->delete();
99
+        };
100
+
101
+        return response()->json([
102
+            'success' => true,
103
+            'message' => 'Riga eliminata',
104
+            'data' => $riga,
105
+        ]);
106
+    }
107
+
108
+
109
+    public function aggiorna_nota(Request $request){
110
+        $riga = RigaOrdine::find($request->riga_ordine_id);
111
+        if($riga == null){
112
+            return response()->json([
113
+                'success' => false,
114
+                'message' => 'Riga ordine non trovata',
115
+                'data' => null,
116
+            ]);
117
+        }
118
+        $riga->note = $request->note;
119
+        $riga->save();
120
+        return response()->json([
121
+            'success' => true,
122
+            'message' => 'Nota aggiornata',
123
+            'data' => $riga,
124
+        ]);
125
+    }
126
+
127
+    public function azzera(Request $request){
128
+        $ordine = Ordine::find($request->ordine_id);
129
+        if($ordine == null){
130
+            return response()->json([
131
+                'success' => false,
132
+                'message' => 'Ordine non trovato',
133
+                'data' => null,
134
+            ]);
135
+        }
136
+        $righe = RigaOrdine::where('ordine_id', $ordine->id)->delete();
137
+        $ordine->prezzo = 0;
138
+        $ordine->save();
139
+        $ordine->delete();
140
+
141
+        switch(Dispositivo::cassa()->first()->tipo){
142
+            case Dispositivo::CASSA:
143
+                return redirect()->route('punto-vendita.show');
144
+                break;
145
+            case Dispositivo::TIPO_KIOSK:
146
+                // return redirect()->route('punto_vendita.kiosk.index');
147
+                return redirect()->route('punto-vendita.show');
148
+
149
+                break;
150
+            case Dispositivo::CAMERIERE:
151
+                // return redirect()->route('punto_vendita.cameriere.index');
152
+                return redirect()->route('punto-vendita.show');
153
+                
154
+                break;
155
+        }
156
+    }
157
+
158
+    public function totale(Request $request){
159
+        $ordine = Ordine::find($request->ordine_id);
160
+        if ($ordine == null){ 
161
+            return response()->json([
162
+                'success' => true,
163
+                'message' => 'Totale carrello',
164
+                'data' => 0,
165
+                'totale' => 0,
166
+                'quantita_totale' => 0,
167
+            ]);
168
+        }
169
+        // dd([$ordine->prezzo , $request->all()]);
170
+        if($ordine->prezzo == null || $ordine->prezzo == 0){
171
+            if($ordine->righe_ordine->count() >0){
172
+                $totale = $ordine->righe_ordine->sum('prezzo');
173
+            }else{
174
+                $totale = 0;
175
+            }
176
+        }else{
177
+            $totale = $ordine->righe_ordine->sum('prezzo');
178
+        }
179
+
180
+        $quantitaTotale = (int) $ordine->righe_ordine->sum('quantita');
181
+
182
+        return response()->json([
183
+            'success' => true,
184
+            'message' => 'Totale carrello',
185
+            'data' => $totale,
186
+            'totale' => $totale,
187
+            'quantita_totale' => $quantitaTotale,
188
+        ]);
189
+    }
190
+    public function aggiorna_info(Request $request){
191
+        $ordine = Ordine::find($request->ordine_id);
192
+        if($ordine == null){
193
+            return response()->json([
194
+                'success' => false,
195
+                'message' => 'Ordine non trovato',
196
+                'data' => null,
197
+            ]);
198
+        }
199
+        $ordine->info = [
200
+            'cliente' => $request->cliente,
201
+            'tavolo' => $request->tavolo,
202
+        ];
203
+        $ordine->save();
204
+        return response()->json([
205
+            'success' => true,  
206
+            'message' => 'Info aggiornata',
207
+            'data' => $ordine->info,
208
+        ]);
209
+    }
210
+
211
+    public function checkout(Request $request){
212
+        // $ordineA = Ordine::where([
213
+        //     'stato' => Ordine::CARRELLO, 
214
+        //     // 'dispositivo_id' => Session::get('dispositivo_id') || $request->dispositivo_id,
215
+        //     'attivita_id' => Session::get('attivita_id') || $request->attivita_id,
216
+        // ])->orderBy('created_at', 'desc')->first();
217
+        $ordine = Ordine::find($request->ordine_id);
218
+        if($ordine == null){
219
+            return  response()->json([
220
+                'success' => false,
221
+                'message' => 'Ordine non trovato',
222
+                'data' => null,
223
+                'ordineA' => $ordineA,
224
+                'ordineB' => $ordineB,
225
+                // 'ordineA->id == ordineB->id' => $ordineA->id == $ordineB->id,
226
+            ]);
227
+        }
228
+
229
+        $ordine->prezzo = $ordine->righe_ordine->sum('prezzo');
230
+        // $ordine->stato = Ordine::CHECKOUT;
231
+        $ordine->metodo_pagamento_id = $request->metodo_pagamento_id;
232
+        $ordine->tipo = $request->tipo;
233
+        $ordine->save();
234
+        
235
+    return view('punto_vendita.cassa._partials.carrello.pagamento.checkout', ['ordine' => $ordine, 'dispositivo' => $ordine->dispositivo, 'attivita' => $ordine->attivita]);
236
+    }
237
+
238
+    public function paga_ordine(Request $request){
239
+        $ordine = Ordine::find($request->ordine_id);
240
+        if($ordine == null){
241
+            return response()->json([
242
+                'success' => false,
243
+                'message' => 'Ordine non trovato',
244
+                'data' => null,
245
+            ]);
246
+        }
247
+        $pagamento = Pagamento::create([
248
+            'attivita_id' => session('attivita_id'), //$request->attivita_id,
249
+            'dispositivo_id' => $request->dispositivo_id,
250
+            'ordine_id' => $ordine->id,
251
+            'metodo_pagamento_id' => $request->metodo_pagamento_id,
252
+            'tipo' => $request->tipo,
253
+            'importo' => $ordine->prezzo,
254
+            'causale' => $ordine->attivita->nome.' - Pagamento ordine #'.$ordine->id,
255
+        ]);
256
+        $ordine->pagamento_id = $pagamento->id;
257
+        $ordine->stato = Ordine::IN_ATTESA_PAGAMENTO;
258
+        $ordine->save();
259
+        
260
+        switch($pagamento->metodo_pagamento->tipo){
261
+            case MetodoPagamento::CONTANTI:
262
+                $pagamento->stato = Pagamento::PAGATO;
263
+                $pagamento->save();
264
+                $ordine->update(['stato' => Ordine::PAGATO]);
265
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('success', 'Pagamento con contanti riuscito. ->'.$pagamento->metodo_pagamento->tipo);
266
+                break;
267
+            case MetodoPagamento::BONIFICO:
268
+                $pagamento->update(['stato' , Pagamento::PAGATO]);
269
+                $pagamento->save();
270
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('success', 'Pagamento con bonifico riuscito.');
271
+                break;  
272
+            case MetodoPagamento::PAYPAL:
273
+                $pagamento->update(['stato' , Pagamento::PAGATO]);
274
+                $pagamento->save();
275
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('success', 'Pagamento con paypal riuscito.');
276
+                break;
277
+            case MetodoPagamento::CARTA_DI_DEBITO:  
278
+                $pagamento->update(['stato' , Pagamento::PAGATO]);
279
+                $pagamento->save();
280
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('success', 'Pagamento con carta di debito riuscito.');
281
+                break;
282
+            case MetodoPagamento::CUPON:
283
+                $pagamento->update(['stato' , Pagamento::PAGATO]);
284
+                $pagamento->save();
285
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('success', 'Pagamento con coupon riuscito.');
286
+                break;
287
+            case MetodoPagamento::SEGRESTA_WALLET:
288
+                $pagamento->update(['stato' , Pagamento::PAGATO]);
289
+                $pagamento->save();
290
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('success', 'Pagamento con wallet riuscito.');
291
+                break;
292
+            case MetodoPagamento::APPLE_PAY:
293
+                $pagamento->update(['stato' , Pagamento::PAGATO]);
294
+                $pagamento->save();
295
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('success', 'Pagamento con apple pay riuscito.');
296
+                break;
297
+            case MetodoPagamento::GOOGLE_PAY:
298
+                $pagamento->update(['stato' , Pagamento::PAGATO]);
299
+                $pagamento->save();
300
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('success', 'Pagamento con google pay riuscito.');
301
+                break;
302
+            case MetodoPagamento::POS:
303
+                $pagamento->update(['stato' , Pagamento::PAGATO]);
304
+                $pagamento->save();
305
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('success', 'Pagamento con pos riuscito.');
306
+                break;
307
+            default:
308
+                return redirect()->route('punto-vendita.show', ['punto_vendita_id' => $ordine->dispositivo_id])->with('error', 'Metodo di pagamento non supportato. Pagamento non riuscito.'.$request->metodo_pagamento_id?? 'ND');
309
+                break;
310
+        }
311
+    }
312
+}

+ 33
- 0
app/Http/Controllers/ConsultaController.php 파일 보기

@@ -0,0 +1,33 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Ordine;
7
+
8
+class ConsultaController extends Controller
9
+{
10
+    public function index()
11
+    {
12
+        return view('consulta.index');
13
+    }
14
+
15
+    public function scontrino_show(Request $request)
16
+    {
17
+        $ordine = Ordine::find($request->route('ordine_id'));
18
+        // dd($ordine);
19
+        if (!$ordine) {
20
+            return redirect()->route('consulta.index')->with('error', 'Ordine non trovato');
21
+        }
22
+        return view('consulta.scontrino.show', compact('ordine'));
23
+    }
24
+    
25
+    public function comanda_show(Request $request)
26
+    {
27
+        $ordine = Ordine::find($request->route('ordine_id'));
28
+        if (!$ordine) {
29
+            return redirect()->route('consulta.index')->with('error', 'Ordine non trovato');
30
+        }
31
+        return view('consulta.comanda.show', compact('ordine'));
32
+    }
33
+}

+ 62
- 0
app/Http/Controllers/ContenutoBachecaController.php 파일 보기

@@ -0,0 +1,62 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\ContenutoBacheca;
7
+use App\DataTables\ContenutoBachecaDataTable;
8
+use App\DataTables\ContenutoBachecaDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+use Illuminate\Support\Facades\Session;
11
+
12
+class ContenutoBachecaController extends Controller
13
+{
14
+    public static $permission_group = "Contenuto Bacheca";
15
+    public static $permissions = [
16
+        'view-contenuto_bacheca' => 'Vedi',
17
+        'create-contenuto_bacheca' => 'Crea',
18
+        'edit-contenuto_bacheca' => 'Modifica',
19
+        'delete-contenuto_bacheca' => 'Elimina',
20
+    ];
21
+    
22
+    public static function middleware(): array
23
+    {
24
+        return [
25
+            new Middleware('permission:view-contenuto_bacheca', only: ['index']),
26
+            new Middleware('permission:create-contenuto_bacheca|edit-contenuto_bacheca|delete-contenuto_bacheca', only: ['store', 'update', 'destroy']),
27
+        ];
28
+    }
29
+    
30
+    public function index(ContenutoBachecaDataTable $dataTable)
31
+    {
32
+        return $dataTable->render('contenuto_bacheca.index');
33
+    }
34
+    
35
+    public function store(ContenutoBachecaDataTableEditor $editor)
36
+    {
37
+        $request = request();
38
+        $input = $request->all();
39
+        if($request->has('action')){
40
+            switch($input['action']){
41
+                case 'create':
42
+                    if(!Auth::user()->can('create-contenuto_bacheca')) return;
43
+                    break;
44
+                case 'edit':
45
+                    if(!Auth::user()->can('edit-contenuto_bacheca')) return;
46
+                    break;
47
+                case 'delete':
48
+                    if(!Auth::user()->can('delete-contenuto_bacheca')) return;
49
+                    break;
50
+            }
51
+        }
52
+        return $editor->process($request);
53
+    }
54
+    
55
+    public function show(Request $request)
56
+    {
57
+        $contenuto_bacheca = ContenutoBacheca::find($request->get('contenuto_bacheca_id'));
58
+        return view('contenuto_bacheca.show', ['contenuto_bacheca' => $contenuto_bacheca]);
59
+    }
60
+    
61
+}
62
+

+ 8
- 0
app/Http/Controllers/Controller.php 파일 보기

@@ -0,0 +1,8 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+abstract class Controller
6
+{
7
+  //
8
+}

+ 56
- 0
app/Http/Controllers/CucinaController.php 파일 보기

@@ -0,0 +1,56 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Cucina;
7
+use App\DataTables\CucinaDataTable;
8
+use App\DataTables\CucinaDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+
12
+class CucinaController extends Controller
13
+{
14
+    public static $permission_group = "Cucina";
15
+    public static $permissions = [
16
+        'view-cucina' => 'Vedi',
17
+        'create-cucina' => 'Crea',
18
+        'edit-cucina' => 'Modifica',
19
+        'delete-cucina' => 'Elimina',
20
+    ];
21
+
22
+    public static function middleware(): array
23
+    {
24
+        return [
25
+            new Middleware('permission:view-cucina', only: ['index']),
26
+            new Middleware('permission:create-cucina|edit-cucina|delete-cucina', only: ['store', 'update', 'destroy']),
27
+        ];
28
+    }
29
+
30
+    public function index(CucinaDataTable $dataTable)
31
+    {
32
+        return $dataTable->render('cucina.index');
33
+    }
34
+
35
+    public function store(CucinaDataTableEditor $editor)
36
+    {
37
+        $request = request();
38
+        $input = $request->all();
39
+        if($request->has('action')){
40
+          switch($input['action']){
41
+            case 'create':
42
+              if(!Auth::user()->can('create-cucina')) return;
43
+              break;
44
+            case 'edit':
45
+              if(!Auth::user()->can('edit-cucina')) return;
46
+              break;
47
+            case 'remove':
48
+              if(!Auth::user()->can('delete-cucina')) return;
49
+              break;
50
+          }
51
+        }
52
+        return $editor->process($request);
53
+    }
54
+
55
+
56
+}

+ 53
- 0
app/Http/Controllers/DispositivoController.php 파일 보기

@@ -0,0 +1,53 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Dispositivo;
7
+use App\DataTables\DispositivoDataTable;
8
+use App\DataTables\DispositivoDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+
12
+class DispositivoController extends Controller
13
+{
14
+    public static $permission_group = "Dispositivi";
15
+    public static $permissions = [
16
+        'view-dispositivo' => 'Vedi',
17
+        'create-dispositivo' => 'Crea',
18
+        'edit-dispositivo' => 'Modifica',
19
+        'delete-dispositivo' => 'Elimina',
20
+    ];
21
+    
22
+    public static function middleware(): array
23
+    {
24
+        return [
25
+            new Middleware('permission:view-dispositivo', only: ['index']),
26
+            new Middleware('permission:create-dispositivo|edit-dispositivo|delete-dispositivo', only: ['store', 'update', 'destroy']),
27
+        ];
28
+    }
29
+    
30
+    public function index(DispositivoDataTable $dataTable)
31
+    {
32
+        return $dataTable->render('dispositivo.index');
33
+    }
34
+    public function store(DispositivoDataTableEditor $editor)
35
+    {
36
+        $request = request();
37
+        $input = $request->all();
38
+        if($request->has('action')){
39
+            switch($input['action']){
40
+                case 'create':
41
+                    if(!Auth::user()->can('create-dispositivo')) return;
42
+                    break;
43
+                case 'edit':
44
+                    if(!Auth::user()->can('edit-dispositivo')) return;
45
+                    break;
46
+                case 'remove':
47
+                    if(!Auth::user()->can('delete-dispositivo')) return;
48
+                    break;
49
+            }
50
+        }
51
+        return $editor->process($request);
52
+    }
53
+}

+ 230
- 0
app/Http/Controllers/EndpointController.php 파일 보기

@@ -0,0 +1,230 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use Illuminate\Support\Facades\Log;
7
+use Illuminate\Support\Facades\Http;
8
+use App\Models\Endpoint;
9
+use App\Models\Dispositivo;
10
+use App\Models\PrintJob;
11
+use App\DataTables\EndpointDataTable;
12
+
13
+class EndpointController extends Controller
14
+{
15
+    public static $permission_group = "Endpoint";
16
+    public static $permissions = [
17
+        'view-endpoint' => 'Vedi',
18
+        'create-endpoint' => 'Crea',
19
+        'edit-endpoint' => 'Modifica',
20
+        'delete-endpoint' => 'Elimina',
21
+    ];
22
+    
23
+    
24
+    public static function middleware(): array
25
+    {
26
+        return [
27
+            new Middleware('permission:view-endpoint', only: ['index']),
28
+            new Middleware('permission:create-endpoint|edit-endpoint|delete-endpoint', only: ['store', 'update', 'destroy']),
29
+        ];
30
+    }
31
+    
32
+    //API
33
+    public function register(Request $request)
34
+    {
35
+        $request->validate([
36
+            'label' => 'required|string|max:255',
37
+            'descrizione' => 'required|string|max:255',
38
+            'url' => 'nullable|string|max:255',
39
+            'attivita_id' => 'required|integer|exists:attivita,id',
40
+        ]);
41
+        $endpoint = Endpoint::create([
42
+            'label' => $request->label,
43
+            'descrizione' => $request->descrizione,
44
+            'url' => $request->url,
45
+            'attivita_id' => $request->attivita_id,
46
+            'user_id' => $request->user()->id,
47
+            'info' => [
48
+              'stampanti' => [],
49
+            ],
50
+        ]);
51
+        return response()->json([
52
+            'message' => 'Endpoint registrato con successo',
53
+            'status' => 'success',
54
+            'success' => true,
55
+            'endpoint' => $endpoint
56
+        ]);
57
+    }
58
+
59
+    public function stampanti_register(Request $request)
60
+    {
61
+        Log::info('stampanti_register');
62
+        Log::info($request->all());
63
+        $request->validate([
64
+            'endpoint_id' => 'required|integer|exists:endpoint,id',
65
+            'attivita_id' => 'required|integer|exists:attivita,id',
66
+            'stampanti' => 'required|array',
67
+            // 'descrizione' => 'required|string|max:255',
68
+            // 'url' => 'required|url',
69
+        ]);
70
+       
71
+        $stampanti = $request->stampanti;
72
+        $stampanti_endpoint = Endpoint::find($request->endpoint_id)->info['stampanti'];
73
+        $endpoint = Endpoint::find($request->endpoint_id);
74
+
75
+        if(count($stampanti) > 0){
76
+            foreach($stampanti as $stampante){
77
+                $dispositivo = Dispositivo::create([
78
+                    'tipo' => Dispositivo::STAMPANTE,
79
+                    'attivita_id' => $request->attivita_id,
80
+                    'nome' => $stampante['nome'],
81
+                    'url_stampante' => $stampante['url_stampante'],
82
+                    'ubicazione' => "endpoint:".$request->endpoint_id,
83
+                    'is_attivo' => true,
84
+                    'endpoint_id' => $request->endpoint_id,
85
+                 ]);
86
+                 // Verifico che la stampante non sia già presente tra quelle registrate su questo endpoint
87
+                 if (!in_array($dispositivo->id, $endpoint->info['stampanti'])) {
88
+                     $info = $endpoint->info;
89
+                     $info['stampanti'][] = $dispositivo->id;
90
+                     $endpoint->info = $info;
91
+                     $endpoint->save();
92
+                 }
93
+            }
94
+            $forMapping = [];
95
+            foreach($endpoint->info['stampanti'] as $stampante_id){
96
+                // dd([$stampante_id , Dispositivo::find($stampante_id)]);
97
+                $forMapping[] = [
98
+                    'id' => $stampante_id,
99
+                    'nome' => Dispositivo::find($stampante_id)->nome,
100
+                    'url_stampante' => Dispositivo::find($stampante_id)->url_stampante,
101
+                ];
102
+            }
103
+            return response()->json([
104
+                'message' => 'Stampanti registrate con successo',
105
+                'status' => 'success',
106
+                'success' => true,
107
+                'endpoint' => $endpoint,
108
+                'stampanti' => $forMapping,
109
+            ]);
110
+
111
+        }else{
112
+            return response()->json([
113
+                'message' => 'Nessuna nuova stampante registrata',
114
+                'status' => 'error',
115
+                'success' => false,
116
+            ]);
117
+        }
118
+
119
+    }
120
+
121
+    public function get_lavoro(Request $request)
122
+    {
123
+        $request->validate([
124
+            'endpoint_id' => 'required|integer|exists:endpoint,id',
125
+            'attivita_id' => 'required|integer|exists:attivita,id',
126
+        ]);
127
+
128
+        $has_lavoro = false;
129
+        $endpoint = Endpoint::find($request->endpoint_id);
130
+        $stampanti = $endpoint->stampanti;
131
+        // Trova la lista degli ID delle stampanti associate a questo endpoint
132
+        $stampanti_ids = $endpoint->stampanti->pluck('id')->toArray();
133
+        // Cerca lavori associati a queste stampanti
134
+        $query = PrintJob::whereIn('stampante_id', $stampanti_ids)
135
+            ->where('stato', PrintJob::STATO_IN_CODA);
136
+
137
+        $lavori = $query->get();
138
+        // dd($lavori);
139
+        // dd($query->count());
140
+        if($query->count() > 0){
141
+            PrintJob::whereIn('stampante_id', $stampanti_ids)
142
+            ->where('stato', PrintJob::STATO_IN_CODA)
143
+            ->update([
144
+                'stato' => PrintJob::STATO_PRESO,
145
+            ]);
146
+            $has_lavoro = true;
147
+        }else{
148
+            $has_lavoro = false;
149
+        }
150
+
151
+        return response()->json([
152
+            'message' => $has_lavoro ? 'Lavoro trovato con successo' : 'Nessun lavoro trovato',
153
+            'status' => 'success',
154
+            'success' => true,
155
+            'lavoro' => $has_lavoro,
156
+            'lavori' => $lavori,
157
+        ]);
158
+
159
+    }
160
+
161
+    public function esito_stampa(Request $request)
162
+    {
163
+        $request->validate([
164
+            'printJob_id' => 'required|integer|exists:print_job,id',
165
+            'esito' => 'required|string|in:success,error',
166
+            'endpoint_id' => 'required|integer|exists:endpoint,id',
167
+        ]);
168
+
169
+        $printJob = PrintJob::find($request->printJob_id)->where('stato', PrintJob::STATO_PRESO);
170
+        if($printJob->count() == 0){
171
+            return response()->json([
172
+                'message' => 'Print job non trovato o non in stato preso',
173
+                'status' => 'error',
174
+                'success' => false,
175
+            ]);
176
+        };
177
+
178
+        switch($request->esito){
179
+            case 'success':
180
+                $printJob->update([
181
+                    'stato' => PrintJob::STATO_COMPLETATO,
182
+                ]);
183
+                break;
184
+            case 'error':
185
+                $printJob->update([
186
+                    'stato' => PrintJob::STATO_FALLITO,
187
+                ]);
188
+                break;
189
+        }
190
+        return response()->json([
191
+            'message' => 'Esito stampa aggiornato con successo',
192
+        ]);
193
+    }
194
+
195
+    //WEB
196
+    public function index(EndpointDataTable $dataTable)
197
+    {
198
+        return $dataTable->render('endpoint.index');
199
+    }
200
+
201
+    public function store(EndpointDataTableEditor $editor)
202
+    {
203
+        $request = request();
204
+        $input = $request->all();
205
+        if($request->has('action')){
206
+            switch($input['action']){
207
+                case 'create':
208
+                    if(!Auth::user()->can('create-endpoint')) return;
209
+                    break;  
210
+                case 'edit':
211
+                    if(!Auth::user()->can('edit-endpoint')) return;
212
+                    break;
213
+                case 'remove':
214
+                    if(!Auth::user()->can('delete-endpoint')) return;
215
+                    break;
216
+            }
217
+        }
218
+        return $editor->process($request);
219
+    }
220
+    public function index_api(Request $request)
221
+    {
222
+        $endpoints = Endpoint::all();
223
+        return response()->json([
224
+         'message' => 'Endpoint trovati con successo',
225
+         'count' => $endpoints->count(),
226
+         'status' => 'success', 
227
+         'success' => true, 
228
+         'endpoints' => $endpoints]);
229
+    }
230
+}

+ 86
- 0
app/Http/Controllers/EventoController.php 파일 보기

@@ -0,0 +1,86 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Evento;
7
+use App\DataTables\EventoDataTable;
8
+use App\DataTables\EventoDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+class EventoController extends Controller
12
+{
13
+    public static $permission_group = "Eventi";
14
+    public static $permissions = [
15
+        'view-evento' => 'Vedi',
16
+        'create-evento' => 'Crea',
17
+        'edit-evento' => 'Modifica',
18
+        'delete-evento' => 'Elimina',
19
+    ];
20
+
21
+    public static function middleware(): array
22
+    {
23
+        return [
24
+            new Middleware('permission:view-evento', only: ['index']),
25
+            new Middleware('permission:create-evento|edit-evento|delete-evento', only: ['store', 'update', 'destroy']),
26
+        ];
27
+    }
28
+
29
+    public function index(EventoDatatable $dataTable)
30
+    {
31
+        return $dataTable->render('evento.index');
32
+    }
33
+    public function store(EventoDataTableEditor $editor)
34
+    {
35
+        $request = request();
36
+        $input = $request->all();
37
+        if($request->has('action')){
38
+          switch($input['action']){
39
+            case 'create':
40
+              if(!Auth::user()->can('create-evento')) return;
41
+              break;
42
+            case 'edit':
43
+              if(!Auth::user()->can('edit-evento')) return;
44
+              break;
45
+            case 'remove':
46
+              if(!Auth::user()->can('delete-evento')) return;
47
+              break;
48
+          }
49
+        }
50
+        return $editor->process($request);
51
+    }
52
+
53
+    public function show(Request $request)
54
+    {
55
+      // dd($request->all());
56
+        $evento = Evento::find($request->get('evento_id'));
57
+        return view('evento.show', [
58
+          'evento' => $evento , 
59
+          'galleriaItems' => is_array(json_decode($evento->galleria, true)) ? json_decode($evento->galleria, true) : []]);
60
+    }
61
+
62
+    public function gallery_edit(Request $request)
63
+    {
64
+      $evento = Evento::find($request->get('evento_id'));
65
+
66
+      return view('evento.gallery.edit', [
67
+          'evento' => $evento,
68
+          'galleria' => json_decode($evento->galleria, true),
69
+      ]);
70
+    }
71
+
72
+    public function gallery_upload(Request $request)
73
+    {
74
+      $evento = Evento::find($request->get('evento_id'));
75
+      $galleria = json_decode($evento->galleria);
76
+      if($galleria == null) $galleria = [];
77
+      $nome = $request->file('file')->getClientOriginalName();
78
+      $galleria[] = [
79
+        'nome' => $nome,
80
+        'path' => $request->file('file')->store( $evento->id . '/gallery', 'eventi')
81
+      ];
82
+      $evento->galleria = json_encode($galleria);
83
+      $evento->save();
84
+      return redirect()->route('evento.gallery.edit', ['evento_id' => $evento->id])->with('success', 'Foto aggiunta con successo');
85
+    }
86
+}

+ 53
- 0
app/Http/Controllers/FornitoreController.php 파일 보기

@@ -0,0 +1,53 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Fornitore;
7
+use App\DataTables\FornitoreDataTable;
8
+use App\DataTables\FornitoreDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+class FornitoreController extends Controller
12
+{
13
+    public static $permission_group = "Fornitori";
14
+    public static $permissions = [
15
+        'view-fornitore' => 'Vedi',
16
+        'create-fornitore' => 'Crea',
17
+        'edit-fornitore' => 'Modifica',
18
+        'delete-fornitore' => 'Elimina',
19
+    ];
20
+    
21
+    public static function middleware(): array
22
+    {
23
+        return [
24
+            new Middleware('permission:view-fornitore', only: ['index']),
25
+            new Middleware('permission:create-fornitore|edit-fornitore|delete-fornitore', only: ['store', 'update', 'destroy']),
26
+        ];
27
+    }
28
+    
29
+    public function index(FornitoreDataTable $dataTable)
30
+    {
31
+        return $dataTable->render('fornitore.index');
32
+    }
33
+    
34
+    public function store(FornitoreDataTableEditor $editor)
35
+    {
36
+        $request = request();
37
+        $input = $request->all();
38
+        if($request->has('action')){
39
+            switch($input['action']){
40
+                case 'create':
41
+                    if(!Auth::user()->can('create-fornitore')) return;
42
+                    break;
43
+                case 'edit':
44
+                    if(!Auth::user()->can('edit-fornitore')) return;
45
+                    break;
46
+                case 'remove':
47
+                    if(!Auth::user()->can('delete-fornitore')) return;
48
+                    break;
49
+            }
50
+        }
51
+        return $editor->process($request);
52
+    }
53
+}

+ 389
- 0
app/Http/Controllers/HomePageController.php 파일 보기

@@ -0,0 +1,389 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use App\Http\Controllers\Controller;
6
+use Illuminate\Http\Request;
7
+use App\Models\Segnalazione;
8
+use App\Models\Reparto;
9
+use App\Models\Manutentore;
10
+use App\Models\TempoImpiegato;
11
+use App\Models\Config;
12
+use App\Models\ConfiguraSegnalazione;
13
+use App\Models\Annotazione;
14
+use App\Models\Ordine;
15
+use Carbon\Carbon;
16
+use Illuminate\Support\Facades\DB;
17
+
18
+class HomePageController extends Controller
19
+{
20
+  public function welcome()
21
+  {
22
+    $pageConfigs = ['myLayout' => 'front'];
23
+    return view('welcome', ['pageConfigs' => $pageConfigs]);
24
+  }
25
+
26
+  public function admin_dashboard()
27
+  {
28
+    return view('dashboard.index', [
29
+      'statOrdini' => $this->getStatOrdini(),
30
+      'totaleRedditi' => $this->getTotaleRedditi(),
31
+    ]);
32
+  }
33
+
34
+  /**
35
+   * Incassi da ordini (esclusi carrello / annullati): serie mensile anno corrente e KPI riepilogo.
36
+   *
37
+   * @return array<string, mixed>
38
+   */
39
+  private function getTotaleRedditi(): array
40
+  {
41
+    $now = Carbon::now();
42
+    $year = (int) $now->year;
43
+    $startYear = Carbon::create($year, 1, 1)->startOfDay();
44
+    $endYear = Carbon::create($year, 12, 31)->endOfDay();
45
+
46
+    $base = Ordine::query()
47
+      ->whereNotNull('prezzo')
48
+      ->where('prezzo', '>', 0)
49
+      ->whereNotIn('stato', [
50
+        Ordine::CARRELLO,
51
+        Ordine::ANNULATO,
52
+        Ordine::CANCELLATO,
53
+        Ordine::CHECKOUT,
54
+      ]);
55
+
56
+    $chartSeries = [];
57
+    for ($m = 1; $m <= 12; $m++) {
58
+      $chartSeries[] = round((float) (clone $base)
59
+        ->whereYear('created_at', $year)
60
+        ->whereMonth('created_at', $m)
61
+        ->sum('prezzo'), 2);
62
+    }
63
+
64
+    $categories = ['Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic'];
65
+
66
+    $ytdEnd = $now->copy()->endOfDay();
67
+    if ($ytdEnd->gt($endYear)) {
68
+      $ytdEnd = $endYear->copy();
69
+    }
70
+
71
+    $incassoYtd = (float) (clone $base)
72
+      ->whereBetween('created_at', [$startYear, $ytdEnd])
73
+      ->sum('prezzo');
74
+
75
+    $prevYearStart = $startYear->copy()->subYear();
76
+    $prevYearSameDay = $now->copy()->subYear();
77
+    $incassoYtdAnnoPrec = (float) (clone $base)
78
+      ->whereBetween('created_at', [$prevYearStart, $prevYearSameDay])
79
+      ->sum('prezzo');
80
+
81
+    $deltaYtdPct = $incassoYtdAnnoPrec > 0.009
82
+      ? round((($incassoYtd - $incassoYtdAnnoPrec) / $incassoYtdAnnoPrec) * 100, 1)
83
+      : null;
84
+
85
+    $monthsElapsed = max(1, (int) $now->month);
86
+    $mediaMensile = $incassoYtd / $monthsElapsed;
87
+
88
+    $meseCorrenteStart = $now->copy()->startOfMonth();
89
+    $meseCorrenteEnd = $now->copy()->endOfMonth();
90
+    $incassoMeseCorrente = (float) (clone $base)
91
+      ->whereBetween('created_at', [$meseCorrenteStart, $meseCorrenteEnd])
92
+      ->sum('prezzo');
93
+
94
+    $mesePrecStart = $now->copy()->subMonth()->startOfMonth();
95
+    $mesePrecEnd = $now->copy()->subMonth()->endOfMonth();
96
+    $incassoMesePrec = (float) (clone $base)
97
+      ->whereBetween('created_at', [$mesePrecStart, $mesePrecEnd])
98
+      ->sum('prezzo');
99
+
100
+    $deltaMeseEuro = $incassoMeseCorrente - $incassoMesePrec;
101
+
102
+    $maxChart = max($chartSeries) ?: 1.0;
103
+
104
+    $nomiMesi = [
105
+      1 => 'Gennaio', 2 => 'Febbraio', 3 => 'Marzo', 4 => 'Aprile',
106
+      5 => 'Maggio', 6 => 'Giugno', 7 => 'Luglio', 8 => 'Agosto',
107
+      9 => 'Settembre', 10 => 'Ottobre', 11 => 'Novembre', 12 => 'Dicembre',
108
+    ];
109
+
110
+    return [
111
+      'year' => $year,
112
+      'mese_corrente_nome' => $nomiMesi[(int) $now->month] ?? '',
113
+      'chart_categories' => $categories,
114
+      'chart_series' => $chartSeries,
115
+      'chart_max' => max(100.0, $maxChart * 1.15),
116
+      'incasso_ytd' => $incassoYtd,
117
+      'incasso_ytd_fmt' => number_format($incassoYtd, 2, ',', '.'),
118
+      'delta_ytd_pct' => $deltaYtdPct,
119
+      'delta_ytd_positive' => $deltaYtdPct === null ? null : $deltaYtdPct >= 0,
120
+      'media_mensile' => $mediaMensile,
121
+      'media_mensile_fmt' => number_format($mediaMensile, 2, ',', '.'),
122
+      'incasso_mese_corrente' => $incassoMeseCorrente,
123
+      'incasso_mese_corrente_fmt' => number_format($incassoMeseCorrente, 2, ',', '.'),
124
+      'delta_mese_euro' => $deltaMeseEuro,
125
+      'delta_mese_fmt' => ($deltaMeseEuro >= 0 ? '+' : '-') . ' ' . number_format(abs($deltaMeseEuro), 2, ',', '.') . ' €',
126
+      'delta_mese_positive' => $deltaMeseEuro >= 0,
127
+      'delta_ytd_fmt' => $deltaYtdPct === null
128
+        ? null
129
+        : (($deltaYtdPct >= 0 ? '+' : '') . number_format($deltaYtdPct, 1, ',', '.') . ' %'),
130
+    ];
131
+  }
132
+
133
+  private function getStatOrdini(): array
134
+  {
135
+    $total = Ordine::query()->count();
136
+    $totaleIncasso = (float) Ordine::query()->whereNotNull('prezzo')->sum('prezzo');
137
+
138
+    $byStato = Ordine::query()
139
+      ->select('stato', DB::raw('COUNT(*) as totale'))
140
+      ->groupBy('stato')
141
+      ->orderByDesc('totale')
142
+      ->get();
143
+
144
+    $statiMap = Ordine::STATI;
145
+    $colorCycle = ['#28c76f', '#696cff', '#03c3ec', '#ff9f43', '#8592a3', '#ff3e1d', '#7367f0', '#ea5455', '#00cfe8'];
146
+    $bgCycle = ['primary', 'success', 'info', 'warning', 'secondary', 'danger', 'primary', 'danger', 'info'];
147
+
148
+    $rows = [];
149
+    $chartLabels = [];
150
+    $chartSeries = [];
151
+    $chartColors = [];
152
+
153
+    $i = 0;
154
+    foreach ($byStato as $row) {
155
+      $key = (string) $row->stato;
156
+      $count = (int) $row->totale;
157
+      $meta = $statiMap[$key] ?? null;
158
+      $label = is_array($meta) ? ($meta['label'] ?? $key) : $key;
159
+      $subtitle = is_array($meta) ? ($meta['descrizione'] ?? $key) : $key;
160
+
161
+      $rows[] = [
162
+        'label' => $label,
163
+        'count' => $count,
164
+        'subtitle' => $subtitle,
165
+        'icon' => $this->iconForOrdineStato($key),
166
+        'bg' => 'bg-label-' . $bgCycle[$i % count($bgCycle)],
167
+      ];
168
+      $chartLabels[] = $label;
169
+      $chartSeries[] = $count;
170
+      $chartColors[] = $colorCycle[$i % count($colorCycle)];
171
+      $i++;
172
+    }
173
+
174
+    if ($total === 0) {
175
+      $chartLabels = ['Nessun ordine'];
176
+      $chartSeries = [1];
177
+      $chartColors = ['#8592a3'];
178
+    }
179
+
180
+    return [
181
+      'total_ordini' => $total,
182
+      'totale_incasso' => $totaleIncasso,
183
+      'totale_incasso_fmt' => number_format($totaleIncasso, 2, ',', '.'),
184
+      'rows' => $rows,
185
+      'chart_labels' => $chartLabels,
186
+      'chart_series' => $chartSeries,
187
+      'chart_colors' => $chartColors,
188
+    ];
189
+  }
190
+
191
+  private function iconForOrdineStato(string $stato): string
192
+  {
193
+    $meta = Ordine::STATI[$stato] ?? null;
194
+    return is_array($meta) ? ($meta['icon'] ?? 'bx bx-receipt') : 'bx bx-receipt';
195
+
196
+  }
197
+
198
+  private function getDashboardData()
199
+  {
200
+    // KPI - Statistiche generali
201
+    $totaleSegnalazioni = Segnalazione::count();
202
+    $segnalazioniAperte = Segnalazione::where('stato', Config::getStatiSegnalazione('aperte'))->count();
203
+    $segnalazioniInLavorazione = Segnalazione::whereIn('stato', Config::getStatiSegnalazione('in_lavorazione'))->count();
204
+    $segnalazioniChiuse = Segnalazione::whereIn('stato', Config::getStatiSegnalazione('chiuse'))->count();
205
+
206
+    // Statistiche mese corrente
207
+    $meseCorrente = Carbon::now()->startOfMonth();
208
+    $fineMeseCorrente = Carbon::now()->endOfMonth();
209
+    $mesePrecedente = Carbon::now()->subMonth()->startOfMonth();
210
+    $fineMesePrecedente = Carbon::now()->subMonth()->endOfMonth();
211
+
212
+    $costiMese = Annotazione::whereBetween('created_at', [$meseCorrente, $fineMeseCorrente])->sum('costo');
213
+
214
+    $costiMesePrecedente = Annotazione::whereBetween('created_at', [$mesePrecedente, $fineMesePrecedente])->sum('costo');
215
+
216
+    $variazioneCosti = $costiMesePrecedente > 0
217
+    ? round((($costiMese - $costiMesePrecedente) / $costiMesePrecedente) * 100, 2)
218
+    : ($costiMese > 0 ? 100 : 0);
219
+
220
+    $tempiMese = Annotazione::whereBetween('tempo_data', [$meseCorrente, $fineMeseCorrente])->sum('tempo_minuti');
221
+    $oreTotaliMese = Config::formatTempo($tempiMese);
222
+
223
+    // Tempo medio di risoluzione (in giorni)
224
+    $segnalazioniChiuseConTempo = Segnalazione::whereIn('stato', Config::getStatiSegnalazione('chiuse'))
225
+    ->whereNotNull('updated_at')
226
+    ->whereNotNull('created_at')
227
+    ->get();
228
+
229
+    $tempoMedioRisoluzione = 0;
230
+    if ($segnalazioniChiuseConTempo->count() > 0) {
231
+      $giorniTotali = $segnalazioniChiuseConTempo->sum(function($segnalazione) {
232
+        return $segnalazione->created_at->diffInDays($segnalazione->updated_at);
233
+      });
234
+      $tempoMedioRisoluzione = round($giorniTotali / $segnalazioniChiuseConTempo->count(), 1);
235
+    }
236
+
237
+
238
+    $segnalazioniUrgentiAperte = Segnalazione::whereNotIn('stato', Config::getStatiSegnalazione('chiuse'))
239
+    ->whereIn('priorita', ['urgente', 'emergenza_immediata'])
240
+    ->count();
241
+
242
+    // Segnalazioni senza assegnazione
243
+    $segnalazioniSenzaAssegnazione = Segnalazione::whereNotIn('stato', Config::getStatiSegnalazione('chiuse'))->whereNull('user_id')
244
+    ->count();
245
+
246
+    // Segnalazioni aperte da più di 7 giorni
247
+    $dataLimite = Carbon::now()->subDays(7);
248
+    $segnalazioniAperteVecchie = Segnalazione::whereNotIn('stato', Config::getStatiSegnalazione('chiuse'))
249
+    ->where('created_at', '<', $dataLimite)
250
+    ->count();
251
+
252
+    // Grafico segnalazioni nel tempo (ultimi 30 giorni)
253
+    $giorni = 30;
254
+    $dataInizio = Carbon::now()->subDays($giorni);
255
+    $segnalazioniTempo = Segnalazione::where('created_at', '>=', $dataInizio)
256
+    ->selectRaw('DATE(created_at) as data, COUNT(*) as totale')
257
+    ->groupBy('data')
258
+    ->orderBy('data')
259
+    ->get();
260
+
261
+    $labelsTempo = [];
262
+    $datiTempo = [];
263
+    $dataCorrente = $dataInizio->copy();
264
+    while ($dataCorrente <= Carbon::now()) {
265
+      $dataStr = $dataCorrente->format('Y-m-d');
266
+      $labelsTempo[] = $dataCorrente->format('d/m');
267
+      $datiTempo[] = $segnalazioniTempo->firstWhere('data', $dataStr)->totale ?? 0;
268
+      $dataCorrente->addDay();
269
+    }
270
+
271
+    // Distribuzione per stato
272
+    $distribuzioneStato = Segnalazione::select('stato', DB::raw('COUNT(*) as totale'))
273
+    ->groupBy('stato')
274
+    ->get();
275
+
276
+    $labelsStato = [];
277
+    $datiStato = [];
278
+    foreach ($distribuzioneStato as $item) {
279
+      $config = ConfiguraSegnalazione::where('gruppo', 'stato')
280
+      ->where('value', $item->stato)
281
+      ->first();
282
+      $labelsStato[] = $config ? $config->label : $item->stato;
283
+      $datiStato[] = $item->totale;
284
+    }
285
+
286
+    // Distribuzione per priorità
287
+    $distribuzionePriorita = Segnalazione::select('priorita', DB::raw('COUNT(*) as totale'))
288
+    ->whereNotNull('priorita')
289
+    ->groupBy('priorita')
290
+    ->get();
291
+
292
+    $labelsPriorita = [];
293
+    $datiPriorita = [];
294
+    foreach(ConfiguraSegnalazione::where('gruppo', 'Priorità')->orderBy('order', 'asc')->get() as $config) {
295
+      $labelsPriorita[] = $config->label;
296
+      $datiPriorita[] = Segnalazione::where('priorita', $config->value)->count();
297
+    }
298
+
299
+    // Distribuzione per tipo
300
+    $distribuzioneTipo = Segnalazione::select('tipo', DB::raw('COUNT(*) as totale'))
301
+    ->whereNotNull('tipo')
302
+    ->groupBy('tipo')
303
+    ->get();
304
+
305
+    $labelsTipo = [];
306
+    $datiTipo = [];
307
+    foreach ($distribuzioneTipo as $item) {
308
+      $config = ConfiguraSegnalazione::where('gruppo', 'Tipo')
309
+      ->where('value', $item->tipo)
310
+      ->first();
311
+      $labelsTipo[] = $config ? $config->label : $item->tipo;
312
+      $datiTipo[] = $item->totale;
313
+    }
314
+
315
+    // Distribuzione per reparto
316
+    $labelsReparto = [];
317
+    $datiReparto = [];
318
+
319
+    foreach(Reparto::where('is_attivo', true)->orderBy('label', 'asc')->get() as $reparto) {
320
+      $labelsReparto[] = $reparto->label;
321
+      $datiReparto[] = Segnalazione::where('reparto_id', $reparto->id)->count();
322
+    }
323
+
324
+    // Assicurati che tutti gli array non siano vuoti per evitare errori nei grafici
325
+    if (empty($labelsTempo)) {
326
+      $labelsTempo = ['Nessun dato'];
327
+      $datiTempo = [0];
328
+    }
329
+    if (empty($labelsStato)) {
330
+      $labelsStato = ['Nessun dato'];
331
+      $datiStato = [0];
332
+    }
333
+    if (empty($labelsPriorita)) {
334
+      $labelsPriorita = ['Nessun dato'];
335
+      $datiPriorita = [0];
336
+    }
337
+    if (empty($labelsReparto)) {
338
+      $labelsReparto = ['Nessun dato'];
339
+      $datiReparto = [0];
340
+    }
341
+    if (empty($labelsManutentori)) {
342
+      $labelsManutentori = ['Nessun dato'];
343
+      $datiManutentori = [0];
344
+    }
345
+    if (empty($labelsCostiReparto)) {
346
+      $labelsCostiReparto = ['Nessun dato'];
347
+      $datiCostiReparto = [0];
348
+    }
349
+    if (empty($labelsTipo)) {
350
+      $labelsTipo = ['Nessun dato'];
351
+      $datiTipo = [0];
352
+    }
353
+    if (empty($labelsCostiTipo)) {
354
+      $labelsCostiTipo = ['Nessun dato'];
355
+      $datiCostiTipo = [0];
356
+    }
357
+
358
+    return [
359
+      'totaleSegnalazioni' => $totaleSegnalazioni,
360
+      'segnalazioniAperte' => $segnalazioniAperte,
361
+      'segnalazioniInLavorazione' => $segnalazioniInLavorazione,
362
+      'segnalazioniChiuse' => $segnalazioniChiuse,
363
+      'costiMese' => $costiMese,
364
+      'costiMesePrecedente' => $costiMesePrecedente,
365
+      'variazioneCosti' => $variazioneCosti,
366
+      'oreTotaliMese' => $oreTotaliMese,
367
+      'tempoMedioRisoluzione' => $tempoMedioRisoluzione,
368
+      'segnalazioniUrgentiAperte' => $segnalazioniUrgentiAperte,
369
+      'segnalazioniSenzaAssegnazione' => $segnalazioniSenzaAssegnazione,
370
+      'segnalazioniAperteVecchie' => $segnalazioniAperteVecchie,
371
+      'labelsTempo' => $labelsTempo,
372
+      'datiTempo' => $datiTempo,
373
+      'labelsStato' => $labelsStato,
374
+      'datiStato' => $datiStato,
375
+      'labelsPriorita' => $labelsPriorita,
376
+      'datiPriorita' => $datiPriorita,
377
+      'labelsReparto' => $labelsReparto,
378
+      'datiReparto' => $datiReparto,
379
+      'labelsManutentori' => $labelsManutentori,
380
+      'datiManutentori' => $datiManutentori,
381
+      'labelsCostiReparto' => $labelsCostiReparto,
382
+      'datiCostiReparto' => $datiCostiReparto,
383
+      'labelsTipo' => $labelsTipo,
384
+      'datiTipo' => $datiTipo,
385
+      'labelsCostiTipo' => $labelsCostiTipo,
386
+      'datiCostiTipo' => $datiCostiTipo,
387
+    ];
388
+  }
389
+}

+ 10
- 0
app/Http/Controllers/LicenzaController.php 파일 보기

@@ -0,0 +1,10 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+
7
+class LicenzaController extends Controller
8
+{
9
+    //
10
+}

+ 209
- 0
app/Http/Controllers/MappaDispositiviController.php 파일 보기

@@ -0,0 +1,209 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Attivita;
7
+use App\Models\Dispositivo;
8
+use App\Models\Cucina;
9
+use App\DataTables\DispositivoDataTable;
10
+use App\DataTables\DispositivoDataTableEditor;
11
+use Illuminate\Support\Facades\Auth;
12
+use Illuminate\Support\Facades\Session;
13
+
14
+class MappaDispositiviController extends Controller
15
+{
16
+    public static $permission_group = "Mappa Dispositivi";
17
+    public static $permissions = [
18
+        'view-mappa_dispositivi' => 'Vedi',
19
+        'create-mappa_dispositivi' => 'Crea',
20
+        'edit-mappa_dispositivi' => 'Modifica',
21
+        'delete-mappa_dispositivi' => 'Elimina',
22
+    ];
23
+    
24
+    public static function middleware(): array
25
+    {
26
+        return [
27
+            new Middleware('permission:view-mappa_dispositivi', only: ['index']),
28
+            new Middleware('permission:create-mappa_dispositivi|edit-mappa_dispositivi|delete-mappa_dispositivi', only: ['store', 'update', 'destroy']),
29
+        ];
30
+    }
31
+    
32
+    public function index(DispositivoDataTable $dataTable)
33
+    {
34
+        $response = $dataTable->render('mappa_dispositivi.index');
35
+
36
+        // Passiamo i dati per la topografica SOLO quando stiamo rendendo HTML.
37
+        // In AJAX (DataTables) qui arriva una JsonResponse.
38
+        if ($response instanceof \Illuminate\View\View) {
39
+            $topologyByAttivita = self::buildTopologyByAttivita();
40
+
41
+            return $response->with('topologyByAttivita', $topologyByAttivita);
42
+        }
43
+
44
+        return $response;
45
+    }
46
+
47
+    public function store(DispositivoDataTableEditor $editor)
48
+    {
49
+        $request = request();
50
+        $input = $request->all();
51
+        if($request->has('action')){
52
+            switch($input['action']){
53
+                case 'create':
54
+                    if(!Auth::user()->can('create-mappa_dispositivi')) return;
55
+                    break;
56
+                case 'edit':
57
+                    if(!Auth::user()->can('edit-mappa_dispositivi')) return;
58
+                    break;
59
+                case 'remove':
60
+                    if(!Auth::user()->can('delete-mappa_dispositivi')) return;
61
+                    break;
62
+            }
63
+        }
64
+        return $editor->process($request);
65
+    }
66
+    public function show($dispositivo_id)
67
+    {
68
+        $dispositivo = Dispositivo::find($dispositivo_id);
69
+        return view('mappa_dispositivi.show', ['dispositivo' => $dispositivo]);
70
+    }
71
+
72
+    /**
73
+     * Bozza mappa: contenitore = attività → punto vendita (cassa/kiosk/cameriere) + cucine → stampante.
74
+     */
75
+    public static function buildTopologyByAttivita(): array
76
+    {
77
+        $pvTipi = [Dispositivo::CASSA, Dispositivo::KIOSK, Dispositivo::CAMERIERE];
78
+
79
+        $attivitaRows = Attivita::query()
80
+            ->where('is_attiva', true)
81
+            ->orderBy('nome')
82
+            ->get(['id', 'nome']);
83
+
84
+        $attivitaIds = $attivitaRows->pluck('id')->all();
85
+
86
+        $devicesGrouped = Dispositivo::query()
87
+            ->whereIn('attivita_id', $attivitaIds)
88
+            ->orderBy('nome')
89
+            ->get(['id', 'nome', 'ubicazione', 'tipo', 'is_attivo', 'attivita_id'])
90
+            ->groupBy(fn (Dispositivo $d) => (int) $d->attivita_id);
91
+
92
+        $cucineByAttivita = Cucina::query()
93
+            ->whereIn('attivita_id', $attivitaIds)
94
+            ->orderBy('nome')
95
+            ->get(['id', 'nome', 'stampante_id', 'attivita_id'])
96
+            ->groupBy(fn (Cucina $c) => (int) $c->attivita_id);
97
+
98
+        $stampanteIds = Cucina::query()
99
+            ->whereIn('attivita_id', $attivitaIds)
100
+            ->whereNotNull('stampante_id')
101
+            ->pluck('stampante_id')
102
+            ->unique()
103
+            ->filter()
104
+            ->values();
105
+
106
+        $stampanti = Dispositivo::query()
107
+            ->whereIn('id', $stampanteIds)
108
+            ->get(['id', 'nome', 'ubicazione', 'tipo', 'is_attivo'])
109
+            ->keyBy('id');
110
+
111
+        $serialize = static function (Dispositivo $d): array {
112
+            $attrs = $d->getAttributes();
113
+            $ip = null;
114
+            if (array_key_exists('ip', $attrs) && $attrs['ip'] !== null) {
115
+                $ip = (string) $attrs['ip'];
116
+            }
117
+
118
+            return [
119
+                'id' => (int) $d->id,
120
+                'nome' => (string) $d->nome,
121
+                'ubicazione' => $d->ubicazione !== null ? (string) $d->ubicazione : null,
122
+                'tipo' => $d->tipo !== null ? (string) $d->tipo : null,
123
+                'is_attivo' => (bool) $d->is_attivo,
124
+                'ip' => $ip,
125
+            ];
126
+        };
127
+
128
+        $out = [];
129
+
130
+        foreach ($attivitaRows as $att) {
131
+            $aid = (int) $att->id;
132
+            $devices = $devicesGrouped->get($aid, collect());
133
+            $puntiVendita = $devices->whereIn('tipo', $pvTipi)->values()->map($serialize)->all();
134
+            $altri = $devices->whereNotIn('tipo', $pvTipi)->values()->map($serialize)->all();
135
+
136
+            $cucinePayload = [];
137
+            foreach ($cucineByAttivita->get($aid, collect()) as $cucina) {
138
+                $st = null;
139
+                if ($cucina->stampante_id && $stampanti->has((int) $cucina->stampante_id)) {
140
+                    $st = $serialize($stampanti->get((int) $cucina->stampante_id));
141
+                } elseif ($cucina->stampante_id) {
142
+                    $fallback = Dispositivo::query()->find((int) $cucina->stampante_id);
143
+                    if ($fallback) {
144
+                        $st = $serialize($fallback);
145
+                    }
146
+                }
147
+                $cucinePayload[] = [
148
+                    'id' => (int) $cucina->id,
149
+                    'nome' => (string) $cucina->nome,
150
+                    'stampante' => $st,
151
+                ];
152
+            }
153
+
154
+            $out[] = [
155
+                'id' => $aid,
156
+                'nome' => (string) $att->nome,
157
+                'punti_vendita' => $puntiVendita,
158
+                'cucine' => $cucinePayload,
159
+                'altri' => $altri,
160
+            ];
161
+        }
162
+
163
+        $orphanDevices = Dispositivo::query()
164
+            ->whereNull('attivita_id')
165
+            ->orderBy('nome')
166
+            ->get(['id', 'nome', 'ubicazione', 'tipo', 'is_attivo', 'attivita_id']);
167
+
168
+        $orphanCucine = Cucina::query()
169
+            ->whereNull('attivita_id')
170
+            ->orderBy('nome')
171
+            ->get(['id', 'nome', 'stampante_id', 'attivita_id']);
172
+
173
+        if ($orphanDevices->isNotEmpty() || $orphanCucine->isNotEmpty()) {
174
+            $orphanStampanteIds = $orphanCucine->pluck('stampante_id')->filter()->unique()->values();
175
+            $orphanStampanti = Dispositivo::query()
176
+                ->whereIn('id', $orphanStampanteIds)
177
+                ->get(['id', 'nome', 'ubicazione', 'tipo', 'is_attivo'])
178
+                ->keyBy('id');
179
+
180
+            $cucineOrfane = [];
181
+            foreach ($orphanCucine as $cucina) {
182
+                $st = null;
183
+                if ($cucina->stampante_id && $orphanStampanti->has((int) $cucina->stampante_id)) {
184
+                    $st = $serialize($orphanStampanti->get((int) $cucina->stampante_id));
185
+                } elseif ($cucina->stampante_id) {
186
+                    $fb = Dispositivo::query()->find((int) $cucina->stampante_id);
187
+                    if ($fb) {
188
+                        $st = $serialize($fb);
189
+                    }
190
+                }
191
+                $cucineOrfane[] = [
192
+                    'id' => (int) $cucina->id,
193
+                    'nome' => (string) $cucina->nome,
194
+                    'stampante' => $st,
195
+                ];
196
+            }
197
+
198
+            $out[] = [
199
+                'id' => 0,
200
+                'nome' => 'Senza attività',
201
+                'punti_vendita' => $orphanDevices->whereIn('tipo', $pvTipi)->values()->map($serialize)->all(),
202
+                'cucine' => $cucineOrfane,
203
+                'altri' => $orphanDevices->whereNotIn('tipo', $pvTipi)->values()->map($serialize)->all(),
204
+            ];
205
+        }
206
+
207
+        return $out;
208
+    }
209
+}

+ 53
- 0
app/Http/Controllers/MetodoPagamentoController.php 파일 보기

@@ -0,0 +1,53 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\MetodoPagamento;
7
+use App\DataTables\MetodoPagamentoDataTable;
8
+use App\DataTables\MetodoPagamentoDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+class MetodoPagamentoController extends Controller
12
+{
13
+    public static $permission_group = "Metodi di pagamento";
14
+    public static $permissions = [
15
+        'view-metodo_pagamento' => 'Vedi',
16
+        'create-metodo_pagamento' => 'Crea',
17
+        'edit-metodo_pagamento' => 'Modifica',
18
+        'delete-metodo_pagamento' => 'Elimina',
19
+    ];
20
+    
21
+    public static function middleware(): array
22
+    {
23
+        return [
24
+            new Middleware('permission:view-metodo_pagamento', only: ['index']),
25
+            new Middleware('permission:create-metodo_pagamento|edit-metodo_pagamento|delete-metodo_pagamento', only: ['store', 'update', 'destroy']),
26
+        ];
27
+    }
28
+    
29
+    public function index(MetodoPagamentoDataTable $dataTable)
30
+    {
31
+        return $dataTable->render('metodo_pagamento.index');
32
+    }
33
+    public function store(MetodoPagamentoDataTableEditor $editor)
34
+    {
35
+        $request = request();
36
+        $input = $request->all();
37
+        if($request->has('action')){
38
+            switch($input['action']){
39
+                case 'create':
40
+                    if(!Auth::user()->can('create-metodo_pagamento')) return;
41
+                    break;
42
+                case 'edit':
43
+                    if(!Auth::user()->can('edit-metodo_pagamento')) return;
44
+                    break;
45
+                case 'remove':
46
+                    if(!Auth::user()->can('delete-metodo_pagamento')) return;
47
+                    break;
48
+            }
49
+        }
50
+        return $editor->process($request);
51
+    }
52
+
53
+}

+ 57
- 0
app/Http/Controllers/MonitorController.php 파일 보기

@@ -0,0 +1,57 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Dispositivo;
7
+use App\DataTables\MonitorDataTable;
8
+use App\DataTables\MonitorDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+class MonitorController extends Controller
12
+{
13
+    public static $permission_group = "Monitor";
14
+    public static $permissions = [
15
+        'view-monitor' => 'Vedi',
16
+        'create-monitor' => 'Crea',
17
+        'edit-monitor' => 'Modifica',
18
+        'delete-monitor' => 'Elimina',
19
+    ];
20
+    
21
+    public static function middleware(): array
22
+    {
23
+        return [
24
+            new Middleware('permission:view-monitor', only: ['index']),
25
+            new Middleware('permission:create-monitor|edit-monitor|delete-monitor', only: ['store', 'update', 'destroy']),
26
+        ];
27
+    }
28
+    
29
+    public function index(MonitorDataTable $dataTable)
30
+    {
31
+        return $dataTable->render('monitor.index');
32
+    }
33
+    public function store(MonitorDataTableEditor $editor)
34
+    {
35
+        $request = request();
36
+        $input = $request->all();
37
+        if($request->has('action')){
38
+            switch($input['action']){
39
+                case 'create':
40
+                    if(!Auth::user()->can('create-monitor')) return;
41
+                    break;
42
+                case 'edit':
43
+                    if(!Auth::user()->can('edit-monitor')) return;
44
+                    break;
45
+                case 'remove':
46
+                    if(!Auth::user()->can('delete-monitor')) return;
47
+                    break;
48
+            }
49
+        }
50
+        return $editor->process($request);
51
+    }
52
+    public function show($monitor_id)
53
+    {
54
+        $monitor = Monitor::find($monitor_id);
55
+        return view('monitor.show', ['monitor' => $monitor]);
56
+    }
57
+}

+ 60
- 0
app/Http/Controllers/OrdineController.php 파일 보기

@@ -0,0 +1,60 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Ordine;
7
+use App\DataTables\OrdineDataTable;
8
+use App\DataTables\OrdineDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+class OrdineController extends Controller
12
+{
13
+    public static $permission_group = "Ordini";
14
+    public static $permissions = [
15
+        'view-ordine' => 'Vedi',
16
+        'create-ordine' => 'Crea',
17
+        'edit-ordine' => 'Modifica',
18
+        'delete-ordine' => 'Elimina',
19
+    ];
20
+
21
+    public static function middleware(): array
22
+    {
23
+        return [
24
+            new Middleware('permission:view-ordine', only: ['index']),
25
+            new Middleware('permission:create-ordine|edit-ordine|delete-ordine', only: ['store', 'update', 'destroy']),
26
+        ];
27
+    }
28
+
29
+    public function index(OrdineDataTable $dataTable)
30
+    {
31
+        return $dataTable->render('ordine.index');
32
+    }
33
+
34
+    public function store(OrdineDataTableEditor $editor)
35
+    {
36
+        $request = request();
37
+        $input = $request->all();
38
+        if($request->has('action')){
39
+          switch($input['action']){
40
+            case 'create':
41
+              if(!Auth::user()->can('create-ordine')) return;
42
+              break;
43
+            case 'edit':
44
+              if(!Auth::user()->can('edit-ordine')) return;
45
+              break;
46
+            case 'remove':
47
+              if(!Auth::user()->can('delete-ordine')) return;
48
+              break;
49
+          }
50
+        }
51
+        return $editor->process($request);
52
+    }
53
+
54
+    public function show(Request $request)
55
+    {
56
+        $ordine = Ordine::find($request->get('ordine_id'));
57
+        return view('ordine.show', compact('ordine'));
58
+    }
59
+}
60
+

+ 63
- 0
app/Http/Controllers/PagamentoController.php 파일 보기

@@ -0,0 +1,63 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Pagamento;
7
+use App\Models\MetodoPagamento;
8
+use App\DataTables\PagamentoDataTable;
9
+use App\DataTables\PagamentoDataTableEditor;
10
+use Illuminate\Support\Facades\Auth;
11
+
12
+class PagamentoController extends Controller
13
+{
14
+    public static $permission_group = "Pagamenti";
15
+    public static $permissions = [
16
+        'view-pagamento' => 'Vedi',
17
+        'create-pagamento' => 'Crea',
18
+        'edit-pagamento' => 'Modifica',
19
+        'delete-pagamento' => 'Elimina',
20
+    ];
21
+
22
+    public static function middleware(): array
23
+    {
24
+        return [
25
+            new Middleware('permission:view-pagamento', only: ['index']),
26
+            new Middleware('permission:create-pagamento|edit-pagamento|delete-pagamento', only: ['store', 'update', 'destroy']),
27
+        ];
28
+    }
29
+
30
+    public function index(PagamentoDataTable $dataTable)
31
+    {
32
+        return $dataTable->render('pagamento.index');
33
+    }
34
+
35
+    public function store(PagamentoDataTableEditor $editor)
36
+    {
37
+        $request = request();
38
+        $input = $request->all();
39
+        if($request->has('action')){
40
+            switch($input['action']){
41
+                case 'create':
42
+                    if(!Auth::user()->can('create-pagamento')) return;
43
+                    break;
44
+                case 'edit':
45
+                    if(!Auth::user()->can('edit-pagamento')) return;
46
+                    break;
47
+                case 'remove':
48
+                    if(!Auth::user()->can('delete-pagamento')) return;
49
+                    break;
50
+                }
51
+        return $editor->process($request);
52
+    }
53
+}
54
+
55
+    public function show(Request $request)
56
+    {
57
+        $pagamento = Pagamento::find($request->get('pagamento_id'));
58
+        return view('pagamento.show', compact('pagamento'));
59
+    }
60
+
61
+
62
+    
63
+}

+ 118
- 0
app/Http/Controllers/PiattoController.php 파일 보기

@@ -0,0 +1,118 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Piatto;
7
+use App\Models\PiattoHasAllergene;
8
+use App\DataTables\PiattoDataTable;
9
+use App\DataTables\PiattoDataTableEditor;
10
+use Illuminate\Support\Facades\Auth;
11
+
12
+class PiattoController extends Controller
13
+{
14
+    public static $permission_group = "Piatti";
15
+    public static $permissions = [
16
+        'view-piatto' => 'Vedi',
17
+        'create-piatto' => 'Crea',
18
+        'edit-piatto' => 'Modifica',
19
+        'delete-piatto' => 'Elimina',
20
+    ];
21
+
22
+    public static function middleware(): array
23
+    {
24
+        return [
25
+            new Middleware('permission:view-piatto', only: ['index']),
26
+            new Middleware('permission:create-piatto|edit-piatto|delete-piatto', only: ['store', 'update', 'destroy']),
27
+        ];
28
+    }
29
+
30
+    public function index(PiattoDataTable $dataTable){
31
+      // if(request()->get('menu_id')){
32
+      //   $dataTable->menu_id = request()->get('menu_id');
33
+      // }
34
+      if(request()->get('cucina_id')){
35
+        $dataTable->cucina_id = request()->get('cucina_id');
36
+      }
37
+      // if(isset($dataTable->categoria_id) || isset($dataTable->menu_id)){
38
+      // return $dataTable->render('piatto.datatable');
39
+      // }
40
+        return $dataTable->render('piatto.index');
41
+    }
42
+
43
+    // public function datatable(PiattoDataTable $dataTable){
44
+    //   $dataTable->menu_id = request()->get('menu_id');
45
+    //   return $dataTable->render('piatto.datatable');
46
+    // }
47
+
48
+    public function store(PiattoDataTableEditor $editor)
49
+    {
50
+      $request = request();
51
+
52
+      if ($request->has('action')) {
53
+        $action = $request->input('action');
54
+
55
+        switch ($action) {
56
+          case 'create':
57
+            if (! Auth::user()->can('create-user')) return;
58
+            break;
59
+
60
+          case 'edit':
61
+            if (! Auth::user()->can('edit-user')) return;
62
+            break;
63
+
64
+          case 'remove':
65
+            if (! Auth::user()->can('remove-user')) return;
66
+            break;
67
+        }
68
+      }
69
+
70
+      return $editor->process($request);
71
+    }
72
+
73
+    /**
74
+     * Metodo helper per aggiornare la pivot `piatto_allergene`.
75
+     * (L'update principale avviene in `PiattoDataTableEditor`.)
76
+     */
77
+    public function allergeni(Request $request)
78
+    {
79
+      // Payload DataTables Editor (edit) -> request->get('data') format:
80
+      // { "<piatto_id>": { "allergeni": [1,2,...], ... }, ... }
81
+      $payload = $request->get('data', []);
82
+
83
+      if (! is_array($payload)) {
84
+        return response()->json(['ok' => false, 'error' => 'Invalid payload'], 422);
85
+      }
86
+
87
+      foreach ($payload as $piattoId => $data) {
88
+        $piattoId = (int) $piattoId;
89
+        $allergenIds = $data['allergeni'] ?? [];
90
+
91
+        if (is_string($allergenIds)) {
92
+          $allergenIds = array_filter(array_map('trim', explode(',', $allergenIds)));
93
+        }
94
+
95
+        if (! is_array($allergenIds)) {
96
+          $allergenIds = [];
97
+        }
98
+
99
+        $allergenIds = array_values(array_unique(array_map(static fn ($id) => (int) $id, $allergenIds)));
100
+        $allergenIds = array_values(array_filter($allergenIds, static fn ($id) => $id > 0));
101
+
102
+        PiattoHasAllergene::where('piatto_id', $piattoId)->delete();
103
+
104
+        if (! empty($allergenIds)) {
105
+          $rows = array_map(static function ($allergeneId) use ($piattoId) {
106
+            return [
107
+              'piatto_id' => $piattoId,
108
+              'allergene_id' => $allergeneId,
109
+            ];
110
+          }, $allergenIds);
111
+
112
+          PiattoHasAllergene::insert($rows);
113
+        }
114
+      }
115
+
116
+      return response()->json(['ok' => true]);
117
+    }
118
+}

+ 68
- 0
app/Http/Controllers/PrenotazioneController.php 파일 보기

@@ -0,0 +1,68 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Prenotazione;
7
+use App\DataTables\PrenotazioneDataTable;
8
+use App\DataTables\PrenotazioneDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+use App\Models\Evento;
11
+
12
+
13
+class PrenotazioneController extends Controller
14
+{
15
+    public static $permission_group = "Prenotazioni";
16
+    public static $permissions = [
17
+        'view-prenotazione' => 'Vedi',
18
+        'create-prenotazione' => 'Crea',
19
+        'edit-prenotazione' => 'Modifica',
20
+        'delete-prenotazione' => 'Elimina',
21
+    ];
22
+
23
+    public static function middleware(): array
24
+    {
25
+        return [
26
+            new Middleware('permission:view-prenotazione', only: ['index']),
27
+            new Middleware('permission:create-prenotazione|edit-prenotazione|delete-prenotazione', only: ['store', 'update', 'destroy']),
28
+        ];
29
+    }
30
+
31
+    public function index(PrenotazioneDataTable $dataTable)
32
+    {
33
+        return $dataTable->render('prenotazione.index');
34
+    }
35
+
36
+    public function store(PrenotazioneDataTableEditor $editor)
37
+    {
38
+        $request = request();
39
+        $input = $request->all();
40
+        if($request->has('action')){
41
+          switch($input['action']){
42
+            case 'create':
43
+              if(!Auth::user()->can('create-prenotazione')) return;
44
+              break;
45
+            case 'edit':
46
+              if(!Auth::user()->can('edit-prenotazione')) return;
47
+              break;
48
+            case 'remove':
49
+              if(!Auth::user()->can('delete-prenotazione')) return;
50
+              break;
51
+          }
52
+        }
53
+        return $editor->process($request);
54
+    }
55
+
56
+    public function index_evento(PrenotazioneDataTable $dataTable)
57
+    {
58
+        $dataTable->evento_id = request()->get('evento_id');
59
+        return $dataTable->render('prenotazione.index', ['evento' => Evento::find($dataTable->evento_id)]);
60
+    }
61
+
62
+    public function show(Request $request)
63
+    {
64
+        $prenotazione = Prenotazione::find($request->get('prenotazione_id'));
65
+        return view('prenotazione._partials.modal', ['prenotazione' => $prenotazione]);
66
+    }
67
+
68
+}

+ 59
- 0
app/Http/Controllers/PrimaNotaController.php 파일 보기

@@ -0,0 +1,59 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\PrimaNota;
7
+use App\DataTables\PrimaNotaDataTable;
8
+use App\DataTables\PrimaNotaDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+class PrimaNotaController extends Controller
12
+{ 
13
+    public static $permission_group = "Prima Nota";
14
+    public static $permissions = [
15
+        'view-primanota' => 'Vedi',
16
+        'create-primanota' => 'Crea',
17
+        'edit-primanota' => 'Modifica',
18
+        'delete-primanota' => 'Elimina',
19
+    ];
20
+
21
+    public static function middleware(): array
22
+    {
23
+        return [
24
+            new Middleware('permission:view-primanota', only: ['index']),
25
+            new Middleware('permission:create-primanota|edit-primanota|delete-primanota', only: ['store', 'update', 'destroy']),
26
+        ];
27
+    }
28
+
29
+    public function index(PrimaNotaDataTable $dataTable)
30
+    {
31
+        return $dataTable->render('prima_nota.index');
32
+    }
33
+
34
+    public function store(PrimaNotaDataTableEditor $editor)
35
+    {
36
+        $request = request();
37
+        $input = $request->all();
38
+        if($request->has('action')){
39
+            switch($input['action']){
40
+                case 'create':
41
+                    if(!Auth::user()->can('create-primanota')) return;
42
+                    break;
43
+                case 'edit':
44
+                    if(!Auth::user()->can('edit-primanota')) return;
45
+                    break;
46
+                case 'remove':
47
+                    if(!Auth::user()->can('delete-primanota')) return;
48
+                    break;
49
+                }
50
+        return $editor->process($request);
51
+    }
52
+}
53
+
54
+    public function show(Request $request)
55
+    {
56
+        $primanota = PrimaNota::find($request->get('primanota_id'));
57
+        return view('prima_nota.show', compact('primanota'));
58
+    }
59
+}

+ 57
- 0
app/Http/Controllers/PrintJobController.php 파일 보기

@@ -0,0 +1,57 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\PrintJob;
7
+use App\DataTables\PrintJobDataTable;
8
+use App\DataTables\PrintJobDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+class PrintJobController extends Controller
12
+{
13
+    public static $permission_group = "Code di stampa";
14
+    public static $permissions = [
15
+        'view-print-job' => 'Vedi',
16
+        'create-print-job' => 'Crea',
17
+        'edit-print-job' => 'Modifica',
18
+        'delete-print-job' => 'Elimina',
19
+    ];
20
+    
21
+    public static function middleware(): array
22
+    {
23
+        return [
24
+            new Middleware('permission:view-print-job', only: ['index']),
25
+            new Middleware('permission:create-print-job|edit-print-job|delete-print-job', only: ['store', 'update', 'destroy']),
26
+        ];
27
+    }
28
+    
29
+    public function index(PrintJobDataTable $dataTable)
30
+    {
31
+        return $dataTable->render('print_job.index');
32
+    }
33
+    public function store(PrintJobDataTableEditor $editor)
34
+    {
35
+        $request = request();
36
+        $input = $request->all();
37
+        if($request->has('action')){
38
+            switch($input['action']){
39
+                case 'create':
40
+                    if(!Auth::user()->can('create-print-job')) return;
41
+                    break;
42
+                case 'edit':
43
+                    if(!Auth::user()->can('edit-print-job')) return;
44
+                    break;
45
+                case 'remove':
46
+                    if(!Auth::user()->can('delete-print-job')) return;
47
+                    break;
48
+            }
49
+        }
50
+        return $editor->process($request);
51
+    }
52
+    public function show(Request $request)
53
+    {
54
+        $print_job = PrintJob::find($request->get('print_job_id'));
55
+        return view('print_job.show', compact('print_job'));
56
+    }
57
+}

+ 170
- 0
app/Http/Controllers/PuntovenditaController.php 파일 보기

@@ -0,0 +1,170 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Cucina;
7
+use App\Models\Ordine;
8
+use App\Models\Dispositivo;
9
+use App\Models\Pagamento;
10
+use App\DataTables\PuntoVenditaDataTable;
11
+use App\DataTables\PuntoVenditaDataTableEditor;
12
+use App\DataTables\RigaOrdineDataTable;
13
+use Illuminate\Support\Facades\Auth;
14
+use Illuminate\Support\Facades\Session;
15
+
16
+class PuntovenditaController extends Controller
17
+{
18
+    public static $permission_group = "Punto di vendita";
19
+    public static $permissions = [
20
+        'view-punto_vendita' => 'Vedi',
21
+        'create-punto_vendita' => 'Crea',
22
+        'edit-punto_vendita' => 'Modifica',
23
+        'delete-punto_vendita' => 'Elimina',
24
+    ];
25
+    
26
+    public static function middleware(): array
27
+    {
28
+        return [
29
+            new Middleware('permission:view-punto_vendita', only: ['index']),
30
+            new Middleware('permission:create-punto_vendita|edit-punto_vendita|delete-punto_vendita', only: ['store', 'update', 'destroy']),
31
+        ];
32
+    }
33
+    
34
+    public function index(PuntoVenditaDataTable $dataTable)
35
+    {
36
+        return $dataTable->render('punto_vendita.index');
37
+    }
38
+    
39
+    public function store(PuntoVenditaDataTableEditor $editor)
40
+    {
41
+        $request = request();
42
+        $input = $request->all();
43
+        if($request->has('action')){
44
+            switch($input['action']){
45
+                case 'create':
46
+                    if(!Auth::user()->can('create-punto_vendita')) return;
47
+                    break;
48
+                case 'edit':
49
+                    if(!Auth::user()->can('edit-punto_vendita')) return;
50
+                    break;
51
+                case 'remove':
52
+                    if(!Auth::user()->can('delete-punto_vendita')) return;
53
+                    break;
54
+            }
55
+        }
56
+        return $editor->process($request);
57
+    }
58
+
59
+    public function show(Request $request, RigaOrdineDataTable $dataTable)
60
+    {
61
+        $puntoVendita = Dispositivo::find(request()->get('punto_vendita_id'));
62
+        // $puntoVendita = Dispositivo::cassa()->first();
63
+        if(!$puntoVendita){
64
+            return redirect()->route('punto-vendita.index')
65
+            ->with('error', 'Punto di vendita non trovato');
66
+        }
67
+
68
+        $cucine = Cucina::where(['is_attiva' => true , 'attivita_id' => $puntoVendita->attivita_id])
69
+        ->orderBy('nome')->get();
70
+
71
+
72
+$ordine = Ordine::firstOrCreate([
73
+    'stato' => Ordine::CARRELLO,
74
+    'dispositivo_id' => $puntoVendita->id,
75
+    'attivita_id' => $puntoVendita->attivita_id,
76
+]);
77
+        Session::put([
78
+            'dispositivo_id' => $puntoVendita->id,
79
+            'attivita_id' => $puntoVendita->attivita_id,
80
+        ]);
81
+$dataTable->ordine_id = $ordine->id;
82
+
83
+        switch($puntoVendita->tipo){
84
+            case Dispositivo::CASSA:
85
+                return $dataTable->render('punto_vendita.cassa.index', ['punto_vendita' => $puntoVendita , 'cucine' => $cucine, 'ordine' => $ordine, 'dataTable_rigaordine' => $dataTable]);
86
+            case Dispositivo::KIOSK:
87
+                return $dataTable->render('punto_vendita.kiosk.index', ['punto_vendita' => $puntoVendita , 'cucine' => $cucine, 'ordine' => $ordine, 'dataTable_rigaordine' => $dataTable]);
88
+            case Dispositivo::CAMERIERE:
89
+                return $dataTable->render('punto_vendita.cam.index', ['punto_vendita' => $puntoVendita , 'cucine' => $cucine, 'ordine' => $ordine, 'dataTable_rigaordine' => $dataTable]);
90
+        };
91
+    }
92
+
93
+    public function riepilogo(Request $request)
94
+    {
95
+        $ordine = Ordine::find($request->ordine_id);
96
+        if(!$ordine){
97
+            return redirect()->route('punto-vendita.kiosk.index')
98
+            ->with('error', 'Ordine non trovato');
99
+        }
100
+        
101
+        return view('punto_vendita.kiosk.riepilogo', ['ordine' => $ordine]);
102
+    }
103
+    public function dettagli(Request $request)
104
+    {
105
+        $puntoVendita = Dispositivo::find($request->punto_vendita_id);
106
+        if(!$puntoVendita){
107
+            return redirect()->route('punto-vendita.index')
108
+            ->with('error', 'Punto di vendita non trovato');
109
+        }
110
+        return view('punto_vendita.dettagli', ['puntoVendita' => $puntoVendita]);
111
+    }
112
+    
113
+    
114
+    public function riepilogo_cassa(Request $request)
115
+    {
116
+        $puntoVendita = Dispositivo::find($request->punto_vendita_id);
117
+        if(!$puntoVendita){
118
+            return redirect()->route('punto-vendita.index')
119
+            ->with('error', 'Punto di vendita non trovato');
120
+        }
121
+        // Calcola la data di oggi
122
+        $oggi = now()->startOfDay();
123
+
124
+        // Recupera tutti gli ordini di oggi per il punto vendita
125
+        $ordiniOggi = \App\Models\Ordine::where('dispositivo_id', $puntoVendita->id)
126
+            ->whereDate('created_at', $oggi)
127
+            ->get();
128
+
129
+        // Conta il totale ordini di oggi
130
+        $totaleOrdiniOggi = $ordiniOggi->count();
131
+
132
+        $ordineIds = $ordiniOggi->pluck('id')->all();
133
+
134
+        if ($ordineIds === []) {
135
+            $totaleIncassi = 0;
136
+            $pagamentiPerMetodo = [];
137
+            $pagamentiConteggioPerMetodo = [];
138
+        } else {
139
+            // Somma importi pagamenti legati agli ordini di oggi di questo punto vendita
140
+            $totaleIncassi = (float) Pagamento::query()
141
+                ->whereIn('ordine_id', $ordineIds)
142
+                ->sum('importo');
143
+
144
+            // Raggruppa per metodo_pagamento_id (colonna reale su tabella pagamento)
145
+            $pagamentiPerMetodo = Pagamento::query()
146
+                ->whereIn('ordine_id', $ordineIds)
147
+                ->selectRaw('metodo_pagamento_id, SUM(importo) as totale_importo')
148
+                ->groupBy('metodo_pagamento_id')
149
+                ->pluck('totale_importo', 'metodo_pagamento_id')
150
+                ->map(fn ($v) => (float) $v)
151
+                ->all();
152
+
153
+            $pagamentiConteggioPerMetodo = Pagamento::query()
154
+                ->whereIn('ordine_id', $ordineIds)
155
+                ->selectRaw('metodo_pagamento_id, COUNT(*) as conteggio')
156
+                ->groupBy('metodo_pagamento_id')
157
+                ->pluck('conteggio', 'metodo_pagamento_id')
158
+                ->map(fn ($v) => (int) $v)
159
+                ->all();
160
+        }
161
+
162
+        return view('punto_vendita.cassa.riepilogo_cassa', [
163
+            'puntoVendita' => $puntoVendita,
164
+            'totaleOrdiniOggi' => $totaleOrdiniOggi,
165
+            'totaleIncassi' => $totaleIncassi,
166
+            'pagamentiPerMetodo' => $pagamentiPerMetodo,
167
+            'pagamentiConteggioPerMetodo' => $pagamentiConteggioPerMetodo,
168
+        ]);
169
+    }
170
+}

+ 43
- 0
app/Http/Controllers/RigaOrdineController.php 파일 보기

@@ -0,0 +1,43 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\RigaOrdine;
7
+
8
+class RigaOrdineController extends Controller
9
+{
10
+    public static $permission_group = "Riga Ordine";
11
+    public static $permissions = [
12
+        'view-riga_ordine' => 'Vedi',
13
+        'create-riga_ordine' => 'Crea',
14
+        'edit-riga_ordine' => 'Modifica',
15
+        'delete-riga_ordine' => 'Elimina',
16
+    ];
17
+    
18
+    public static function middleware(): array
19
+    {
20
+        return [
21
+            new Middleware('permission:view-riga_ordine', only: ['index']),
22
+            new Middleware('permission:create-riga_ordine|edit-riga_ordine|delete-riga_ordine', only: ['store', 'update', 'destroy']),
23
+        ];
24
+    }
25
+
26
+    public function dettagli(Request $request){
27
+        if($request->has('riga_ordine_id')){
28
+            $riga_ordine = RigaOrdine::find($request->riga_ordine_id);
29
+            if($riga_ordine == null){ return response()->json(['success' => false, 'message' => 'Riga ordine non trovata']); }
30
+            return view('punto_vendita.cassa._partials.carrello.cmd_carrello', ['cmd' => 'dettagli', 'riga_ordine_id' => $riga_ordine->id]);
31
+        }
32
+        return response()->json(['success' => false, 'message' => 'ID non valido']);
33
+        
34
+    }
35
+    // public function index(RigaOrdineDataTable $dataTable){
36
+    //     return $dataTable->render('riga_ordine.index');
37
+    // }
38
+
39
+    // public function datatable(RigaOrdineDataTable $dataTable){
40
+    //     return $dataTable->render('punto_vendita.cassa._partials.carrello.index');
41
+    // }
42
+
43
+}

+ 130
- 0
app/Http/Controllers/RoleController.php 파일 보기

@@ -0,0 +1,130 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Routing\Controllers\Middleware;
6
+use Illuminate\Routing\Controllers\HasMiddleware;
7
+use Illuminate\Http\Request;
8
+use App\Models\Config;
9
+use App\Models\Role;
10
+use App\Models\Permission;
11
+use Illuminate\Support\Facades\Auth;
12
+use Notification;
13
+use Session;
14
+use PDF;
15
+use Illuminate\Support\Str;
16
+use Carbon\Carbon;
17
+use Illuminate\Support\Facades\Storage;
18
+use Intervention\Image\ImageManager;
19
+use Intervention\Image\Drivers\Imagick\Driver;
20
+use Illuminate\Support\Facades\Log;
21
+use App\DataTables\RoleDataTable;
22
+
23
+class RoleController extends Controller implements HasMiddleware
24
+{
25
+  public static $permission_group = "Ruoli e Permessi";
26
+  public static $permissions = [
27
+    'view-role' => 'Vedi',
28
+    'create-role' => 'Crea',
29
+    'edit-role' => 'Modifica',
30
+    'remove-role' => 'Elimina',
31
+  ];
32
+
33
+  public static function middleware(): array
34
+  {
35
+    return [
36
+      new Middleware('permission:view-role', only: ['index']),
37
+      new Middleware('permission:create-role|edit-role|remove-role', only: ['store']),
38
+    ];
39
+  }
40
+
41
+  public function index(RoleDataTable $dataTable)
42
+  {
43
+    return $dataTable->render('role.index');
44
+  }
45
+
46
+  public function showEdit(Request $request){
47
+    if(!$request->has('role_id') || !$request->role_id){
48
+      return response()->json(['error' => 'ID ruolo non specificato'], 400);
49
+    }
50
+    
51
+    $role = Role::find($request->role_id);
52
+    
53
+    if(!$role){
54
+      return response()->json(['error' => 'Ruolo non trovato'], 404);
55
+    }
56
+    
57
+    return view('role.modal_edit', ['role' => $role]);
58
+  }
59
+
60
+  public function showNew(Request $request){
61
+    return view('role.modal_new');
62
+  }
63
+
64
+  public function updatePermission(Request $request){
65
+    $input = $request->all();
66
+    // dd($input);
67
+    $permissions = [];
68
+    $role = Role::find($input['role_id']);
69
+    // $role->display_name = $request->modalRoleName;
70
+    // $role->name = Str::slug($role->display_name);
71
+    $role->save();
72
+
73
+    if($request->has('permesso')){
74
+      foreach($input['permesso'] as $key => $value){
75
+        $p = Permission::find($value);
76
+        if($p != null){
77
+          array_push($permissions, $p->name);
78
+        }
79
+      }
80
+
81
+    }
82
+
83
+    $role->syncPermissions($permissions);
84
+
85
+    $request->session()->flash('status', 'Permessi aggiornati!');
86
+    return redirect()->route('role.index');
87
+  }
88
+
89
+  public function createRole(Request $request){
90
+    $input = $request->all();
91
+    $permissions = [];
92
+    $role = new Role;
93
+    $role->display_name = $request->modalRoleName;
94
+    $role->guard_name = 'web';
95
+    $role->name = Str::slug($role->display_name);;
96
+    $role->save();
97
+
98
+    if($request->has('permesso')){
99
+      foreach($input['permesso'] as $key => $value){
100
+        $p = Permission::find($value);
101
+        if($p != null){
102
+          array_push($permissions, $p->name);
103
+        }
104
+      }
105
+
106
+    }
107
+
108
+    $role->syncPermissions($permissions);
109
+
110
+    $request->session()->flash('status', 'Ruolo creato!');
111
+    return redirect()->route('user.index');
112
+  }
113
+
114
+  public function getPermissions(Request $request){
115
+    if(!$request->has('role_id') || !$request->role_id){
116
+      return response()->json(['error' => 'ID ruolo non specificato'], 400);
117
+    }
118
+    
119
+    $role = Role::find($request->role_id);
120
+    
121
+    if(!$role){
122
+      return response()->json(['error' => 'Ruolo non trovato'], 404);
123
+    }
124
+    if($request->has('modal-edit')){
125
+      return view('role.permessi', ['role' => $role]);
126
+    }
127
+    return response()->json(['permissions' => $role->permissions]);
128
+  }
129
+
130
+}

+ 52
- 0
app/Http/Controllers/StampanteController.php 파일 보기

@@ -0,0 +1,52 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\Dispositivo;
7
+use App\DataTables\StampanteDataTable;
8
+use App\DataTables\StampanteDataTableEditor;
9
+use Illuminate\Support\Facades\Auth;
10
+
11
+class StampanteController extends Controller
12
+{
13
+    public static $permission_group = "Stampanti";
14
+    public static $permissions = [
15
+        'view-stampante' => 'Vedi',
16
+        'create-stampante' => 'Crea',
17
+        'edit-stampante' => 'Modifica',
18
+        'delete-stampante' => 'Elimina',
19
+    ];
20
+    
21
+    public static function middleware(): array
22
+    {
23
+        return [
24
+            new Middleware('permission:view-stampante', only: ['index']),
25
+            new Middleware('permission:create-stampante|edit-stampante|delete-stampante', only: ['store', 'update', 'destroy']),
26
+        ];
27
+    }
28
+    
29
+    public function index(StampanteDataTable $dataTable)
30
+    {
31
+        return $dataTable->render('stampante.index');
32
+    }
33
+    public function store(StampanteDataTableEditor $editor)
34
+    {
35
+        $request = request();
36
+        $input = $request->all();
37
+        if($request->has('action')){
38
+            switch($input['action']){
39
+                case 'create':
40
+                    if(!Auth::user()->can('create-stampante')) return;
41
+                    break;
42
+                case 'edit':
43
+                    if(!Auth::user()->can('edit-stampante')) return;
44
+                    break;
45
+                case 'remove':
46
+                    if(!Auth::user()->can('delete-stampante')) return;
47
+                    break;
48
+            }
49
+        }
50
+        return $editor->process($request);
51
+    }
52
+}

+ 166
- 0
app/Http/Controllers/UserController.php 파일 보기

@@ -0,0 +1,166 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Routing\Controllers\Middleware;
6
+use Illuminate\Routing\Controllers\HasMiddleware;
7
+
8
+use Illuminate\Http\Request;
9
+use App\Models\User;
10
+use App\DataTables\UserDataTableEditor;
11
+use App\DataTables\UserDataTable;
12
+use Illuminate\Support\Facades\Auth;
13
+use Notification;
14
+use Session;
15
+use PDF;
16
+use Illuminate\Support\Facades\Storage;
17
+use Illuminate\Support\Str;
18
+use Carbon\Carbon;
19
+use Illuminate\Support\Facades\Hash;
20
+use Illuminate\Support\Facades\Mail;
21
+use App\Mail\InvitoFamiglia;
22
+use Intervention\Image\ImageManager;
23
+use Intervention\Image\Drivers\Gd\Driver;
24
+use Illuminate\Support\Facades\Validator;
25
+
26
+class UserController extends Controller implements HasMiddleware
27
+{
28
+  public static $permission_group = "Utenti";
29
+  public static $permissions = [
30
+    'view-user' => 'Vedi',
31
+    'create-user' => 'Crea',
32
+    'edit-user' => 'Modifica',
33
+    'remove-user' => 'Rimuovi'
34
+  ];
35
+
36
+  public $messages = [
37
+    'nome.required' => 'Devi indicare il nome',
38
+    'cognome.required' => 'Devi indicare il cognome',
39
+    // 'telefono.required' => 'Devi indicare il telefono',
40
+    'email.required' => 'Devi indicare l\'indirizzo email',
41
+    'email.email' => 'L\'indirizzo email indicato non è valido',
42
+    'email.unique' => 'L\'indirizzo email indicato non è valido',
43
+    'password.required' => 'Devi indicare la password',
44
+    'password.confirmed' => 'La password non corriponde a quella di conferma',
45
+    'password.min' => 'La password deve essere composta da almeno 8 caratteri',
46
+  ];
47
+
48
+  public static function middleware(): array
49
+  {
50
+    return [
51
+      new Middleware('permission:view-user', only: ['index']),
52
+      new Middleware('permission:create-user|edit-user|remove-user', only: ['store', 'admin_aggiorna']),
53
+    ];
54
+  }
55
+
56
+  public function index(UserDataTable $dataTable)
57
+  {
58
+    return $dataTable->render('user.index');
59
+  }
60
+
61
+  public function store(UserDataTableEditor $editor)
62
+  {
63
+    $request = request();
64
+    $input = $request->all();
65
+
66
+    if($request->has('action')){
67
+      switch($input['action']){
68
+        case 'create':
69
+          if(!Auth::user()->can('create-user')) return;
70
+          break;
71
+
72
+          case 'edit':
73
+            if(!Auth::user()->can('edit-user')) return;
74
+            break;
75
+
76
+            case 'remove':
77
+              if(!Auth::user()->can('remove-user')) return;
78
+              break;
79
+            }
80
+          }
81
+          return $editor->process($request);
82
+        }
83
+
84
+
85
+        //////
86
+
87
+
88
+        public function upload_foto_profilo(Request $request){
89
+          $original_name = $request->file->getClientOriginalName();
90
+          $extension = pathinfo($original_name, PATHINFO_EXTENSION);
91
+
92
+          $filename = pathinfo(Str::camel($original_name), PATHINFO_FILENAME)."_".time().".".$extension;
93
+
94
+          //store file into temp folder
95
+          $file = $request->file->storeAs('', $filename , 'temp');
96
+          // $evento->path_img = $file;
97
+          // $evento->save();
98
+
99
+          return response()->json(['url' => Storage::disk('temp')->url($file), 'filename' => $file]);
100
+        }
101
+
102
+        public function showCropImage(Request $request){
103
+          return view('profile.cropImage', ['filename' => $request->filename]);
104
+        }
105
+
106
+        public function cropImage(Request $request){
107
+          // $evento = Evento::find($request->evento_id);
108
+          $fileName = explode(".", $request->filename);
109
+          $extension = array_pop($fileName);
110
+          $filename = implode("_", $fileName);
111
+
112
+          // create new image instance
113
+          $manager = new ImageManager(new Driver());
114
+          $image = $manager->read(Storage::disk('temp')->path($request->filename));
115
+          $image->crop($request->cropBoxData['width'], $request->cropBoxData['height'], $request->cropBoxData['x'], $request->cropBoxData['y']);
116
+          $newFileName = $filename.'_'.time().'_cropped.'.$extension;
117
+          Storage::disk('temp')->put($filename.'_'.time().'_cropped.'.$extension, $image->encodeByExtension($extension, quality: 100));
118
+          // $evento->path_img = $newFileName;
119
+          // $evento->save();
120
+
121
+          return response()->json(['url' => Storage::disk('temp')->url($newFileName), 'filename' => $newFileName]);
122
+        }
123
+
124
+        public function admin_list(Request $request){
125
+          $input = $request->all();
126
+          $list = array();
127
+
128
+          if($request->has('initialValue') && $input['initialValue'] == "true"){
129
+            $val = trim(str_replace('"', '', $input['value']));
130
+            $entity = User::find($val);
131
+            return response()->json(['id' => $entity->id, 'text' => $entity->full_name]);
132
+
133
+          }else{
134
+            $page = $input['page'];
135
+            $resultCount = 25;
136
+            $offset = ($page - 1) * $resultCount;
137
+            $entitys = User::where(function($q)use($input){
138
+              $q->where('nome', 'LIKE', '%'.$input['term'].'%')
139
+              ->orWhere('cognome', 'LIKE', '%'.$input['term'].'%');
140
+            })
141
+            ->orderBy('cognome', 'ASC');
142
+
143
+
144
+            foreach ($entitys->skip($offset)->take($resultCount)->get() as $e) {
145
+              if(!$e->hasRole('superadmin') || ($e->hasRole('superadmin') && Auth::user()->hasRole('superadmin'))){
146
+                array_push($list, array('id' => $e->id, 'text' => $e->full_name));
147
+              }
148
+            }
149
+
150
+            $count = $entitys->count();
151
+            $endCount = $offset + $resultCount;
152
+            $morePages = $count > $endCount;
153
+
154
+            $results = array(
155
+              "results" => $list,
156
+              "pagination" => array(
157
+                "more" => $morePages
158
+                )
159
+              );
160
+
161
+            }
162
+            return response()->json($results);
163
+          }
164
+
165
+
166
+        }

+ 26
- 0
app/Http/Middleware/AttivitaMiddleware.php 파일 보기

@@ -0,0 +1,26 @@
1
+<?php
2
+
3
+namespace App\Http\Middleware;
4
+
5
+use Closure;
6
+use Illuminate\Http\Request;
7
+use Symfony\Component\HttpFoundation\Response;
8
+use App\Models\Attivita;
9
+
10
+class AttivitaMiddleware
11
+{
12
+  /**
13
+   * Handle an incoming request.
14
+   *
15
+   * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
16
+   */
17
+  public function handle(Request $request, Closure $next): Response
18
+  {
19
+    // Attività is selected and active
20
+
21
+    if (!session()->has('attivita_attuale') || session()->get('attivita_attuale') == null || session()->get('attivita_attuale') == 0 || !Attivita::find(session()->get('attivita_attuale'))->is_attiva) {
22
+      return redirect()->route('attivita.index')->with('danger', 'Seleziona un\'attività per continuare');
23
+    }
24
+    return $next($request);
25
+  }
26
+}

+ 85
- 0
app/Jobs/ElaboraJobStampa.php 파일 보기

@@ -0,0 +1,85 @@
1
+<?php
2
+
3
+namespace App\Jobs;
4
+
5
+use App\Models\PrintJob;
6
+use Illuminate\Bus\Queueable;
7
+use Illuminate\Contracts\Queue\ShouldQueue;
8
+use Illuminate\Foundation\Bus\Dispatchable;
9
+use Illuminate\Queue\InteractsWithQueue;
10
+use Illuminate\Queue\SerializesModels;
11
+use App\Services\Stampa\CreaScontrino;
12
+use App\Services\Stampa\CreaComandaCucina;
13
+use Throwable;
14
+use Illuminate\Support\Facades\Log;
15
+
16
+class ElaboraJobStampa implements ShouldQueue
17
+{
18
+    use Dispatchable;
19
+    use InteractsWithQueue;
20
+    use Queueable;
21
+    use SerializesModels;
22
+
23
+    public int $tries = 3;
24
+
25
+    public function __construct(public int $printJobId) {}
26
+
27
+    public function handle(): void
28
+    {
29
+        $job = PrintJob::query()->find($this->printJobId);
30
+
31
+        if ($job === null) {
32
+            return;
33
+        }
34
+
35
+        if (in_array($job->stato, [PrintJob::STATO_COMPLETATO, PrintJob::STATO_ANNULLATO], true)) {
36
+            return;
37
+        }
38
+
39
+        $job->loadMissing('ordine');
40
+
41
+        $payload = is_array($job->payload) ? $job->payload : [];
42
+
43
+        if ($job->tipo === PrintJob::TIPO_SCONTRINO) {
44
+            if ($job->ordine === null) {
45
+                Log::error('Print job senza ordine associato.');
46
+                throw new \RuntimeException('Print job senza ordine associato.');
47
+            }
48
+            $payload = array_merge($payload, app(CreaScontrino::class)->perOrdine($job->ordine));
49
+
50
+        }elseif(str_starts_with($job->tipo, PrintJob::TIPO_COMANDA_CUCINA.'_')){
51
+                if ($job->ordine === null) {
52
+                    Log::error('Print job senza ordine associato.');
53
+                    throw new \RuntimeException('Print job senza ordine associato.');
54
+                }
55
+                
56
+                $prefix = PrintJob::TIPO_COMANDA_CUCINA . '_';
57
+                $cucina_id = str_starts_with($job->tipo, $prefix) ? substr($job->tipo, strlen($prefix)) : null;
58
+
59
+                if ($cucina_id === null || $cucina_id === '' || ! is_numeric($cucina_id)) {
60
+                    Log::error('Print job senza cucina associata.');
61
+                    throw new \RuntimeException('Print job senza cucina associata.');
62
+                }
63
+                $payload = array_merge($payload, app(CreaComandaCucina::class)->perOrdine($job->ordine, $cucina_id));
64
+        }else{
65
+            Log::error('Tipo di stampa non supportato: '.$job->tipo);
66
+            throw new \RuntimeException('Tipo di stampa non supportato: '.$job->tipo);
67
+        }
68
+
69
+        $job->update([
70
+            'stato' => PrintJob::STATO_IN_CODA,
71
+            'queued_at' => now(),
72
+            'payload' => $payload,
73
+            'last_error' => null,
74
+        ]);
75
+    }
76
+
77
+    public function failed(?Throwable $exception): void
78
+    {
79
+        PrintJob::query()->whereKey($this->printJobId)->update([
80
+            'stato' => PrintJob::STATO_FALLITO,
81
+            'failed_at' => now(),
82
+            'last_error' => $exception?->getMessage(),
83
+        ]);
84
+    }
85
+}

+ 45
- 0
app/Listeners/InviaNotificaSegnalazione.php 파일 보기

@@ -0,0 +1,45 @@
1
+ <?php
2
+/*
3
+namespace App\Listeners;
4
+
5
+use App\Events\NuovaSegnalazione;
6
+use App\Models\ConfigNotifiche;
7
+use Illuminate\Contracts\Queue\ShouldQueue;
8
+use Illuminate\Queue\InteractsWithQueue;
9
+use Illuminate\Support\Facades\Notification;
10
+use App\Notifications\NuovaSegnalazioneAdmin;
11
+use App\Notifications\NuovaSegnalazioneUser;
12
+use App\Notifications\NuovaSegnalazioneReparto;
13
+
14
+class InviaNotificaSegnalazione
15
+{
16
+    public function __construct()
17
+    {
18
+        //
19
+    }
20
+
21
+    public function handle(NuovaSegnalazione $event): void
22
+    {
23
+      // Invio all'admin la notifica di nuova segnalazione
24
+      $configNotifiche = ConfigNotifiche::where('event', ConfigNotifiche::NUOVA_SEGNALAZIONE_ADMIN)->first();
25
+      if($configNotifiche != null && $configNotifiche->is_attivo == true && count($configNotifiche->utenti) > 0){
26
+        Notification::send($configNotifiche->utenti, new NuovaSegnalazioneAdmin($event->segnalazione));
27
+      }
28
+
29
+      // Se è già stata assegnata, invio anche la notifica all'utente assegnato
30
+      if($event->segnalazione->user_id != null){
31
+        $configNotifiche = ConfigNotifiche::where('event', ConfigNotifiche::NUOVA_SEGNALAZIONE_ASSEGNATA)->first();
32
+        if($configNotifiche != null && $configNotifiche->is_attivo == true){
33
+          Notification::send($event->segnalazione->user, new NuovaSegnalazioneUser($event->segnalazione));
34
+        }
35
+      }
36
+
37
+      // Invio anche la notifica al reparto, se la mail è presente
38
+      if($event->segnalazione->reparto_id != null){
39
+        $configNotifiche = ConfigNotifiche::where('event', ConfigNotifiche::NUOVA_SEGNALAZIONE_REPARTO)->first();
40
+        if($configNotifiche != null && $configNotifiche->is_attivo == true){
41
+          Notification::route('mail', $event->segnalazione->email)->notify(new NuovaSegnalazioneReparto($event->segnalazione));
42
+        }
43
+      }
44
+    }
45
+} */

+ 68
- 0
app/Models/AbstractModels/AbstractAllergene.php 파일 보기

@@ -0,0 +1,68 @@
1
+<?php
2
+/**
3
+ * Model object generated by: Skipper (http://www.skipper18.com)
4
+ * Do not modify this file manually.
5
+ */
6
+
7
+namespace App\Models\AbstractModels;
8
+
9
+abstract class AbstractAllergene extends \Illuminate\Foundation\Auth\User
10
+{
11
+    /**  
12
+     * The table associated with the model.
13
+     * 
14
+     * @var string
15
+     */
16
+    protected $table = 'allergene';
17
+    
18
+    /**  
19
+     * Primary key type.
20
+     * 
21
+     * @var string
22
+     */
23
+    protected $keyType = 'bigInteger';
24
+    
25
+    /**  
26
+     * The model's default values for attributes.
27
+     * 
28
+     * @var array
29
+     */
30
+    // protected $attributes = ['is_gruppo' => 0];
31
+    
32
+    /**  
33
+     * The attributes that should be cast to native types.
34
+     * 
35
+     * @var array
36
+     */
37
+    protected $casts = [
38
+        'id' => 'integer',  
39
+        'nome' => 'string',
40
+        'descrizione' => 'string',
41
+        'disponibile' => 'boolean',
42
+        'icona' => 'string',
43
+        'colore' => 'string',
44
+        'created_at' => 'datetime',
45
+        'updated_at' => 'datetime'
46
+    ];
47
+    
48
+    /**  
49
+     * The attributes that are mass assignable.
50
+     * 
51
+     * @var array
52
+     */
53
+    protected $fillable = [
54
+        'id',
55
+        'nome',
56
+        'descrizione',
57
+        'disponibile',
58
+        'icona',
59
+        'colore',
60
+        'created_at',
61
+        'updated_at'
62
+    ];
63
+    
64
+    public function piatti()
65
+    {
66
+        return $this->belongsToMany('\App\Models\Piatto', 'piatto_allergene', 'allergene_id', 'piatto_id');
67
+    }
68
+}

+ 0
- 0
app/Models/AbstractModels/AbstractAttivita.php 파일 보기


이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.

Loading…
취소
저장