| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- class RecordINOUT extends Component
- {
- public $records_in, $records_out;
- public $total_in = 0;
- public $total_out = 0;
- public $month;
- public $year;
- public $hasFilter = false;
- public $total = 0;
- public $selectedFilter = '';
- public $causals = array();
- public $payments = array();
- public $members = array();
- public function mount()
- {
- $this->month = date("n");
- $this->year = date("Y");
- /*$this->causals = array();
- $this->getCausale(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'IN')->get(), 0);
- $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])->orderBy('last_name')->orderBy('first_name')->get();
- $this->payments = \App\Models\PaymentMethod::select('id', 'name')->orderBy('name')->get();
- if ($this->first)
- {
- if (isset($_GET["new"]))
- {
- $this->refreshAfter = 1;
- $this->add();
- }
- if (isset($_GET["memberId"]))
- $this->member_id = $_GET["memberId"];
- if (isset($_GET["causalId"]))
- $this->causal_id = $_GET["causalId"];
- }
- $this->first = false;*/
- }
- public function render()
- {
- $my = $this->month . "-" . $this->year;
- // $datas_in = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method');
- $datas_in = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method')
- ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
- ->where('records_rows.when', 'like', '%' . $my . '%');
- $this->records_in = $datas_in->orderBy('date', 'DESC')->get();
- $this->total_in = 0;
- foreach($this->records_in as $in)
- {
- $amount = $in->amount;
- $when = sizeof(json_decode($in->when));
- if ($when > 1)
- {
- $amount = $amount / $when;
- $in->amount = $amount;
- }
- $this->total_in += $amount;
- }
- // $this->total_in = $this->records_in->sum('amount');
- $datas_out = \App\Models\Record::where('type', 'OUT')->with('member', 'payment_method')
- ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
- ->where('records_rows.when', 'like', '%' . $my . '%');
- /*
- $datas_out = \App\Models\Record::where('type', 'OUT')->with('supplier', 'causal', 'payment_method');
- if ($this->month > 0)
- {
- $datas_out = $datas_out->where('month', $this->month);
- }
- if ($this->year > 0)
- {
- $datas_out = $datas_out->where('year', $this->year);
- }
- */
- $this->records_out = $datas_out->orderBy('date', 'DESC')->get();
- // $this->total_out = $this->records_out->sum('amount');
- $this->total_out = 0;
- foreach($this->records_out as $out)
- {
- $amount = $out->amount;
- $when = sizeof(json_decode($out->when));
- if ($when > 1)
- {
- $amount = $amount / $when;
- $out->amount = $amount;
- }
- $this->total_out += $amount;
- }
- return view('livewire.records_in_out');
- }
- public function getCausal($causal)
- {
- $ret = '';
- if ($causal > 0)
- {
- $ret = \App\Models\Causal::findOrFail($causal)->getTree();
- }
- return $ret;
- }
- }
|