Receipt.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use Barryvdh\DomPDF\Facade\Pdf;
  5. use App\Models\Member;
  6. class Receipt extends Component
  7. {
  8. public $records;
  9. public $filterStatus = '';
  10. public $hasFilter = false;
  11. public $filterFrom = '', $filterTo = '';
  12. public $filteredMemberId = '';
  13. public $members = [];
  14. public function mount()
  15. {
  16. // Load members for the dropdown
  17. $this->members = Member::orderBy('last_name')->orderBy('first_name')->get();
  18. }
  19. public function updatedFilterFrom()
  20. {
  21. $this->emit('destroy-data-table');
  22. }
  23. public function updatedFilterTo()
  24. {
  25. $this->emit('destroy-data-table');
  26. }
  27. public function render()
  28. {
  29. if ($this->hasFilter)
  30. {
  31. $r = \App\Models\Receipt::with('member');
  32. if ($this->filterStatus != '')
  33. $r = $r->where('status', $this->filterStatus);
  34. if ($this->filterFrom != '')
  35. $r = $r->where('date', '>=', $this->filterFrom);
  36. if ($this->filterTo != '')
  37. $r = $r->where('date', '<=', $this->filterTo);
  38. if ($this->filteredMemberId != '')
  39. $r = $r->where('member_id', $this->filteredMemberId);
  40. $this->records = $r->get();
  41. }
  42. else
  43. {
  44. $this->records = \App\Models\Receipt::with('member')->get();
  45. }
  46. $this->emit('load-data-table');
  47. return view('livewire.receipt');
  48. }
  49. public function printReceipt($id)
  50. {
  51. $this->emit('load-data-table');
  52. $receipt = \App\Models\Receipt::findOrFail($id);
  53. //$pdf = PDF::loadView('pdf/receipt', array('datas' => $datas, 'from' => $x, 'to' => $y, 'who' => '', 'matricola' => $matricola));
  54. $pdf = PDF::loadView('receipt', array('receipt' => $receipt));//->output();
  55. return $pdf->stream('aaa.pdf');
  56. }
  57. public function search()
  58. {
  59. $this->hasFilter = true;
  60. }
  61. public function disableSearch()
  62. {
  63. $this->filterStatus = "";
  64. $this->filterTo = '';
  65. $this->filterFrom = '';
  66. $this->filteredMemberId = '';
  67. $this->hasFilter = false;
  68. }
  69. }