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; } }