Receipt.php 2.5 KB

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