web.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. use Illuminate\Support\Facades\Route;
  3. use Barryvdh\DomPDF\Facade\Pdf;
  4. /*
  5. |--------------------------------------------------------------------------
  6. | Web Routes
  7. |--------------------------------------------------------------------------
  8. |
  9. | Here is where you can register web routes for your application. These
  10. | routes are loaded by the RouteServiceProvider within a group which
  11. | contains the "web" middleware group. Now create something great!
  12. |
  13. */
  14. Route::get('/', function () {
  15. return view('login');
  16. // return Redirect::to('/dashboard');
  17. });
  18. //Route::get('/', \App\Http\Livewire\Login::class);
  19. Route::get('/dashboard', \App\Http\Livewire\Dashboard::class);
  20. Route::get('/settings', \App\Http\Livewire\Setting::class);
  21. Route::get('/courses', \App\Http\Livewire\Course::class);
  22. Route::get('/categories', \App\Http\Livewire\Category::class);
  23. Route::get('/nations_list', \App\Http\Livewire\Nation::class);
  24. Route::get('/provinces', \App\Http\Livewire\Province::class);
  25. Route::get('/cities', \App\Http\Livewire\City::class);
  26. Route::get('/banks', \App\Http\Livewire\Bank::class);
  27. Route::get('/vats', \App\Http\Livewire\Vat::class);
  28. Route::get('/disciplines', \App\Http\Livewire\Discipline::class);
  29. Route::get('/course_types', \App\Http\Livewire\CourseType::class);
  30. Route::get('/course_subscriptions', \App\Http\Livewire\CourseSubscription::class);
  31. Route::get('/course_durations', \App\Http\Livewire\CourseDuration::class);
  32. Route::get('/course_levels', \App\Http\Livewire\CourseLevel::class);
  33. Route::get('/course_frequencies', \App\Http\Livewire\CourseFrequency::class);
  34. Route::get('/course_list', \App\Http\Livewire\CourseList::class);
  35. Route::get('/course_member', \App\Http\Livewire\CourseMember::class);
  36. Route::get('/receipts', \App\Http\Livewire\Receipt::class);
  37. Route::get('/cards', \App\Http\Livewire\Card::class);
  38. Route::get('/causals', \App\Http\Livewire\Causal::class);
  39. Route::get('/payment_methods', \App\Http\Livewire\PaymentMethod::class);
  40. Route::get('/members', \App\Http\Livewire\Member::class);
  41. Route::get('/suppliers', \App\Http\Livewire\Supplier::class);
  42. Route::get('/sponsors', \App\Http\Livewire\Sponsor::class);
  43. Route::get('/records', \App\Http\Livewire\Record::class);
  44. Route::get('/reminders', \App\Http\Livewire\Reminder::class);
  45. Route::get('/in', \App\Http\Livewire\RecordIN::class);
  46. Route::get('/out', \App\Http\Livewire\RecordOUT::class);
  47. Route::get('/records_in_out', \App\Http\Livewire\RecordINOUT::class);
  48. Route::get('/receipt/{id}', function($id){
  49. $receipt = \App\Models\Receipt::findOrFail($id);
  50. $pdf = PDF::loadView('receipt', array('receipt' => $receipt));
  51. return $pdf->stream();
  52. /*return response()->streamDownload(
  53. fn () => print($pdf),
  54. "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf"
  55. );*/
  56. });
  57. Route::get('/nations', function(){
  58. if (isset($_GET["q"]))
  59. $datas = \App\Models\Nation::where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
  60. else
  61. $datas = \App\Models\Nation::orderBy('name')->get();
  62. $data = array();
  63. foreach($datas as $d)
  64. {
  65. $data[] = array("id" => $d->id, "text" => $d->name);
  66. }
  67. return array("results" => $data);
  68. });
  69. Route::get('/provinces/{nation_id}', function($nation_id){
  70. if (isset($_GET["q"]))
  71. $datas = \App\Models\Province::where('nation_id', $nation_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
  72. else
  73. $datas = \App\Models\Province::where('nation_id', $nation_id)->orderBy('name')->get();
  74. $data = array();
  75. foreach($datas as $d)
  76. {
  77. $data[] = array("id" => $d->id, "text" => $d->name);
  78. }
  79. return array("results" => $data);
  80. });
  81. Route::get('/cities/{province_id}', function($province_id){
  82. if (isset($_GET["q"]))
  83. $datas = \App\Models\City::where('province_id', $province_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
  84. else
  85. $datas = \App\Models\City::where('province_id', $province_id)->orderBy('name')->get();
  86. $data = array();
  87. foreach($datas as $d)
  88. {
  89. $data[] = array("id" => $d->id, "text" => $d->name);
  90. }
  91. return array("results" => $data);
  92. });
  93. Route::get('/get_members', function(){
  94. $datas = [];
  95. // $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
  96. $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone', 'birth_date')->where('id', '>', 0);
  97. if ($_GET["cards"] != "")
  98. {
  99. $card_ids = \App\Models\MemberCard::whereIn('card_id', explode(",", $_GET["cards"]))->pluck('member_id');
  100. $x = $x->whereIn('id', $card_ids);
  101. }
  102. if ($_GET["categories"] != "")
  103. {
  104. $cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["categories"]))->pluck('member_id');
  105. $x = $x->whereIn('id', $cats_ids);
  106. }
  107. if ($_GET["fromYear"] != "")
  108. {
  109. $x = $x->where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time())));
  110. }
  111. if ($_GET["toYear"] != "")
  112. {
  113. $x = $x->where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())));
  114. }
  115. $certs = [];
  116. if ($_GET["chkCertificateNormal"] != "")
  117. {
  118. $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
  119. $x = $x->whereIn('id', $normal);;
  120. }
  121. if ($_GET["chkCertificateAgonistico"] != "")
  122. {
  123. $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
  124. $x = $x->whereIn('id', $agonistic);
  125. }
  126. if ($_GET["chkCertificateScaduti"] != "")
  127. {
  128. $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  129. $x = $x->whereIn('id', $scaduto);
  130. }
  131. if ($_GET["chkCertificateScadenza"] != "")
  132. {
  133. $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  134. $x = $x->whereIn('id', $scadenza);
  135. }
  136. if (sizeof($certs) > 0)
  137. {
  138. $x = $x->whereIn('id', $certs);
  139. }
  140. $x = $x->get();
  141. $filterStatus = isset($_GET["status"]) ? $_GET["status"] : -1;
  142. foreach($x as $idx => $r)
  143. {
  144. $status = $r->getStatus();
  145. $status = $status["status"];
  146. $state = $r->isActive();
  147. $procede = true;
  148. if ($filterStatus >= 0)
  149. {
  150. if ($state["status"] != $filterStatus)
  151. $procede = false;
  152. }
  153. if ($procede)
  154. {
  155. $class = $status > 0 ? ($status == 2 ? 'active' : 'suspended') : 'due';
  156. $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
  157. $x = $state["status"] > 0 ? ($state["status"] == 2 ? 'active' : 'suspended') : '';
  158. $x .= "|";
  159. $x .= $state["status"] > 0 ? ($state["status"] == 2 ? 'Attivo' : 'Sospesa') : '';
  160. $x .= "|";
  161. $x .= $state["status"] ? 'Scadenza : ' : ($state["date"] != '' ? 'Scaduto : ' : '');
  162. $x .= "|";
  163. $x .= $state["date"] != '' ? date("d/m/Y", strtotime($state["date"])) : '';
  164. $has_certificate = $r->hasCertificate();
  165. $y = '';
  166. if($has_certificate["date"] != '')
  167. {
  168. if($has_certificate["date"] < date("Y-m-d"))
  169. $y .= '0';
  170. if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
  171. $y .= '1';
  172. if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
  173. $y .= '2';
  174. $y .= '|';
  175. $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : '';
  176. }
  177. $datas[] = array(
  178. //'c' => $idx + 1,
  179. 'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
  180. 'first_name' => $r->first_name . "|" . $r->id,
  181. 'last_name' => $r->last_name . "|" . $r->id,
  182. 'phone' => $r->phone,
  183. 'age' => $r->getAge(),
  184. 'status' => $class . "|" . $text,
  185. 'state' => $x,
  186. 'certificate' => $y,
  187. 'action' => $r->id
  188. );
  189. }
  190. /*
  191. $r->age = $r->getAge();
  192. $active = $r->isActive();
  193. $r->status = $active["status"];
  194. $r->date = $active["date"] . "|" . $r->hasCertificate()["date"];
  195. $r->state = $r->getStatus()["status"];
  196. $r->action = '';*/
  197. }
  198. /*
  199. if ($this->sortAsc)
  200. $this->records = $this->records->sortBy($this->sortField);
  201. else
  202. $this->records = $this->records->sortByDesc($this->sortField);
  203. */
  204. // $datas = $x; // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
  205. return json_encode(array("data" => $datas));
  206. });
  207. Route::get('/get_record_in', function(){
  208. $datas = [];
  209. $x = \App\Models\Record::select('records.*', \DB::raw('members.first_name as first_name'), \DB::raw('members.last_name as last_name'), \DB::raw('payment_methods.name as payment')) // , \DB::raw('SUM(records.id) As total'))
  210. ->leftJoin('members', 'records.member_id', '=', 'members.id')
  211. ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
  212. ->where('records.type', 'IN');
  213. // $datas = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method');
  214. if ($_GET["filterCommercial"] > 0)
  215. {
  216. $x = $x->where('commercial', $_GET["filterCommercial"] == 1 ? true : false);
  217. }
  218. if ($_GET["filterMember"] > 0)
  219. {
  220. $x = $x->where('member_id', $_GET["filterMember"]);
  221. }
  222. if ($_GET["filterPaymentMethod"] > 0)
  223. {
  224. $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]);
  225. }
  226. if ($_GET["filterCausals"] > 0)
  227. {
  228. $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  229. $x = $x->whereIn('records.id', $causals);
  230. }
  231. if ($_GET["filterFrom"] != '')
  232. {
  233. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  234. }
  235. if ($_GET["filterTo"] != '')
  236. {
  237. $x = $x->where('date', '<=', $_GET["filterTo"]);
  238. }
  239. $total = 0;
  240. foreach($x->get() as $r)
  241. {
  242. foreach($r->rows as $rr)
  243. {
  244. $total += $rr->amount;
  245. if ($rr->vat_id > 0)
  246. $total += getVatValue($rr->amount, $rr->vat_id);
  247. }
  248. }
  249. $x = $x->get();
  250. foreach($x as $idx => $r)
  251. {
  252. $causals = '';
  253. foreach($r->rows as $row)
  254. {
  255. $causals .= $row->causal->getTree() . "<br>";
  256. }
  257. $datas[] = array(
  258. //'id' => $r->id,
  259. 'date' => $r->date,
  260. 'total' => formatPrice($r->getTotal()),
  261. 'first_name' => $r->first_name,
  262. 'last_name' => $r->last_name,
  263. 'commercial' => $r->commercial ? 'SI' : 'NO',
  264. 'causals' => $causals,
  265. 'payment' => $r->payment_method->name,
  266. 'status' => $r->deleted ? 'Annullato' : '',
  267. 'action' => $r->id . "|" . formatPrice($total) . "|" . ($r->deleted ? 'x' : '')
  268. );
  269. }
  270. $datas[] = array(
  271. //'id' => $r->id,
  272. 'date' => '',
  273. 'total' => formatPrice($total),
  274. 'first_name' => '',
  275. 'last_name' => '',
  276. 'commercial' => '',
  277. 'causals' => '',
  278. 'payment' => '',
  279. 'status' => '',
  280. 'action' => ''
  281. );
  282. return json_encode(array("data" => $datas));
  283. });
  284. Route::get('/get_record_out', function(){
  285. $datas = [];
  286. $x = \App\Models\Record::where('type', 'OUT')->with('supplier', 'payment_method');
  287. if ($_GET["filterSupplier"] > 0)
  288. {
  289. $x = $x->where('supplier_id', $_GET["filterSupplier"]);
  290. }
  291. if ($_GET["filterPaymentMethod"] > 0)
  292. {
  293. $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]);
  294. }
  295. if ($_GET["filterCausals"] > 0)
  296. {
  297. $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  298. $x = $x->whereIn('records.id', $causals);
  299. }
  300. if ($_GET["filterFrom"] != '')
  301. {
  302. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  303. }
  304. if ($_GET["filterTo"] != '')
  305. {
  306. $x = $x->where('date', '<=', $_GET["filterTo"]);
  307. }
  308. $total = 0;
  309. foreach($x->get() as $r)
  310. {
  311. foreach($r->rows as $rr)
  312. {
  313. $total += $rr->amount;
  314. if ($rr->vat_id > 0)
  315. $total += getVatValue($rr->amount, $rr->vat_id);
  316. }
  317. }
  318. $x = $x->get();
  319. foreach($x as $idx => $r)
  320. {
  321. $causals = '';
  322. foreach($r->rows as $row)
  323. {
  324. $causals .= $row->causal->getTree() . "<br>";
  325. }
  326. $datas[] = array(
  327. //'id' => $r->id,
  328. 'date' => $r->date,
  329. 'total' => formatPrice($r->getTotal()),
  330. 'supplier' => $r->supplier->name,
  331. 'causals' => $causals,
  332. 'payment' => $r->payment_method->name,
  333. 'action' => $r->id . "|" . formatPrice($total)
  334. );
  335. }
  336. $datas[] = array(
  337. //'id' => $r->id,
  338. 'date' => '',
  339. 'total' => formatPrice($total),
  340. 'supplier' => '',
  341. 'causals' => '',
  342. 'payment' => '',
  343. 'action' => ''
  344. );
  345. return json_encode(array("data" => $datas));
  346. });
  347. Route::get('/migrate', function(){
  348. \Artisan::call('migrate');
  349. dd('migrated!');
  350. });