web.php 13 KB

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