web.php 44 KB

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