web.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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. })->name('login');
  18. Route::post('/login', function () {
  19. if(\Auth::attempt(array('email' => $_POST["email"], 'password' => $_POST["password"])))
  20. {
  21. return Redirect::to('/dashboard');
  22. }
  23. else
  24. {
  25. return Redirect::to('/?error=1');
  26. }
  27. })->name('login');
  28. Route::get('/logout', function(){
  29. Auth::logout();
  30. return redirect('/');
  31. });
  32. Route::group(['middleware' => 'auth'],function(){
  33. //Route::get('/', \App\Http\Livewire\Login::class);
  34. Route::get('/dashboard', \App\Http\Livewire\Dashboard::class);
  35. Route::get('/settings', \App\Http\Livewire\Setting::class);
  36. Route::get('/courses', \App\Http\Livewire\Course::class);
  37. Route::get('/categories', \App\Http\Livewire\Category::class);
  38. Route::get('/nations_list', \App\Http\Livewire\Nation::class);
  39. Route::get('/provinces', \App\Http\Livewire\Province::class);
  40. Route::get('/cities', \App\Http\Livewire\City::class);
  41. Route::get('/banks', \App\Http\Livewire\Bank::class);
  42. Route::get('/vats', \App\Http\Livewire\Vat::class);
  43. Route::get('/disciplines', \App\Http\Livewire\Discipline::class);
  44. Route::get('/course_types', \App\Http\Livewire\CourseType::class);
  45. Route::get('/course_subscriptions', \App\Http\Livewire\CourseSubscription::class);
  46. Route::get('/course_durations', \App\Http\Livewire\CourseDuration::class);
  47. Route::get('/course_levels', \App\Http\Livewire\CourseLevel::class);
  48. Route::get('/course_frequencies', \App\Http\Livewire\CourseFrequency::class);
  49. Route::get('/course_list', \App\Http\Livewire\CourseList::class);
  50. Route::get('/course_member', \App\Http\Livewire\CourseMember::class);
  51. Route::get('/receipts', \App\Http\Livewire\Receipt::class);
  52. Route::get('/cards', \App\Http\Livewire\Card::class);
  53. Route::get('/causals', \App\Http\Livewire\Causal::class);
  54. Route::get('/payment_methods', \App\Http\Livewire\PaymentMethod::class);
  55. Route::get('/members', \App\Http\Livewire\Member::class);
  56. Route::get('/suppliers', \App\Http\Livewire\Supplier::class);
  57. Route::get('/sponsors', \App\Http\Livewire\Sponsor::class);
  58. Route::get('/records', \App\Http\Livewire\Record::class);
  59. Route::get('/reminders', \App\Http\Livewire\Reminder::class);
  60. Route::get('/in', \App\Http\Livewire\RecordIN::class);
  61. Route::get('/out', \App\Http\Livewire\RecordOUT::class);
  62. Route::get('/records_in_out', \App\Http\Livewire\RecordINOUT::class);
  63. Route::get('/users', \App\Http\Livewire\User::class);
  64. });
  65. Route::get('/receipt/{id}', function($id){
  66. $receipt = \App\Models\Receipt::findOrFail($id);
  67. $pdf = PDF::loadView('receipt', array('receipt' => $receipt));
  68. $pdfName = "Ricevuta_" . $receipt->member->last_name . "_" . $receipt->number . "_" . $receipt->year . ".pdf";
  69. return $pdf->stream($pdfName);
  70. /*return response()->streamDownload(
  71. fn () => print($pdf),
  72. "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf"
  73. );*/
  74. });
  75. Route::get('/receipt/mail/{id}', function($id){
  76. $receipt = \App\Models\Receipt::findOrFail($id);
  77. if ($receipt->status == 99)
  78. sendReceiptDeleteEmail($receipt);
  79. else
  80. sendReceiptEmail($receipt);
  81. /*
  82. $pdf = PDF::loadView('receipt', array('receipt' => $receipt));
  83. $pdfName = "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf";
  84. Storage::put('public/pdf/' . $pdfName, $pdf->output());
  85. $email = \App\Models\Member::findOrFail($receipt->member_id)->email;
  86. if ($email != '')
  87. {
  88. Mail::to($email)->send(new \App\Mail\ReceipEmail([
  89. 'name' => 'Luca',
  90. 'pdf' => 'public/pdf/' . $pdfName,
  91. 'number' => $receipt->number . "/" . $receipt->year
  92. ]));
  93. }
  94. */
  95. return true;
  96. //return $pdf->stream();
  97. /*return response()->streamDownload(
  98. fn () => print($pdf),
  99. "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf"
  100. );*/
  101. });
  102. Route::get('/nations', function(){
  103. if (isset($_GET["q"]))
  104. $datas = \App\Models\Nation::where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
  105. else
  106. $datas = \App\Models\Nation::orderBy('name')->get();
  107. $data = array();
  108. foreach($datas as $d)
  109. {
  110. $data[] = array("id" => $d->id, "text" => $d->name);
  111. }
  112. return array("results" => $data);
  113. });
  114. Route::get('/provinces/{nation_id}', function($nation_id){
  115. if (isset($_GET["q"]))
  116. $datas = \App\Models\Province::where('nation_id', $nation_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
  117. else
  118. $datas = \App\Models\Province::where('nation_id', $nation_id)->orderBy('name')->get();
  119. $data = array();
  120. foreach($datas as $d)
  121. {
  122. $data[] = array("id" => $d->id, "text" => $d->name);
  123. }
  124. return array("results" => $data);
  125. });
  126. Route::get('/cities/{province_id}', function($province_id){
  127. if (isset($_GET["q"]))
  128. $datas = \App\Models\City::where('province_id', $province_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
  129. else
  130. $datas = \App\Models\City::where('province_id', $province_id)->orderBy('name')->get();
  131. $data = array();
  132. foreach($datas as $d)
  133. {
  134. $data[] = array("id" => $d->id, "text" => $d->name);
  135. }
  136. return array("results" => $data);
  137. });
  138. Route::get('/get_members', function(){
  139. $datas = [];
  140. // $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
  141. $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone', 'birth_date', 'to_complete', 'current_status', 'certificate', 'certificate_date')->where('id', '>', 0);
  142. if (isset($_GET["search"]["value"]))
  143. {
  144. $v = str_replace("'", "''", stripcslashes($_GET["search"]["value"]));
  145. $x = $x->where(function ($query) use ($v) {
  146. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  147. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  148. });
  149. //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
  150. }
  151. if ($_GET["cards"] != "")
  152. {
  153. $card_ids = \App\Models\MemberCard::whereIn('card_id', explode(",", $_GET["cards"]))->pluck('member_id');
  154. $x = $x->whereIn('id', $card_ids);
  155. }
  156. if ($_GET["filterCategories"] != "null")
  157. {
  158. $cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["filterCategories"]))->pluck('member_id');
  159. $x = $x->whereIn('id', $cats_ids);
  160. }
  161. if ($_GET["fromYear"] != "")
  162. {
  163. $x = $x->where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time())));
  164. }
  165. if ($_GET["toYear"] != "")
  166. {
  167. $x = $x->where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())));
  168. }
  169. if ($_GET["fromYearYear"] != "")
  170. {
  171. $x = $x->whereYear('birth_date', '>=', $_GET["fromYearYear"]);
  172. }
  173. if ($_GET["toYearYear"] != "")
  174. {
  175. $x = $x->whereYear('birth_date', '<=', $_GET["toYearYear"]);
  176. }
  177. $ids = [];
  178. if ($_GET["filterCertificateType"] != "null")
  179. {
  180. $types = \App\Models\MemberCertificate::where('type', $_GET["filterCertificateType"])->pluck('member_id');
  181. $x = $x->whereIn('id', $types->toArray());;
  182. //$ids = array_merge($ids, $types->toArray());
  183. }
  184. if ($_GET["filterScadenza"] != "null")
  185. {
  186. if ($_GET["filterScadenza"] == "1")
  187. $scad = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  188. if ($_GET["filterScadenza"] == "2")
  189. $scad = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  190. //$ids = array_merge($ids, $scad->toArray());
  191. $x = $x->whereIn('id', $scad->toArray());;
  192. //$x = $x->whereIn('id', $scadenza);
  193. }
  194. if ($_GET["filterStatus"] != "null")
  195. {
  196. $status = explode(",", $_GET["filterStatus"]);
  197. $members = \App\Models\Member::all();
  198. foreach($status as $s)
  199. {
  200. foreach($members as $m)
  201. {
  202. $state = $m->isActive();
  203. if ($state["status"] == $s)
  204. $ids[] = $m->id;
  205. }
  206. }
  207. }
  208. if (sizeof($ids) > 0)
  209. {
  210. $x = $x->whereIn('id', $ids);
  211. }
  212. else
  213. {
  214. if ($_GET["filterStatus"] != "null")
  215. $x = $x->whereIn('id', [-1]);
  216. }
  217. $count = $x->count();
  218. $x = $x->orderBy('to_complete', 'DESC');
  219. if (isset($_GET["order"]))
  220. {
  221. $column = '';
  222. if ($_GET["order"][0]["column"] == 0)
  223. $column = 'last_name';
  224. if ($_GET["order"][0]["column"] == 1)
  225. $column = 'first_name';
  226. if ($_GET["order"][0]["column"] == 2)
  227. $column = 'phone';
  228. if ($_GET["order"][0]["column"] == 3)
  229. $column = 'birth_date';
  230. if ($_GET["order"][0]["column"] == 4)
  231. $column = 'birth_date';
  232. if ($_GET["order"][0]["column"] == 5)
  233. $column = 'current_status';
  234. if ($_GET["order"][0]["column"] == 6)
  235. $column = 'certificate';
  236. if ($column != '')
  237. $x = $x->orderBy($column, $_GET["order"][0]["dir"]);
  238. else
  239. $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  240. }
  241. else
  242. $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  243. if (isset($_GET["start"]))
  244. $x = $x->offset($_GET["start"])->limit($_GET["length"])->get();
  245. else
  246. $x = $x->get();
  247. foreach($x as $idx => $r)
  248. {
  249. // $status = $r->getStatus();
  250. // $status = $status["status"];
  251. $status = $r->current_status;
  252. $class = $status > 0 ? ($status == 2 ? 'active' : 'due') : 'suspended';
  253. $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
  254. if ($r->to_complete)
  255. {
  256. $text = 'Da completare';
  257. $class = "complete";
  258. }
  259. // $has_certificate = $r->hasCertificate();
  260. $y = '';
  261. if ($r->certificate_date != '')
  262. {
  263. $y = $r->certificate . "|" . date("d/m/Y", strtotime($r->certificate_date));
  264. }
  265. /*
  266. if($has_certificate["date"] != '')
  267. {
  268. if($has_certificate["date"] < date("Y-m-d"))
  269. $y .= '0';
  270. if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
  271. $y .= '1';
  272. if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
  273. $y .= '2';
  274. $y .= '|';
  275. $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : '';
  276. }*/
  277. $datas[] = array(
  278. //'c' => $idx + 1,
  279. //'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
  280. 'last_name' => $r->last_name . "|" . $r->id,
  281. 'first_name' => $r->first_name . "|" . $r->id,
  282. 'phone' => $r->phone,
  283. 'age' => $r->getAge(),
  284. 'year' => date("Y", strtotime($r->birth_date)),
  285. 'status' => $class . "|" . $text,
  286. // 'state' => $x,
  287. 'certificate' => $y,
  288. 'action' => $r->id
  289. );
  290. }
  291. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  292. });
  293. Route::get('/get_record_in', function(){
  294. $datas = [];
  295. $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'))
  296. ->leftJoin('members', 'records.member_id', '=', 'members.id')
  297. ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
  298. ->where('records.type', 'IN');
  299. if (isset($_GET["search"]["value"]))
  300. {
  301. $v = str_replace("'", "''", stripcslashes($_GET["search"]["value"]));
  302. $x = $x->where(function ($query) use ($v) {
  303. $query->where('first_name', 'like', '%' . $v . '%')
  304. ->orWhere('last_name', 'like', '%' . $v . '%');
  305. });
  306. //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
  307. }
  308. //$x = $x->where(function ($query) use ($v) {
  309. // $datas = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method');
  310. if ($_GET["filterCommercial"] == 1)
  311. {
  312. $x = $x->where('commercial', true );
  313. }
  314. if ($_GET["filterCommercial"] == 2)
  315. {
  316. $x = $x->where('commercial', false);
  317. }
  318. if ($_GET["filterMember"] > 0)
  319. {
  320. $x = $x->where('member_id', $_GET["filterMember"]);
  321. }
  322. if ($_GET["filterPaymentMethod"] != "null")
  323. {
  324. $payments = explode(",", $_GET["filterPaymentMethod"]);
  325. $x = $x->whereIn('payment_method_id', $payments);
  326. }
  327. if ($_GET["filterCausals"] != "null")
  328. {
  329. $causals = explode(",", $_GET["filterCausals"]);
  330. //$causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  331. $causals = \App\Models\RecordRow::whereIn('causal_id', $causals)->pluck('record_id');
  332. $x = $x->whereIn('records.id', $causals);
  333. }
  334. if ($_GET["filterFrom"] != '')
  335. {
  336. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  337. }
  338. if ($_GET["filterTo"] != '')
  339. {
  340. $x = $x->where('date', '<=', $_GET["filterTo"]);
  341. }
  342. //});
  343. $start = 0;
  344. $limit = 100000;
  345. if (isset($_GET["start"]))
  346. {
  347. $start = $_GET["start"];
  348. $limit = $_GET["length"];
  349. }
  350. $excludeCausals = [];
  351. /*$borsellino = \App\Models\Causal::where('money', true)->first();
  352. if ($borsellino)
  353. $excludeCausals[] = $borsellino->id;*/
  354. // Aggiungo
  355. $excludes = \App\Models\Causal::where('no_records', true)->get();
  356. foreach($excludes as $e)
  357. {
  358. $excludeCausals[] = $e->id;
  359. }
  360. $exclude_from_records = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
  361. // Pagamento money
  362. $moneys = \App\Models\PaymentMethod::where('money', true)->pluck('id')->toArray();
  363. // Causale money
  364. $moneysCausal = \App\Models\Causal::where('money', true)->pluck('id')->toArray();
  365. $total = 0;
  366. /*
  367. foreach($x->get() as $r)
  368. {
  369. if (!in_array($r->payment_method_id, $moneys))
  370. {
  371. foreach($r->rows as $rr)
  372. {
  373. if ((!in_array($rr->member_id, $exclude_from_records) || in_array($r->causal_id, $moneysCausal)) && (!$r->deleted || $r->deleted == null) && (!in_array($rr->causal_id, $excludeCausals) || in_array($r->causal_id, $moneysCausal)) && (!$r->financial_movement || $r->financial_movement == null) && (!$r->corrispettivo_fiscale || $r->corrispettivo_fiscale == null))
  374. {
  375. $total += $rr->amount;
  376. if ($rr->vat_id > 0)
  377. $total += getVatValue($rr->amount, $rr->vat_id);
  378. }
  379. }
  380. }
  381. }
  382. */
  383. $count = $x->count();
  384. if (isset($_GET["order"]))
  385. {
  386. $column = '';
  387. if ($_GET["order"][0]["column"] == 0)
  388. $column = 'date';
  389. if ($_GET["order"][0]["column"] == 1)
  390. $column = 'records.amount';
  391. if ($_GET["order"][0]["column"] == 2)
  392. $column = 'last_name';
  393. if ($_GET["order"][0]["column"] == 3)
  394. $column = 'first_name';
  395. if ($_GET["order"][0]["column"] == 4)
  396. $column = 'commercial';
  397. if ($column != '')
  398. $x = $x->orderBy($column, $_GET["order"][0]["dir"])->orderBy('records.id', 'DESC');
  399. else
  400. $x = $x->orderBy('records.id', 'DESC');
  401. }
  402. else
  403. $x = $x->orderBy('records.date', 'DESC')->orderBy('records.id', 'DESC');
  404. $x = $x->offset($start)->limit($limit)->get();
  405. foreach($x as $idx => $r)
  406. {
  407. $causals = '';
  408. foreach($r->rows as $row)
  409. {
  410. $causals .= $row->causal->getTree() . "<br>";
  411. }
  412. $datas[] = array(
  413. //'id' => $r->id,
  414. 'date' => $r->date,
  415. 'total' => formatPrice($r->getTotal()),
  416. 'first_name' => $r->first_name,
  417. 'last_name' => $r->last_name,
  418. 'commercial' => $r->financial_movement ? 'Movimento finanziario' : ($r->commercial ? 'SI' : 'NO'),
  419. 'causals' => $causals,
  420. 'payment' => $r->payment_method->name,
  421. 'status' => $r->deleted ? 'Annullato' : '',
  422. 'action' => $r->id . "|" . formatPrice($total) . "|" . ($r->deleted ? 'x' : '')
  423. );
  424. }
  425. /*$datas[] = array(
  426. //'id' => $r->id,
  427. 'date' => '',
  428. 'total' => formatPrice($total),
  429. 'first_name' => '',
  430. 'last_name' => '',
  431. 'commercial' => '',
  432. 'causals' => '',
  433. 'payment' => '',
  434. 'status' => '',
  435. 'action' => ''
  436. );*/
  437. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  438. });
  439. Route::get('/get_record_out', function(){
  440. $datas = [];
  441. $x = \App\Models\Record::where('type', 'OUT')->with('supplier', 'payment_method');
  442. if ($_GET["filterSupplier"] > 0)
  443. {
  444. $x = $x->where('supplier_id', $_GET["filterSupplier"]);
  445. }
  446. /*if ($_GET["filterPaymentMethod"] > 0)
  447. {
  448. $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]);
  449. }
  450. if ($_GET["filterCausals"] > 0)
  451. {
  452. $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  453. $x = $x->whereIn('records.id', $causals);
  454. }*/
  455. if ($_GET["filterPaymentMethod"] != "null")
  456. {
  457. $payments = explode(",", $_GET["filterPaymentMethod"]);
  458. $x = $x->whereIn('payment_method_id', $payments);
  459. }
  460. if ($_GET["filterCausals"] != "null")
  461. {
  462. $causals = explode(",", $_GET["filterCausals"]);
  463. //$causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  464. $causals = \App\Models\RecordRow::whereIn('causal_id', $causals)->pluck('record_id');
  465. $x = $x->whereIn('records.id', $causals);
  466. }
  467. if ($_GET["filterFrom"] != '')
  468. {
  469. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  470. }
  471. if ($_GET["filterTo"] != '')
  472. {
  473. $x = $x->where('date', '<=', $_GET["filterTo"]);
  474. }
  475. $total = 0;
  476. /*foreach($x->get() as $r)
  477. {
  478. foreach($r->rows as $rr)
  479. {
  480. $total += $rr->amount;
  481. if ($rr->vat_id > 0)
  482. $total += getVatValue($rr->amount, $rr->vat_id);
  483. }
  484. }*/
  485. $x = $x->get();
  486. foreach($x as $idx => $r)
  487. {
  488. $causals = '';
  489. foreach($r->rows as $row)
  490. {
  491. $causals .= $row->causal->getTree() . "<br>";
  492. }
  493. $datas[] = array(
  494. //'id' => $r->id,
  495. 'date' => $r->date,
  496. 'total' => formatPrice($r->getTotal()),
  497. 'supplier' => $r->supplier->name,
  498. 'causals' => $causals,
  499. 'payment' => $r->payment_method->name,
  500. 'action' => $r->id . "|" . formatPrice($total)
  501. );
  502. }
  503. /*
  504. $datas[] = array(
  505. //'id' => $r->id,
  506. 'date' => '',
  507. 'total' => formatPrice($total),
  508. 'supplier' => '',
  509. 'causals' => '',
  510. 'payment' => '',
  511. 'action' => ''
  512. );
  513. */
  514. return json_encode(array("data" => $datas));
  515. });
  516. Route::get('/get_course_list', function(){
  517. $member_course = \App\Models\MemberCourse::with('member');
  518. if (isset($_GET["search"]["value"]))
  519. {
  520. $v = str_replace("'", "''", stripcslashes($_GET["search"]["value"]));
  521. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  522. $query->where('first_name', 'like', '%' . $v . '%')
  523. ->orWhere('last_name', 'like', '%' . $v . '%');
  524. })->pluck('id');
  525. $member_course = $member_course->whereIn('member_id', $member_ids);
  526. }
  527. if ($_GET["filterCourse"] != "null")
  528. {
  529. $course_ids = [];
  530. $courses = explode(",", $_GET["filterCourse"]);
  531. foreach($courses as $c)
  532. {
  533. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  534. foreach($all as $a)
  535. {
  536. $course_ids[] = $a->id;
  537. }
  538. }
  539. $member_course = $member_course->whereIn('course_id', $course_ids);
  540. }
  541. if ($_GET["filterLevel"] != "null")
  542. {
  543. $levels = explode(",", $_GET["filterLevel"]);
  544. $course_ids = \App\Models\Course::whereIn('course_level_id', $levels)->pluck('id');
  545. $member_course = $member_course->whereIn('course_id', $course_ids);
  546. }
  547. if ($_GET["filterFrequency"] != "null")
  548. {
  549. $frequencies = explode(",", $_GET["filterFrequency"]);
  550. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $frequencies)->pluck('id');
  551. $member_course = $member_course->whereIn('course_id', $course_ids);
  552. }
  553. if ($_GET["filterType"] != "null")
  554. {
  555. $types = explode(",", $_GET["filterType"]);
  556. $course_ids = \App\Models\Course::whereIn('course_type_id', $types)->pluck('id');
  557. $member_course = $member_course->whereIn('course_id', $course_ids);
  558. }
  559. if ($_GET["filterDuration"] != "null")
  560. {
  561. $durations = explode(",", $_GET["filterDuration"]);
  562. $course_ids = \App\Models\Course::whereIn('course_duration_id', $durations)->pluck('id');
  563. $member_course = $member_course->whereIn('course_id', $course_ids);
  564. }
  565. $totals = [];
  566. $totalIsc = [];
  567. $member_course_totals = $member_course->get();
  568. foreach($member_course_totals as $x)
  569. {
  570. $price = 0;
  571. $price = $x->course->price;
  572. $subPrice = $x->course->subscription_price;
  573. $records = \App\Models\Record::where('member_course_id', $x->id)->where('deleted', 0)->get();
  574. $prices = [];
  575. foreach ($records as $record)
  576. {
  577. foreach ($record->rows as $row)
  578. {
  579. //if ($row->causal_id == $x->course->sub_causal_id || str_contains(strtolower($row->note), 'iscrizione'))
  580. if (str_contains(strtolower($row->note), 'iscrizione'))
  581. {
  582. $subPrice = $row->amount;
  583. }
  584. if ($row->causal_id == $x->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
  585. {
  586. $tot = sizeof(json_decode($row->when));
  587. foreach(json_decode($row->when) as $m)
  588. {
  589. $prices[$m->month] = $row->amount / $tot;
  590. }
  591. }
  592. }
  593. }
  594. for($i=1; $i<=12; $i++)
  595. {
  596. $cls = getColor($x->months, $i);
  597. if ($cls != 'grey')
  598. {
  599. if (!isset($totals[$i]))
  600. {
  601. $totals[$i]['green'] = 0;
  602. $totals[$i]['orange'] = 0;
  603. $totals[$i]['yellow'] = 0;
  604. }
  605. if ($cls == 'yellow')
  606. {
  607. $totals[$i][$cls] += 1;
  608. }
  609. else
  610. {
  611. $p = isset($prices[$i]) ? $prices[$i] : $price;
  612. $totals[$i][$cls] += $p;
  613. }
  614. }
  615. }
  616. $sub = $x->subscribed ? "Y" : "N";
  617. if (isset($totalIsc[$sub]))
  618. $totalIsc[$sub] += $subPrice;
  619. else
  620. $totalIsc[$sub] = $subPrice;
  621. }
  622. $count = $member_course->count();
  623. $js = '';
  624. $xx = 2;
  625. $str = '';
  626. if ($count > 0)
  627. {
  628. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=green><small>" . (isset($totalIsc["Y"]) ? formatPrice($totalIsc["Y"]) : 0) . "</small></a><br>";
  629. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=orange><small>" . (isset($totalIsc["N"]) ? formatPrice($totalIsc["N"]) : 0) . "</small></a><br>";
  630. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=yellow><small>0</small></a><br>";
  631. }
  632. $js .= "2§" . $str . "_";
  633. $str = "";
  634. foreach($totals as $z => $t)
  635. {
  636. if ($z == 1) $xx = 7;
  637. if ($z == 2) $xx = 8;
  638. if ($z == 3) $xx = 9;
  639. if ($z == 4) $xx = 10;
  640. if ($z == 5) $xx = 11;
  641. if ($z == 6) $xx = 12;
  642. if ($z == 7) $xx = 13;
  643. if ($z == 8) $xx = 14;
  644. if ($z == 9) $xx = 3;
  645. if ($z == 10) $xx = 4;
  646. if ($z == 11) $xx = 5;
  647. if ($z == 12) $xx = 6;
  648. $str = '';
  649. foreach($t as $x => $c)
  650. {
  651. $y = $x == 'yellow' ? $c : formatPrice($c);
  652. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=" . $x . "><small>" . $y . "</small></a><br>";
  653. }
  654. $js .= $xx . "§" . $str . "_";
  655. $xx += 1;
  656. }
  657. //$member_course = $member_course->where('course_id', 999999);
  658. $start = 0;
  659. $limit = 100000;
  660. if (isset($_GET["start"]))
  661. {
  662. $start = $_GET["start"];
  663. $limit = $_GET["length"];
  664. }
  665. $member_course = $member_course->offset($start)->limit($limit)->get();
  666. $datas = [];
  667. foreach($member_course as $x)
  668. {
  669. $price = 0;
  670. $price = $x->course->price;
  671. $subPrice = $x->course->subscription_price;
  672. $records = \App\Models\Record::where('member_course_id', $x->id)->where('deleted', 0)->get();
  673. $prices = [];
  674. foreach ($records as $record)
  675. {
  676. foreach ($record->rows as $row)
  677. {
  678. //if ($row->causal_id == $x->course->sub_causal_id || str_contains(strtolower($row->note), 'iscrizione'))
  679. if (str_contains(strtolower($row->note), 'iscrizione'))
  680. {
  681. $subPrice = $row->amount;
  682. }
  683. if ($row->causal_id == $x->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
  684. {
  685. $tot = sizeof(json_decode($row->when));
  686. foreach(json_decode($row->when) as $m)
  687. {
  688. $prices[$m->month] = $row->amount / $tot;
  689. }
  690. }
  691. }
  692. }
  693. for($i=1; $i<=12; $i++)
  694. {
  695. $cls = getColor($x->months, $i);
  696. if ($cls != 'grey')
  697. {
  698. if (!isset($totals[$i]))
  699. {
  700. $totals[$i]['green'] = 0;
  701. $totals[$i]['orange'] = 0;
  702. $totals[$i]['yellow'] = 0;
  703. }
  704. if ($cls == 'yellow')
  705. {
  706. $prices[$i] = 0;
  707. $totals[$i][$cls] += 1;
  708. }
  709. else
  710. {
  711. $p = isset($prices[$i]) ? $prices[$i] : $price;
  712. $totals[$i][$cls] += $p;
  713. }
  714. }
  715. }
  716. $sub = $x->subscribed ? "Y" : "N";
  717. if (isset($totalIsc[$sub]))
  718. $totalIsc[$sub] += $subPrice;
  719. else
  720. $totalIsc[$sub] = $subPrice;
  721. $datas[] = array(
  722. "column_0" => $x->member->last_name,
  723. "column_1" => $x->member->first_name,
  724. "column_2" => $x->subscribed . "§" . formatPrice($subPrice),
  725. "column_3" => getColor($x->months, 9) . "§" . formatPrice(isset($prices[9]) ? $prices[9] : $price),
  726. "column_4" => getColor($x->months, 10) . "§" . formatPrice(isset($prices[10]) ? $prices[10] : $price),
  727. "column_5" => getColor($x->months, 11) . "§" . formatPrice(isset($prices[11]) ? $prices[11] : $price),
  728. "column_6" => getColor($x->months, 12) . "§" . formatPrice(isset($prices[12]) ? $prices[12] : $price),
  729. "column_7" => getColor($x->months, 1) . "§" . formatPrice(isset($prices[1]) ? $prices[1] : $price),
  730. "column_8" => getColor($x->months, 2) . "§" . formatPrice(isset($prices[2]) ? $prices[2] : $price),
  731. "column_9" => getColor($x->months, 3) . "§" . formatPrice(isset($prices[3]) ? $prices[3] : $price),
  732. "column_10" => getColor($x->months, 4) . "§" . formatPrice(isset($prices[4]) ? $prices[4] : $price),
  733. "column_11" => getColor($x->months, 5) . "§" . formatPrice(isset($prices[5]) ? $prices[5] : $price),
  734. "column_12" => getColor($x->months, 6) . "§" . formatPrice(isset($prices[6]) ? $prices[6] : $price),
  735. "column_13" => getColor($x->months, 7) . "§" . formatPrice(isset($prices[7]) ? $prices[7] : $price),
  736. "column_14" => getColor($x->months, 8) . "§" . formatPrice(isset($prices[8]) ? $prices[8] : $price),
  737. "column_15" => $x->course_id,
  738. "column_16" => $x->id,
  739. "column_17" => $x->member_id
  740. );
  741. }
  742. // Sort data
  743. /*
  744. if (isset($_GET["order"]))
  745. array_multisort(array_column($datas, 'column_' . $_GET["order"][0]["column"]), $_GET["order"][0]["dir"] == "asc" ? SORT_ASC : SORT_DESC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
  746. else
  747. array_multisort(array_column($datas, 'column_0'), SORT_DESC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
  748. //$x = $x->orderBy('records.date', 'DESC')->orderBy('records.id', 'DESC');
  749. */
  750. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count, "totals" => $js));
  751. });
  752. Route::get('/get_course_members', function(){
  753. //$datas = \App\Models\MemberCourse::with('member');
  754. $datas = \App\Models\MemberCourse::select('member_courses.*', 'members.first_name', 'members.last_name', 'members.email', 'members.phone', 'members.birth_date')->leftJoin('members', 'member_courses.member_id', '=', 'members.id');
  755. if ($_GET["filterCourse"] != "null")
  756. {
  757. $course_ids = [];
  758. $courses = explode(",", $_GET["filterCourse"]);
  759. foreach($courses as $c)
  760. {
  761. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  762. foreach($all as $a)
  763. {
  764. $course_ids[] = $a->id;
  765. }
  766. }
  767. $datas = $datas->whereIn('course_id', $course_ids);
  768. }
  769. if ($_GET["filterLevel"] != "null")
  770. {
  771. $levels = explode(",", $_GET["filterLevel"]);
  772. $course_ids = \App\Models\Course::whereIn('course_level_id', $levels)->pluck('id');
  773. $datas = $datas->whereIn('course_id', $course_ids);
  774. }
  775. if ($_GET["filterFrequency"] != "null")
  776. {
  777. $frequencies = explode(",", $_GET["filterFrequency"]);
  778. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $frequencies)->pluck('id');
  779. $datas = $datas->whereIn('course_id', $course_ids);
  780. }
  781. if ($_GET["filterType"] != "null")
  782. {
  783. $types = explode(",", $_GET["filterType"]);
  784. $course_ids = \App\Models\Course::whereIn('course_type_id', $types)->pluck('id');
  785. $datas = $datas->whereIn('course_id', $course_ids);
  786. }
  787. if ($_GET["filterDuration"] != "null")
  788. {
  789. $durations = explode(",", $_GET["filterDuration"]);
  790. $course_ids = \App\Models\Course::whereIn('course_duration_id', $durations)->pluck('id');
  791. $datas = $datas->whereIn('course_id', $course_ids);
  792. }
  793. if ($_GET["filterDays"] != "null")
  794. {
  795. $ids = [];
  796. $days = explode(",", $_GET["filterDays"]);
  797. foreach($days as $d)
  798. {
  799. $all = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->get();
  800. foreach($all as $a)
  801. {
  802. $ids[] = $a->id;
  803. }
  804. }
  805. $datas = $datas->whereIn('member_courses.id', $ids);
  806. }
  807. if ($_GET["filterHours"] != "null")
  808. {
  809. $ids = [];
  810. $hours = explode(",", $_GET["filterHours"]);
  811. foreach($hours as $h)
  812. {
  813. $all = \App\Models\MemberCourse::where('when', 'like', '%"from":"' . $h . "%")->get();
  814. foreach($all as $a)
  815. {
  816. $ids[] = $a->id;
  817. }
  818. }
  819. $datas = $datas->whereIn('member_courses.id', $ids);
  820. }
  821. if ($_GET["filterSubscription"] != "")
  822. {
  823. $ids = \App\Models\MemberCourse::where('subscribed', $_GET["filterSubscription"] == 1 ? true : false)->pluck('id');
  824. $datas = $datas->whereIn('member_courses.id', $ids);
  825. //$this->filter .= $this->filter != '' ? ', ' : '';
  826. //$this->filter .= "Pagata sottoscrizione : " . ($this->filterSubscription == 1 ? "SI" : "NO") . " ";
  827. }
  828. if ($_GET["filterCertificateType"] != "null")
  829. {
  830. $ctypes = \App\Models\MemberCertificate::where('type', $_GET["filterCertificateType"])->pluck('member_id');
  831. $datas = $datas->whereIn('member_id', $ctypes);
  832. }
  833. if ($_GET["filterCertificateScadenza"] != "null")
  834. {
  835. if ($_GET["filterCertificateScadenza"] == "1")
  836. $scad = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  837. if ($_GET["filterCertificateScadenza"] == "2")
  838. $scad = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  839. $datas = $datas->whereIn('member_id', $scad);
  840. }
  841. if ($_GET["fromYear"] != "")
  842. {
  843. $m_ids = \App\Models\Member::where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time())))->pluck('id');
  844. $datas = $datas->whereIn('member_id', $m_ids);
  845. }
  846. if ($_GET["toYear"] != "")
  847. {
  848. $m_ids = \App\Models\Member::where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())))->pluck('id');
  849. $datas = $datas->whereIn('member_id', $m_ids);
  850. }
  851. if ($_GET["fromFromYear"] != "")
  852. {
  853. $m_ids = \App\Models\Member::whereYear('birth_date', '>=', $_GET["fromFromYear"])->pluck('id');
  854. $datas = $datas->whereIn('member_id', $m_ids);
  855. }
  856. if ($_GET["toToYear"] != "")
  857. {
  858. $m_ids = \App\Models\Member::whereYear('birth_date', '<=', $_GET["toToYear"])->pluck('id');
  859. $datas = $datas->whereIn('member_id', $m_ids);
  860. }
  861. if ($_GET["filterCards"] != "null")
  862. {
  863. $cards = explode(",", $_GET["filterCards"]);
  864. $card_ids = \App\Models\MemberCard::whereIn('card_id', $cards)->pluck('member_id');
  865. $datas = $datas->whereIn('member_id', $card_ids);
  866. }
  867. if ($_GET["filterYear"] != "")
  868. {
  869. $course_ids = \App\Models\Course::where('year', $_GET["filterYear"])->pluck('id');
  870. $datas = $datas->whereIn('course_id', $course_ids);
  871. //$this->filter .= $this->filter != '' ? ', ' : '';
  872. //$this->filter .= "Anno : " . $this->filterYear . " ";
  873. }
  874. $aRet = [];
  875. if (isset($_GET["order"]))
  876. {
  877. $column = '';
  878. if ($_GET["order"][0]["column"] == 1)
  879. $column = 'last_name';
  880. if ($_GET["order"][0]["column"] == 2)
  881. $column = 'first_name';
  882. if ($_GET["order"][0]["column"] == 2)
  883. $column = 'birth_date';
  884. if ($_GET["order"][0]["column"] == 3)
  885. $column = 'birth_date';
  886. if ($_GET["order"][0]["column"] == 4)
  887. $column = 'birth_date';
  888. if ($_GET["order"][0]["column"] == 5)
  889. $column = 'phone';
  890. if ($_GET["order"][0]["column"] == 6)
  891. $column = 'email';
  892. if ($column != '')
  893. $datas = $datas->orderBy($column, $_GET["order"][0]["dir"]);
  894. else
  895. $datas = $datas->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  896. }
  897. else
  898. $datas = $datas->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  899. if ($_GET["filterStatus"] != "null")
  900. {
  901. $status = explode(",", $_GET["filterStatus"]);
  902. foreach($status as $s)
  903. {
  904. foreach($datas->get() as $aaa)
  905. {
  906. $state = \App\Models\Member::findOrFail($aaa->member_id)->isActive();
  907. if ($state["status"] == $s)
  908. $aRet[] = $aaa;
  909. }
  910. }
  911. }
  912. else
  913. $aRet = $datas->get();
  914. $ret = [];
  915. foreach($aRet as $idx => $r)
  916. {
  917. $date1 = new DateTime($r->birth_date);
  918. $date2 = new DateTime("now");
  919. $interval = $date1->diff($date2);
  920. $ret[] = array(
  921. "column_0" => $idx + 1,
  922. "column_1" => $r->last_name,
  923. "column_2" => $r->first_name,
  924. "column_3" => strval($interval->y),
  925. "column_4" => date("Y", strtotime($r->birth_date)),
  926. "column_5" => $r->phone,
  927. "column_6" => $r->email,
  928. "column_7" => $r->member_id
  929. );
  930. }
  931. if (isset($_GET["start"]))
  932. $ret = array_slice($ret, $_GET["start"], $_GET["length"]);
  933. return json_encode(array("data" => $ret, "recordsTotal" => sizeof($aRet), "recordsFiltered" => sizeof($aRet)));
  934. });
  935. Route::get('/get_receipts', function(){
  936. $x = \App\Models\Receipt::select('receipts.*', 'members.first_name', 'members.last_name')->leftJoin('members', 'receipts.member_id', '=', 'members.id');
  937. if (isset($_GET["search"]["value"]))
  938. {
  939. $v = str_replace("'", "''", stripcslashes($_GET["search"]["value"]));
  940. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  941. $query->where('first_name', 'like', '%' . $v . '%')
  942. ->orWhere('last_name', 'like', '%' . $v . '%');
  943. })->pluck('id');
  944. $x = $x->whereIn('member_id', $member_ids);
  945. }
  946. if ($_GET["filterStatus"] != '')
  947. $x = $x->where('receipts.status', $_GET["filterStatus"]);
  948. if ($_GET["filterFrom"] != "")
  949. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  950. if ($_GET["filterTo"] != "")
  951. $x = $x->where('date', '<=', $_GET["filterTo"]);
  952. $count = $x->count();
  953. if (isset($_GET["order"]))
  954. {
  955. $column = '';
  956. if ($_GET["order"][0]["column"] == 0)
  957. $column = 'year';
  958. if ($_GET["order"][0]["column"] == 1)
  959. $column = 'number';
  960. if ($_GET["order"][0]["column"] == 2)
  961. $column = 'last_name';
  962. if ($_GET["order"][0]["column"] == 3)
  963. $column = 'first_name';
  964. if ($_GET["order"][0]["column"] == 4)
  965. $column = 'status';
  966. if ($_GET["order"][0]["column"] == 5)
  967. $column = 'date';
  968. if ($column != '')
  969. $x = $x->orderBy($column, $_GET["order"][0]["dir"])->orderBy('id', 'DESC');
  970. else
  971. $x = $x->orderBy('id', 'DESC');
  972. }
  973. else
  974. $x = $x->orderBy('id', 'DESC');
  975. if (isset($_GET["start"]))
  976. $x = $x->offset($_GET["start"])->limit($_GET["length"])->get();
  977. else
  978. $x = $x->get();
  979. $datas = [];
  980. foreach($x as $idx => $r)
  981. {
  982. $datas[] = array(
  983. 'year' => $r->year,
  984. 'number' => $r->number,
  985. 'last_name' => $r->member->last_name,
  986. 'first_name' => $r->member->first_name,
  987. 'status' => $r->status,
  988. 'date' => date("d/m/Y", strtotime($r->date)),
  989. 'totals' => formatPrice($r->rows->sum('amount')),
  990. 'action' => $r->id
  991. );
  992. }
  993. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  994. });
  995. function getColor($months, $m)
  996. {
  997. $class = "grey";
  998. foreach(json_decode($months) as $mm)
  999. {
  1000. if ($mm->m == $m)
  1001. {
  1002. if ($mm->status == "")
  1003. {
  1004. $class = "orange";
  1005. }
  1006. if ($mm->status == "1")
  1007. {
  1008. $class = "green";
  1009. }
  1010. if ($mm->status == "2")
  1011. {
  1012. $class = "yellow";
  1013. }
  1014. }
  1015. }
  1016. return $class;
  1017. }
  1018. Route::get('/migrate', function(){
  1019. \Artisan::call('migrate');
  1020. dd('migrated!');
  1021. });
  1022. Route::get('/updateData', function()
  1023. {
  1024. // Call and Artisan command from within your application.
  1025. Artisan::call('update:data');
  1026. });
  1027. Route::get('/seed', function()
  1028. {
  1029. // Call and Artisan command from within your application.
  1030. Artisan::call('db:seed');
  1031. });