orderBy('name')->get(); else $datas = \App\Models\Nation::orderBy('name')->get(); $data = array(); foreach($datas as $d) { $data[] = array("id" => $d->id, "text" => $d->name); } return array("results" => $data); }); Route::get('/provinces/{nation_id}', function($nation_id){ if (isset($_GET["q"])) $datas = \App\Models\Province::where('nation_id', $nation_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get(); else $datas = \App\Models\Province::where('nation_id', $nation_id)->orderBy('name')->get(); $data = array(); foreach($datas as $d) { $data[] = array("id" => $d->id, "text" => $d->name); } return array("results" => $data); }); Route::get('/cities/{province_id}', function($province_id){ if (isset($_GET["q"])) $datas = \App\Models\City::where('province_id', $province_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get(); else $datas = \App\Models\City::where('province_id', $province_id)->orderBy('name')->get(); $data = array(); foreach($datas as $d) { $data[] = array("id" => $d->id, "text" => $d->name); } return array("results" => $data); }); Route::get('/get_members', function(){ $datas = []; // $datas = \App\Models\Member::select('members.*')->where('id', '>', 0); $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone', 'birth_date')->where('id', '>', 0); if ($_GET["cards"] != "") { $card_ids = \App\Models\MemberCard::whereIn('card_id', explode(",", $_GET["cards"]))->pluck('member_id'); $x = $x->whereIn('id', $card_ids); } if ($_GET["categories"] != "") { $cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["categories"]))->pluck('member_id'); $x = $x->whereIn('id', $cats_ids); } if ($_GET["fromYear"] != "") { $x = $x->where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time()))); } if ($_GET["toYear"] != "") { $x = $x->where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time()))); } $certs = []; if ($_GET["chkCertificateNormal"] != "") { $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id'); $x = $x->whereIn('id', $normal);; } if ($_GET["chkCertificateAgonistico"] != "") { $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id'); $x = $x->whereIn('id', $agonistic); } if ($_GET["chkCertificateScaduti"] != "") { $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id'); $x = $x->whereIn('id', $scaduto); } if ($_GET["chkCertificateScadenza"] != "") { $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id'); $x = $x->whereIn('id', $scadenza); } if (sizeof($certs) > 0) { $x = $x->whereIn('id', $certs); } $x = $x->get(); $filterStatus = isset($_GET["status"]) ? $_GET["status"] : -1; foreach($x as $idx => $r) { $status = $r->getStatus(); $status = $status["status"]; $state = $r->isActive(); $procede = true; if ($filterStatus >= 0) { if ($state["status"] != $filterStatus) $procede = false; } if ($procede) { $class = $status > 0 ? ($status == 2 ? 'active' : 'suspended') : 'due'; $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato'; $x = $state["status"] > 0 ? ($state["status"] == 2 ? 'active' : 'suspended') : ''; $x .= "|"; $x .= $state["status"] > 0 ? ($state["status"] == 2 ? 'Attivo' : 'Sospesa') : ''; $x .= "|"; $x .= $state["status"] ? 'Scadenza : ' : ($state["date"] != '' ? 'Scaduto : ' : ''); $x .= "|"; $x .= $state["date"] != '' ? date("d/m/Y", strtotime($state["date"])) : ''; $has_certificate = $r->hasCertificate(); $y = ''; if($has_certificate["date"] != '') { if($has_certificate["date"] < date("Y-m-d")) $y .= '0'; if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month"))) $y .= '1'; if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month"))) $y .= '2'; $y .= '|'; $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : ''; } $datas[] = array( //'c' => $idx + 1, 'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT), 'first_name' => $r->first_name . "|" . $r->id, 'last_name' => $r->last_name . "|" . $r->id, 'phone' => $r->phone, 'age' => $r->getAge(), 'status' => $class . "|" . $text, 'state' => $x, 'certificate' => $y, 'action' => $r->id ); } /* $r->age = $r->getAge(); $active = $r->isActive(); $r->status = $active["status"]; $r->date = $active["date"] . "|" . $r->hasCertificate()["date"]; $r->state = $r->getStatus()["status"]; $r->action = '';*/ } /* if ($this->sortAsc) $this->records = $this->records->sortBy($this->sortField); else $this->records = $this->records->sortByDesc($this->sortField); */ // $datas = $x; // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10); return json_encode(array("data" => $datas)); }); Route::get('/get_record_in', function(){ $datas = []; $x = \App\Models\Record::select('records.*', \DB::raw('members.first_name as first_name'), \DB::raw('members.last_name as last_name'), \DB::raw('payment_methods.name as payment')) // , \DB::raw('SUM(records.id) As total')) ->leftJoin('members', 'records.member_id', '=', 'members.id') ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id') ->where('records.type', 'IN'); // $datas = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method'); if ($_GET["filterCommercial"] > 0) { $x = $x->where('commercial', $_GET["filterCommercial"] == 1 ? true : false); } if ($_GET["filterMember"] > 0) { $x = $x->where('member_id', $_GET["filterMember"]); } if ($_GET["filterPaymentMethod"] > 0) { $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]); } if ($_GET["filterCausals"] > 0) { $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id'); $x = $x->whereIn('records.id', $causals); } if ($_GET["filterFrom"] != '') { $x = $x->where('date', '>=', $_GET["filterFrom"]); } if ($_GET["filterTo"] != '') { $x = $x->where('date', '<=', $_GET["filterTo"]); } $total = 0; foreach($x->get() as $r) { foreach($r->rows as $rr) { $total += $rr->amount; if ($rr->vat_id > 0) $total += getVatValue($rr->amount, $rr->vat_id); } } $x = $x->get(); foreach($x as $idx => $r) { $causals = ''; foreach($r->rows as $row) { $causals .= $row->causal->getTree() . "
"; } $datas[] = array( //'id' => $r->id, 'date' => $r->date, 'total' => formatPrice($r->getTotal()), 'first_name' => $r->first_name, 'last_name' => $r->last_name, 'commercial' => $r->commercial ? 'SI' : 'NO', 'causals' => $causals, 'payment' => $r->payment_method->name, 'action' => $r->id . "|" . formatPrice($total) ); } $datas[] = array( //'id' => $r->id, 'date' => '', 'total' => formatPrice($total), 'first_name' => '', 'last_name' => '', 'commercial' => '', 'causals' => '', 'payment' => '', 'action' => '' ); return json_encode(array("data" => $datas)); }); Route::get('/get_record_out', function(){ $datas = []; $x = \App\Models\Record::where('type', 'OUT')->with('supplier', 'payment_method'); if ($_GET["filterSupplier"] > 0) { $x = $x->where('supplier_id', $_GET["filterSupplier"]); } if ($_GET["filterPaymentMethod"] > 0) { $x = $x->where('payment_method_id', $_GET["filterPaymentMethod"]); } if ($_GET["filterCausals"] > 0) { $causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id'); $x = $x->whereIn('records.id', $causals); } if ($_GET["filterFrom"] != '') { $x = $x->where('date', '>=', $_GET["filterFrom"]); } if ($_GET["filterTo"] != '') { $x = $x->where('date', '<=', $_GET["filterTo"]); } $total = 0; foreach($x->get() as $r) { foreach($r->rows as $rr) { $total += $rr->amount; if ($rr->vat_id > 0) $total += getVatValue($rr->amount, $rr->vat_id); } } $x = $x->get(); foreach($x as $idx => $r) { $causals = ''; foreach($r->rows as $row) { $causals .= $row->causal->getTree() . "
"; } $datas[] = array( //'id' => $r->id, 'date' => $r->date, 'total' => formatPrice($r->getTotal()), 'supplier' => $r->supplier->name, 'causals' => $causals, 'payment' => $r->payment_method->name, 'action' => $r->id . "|" . formatPrice($total) ); } $datas[] = array( //'id' => $r->id, 'date' => '', 'total' => formatPrice($total), 'supplier' => '', 'causals' => '', 'payment' => '', 'action' => '' ); return json_encode(array("data" => $datas)); }); Route::get('/migrate', function(){ \Artisan::call('migrate'); dd('migrated!'); });