web.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. });
  18. //Route::get('/', \App\Http\Livewire\Login::class);
  19. Route::get('/dashboard', \App\Http\Livewire\Dashboard::class);
  20. Route::get('/settings', \App\Http\Livewire\Setting::class);
  21. Route::get('/courses', \App\Http\Livewire\Course::class);
  22. Route::get('/categories', \App\Http\Livewire\Category::class);
  23. Route::get('/nations_list', \App\Http\Livewire\Nation::class);
  24. Route::get('/provinces', \App\Http\Livewire\Province::class);
  25. Route::get('/cities', \App\Http\Livewire\City::class);
  26. Route::get('/banks', \App\Http\Livewire\Bank::class);
  27. Route::get('/vats', \App\Http\Livewire\Vat::class);
  28. Route::get('/disciplines', \App\Http\Livewire\Discipline::class);
  29. Route::get('/course_types', \App\Http\Livewire\CourseType::class);
  30. Route::get('/course_subscriptions', \App\Http\Livewire\CourseSubscription::class);
  31. Route::get('/course_durations', \App\Http\Livewire\CourseDuration::class);
  32. Route::get('/course_levels', \App\Http\Livewire\CourseLevel::class);
  33. Route::get('/course_frequencies', \App\Http\Livewire\CourseFrequency::class);
  34. Route::get('/course_list', \App\Http\Livewire\CourseList::class);
  35. Route::get('/course_member', \App\Http\Livewire\CourseMember::class);
  36. Route::get('/receipts', \App\Http\Livewire\Receipt::class);
  37. Route::get('/cards', \App\Http\Livewire\Card::class);
  38. Route::get('/causals', \App\Http\Livewire\Causal::class);
  39. Route::get('/payment_methods', \App\Http\Livewire\PaymentMethod::class);
  40. Route::get('/members', \App\Http\Livewire\Member::class);
  41. Route::get('/suppliers', \App\Http\Livewire\Supplier::class);
  42. Route::get('/sponsors', \App\Http\Livewire\Sponsor::class);
  43. Route::get('/records', \App\Http\Livewire\Record::class);
  44. Route::get('/reminders', \App\Http\Livewire\Reminder::class);
  45. Route::get('/in', \App\Http\Livewire\RecordIN::class);
  46. Route::get('/out', \App\Http\Livewire\RecordOUT::class);
  47. Route::get('/records_in_out', \App\Http\Livewire\RecordINOUT::class);
  48. Route::get('/receipt/{id}', function($id){
  49. $receipt = \App\Models\Receipt::findOrFail($id);
  50. $pdf = PDF::loadView('receipt', array('receipt' => $receipt));
  51. $pdfName = "Ricevuta_" . $receipt->member->last_name . "_" . $receipt->number . "_" . $receipt->year . ".pdf";
  52. return $pdf->stream($pdfName);
  53. /*return response()->streamDownload(
  54. fn () => print($pdf),
  55. "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf"
  56. );*/
  57. });
  58. Route::get('/receipt/mail/{id}', function($id){
  59. $receipt = \App\Models\Receipt::findOrFail($id);
  60. if ($receipt->status == 99)
  61. sendReceiptDeleteEmail($receipt);
  62. else
  63. sendReceiptEmail($receipt);
  64. /*
  65. $pdf = PDF::loadView('receipt', array('receipt' => $receipt));
  66. $pdfName = "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf";
  67. Storage::put('public/pdf/' . $pdfName, $pdf->output());
  68. $email = \App\Models\Member::findOrFail($receipt->member_id)->email;
  69. if ($email != '')
  70. {
  71. Mail::to($email)->send(new \App\Mail\ReceipEmail([
  72. 'name' => 'Luca',
  73. 'pdf' => 'public/pdf/' . $pdfName,
  74. 'number' => $receipt->number . "/" . $receipt->year
  75. ]));
  76. }
  77. */
  78. return true;
  79. //return $pdf->stream();
  80. /*return response()->streamDownload(
  81. fn () => print($pdf),
  82. "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf"
  83. );*/
  84. });
  85. Route::get('/nations', function(){
  86. if (isset($_GET["q"]))
  87. $datas = \App\Models\Nation::where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
  88. else
  89. $datas = \App\Models\Nation::orderBy('name')->get();
  90. $data = array();
  91. foreach($datas as $d)
  92. {
  93. $data[] = array("id" => $d->id, "text" => $d->name);
  94. }
  95. return array("results" => $data);
  96. });
  97. Route::get('/provinces/{nation_id}', function($nation_id){
  98. if (isset($_GET["q"]))
  99. $datas = \App\Models\Province::where('nation_id', $nation_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
  100. else
  101. $datas = \App\Models\Province::where('nation_id', $nation_id)->orderBy('name')->get();
  102. $data = array();
  103. foreach($datas as $d)
  104. {
  105. $data[] = array("id" => $d->id, "text" => $d->name);
  106. }
  107. return array("results" => $data);
  108. });
  109. Route::get('/cities/{province_id}', function($province_id){
  110. if (isset($_GET["q"]))
  111. $datas = \App\Models\City::where('province_id', $province_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get();
  112. else
  113. $datas = \App\Models\City::where('province_id', $province_id)->orderBy('name')->get();
  114. $data = array();
  115. foreach($datas as $d)
  116. {
  117. $data[] = array("id" => $d->id, "text" => $d->name);
  118. }
  119. return array("results" => $data);
  120. });
  121. Route::get('/get_members', function(){
  122. $datas = [];
  123. // $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
  124. $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone', 'birth_date')->where('id', '>', 0);
  125. if (isset($_GET["search"]["value"]))
  126. {
  127. $v = str_replace("'", "''", stripcslashes($_GET["search"]["value"]));
  128. $x = $x->where(function ($query) use ($v) {
  129. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
  130. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
  131. });
  132. //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
  133. }
  134. if ($_GET["cards"] != "")
  135. {
  136. $card_ids = \App\Models\MemberCard::whereIn('card_id', explode(",", $_GET["cards"]))->pluck('member_id');
  137. $x = $x->whereIn('id', $card_ids);
  138. }
  139. if ($_GET["categories"] != "")
  140. {
  141. $cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["categories"]))->pluck('member_id');
  142. $x = $x->whereIn('id', $cats_ids);
  143. }
  144. if ($_GET["fromYear"] != "")
  145. {
  146. $x = $x->where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time())));
  147. }
  148. if ($_GET["toYear"] != "")
  149. {
  150. $x = $x->where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())));
  151. }
  152. if ($_GET["fromYearYear"] != "")
  153. {
  154. $x = $x->whereYear('birth_date', '>=', $_GET["fromYearYear"]);
  155. }
  156. if ($_GET["toYearYear"] != "")
  157. {
  158. $x = $x->whereYear('birth_date', '<=', $_GET["toYearYear"]);
  159. }
  160. $ids = [];
  161. if ($_GET["chkCertificateType"] != "")
  162. {
  163. $types = \App\Models\MemberCertificate::where('type', $_GET["chkCertificateType"])->pluck('member_id');
  164. $x = $x->whereIn('id', $types->toArray());;
  165. //$ids = array_merge($ids, $types->toArray());
  166. }
  167. /*
  168. if ($_GET["chkCertificateNormal"] != "")
  169. {
  170. $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
  171. $ids = array_merge($ids, $normal->toArray());
  172. //$x = $x->whereIn('id', $normal);;
  173. }
  174. if ($_GET["chkCertificateAgonistico"] != "")
  175. {
  176. $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
  177. $ids = array_merge($ids, $agonistic->toArray());
  178. //$x = $x->whereIn('id', $agonistic);
  179. }
  180. if ($_GET["chkCertificateScaduti"] != "")
  181. {
  182. $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  183. $ids = array_merge($ids, $scaduto->toArray());
  184. //$x = $x->whereIn('id', $scaduto);
  185. }*/
  186. if ($_GET["chkCertificateScadenza"] != "")
  187. {
  188. if ($_GET["chkCertificateScadenza"] == "1")
  189. $scad = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  190. if ($_GET["chkCertificateScadenza"] == "2")
  191. $scad = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  192. //$ids = array_merge($ids, $scad->toArray());
  193. $x = $x->whereIn('id', $scad->toArray());;
  194. //$x = $x->whereIn('id', $scadenza);
  195. }
  196. //$filterStatus = isset($_GET["status"]) ? $_GET["status"] : -1;
  197. $chkStatus = [];
  198. $chkStatus0 = isset($_GET["chkStatus0"]) ? $_GET["chkStatus0"] : 0;
  199. if($chkStatus0 > 0)
  200. $chkStatus[] = 0;
  201. $chkStatus1 = isset($_GET["chkStatus1"]) ? $_GET["chkStatus1"] : 0;
  202. if($chkStatus1 > 0)
  203. $chkStatus[] = 1;
  204. $chkStatus2 = isset($_GET["chkStatus2"]) ? $_GET["chkStatus2"] : 0;
  205. if($chkStatus2 > 0)
  206. $chkStatus[] = 2;
  207. if (sizeof($chkStatus) > 0)
  208. {
  209. $members = \App\Models\Member::all();
  210. foreach($members as $m)
  211. {
  212. $state = $m->isActive();
  213. if (in_array($state["status"], $chkStatus))
  214. $ids[] = $m->id;
  215. }
  216. }
  217. if (sizeof($ids) > 0)
  218. {
  219. $x = $x->whereIn('id', $ids);
  220. }
  221. else
  222. {
  223. if (sizeof($chkStatus) > 0)
  224. $x = $x->whereIn('id', [-1]);
  225. }
  226. $count = $x->count();
  227. if (isset($_GET["order"]))
  228. {
  229. $column = '';
  230. if ($_GET["order"][0]["column"] == 0)
  231. $column = 'last_name';
  232. if ($_GET["order"][0]["column"] == 1)
  233. $column = 'first_name';
  234. if ($_GET["order"][0]["column"] == 2)
  235. $column = 'phone';
  236. if ($_GET["order"][0]["column"] == 3)
  237. $column = 'birth_date';
  238. if ($_GET["order"][0]["column"] == 4)
  239. $column = 'birth_date';
  240. if ($column != '')
  241. $x = $x->orderBy($column, $_GET["order"][0]["dir"]);
  242. else
  243. $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  244. }
  245. else
  246. $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
  247. if (isset($_GET["start"]))
  248. $x = $x->offset($_GET["start"])->limit($_GET["length"])->get();
  249. else
  250. $x = $x->get();
  251. foreach($x as $idx => $r)
  252. {
  253. $status = $r->getStatus();
  254. $status = $status["status"];
  255. // $state = $r->isActive();
  256. $class = $status > 0 ? ($status == 2 ? 'active' : 'due') : 'suspended';
  257. $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
  258. /*$x = $state["status"] > 0 ? ($state["status"] == 2 ? 'active' : 'suspended') : '';
  259. $x .= "|";
  260. $x .= $state["status"] > 0 ? ($state["status"] == 2 ? 'Attivo' : 'Sospesa') : '';
  261. $x .= "|";
  262. $x .= $state["status"] ? 'Scadenza : ' : ($state["date"] != '' ? 'Scaduto : ' : '');
  263. $x .= "|";
  264. $x .= $state["date"] != '' ? date("d/m/Y", strtotime($state["date"])) : '';*/
  265. $has_certificate = $r->hasCertificate();
  266. $y = '';
  267. if($has_certificate["date"] != '')
  268. {
  269. if($has_certificate["date"] < date("Y-m-d"))
  270. $y .= '0';
  271. if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
  272. $y .= '1';
  273. if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
  274. $y .= '2';
  275. $y .= '|';
  276. $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : '';
  277. }
  278. $datas[] = array(
  279. //'c' => $idx + 1,
  280. //'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
  281. 'last_name' => $r->last_name . "|" . $r->id,
  282. 'first_name' => $r->first_name . "|" . $r->id,
  283. 'phone' => $r->phone,
  284. 'age' => $r->getAge(),
  285. 'year' => date("Y", strtotime($r->birth_date)),
  286. 'status' => $class . "|" . $text,
  287. // 'state' => $x,
  288. 'certificate' => $y,
  289. 'action' => $r->id
  290. );
  291. }
  292. /*
  293. $r->age = $r->getAge();
  294. $active = $r->isActive();
  295. $r->status = $active["status"];
  296. $r->date = $active["date"] . "|" . $r->hasCertificate()["date"];
  297. $r->state = $r->getStatus()["status"];
  298. $r->action = '';*/
  299. /*
  300. if ($this->sortAsc)
  301. $this->records = $this->records->sortBy($this->sortField);
  302. else
  303. $this->records = $this->records->sortByDesc($this->sortField);
  304. */
  305. // $datas = $x; // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
  306. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  307. });
  308. Route::get('/get_record_in', function(){
  309. $datas = [];
  310. $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'))
  311. ->leftJoin('members', 'records.member_id', '=', 'members.id')
  312. ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
  313. ->where('records.type', 'IN');
  314. if (isset($_GET["search"]["value"]))
  315. {
  316. $v = str_replace("'", "''", stripcslashes($_GET["search"]["value"]));
  317. $x = $x->where(function ($query) use ($v) {
  318. $query->where('first_name', 'like', '%' . $v . '%')
  319. ->orWhere('last_name', 'like', '%' . $v . '%');
  320. });
  321. //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
  322. }
  323. //$x = $x->where(function ($query) use ($v) {
  324. // $datas = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method');
  325. if ($_GET["filterCommercial"] > 0)
  326. {
  327. $x = $x->where('commercial', $_GET["filterCommercial"] == 1 ? true : false);
  328. }
  329. if ($_GET["filterMember"] > 0)
  330. {
  331. $x = $x->where('member_id', $_GET["filterMember"]);
  332. }
  333. if ($_GET["filterPaymentMethod"] != "null")
  334. {
  335. $payments = explode(",", $_GET["filterPaymentMethod"]);
  336. $x = $x->whereIn('payment_method_id', $payments);
  337. }
  338. if ($_GET["filterCausals"] != "null")
  339. {
  340. $causals = explode(",", $_GET["filterCausals"]);
  341. //$causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  342. $causals = \App\Models\RecordRow::whereIn('causal_id', $causals)->pluck('record_id');
  343. $x = $x->whereIn('records.id', $causals);
  344. }
  345. if ($_GET["filterFrom"] != '')
  346. {
  347. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  348. }
  349. if ($_GET["filterTo"] != '')
  350. {
  351. $x = $x->where('date', '<=', $_GET["filterTo"]);
  352. }
  353. //});
  354. $start = 0;
  355. $limit = 100000;
  356. if (isset($_GET["start"]))
  357. {
  358. $start = $_GET["start"];
  359. $limit = $_GET["length"];
  360. }
  361. $excludeCausals = [];
  362. $borsellino = \App\Models\Causal::where('money', true)->first();
  363. if ($borsellino)
  364. $excludeCausals[] = $borsellino->id;
  365. // Aggiungo
  366. $excludes = \App\Models\Causal::where('no_records', true)->get();
  367. foreach($excludes as $e)
  368. {
  369. $excludeCausals[] = $e->id;
  370. }
  371. $exclude_from_records = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
  372. // Pagamento money
  373. $moneys = \App\Models\PaymentMethod::where('money', true)->pluck('id')->toArray();
  374. // Causale money
  375. $moneysCausal = \App\Models\Causal::where('money', true)->pluck('id')->toArray();
  376. $total = 0;
  377. foreach($x->get() as $r)
  378. {
  379. if (!in_array($r->payment_method_id, $moneys))
  380. {
  381. foreach($r->rows as $rr)
  382. {
  383. 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))
  384. {
  385. $total += $rr->amount;
  386. if ($rr->vat_id > 0)
  387. $total += getVatValue($rr->amount, $rr->vat_id);
  388. }
  389. }
  390. }
  391. }
  392. $count = $x->count();
  393. if (isset($_GET["order"]))
  394. {
  395. $column = '';
  396. if ($_GET["order"][0]["column"] == 0)
  397. $column = 'date';
  398. if ($_GET["order"][0]["column"] == 1)
  399. $column = 'records.amount';
  400. if ($_GET["order"][0]["column"] == 2)
  401. $column = 'last_name';
  402. if ($_GET["order"][0]["column"] == 3)
  403. $column = 'first_name';
  404. if ($_GET["order"][0]["column"] == 4)
  405. $column = 'commercial';
  406. if ($column != '')
  407. $x = $x->orderBy($column, $_GET["order"][0]["dir"])->orderBy('records.id', 'DESC');
  408. else
  409. $x = $x->orderBy('records.id', 'DESC');
  410. }
  411. else
  412. $x = $x->orderBy('records.date', 'DESC')->orderBy('records.id', 'DESC');
  413. $x = $x->offset($start)->limit($limit)->get();
  414. foreach($x as $idx => $r)
  415. {
  416. $causals = '';
  417. foreach($r->rows as $row)
  418. {
  419. $causals .= $row->causal->getTree() . "<br>";
  420. }
  421. $datas[] = array(
  422. //'id' => $r->id,
  423. 'date' => $r->date,
  424. 'total' => formatPrice($r->getTotal()),
  425. 'first_name' => $r->first_name,
  426. 'last_name' => $r->last_name,
  427. 'commercial' => $r->financial_movement ? 'Movimento finanziario' : ($r->commercial ? 'SI' : 'NO'),
  428. 'causals' => $causals,
  429. 'payment' => $r->payment_method->name,
  430. 'status' => $r->deleted ? 'Annullato' : '',
  431. 'action' => $r->id . "|" . formatPrice($total) . "|" . ($r->deleted ? 'x' : '')
  432. );
  433. }
  434. /*$datas[] = array(
  435. //'id' => $r->id,
  436. 'date' => '',
  437. 'total' => formatPrice($total),
  438. 'first_name' => '',
  439. 'last_name' => '',
  440. 'commercial' => '',
  441. 'causals' => '',
  442. 'payment' => '',
  443. 'status' => '',
  444. 'action' => ''
  445. );*/
  446. return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count));
  447. });
  448. Route::get('/get_record_out', function(){
  449. $datas = [];
  450. $x = \App\Models\Record::where('type', 'OUT')->with('supplier', 'payment_method');
  451. if ($_GET["filterSupplier"] > 0)
  452. {
  453. $x = $x->where('supplier_id', $_GET["filterSupplier"]);
  454. }
  455. /*if ($_GET["filterPaymentMethod"] > 0)
  456. {
  457. $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]);
  458. }
  459. if ($_GET["filterCausals"] > 0)
  460. {
  461. $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  462. $x = $x->whereIn('records.id', $causals);
  463. }*/
  464. if ($_GET["filterPaymentMethod"] != "null")
  465. {
  466. $payments = explode(",", $_GET["filterPaymentMethod"]);
  467. $x = $x->whereIn('payment_method_id', $payments);
  468. }
  469. if ($_GET["filterCausals"] != "null")
  470. {
  471. $causals = explode(",", $_GET["filterCausals"]);
  472. //$causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
  473. $causals = \App\Models\RecordRow::whereIn('causal_id', $causals)->pluck('record_id');
  474. $x = $x->whereIn('records.id', $causals);
  475. }
  476. if ($_GET["filterFrom"] != '')
  477. {
  478. $x = $x->where('date', '>=', $_GET["filterFrom"]);
  479. }
  480. if ($_GET["filterTo"] != '')
  481. {
  482. $x = $x->where('date', '<=', $_GET["filterTo"]);
  483. }
  484. $total = 0;
  485. foreach($x->get() as $r)
  486. {
  487. foreach($r->rows as $rr)
  488. {
  489. $total += $rr->amount;
  490. if ($rr->vat_id > 0)
  491. $total += getVatValue($rr->amount, $rr->vat_id);
  492. }
  493. }
  494. $x = $x->get();
  495. foreach($x as $idx => $r)
  496. {
  497. $causals = '';
  498. foreach($r->rows as $row)
  499. {
  500. $causals .= $row->causal->getTree() . "<br>";
  501. }
  502. $datas[] = array(
  503. //'id' => $r->id,
  504. 'date' => $r->date,
  505. 'total' => formatPrice($r->getTotal()),
  506. 'supplier' => $r->supplier->name,
  507. 'causals' => $causals,
  508. 'payment' => $r->payment_method->name,
  509. 'action' => $r->id . "|" . formatPrice($total)
  510. );
  511. }
  512. /*
  513. $datas[] = array(
  514. //'id' => $r->id,
  515. 'date' => '',
  516. 'total' => formatPrice($total),
  517. 'supplier' => '',
  518. 'causals' => '',
  519. 'payment' => '',
  520. 'action' => ''
  521. );
  522. */
  523. return json_encode(array("data" => $datas));
  524. });
  525. Route::get('/migrate', function(){
  526. \Artisan::call('migrate');
  527. dd('migrated!');
  528. });