Receipt.php 1.8 KB

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