Receipt.php 2.0 KB

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