web.php 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567
  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. $categories = [];
  164. $cats = explode(",", $_GET["filterCategories"]);
  165. // Per ogni causale, se ha dei figli allora aggiungo le causali figlio
  166. foreach($cats as $c)
  167. {
  168. $categories[] = $c;
  169. $childs = \App\Models\Category::where('parent_id', $c)->get();
  170. foreach($childs as $_cc)
  171. {
  172. $categories[] = $_cc->id;
  173. $childss = \App\Models\Category::where('parent_id', $_cc->id)->get();
  174. foreach($childss as $ccc)
  175. {
  176. $categories[] = $ccc->id;
  177. }
  178. }
  179. }
  180. $cc = array();
  181. foreach($categories as $c)
  182. {
  183. $m_ids = \App\Models\MemberCategory::where('category_id', $c)->pluck('member_id')->toArray();
  184. /*if (sizeof($cc) > 0)
  185. $cc = array_intersect($cc, $m_ids);
  186. else
  187. $cc = $m_ids;
  188. */
  189. $cc = array_merge($cc, $m_ids);
  190. }
  191. $x = $x->whereIn('id', $cc);
  192. //$cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["filterCategories"]))->pluck('member_id');
  193. //$x = $x->whereIn('id', $cats_ids);
  194. }
  195. if ($_GET["fromYear"] != "")
  196. {
  197. $x = $x->where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time())));
  198. }
  199. if ($_GET["toYear"] != "")
  200. {
  201. $x = $x->where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())));
  202. }
  203. if ($_GET["fromYearYear"] != "")
  204. {
  205. $x = $x->whereYear('birth_date', '>=', $_GET["fromYearYear"]);
  206. }
  207. if ($_GET["toYearYear"] != "")
  208. {
  209. $x = $x->whereYear('birth_date', '<=', $_GET["toYearYear"]);
  210. }
  211. $ids = [];
  212. if ($_GET["filterCertificateType"] != "null")
  213. {
  214. $types = \App\Models\MemberCertificate::where('type', $_GET["filterCertificateType"])->where('expire_date', '>', date("Y-m-d"))->pluck('member_id');
  215. $x = $x->whereIn('id', $types->toArray());;
  216. //$ids = array_merge($ids, $types->toArray());
  217. }
  218. if ($_GET["filterScadenza"] != "null")
  219. {
  220. if ($_GET["filterScadenza"] == "1")
  221. $scad = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  222. if ($_GET["filterScadenza"] == "2")
  223. $scad = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  224. //$ids = array_merge($ids, $scad->toArray());
  225. $x = $x->whereIn('id', $scad->toArray());;
  226. //$x = $x->whereIn('id', $scadenza);
  227. }
  228. if ($_GET["filterStatus"] != "null")
  229. {
  230. $status = explode(",", $_GET["filterStatus"]);
  231. $members = \App\Models\Member::all();
  232. foreach($status as $s)
  233. {
  234. foreach($members as $m)
  235. {
  236. $state = $m->isActive();
  237. if ($state["status"] == $s)
  238. $ids[] = $m->id;
  239. }
  240. }
  241. }
  242. if (sizeof($ids) > 0)
  243. {
  244. $x = $x->whereIn('id', $ids);
  245. }
  246. else
  247. {
  248. if ($_GET["filterStatus"] != "null")
  249. $x = $x->whereIn('id', [-1]);
  250. }
  251. $count = $x->count();
  252. $x = $x->orderBy('to_complete', 'DESC');
  253. if (isset($_GET["order"]))
  254. {
  255. $column = '';
  256. if ($_GET["order"][0]["column"] == 0)
  257. $column = 'last_name';
  258. if ($_GET["order"][0]["column"] == 1)
  259. $column = 'first_name';
  260. if ($_GET["order"][0]["column"] == 2)
  261. $column = 'phone';
  262. if ($_GET["order"][0]["column"] == 3)
  263. $column = 'birth_date';
  264. if ($_GET["order"][0]["column"] == 4)
  265. $column = 'birth_date';
  266. if ($_GET["order"][0]["column"] == 5)
  267. $column = 'current_status';
  268. if ($_GET["order"][0]["column"] == 6)
  269. $column = 'certificate';
  270. if ($column != '')
  271. {
  272. $x = $x->orderBy($column, $_GET["order"][0]["dir"]);
  273. if ($column == 'certificate')
  274. $x = $x->orderBy('certificate_date', $_GET["order"][0]["dir"]);
  275. }
  276. else
  277. $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  278. }
  279. else
  280. $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  281. if (isset($_GET["start"]))
  282. $x = $x->offset($_GET["start"])->limit($_GET["length"])->get();
  283. else
  284. $x = $x->get();
  285. foreach($x as $idx => $r)
  286. {
  287. // $status = $r->getStatus();
  288. // $status = $status["status"];
  289. $status = $r->current_status;
  290. $class = $status > 0 ? ($status == 2 ? 'active' : 'due') : 'suspended';
  291. $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
  292. if ($r->to_complete)
  293. {
  294. $text = 'Da completare';
  295. $class = "complete";
  296. }
  297. // $has_certificate = $r->hasCertificate();
  298. $y = '';
  299. if ($r->certificate_date != '')
  300. {
  301. $y = $r->certificate . "|" . date("d/m/Y", strtotime($r->certificate_date));
  302. }
  303. /*
  304. if($has_certificate["date"] != '')
  305. {
  306. if($has_certificate["date"] < date("Y-m-d"))
  307. $y .= '0';
  308. if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
  309. $y .= '1';
  310. if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
  311. $y .= '2';
  312. $y .= '|';
  313. $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : '';
  314. }*/
  315. $datas[] = array(
  316. //'c' => $idx + 1,
  317. //'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
  318. 'last_name' => $r->last_name . "|" . $r->id,
  319. 'first_name' => $r->first_name . "|" . $r->id,
  320. 'phone' => $r->phone,
  321. 'age' => $r->getAge(),
  322. 'year' => date("Y", strtotime($r->birth_date)),
  323. 'status' => $class . "|" . $text,
  324. // 'state' => $x,
  325. 'certificate' => $y,
  326. 'action' => $r->id
  327. );
  328. }
  329. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  330. });
  331. Route::get('/get_record_in', function(){
  332. $datas = [];
  333. $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('receipts.created_at as receipt_date')) // , \DB::raw('SUM(records.id) As total'))
  334. ->leftJoin('members', 'records.member_id', '=', 'members.id')
  335. ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
  336. ->leftJoin('receipts', 'records.id', '=', 'receipts.record_id')
  337. ->where('records.type', 'IN');
  338. $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'))
  339. ->leftJoin('members', 'records.member_id', '=', 'members.id')
  340. ->leftJoin('records_rows', 'records.id', '=', 'records_rows.record_id')
  341. //->leftJoin('receipts', 'records.id', '=', 'receipts.record_id')
  342. ->where('records.type', 'IN');
  343. $hasFilter = false;
  344. if (isset($_GET["search"]["value"]))
  345. {
  346. if ($_GET["search"]["value"] != '')
  347. {
  348. $hasFilter = true;
  349. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  350. $x = $x->where(function ($query) use ($v) {
  351. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  352. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  353. });
  354. $y = $y->where(function ($query) use ($v) {
  355. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  356. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  357. });
  358. }
  359. /*$v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  360. $x = $x->where(function ($query) use ($v) {
  361. $query->where('first_name', 'like', '%' . $v . '%')
  362. ->orWhere('last_name', 'like', '%' . $v . '%');
  363. });
  364. $y = $y->where(function ($query) use ($v) {
  365. $query->where('first_name', 'like', '%' . $v . '%')
  366. ->orWhere('last_name', 'like', '%' . $v . '%');
  367. });
  368. }*/
  369. //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
  370. }
  371. //$x = $x->where(function ($query) use ($v) {
  372. // $datas = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method');
  373. if ($_GET["filterCommercial"] == 1)
  374. {
  375. $hasFilter = true;
  376. $x = $x->where('records.commercial', true );
  377. $y = $y->where('records.commercial', true );
  378. }
  379. if ($_GET["filterCommercial"] == 2)
  380. {
  381. $hasFilter = true;
  382. $x = $x->where('records.commercial', false);
  383. $y = $y->where('records.commercial', false);
  384. }
  385. if ($_GET["filterMember"] > 0)
  386. {
  387. $hasFilter = true;
  388. $x = $x->where('records.member_id', $_GET["filterMember"]);
  389. $y = $y->where('records.member_id', $_GET["filterMember"]);
  390. }
  391. if ($_GET["filterPaymentMethod"] != "null")
  392. {
  393. $hasFilter = true;
  394. $payments = explode(",", $_GET["filterPaymentMethod"]);
  395. $x = $x->whereIn('records.payment_method_id', $payments);
  396. $y = $y->whereIn('records.payment_method_id', $payments);
  397. }
  398. if ($_GET["filterCausals"] != "null")
  399. {
  400. $hasFilter = true;
  401. $causals = explode(",", $_GET["filterCausals"]);
  402. // Per ogni causale, se ha dei figli allora aggiungo le causali figlio
  403. foreach($causals as $c)
  404. {
  405. $childs = \App\Models\Causal::where('parent_id', $c)->get();
  406. foreach($childs as $cc)
  407. {
  408. $causals[] = $cc->id;
  409. $childss = \App\Models\Causal::where('parent_id', $cc->id)->get();
  410. foreach($childss as $ccc)
  411. {
  412. $causals[] = $ccc->id;
  413. }
  414. }
  415. }
  416. //$causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  417. $causals = \App\Models\RecordRow::whereIn('causal_id', $causals)->pluck('record_id');
  418. $x = $x->whereIn('records.id', $causals);
  419. $y = $y->whereIn('records.id', $causals);
  420. }
  421. if ($_GET["filterFrom"] != '')
  422. {
  423. $hasFilter = true;
  424. $x = $x->where('records.date', '>=', $_GET["filterFrom"]);
  425. $y = $y->where('date', '>=', $_GET["filterFrom"]);
  426. }
  427. if ($_GET["filterTo"] != '')
  428. {
  429. $hasFilter = true;
  430. $x = $x->where('records.date', '<=', $_GET["filterTo"]);
  431. $y = $y->where('date', '<=', $_GET["filterTo"]);
  432. }
  433. //});
  434. $start = 0;
  435. $limit = 100000;
  436. if (isset($_GET["start"]))
  437. {
  438. $start = $_GET["start"];
  439. $limit = $_GET["length"];
  440. }
  441. $excludeCausals = [];
  442. /*$borsellino = \App\Models\Causal::where('money', true)->first();
  443. if ($borsellino)
  444. $excludeCausals[] = $borsellino->id;*/
  445. // Aggiungo
  446. $excludes = \App\Models\Causal::where('no_records', true)->get();
  447. foreach($excludes as $e)
  448. {
  449. $excludeCausals[] = $e->id;
  450. }
  451. $exclude_from_records = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
  452. // Pagamento money
  453. $moneys = \App\Models\PaymentMethod::where('money', true)->pluck('id')->toArray();
  454. // Causale money
  455. $moneysCausal = \App\Models\Causal::where('money', true)->pluck('id')->toArray();
  456. $total = 0;
  457. $causals = [];
  458. if ($_GET["filterCausals"] != "null")
  459. $causals = explode(",", $_GET["filterCausals"]);
  460. foreach($y->get() as $r)
  461. {
  462. if (!in_array($r->payment_method_id, $moneys))
  463. {
  464. 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))
  465. {
  466. if (sizeof($causals) == 0 || in_array($r->causal_id, $causals))
  467. {
  468. $total += $r->amount;
  469. if ($r->vat_id > 0)
  470. $total += getVatValue($r->amount, $r->vat_id);
  471. }
  472. }
  473. }
  474. }
  475. $count = $x->count();
  476. if (isset($_GET["order"]))
  477. {
  478. $column = '';
  479. if ($_GET["order"][0]["column"] == 0)
  480. $column = 'date';
  481. if ($_GET["order"][0]["column"] == 1)
  482. $column = 'records.amount';
  483. if ($_GET["order"][0]["column"] == 2)
  484. $column = 'last_name';
  485. if ($_GET["order"][0]["column"] == 3)
  486. $column = 'first_name';
  487. if ($_GET["order"][0]["column"] == 4)
  488. $column = 'commercial';
  489. if ($column != '')
  490. $x = $x->orderBy($column, $_GET["order"][0]["dir"])->orderBy('records.id', 'DESC');
  491. else
  492. $x = $x->orderBy('records.id', 'DESC');
  493. }
  494. else
  495. $x = $x->orderBy('records.date', 'DESC')->orderBy('records.id', 'DESC');
  496. $x = $x->offset($start)->limit($limit)->get();
  497. foreach($x as $idx => $r)
  498. {
  499. $causals = '';
  500. foreach($r->rows as $row)
  501. {
  502. $causals .= $row->causal->getTree() . "<br>";
  503. }
  504. $datas[] = array(
  505. //'id' => $r->id,
  506. 'date' => $r->date,
  507. //'date' => $r->receipt_date != null ? $r->receipt_date : "",
  508. 'total' => formatPrice($r->getTotal()),
  509. 'first_name' => $r->first_name,
  510. 'last_name' => $r->last_name,
  511. 'commercial' => $r->financial_movement ? 'Movimento finanziario' : ($r->commercial ? 'SI' : 'NO'),
  512. 'causals' => $causals,
  513. 'payment' => $r->payment_method->name,
  514. //'payment_date' => date("d/m/Y", strtotime($r->date)),
  515. 'status' => $r->deleted ? 'Annullato' : '',
  516. 'action' => $r->id . "||" . ($r->deleted ? 'x' : '')
  517. );
  518. }
  519. /*$datas[] = array(
  520. //'id' => $r->id,
  521. 'date' => '',
  522. 'total' => formatPrice($total),
  523. 'first_name' => '',
  524. 'last_name' => '',
  525. 'commercial' => '',
  526. 'causals' => '',
  527. 'payment' => '',
  528. 'status' => '',
  529. 'action' => ''
  530. );*/
  531. if ($hasFilter)
  532. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count, "totals" => formatPrice($total)));
  533. else
  534. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  535. });
  536. Route::get('/get_record_out', function(){
  537. $datas = [];
  538. $hasFilter = false;
  539. $x = \App\Models\Record::where('type', 'OUT')->with('supplier', 'payment_method');
  540. if ($_GET["filterSupplier"] > 0)
  541. {
  542. $x = $x->where('supplier_id', $_GET["filterSupplier"]);
  543. $hasFilter = true;
  544. }
  545. /*if ($_GET["filterPaymentMethod"] > 0)
  546. {
  547. $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]);
  548. }
  549. if ($_GET["filterCausals"] > 0)
  550. {
  551. $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  552. $x = $x->whereIn('records.id', $causals);
  553. }*/
  554. if ($_GET["filterPaymentMethod"] != "null")
  555. {
  556. $payments = explode(",", $_GET["filterPaymentMethod"]);
  557. $x = $x->whereIn('payment_method_id', $payments);
  558. $hasFilter = true;
  559. }
  560. if ($_GET["filterCausals"] != "null")
  561. {
  562. $causals = explode(",", $_GET["filterCausals"]);
  563. // Per ogni causale, se ha dei figli allora aggiungo le causali figlio
  564. foreach($causals as $c)
  565. {
  566. $childs = \App\Models\Causal::where('parent_id', $c)->get();
  567. foreach($childs as $cc)
  568. {
  569. $causals[] = $cc->id;
  570. $childss = \App\Models\Causal::where('parent_id', $cc->id)->get();
  571. foreach($childss as $ccc)
  572. {
  573. $causals[] = $ccc->id;
  574. }
  575. }
  576. }
  577. //$causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  578. $causals = \App\Models\RecordRow::whereIn('causal_id', $causals)->pluck('record_id');
  579. $x = $x->whereIn('records.id', $causals);
  580. $hasFilter = true;
  581. }
  582. if ($_GET["filterFrom"] != '')
  583. {
  584. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  585. $hasFilter = true;
  586. }
  587. if ($_GET["filterTo"] != '')
  588. {
  589. $x = $x->where('date', '<=', $_GET["filterTo"]);
  590. $hasFilter = true;
  591. }
  592. $total = 0;
  593. foreach($x->get() as $r)
  594. {
  595. foreach($r->rows as $rr)
  596. {
  597. $total += $rr->amount;
  598. if ($rr->vat_id > 0)
  599. $total += getVatValue($rr->amount, $rr->vat_id);
  600. }
  601. }
  602. $x = $x->get();
  603. foreach($x as $idx => $r)
  604. {
  605. $causals = '';
  606. foreach($r->rows as $row)
  607. {
  608. $causals .= $row->causal->getTree() . "<br>";
  609. }
  610. $datas[] = array(
  611. //'id' => $r->id,
  612. 'date' => $r->date,
  613. 'total' => formatPrice($r->getTotal()),
  614. 'supplier' => $r->supplier->name,
  615. 'causals' => $causals,
  616. 'payment' => $r->payment_method->name,
  617. 'action' => $r->id . "|"
  618. );
  619. }
  620. /*
  621. $datas[] = array(
  622. //'id' => $r->id,
  623. 'date' => '',
  624. 'total' => formatPrice($total),
  625. 'supplier' => '',
  626. 'causals' => '',
  627. 'payment' => '',
  628. 'action' => ''
  629. );
  630. */
  631. if ($hasFilter)
  632. return json_encode(array("data" => $datas, "totals" => formatPrice($total)));
  633. else
  634. return json_encode(array("data" => $datas));
  635. });
  636. Route::get('/get_course_list', function(){
  637. $member_course = \App\Models\MemberCourse::with('member')->with('course');
  638. if (isset($_GET["search"]["value"]))
  639. {
  640. if ($_GET["search"]["value"] != '')
  641. {
  642. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  643. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  644. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  645. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  646. })->pluck('id');
  647. /*
  648. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  649. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  650. $query->where('first_name', 'like', '%' . $v . '%')
  651. ->orWhere('last_name', 'like', '%' . $v . '%');
  652. })->pluck('id');*/
  653. $member_course = $member_course->whereIn('member_id', $member_ids);
  654. }
  655. }
  656. if ($_GET["filterCourse"] != "null")
  657. {
  658. $course_ids = [];
  659. $courses = explode(",", $_GET["filterCourse"]);
  660. foreach($courses as $c)
  661. {
  662. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  663. foreach($all as $a)
  664. {
  665. $course_ids[] = $a->id;
  666. }
  667. }
  668. $member_course = $member_course->whereIn('course_id', $course_ids);
  669. }
  670. if ($_GET["filterYear"] != "")
  671. {
  672. $course_ids = \App\Models\Course::where('year', $_GET["filterYear"])->pluck('id');
  673. $member_course = $member_course->whereIn('course_id', $course_ids);
  674. }
  675. if ($_GET["filterLevel"] != "null")
  676. {
  677. $levels = explode(",", $_GET["filterLevel"]);
  678. $course_ids = \App\Models\Course::whereIn('course_level_id', $levels)->pluck('id');
  679. $member_course = $member_course->whereIn('course_id', $course_ids);
  680. }
  681. if ($_GET["filterFrequency"] != "null")
  682. {
  683. $frequencies = explode(",", $_GET["filterFrequency"]);
  684. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $frequencies)->pluck('id');
  685. $member_course = $member_course->whereIn('course_id', $course_ids);
  686. }
  687. if ($_GET["filterType"] != "null")
  688. {
  689. $types = explode(",", $_GET["filterType"]);
  690. $course_ids = \App\Models\Course::whereIn('course_type_id', $types)->pluck('id');
  691. $member_course = $member_course->whereIn('course_id', $course_ids);
  692. }
  693. if ($_GET["filterDuration"] != "null")
  694. {
  695. $durations = explode(",", $_GET["filterDuration"]);
  696. $course_ids = \App\Models\Course::whereIn('course_duration_id', $durations)->pluck('id');
  697. $member_course = $member_course->whereIn('course_id', $course_ids);
  698. }
  699. $totals = [];
  700. $totalIsc = [];
  701. $datas = [];
  702. $xxx = 1;
  703. /*
  704. $sortColumn = '';
  705. if (isset($_GET["order"]))
  706. {
  707. }
  708. */
  709. $column = '';
  710. $sort_value = 0;
  711. if (isset($_GET["order"]))
  712. {
  713. $f = $_GET["order"][0]["column"];
  714. $d = $_GET["order"][0]["dir"];
  715. if ($f >= 5 && $f <= 16)
  716. {
  717. $column = 'column_' . ($f - 2);
  718. if (session()->get('sort_column'))
  719. {
  720. if (session()->get('sort_column') != $f)
  721. {
  722. session()->put('sort_column', $f);
  723. session()->put('sort_order', $d);
  724. session()->put('sort_value', 0);
  725. $sort_value = 0;
  726. }
  727. else
  728. {
  729. if (session()->get('sort_order') == $d)
  730. {
  731. //session()->put('sort_value', 0);
  732. $sort_value = session()->get('sort_value', 0);
  733. }
  734. else
  735. {
  736. if (session()->get('sort_value', 0) == 0)
  737. {
  738. $sort_value = 1;
  739. }
  740. if (session()->get('sort_value', 0) == 1)
  741. {
  742. $sort_value = 2;
  743. }
  744. if (session()->get('sort_value', 0) == 2)
  745. {
  746. $sort_value = 3;
  747. }
  748. if (session()->get('sort_value', 0) == 3)
  749. {
  750. $sort_value = 0;
  751. }
  752. session()->put('sort_value', $sort_value);
  753. }
  754. session()->put('sort_order', $d);
  755. }
  756. }
  757. else
  758. {
  759. session()->put('sort_column', $f);
  760. session()->put('sort_order', $d);
  761. session()->put('sort_value', 0);
  762. $sort_value = 0;
  763. }
  764. }
  765. }
  766. //print $sort_value;
  767. $member_course_totals = $member_course->get();
  768. foreach($member_course_totals as $x)
  769. {
  770. $price = 0;
  771. $price = $x->price; // $x->course->price;
  772. $subPrice = $x->subscription_price; // $x->course->subscription_price;
  773. $records = \App\Models\Record::where('member_course_id', $x->id)->where('deleted', 0)->get();
  774. $prices = [];
  775. foreach ($records as $record)
  776. {
  777. foreach ($record->rows as $row)
  778. {
  779. if ($row->causal_id == $x->course->sub_causal_id) // || str_contains(strtolower($row->note), 'iscrizione'))
  780. //if (str_contains(strtolower($row->note), 'iscrizione'))
  781. {
  782. $subPrice = $row->amount;
  783. }
  784. if ($row->causal_id == $x->course->causal_id && !str_contains(strtolower($row->note), 'iscrizione'))
  785. {
  786. $tot = sizeof(json_decode($row->when));
  787. foreach(json_decode($row->when) as $m)
  788. {
  789. $prices[$m->month] = $row->amount / $tot;
  790. }
  791. }
  792. }
  793. }
  794. for($i=1; $i<=12; $i++)
  795. {
  796. $cls = getColor($x->months, $i);
  797. if ($cls != 'wgrey')
  798. {
  799. if (!isset($totals[$i]))
  800. {
  801. $totals[$i]['green'] = 0;
  802. $totals[$i]['orange'] = 0;
  803. $totals[$i]['yellow'] = 0;
  804. }
  805. if ($cls == 'yellow')
  806. {
  807. $totals[$i][$cls] += 1;
  808. }
  809. else
  810. {
  811. $p = isset($prices[$i]) ? $prices[$i] : $price;
  812. $totals[$i][$cls] += $p;
  813. }
  814. }
  815. }
  816. $sub = $x->subscribed ? "Y" : "N";
  817. if (isset($totalIsc[$sub]))
  818. $totalIsc[$sub] += $subPrice;
  819. else
  820. $totalIsc[$sub] = $subPrice;
  821. $s = 0;
  822. if ($column != '')
  823. {
  824. $z = 0;
  825. switch ($column) {
  826. case 'column_3':
  827. $z = 9;
  828. break;
  829. case 'column_4':
  830. $z = 10;
  831. break;
  832. case 'column_5':
  833. $z = 11;
  834. break;
  835. case 'column_6':
  836. $z = 12;
  837. break;
  838. case 'column_7':
  839. $z = 1;
  840. break;
  841. case 'column_8':
  842. $z = 2;
  843. break;
  844. case 'column_9':
  845. $z = 3;
  846. break;
  847. case 'column_10':
  848. $z = 4;
  849. break;
  850. case 'column_11':
  851. $z = 5;
  852. break;
  853. case 'column_12':
  854. $z = 6;
  855. break;
  856. case 'column_13':
  857. $z = 7;
  858. break;
  859. case 'column_14':
  860. $z = 8;
  861. break;
  862. default:
  863. $z = 0;
  864. break;
  865. }
  866. $c = getColor($x->months, $z);
  867. if ($sort_value == 0)
  868. {
  869. switch ($c) {
  870. case 'wgrey':
  871. $s = 0;
  872. break;
  873. case 'orange':
  874. $s = 1;
  875. break;
  876. case 'green':
  877. $s = 2;
  878. break;
  879. case 'yellow':
  880. $s = 3;
  881. break;
  882. default:
  883. $s = 0;
  884. break;
  885. }
  886. }
  887. if ($sort_value == 1)
  888. {
  889. switch ($c) {
  890. case 'wgrey':
  891. $s = 3;
  892. break;
  893. case 'orange':
  894. $s = 0;
  895. break;
  896. case 'green':
  897. $s = 1;
  898. break;
  899. case 'yellow':
  900. $s = 2;
  901. break;
  902. default:
  903. $s = 0;
  904. break;
  905. }
  906. }
  907. if ($sort_value == 2)
  908. {
  909. switch ($c) {
  910. case 'wgrey':
  911. $s = 2;
  912. break;
  913. case 'orange':
  914. $s = 3;
  915. break;
  916. case 'green':
  917. $s = 0;
  918. break;
  919. case 'yellow':
  920. $s = 1;
  921. break;
  922. default:
  923. $s = 0;
  924. break;
  925. }
  926. }
  927. if ($sort_value == 3)
  928. {
  929. switch ($c) {
  930. case 'wgrey':
  931. $s = 1;
  932. break;
  933. case 'orange':
  934. $s = 2;
  935. break;
  936. case 'green':
  937. $s = 3;
  938. break;
  939. case 'yellow':
  940. $s = 0;
  941. break;
  942. default:
  943. $s = 0;
  944. break;
  945. }
  946. }
  947. }
  948. $datas[] = array(
  949. "column_19" => $x->course->name,
  950. "column_0" => $x->member->last_name,
  951. "column_1" => $x->member->first_name,
  952. "column_2" => $x->subscribed . "§" . formatPrice($subPrice),
  953. "column_3" => getColor($x->months, 9) . "§" . formatPrice(isset($prices[9]) ? $prices[9] : $price),
  954. "column_4" => getColor($x->months, 10) . "§" . formatPrice(isset($prices[10]) ? $prices[10] : $price),
  955. "column_5" => getColor($x->months, 11) . "§" . formatPrice(isset($prices[11]) ? $prices[11] : $price),
  956. "column_6" => getColor($x->months, 12) . "§" . formatPrice(isset($prices[12]) ? $prices[12] : $price),
  957. "column_7" => getColor($x->months, 1) . "§" . formatPrice(isset($prices[1]) ? $prices[1] : $price),
  958. "column_8" => getColor($x->months, 2) . "§" . formatPrice(isset($prices[2]) ? $prices[2] : $price),
  959. "column_9" => getColor($x->months, 3) . "§" . formatPrice(isset($prices[3]) ? $prices[3] : $price),
  960. "column_10" => getColor($x->months, 4) . "§" . formatPrice(isset($prices[4]) ? $prices[4] : $price),
  961. "column_11" => getColor($x->months, 5) . "§" . formatPrice(isset($prices[5]) ? $prices[5] : $price),
  962. "column_12" => getColor($x->months, 6) . "§" . formatPrice(isset($prices[6]) ? $prices[6] : $price),
  963. "column_13" => getColor($x->months, 7) . "§" . formatPrice(isset($prices[7]) ? $prices[7] : $price),
  964. "column_14" => getColor($x->months, 8) . "§" . formatPrice(isset($prices[8]) ? $prices[8] : $price),
  965. "column_15" => $x->course_id,
  966. "column_16" => $x->id,
  967. "column_17" => $x->member_id,
  968. "column_18" => $xxx++,
  969. "column_20" => $s
  970. );
  971. }
  972. $count = $member_course->count();
  973. $js = '';
  974. $xx = 4;
  975. $str = '';
  976. if ($count > 0)
  977. {
  978. $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>";
  979. $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>";
  980. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=yellow><small>0</small></a><br>";
  981. }
  982. $js .= $xx . "§" . $str . "_";
  983. $str = "";
  984. foreach($totals as $z => $t)
  985. {
  986. if ($z == 1) $xx = 9;
  987. if ($z == 2) $xx = 10;
  988. if ($z == 3) $xx = 11;
  989. if ($z == 4) $xx = 12;
  990. if ($z == 5) $xx = 13;
  991. if ($z == 6) $xx = 14;
  992. if ($z == 7) $xx = 15;
  993. if ($z == 8) $xx = 16;
  994. if ($z == 9) $xx = 5;
  995. if ($z == 10) $xx = 6;
  996. if ($z == 11) $xx = 7;
  997. if ($z == 12) $xx = 8;
  998. $str = '';
  999. foreach($t as $x => $c)
  1000. {
  1001. $y = $x == 'yellow' ? $c : formatPrice($c);
  1002. $str .= "<a style='width:100%;float:right; text-align:right; display:block;' class=" . $x . "><small>" . $y . "</small></a><br>";
  1003. }
  1004. $js .= $xx . "§" . $str . "_";
  1005. $xx += 1;
  1006. }
  1007. if (isset($_GET["order"]))
  1008. {
  1009. $s = $_GET["order"][0]["column"];
  1010. if ($s == 1) $s = 21;
  1011. if ($column != '')
  1012. array_multisort(array_column($datas, 'column_20'), SORT_ASC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
  1013. else
  1014. array_multisort(array_column($datas, 'column_' . ($s - 2)), $_GET["order"][0]["dir"] == "asc" ? SORT_ASC : SORT_DESC, SORT_NATURAL|SORT_FLAG_CASE, $datas);
  1015. }
  1016. $xxx = 1;
  1017. foreach($datas as $yyy => $d)
  1018. {
  1019. $datas[$yyy]["column_18"] = $xxx++;
  1020. }
  1021. if (isset($_GET["start"]))
  1022. $datas = array_slice($datas, $_GET["start"], $_GET["length"]);
  1023. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count, "totals" => $js));
  1024. });
  1025. Route::get('/get_course_members', function(){
  1026. //$datas = \App\Models\MemberCourse::with('member');
  1027. $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')
  1028. ->leftJoin('courses', 'member_courses.course_id', '=', 'courses.id')
  1029. ->leftJoin('members', 'member_courses.member_id', '=', 'members.id');
  1030. if (isset($_GET["search"]["value"]))
  1031. {
  1032. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  1033. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  1034. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  1035. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  1036. })->pluck('id');
  1037. /*$member_ids = \App\Models\Member::where(function ($query) use ($v) {
  1038. $query->where('first_name', 'like', '%' . $v . '%')
  1039. ->orWhere('last_name', 'like', '%' . $v . '%');
  1040. })->pluck('id');*/
  1041. $datas = $datas->whereIn('member_id', $member_ids);
  1042. }
  1043. if ($_GET["filterCourse"] != "null")
  1044. {
  1045. $course_ids = [];
  1046. $courses = explode(",", $_GET["filterCourse"]);
  1047. foreach($courses as $c)
  1048. {
  1049. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  1050. foreach($all as $a)
  1051. {
  1052. $course_ids[] = $a->id;
  1053. }
  1054. }
  1055. $datas = $datas->whereIn('course_id', $course_ids);
  1056. }
  1057. if ($_GET["filterLevel"] != "null")
  1058. {
  1059. $levels = explode(",", $_GET["filterLevel"]);
  1060. $course_ids = \App\Models\Course::whereIn('course_level_id', $levels)->pluck('id');
  1061. $datas = $datas->whereIn('course_id', $course_ids);
  1062. }
  1063. if ($_GET["filterFrequency"] != "null")
  1064. {
  1065. $frequencies = explode(",", $_GET["filterFrequency"]);
  1066. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $frequencies)->pluck('id');
  1067. $datas = $datas->whereIn('course_id', $course_ids);
  1068. }
  1069. if ($_GET["filterType"] != "null")
  1070. {
  1071. $types = explode(",", $_GET["filterType"]);
  1072. $course_ids = \App\Models\Course::whereIn('course_type_id', $types)->pluck('id');
  1073. $datas = $datas->whereIn('course_id', $course_ids);
  1074. }
  1075. if ($_GET["filterDuration"] != "null")
  1076. {
  1077. $durations = explode(",", $_GET["filterDuration"]);
  1078. $course_ids = \App\Models\Course::whereIn('course_duration_id', $durations)->pluck('id');
  1079. $datas = $datas->whereIn('course_id', $course_ids);
  1080. }
  1081. if ($_GET["filterDays"] != "null")
  1082. {
  1083. $ids = [];
  1084. $days = explode(",", $_GET["filterDays"]);
  1085. foreach($days as $d)
  1086. {
  1087. $all = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->get();
  1088. foreach($all as $a)
  1089. {
  1090. $ids[] = $a->id;
  1091. }
  1092. }
  1093. $datas = $datas->whereIn('member_courses.id', $ids);
  1094. }
  1095. if ($_GET["filterHours"] != "null")
  1096. {
  1097. $ids = [];
  1098. $hours = explode(",", $_GET["filterHours"]);
  1099. foreach($hours as $h)
  1100. {
  1101. $all = \App\Models\MemberCourse::where('when', 'like', '%"from":"' . $h . "%")->get();
  1102. foreach($all as $a)
  1103. {
  1104. $ids[] = $a->id;
  1105. }
  1106. }
  1107. $datas = $datas->whereIn('member_courses.id', $ids);
  1108. }
  1109. if ($_GET["filterSubscription"] != "")
  1110. {
  1111. $ids = \App\Models\MemberCourse::where('subscribed', $_GET["filterSubscription"] == 1 ? true : false)->pluck('id');
  1112. $datas = $datas->whereIn('member_courses.id', $ids);
  1113. //$this->filter .= $this->filter != '' ? ', ' : '';
  1114. //$this->filter .= "Pagata sottoscrizione : " . ($this->filterSubscription == 1 ? "SI" : "NO") . " ";
  1115. }
  1116. if ($_GET["filterCertificateType"] != "null")
  1117. {
  1118. $ctypes = \App\Models\MemberCertificate::where('type', $_GET["filterCertificateType"])->where('expire_date', '>', date("Y-m-d"))->pluck('member_id');
  1119. $datas = $datas->whereIn('member_id', $ctypes);
  1120. }
  1121. if ($_GET["filterCertificateScadenza"] != "null")
  1122. {
  1123. if ($_GET["filterCertificateScadenza"] == "1")
  1124. $scad = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  1125. if ($_GET["filterCertificateScadenza"] == "2")
  1126. $scad = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  1127. $datas = $datas->whereIn('member_id', $scad);
  1128. }
  1129. if ($_GET["fromYear"] != "")
  1130. {
  1131. $m_ids = \App\Models\Member::where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time())))->pluck('id');
  1132. $datas = $datas->whereIn('member_id', $m_ids);
  1133. }
  1134. if ($_GET["toYear"] != "")
  1135. {
  1136. $m_ids = \App\Models\Member::where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())))->pluck('id');
  1137. $datas = $datas->whereIn('member_id', $m_ids);
  1138. }
  1139. if ($_GET["fromFromYear"] != "")
  1140. {
  1141. $m_ids = \App\Models\Member::whereYear('birth_date', '>=', $_GET["fromFromYear"])->pluck('id');
  1142. $datas = $datas->whereIn('member_id', $m_ids);
  1143. }
  1144. if ($_GET["toToYear"] != "")
  1145. {
  1146. $m_ids = \App\Models\Member::whereYear('birth_date', '<=', $_GET["toToYear"])->pluck('id');
  1147. $datas = $datas->whereIn('member_id', $m_ids);
  1148. }
  1149. if ($_GET["filterCards"] != "null")
  1150. {
  1151. $cards = explode(",", $_GET["filterCards"]);
  1152. $card_ids = \App\Models\MemberCard::whereIn('card_id', $cards)->pluck('member_id');
  1153. $datas = $datas->whereIn('member_id', $card_ids);
  1154. }
  1155. if ($_GET["filterYear"] != "")
  1156. {
  1157. $course_ids = \App\Models\Course::where('year', $_GET["filterYear"])->pluck('id');
  1158. $datas = $datas->whereIn('course_id', $course_ids);
  1159. //$this->filter .= $this->filter != '' ? ', ' : '';
  1160. //$this->filter .= "Anno : " . $this->filterYear . " ";
  1161. }
  1162. $aRet = [];
  1163. if (isset($_GET["order"]))
  1164. {
  1165. $column = '';
  1166. if ($_GET["order"][0]["column"] == 1)
  1167. $column = 'course_name';
  1168. if ($_GET["order"][0]["column"] == 2)
  1169. $column = 'last_name';
  1170. if ($_GET["order"][0]["column"] == 3)
  1171. $column = 'first_name';
  1172. if ($_GET["order"][0]["column"] == 4)
  1173. $column = 'birth_date';
  1174. if ($_GET["order"][0]["column"] == 5)
  1175. $column = 'birth_date';
  1176. if ($_GET["order"][0]["column"] == 6)
  1177. $column = 'birth_date';
  1178. if ($_GET["order"][0]["column"] == 7)
  1179. $column = 'phone';
  1180. if ($_GET["order"][0]["column"] == 8)
  1181. $column = 'email';
  1182. if ($column != '')
  1183. $datas = $datas->orderBy($column, $_GET["order"][0]["dir"]);
  1184. else
  1185. $datas = $datas->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  1186. }
  1187. else
  1188. $datas = $datas->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  1189. if ($_GET["filterStatus"] != "null")
  1190. {
  1191. $status = explode(",", $_GET["filterStatus"]);
  1192. foreach($status as $s)
  1193. {
  1194. foreach($datas->get() as $aaa)
  1195. {
  1196. $state = \App\Models\Member::findOrFail($aaa->member_id)->isActive();
  1197. if ($state["status"] == $s)
  1198. $aRet[] = $aaa;
  1199. }
  1200. }
  1201. }
  1202. else
  1203. $aRet = $datas->get();
  1204. $ret = [];
  1205. foreach($aRet as $idx => $r)
  1206. {
  1207. $date1 = new DateTime($r->birth_date);
  1208. $date2 = new DateTime("now");
  1209. $interval = $date1->diff($date2);
  1210. $ret[] = array(
  1211. "column_0" => $idx + 1,
  1212. "column_8" => $r->course_name,
  1213. "column_1" => $r->last_name,
  1214. "column_2" => $r->first_name,
  1215. "column_3" => strval($interval->y),
  1216. "column_4" => date("Y", strtotime($r->birth_date)),
  1217. "column_5" => $r->phone,
  1218. "column_6" => $r->email,
  1219. "column_7" => $r->member_id
  1220. );
  1221. }
  1222. if (isset($_GET["start"]))
  1223. $ret = array_slice($ret, $_GET["start"], $_GET["length"]);
  1224. return json_encode(array("data" => $ret, "recordsTotal" => sizeof($aRet), "recordsFiltered" => sizeof($aRet)));
  1225. });
  1226. Route::get('/get_receipts', function(){
  1227. $x = \App\Models\Receipt::select('receipts.*', 'members.first_name', 'members.last_name')->leftJoin('members', 'receipts.member_id', '=', 'members.id');
  1228. if (isset($_GET["search"]["value"]))
  1229. {
  1230. $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
  1231. $member_ids = \App\Models\Member::where(function ($query) use ($v) {
  1232. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  1233. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  1234. })->pluck('id');
  1235. /*$member_ids = \App\Models\Member::where(function ($query) use ($v) {
  1236. $query->where('first_name', 'like', '%' . $v . '%')
  1237. ->orWhere('last_name', 'like', '%' . $v . '%');
  1238. })->pluck('id');*/
  1239. $x = $x->whereIn('member_id', $member_ids);
  1240. }
  1241. if ($_GET["filterStatus"] != '')
  1242. $x = $x->where('receipts.status', $_GET["filterStatus"]);
  1243. if ($_GET["filterFrom"] != "")
  1244. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  1245. if ($_GET["filterTo"] != "")
  1246. $x = $x->where('date', '<=', $_GET["filterTo"]);
  1247. $count = $x->count();
  1248. if (isset($_GET["order"]))
  1249. {
  1250. $column = '';
  1251. if ($_GET["order"][0]["column"] == 0)
  1252. $column = 'year';
  1253. if ($_GET["order"][0]["column"] == 1)
  1254. $column = 'number';
  1255. if ($_GET["order"][0]["column"] == 2)
  1256. $column = 'last_name';
  1257. if ($_GET["order"][0]["column"] == 3)
  1258. $column = 'first_name';
  1259. if ($_GET["order"][0]["column"] == 4)
  1260. $column = 'status';
  1261. if ($_GET["order"][0]["column"] == 5)
  1262. $column = 'date';
  1263. if ($column != '')
  1264. $x = $x->orderBy($column, $_GET["order"][0]["dir"])->orderBy('id', 'DESC');
  1265. else
  1266. $x = $x->orderBy('id', 'DESC');
  1267. }
  1268. else
  1269. $x = $x->orderBy('id', 'DESC');
  1270. if (isset($_GET["start"]))
  1271. $x = $x->offset($_GET["start"])->limit($_GET["length"])->get();
  1272. else
  1273. $x = $x->get();
  1274. $datas = [];
  1275. foreach($x as $idx => $r)
  1276. {
  1277. $ids = $r->id . "|" . $r->record_id;
  1278. $datas[] = array(
  1279. 'year' => $r->year,
  1280. 'number' => $r->number,
  1281. 'last_name' => $r->member->last_name,
  1282. 'first_name' => $r->member->first_name,
  1283. 'status' => $r->status,
  1284. 'date' => date("d/m/Y", strtotime($r->date)),
  1285. 'totals' => formatPrice($r->rows->sum('amount')),
  1286. 'action' => $ids
  1287. );
  1288. }
  1289. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  1290. });
  1291. function getColor($months, $m)
  1292. {
  1293. $class = "wgrey";
  1294. foreach(json_decode($months) as $mm)
  1295. {
  1296. if ($mm->m == $m)
  1297. {
  1298. if ($mm->status == "")
  1299. {
  1300. $class = "orange";
  1301. }
  1302. if ($mm->status == "1")
  1303. {
  1304. $class = "green";
  1305. }
  1306. if ($mm->status == "2")
  1307. {
  1308. $class = "yellow";
  1309. }
  1310. }
  1311. }
  1312. return $class;
  1313. }
  1314. Route::get('/migrate', function(){
  1315. \Artisan::call('migrate');
  1316. dd('migrated!');
  1317. });
  1318. Route::get('/updateData', function()
  1319. {
  1320. // Call and Artisan command from within your application.
  1321. Artisan::call('update:data');
  1322. });
  1323. Route::get('/seed', function()
  1324. {
  1325. // Call and Artisan command from within your application.
  1326. Artisan::call('db:seed');
  1327. });
  1328. Route::get('/updateCourseCausal', function(){
  1329. $member_courses = \App\Models\MemberCourse::all();
  1330. foreach($member_courses as $x)
  1331. {
  1332. $records = \App\Models\Record::where('member_course_id', $x->id)->get();
  1333. foreach ($records as $record)
  1334. {
  1335. foreach ($record->rows as $row)
  1336. {
  1337. //if ($row->causal_id == $x->course->sub_causal_id || str_contains(strtolower($row->note), 'iscrizione'))
  1338. if (str_contains(strtolower($row->note), 'iscrizione'))
  1339. {
  1340. $row->causal_id = $x->course->sub_causal_id;
  1341. $row->save();
  1342. }
  1343. }
  1344. }
  1345. }
  1346. });
  1347. Route::get('/test_sms', function()
  1348. {
  1349. $expire_date = date("Y-m-d", strtotime("+1 month"));
  1350. $expire_date_it = date("d/m/Y", strtotime("+1 month"));
  1351. $certificates = \App\Models\MemberCertificate::where('expire_date', $expire_date)->get();
  1352. foreach($certificates as $certificate)
  1353. {
  1354. //$phone = $certificate->member->phone;
  1355. $phone = '3893163265';
  1356. $params = array(
  1357. 'to' => '+39' . $phone,
  1358. 'from' => env('SMS_FROM', 'Test'),
  1359. 'message' => $certificate->member->first_name . ', il tuo certificato medico scadrà il ' . $expire_date_it,
  1360. 'format' => 'json',
  1361. );
  1362. sms_send($params);
  1363. print "Inviato";
  1364. }
  1365. /*
  1366. $params = array(
  1367. 'to' => '+393893163265',
  1368. 'from' => env('SMS_FROM', 'Test'),
  1369. 'message' => 'Prova SMS da IAO',
  1370. 'format' => 'json',
  1371. );
  1372. echo sms_send($params);
  1373. */
  1374. });