web.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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 (isset($_GET["search"]["value"]))
  98. {
  99. $v = $_GET["search"]["value"];
  100. $x = $x->where(function ($query) use ($v) {
  101. $query->where('first_name', 'like', '%' . $v . '%')
  102. ->orWhere('last_name', 'like', '%' . $v . '%');
  103. });
  104. //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
  105. }
  106. if ($_GET["cards"] != "")
  107. {
  108. $card_ids = \App\Models\MemberCard::whereIn('card_id', explode(",", $_GET["cards"]))->pluck('member_id');
  109. $x = $x->whereIn('id', $card_ids);
  110. }
  111. if ($_GET["categories"] != "")
  112. {
  113. $cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["categories"]))->pluck('member_id');
  114. $x = $x->whereIn('id', $cats_ids);
  115. }
  116. if ($_GET["fromYear"] != "")
  117. {
  118. $x = $x->where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time())));
  119. }
  120. if ($_GET["toYear"] != "")
  121. {
  122. $x = $x->where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())));
  123. }
  124. $certs = [];
  125. if ($_GET["chkCertificateNormal"] != "")
  126. {
  127. $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
  128. $x = $x->whereIn('id', $normal);;
  129. }
  130. if ($_GET["chkCertificateAgonistico"] != "")
  131. {
  132. $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
  133. $x = $x->whereIn('id', $agonistic);
  134. }
  135. if ($_GET["chkCertificateScaduti"] != "")
  136. {
  137. $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  138. $x = $x->whereIn('id', $scaduto);
  139. }
  140. if ($_GET["chkCertificateScadenza"] != "")
  141. {
  142. $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  143. $x = $x->whereIn('id', $scadenza);
  144. }
  145. if (sizeof($certs) > 0)
  146. {
  147. $x = $x->whereIn('id', $certs);
  148. }
  149. $count = $x->count();
  150. if (isset($_GET["start"]))
  151. $x = $x->offset($_GET["start"])->limit($_GET["length"])->get();
  152. else
  153. $x = $x->get();
  154. $filterStatus = isset($_GET["status"]) ? $_GET["status"] : -1;
  155. foreach($x as $idx => $r)
  156. {
  157. $status = $r->getStatus();
  158. $status = $status["status"];
  159. $state = $r->isActive();
  160. $procede = true;
  161. if ($filterStatus >= 0)
  162. {
  163. if ($state["status"] != $filterStatus)
  164. $procede = false;
  165. }
  166. if ($procede)
  167. {
  168. $class = $status > 0 ? ($status == 2 ? 'active' : 'suspended') : 'due';
  169. $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
  170. $x = $state["status"] > 0 ? ($state["status"] == 2 ? 'active' : 'suspended') : '';
  171. $x .= "|";
  172. $x .= $state["status"] > 0 ? ($state["status"] == 2 ? 'Attivo' : 'Sospesa') : '';
  173. $x .= "|";
  174. $x .= $state["status"] ? 'Scadenza : ' : ($state["date"] != '' ? 'Scaduto : ' : '');
  175. $x .= "|";
  176. $x .= $state["date"] != '' ? date("d/m/Y", strtotime($state["date"])) : '';
  177. $has_certificate = $r->hasCertificate();
  178. $y = '';
  179. if($has_certificate["date"] != '')
  180. {
  181. if($has_certificate["date"] < date("Y-m-d"))
  182. $y .= '0';
  183. if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
  184. $y .= '1';
  185. if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
  186. $y .= '2';
  187. $y .= '|';
  188. $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : '';
  189. }
  190. $datas[] = array(
  191. //'c' => $idx + 1,
  192. 'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
  193. 'first_name' => $r->first_name . "|" . $r->id,
  194. 'last_name' => $r->last_name . "|" . $r->id,
  195. 'phone' => $r->phone,
  196. 'age' => $r->getAge(),
  197. 'status' => $class . "|" . $text,
  198. 'state' => $x,
  199. 'certificate' => $y,
  200. 'action' => $r->id
  201. );
  202. }
  203. /*
  204. $r->age = $r->getAge();
  205. $active = $r->isActive();
  206. $r->status = $active["status"];
  207. $r->date = $active["date"] . "|" . $r->hasCertificate()["date"];
  208. $r->state = $r->getStatus()["status"];
  209. $r->action = '';*/
  210. }
  211. /*
  212. if ($this->sortAsc)
  213. $this->records = $this->records->sortBy($this->sortField);
  214. else
  215. $this->records = $this->records->sortByDesc($this->sortField);
  216. */
  217. // $datas = $x; // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
  218. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  219. });
  220. Route::get('/get_record_in', function(){
  221. $datas = [];
  222. $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'))
  223. ->leftJoin('members', 'records.member_id', '=', 'members.id')
  224. ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
  225. ->where('records.type', 'IN');
  226. // $datas = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method');
  227. if ($_GET["filterCommercial"] > 0)
  228. {
  229. $x = $x->where('commercial', $_GET["filterCommercial"] == 1 ? true : false);
  230. }
  231. if ($_GET["filterMember"] > 0)
  232. {
  233. $x = $x->where('member_id', $_GET["filterMember"]);
  234. }
  235. if ($_GET["filterPaymentMethod"] > 0)
  236. {
  237. $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]);
  238. }
  239. if ($_GET["filterCausals"] > 0)
  240. {
  241. $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  242. $x = $x->whereIn('records.id', $causals);
  243. }
  244. if ($_GET["filterFrom"] != '')
  245. {
  246. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  247. }
  248. if ($_GET["filterTo"] != '')
  249. {
  250. $x = $x->where('date', '<=', $_GET["filterTo"]);
  251. }
  252. if (isset($_GET["search"]["value"]))
  253. {
  254. $v = $_GET["search"]["value"];
  255. $x = $x->where(function ($query) use ($v) {
  256. $query->where('first_name', 'like', '%' . $v . '%')
  257. ->orWhere('last_name', 'like', '%' . $v . '%');
  258. });
  259. //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
  260. }
  261. $start = 0;
  262. $limit = 10000;
  263. if (isset($_GET["start"]))
  264. {
  265. $start = $_GET["start"];
  266. $limit = $_GET["length"];
  267. }
  268. $total = 0;
  269. foreach($x->get() as $r)
  270. {
  271. foreach($r->rows as $rr)
  272. {
  273. if (!$r->deleted)
  274. {
  275. $total += $rr->amount;
  276. if ($rr->vat_id > 0)
  277. $total += getVatValue($rr->amount, $rr->vat_id);
  278. }
  279. }
  280. }
  281. $x = $x->offset($start)->limit($limit)->get();
  282. foreach($x as $idx => $r)
  283. {
  284. $causals = '';
  285. foreach($r->rows as $row)
  286. {
  287. $causals .= $row->causal->getTree() . "<br>";
  288. }
  289. $datas[] = array(
  290. //'id' => $r->id,
  291. 'date' => $r->date,
  292. 'total' => formatPrice($r->getTotal()),
  293. 'first_name' => $r->first_name,
  294. 'last_name' => $r->last_name,
  295. 'commercial' => $r->commercial ? 'SI' : 'NO',
  296. 'causals' => $causals,
  297. 'payment' => $r->payment_method->name,
  298. 'status' => $r->deleted ? 'Annullato' : '',
  299. 'action' => $r->id . "|" . formatPrice($total) . "|" . ($r->deleted ? 'x' : '')
  300. );
  301. }
  302. $datas[] = array(
  303. //'id' => $r->id,
  304. 'date' => '',
  305. 'total' => formatPrice($total),
  306. 'first_name' => '',
  307. 'last_name' => '',
  308. 'commercial' => '',
  309. 'causals' => '',
  310. 'payment' => '',
  311. 'status' => '',
  312. 'action' => ''
  313. );
  314. return json_encode(array("data" => $datas));
  315. });
  316. Route::get('/get_record_out', function(){
  317. $datas = [];
  318. $x = \App\Models\Record::where('type', 'OUT')->with('supplier', 'payment_method');
  319. if ($_GET["filterSupplier"] > 0)
  320. {
  321. $x = $x->where('supplier_id', $_GET["filterSupplier"]);
  322. }
  323. if ($_GET["filterPaymentMethod"] > 0)
  324. {
  325. $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]);
  326. }
  327. if ($_GET["filterCausals"] > 0)
  328. {
  329. $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  330. $x = $x->whereIn('records.id', $causals);
  331. }
  332. if ($_GET["filterFrom"] != '')
  333. {
  334. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  335. }
  336. if ($_GET["filterTo"] != '')
  337. {
  338. $x = $x->where('date', '<=', $_GET["filterTo"]);
  339. }
  340. $total = 0;
  341. foreach($x->get() as $r)
  342. {
  343. foreach($r->rows as $rr)
  344. {
  345. $total += $rr->amount;
  346. if ($rr->vat_id > 0)
  347. $total += getVatValue($rr->amount, $rr->vat_id);
  348. }
  349. }
  350. $x = $x->get();
  351. foreach($x as $idx => $r)
  352. {
  353. $causals = '';
  354. foreach($r->rows as $row)
  355. {
  356. $causals .= $row->causal->getTree() . "<br>";
  357. }
  358. $datas[] = array(
  359. //'id' => $r->id,
  360. 'date' => $r->date,
  361. 'total' => formatPrice($r->getTotal()),
  362. 'supplier' => $r->supplier->name,
  363. 'causals' => $causals,
  364. 'payment' => $r->payment_method->name,
  365. 'action' => $r->id . "|" . formatPrice($total)
  366. );
  367. }
  368. $datas[] = array(
  369. //'id' => $r->id,
  370. 'date' => '',
  371. 'total' => formatPrice($total),
  372. 'supplier' => '',
  373. 'causals' => '',
  374. 'payment' => '',
  375. 'action' => ''
  376. );
  377. return json_encode(array("data" => $datas));
  378. });
  379. Route::get('/migrate', function(){
  380. \Artisan::call('migrate');
  381. dd('migrated!');
  382. });