122 lines
4.0 KiB
PHP
122 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
// Add This For Import DOMPDF Library
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
|
|
|
|
class NotificationController extends Controller
|
|
{
|
|
//Function Retrieve Current Rainfall Notification
|
|
public function rainfallNotification()
|
|
{
|
|
$rainfallData =collect( DB::select("
|
|
SELECT s.*, n.*
|
|
FROM station s
|
|
INNER JOIN notification n ON s.stationid = n.stationid
|
|
WHERE n.stationtype = 1
|
|
AND n.timestamp::date = CURRENT_DATE
|
|
ORDER BY n.timestamp desc
|
|
"));
|
|
|
|
return view('layout.notification.rainfall',compact('rainfallData'));
|
|
}
|
|
|
|
// Function Retrieve Current Water Level Notification
|
|
public function wlNotification()
|
|
{
|
|
$wlData = collect(DB::select("
|
|
SELECT s.*,n.*
|
|
FROM station s
|
|
INNER JOIN notification n ON s.stationid = n.stationid
|
|
WHERE n.stationtype = 2
|
|
AND n.timestamp::date = CURRENT_DATE
|
|
ORDER BY timestamp desc
|
|
"));
|
|
|
|
return view('layout.notification.waterlevel',compact('wlData'));
|
|
}
|
|
|
|
// Function Retrieve Current Siren Notification
|
|
public function SirenNotification()
|
|
{
|
|
$sirenData = collect(DB::select("
|
|
SELECT
|
|
station.*,
|
|
siren.*
|
|
FROM station
|
|
INNER JOIN siren ON station.stationid = siren.stationid
|
|
INNER JOIN (
|
|
SELECT stationid, MAX(active_time) AS active_time
|
|
FROM siren
|
|
GROUP BY stationid
|
|
) latest ON siren.stationid = latest.stationid
|
|
AND siren.active_time = latest.active_time
|
|
WHERE station.siren = 1 AND siren.level != 'N' AND siren.active_time >= CURRENT_DATE - INTERVAL '3 days'
|
|
ORDER BY siren.active_time DESC
|
|
"));
|
|
|
|
return view('layout.notification.siren',compact('sirenData'));
|
|
}
|
|
|
|
// Function Retrieve Rainfall Notification History
|
|
public function rfHistory()
|
|
{
|
|
$rfHistory = DB::table('station')
|
|
->join('notification','station.stationid','notification.stationid')
|
|
->select('station.*','notification.*')
|
|
->where('notification.stationtype',1)
|
|
->orderByDesc('notification.timestamp')
|
|
->paginate(10);
|
|
return view('layout.notification.history.rainfall',compact('rfHistory'));
|
|
}
|
|
|
|
// Function Retrieve Water Level History
|
|
public function wlHistory()
|
|
{
|
|
$wlHistory = DB::table('station')
|
|
->join('notification','station.stationid','notification.stationid')
|
|
->select('station.*','notification.*')
|
|
->where('notification.stationtype',2)
|
|
->orderByDesc('notification.timestamp')
|
|
->paginate(10);
|
|
return view('layout.notification.history.waterlevel',compact('wlHistory'));
|
|
}
|
|
|
|
//Function Export PDF for Rainfall History
|
|
public function exportHistoryRfPDF()
|
|
{
|
|
$rfHistory = DB::table('station')
|
|
->join('notification','station.stationid','notification.stationid')
|
|
->select('station.*','notification.*')
|
|
->where('notification.stationtype',1)
|
|
->orderByDesc('notification.timestamp')->get();
|
|
|
|
$pdf = Pdf::loadView('pdf.rfhistory',compact('rfHistory'))
|
|
->setPaper('a4','portrait');
|
|
|
|
return $pdf->download('Rainfall Alarm History.pdf');
|
|
|
|
}
|
|
|
|
// Function Export PDF for Water Level History
|
|
public function exportHistoryWlPDF()
|
|
{
|
|
$wlHistory = DB::table('station')
|
|
->join('notification','station.stationid','notification.stationid')
|
|
->select('station.*','notification.*')
|
|
->where('notification.stationtype',2)
|
|
->orderByDesc('notification.timestamp')->get();
|
|
|
|
$pdf = Pdf::loadView('pdf.wlhistory',compact('wlHistory'))
|
|
->setPaper('a4','portrait');
|
|
|
|
return $pdf->download('Water Level Alarm History.pdf');
|
|
|
|
}
|
|
}
|