# Conflicts:
#	Http/Controllers/FrontendController.php
This commit is contained in:
Daeng Deni Mardaeni 2023-09-13 23:38:21 +07:00
commit 540869408d

View File

@ -1,99 +1,98 @@
<?php
namespace Modules\Frontend\Http\Controllers;
namespace Modules\Frontend\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Revolution\Google\Sheets\Facades\Sheets;
use Carbon\Carbon;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Revolution\Google\Sheets\Facades\Sheets;
class FrontendController extends Controller
{
class FrontendController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Renderable
*/
public function index()
{
if (File::exists('storage/kurs.json')) {
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
if($kurs->date != date('Y-m-d')){
$date = Carbon::createFromTimestamp($kurs->time_last_update_unix)->format('Y-m-d');
if ($date != date('Y-m-d')) {
$this->getKurs();
}
} else {
$this->getKurs();
}
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
$usd = $kurs->rates->IDR/$kurs->rates->USD;
$date = Carbon::createFromTimestamp($kurs->timestamp)->locale('id')->setTimezone('Asia/Jakarta')->translatedFormat('d F Y H:i:s');
$usd = $kurs->conversion_rate;
$sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')->sheet('Platform')->range('A:F')->get();
$date = Carbon::createFromTimestamp($kurs->time_last_update_unix)
->locale('id')
->setTimezone('Asia/Jakarta')
->translatedFormat('d F Y H:i:s');
$sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')
->sheet('Platform')
->range('A:F')
->get();
$header = $sheets->pull(0);
$posts = Sheets::collection($header, $sheets);
$posts = $posts->take(5000);
$data = new Collection($posts->toArray());
$platform = $data->random(5);
return view('frontend::index', compact('kurs', 'usd','date','platform'));
}
public function ont()
{
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
if($kurs->date != date('Y-m-d')){
$this->getKurs();
}
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
$usd = $kurs->rates->IDR/$kurs->rates->USD;
$date = Carbon::createFromTimestamp($kurs->timestamp)->locale('id')->setTimezone('Asia/Jakarta')->translatedFormat('d F Y H:i:s');
$sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')->sheet('Platform')->range('A:F')->get();
$header = $sheets->pull(0);
$posts = Sheets::collection($header, $sheets);
$posts = $posts->take(5000);
$data = new Collection($posts->toArray());
$platform = $data->random(5);
return view('frontend::ont', compact('kurs', 'usd','date','platform'));
}
public function press()
{
return view('frontend::press-release');
return view('frontend::index', compact('kurs', 'usd', 'date', 'platform'));
}
public function cakupan()
{
if (File::exists('storage/kurs.json')) {
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
if($kurs->date != date('Y-m-d')){
$date = Carbon::createFromTimestamp($kurs->time_last_update_unix)->format('Y-m-d');
if ($date != date('Y-m-d')) {
$this->getKurs();
}
} else {
$this->getKurs();
}
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
$usd = $kurs->rates->IDR/$kurs->rates->USD;
$date = Carbon::createFromTimestamp($kurs->timestamp)->locale('id')->setTimezone('Asia/Jakarta')->translatedFormat('d F Y H:i:s');
$usd = $kurs->conversion_rate;
$date = Carbon::createFromTimestamp($kurs->time_last_update_unix)
->locale('id')
->setTimezone('Asia/Jakarta')
->translatedFormat('d F Y H:i:s');
$sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')->sheet('Platform')->range('A:F')->get();
$sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')
->sheet('Platform')
->range('A:F')
->get();
$header = $sheets->pull(0);
$posts = Sheets::collection($header, $sheets);
$data = new Collection($posts->toArray());
return view('frontend::cakupan', compact('kurs', 'usd','date','data'));
return view('frontend::cakupan', compact('kurs', 'usd', 'date', 'data'));
}
public function peneliti()
{
$sheets = Sheets::spreadsheet('1kM32QnxjRDpH1WkFSfOwMuTKzoCQpXFDYhekARcypjY')->sheet('Research Proposal')->range('A:K')->get();
$sheets = Sheets::spreadsheet('1kM32QnxjRDpH1WkFSfOwMuTKzoCQpXFDYhekARcypjY')
->sheet('Research Proposal')
->range('A:K')
->get();
$header = $sheets->pull(0);
$posts = Sheets::collection($header, $sheets);
$posts = $posts->take(5000);
@ -126,7 +125,9 @@ class FrontendController extends Controller
public function facility()
{
$sheets = Sheets::spreadsheet('1kM32QnxjRDpH1WkFSfOwMuTKzoCQpXFDYhekARcypjY')->sheet('Sequencing Facility')->get();
$sheets = Sheets::spreadsheet('1kM32QnxjRDpH1WkFSfOwMuTKzoCQpXFDYhekARcypjY')
->sheet('Sequencing Facility')
->get();
$header = $sheets->pull(0);
$posts = Sheets::collection($header, $sheets);
$posts = $posts->take(5000);
@ -173,13 +174,15 @@ class FrontendController extends Controller
{
return view('frontend::ci');
}
public function silx_ic()
{
return view('frontend::ic');
}
public function getKurs(){
$response = Http::get('http://api.exchangeratesapi.io/v1/latest?access_key=9f7cd7db5b72280a93c8e15243fadab7&symbols=USD,IDR');
public function getKurs()
{
$response = Http::get('https://v6.exchangerate-api.com/v6/7ac9163481b1e658bc0ef6a5/pair/USD/IDR');
$data = $response->json();
Storage::disk('public')->put('kurs.json', json_encode($data));
}
@ -202,4 +205,4 @@ class FrontendController extends Controller
return view('frontend::domain');
}
}
}
}