$receipt)); return $pdf->stream(); /*return response()->streamDownload( fn () => print($pdf), "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf" );*/ }); Route::get('/receipt/mail/{id}', function($id){ $receipt = \App\Models\Receipt::findOrFail($id); if ($receipt->status == 99) sendReceiptDeleteEmail($receipt); else sendReceiptEmail($receipt); /* $pdf = PDF::loadView('receipt', array('receipt' => $receipt)); $pdfName = "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf"; Storage::put('public/pdf/' . $pdfName, $pdf->output()); $email = \App\Models\Member::findOrFail($receipt->member_id)->email; if ($email != '') { Mail::to($email)->send(new \App\Mail\ReceipEmail([ 'name' => 'Luca', 'pdf' => 'public/pdf/' . $pdfName, 'number' => $receipt->number . "/" . $receipt->year ])); } */ return true; //return $pdf->stream(); /*return response()->streamDownload( fn () => print($pdf), "ricevuta_" . $receipt->number . "_" . $receipt->year . ".pdf" );*/ }); Route::get('/nations', function(){ if (isset($_GET["q"])) $datas = \App\Models\Nation::where('name', 'like', $_GET["q"] . '%')->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 (isset($_GET["search"]["value"])) { $v = str_replace("'", "''", stripcslashes($_GET["search"]["value"])); $x = $x->where(function ($query) use ($v) { $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'") ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'"); }); //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%'); } 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()))); } $ids = []; if ($_GET["chkCertificateNormal"] != "") { $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id'); $ids = array_merge($ids, $normal->toArray()); //$x = $x->whereIn('id', $normal);; } if ($_GET["chkCertificateAgonistico"] != "") { $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id'); $ids = array_merge($ids, $agonistic->toArray()); //$x = $x->whereIn('id', $agonistic); } if ($_GET["chkCertificateScaduti"] != "") { $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id'); $ids = array_merge($ids, $scaduto->toArray()); //$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'); $ids = array_merge($ids, $scadenza->toArray()); //$x = $x->whereIn('id', $scadenza); } //$filterStatus = isset($_GET["status"]) ? $_GET["status"] : -1; $chkStatus = []; $chkStatus0 = isset($_GET["chkStatus0"]) ? $_GET["chkStatus0"] : 0; if($chkStatus0 > 0) $chkStatus[] = 0; $chkStatus1 = isset($_GET["chkStatus1"]) ? $_GET["chkStatus1"] : 0; if($chkStatus1 > 0) $chkStatus[] = 1; $chkStatus2 = isset($_GET["chkStatus2"]) ? $_GET["chkStatus2"] : 0; if($chkStatus2 > 0) $chkStatus[] = 2; if (sizeof($chkStatus) > 0) { $members = \App\Models\Member::all(); foreach($members as $m) { $state = $m->isActive(); if (in_array($state["status"], $chkStatus)) $ids[] = $m->id; } } if (sizeof($ids) > 0) { $x = $x->whereIn('id', $ids); } else { if (sizeof($chkStatus) > 0) $x = $x->whereIn('id', [-1]); } $count = $x->count(); $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC'); if (isset($_GET["start"])) $x = $x->offset($_GET["start"])->limit($_GET["length"])->get(); else $x = $x->get(); foreach($x as $idx => $r) { $status = $r->getStatus(); $status = $status["status"]; // $state = $r->isActive(); $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), 'last_name' => $r->last_name . "|" . $r->id, 'first_name' => $r->first_name . "|" . $r->id, 'phone' => $r->phone, 'age' => $r->getAge(), 'year' => date("Y", strtotime($r->birth_date)), '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, "recordsTotal" => $count, "recordsFiltered" => $count)); }); 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"]); } if (isset($_GET["search"]["value"])) { $v = str_replace("'", "''", stripcslashes($_GET["search"]["value"])); $x = $x->where(function ($query) use ($v) { $query->where('first_name', 'like', '%' . $v . '%') ->orWhere('last_name', 'like', '%' . $v . '%'); }); //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%'); } $start = 0; $limit = 100000; if (isset($_GET["start"])) { $start = $_GET["start"]; $limit = $_GET["length"]; } $excludeCausals = []; $borsellino = \App\Models\Causal::where('money', true)->first(); if ($borsellino) $excludeCausals[] = $borsellino->id; // Aggiungo $excludes = \App\Models\Causal::where('no_records', true)->get(); foreach($excludes as $e) { $excludeCausals[] = $e->id; } $exclude_from_records = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray(); $total = 0; foreach($x->get() as $r) { foreach($r->rows as $rr) { if (!in_array($rr->member_id, $exclude_from_records) && (!$r->deleted || $r->deleted == null) && !in_array($rr->causal_id, $excludeCausals) && (!$r->financial_movement || $r->financial_movement == null) && (!$r->corrispettivo_fiscale || $r->corrispettivo_fiscale == null)) { $total += $rr->amount; if ($rr->vat_id > 0) $total += getVatValue($rr->amount, $rr->vat_id); } } } $count = $x->count(); $x = $x->orderBy('date', 'DESC')->orderBy('id', 'DESC'); $x = $x->offset($start)->limit($limit)->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->financial_movement ? 'Movimento finanziario' : ($r->commercial ? 'SI' : 'NO'), 'causals' => $causals, 'payment' => $r->payment_method->name, 'status' => $r->deleted ? 'Annullato' : '', 'action' => $r->id . "|" . formatPrice($total) . "|" . ($r->deleted ? 'x' : '') ); } /*$datas[] = array( //'id' => $r->id, 'date' => '', 'total' => formatPrice($total), 'first_name' => '', 'last_name' => '', 'commercial' => '', 'causals' => '', 'payment' => '', 'status' => '', 'action' => '' );*/ return json_encode(array("data" => $datas, "recordsTotal" => $count, "recordsFiltered" => $count)); }); 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!'); });