web.php 45 KB

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