Commit 6ce325f8 by Febry San

feat: query terbaru fitler undangan

parent f445df84
...@@ -35,24 +35,29 @@ public function index(Request $request) ...@@ -35,24 +35,29 @@ public function index(Request $request)
$tahun = '2023'; $tahun = '2023';
$nip = '197410082006041002'; $nip = '197410082006041002';
// $data = UserAgenda::whereDate('start', '>=', $request->start) // * CEK SURAT KELUAR
// ->whereDate('end', '<=', $request->end) $sql = "SELECT
// ->get(['id', 'title', 'start', 'end']); tr_surat_keluar.id as id,
tr_surat_keluar.perihal as title,
$data = DB::connection('eoffice')->table('tr_surat_masuk') tr_surat_keluar.tglmulai as start,
->select('tr_surat_masuk.id', 'tr_surat_masuk.perihal as title', 'tr_surat_masuk.tglmulai as start', 'tr_surat_masuk.tglmulai as end', 'tr_surat_masuk.jam_mulai', 'tr_surat_masuk.jam_selesai') tr_surat_keluar.tglselesai as end,
->leftJoin('tr_penerima_surat_masuk as a', 'a.idsurat', '=', 'tr_surat_masuk.id') tr_surat_keluar.jam_mulai,
->where('a.nip', $nip) tr_surat_keluar.jam_selesai
// ->where('tr_surat_masuk.perihal', 'like', '%undangan%') FROM
->where('tr_surat_masuk.tglmulai', '>=', $request->start) tr_surat_keluar
->where('tr_surat_masuk.tglmulai', '<=', $request->end) LEFT JOIN tr_penerima_surat_keluar AS a ON a.idsurat = tr_surat_keluar.id
// ->where('tr_surat_masuk.tahun', $tahun) WHERE
->get(['id', 'title', 'start', 'end']); a.nip = '199405072022032014'
// dd($data); AND tr_surat_keluar.tglmulai >= '$request->start'
AND tr_surat_keluar.tglselesai <= '$request->end'
AND UPPER(tr_surat_keluar.perihal :: TEXT) LIKE '%UNDANGAN%' ";
$keluar = DB::connection('eoffice')->select($sql);
$getData = array(); $getData = array();
$i = 0; $i = 0;
foreach ($data as $item) { foreach ($keluar as $item) {
if ($item->jam_mulai !== null) { if ($item->jam_mulai !== null ) {
$date = $item->start . ' ' . $item->jam_mulai; $date = $item->start . ' ' . $item->jam_mulai;
$newDate = date('Y-m-d H:i:s', strtotime($date)); $newDate = date('Y-m-d H:i:s', strtotime($date));
...@@ -66,7 +71,7 @@ public function index(Request $request) ...@@ -66,7 +71,7 @@ public function index(Request $request)
$start = $newDate; $start = $newDate;
} }
if ($item->jam_selesai !== null) { if ($item->jam_selesai !== null and $item->jam_mulai < $item->jam_selesai) {
$date = $item->start . ' ' . $item->jam_selesai; $date = $item->start . ' ' . $item->jam_selesai;
$newDate = date('Y-m-d H:i:s', strtotime($date)); $newDate = date('Y-m-d H:i:s', strtotime($date));
...@@ -85,22 +90,66 @@ public function index(Request $request) ...@@ -85,22 +90,66 @@ public function index(Request $request)
'title' => $item->title, 'title' => $item->title,
'start' => $start, 'start' => $start,
'end' => $end, 'end' => $end,
]; ];
// $getData[$i++]['title'] = $item->title; }
// $getData[$i++]['start'] = $item->start;
// $getData[$i++]['end'] = $item->end; // * CEK SURAT MASUK
$sql = "SELECT
tr_surat_masuk.id as id,
tr_surat_masuk.perihal as title,
tr_surat_masuk.tglmulai as start,
tr_surat_masuk.tglselesai as end,
tr_surat_masuk.jam_mulai,
tr_surat_masuk.jam_selesai
FROM
tr_surat_masuk
LEFT JOIN tr_penerima_surat_masuk AS a ON a.idsurat = tr_surat_masuk.id
WHERE
a.nip = '199405072022032014'
AND tr_surat_masuk.tglmulai >= '$request->start'
AND tr_surat_masuk.tglselesai <= '$request->end'
AND UPPER(tr_surat_masuk.perihal :: TEXT) LIKE '%UNDANGAN%' ";
$masuk = DB::connection('eoffice')->select($sql);
$i = 0;
foreach ($masuk as $item) {
if ($item->jam_mulai !== null ) {
$date = $item->start . ' ' . $item->jam_mulai;
$newDate = date('Y-m-d H:i:s', strtotime($date));
$start = $newDate;
} else {
$date = $item->start . ' 08:00:00';
$newDate = date('Y-m-d H:i:s', strtotime($date));
$start = $newDate;
}
if ($item->jam_selesai !== null and $item->jam_mulai < $item->jam_selesai) {
$date = $item->start . ' ' . $item->jam_selesai;
$newDate = date('Y-m-d H:i:s', strtotime($date));
$end = $newDate;
} else {
$date = $item->start . ' 16:00:00';
$newDate = date('Y-m-d H:i:s', strtotime($date));
$end = $newDate;
}
$getData[$i++] = [
'id' => $item->id,
'title' => $item->title,
'start' => $start,
'end' => $end,
];
} }
// $data['surat_keluar_eoffice'] = DB::connection('eoffice')->table('tr_surat_keluar')
// ->select('tr_surat_keluar.perihal', 'tr_surat_keluar.tglmulai', 'tr_surat_keluar.jam_mulai', 'tr_surat_keluar.jam_selesai')
// ->leftJoin('tr_penerima_surat_keluar as a', 'a.idsurat', '=', 'tr_surat_keluar.id')
// ->where('a.nip', $nip)
// ->where('tr_surat_keluar.perihal', 'like', '%undangan%')
// ->where('tr_surat_keluar.tahun', $tahun)
// ->get();
// dd($surat);
return response()->json($getData); return response()->json($getData);
} }
// $data = UserAgenda::all(); // $data = UserAgenda::all();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment