Melakukan Perubahan

This commit is contained in:
Vinsensiaaa
2024-09-20 13:19:35 +07:00
parent 507986ccfb
commit 1e4155ff8a
+69 -53
View File
@@ -10,6 +10,7 @@ use Maatwebsite\Excel\Facades\Excel;
use App\Models\LaporanFile;
use App\Models\MappingDbhSkpd;
use App\Models\User;
use App\Models\Tropd;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Illuminate\Support\Facades\URL;
@@ -17,7 +18,8 @@ use Illuminate\Support\Facades\File;
class LaporanFileController extends Controller
{
public function __construct(){
public function __construct()
{
$this->siteTitle = "Laporan File";
parent::__construct();
$this->setIconTitle("fa fa-reply");
@@ -36,16 +38,15 @@ class LaporanFileController extends Controller
public function store(Request $request)
{
try{
try {
$date = date("Ymd");
DB::beginTransaction();
$req = $request->all();
$LaporanExists = LaporanFile::where("nama_laporan",$req["nama_laporan"])->count();
if ($LaporanExists > 0)
{
$LaporanExists = LaporanFile::where("nama_laporan", $req["nama_laporan"])->count();
if ($LaporanExists > 0) {
return redirect(URL::to("/laporan-file"))
->with('error','Data nama laporan '.$req["nama_laporan"].' sudah ada!');
->with('error', 'Data nama laporan ' . $req["nama_laporan"] . ' sudah ada!');
}
$this->validate($request, [
@@ -58,10 +59,10 @@ class LaporanFileController extends Controller
$data["nama_skpd"] = Auth::user()->name;
$data["nama_laporan"] = $req["nama_laporan"];
$file = $request->file('file');
if ($file){
if ($file) {
$fileName = $file->getClientOriginalName();
$ext = $file->getClientOriginalExtension();
$NewFileName = $req["nama_laporan"].".".$ext;
$NewFileName = $req["nama_laporan"] . "." . $ext;
$tujuan_upload = config('constants.upload_path_laporan');
File::isDirectory($tujuan_upload) or File::makeDirectory($tujuan_upload, 0777, true, true);
$file->move($tujuan_upload, $NewFileName);
@@ -70,31 +71,30 @@ class LaporanFileController extends Controller
LaporanFile::create($data);
DB::commit();
return redirect(URL::to("/laporan-file"))->with('success','Laporan berhasil dibuat!');
}catch(\Exception $e){
return redirect(URL::to("/laporan-file"))->with('success', 'Laporan berhasil dibuat!');
} catch (\Exception $e) {
DB::rollBack();
return redirect(URL::to("/laporan-file"))->with('error',$e->getMessage());
return redirect(URL::to("/laporan-file"))->with('error', $e->getMessage());
}
}
public function edit(LaporanFile $laporanFile)
{
$this->setSubtitle("Ubah Data");
return view('laporan_file.edit',compact('laporanFile'));
return view('laporan_file.edit', compact('laporanFile'));
}
public function update(Request $request, LaporanFile $laporanFile)
{
try{
try {
DB::beginTransaction();
$req = $request->all();
$LaporanExists = LaporanFile::where("nama_laporan",$req["nama_laporan"])->where("id","<>",$laporanFile->id)->count();
if ($LaporanExists > 0)
{
$LaporanExists = LaporanFile::where("nama_laporan", $req["nama_laporan"])->where("id", "<>", $laporanFile->id)->count();
if ($LaporanExists > 0) {
return redirect(URL::to("/laporan-file"))
->with('error','Data nama laporan '.$req["nama_laporan"].' sudah ada!');
->with('error', 'Data nama laporan ' . $req["nama_laporan"] . ' sudah ada!');
}
$this->validate($request, [
@@ -108,28 +108,28 @@ class LaporanFileController extends Controller
$data["nama_laporan"] = $req["nama_laporan"];
$file = $request->file('file');
$tujuan_upload = config('constants.upload_path_laporan');
if ($file){
if ($file) {
$fileName = $file->getClientOriginalName();
$ext = $file->getClientOriginalExtension();
$NewFileName = $req["nama_laporan"].".".$ext;
$NewFileName = $req["nama_laporan"] . "." . $ext;
File::isDirectory($tujuan_upload) or File::makeDirectory($tujuan_upload, 0777, true, true);
$file->move($tujuan_upload, $NewFileName);
$data["nama_file"] = $NewFileName;
}else{
$arrName = explode(".",$laporanFile->nama_file);
} else {
$arrName = explode(".", $laporanFile->nama_file);
$ext = end($arrName);
rename($tujuan_upload.$laporanFile->nama_file, $tujuan_upload.$req["nama_laporan"].".".$ext);
$data["nama_file"] = $req["nama_laporan"].".".$ext;
rename($tujuan_upload . $laporanFile->nama_file, $tujuan_upload . $req["nama_laporan"] . "." . $ext);
$data["nama_file"] = $req["nama_laporan"] . "." . $ext;
}
$laporanFile->update($data);
DB::commit();
return redirect(URL::to("/laporan-file"))->with('success','Laporan berhasil diubah.');
}catch(Throwable $e){
return redirect(URL::to("/laporan-file"))->with('success', 'Laporan berhasil diubah.');
} catch (Throwable $e) {
DB::rollBack();
return redirect(URL::to("/laporan-file"))->with('error','Laporan gagal diubah!');
return redirect(URL::to("/laporan-file"))->with('error', 'Laporan gagal diubah!');
}
}
@@ -138,64 +138,81 @@ class LaporanFileController extends Controller
$post = $request->all();
$offset = $post["start"];
$limit = $post["length"];
$kode_rekening = isset($post["kode_rekening"])?$post["kode_rekening"]:"";
$kode_rekening = isset($post["kode_rekening"]) ? $post["kode_rekening"] : "";
$ta = $post["ta"];
$src = isset($post["search"]["value"]) ? strtolower($post["search"]["value"]):"";
$src = isset($post["search"]["value"]) ? strtolower($post["search"]["value"]) : "";
$data = LaporanFile::where("tahun",$ta);
if (getRole()=="skpd"){
$data->whereIn("kode_skpd",[Auth::user()->nrk,'anggaran']);
$data->where(function($subquery){
$subquery->whereIn("kode_rekening",MappingDbhSkpd::whereIn("kode_skpd",[Auth::user()->nrk])->pluck("kode_rekening"));
$data = LaporanFile::where("tahun", $ta);
if (getRole() == "skpd") {
$data->whereIn("kode_skpd", [Auth::user()->nrk, 'anggaran']);
$data->where(function ($subquery) {
$subquery->whereIn("kode_rekening", MappingDbhSkpd::whereIn("kode_skpd", [Auth::user()->nrk])->pluck("kode_rekening"));
});
} elseif (getRole() == "sbpk") {
$data->whereIn("kode_skpd", function ($query) {
$query->select('C_OPD')
->from('NEWSIPKD.TROPD')
->where('C_WIL_SP2DPROSES', Auth::user()->wilayah);
});
$data->where(function ($subquery) {
$subquery->whereIn("kode_rekening", MappingDbhSkpd::whereIn("kode_skpd", [Auth::user()->nrk])->pluck("kode_rekening"));
});
} elseif (getRole() == "walikota") {
$id = Tropd::where("C_OPD", Auth::user()->nrk)->first()["i_id"];
$data->whereIn("kode_skpd", function ($query) use ($id) {
$query->select('C_OPD')
->from('NEWSIPKD.TROPD')
->where('I_IDINDUK', $id);
});
$data->where(function ($subquery) {
$subquery->whereIn("kode_rekening", MappingDbhSkpd::whereIn("kode_skpd", [Auth::user()->nrk])->pluck("kode_rekening"));
});
}
// var_dump(MappingDbhSkpd::whereIn("kode_skpd",[Auth::user()->nrk])->pluck("kode_rekening")); exit;
if($kode_rekening){
if ($kode_rekening) {
$data->where("kode_rekening", $kode_rekening);
}
if (!empty($src))
{
if (!empty($src)) {
$src = strtolower($src);
//$data->whereRaw("( LOWER(simtrad4_uraian) like '%".$src."%' OR LOWER(simtrad4_sp2d_bun) like '%".$src."%' OR LOWER(rkud_no_sts) like '%".$src."%')");
}
$dataFilter = $data->count();
$dataTotal = LaporanFile::where("tahun",$ta);
if (getRole()=="skpd"){
$dataTotal->where("kode_skpd",Auth::user()->nrk);
$dataTotal = LaporanFile::where("tahun", $ta);
if (getRole() == "skpd") {
$dataTotal->where("kode_skpd", Auth::user()->nrk);
}
return response()->json([
"recordsTotal" => $dataTotal->count(),
"recordsFiltered" => $dataFilter,
"data"=> $data->orderBy("created_at","ASC")->skip($offset)->take($limit)->get()
"data" => $data->orderBy("created_at", "ASC")->skip($offset)->take($limit)->get()
]);
}
public function destroy(LaporanFile $laporanFile)
{
try{
try {
DB::beginTransaction();
$alamatFile = config('constants.upload_path_laporan').$laporanFile->nama_file;
if (file_exists($alamatFile)){
$alamatFile = config('constants.upload_path_laporan') . $laporanFile->nama_file;
if (file_exists($alamatFile)) {
unlink($alamatFile);
}
$laporanFile->delete();
DB::commit();
return redirect(URL::to("/laporan-file"))->with('success','Data Laporan berhasil dihapus!');
}catch(Throwable $e){
return redirect(URL::to("/laporan-file"))->with('success', 'Data Laporan berhasil dihapus!');
} catch (Throwable $e) {
DB::rollBack();
return redirect(URL::to("/laporan-file"))->with('error','Data Laporan gagal dihapus.');
return redirect(URL::to("/laporan-file"))->with('error', 'Data Laporan gagal dihapus.');
}
}
public function show(LaporanFile $laporanFile)
{
$this->setSubtitle("Detail Data");
return view('laporan_file.show',compact("laporanFile"));
return view('laporan_file.show', compact("laporanFile"));
}
public function download($kode)
@@ -203,13 +220,12 @@ class LaporanFileController extends Controller
$laporanFile = LaporanFile::where("id", $kode)->firstorNew();
$headers = [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment;filename='.$laporanFile->nama_file
'Content-Disposition' => 'attachment;filename=' . $laporanFile->nama_file
];
if ($laporanFile){
return response()->download(config('constants.upload_path_laporan').$laporanFile->nama_file);
}else{
if ($laporanFile) {
return response()->download(config('constants.upload_path_laporan') . $laporanFile->nama_file);
} else {
echo "File tidak ditemukan!";
}
}
}