web.php 47 KB

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