| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- <?php
- use Illuminate\Support\Facades\Route;
- use Barryvdh\DomPDF\Facade\Pdf;
- /*
- |--------------------------------------------------------------------------
- | Web Routes
- |--------------------------------------------------------------------------
- |
- | Here is where you can register web routes for your application. These
- | routes are loaded by the RouteServiceProvider within a group which
- | contains the "web" middleware group. Now create something great!
- |
- */
- Route::get('/', function () {
- return view('login');
- // return Redirect::to('/dashboard');
- });
- //Route::get('/', \App\Http\Livewire\Login::class);
- Route::get('/dashboard', \App\Http\Livewire\Dashboard::class);
- Route::get('/settings', \App\Http\Livewire\Setting::class);
- Route::get('/courses', \App\Http\Livewire\Course::class);
- Route::get('/categories', \App\Http\Livewire\Category::class);
- Route::get('/nations_list', \App\Http\Livewire\Nation::class);
- Route::get('/provinces', \App\Http\Livewire\Province::class);
- Route::get('/cities', \App\Http\Livewire\City::class);
- Route::get('/banks', \App\Http\Livewire\Bank::class);
- Route::get('/vats', \App\Http\Livewire\Vat::class);
- Route::get('/disciplines', \App\Http\Livewire\Discipline::class);
- Route::get('/course_types', \App\Http\Livewire\CourseType::class);
- Route::get('/course_subscriptions', \App\Http\Livewire\CourseSubscription::class);
- Route::get('/course_durations', \App\Http\Livewire\CourseDuration::class);
- Route::get('/course_levels', \App\Http\Livewire\CourseLevel::class);
- Route::get('/course_frequencies', \App\Http\Livewire\CourseFrequency::class);
- Route::get('/course_list', \App\Http\Livewire\CourseList::class);
- Route::get('/course_member', \App\Http\Livewire\CourseMember::class);
- Route::get('/receipts', \App\Http\Livewire\Receipt::class);
- Route::get('/cards', \App\Http\Livewire\Card::class);
- Route::get('/causals', \App\Http\Livewire\Causal::class);
- Route::get('/payment_methods', \App\Http\Livewire\PaymentMethod::class);
- Route::get('/members', \App\Http\Livewire\Member::class);
- Route::get('/suppliers', \App\Http\Livewire\Supplier::class);
- Route::get('/sponsors', \App\Http\Livewire\Sponsor::class);
- Route::get('/records', \App\Http\Livewire\Record::class);
- Route::get('/reminders', \App\Http\Livewire\Reminder::class);
- Route::get('/in', \App\Http\Livewire\RecordIN::class);
- Route::get('/out', \App\Http\Livewire\RecordOUT::class);
- Route::get('/records_in_out', \App\Http\Livewire\RecordINOUT::class);
- Route::get('/receipt/{id}', function($id){
- $receipt = \App\Models\Receipt::findOrFail($id);
- $pdf = PDF::loadView('receipt', array('receipt' => $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() . "<br>";
- }
- $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() . "<br>";
- }
- $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!');
- });
|