RecordINOUT.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. class RecordINOUT extends Component
  5. {
  6. public $records_in, $records_out;
  7. public $total_in = 0;
  8. public $total_out = 0;
  9. public $month;
  10. public $year;
  11. public $hasFilter = false;
  12. public $total = 0;
  13. public $selectedFilter = '';
  14. public $causals = array();
  15. public $payments = array();
  16. public $members = array();
  17. public function mount()
  18. {
  19. $this->month = date("n");
  20. $this->year = date("Y");
  21. /*$this->causals = array();
  22. $this->getCausale(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'IN')->get(), 0);
  23. $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])->orderBy('last_name')->orderBy('first_name')->get();
  24. $this->payments = \App\Models\PaymentMethod::select('id', 'name')->orderBy('name')->get();
  25. if ($this->first)
  26. {
  27. if (isset($_GET["new"]))
  28. {
  29. $this->refreshAfter = 1;
  30. $this->add();
  31. }
  32. if (isset($_GET["memberId"]))
  33. $this->member_id = $_GET["memberId"];
  34. if (isset($_GET["causalId"]))
  35. $this->causal_id = $_GET["causalId"];
  36. }
  37. $this->first = false;*/
  38. }
  39. public function render()
  40. {
  41. $my = $this->month . "-" . $this->year;
  42. // $datas_in = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method');
  43. $datas_in = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method')
  44. ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
  45. ->where('records_rows.when', 'like', '%' . $my . '%');
  46. $this->records_in = $datas_in->orderBy('date', 'DESC')->get();
  47. $this->total_in = 0;
  48. foreach($this->records_in as $in)
  49. {
  50. $amount = $in->amount;
  51. $when = sizeof(json_decode($in->when));
  52. if ($when > 1)
  53. {
  54. $amount = $amount / $when;
  55. $in->amount = $amount;
  56. }
  57. $this->total_in += $amount;
  58. }
  59. // $this->total_in = $this->records_in->sum('amount');
  60. $datas_out = \App\Models\Record::where('type', 'OUT')->with('member', 'payment_method')
  61. ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
  62. ->where('records_rows.when', 'like', '%' . $my . '%');
  63. /*
  64. $datas_out = \App\Models\Record::where('type', 'OUT')->with('supplier', 'causal', 'payment_method');
  65. if ($this->month > 0)
  66. {
  67. $datas_out = $datas_out->where('month', $this->month);
  68. }
  69. if ($this->year > 0)
  70. {
  71. $datas_out = $datas_out->where('year', $this->year);
  72. }
  73. */
  74. $this->records_out = $datas_out->orderBy('date', 'DESC')->get();
  75. // $this->total_out = $this->records_out->sum('amount');
  76. $this->total_out = 0;
  77. foreach($this->records_out as $out)
  78. {
  79. $amount = $out->amount;
  80. $when = sizeof(json_decode($out->when));
  81. if ($when > 1)
  82. {
  83. $amount = $amount / $when;
  84. $out->amount = $amount;
  85. }
  86. $this->total_out += $amount;
  87. }
  88. return view('livewire.records_in_out');
  89. }
  90. public function getCausal($causal)
  91. {
  92. $ret = '';
  93. if ($causal > 0)
  94. {
  95. $ret = \App\Models\Causal::findOrFail($causal)->getTree();
  96. }
  97. return $ret;
  98. }
  99. }