Rate.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use Barryvdh\DomPDF\Facade\Pdf;
  5. use App\Models\Member;
  6. class Rate extends Component
  7. {
  8. public $records;
  9. public $member_id = 0;
  10. public $member_course_id = 0;
  11. public $mc = null;
  12. public $filterStatus = '';
  13. public $hasFilter = false;
  14. public $filterFrom = '', $filterTo = '';
  15. public $filteredMemberId = '';
  16. public $members = [];
  17. public $detail = '';
  18. public $course_subscription_id;
  19. public $price;
  20. public $date;
  21. public $months = [];
  22. public $couse_subscriptions = [];
  23. public $price_list = [];
  24. public function mount()
  25. {
  26. // Load members for the dropdown
  27. $this->member_id = isset($_GET["member_id"]) ? $_GET["member_id"] : 0;
  28. $this->member_course_id = isset($_GET["member_course_id"]) ? $_GET["member_course_id"] : 0;
  29. if ($this->member_id > 0 && $this->member_course_id > 0)
  30. {
  31. $this->mc = \App\Models\MemberCourse::findOrFail($this->member_course_id);
  32. $this->detail = 'Riepilogo rate ' . $this->mc->course->name . ' di ' . $this->mc->member->first_name . " " . $this->mc->member->last_name;
  33. $this->price_list = [];
  34. $c = $this->mc->course;
  35. if ($c->prices != null)
  36. {
  37. foreach(json_decode($c->prices) as $z)
  38. {
  39. $this->price_list[$z->course_subscription_id] = $z->price;
  40. }
  41. }
  42. }
  43. $this->course_subscriptions = \App\Models\CourseSubscription::select('*')->where('enabled', true)->get();
  44. }
  45. public function render()
  46. {
  47. /*if ($this->hasFilter)
  48. {
  49. $r = \App\Models\Receipt::with('member');
  50. if ($this->filterStatus != '')
  51. $r = $r->where('status', $this->filterStatus);
  52. if ($this->filterFrom != '')
  53. $r = $r->where('date', '>=', $this->filterFrom);
  54. if ($this->filterTo != '')
  55. $r = $r->where('date', '<=', $this->filterTo);
  56. if ($this->filteredMemberId != '')
  57. $r = $r->where('member_id', $this->filteredMemberId);
  58. $this->records = $r->get();
  59. }
  60. else
  61. {*/
  62. $this->records = \App\Models\Rate::with('member')->where('member_course_id', $this->member_course_id)->get();
  63. //}
  64. //$this->emit('load-data-table');
  65. return view('livewire.rate');
  66. }
  67. public function updatedCourseSubscriptionId()
  68. {
  69. $this->price = 0;
  70. if (isset($this->price_list[$this->course_subscription_id]))
  71. $this->price = $this->price_list[$this->course_subscription_id];
  72. }
  73. public function add()
  74. {
  75. $rate = new \App\Models\Rate();
  76. $rate->member_id = $this->member_id;
  77. $rate->member_course_id = $this->member_course_id;
  78. $rate->course_subscription_id = $this->course_subscription_id;
  79. $rate->price = currencyToDouble($this->price);
  80. $rate->date = $this->date;
  81. $rate->months = json_encode($this->months);
  82. $rate->note = '';
  83. $rate->status = 0;
  84. $rate->save();
  85. $this->course_subscription_id = null;
  86. $this->price = 0;
  87. $this->date = null;
  88. $this->months = [];
  89. $this->emit('close-popup');
  90. }
  91. public function printReceipt($id)
  92. {
  93. $this->emit('load-data-table');
  94. $receipt = \App\Models\Receipt::findOrFail($id);
  95. //$pdf = PDF::loadView('pdf/receipt', array('datas' => $datas, 'from' => $x, 'to' => $y, 'who' => '', 'matricola' => $matricola));
  96. $pdf = PDF::loadView('receipt', array('receipt' => $receipt));//->output();
  97. return $pdf->stream('aaa.pdf');
  98. }
  99. public function search()
  100. {
  101. $this->hasFilter = true;
  102. }
  103. public function disableSearch()
  104. {
  105. $this->filterStatus = "";
  106. $this->filterTo = '';
  107. $this->filterFrom = '';
  108. $this->filteredMemberId = '';
  109. $this->hasFilter = false;
  110. }
  111. public function delete($id)
  112. {
  113. try{
  114. \App\Models\Rate::find($id)->delete();
  115. //$this->emit('load-data-table');
  116. session()->flash('success',"Rata eliminata");
  117. }catch(\Exception $e){
  118. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  119. }
  120. }
  121. public function addDeleteMonth($m)
  122. {
  123. if (!in_array($m, $this->months))
  124. {
  125. $this->months[] = $m;
  126. }
  127. else
  128. {
  129. }
  130. }
  131. }