web.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  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. $hasFilter = false;
  503. $x = \App\Models\Record::where('type', 'OUT')->with('supplier', 'payment_method');
  504. if ($_GET["filterSupplier"] > 0)
  505. {
  506. $x = $x->where('supplier_id', $_GET["filterSupplier"]);
  507. $hasFilter = true;
  508. }
  509. /*if ($_GET["filterPaymentMethod"] > 0)
  510. {
  511. $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]);
  512. }
  513. if ($_GET["filterCausals"] > 0)
  514. {
  515. $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  516. $x = $x->whereIn('records.id', $causals);
  517. }*/
  518. if ($_GET["filterPaymentMethod"] != "null")
  519. {
  520. $payments = explode(",", $_GET["filterPaymentMethod"]);
  521. $x = $x->whereIn('payment_method_id', $payments);
  522. $hasFilter = true;
  523. }
  524. if ($_GET["filterCausals"] != "null")
  525. {
  526. $causals = explode(",", $_GET["filterCausals"]);
  527. //$causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  528. $causals = \App\Models\RecordRow::whereIn('causal_id', $causals)->pluck('record_id');
  529. $x = $x->whereIn('records.id', $causals);
  530. $hasFilter = true;
  531. }
  532. if ($_GET["filterFrom"] != '')
  533. {
  534. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  535. $hasFilter = true;
  536. }
  537. if ($_GET["filterTo"] != '')
  538. {
  539. $x = $x->where('date', '<=', $_GET["filterTo"]);
  540. $hasFilter = true;
  541. }
  542. $total = 0;
  543. foreach($x->get() as $r)
  544. {
  545. foreach($r->rows as $rr)
  546. {
  547. $total += $rr->amount;
  548. if ($rr->vat_id > 0)
  549. $total += getVatValue($rr->amount, $rr->vat_id);
  550. }
  551. }
  552. $x = $x->get();
  553. foreach($x as $idx => $r)
  554. {
  555. $causals = '';
  556. foreach($r->rows as $row)
  557. {
  558. $causals .= $row->causal->getTree() . "<br>";
  559. }
  560. $datas[] = array(
  561. //'id' => $r->id,
  562. 'date' => $r->date,
  563. 'total' => formatPrice($r->getTotal()),
  564. 'supplier' => $r->supplier->name,
  565. 'causals' => $causals,
  566. 'payment' => $r->payment_method->name,
  567. 'action' => $r->id . "|"
  568. );
  569. }
  570. /*
  571. $datas[] = array(
  572. //'id' => $r->id,
  573. 'date' => '',
  574. 'total' => formatPrice($total),
  575. 'supplier' => '',
  576. 'causals' => '',
  577. 'payment' => '',
  578. 'action' => ''
  579. );
  580. */
  581. if ($hasFilter)
  582. return json_encode(array("data" => $datas, "totals" => formatPrice($total)));
  583. else
  584. return json_encode(array("data" => $datas));
  585. });
  586. Route::get('/get_course_list', function(){
  587. $member_course = \App\Models\MemberCourse::with('member');
  588. if (isset($_GET["search"]["value"]))
  589. {
  590. if ($_GET["search"]["value"] != '')
  591. {
  592. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  593. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  594. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  595. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  596. })->pluck('id');
  597. /*
  598. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  599. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  600. $query->where('first_name', 'like', '%' . $v . '%')
  601. ->orWhere('last_name', 'like', '%' . $v . '%');
  602. })->pluck('id');*/
  603. $member_course = $member_course->whereIn('member_id', $member_ids);
  604. }
  605. }
  606. if ($_GET["filterCourse"] != "null")
  607. {
  608. $course_ids = [];
  609. $courses = explode(",", $_GET["filterCourse"]);
  610. foreach($courses as $c)
  611. {
  612. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  613. foreach($all as $a)
  614. {
  615. $course_ids[] = $a->id;
  616. }
  617. }
  618. $member_course = $member_course->whereIn('course_id', $course_ids);
  619. }
  620. if ($_GET["filterYear"] != "")
  621. {
  622. $course_ids = \App\Models\Course::where('year', $_GET["filterYear"])->pluck('id');
  623. $member_course = $member_course->whereIn('course_id', $course_ids);
  624. }
  625. if ($_GET["filterLevel"] != "null")
  626. {
  627. $levels = explode(",", $_GET["filterLevel"]);
  628. $course_ids = \App\Models\Course::whereIn('course_level_id', $levels)->pluck('id');
  629. $member_course = $member_course->whereIn('course_id', $course_ids);
  630. }
  631. if ($_GET["filterFrequency"] != "null")
  632. {
  633. $frequencies = explode(",", $_GET["filterFrequency"]);
  634. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $frequencies)->pluck('id');
  635. $member_course = $member_course->whereIn('course_id', $course_ids);
  636. }
  637. if ($_GET["filterType"] != "null")
  638. {
  639. $types = explode(",", $_GET["filterType"]);
  640. $course_ids = \App\Models\Course::whereIn('course_type_id', $types)->pluck('id');
  641. $member_course = $member_course->whereIn('course_id', $course_ids);
  642. }
  643. if ($_GET["filterDuration"] != "null")
  644. {
  645. $durations = explode(",", $_GET["filterDuration"]);
  646. $course_ids = \App\Models\Course::whereIn('course_duration_id', $durations)->pluck('id');
  647. $member_course = $member_course->whereIn('course_id', $course_ids);
  648. }
  649. $totals = [];
  650. $totalIsc = [];
  651. $datas = [];
  652. $xxx = 1;
  653. $member_course_totals = $member_course->get();
  654. foreach($member_course_totals as $x)
  655. {
  656. $price = 0;
  657. $price = $x->price; // $x->course->price;
  658. $subPrice = $x->subscription_price; // $x->course->subscription_price;
  659. $records = \App\Models\Record::where('member_course_id', $x->id)->where('deleted', 0)->get();
  660. $prices = [];
  661. foreach ($records as $record)
  662. {
  663. foreach ($record->rows as $row)
  664. {
  665. if ($row->causal_id == $x->course->sub_causal_id) // || str_contains(strtolower($row->note), 'iscrizione'))
  666. //if (str_contains(strtolower($row->note), 'iscrizione'))
  667. {
  668. $subPrice = $row->amount;
  669. }
  670. if ($row->causal_id == $x->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
  671. {
  672. $tot = sizeof(json_decode($row->when));
  673. foreach(json_decode($row->when) as $m)
  674. {
  675. $prices[$m->month] = $row->amount / $tot;
  676. }
  677. }
  678. }
  679. }
  680. for($i=1; $i<=12; $i++)
  681. {
  682. $cls = getColor($x->months, $i);
  683. if ($cls != 'wgrey')
  684. {
  685. if (!isset($totals[$i]))
  686. {
  687. $totals[$i]['green'] = 0;
  688. $totals[$i]['orange'] = 0;
  689. $totals[$i]['yellow'] = 0;
  690. }
  691. if ($cls == 'yellow')
  692. {
  693. $totals[$i][$cls] += 1;
  694. }
  695. else
  696. {
  697. $p = isset($prices[$i]) ? $prices[$i] : $price;
  698. $totals[$i][$cls] += $p;
  699. }
  700. }
  701. }
  702. $sub = $x->subscribed ? "Y" : "N";
  703. if (isset($totalIsc[$sub]))
  704. $totalIsc[$sub] += $subPrice;
  705. else
  706. $totalIsc[$sub] = $subPrice;
  707. $datas[] = array(
  708. "column_0" => $x->member->last_name,
  709. "column_1" => $x->member->first_name,
  710. "column_2" => $x->subscribed . "§" . formatPrice($subPrice),
  711. "column_3" => getColor($x->months, 9) . "§" . formatPrice(isset($prices[9]) ? $prices[9] : $price),
  712. "column_4" => getColor($x->months, 10) . "§" . formatPrice(isset($prices[10]) ? $prices[10] : $price),
  713. "column_5" => getColor($x->months, 11) . "§" . formatPrice(isset($prices[11]) ? $prices[11] : $price),
  714. "column_6" => getColor($x->months, 12) . "§" . formatPrice(isset($prices[12]) ? $prices[12] : $price),
  715. "column_7" => getColor($x->months, 1) . "§" . formatPrice(isset($prices[1]) ? $prices[1] : $price),
  716. "column_8" => getColor($x->months, 2) . "§" . formatPrice(isset($prices[2]) ? $prices[2] : $price),
  717. "column_9" => getColor($x->months, 3) . "§" . formatPrice(isset($prices[3]) ? $prices[3] : $price),
  718. "column_10" => getColor($x->months, 4) . "§" . formatPrice(isset($prices[4]) ? $prices[4] : $price),
  719. "column_11" => getColor($x->months, 5) . "§" . formatPrice(isset($prices[5]) ? $prices[5] : $price),
  720. "column_12" => getColor($x->months, 6) . "§" . formatPrice(isset($prices[6]) ? $prices[6] : $price),
  721. "column_13" => getColor($x->months, 7) . "§" . formatPrice(isset($prices[7]) ? $prices[7] : $price),
  722. "column_14" => getColor($x->months, 8) . "§" . formatPrice(isset($prices[8]) ? $prices[8] : $price),
  723. "column_15" => $x->course_id,
  724. "column_16" => $x->id,
  725. "column_17" => $x->member_id,
  726. "column_18" => $xxx++
  727. );
  728. }
  729. $count = $member_course->count();
  730. $js = '';
  731. $xx = 3;
  732. $str = '';
  733. if ($count > 0)
  734. {
  735. $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>";
  736. $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>";
  737. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=yellow><small>0</small></a><br>";
  738. }
  739. $js .= $xx . "§" . $str . "_";
  740. $str = "";
  741. foreach($totals as $z => $t)
  742. {
  743. if ($z == 1) $xx = 8;
  744. if ($z == 2) $xx = 9;
  745. if ($z == 3) $xx = 10;
  746. if ($z == 4) $xx = 11;
  747. if ($z == 5) $xx = 12;
  748. if ($z == 6) $xx = 13;
  749. if ($z == 7) $xx = 14;
  750. if ($z == 8) $xx = 15;
  751. if ($z == 9) $xx = 4;
  752. if ($z == 10) $xx = 5;
  753. if ($z == 11) $xx = 6;
  754. if ($z == 12) $xx = 7;
  755. $str = '';
  756. foreach($t as $x => $c)
  757. {
  758. $y = $x == 'yellow' ? $c : formatPrice($c);
  759. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=" . $x . "><small>" . $y . "</small></a><br>";
  760. }
  761. $js .= $xx . "§" . $str . "_";
  762. $xx += 1;
  763. }
  764. if (isset($_GET["order"]))
  765. 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);
  766. $xxx = 1;
  767. foreach($datas as $yyy => $d)
  768. {
  769. $datas[$yyy]["column_18"] = $xxx++;
  770. }
  771. if (isset($_GET["start"]))
  772. $datas = array_slice($datas, $_GET["start"], $_GET["length"]);
  773. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count, "totals" => $js));
  774. });
  775. Route::get('/get_course_members', function(){
  776. //$datas = \App\Models\MemberCourse::with('member');
  777. $datas = \App\Models\MemberCourse::select('member_courses.*', 'courses.name as course_name', 'members.first_name', 'members.last_name', 'members.email', 'members.phone', 'members.birth_date')
  778. ->leftJoin('courses', 'member_courses.course_id', '=', 'courses.id')
  779. ->leftJoin('members', 'member_courses.member_id', '=', 'members.id');
  780. if (isset($_GET["search"]["value"]))
  781. {
  782. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  783. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  784. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  785. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  786. })->pluck('id');
  787. /*$member_ids = \App\Models\Member::where(function ($query) use ($v) {
  788. $query->where('first_name', 'like', '%' . $v . '%')
  789. ->orWhere('last_name', 'like', '%' . $v . '%');
  790. })->pluck('id');*/
  791. $datas = $datas->whereIn('member_id', $member_ids);
  792. }
  793. if ($_GET["filterCourse"] != "null")
  794. {
  795. $course_ids = [];
  796. $courses = explode(",", $_GET["filterCourse"]);
  797. foreach($courses as $c)
  798. {
  799. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  800. foreach($all as $a)
  801. {
  802. $course_ids[] = $a->id;
  803. }
  804. }
  805. $datas = $datas->whereIn('course_id', $course_ids);
  806. }
  807. if ($_GET["filterLevel"] != "null")
  808. {
  809. $levels = explode(",", $_GET["filterLevel"]);
  810. $course_ids = \App\Models\Course::whereIn('course_level_id', $levels)->pluck('id');
  811. $datas = $datas->whereIn('course_id', $course_ids);
  812. }
  813. if ($_GET["filterFrequency"] != "null")
  814. {
  815. $frequencies = explode(",", $_GET["filterFrequency"]);
  816. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $frequencies)->pluck('id');
  817. $datas = $datas->whereIn('course_id', $course_ids);
  818. }
  819. if ($_GET["filterType"] != "null")
  820. {
  821. $types = explode(",", $_GET["filterType"]);
  822. $course_ids = \App\Models\Course::whereIn('course_type_id', $types)->pluck('id');
  823. $datas = $datas->whereIn('course_id', $course_ids);
  824. }
  825. if ($_GET["filterDuration"] != "null")
  826. {
  827. $durations = explode(",", $_GET["filterDuration"]);
  828. $course_ids = \App\Models\Course::whereIn('course_duration_id', $durations)->pluck('id');
  829. $datas = $datas->whereIn('course_id', $course_ids);
  830. }
  831. if ($_GET["filterDays"] != "null")
  832. {
  833. $ids = [];
  834. $days = explode(",", $_GET["filterDays"]);
  835. foreach($days as $d)
  836. {
  837. $all = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->get();
  838. foreach($all as $a)
  839. {
  840. $ids[] = $a->id;
  841. }
  842. }
  843. $datas = $datas->whereIn('member_courses.id', $ids);
  844. }
  845. if ($_GET["filterHours"] != "null")
  846. {
  847. $ids = [];
  848. $hours = explode(",", $_GET["filterHours"]);
  849. foreach($hours as $h)
  850. {
  851. $all = \App\Models\MemberCourse::where('when', 'like', '%"from":"' . $h . "%")->get();
  852. foreach($all as $a)
  853. {
  854. $ids[] = $a->id;
  855. }
  856. }
  857. $datas = $datas->whereIn('member_courses.id', $ids);
  858. }
  859. if ($_GET["filterSubscription"] != "")
  860. {
  861. $ids = \App\Models\MemberCourse::where('subscribed', $_GET["filterSubscription"] == 1 ? true : false)->pluck('id');
  862. $datas = $datas->whereIn('member_courses.id', $ids);
  863. //$this->filter .= $this->filter != '' ? ', ' : '';
  864. //$this->filter .= "Pagata sottoscrizione : " . ($this->filterSubscription == 1 ? "SI" : "NO") . " ";
  865. }
  866. if ($_GET["filterCertificateType"] != "null")
  867. {
  868. $ctypes = \App\Models\MemberCertificate::where('type', $_GET["filterCertificateType"])->where('expire_date', '>', date("Y-m-d"))->pluck('member_id');
  869. $datas = $datas->whereIn('member_id', $ctypes);
  870. }
  871. if ($_GET["filterCertificateScadenza"] != "null")
  872. {
  873. if ($_GET["filterCertificateScadenza"] == "1")
  874. $scad = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  875. if ($_GET["filterCertificateScadenza"] == "2")
  876. $scad = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  877. $datas = $datas->whereIn('member_id', $scad);
  878. }
  879. if ($_GET["fromYear"] != "")
  880. {
  881. $m_ids = \App\Models\Member::where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time())))->pluck('id');
  882. $datas = $datas->whereIn('member_id', $m_ids);
  883. }
  884. if ($_GET["toYear"] != "")
  885. {
  886. $m_ids = \App\Models\Member::where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())))->pluck('id');
  887. $datas = $datas->whereIn('member_id', $m_ids);
  888. }
  889. if ($_GET["fromFromYear"] != "")
  890. {
  891. $m_ids = \App\Models\Member::whereYear('birth_date', '>=', $_GET["fromFromYear"])->pluck('id');
  892. $datas = $datas->whereIn('member_id', $m_ids);
  893. }
  894. if ($_GET["toToYear"] != "")
  895. {
  896. $m_ids = \App\Models\Member::whereYear('birth_date', '<=', $_GET["toToYear"])->pluck('id');
  897. $datas = $datas->whereIn('member_id', $m_ids);
  898. }
  899. if ($_GET["filterCards"] != "null")
  900. {
  901. $cards = explode(",", $_GET["filterCards"]);
  902. $card_ids = \App\Models\MemberCard::whereIn('card_id', $cards)->pluck('member_id');
  903. $datas = $datas->whereIn('member_id', $card_ids);
  904. }
  905. if ($_GET["filterYear"] != "")
  906. {
  907. $course_ids = \App\Models\Course::where('year', $_GET["filterYear"])->pluck('id');
  908. $datas = $datas->whereIn('course_id', $course_ids);
  909. //$this->filter .= $this->filter != '' ? ', ' : '';
  910. //$this->filter .= "Anno : " . $this->filterYear . " ";
  911. }
  912. $aRet = [];
  913. if (isset($_GET["order"]))
  914. {
  915. $column = '';
  916. if ($_GET["order"][0]["column"] == 1)
  917. $column = 'course_name';
  918. if ($_GET["order"][0]["column"] == 2)
  919. $column = 'last_name';
  920. if ($_GET["order"][0]["column"] == 3)
  921. $column = 'first_name';
  922. if ($_GET["order"][0]["column"] == 4)
  923. $column = 'birth_date';
  924. if ($_GET["order"][0]["column"] == 5)
  925. $column = 'birth_date';
  926. if ($_GET["order"][0]["column"] == 6)
  927. $column = 'birth_date';
  928. if ($_GET["order"][0]["column"] == 7)
  929. $column = 'phone';
  930. if ($_GET["order"][0]["column"] == 8)
  931. $column = 'email';
  932. if ($column != '')
  933. $datas = $datas->orderBy($column, $_GET["order"][0]["dir"]);
  934. else
  935. $datas = $datas->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  936. }
  937. else
  938. $datas = $datas->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  939. if ($_GET["filterStatus"] != "null")
  940. {
  941. $status = explode(",", $_GET["filterStatus"]);
  942. foreach($status as $s)
  943. {
  944. foreach($datas->get() as $aaa)
  945. {
  946. $state = \App\Models\Member::findOrFail($aaa->member_id)->isActive();
  947. if ($state["status"] == $s)
  948. $aRet[] = $aaa;
  949. }
  950. }
  951. }
  952. else
  953. $aRet = $datas->get();
  954. $ret = [];
  955. foreach($aRet as $idx => $r)
  956. {
  957. $date1 = new DateTime($r->birth_date);
  958. $date2 = new DateTime("now");
  959. $interval = $date1->diff($date2);
  960. $ret[] = array(
  961. "column_0" => $idx + 1,
  962. "column_8" => $r->course_name,
  963. "column_1" => $r->last_name,
  964. "column_2" => $r->first_name,
  965. "column_3" => strval($interval->y),
  966. "column_4" => date("Y", strtotime($r->birth_date)),
  967. "column_5" => $r->phone,
  968. "column_6" => $r->email,
  969. "column_7" => $r->member_id
  970. );
  971. }
  972. if (isset($_GET["start"]))
  973. $ret = array_slice($ret, $_GET["start"], $_GET["length"]);
  974. return json_encode(array("data" => $ret, "recordsTotal" => sizeof($aRet), "recordsFiltered" => sizeof($aRet)));
  975. });
  976. Route::get('/get_receipts', function(){
  977. $x = \App\Models\Receipt::select('receipts.*', 'members.first_name', 'members.last_name')->leftJoin('members', 'receipts.member_id', '=', 'members.id');
  978. if (isset($_GET["search"]["value"]))
  979. {
  980. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  981. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  982. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  983. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  984. })->pluck('id');
  985. /*$member_ids = \App\Models\Member::where(function ($query) use ($v) {
  986. $query->where('first_name', 'like', '%' . $v . '%')
  987. ->orWhere('last_name', 'like', '%' . $v . '%');
  988. })->pluck('id');*/
  989. $x = $x->whereIn('member_id', $member_ids);
  990. }
  991. if ($_GET["filterStatus"] != '')
  992. $x = $x->where('receipts.status', $_GET["filterStatus"]);
  993. if ($_GET["filterFrom"] != "")
  994. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  995. if ($_GET["filterTo"] != "")
  996. $x = $x->where('date', '<=', $_GET["filterTo"]);
  997. $count = $x->count();
  998. if (isset($_GET["order"]))
  999. {
  1000. $column = '';
  1001. if ($_GET["order"][0]["column"] == 0)
  1002. $column = 'year';
  1003. if ($_GET["order"][0]["column"] == 1)
  1004. $column = 'number';
  1005. if ($_GET["order"][0]["column"] == 2)
  1006. $column = 'last_name';
  1007. if ($_GET["order"][0]["column"] == 3)
  1008. $column = 'first_name';
  1009. if ($_GET["order"][0]["column"] == 4)
  1010. $column = 'status';
  1011. if ($_GET["order"][0]["column"] == 5)
  1012. $column = 'date';
  1013. if ($column != '')
  1014. $x = $x->orderBy($column, $_GET["order"][0]["dir"])->orderBy('id', 'DESC');
  1015. else
  1016. $x = $x->orderBy('id', 'DESC');
  1017. }
  1018. else
  1019. $x = $x->orderBy('id', 'DESC');
  1020. if (isset($_GET["start"]))
  1021. $x = $x->offset($_GET["start"])->limit($_GET["length"])->get();
  1022. else
  1023. $x = $x->get();
  1024. $datas = [];
  1025. foreach($x as $idx => $r)
  1026. {
  1027. $ids = $r->id . "|" . $r->record_id;
  1028. $datas[] = array(
  1029. 'year' => $r->year,
  1030. 'number' => $r->number,
  1031. 'last_name' => $r->member->last_name,
  1032. 'first_name' => $r->member->first_name,
  1033. 'status' => $r->status,
  1034. 'date' => date("d/m/Y", strtotime($r->date)),
  1035. 'totals' => formatPrice($r->rows->sum('amount')),
  1036. 'action' => $ids
  1037. );
  1038. }
  1039. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  1040. });
  1041. function getColor($months, $m)
  1042. {
  1043. $class = "wgrey";
  1044. foreach(json_decode($months) as $mm)
  1045. {
  1046. if ($mm->m == $m)
  1047. {
  1048. if ($mm->status == "")
  1049. {
  1050. $class = "orange";
  1051. }
  1052. if ($mm->status == "1")
  1053. {
  1054. $class = "green";
  1055. }
  1056. if ($mm->status == "2")
  1057. {
  1058. $class = "yellow";
  1059. }
  1060. }
  1061. }
  1062. return $class;
  1063. }
  1064. Route::get('/migrate', function(){
  1065. \Artisan::call('migrate');
  1066. dd('migrated!');
  1067. });
  1068. Route::get('/updateData', function()
  1069. {
  1070. // Call and Artisan command from within your application.
  1071. Artisan::call('update:data');
  1072. });
  1073. Route::get('/seed', function()
  1074. {
  1075. // Call and Artisan command from within your application.
  1076. Artisan::call('db:seed');
  1077. });
  1078. Route::get('/updateCourseCausal', function(){
  1079. $member_courses = \App\Models\MemberCourse::all();
  1080. foreach($member_courses as $x)
  1081. {
  1082. $records = \App\Models\Record::where('member_course_id', $x->id)->get();
  1083. foreach ($records as $record)
  1084. {
  1085. foreach ($record->rows as $row)
  1086. {
  1087. //if ($row->causal_id == $x->course->sub_causal_id || str_contains(strtolower($row->note), 'iscrizione'))
  1088. if (str_contains(strtolower($row->note), 'iscrizione'))
  1089. {
  1090. $row->causal_id = $x->course->sub_causal_id;
  1091. $row->save();
  1092. }
  1093. }
  1094. }
  1095. }
  1096. });