web.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. use App\Http\Livewire\Report;
  3. use Illuminate\Support\Facades\Route;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Http\Request;
  7. /*
  8. |--------------------------------------------------------------------------
  9. | Web Routes
  10. |--------------------------------------------------------------------------
  11. |
  12. | Here is where you can register web routes for your application. These
  13. | routes are loaded by the RouteServiceProvider and all of them will
  14. | be assigned to the "web" middleware group. Make something great!
  15. |
  16. */
  17. Route::get('/', function () {
  18. return view('login');
  19. })->name('login');
  20. Route::post('/logout', function (Request $request) {
  21. Auth::logout();
  22. $request->session()->invalidate();
  23. $request->session()->regenerateToken();
  24. return redirect('/');
  25. });
  26. Route::post('/login', function (Request $request) {
  27. $credentials = $request->validate([
  28. 'email' => 'required|email',
  29. 'password' => 'required|string|min:6',
  30. ]);
  31. if (Auth::attempt($credentials)) {
  32. $request->session()->regenerate();
  33. return redirect()->intended('/reports');
  34. }
  35. return back()->withErrors([
  36. 'message' => 'Dati di accesso errati',
  37. ]);
  38. });
  39. Route::group(['middleware' => 'auth'],function(){
  40. Route::get('/dashboard', \App\Http\Livewire\Dashboard::class);
  41. Route::get('/accertatore-grado', \App\Http\Livewire\AccertatoreGrado::class);
  42. Route::get('/ausilio-altri-enti', \App\Http\Livewire\AusilioAltriEnti::class);
  43. Route::get('/compagnie', \App\Http\Livewire\Compagnia::class);
  44. Route::get('/condizioni-strada', \App\Http\Livewire\CondizioneStrada::class);
  45. Route::get('/condizioni-atmosferiche', \App\Http\Livewire\CondizioniAtmosferiche::class);
  46. Route::get('/condizioni-luce', \App\Http\Livewire\CondizioniLuce::class);
  47. Route::get('/fondo-stradale', \App\Http\Livewire\FondoStradale::class);
  48. Route::get('/marche', \App\Http\Livewire\MarcaVeicolo::class);
  49. Route::get('/modelli', \App\Http\Livewire\ModelloVeicolo::class);
  50. Route::get('/materiale-recuperato', \App\Http\Livewire\MaterialeRecuperato::class);
  51. Route::get('/nomenclatura-strada', \App\Http\Livewire\NomenclaturaStrada::class);
  52. Route::get('/particolarita-strada', \App\Http\Livewire\ParticolaritaStrada::class);
  53. Route::get('/pavimentazione-strada', \App\Http\Livewire\PavimentazioneStrada::class);
  54. Route::get('/rilievi', \App\Http\Livewire\Rilievi::class);
  55. Route::get('/segnalazione-pervenuta-da', \App\Http\Livewire\SegnalazionePervenutaDa::class);
  56. Route::get('/segnalazione-verticale', \App\Http\Livewire\SegnalazioneVerticale::class);
  57. Route::get('/segnalazione-orizzontale', \App\Http\Livewire\SegnalazioneOrizzontale::class);
  58. Route::get('/stradario', \App\Http\Livewire\Stradario::class);
  59. Route::get('/tipo-segnalazione', \App\Http\Livewire\TipoSegnalazione::class);
  60. Route::get('/tipo-strada', \App\Http\Livewire\TipoStrada::class);
  61. Route::get('/entita-danno', \App\Http\Livewire\EntitaDanno::class);
  62. Route::get('/effetto-danno', \App\Http\Livewire\EffettoDanno::class);
  63. Route::get('/tipo-danno', \App\Http\Livewire\TipoDanno::class);
  64. Route::get('/tipo-urto', \App\Http\Livewire\TipoUrto::class);
  65. Route::get('/parte-macchina', \App\Http\Livewire\ParteMacchina::class);
  66. Route::get('/tipo-veicolo', \App\Http\Livewire\TipoVeicolo::class);
  67. Route::get('/users', \App\Http\Livewire\User::class);
  68. Route::get('/reports', \App\Http\Livewire\Report::class);
  69. Route::get('/istat', \App\Http\Livewire\Istat::class);
  70. Route::get('/print', Report::class);
  71. Route::get('/stradario_api', function(){
  72. if (isset($_GET["q"]))
  73. $stradario = \App\Models\Stradario::where('descrizione', 'like', '%' . $_GET["q"] . '%')->orderBy('descrizione')->get();
  74. else
  75. $stradario = \App\Models\Stradario::orderBy('descrizione')->get();
  76. $data = array();
  77. foreach($stradario as $s)
  78. {
  79. $data[] = array("id" => $s->id, "text" => $s->TOPONIMO . " " . $s->DESCRIZIONE);
  80. }
  81. return array("results" => $data);
  82. });
  83. Route::get('/anagrafica', function() {
  84. if (isset($_GET["q"])) {
  85. $anagrafica = \App\Models\Anagrafica::where('lastname', 'like', '%' . $_GET["q"] . '%')
  86. ->orWhere('firstname', 'like', '%' . $_GET["q"] . '%')
  87. ->orWhere('rag_soc', 'like', '%' . $_GET["q"] . '%')
  88. ->orderBy('lastname')
  89. ->orderBy('firstname')
  90. ->get();
  91. } else {
  92. $anagrafica = \App\Models\Anagrafica::orderBy('lastname')
  93. ->orderBy('firstname')
  94. ->get();
  95. }
  96. $data = [];
  97. foreach ($anagrafica as $a) {
  98. $text = (empty($a->lastname) && empty($a->firstname))
  99. ? $a->rag_soc // Use company name if names are empty
  100. : trim($a->lastname . ' ' . $a->firstname);
  101. $data[] = ["id" => $a->id, "text" => $text];
  102. }
  103. return ["results" => $data];
  104. });
  105. Route::get('/localita', function(){
  106. if (isset($_GET["q"]))
  107. $localita = \App\Models\LocationTown::where('title', 'like', '%' . $_GET["q"] . '%')->orderBy('title')->get();
  108. else
  109. $localita = \App\Models\LocationTown::orderBy('title')->get();
  110. $data = array();
  111. foreach($localita as $l)
  112. {
  113. $data[] = array("id" => $l->id, "text" => $l->title);
  114. }
  115. return array("results" => $data);
  116. });
  117. Route::get('/veicoli', function(){
  118. if (isset($_GET["q"]))
  119. {
  120. $value = $_GET["q"];
  121. $veicoli = \App\Models\Vehicle::with('marca')->with('modello')->whereHas('marca', function ($q) use ($value) {
  122. $q->where('name', "LIKE", '%' . $value . '%');
  123. })->orWhereHas('modello', function ($q) use ($value) {
  124. $q->where('name', "LIKE", '%' . $value . '%');
  125. })->get()->sortBy('marca.name',SORT_REGULAR,false);
  126. }
  127. else
  128. $veicoli = \App\Models\Vehicle::with('marca')->with('modello')->get()->sortBy('marca.name',SORT_REGULAR,false);
  129. $data = array();
  130. foreach($veicoli as $v)
  131. {
  132. $data[] = array("id" => $v->id, "text" => ($v->marca ? $v->marca->name : '') . " " . ($v->modello ? $v->modello->name : '') . " " . $v->targa);
  133. }
  134. return array("results" => $data);
  135. });
  136. Route::get('/accertatori', function(){
  137. if (isset($_GET["q"]))
  138. {
  139. $value = $_GET["q"];
  140. $accertatori = DB::table('fcf_users')
  141. ->leftjoin('fcf_user_user_groups','fcf_user_user_groups.user_id','=','fcf_users.id')
  142. ->selectRaw('fcf_users.*')
  143. ->where('fcf_user_user_groups.group_id', 2)
  144. ->where(function ($query) {
  145. $query->where('fcf_users.lastname', 'like', '%' . $_GET["q"] . '%')
  146. ->orWhere('fcf_users.firstname', 'like', '%' . $_GET["q"] . '%');
  147. })
  148. ->orderBy('fcf_users.lastname')
  149. ->get();
  150. }
  151. else
  152. $accertatori = DB::table('fcf_users')
  153. ->leftjoin('fcf_user_user_groups','fcf_user_user_groups.user_id','=','fcf_users.id')
  154. ->selectRaw('fcf_users.*')
  155. ->where('fcf_user_user_groups.group_id', 2)
  156. ->orderBy('fcf_users.lastname')
  157. ->get();
  158. $data = array();
  159. foreach($accertatori as $a)
  160. {
  161. $data[] = array("id" => $a->id, "text" => $a->lastname . " " . $a->firstname);
  162. }
  163. return array("results" => $data);
  164. });
  165. Route::get('/polizze', function(){
  166. if (isset($_GET["q"]))
  167. {
  168. $value = $_GET["q"];
  169. $polizze = \App\Models\Polizza::with('compagnia')->with('anagrafica')->where('agenzia', 'LIKE', '%' . $_GET["q"] . '%')
  170. ->orWhereHas('compagnia', function ($q) use ($value) {
  171. $q->where('name', "LIKE", '%' . $value . '%');
  172. })->orWhereHas('anagrafica', function ($q) use ($value) {
  173. $q->where('lastname', "LIKE", '%' . $value . '%')->orWhere('firstname', "LIKE", '%' . $value . '%');
  174. })->get()->sortBy('marca.name',SORT_REGULAR,false);
  175. }
  176. else
  177. $polizze = \App\Models\Polizza::with('compagnia')->with('anagrafica')->get()->sortBy('agenzia',SORT_REGULAR,false);
  178. $data = array();
  179. foreach($polizze as $p)
  180. {
  181. $data[] = array("id" => $p->id, "text" => $p->agenzia . " " . ($p->compagnia ? $p->compagnia->name : '') . " " . ($p->anagrafica ? ($p->anagrafica->lastname . " " . $p->anagrafica->firstname) : ''));
  182. }
  183. return array("results" => $data);
  184. });
  185. });
  186. Route::get('/test_targa/{targa}', function ($targa) {
  187. try
  188. {
  189. $wd = "dettaglioAutoveicoloBase";
  190. $wd = "datiCartaCircolazioneAutoveicoloProprietario";
  191. $url = 'https://www.ilportaledellautomobilista.it/Info-ws/services';
  192. $client = new \SoapClient($url . '/' . $wd . '/' . $wd . '.wsdl', array(
  193. 'stream_context' => stream_context_create(array(
  194. 'ssl' => array(
  195. 'verify_peer' => false,
  196. 'verify_peer_name' => false,
  197. 'allow_self_signed' => true
  198. )
  199. )),
  200. 'trace'=>1
  201. ));
  202. $utente = 'CMRM001301';
  203. $password = '2PMPM*86';
  204. $xml = '<wsse:Security
  205. xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
  206. SOAP-ENV:mustUnderstand="1">
  207. <wsse:UsernameToken
  208. xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
  209. wsu:Id="XWSSGID-1253605895203984534550">
  210. <wsse:Username>' . $utente . '</wsse:Username>
  211. <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' . $password . '</wsse:Password>
  212. </wsse:UsernameToken>
  213. </wsse:Security>';
  214. $header = new \SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
  215. 'Security',
  216. new \SoapVar($xml, XSD_ANYXML),
  217. true
  218. );
  219. $client->__setSoapHeaders($header);
  220. $classe = "dettaglioAutoveicoloBase";
  221. $classe = "dettaglioCartaCircolazioneProprietarioAutoveicolo";
  222. try
  223. {
  224. // Run the function
  225. $obj = $client->__soapCall($classe, array(
  226. $classe . "Request" => array(
  227. "login" => array(
  228. ),
  229. //"dettaglioAutoveicoloBaseInput" => array(
  230. "targa" => array("numeroTarga" => $targa),
  231. //),
  232. "pdf" => false
  233. )
  234. ));
  235. print "<pre>";
  236. print_r($obj);
  237. print "</pre>";
  238. }
  239. catch(\SoapFault $fault)
  240. {
  241. print $fault;
  242. // <xmp> tag displays xml output in html
  243. //echo 'Request : <br/><xmp>',
  244. //$client->__getLastRequest(),
  245. //'</xmp><br/><br/> Error Message : <br/>',
  246. //$fault->getMessage();
  247. }
  248. }
  249. catch(Exception $ex)
  250. {
  251. print "QUA5";
  252. print $ex;
  253. }
  254. });
  255. Route::get('/print-pdf/{id}', [Report::class, 'print'])->name('print.pdf');
  256. Route::get('/countries', function() {
  257. $search = request()->get('search');
  258. $query = \App\Models\LocationCountry::query();
  259. if($search) {
  260. $query->where('name', 'like', "%{$search}%");
  261. }
  262. $countries = $query->get()->map(function($country) {
  263. return [
  264. 'id' => $country->id,
  265. 'text' => $country->name
  266. ];
  267. });
  268. return response()->json([
  269. 'results' => $countries
  270. ]);
  271. });
  272. Route::get('/compagnie', function(){
  273. if (isset($_GET["q"]))
  274. $compagnie = \App\Models\Compagnia::where('name', 'like', '%' . $_GET["q"] . '%')->orderBy('name')->get();
  275. else
  276. $compagnie = \App\Models\Compagnia::orderBy('name')->get();
  277. $data = array();
  278. foreach($compagnie as $c)
  279. {
  280. $data[] = array("id" => $c->id, "text" => $c->name);
  281. }
  282. return array("results" => $data);
  283. });
  284. Route::get('/polizze/agenzie', function(Request $request) {
  285. $query = \App\Models\Polizza::query();
  286. if ($request->has('q')) {
  287. $query->where('agenzia', 'like', '%' . $request->q . '%');
  288. }
  289. // Get unique agenzie
  290. $agenzie = $query->distinct()
  291. ->whereNotNull('agenzia')
  292. ->where('agenzia', '!=', '')
  293. ->pluck('agenzia');
  294. return [
  295. 'results' => $agenzie->map(function($agenzia) {
  296. return [
  297. 'id' => $agenzia,
  298. 'text' => $agenzia
  299. ];
  300. })
  301. ];
  302. });