update
parent
f824852e8f
commit
395f424da3
|
|
@ -222,6 +222,46 @@ class FormController implements HasMiddleware
|
|||
return redirect()->back()->withErrors(['error' => 'Data gagal disimpan. Mohon dicoba kembali.' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
function editSingle(Request $request, $sector, $code) {
|
||||
$request->validate([
|
||||
// 'data' => 'required|array',
|
||||
]);
|
||||
|
||||
|
||||
|
||||
// Filter by Year
|
||||
$inventoryYear = $request->input('inventoryYear') ?? date('Y');
|
||||
$instansi = request('instansi') ?? @session('agency_id');
|
||||
if ($instansi && $instansi != 'all' && $instansi != 'none') {
|
||||
$agency = Agency::where('name', $instansi)->rowActive()->first();
|
||||
$instansi = $agency ? $agency->id : null;
|
||||
} else {
|
||||
$instansi = null;
|
||||
}
|
||||
|
||||
$data = $request->input('data');
|
||||
$unitCodes = $request->input('unit_code');
|
||||
|
||||
try {
|
||||
|
||||
foreach($request->unit_code as $k => $valCode){
|
||||
// dd($request->value[$k]);
|
||||
$detail = ActivityFormDetail::updateOrCreate([
|
||||
|
||||
'form_id' => @$form ? @$form->id : @$Saveform->id,
|
||||
'activity_year' => $request->inventoryYear,
|
||||
'activity_code' => $k,
|
||||
'activity_unit_code' => $valCode,
|
||||
],[
|
||||
'activity_value' => $request->value[$k],
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', 'Data berhasil disimpan.');
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->back()->withErrors(['error' => 'Data gagal disimpan. Mohon dicoba kembali.' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function convertUnit(Request $request)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
<div class="modal fade" id="formModalEdit" tabindex="-1" role="dialog" aria-labelledby="formModalLabel"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg" role="document" style="width:90%; max-width: 90%;">
|
||||
<div class="modal-content">
|
||||
<form action="{{ route('modules.form.editSingle', ['sector' => $form->sector, 'code' => $form->code]) }}" method="POST">
|
||||
@csrf
|
||||
<div class="modal-header">
|
||||
<div class="modal-title" id="formModalLabel">
|
||||
<b>Form Tambah Data Baru</b>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
<input type="hidden" name="id" id="metadataId">
|
||||
<input type="hidden" name="code_id" value="{{ $activityForm->id ?? 0 }}">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<div class="form-group">
|
||||
<label for="inventoryYear">Tahun Inventory:</label>
|
||||
<div class="input-group">
|
||||
<select name="inventoryYear" class="form-control">
|
||||
@for ($year = date('Y'); $year >= (date('Y')-5); $year--)
|
||||
<option value="{{ $year }}" {{ $inventoryYear == $year ? 'selected' : '' }} >
|
||||
{{ $year }}
|
||||
</option>
|
||||
@endfor
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<div class="">
|
||||
<label for="instansi">Instansi:</label>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<select name="instansi" id="instansi" class="form-control">
|
||||
@if (@$scope === \App\Enums\LingkupAksesData::ALL->value)
|
||||
<option value="none" @if ($instansi === null || $instansi == 'none') selected @endif>DATA KONSOLIDASI</option>
|
||||
@if ($agencies->isNotEmpty())
|
||||
<option value="all" @if ($instansi === 'all') selected @endif>SELURUH DATA DARI PRODUSEN</option>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
@foreach ($agencies as $agency)
|
||||
<option value="{{ $agency->name }}" @if ($instansi == $agency->name) selected @endif>
|
||||
{{ $agency->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@foreach ($formDetails as $detail)
|
||||
@php
|
||||
$unitCode = $detail->unit_code;
|
||||
$unitCategory = $unitsMap[$unitCode]->category ?? null;
|
||||
@endphp
|
||||
<div class="col-md-12 mb-3">
|
||||
<b>{{ $detail->activity ? $detail->activity->name : 'N/A' }}</b>
|
||||
@if ($unitCategory)
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control w-50 text-right" name="value[{{ $detail->activity_code }}]" oninput="numberFormat(this)">
|
||||
<div class="input-group-text p-0" style="width: 200px!important;">
|
||||
<select name="unit_code[{{ $detail->activity_code }}]" class="form-control unit-code"
|
||||
data-activity-code="{{ $detail->activity_code }}"
|
||||
data-current-unit="{{ $unitCode }}">
|
||||
@if (@$unitsByCategory[$unitCategory])
|
||||
@foreach (@$unitsByCategory[$unitCategory] as $unit)
|
||||
@if($unit->code == $unitCode)
|
||||
<option value="{{ $unit->code }}"
|
||||
{{ $unit->code == $unitCode ? 'selected' : '' }}>
|
||||
{{ $unit->code }}
|
||||
</option>
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
{{ $unitCode }}
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-primary">Simpan Data</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -243,6 +243,10 @@
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
$('.edit').on('click',function(){
|
||||
$('#formModalEdit').modal('show');
|
||||
});
|
||||
|
||||
function showCreateModal() {
|
||||
$('#formModal').modal('show');
|
||||
|
|
|
|||
|
|
@ -307,6 +307,7 @@ Route::name('management.')->prefix('management')->group(function () {
|
|||
Route::get('/', [FormController::class, 'show'])->name('form.show');
|
||||
Route::post('save', [FormController::class, 'save'])->name('form.save');
|
||||
Route::post('saveSingle', [FormController::class, 'saveSingle'])->name('form.saveSingle');
|
||||
Route::post('editSingle', [FormController::class, 'editSingle'])->name('form.editSingle');
|
||||
Route::get('conversion', [FormController::class, 'convertUnit'])->name('form.conversion');
|
||||
Route::post('{inventoryYear}/import/{instansi?}', [FormController::class, 'import'])->name('form.import');
|
||||
Route::get('{inventoryYear}/export/{instansi?}', [FormController::class, 'export'])->name('form.export');
|
||||
|
|
|
|||
Loading…
Reference in New Issue