425 lines
17 KiB
PHP
425 lines
17 KiB
PHP
@extends('layouts.master')
|
|
|
|
@section('title', $form->name)
|
|
|
|
@section('content')
|
|
@php
|
|
$user = Auth::user();
|
|
$scope = $user->getScope();
|
|
|
|
$inventoryYear = request('inventoryYear') ?? date('Y');
|
|
$instansi = request('instansi') ?? null;
|
|
|
|
if ($agencies->count() === 1 && $scope === \App\Enums\LingkupAksesData::INTERNAL->value) {
|
|
$instansi = $agencies[0]->name;
|
|
}
|
|
|
|
$param = [
|
|
'sector' => $form->sector,
|
|
'code' => $form->code,
|
|
'inventoryYear' => $inventoryYear,
|
|
'instansi' => $instansi,
|
|
];
|
|
|
|
$routeImport = route('modules.form.import', $param);
|
|
$routeExport = route('modules.form.export', $param);
|
|
$routeExportTemplate = route('modules.form.export', array_merge($param, ['isTemplate' => true]));
|
|
$routeApproval = route('modules.form.approval', $param);
|
|
|
|
$internal = $internal ?? null;
|
|
$limitInternal = ($internal !== null) && !$agencies->isNotEmpty();
|
|
@endphp
|
|
|
|
<div class="card shadow-sm" data-sector="{{ $form->sector }}" data-code="{{ $form->code }}">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0 font-weight-bold">{{ $form->name }}</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
|
|
@include('modules.form.action')
|
|
|
|
<form action="{{ route('modules.form.save', ['sector' => $form->sector, 'code' => $form->code]) }}" method="POST">
|
|
<input type="hidden" name="inventoryYear" value="{{ $inventoryYear }}">
|
|
<input type="hidden" name="instansi" value="{{ $instansi }}">
|
|
<div class=" mt-3" style="">
|
|
<table class="table table-bordered table-detail">
|
|
|
|
<tr>
|
|
<th>No.</th>
|
|
<th>Tahun</th>
|
|
@foreach ($formDetails as $detail)
|
|
@php
|
|
$unitCode = $detail->unit_code;
|
|
$unitCategory = $unitsMap[$unitCode]->category ?? null;
|
|
@endphp
|
|
<th style="min-width: 150px; text-decoration:normal">
|
|
{{ $detail->activity ? $detail->activity->name : 'N/A' }} - ({{ $detail->unit_code }})
|
|
|
|
@if ($unitCategory)
|
|
|
|
@else
|
|
{{ $unitCode }}
|
|
@endif
|
|
</th>
|
|
@endforeach
|
|
</tr>
|
|
@php
|
|
$years = activityYearRange($inventoryYear);
|
|
@endphp
|
|
@foreach ($years as $k => $year)
|
|
<tr>
|
|
<td>{{ $k+1 }}</td>
|
|
<td>{{ $year }}</td>
|
|
@foreach ($formDetails as $detail)
|
|
@php
|
|
$activity_value = isset($activityFormDetails[$year])
|
|
? $activityFormDetails[$year]
|
|
->where('activity_code', $detail->activity_code)
|
|
->where('activity_unit_code', $detail->unit_code)
|
|
->first()->activity_value ?? ''
|
|
: ''
|
|
@endphp
|
|
<td>
|
|
<div class="input-group">
|
|
<input type="text"
|
|
name="data[{{ $year }}][{{ $detail->activity_code }}-{{ $detail->unit_code }}]"
|
|
value="{{ @$activity_value == "" ? "" : getFormattedValue($activity_value)}}"
|
|
class="form-control text-right" oninput="numberFormat(this)"
|
|
{{ $isLocked || $instansi === 'all' || $limitInternal ? 'readonly' : '' }}>
|
|
</div>
|
|
</td>
|
|
@endforeach
|
|
</tr>
|
|
@endforeach
|
|
</table>
|
|
</form>
|
|
{{-- @include('modules.form.table') --}}
|
|
{{-- @include('modules.form.copy') --}}
|
|
</div>
|
|
</div>
|
|
@include('modules.form.import')
|
|
|
|
@if ($instansi !== 'all')
|
|
@include('modules.form.aktivitas-user')
|
|
@include('modules.form.metadata.index')
|
|
@endif
|
|
|
|
{{-- @include('modules.form.form') --}}
|
|
@endsection
|
|
|
|
@section('js')
|
|
<script>
|
|
var activitiesTable = null;
|
|
$(document).ready(function() {
|
|
$('#inventoryYear').select2({
|
|
placeholder: 'Pilih Tahun',
|
|
}).on('change', function() {
|
|
$('#filterForm').submit();
|
|
});
|
|
|
|
$('#instansi').select2().on('change', function() {
|
|
$('#filterForm').submit();
|
|
});
|
|
|
|
$('#from_year').select2({
|
|
placeholder: 'Pilih Tahun',
|
|
width: '100%',
|
|
});
|
|
|
|
$('.unit-code').select2({
|
|
placeholder: 'Pilih Unit',
|
|
});
|
|
|
|
$('#metadataForm').on('submit', function(e) {
|
|
e.preventDefault();
|
|
var formData = new FormData(this);
|
|
$.ajax({
|
|
url: '{{ route('modules.form.metadata.store') }}',
|
|
type: 'POST',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(response) {
|
|
Swal.fire({
|
|
title: 'Success!',
|
|
text: response.success,
|
|
icon: 'success',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
|
|
$('#name').val('');
|
|
$('#publisher').val('');
|
|
$('#published_year').val('');
|
|
$('#contact_name').val('');
|
|
$('#contact_phone').val('');
|
|
$('#contact_email').val('');
|
|
$('#description').val('');
|
|
$('#file_document').val('');
|
|
fetchMetadata();
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error);
|
|
if (xhr.status === 422) {
|
|
let errors = xhr.responseJSON.errors;
|
|
let errorMessages = '';
|
|
for (let field in errors) {
|
|
errorMessages += errors[field].join('<br>') + '<br>';
|
|
}
|
|
Swal.fire({
|
|
title: 'Validation Error',
|
|
html: errorMessages,
|
|
icon: 'error',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
title: 'Error!',
|
|
text: xhr.responseJSON.error ||
|
|
'Terjadi kesalahan saat menyimpan metadata.',
|
|
icon: 'error',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
}
|
|
$('#isLoadMetadata').hide();
|
|
}
|
|
});
|
|
});
|
|
|
|
$('.unit-code').on('change', function() {
|
|
var activityCode = $(this).data('activity-code');
|
|
var fromUnitCode = $(this).data('current-unit');
|
|
var toUnitCode = $(this).val();
|
|
|
|
$('[name^="data"]').each(function() {
|
|
if ($(this).attr('name').includes(activityCode)) {
|
|
const sector = '{{ $form->sector }}';
|
|
const code = '{{ $form->code }}';
|
|
const url = `/${sector}/${code}/conversion`;
|
|
|
|
convertUnitValue($(this), fromUnitCode, toUnitCode, url);
|
|
}
|
|
});
|
|
|
|
$(this).data('current-unit', toUnitCode);
|
|
});
|
|
});
|
|
|
|
function convertUnitValue(input, fromUnitCode, toUnitCode, url) {
|
|
let value = input.val();
|
|
value = value.replace(/\./g, '');
|
|
value = value.replace(/,/g, '.');
|
|
|
|
if (value && fromUnitCode && toUnitCode) {
|
|
fetch(`${url}?from=${fromUnitCode}&to=${toUnitCode}&value=${value}`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
input.val(data.convertedValue);
|
|
}
|
|
})
|
|
.catch(error => console.error('Error converting value:', error));
|
|
}
|
|
}
|
|
function showMetadataModal() {
|
|
$('#metadataModal').modal('show');
|
|
fetchMetadata();
|
|
}
|
|
function fetchMetadata() {
|
|
$('#metadataContent').hide();
|
|
$('#isLoadMetadata').show();
|
|
$.ajax({
|
|
url: '{{ route('modules.form.metadata.index', ['form_id' => @$instansi === 'all' ? 0 : @$activityForm->id ?? 0]) }}',
|
|
type: 'GET',
|
|
success: function(data) {
|
|
$('#metadataContent').html(data);
|
|
$('#metadataContent').show();
|
|
$('#isLoadMetadata').hide();
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error);
|
|
$('#isLoadMetadata').hide();
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function showCreateModal() {
|
|
$('#formModal').modal('show');
|
|
fetchFormdata();
|
|
}
|
|
|
|
function fetchFormdata() {
|
|
$('#formContent').hide();
|
|
$('#isLoadForm').show();
|
|
$.ajax({
|
|
url: '{{ route('modules.form.create', ['sector' => @$form->sector, 'code' => @$form->code]) }}',
|
|
type: 'GET',
|
|
success: function(data) {
|
|
$('#formContent').html(data);
|
|
$('#formContent').show();
|
|
$('#isLoadForm').hide();
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error);
|
|
$('#isLoadForm').hide();
|
|
}
|
|
});
|
|
}
|
|
|
|
function showActivityUserModal() {
|
|
$('#userActivityModal').modal('show');
|
|
fetchUserActivity();
|
|
}
|
|
|
|
function fetchUserActivity() {
|
|
if (activitiesTable) {
|
|
activitiesTable.destroy();
|
|
}
|
|
|
|
activitiesTable = $('#activities-table').DataTable({
|
|
pageLength: 10,
|
|
responsive: true,
|
|
serverSide: true,
|
|
scrollX: true,
|
|
searchDelay: 1000,
|
|
ajax: {
|
|
url: '{{ route('modules.form.aktivitasUser', ['form_id' => @$instansi === 'all' ? 0 : @$activityForm->id ?? 0]) }}',
|
|
type: 'GET',
|
|
dataSrc: 'data'
|
|
},
|
|
columns: [{
|
|
data: 'user_name',
|
|
name: 'user_name'
|
|
},
|
|
{
|
|
data: 'activity_type',
|
|
name: 'activity_type'
|
|
},
|
|
{
|
|
data: 'ip_address',
|
|
name: 'ip_address'
|
|
},
|
|
{
|
|
data: 'created_at',
|
|
name: 'created_at'
|
|
}
|
|
],
|
|
order: [
|
|
[3, 'desc']
|
|
]
|
|
});
|
|
}
|
|
|
|
function deleteMetadata(metadataId, storagePath) {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: 'Data akan dihapus secara permanen!',
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, hapus!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
url: "{{ route('modules.form.metadata.destroy', ':id') }}".replace(':id', metadataId),
|
|
type: 'POST',
|
|
data: {
|
|
_token: '{{ csrf_token() }}',
|
|
_method: 'DELETE',
|
|
storage_path: storagePath
|
|
},
|
|
success: function(response) {
|
|
$('#metadata-' + metadataId).slideUp(500, function() {
|
|
$(this).remove();
|
|
reorderMetadata();
|
|
});
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error);
|
|
Swal.fire('Error!', 'Terjadi kesalahan saat menghapus data.', 'error');
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function reorderMetadata() {
|
|
$('.meta-content').each(function(index, element) {
|
|
$(element).animate({
|
|
top: 0
|
|
}, 500);
|
|
});
|
|
}
|
|
|
|
function confirmLock() {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: "Apakah Anda ingin mengunci data aktivitas ini?",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, Kunci Data!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById('lock-form').submit();
|
|
}
|
|
});
|
|
}
|
|
|
|
function confirmUnlock() {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: "Apakah Anda ingin membuka kunci data aktivitas ini?",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, Buka Kunci Data!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById('unlock-form').submit();
|
|
}
|
|
});
|
|
}
|
|
|
|
function confirmCopy() {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: "Apakah Anda ingin melakukan proses salin data aktivitas dari tahun tersebut?",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, Salin Data!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById('copy-form').submit();
|
|
}
|
|
});
|
|
}
|
|
|
|
function confirmApprove(isApproval) {
|
|
const action = isApproval ? 'menyetujui' : 'membatalkan persetujuan';
|
|
|
|
Swal.fire({
|
|
title: `Konfirmasi ${isApproval ? 'Persetujuan' : 'Pembatalan Persetujuan'}`,
|
|
text: `Apakah Anda yakin ingin ${action} Data Produsen ini? Fitur ini digunakan agar Data Produsen yang disetujui dapat dijumlahkan ke Data Konsolidasi.`,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: isApproval ? 'Ya, Setujui' : 'Ya, Batalkan',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById('confirmApprove').submit();
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
@endsection
|