delete, update photo marhun

This commit is contained in:
Amir
2022-09-05 14:33:58 +08:00
parent 2327b98b30
commit cf972c0d68
3 changed files with 153 additions and 46 deletions
+46 -15
View File
@@ -416,13 +416,15 @@ class MarhunController extends Controller
$filemarhun = FileMarhun::where('lelongbid_id', '=', $lelongbid['id'])
->where('photo_type', '=', '1')->first();
if (isset($filemarhun)) {
$lelongbid->filemarhun = $filemarhun->filename;
$lelongbid->filemarhun_filename = $filemarhun->filename;
$lelongbid->filemarhun_id = $filemarhun->id;
}
$marhun = LelongBidMarhun::where('lelongbid_id', '=', $id)->get();
foreach ($marhun as $index) {
$eachmarhun = FileMarhun::where('lelongbidmarhun_id', '=', $index['id'])->first();
if (isset($eachmarhun)) {
$index->eachmarhun = $eachmarhun->filename;
$index->eachmarhun_filename = $eachmarhun->filename;
$index->eachmarhun_id = $eachmarhun->id;
}
}
$lelkarat = LelKarat::where('lelong_id','=',$lelongbid->lelong_id)->get();
@@ -1131,29 +1133,58 @@ class MarhunController extends Controller
return view('marhun.scanbarcode');
}
public function addPhotoMarhun(Request $request) {
public function addPhotoMarhun(Request $request)
{
$data = base64_encode($request->gambarMarhun->get());
$file_type = $request->gambarMarhun->extension();
$addfile = new FileMarhun();
$addfile->lelongbid_id = $request->lelongbid_id;
$addfile->file_type = $file_type;
$addfile->filename = $data;
if ($request->photo_type == 1) {
$addfile = new FileMarhun();
$addfile->lelongbid_id = $request->lelongbid_id;
$addfile->photo_type = 1;
$addfile->file_type = $file_type;
$addfile->filename = $data;
$addfile->save();
}
else if ($request->photo_type == 2) {
$addfile = new FileMarhun();
$addfile->lelongbid_id = $request->lelongbid_id;
$addfile->lelongbidmarhun_id = $request->lelongbidmarhun_id;
} else if ($request->photo_type == 2) {
$addfile->photo_type = 2;
$addfile->file_type = $file_type;
$addfile->filename = $data;
$addfile->lelongbidmarhun_id = $request->lelongbidmarhun_id;
$addfile->save();
}
return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id])
->with('success','Gambar Berjaya Di Simpan.');
->with('success', 'Gambar Berjaya Di Simpan.');
}
public function deletePhotoMarhun(Request $request)
{
$deleteFile = FileMarhun::where('id', '=', $request->filemarhun_id)->first();
$deleteFile->delete();
return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id])
->with('success', 'Gambar Berjaya Di Padam.');
}
public function updatePhotoMarhun(Request $request)
{
$data = base64_encode($request->gambarMarhun->get());
$file_type = $request->gambarMarhun->extension();
$addfile = new FileMarhun();
$addfile->lelongbid_id = $request->lelongbid_id;
$addfile->file_type = $file_type;
$addfile->filename = $data;
if ($request->photo_type == 1) {
$addfile->photo_type = 1;
$addfile->save();
} else if ($request->photo_type == 2) {
$addfile->photo_type = 2;
$addfile->lelongbidmarhun_id = $request->lelongbidmarhun_id;
$addfile->save();
}
$deleteFile = FileMarhun::where('id', '=', $request->filemarhun_id)->first();
$deleteFile->delete();
return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id])
->with('success', 'Gambar Berjaya Di Tukar.');
}
}
+105 -31
View File
@@ -5,13 +5,19 @@
<div class="row ">
<div class="col-md-11 mx-auto card p-4">
<div class="row">
<a href=" {{ route('marhun.senaraimarhun', ['lelong_id'=>$lelongbid->lelong_id]) }}" class="btn btn-secondary">Kembali</a>
<a href=" {{ route('marhun.senaraimarhun', ['lelong_id'=>$lelongbid->lelong_id]) }}" class="btn ml-3 btn-secondary">Kembali</a>
</div>
@if ($message = Session::get('success'))
<div class="alert mt-2 alert-success">
<p>{{ $message }}</p>
</div>
@endif
<form id="deletePhoto" action="{{route('marhun.deletephotomarhun')}}" method="POST">
@csrf
<input type="hidden" id="filemarhun_id" name="filemarhun_id" value="">
<input type="hidden" name="lelongbid_id" value="{{ $lelongbid['id'] }}">
<input type="hidden" name="lelong_id" value="{{ $lelongbid['lelong_id'] }}">
</form>
<form id="formdelete" action="{{ route('marhun.submitdelete') }}" method="POST">
@csrf
<input type="hidden" name="type" value="User">
@@ -32,9 +38,9 @@
<div class="card">
<div class="card-header">Keseluruhan Marhun</div>
<div class="card-body" style="align-self: center; justify-content: center;">
@if ($lelongbid['filemarhun'] != null)
<button type="button" data-toggle="modal" onclick="kesulurahanMarhunData(this)" data-keseluruhanMarhun="{{ $lelongbid['filemarhun'] }}" data-target="#modaloverallphoto">
<img src="data:image/png;base64, {{ $lelongbid['filemarhun'] }}" alt="Image Preview" style="max-width:300px; border: 1px solid #dee2e6" />
@if ($lelongbid['filemarhun_filename'] != null)
<button type="button" data-toggle="modal" onclick="kesulurahanMarhunData(this)" data-lelongid="{{$lelongbid['lelong_id']}}" data-lelongbidid="{{$lelongbid['id']}}" data-fileid="{{ $lelongbid['filemarhun_id'] }}" data-target="#modaloverallphoto">
<img src="data:image/png;base64, {{ $lelongbid['filemarhun_filename'] }}" alt="Image Preview" style="max-width:300px; border: 1px solid #dee2e6" />
</button>
@else
<p>Tiada Data</p>
@@ -61,13 +67,12 @@
</tr>
</thead>
<tbody>
@foreach ($marhun as $item)
<tr>
<td class="text-center"> {{ $loop->iteration }} </td>
<td class="p-2 m-2" style="border: 1px solid black; width: 100px; height: 130px">
<button data-toggle="modal" onclick="marhunData(this)" data-loop="{{$loop->iteration}}" data-marhun="{{$item->marhun}}" data-id="{{$item->id}}" data-target="#modaleachphoto">
<img src="data:image/png;base64, {{ $item->eachmarhun }}" alt="Tambah / Padam Gambar" style="max-width:100px; border: 1px solid #dee2e6" />
<button data-toggle="modal" onclick="eachMarhunData(this)" data-lelongid="{{$lelongbid['lelong_id']}}" data-lelongbidid="{{$lelongbid['id']}}" data-loop="{{$loop->iteration}}" data-fileid="{{$item->eachmarhun_id}}" data-filename="{{$item->eachmarhun_filename}}" data-marhun="{{$item->marhun}}" data-marhunid="{{$item->id}}" data-target="#modaleachphoto">
<img src="data:image/png;base64, {{ $item->eachmarhun_filename }}" alt="Tambah / Padam Gambar" style="max-width:100px; border: 1px solid #dee2e6" />
</button>
</td>
<td>{{ $item->marhun }}</td>
@@ -186,7 +191,7 @@
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" style="width:15%;" data-dismiss="modal">Tutup</button>
<button type="button" class="btn btn-secondary" style="width:15%;" data-dismiss="modal">Kembali</button>
<button type="button" class="btn btn-primary" style="width:15%;" onclick="updateform()">Simpan</button>
</div>
@@ -245,7 +250,7 @@
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" style="width:15%;" data-dismiss="modal">Tutup</button>
<button type="button" class="btn btn-secondary" style="width:15%;" data-dismiss="modal">Kembali</button>
<button type="button" class="btn btn-primary" style="width:15%;" onclick="tambahanmarhun()">Simpan</button>
</div>
@@ -267,7 +272,7 @@
<input type="hidden" name="lelong_id" value="{{ $lelongbid['lelong_id'] }}">
<input type="hidden" name="photo_type" value="1">
<div class="modal-body justify-content-center">
@if (!isset($lelongbid->filemarhun))
@if (!isset($lelongbid->filemarhun_filename))
<div class="row justify-content-center">
<div class="col-8">
<input type="file" accept="image/*;capture=camera" name="gambarMarhun" id="inputGroupFile04" /><br>
@@ -275,8 +280,8 @@
</div>
@else
<div class="row mt-5 justify-content-center">
<button data-dismiss="modal" class="btn m-2 btn-warning">tukar gambar</button>
<button data-dismiss="modal" class="btn m-2 btn-danger">padam gambar</button>
<button data-dismiss="modal" onclick="updatePhoto(1)" type="button" data-target="#modalupdatephoto" data-toggle="modal" class="btn m-2 btn-warning">Tukar Gambar</button>
<button data-dismiss="modal" onclick="confirmDeletePhoto()" class="btn m-2 btn-danger">Padam Gambar</button>
</div>
@endif
</div>
@@ -293,8 +298,8 @@
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="titleHeader" value="titleHeader">Marhun, Bil:</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<h5 class="modal-title" id="titleHeader" value="titleHeader"></h5>
<button type="button" onclick="clearData()" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
@@ -305,19 +310,46 @@
<input type="hidden" name="photo_type" value="2">
<input type="hidden" name="lelongbidmarhun_id" id="marhun_id" value="">
<div class="modal-body justify-content-center">
<!-- <div class="row justify-content-center">
<img id="blah" style="max-width: 400px; max-height: 400px;" src="#" alt="gambar marhun" />
</div> -->
<div class="row justify-content-center">
<div id="createPhoto" hidden class="row justify-content-center">
<input type='file' accept="image/*;capture=camera" name="gambarMarhun" id="inputGroupFile04" /><br>
</div>
<div class="row mt-5 justify-content-center">
<button data-dismiss="modal" class="btn m-2 btn-warning">tukar gambar</button>
<button data-dismiss="modal" class="btn m-2 btn-danger">padam gambar</button>
<div id="updateDeletePhoto" hidden class="row mt-5 justify-content-center">
<button data-dismiss="modal" onclick="updatePhoto(2)" type="button" data-target="#modalupdatephoto" data-toggle="modal" class="btn m-2 btn-warning">Tukar Gambar</button>
<button data-dismiss="modal" onclick="confirmDeletePhoto()" class="btn m-2 btn-danger">Padam Gambar</button>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" style="width:15%;" data-dismiss="modal">Tutup</button>
<button type="button" class="btn btn-secondary" onclick="clearData()" tyle="width:15%;" data-dismiss="modal">Kembali</button>
<button type="submit" class="btn btn-primary" style="width:15%;">Simpan</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" id="modalupdatephoto">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Tukar Gambar</h5>
<button type="button" onclick="clearData()" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="{{route('marhun.updatephotomarhun')}}" method="POST" enctype="multipart/form-data">
@csrf
<input type="hidden" id="val1" name="lelongbid_id" value="">
<input type="hidden" id="val2" name="lelongbidmarhun_id" value="">
<input type="hidden" id="val3" name="filemarhun_id" value="">
<input type="hidden" id="val4" name="lelong_id" value="">
<input type="hidden" id="photo_type" name="photo_type" value="">
<div class="modal-body justify-content-center">
<div class="row justify-content-center">
<input type='file' accept="image/*;capture=camera" name="gambarMarhun" id="inputGroupFile04" /><br>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="clearData()" tyle="width:15%;" data-dismiss="modal">Kembali</button>
<button type="submit" class="btn btn-primary" style="width:15%;">Simpan</button>
</div>
</form>
@@ -329,25 +361,67 @@
<script>
function clearData() {
document.getElementById('inputGroupFile04').value = '';
document.getElementById('marhun_id').value = '';
document.getElementById('filemarhun_id').value = '';
}
function marhunData(value) {
id = $(value).data('id');
console.log(id);
function eachMarhunData(value) {
lelongId = $(value).data('lelongid');
marhunId = $(value).data('marhunid');
lelongBidId = $(value).data('lelongbidid');
marhun = $(value).data('marhun');
loop = $(value).data('loop');
document.getElementById('marhun_id').value = id;
document.getElementById("titleHeader").innerHTML = "Bil:" + loop + ", Id Marhun:" + id + ", Marhun:" + marhun;
fileId = $(value).data('fileid');
fileName = $(value).data('filename');
if (fileName == '') {
$("#createPhoto").attr("hidden", false);
$("#updateDeletePhoto").attr("hidden", true);
} else if (fileName != '') {
$("#createPhoto").attr("hidden", true);
$("#updateDeletePhoto").attr("hidden", false);
}
document.getElementById('marhun_id').value = marhunId;
document.getElementById('filemarhun_id').value = fileId;
document.getElementById("titleHeader").innerHTML = "Bil:" + loop + ", Id Marhun:" + marhunId + ", Marhun:" + marhun;
}
function kesulurahanMarhunData(value) {
console.log(value);
keseluruhanMarhun = $(value).data('keseluruhanMarhun');
document.getElementById('marhun_id').value = keseluruhanMarhun;
lelongBidId = $(value).data('lelongbidid');
marhunId = '';
fileId = $(value).data('fileid');
lelongId = $(value).data('lelongid');
document.getElementById('filemarhun_id').value = fileId;
}
function confirmDeletePhoto() {
$.confirm({
title: 'Perhatian!',
content: 'Padam gambar? Tindakan ini tidak dapat dikembalikan.',
type: 'red',
typeAnimated: true,
buttons: {
Batal: {
btnClass: 'btn-default',
action: function() {}
},
Sahkan: {
btnClass: 'btn-danger',
action: function() {
$("#deletePhoto").submit();
}
}
}
});
}
function updatePhoto(type) {
document.getElementById('val1').value = lelongBidId;
document.getElementById('val2').value = marhunId;
document.getElementById('val3').value = fileId;
document.getElementById('val4').value = lelongId;
document.getElementById('photo_type').value = type;
}
function confirm() {
$.confirm({
+2
View File
@@ -242,6 +242,8 @@ Route::group(['middleware' => ['permission:semakanmarhun','permission:kemaskinim
//Penilai
Route::post('/addphotomarhun',['as'=>'marhun.addphotomarhun','uses'=>'MarhunController@addPhotoMarhun']);
Route::post('/deletephotomarhun',['as'=>'marhun.deletephotomarhun','uses'=>'MarhunController@deletePhotoMarhun']);
Route::post('/updatephotomarhun',['as'=>'marhun.updatephotomarhun','uses'=>'MarhunController@updatePhotoMarhun']);
});
//Khazanah