web.php 46 KB

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