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 = [
|
|
'inventoryYear' => $inventoryYear,
|
|
'instansi' => $instansi,
|
|
];
|
|
|
|
$routeImport = route('folu.import', $param);
|
|
$routeExport = route('folu.export', $param);
|
|
$routeExportTemplate = route('folu.export', array_merge($param, ['isTemplate' => true]));
|
|
$routeApproval = route('folu.approval', $param);
|
|
|
|
$internal = $internal ?? null;
|
|
$limitInternal = $internal !== null && !$agencies->isNotEmpty();
|
|
@endphp
|
|
|
|
<div class="card shadow-sm">
|
|
<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">
|
|
@if ($errors->has('error'))
|
|
<div class="alert alert-danger">
|
|
{{ $errors->first('error') }}
|
|
</div>
|
|
@endif
|
|
|
|
@if (session('success'))
|
|
<div class="alert alert-success">
|
|
{{ session('success') }}
|
|
</div>
|
|
@endif
|
|
<div class="row">
|
|
<div class="col-md-8 order-md-2 d-flex justify-content-end align-items-center flex-wrap">
|
|
<div class="form-group mb-0 mr-2">
|
|
@include('form.approve')
|
|
</div>
|
|
<div class="form-group mb-0 mr-2">
|
|
<button type="button" class="btn btn-info mb-2 mb-md-0" onclick="showMetadataModal()"
|
|
{{ !$activityForm || $instansi === 'all' || $limitInternal ? 'disabled' : '' }}>
|
|
<i class="ti ti-menu-alt"></i>
|
|
{{-- Metadata --}}
|
|
</button>
|
|
</div>
|
|
<div class="form-group mb-0 mr-2">
|
|
<button type="button" class="btn btn-info mb-2 mb-md-0" onclick="showActivityUserModal()"
|
|
{{ !$activityForm || $instansi === 'all' || $limitInternal ? 'disabled' : '' }}>
|
|
Aktivitas User
|
|
</button>
|
|
</div>
|
|
<div class="form-group mb-0 mr-2">
|
|
<a href="{{ $routeExport }}" class="btn btn-info mb-2 mb-md-0">Ekspor Excel</a>
|
|
</div>
|
|
<div class="form-group mb-0">
|
|
<button type="button" class="btn btn-info mb-2 mb-md-0" data-toggle="modal"
|
|
data-target="#importModal">
|
|
Impor Data Aktivitas
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4 order-md-1">
|
|
<form method="GET" action="{{ route('folu.show') }}" id="filterForm">
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<x-inventory-year-select :selected-year="$inventoryYear" />
|
|
</div>
|
|
|
|
{{-- @if ($agencies->isNotEmpty()) --}}
|
|
<div class="col-md-8">
|
|
<div class="form-group">
|
|
<label for="instansi">Instansi:</label>
|
|
<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>
|
|
{{-- @endif --}}
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive" style="overflow-x: auto;">
|
|
<table class="table table-bordered table-detail" style="min-width: 1095px;">
|
|
<thead class="bg-header text-white">
|
|
<tr class="text-center">
|
|
<th colspan="{{ 1 + count($lands) }}">
|
|
{{ $inventoryYear - 1 }}
|
|
</th>
|
|
</tr>
|
|
<tr>
|
|
<th>
|
|
{{ $inventoryYear - 2 }}
|
|
</th>
|
|
@foreach ($lands as $land)
|
|
<th class="text-center" data-toggle="tooltip"
|
|
title="{{ App\Enums\LandType::getDescription($land) }}">
|
|
{{ $land }}
|
|
</th>
|
|
@endforeach
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach ($lands as $land1)
|
|
<tr>
|
|
<td class="text-left font-weight-bold" data-toggle="tooltip"
|
|
title="{{ App\Enums\LandType::getDescription($land1) }}">
|
|
{{ $land1 }}
|
|
</td>
|
|
@foreach ($lands as $land2)
|
|
@php
|
|
$activity_value = isset($activityFormDetails)
|
|
? optional(
|
|
$activityFormDetails
|
|
->where('activity_code', strtolower($land1 . '_' . $land2))
|
|
->first(),
|
|
)->activity_value
|
|
: '';
|
|
@endphp
|
|
<td>
|
|
<input type="text" name="data[{{ strtolower($land1 . '_' . $land2) }}]"
|
|
value="{{ getFormattedValue($activity_value) }}"
|
|
class="form-control text-right wide-input" oninput="numberFormat(this)"
|
|
readonly>
|
|
</td>
|
|
@endforeach
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@include('form.import')
|
|
@if ($instansi !== 'all')
|
|
@include('form.aktivitas-user')
|
|
@include('form.metadata.index')
|
|
@endif
|
|
@endsection
|
|
|
|
@section('css')
|
|
<style>
|
|
.wide-input {
|
|
min-width: 80px;
|
|
}
|
|
|
|
.table-detail td input.form-control {
|
|
width: 100%;
|
|
}
|
|
</style>
|
|
@endsection
|
|
|
|
@section('js')
|
|
<script>
|
|
var activitiesTable = null;
|
|
$(function() {
|
|
// Initialize Bootstrap tooltips
|
|
$('[data-toggle="tooltip"]').tooltip();
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
$('#inventoryYear').select2({
|
|
placeholder: 'Pilih Tahun',
|
|
}).on('change', function() {
|
|
$('#filterForm').submit();
|
|
});
|
|
|
|
$('#instansi').select2({
|
|
placeholder: 'Pilih Instansi',
|
|
}).on('change', function() {
|
|
$('#filterForm').submit();
|
|
});
|
|
|
|
// Handle metadata form submission via AJAX
|
|
$('#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();
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
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 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 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) {
|
|
// Swal.fire('Deleted!', 'Data berhasil dihapus.', 'success');
|
|
$('#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 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
|