Melakukan Perubahan
This commit is contained in:
@@ -10,6 +10,7 @@ use Maatwebsite\Excel\Facades\Excel;
|
|||||||
use App\Models\LaporanFile;
|
use App\Models\LaporanFile;
|
||||||
use App\Models\MappingDbhSkpd;
|
use App\Models\MappingDbhSkpd;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Tropd;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
use Illuminate\Support\Facades\URL;
|
use Illuminate\Support\Facades\URL;
|
||||||
@@ -17,7 +18,8 @@ use Illuminate\Support\Facades\File;
|
|||||||
|
|
||||||
class LaporanFileController extends Controller
|
class LaporanFileController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct(){
|
public function __construct()
|
||||||
|
{
|
||||||
$this->siteTitle = "Laporan File";
|
$this->siteTitle = "Laporan File";
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->setIconTitle("fa fa-reply");
|
$this->setIconTitle("fa fa-reply");
|
||||||
@@ -36,16 +38,15 @@ class LaporanFileController extends Controller
|
|||||||
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
try{
|
try {
|
||||||
$date = date("Ymd");
|
$date = date("Ymd");
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
|
||||||
$req = $request->all();
|
$req = $request->all();
|
||||||
$LaporanExists = LaporanFile::where("nama_laporan",$req["nama_laporan"])->count();
|
$LaporanExists = LaporanFile::where("nama_laporan", $req["nama_laporan"])->count();
|
||||||
if ($LaporanExists > 0)
|
if ($LaporanExists > 0) {
|
||||||
{
|
|
||||||
return redirect(URL::to("/laporan-file"))
|
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, [
|
$this->validate($request, [
|
||||||
@@ -58,10 +59,10 @@ class LaporanFileController extends Controller
|
|||||||
$data["nama_skpd"] = Auth::user()->name;
|
$data["nama_skpd"] = Auth::user()->name;
|
||||||
$data["nama_laporan"] = $req["nama_laporan"];
|
$data["nama_laporan"] = $req["nama_laporan"];
|
||||||
$file = $request->file('file');
|
$file = $request->file('file');
|
||||||
if ($file){
|
if ($file) {
|
||||||
$fileName = $file->getClientOriginalName();
|
$fileName = $file->getClientOriginalName();
|
||||||
$ext = $file->getClientOriginalExtension();
|
$ext = $file->getClientOriginalExtension();
|
||||||
$NewFileName = $req["nama_laporan"].".".$ext;
|
$NewFileName = $req["nama_laporan"] . "." . $ext;
|
||||||
$tujuan_upload = config('constants.upload_path_laporan');
|
$tujuan_upload = config('constants.upload_path_laporan');
|
||||||
File::isDirectory($tujuan_upload) or File::makeDirectory($tujuan_upload, 0777, true, true);
|
File::isDirectory($tujuan_upload) or File::makeDirectory($tujuan_upload, 0777, true, true);
|
||||||
$file->move($tujuan_upload, $NewFileName);
|
$file->move($tujuan_upload, $NewFileName);
|
||||||
@@ -70,31 +71,30 @@ class LaporanFileController extends Controller
|
|||||||
LaporanFile::create($data);
|
LaporanFile::create($data);
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
return redirect(URL::to("/laporan-file"))->with('success','Laporan berhasil dibuat!');
|
return redirect(URL::to("/laporan-file"))->with('success', 'Laporan berhasil dibuat!');
|
||||||
}catch(\Exception $e){
|
} catch (\Exception $e) {
|
||||||
DB::rollBack();
|
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)
|
public function edit(LaporanFile $laporanFile)
|
||||||
{
|
{
|
||||||
$this->setSubtitle("Ubah Data");
|
$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)
|
public function update(Request $request, LaporanFile $laporanFile)
|
||||||
{
|
{
|
||||||
try{
|
try {
|
||||||
|
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
|
||||||
$req = $request->all();
|
$req = $request->all();
|
||||||
$LaporanExists = LaporanFile::where("nama_laporan",$req["nama_laporan"])->where("id","<>",$laporanFile->id)->count();
|
$LaporanExists = LaporanFile::where("nama_laporan", $req["nama_laporan"])->where("id", "<>", $laporanFile->id)->count();
|
||||||
if ($LaporanExists > 0)
|
if ($LaporanExists > 0) {
|
||||||
{
|
|
||||||
return redirect(URL::to("/laporan-file"))
|
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, [
|
$this->validate($request, [
|
||||||
@@ -108,28 +108,28 @@ class LaporanFileController extends Controller
|
|||||||
$data["nama_laporan"] = $req["nama_laporan"];
|
$data["nama_laporan"] = $req["nama_laporan"];
|
||||||
$file = $request->file('file');
|
$file = $request->file('file');
|
||||||
$tujuan_upload = config('constants.upload_path_laporan');
|
$tujuan_upload = config('constants.upload_path_laporan');
|
||||||
if ($file){
|
if ($file) {
|
||||||
$fileName = $file->getClientOriginalName();
|
$fileName = $file->getClientOriginalName();
|
||||||
$ext = $file->getClientOriginalExtension();
|
$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::isDirectory($tujuan_upload) or File::makeDirectory($tujuan_upload, 0777, true, true);
|
||||||
$file->move($tujuan_upload, $NewFileName);
|
$file->move($tujuan_upload, $NewFileName);
|
||||||
$data["nama_file"] = $NewFileName;
|
$data["nama_file"] = $NewFileName;
|
||||||
}else{
|
} else {
|
||||||
$arrName = explode(".",$laporanFile->nama_file);
|
$arrName = explode(".", $laporanFile->nama_file);
|
||||||
$ext = end($arrName);
|
$ext = end($arrName);
|
||||||
rename($tujuan_upload.$laporanFile->nama_file, $tujuan_upload.$req["nama_laporan"].".".$ext);
|
rename($tujuan_upload . $laporanFile->nama_file, $tujuan_upload . $req["nama_laporan"] . "." . $ext);
|
||||||
$data["nama_file"] = $req["nama_laporan"].".".$ext;
|
$data["nama_file"] = $req["nama_laporan"] . "." . $ext;
|
||||||
}
|
}
|
||||||
$laporanFile->update($data);
|
$laporanFile->update($data);
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
return redirect(URL::to("/laporan-file"))->with('success','Laporan berhasil diubah.');
|
return redirect(URL::to("/laporan-file"))->with('success', 'Laporan berhasil diubah.');
|
||||||
}catch(Throwable $e){
|
} catch (Throwable $e) {
|
||||||
|
|
||||||
DB::rollBack();
|
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();
|
$post = $request->all();
|
||||||
$offset = $post["start"];
|
$offset = $post["start"];
|
||||||
$limit = $post["length"];
|
$limit = $post["length"];
|
||||||
$kode_rekening = isset($post["kode_rekening"])?$post["kode_rekening"]:"";
|
$kode_rekening = isset($post["kode_rekening"]) ? $post["kode_rekening"] : "";
|
||||||
$ta = $post["ta"];
|
$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);
|
$data = LaporanFile::where("tahun", $ta);
|
||||||
if (getRole()=="skpd"){
|
if (getRole() == "skpd") {
|
||||||
$data->whereIn("kode_skpd",[Auth::user()->nrk,'anggaran']);
|
$data->whereIn("kode_skpd", [Auth::user()->nrk, 'anggaran']);
|
||||||
$data->where(function($subquery){
|
$data->where(function ($subquery) {
|
||||||
$subquery->whereIn("kode_rekening",MappingDbhSkpd::whereIn("kode_skpd",[Auth::user()->nrk])->pluck("kode_rekening"));
|
$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;
|
// 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);
|
$data->where("kode_rekening", $kode_rekening);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($src))
|
if (!empty($src)) {
|
||||||
{
|
|
||||||
$src = strtolower($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."%')");
|
//$data->whereRaw("( LOWER(simtrad4_uraian) like '%".$src."%' OR LOWER(simtrad4_sp2d_bun) like '%".$src."%' OR LOWER(rkud_no_sts) like '%".$src."%')");
|
||||||
}
|
}
|
||||||
$dataFilter = $data->count();
|
$dataFilter = $data->count();
|
||||||
$dataTotal = LaporanFile::where("tahun",$ta);
|
$dataTotal = LaporanFile::where("tahun", $ta);
|
||||||
if (getRole()=="skpd"){
|
if (getRole() == "skpd") {
|
||||||
$dataTotal->where("kode_skpd",Auth::user()->nrk);
|
$dataTotal->where("kode_skpd", Auth::user()->nrk);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
"recordsTotal" => $dataTotal->count(),
|
"recordsTotal" => $dataTotal->count(),
|
||||||
"recordsFiltered" => $dataFilter,
|
"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)
|
public function destroy(LaporanFile $laporanFile)
|
||||||
{
|
{
|
||||||
try{
|
try {
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
$alamatFile = config('constants.upload_path_laporan').$laporanFile->nama_file;
|
$alamatFile = config('constants.upload_path_laporan') . $laporanFile->nama_file;
|
||||||
if (file_exists($alamatFile)){
|
if (file_exists($alamatFile)) {
|
||||||
unlink($alamatFile);
|
unlink($alamatFile);
|
||||||
}
|
}
|
||||||
$laporanFile->delete();
|
$laporanFile->delete();
|
||||||
DB::commit();
|
DB::commit();
|
||||||
return redirect(URL::to("/laporan-file"))->with('success','Data Laporan berhasil dihapus!');
|
return redirect(URL::to("/laporan-file"))->with('success', 'Data Laporan berhasil dihapus!');
|
||||||
|
} catch (Throwable $e) {
|
||||||
}catch(Throwable $e){
|
|
||||||
|
|
||||||
DB::rollBack();
|
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)
|
public function show(LaporanFile $laporanFile)
|
||||||
{
|
{
|
||||||
$this->setSubtitle("Detail Data");
|
$this->setSubtitle("Detail Data");
|
||||||
return view('laporan_file.show',compact("laporanFile"));
|
return view('laporan_file.show', compact("laporanFile"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function download($kode)
|
public function download($kode)
|
||||||
@@ -203,13 +220,12 @@ class LaporanFileController extends Controller
|
|||||||
$laporanFile = LaporanFile::where("id", $kode)->firstorNew();
|
$laporanFile = LaporanFile::where("id", $kode)->firstorNew();
|
||||||
$headers = [
|
$headers = [
|
||||||
'Content-Type' => 'application/pdf',
|
'Content-Type' => 'application/pdf',
|
||||||
'Content-Disposition' => 'attachment;filename='.$laporanFile->nama_file
|
'Content-Disposition' => 'attachment;filename=' . $laporanFile->nama_file
|
||||||
];
|
];
|
||||||
if ($laporanFile){
|
if ($laporanFile) {
|
||||||
return response()->download(config('constants.upload_path_laporan').$laporanFile->nama_file);
|
return response()->download(config('constants.upload_path_laporan') . $laporanFile->nama_file);
|
||||||
}else{
|
} else {
|
||||||
echo "File tidak ditemukan!";
|
echo "File tidak ditemukan!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user