web.php 48 KB

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