sigd/resources/views/modules/tool/copy/index.blade.php

174 lines
6.6 KiB
PHP

@extends('layouts.master')
@section('title', 'Salin Aktivitas')
@section('content')
<div class="card shadow-sm">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0 font-weight-bold">Salin Aktivitas</h5>
<button type="button" class="btn btn-primary float-right" data-toggle="modal" data-target="#copyModal">
Salin Aktivitas
</button>
</div>
<div class="card-body">
@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
@if ($errors->any())
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
<p>{{ $error }}</p>
@endforeach
</div>
@endif
<div class="table-responsive">
<table class="table align-items-center mb-0 display" id="data-table" style="width:100%">
<thead>
<tr>
<th scope="col">Waktu Input</th>
<th scope="col">Tahun Tujuan</th>
<th scope="col">Tahun Sumber</th>
<th scope="col">Status</th>
<th scope="col">Waktu Eksekusi</th>
<th scope="col">Waktu Selesai</th>
<th scope="col">Durasi</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<!-- Copy Modal -->
<div class="modal fade" id="copyModal" tabindex="-1" aria-labelledby="copyModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="copyModalLabel">Salin Aktivitas</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="{{ route('copy.store') }}" method="POST" id="copyForm">
@csrf
<div class="modal-body">
<div class="form-group">
<label for="to_year">Tahun Tujuan Data Aktivitas <span class="text-danger">*</span></label>
<select name="to_year" id="to_year" class="form-control w-100" required>
@for ($year = date('Y'); $year >= 2000; $year--)
<option value="{{ $year }}">
{{ $year }}
</option>
@endfor
</select>
</div>
<div class="form-group">
<label for="from_year">Tahun Sumber Data Aktivitas <span class="text-danger">*</span></label>
<select name="from_year" id="from_year" class="form-control w-100" required>
<option value=""></option>
@if (isset($availableYears) && count($availableYears) > 0)
@foreach ($availableYears as $year)
<option value="{{ $year }}">{{ $year }}</option>
@endforeach
@else
<option value="" disabled>Tidak ada tahun inventory yang terdata.</option>
@endif
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
<button type="submit" class="btn btn-primary">Salin</button>
</div>
</form>
</div>
</div>
</div>
@endsection
@section('js')
<script>
$(document).ready(function() {
$('#from_year').select2({
placeholder: 'Pilih Tahun',
width: '100%',
});
$('#to_year').select2({
placeholder: 'Pilih Tahun',
width: '100%',
});
var table = $('#data-table').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '{{ route('copy.index') }}',
data: function(d) {}
},
columns: [{
data: 'created_at',
name: 'created_at'
},
{
data: 'to_year',
name: 'to_year'
},
{
data: 'from_year',
name: 'from_year'
},
{
data: 'status',
name: 'status'
},
{
data: 'executed_time',
name: 'executed_time'
},
{
data: 'finished_time',
name: 'finished_time'
},
{
data: 'duration',
name: 'duration'
},
],
order: [
[0, 'desc']
]
});
$('#copyForm').on('submit', function(e) {
e.preventDefault();
var fromYear = $('#from_year').val();
var toYear = $('#to_year').val();
Swal.fire({
title: 'Apakah Anda yakin?',
text: "Anda akan menyalin data dari tahun " + fromYear + " ke tahun " + toYear +
". Data yang sudah ada akan di-refresh/replace.",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Ya, Salin!',
cancelButtonText: 'Batal'
}).then((result) => {
if (result.isConfirmed) {
this.submit();
}
});
});
});
</script>
@endsection