Receipt.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 response()->streamDownload(
  46. fn () => print($pdf),
  47. "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf"
  48. );
  49. /*return response()->streamDownload(function () {
  50. echo $pdf->stream();
  51. }, 'test.pdf');*/
  52. }
  53. public function search()
  54. {
  55. $this->hasFilter = true;
  56. }
  57. public function disableSearch()
  58. {
  59. $this->filterStatus = "";
  60. $this->filterTo = '';
  61. $this->filterFrom = '';
  62. $this->hasFilter = false;
  63. }
  64. }