web.php 47 KB

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