added autoserahan

This commit is contained in:
Hafifie PKB
2025-03-17 11:39:56 +08:00
parent a2331b0bed
commit 5ee3d492fc
3 changed files with 164 additions and 19 deletions
+67 -1
View File
@@ -5,7 +5,7 @@ use App\Events\AutoSerahan;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Log;
class AutoSerahanController extends Controller
{
public function index(Request $request)
@@ -15,12 +15,18 @@ class AutoSerahanController extends Controller
'page' => request('page', 1) // Get current page from request
])->json();
// Extract pagination details
$items = $response['data'] ?? []; // Data array
$total = $response['total'] ?? 0; // Total items
$perPage = $response['per_page'] ?? 10; // Items per page
$currentPage = $response['current_page'] ?? 1; // Current page
$items = array_map(function ($item) {
$item['cawangan_name'] = $this->CawanganKod($item['kodcaw']);
return $item;
}, $items);
// Create Laravel paginator
$list = new LengthAwarePaginator($items, $total, $perPage, $currentPage, [
'path' => request()->url(), // Current URL
@@ -39,6 +45,59 @@ class AutoSerahanController extends Controller
'sendApproval' => 'ACCEPTED',
'operasi_name' => auth()->user()->name,
])->json();
Log::debug($response);
if($response['approve_status'] == 'approved'){
$approvalserahan = Http::get(config('api.url_koop') . '/api/autoserahan/get', [
'id' => $request->id,
'kodcaw' => $request->kodcaw
])->json();
if($approvalserahan['action'] == 'create'){
$pendahuluan = Http::put(config('api.url_koop') . '/api/autoserahan/pendahuluan', [
'id' => $request->id,
'kodcaw' => $request->kodcaw,
'teller' => $request->teller,
'amaun' => $request->amaun,
'denopendser_id' => $approvalserahan['denopendser_id_v3']
])->json();
$serahan = Http::put(config('api.url_pkb') . '/api/autoserahan/serahan', [
'id' => $request->id,
'kodcaw' => $request->kodcaw,
'teller' => $request->teller,
'amaun' => $request->amaun,
'denopendser_id' => $approvalserahan['denopendser_id_v2']
])->json();
Log::error($serahan);
$call_set_approval_v3 = Http::withOptions(['verify' => config('app.api_verify')])
->put(config('api.url_koop') . '/api/autoserahan/setapproval', [
'id' => $request->id,
'jenis' => 'rewrite',
'gldetail_id' => $serahan['gldetail_id']
])->json();
}else{
$pendahuluan = Http::put(config('api.url_koop') . '/api/autoserahan/delete/pendahuluan', [
'array_approval' => $approvalserahan,
'kodcaw' => $request->kodcaw,
'teller' => $request->teller,
'amaun' => $request->amaun,
])->json();
Log::info($pendahuluan);
$serahan = Http::put(config('api.url_pkb') . '/api/autoserahan/delete/serahan', [
'array_approval' => $approvalserahan,
'kodcaw' => $request->kodcaw,
'teller' => $request->teller,
'amaun' => $request->amaun,
])->json();
Log::info($serahan);
}
}
if($response['status'] == 'success'){
event(new AutoSerahan("Lulus",$request->id,$request->kodcaw,$request->teller));
@@ -68,4 +127,11 @@ class AutoSerahanController extends Controller
return redirect()->route('autoserahan')->with('error', 'Serahan rejected failed');
}
}
private function CawanganKod($kodcaw) {
$cawangan = Http::get(config('api.url_koop') . '/api/cawangan/' . $kodcaw)->json();
return $cawangan['details_caw'] ?? 'Undefined';
}
}
+92 -13
View File
@@ -24,26 +24,42 @@
<table class="min-w-full leading-normal">
<thead class="text-center">
<tr>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Bil</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Cawangan</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Pemohon</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Amaun</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Tindakan</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider text-center">Bil</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider text-center">Cawangan</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider text-center">Tindakan</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider text-center">Pemohon</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider text-center">Amaun</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider text-center">Tindakan</th>
</tr>
</thead>
@if ($list->count() > 0)
@foreach($list as $item)
<tbody>
<tr>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">{{ $item['id'] }}</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">{{ $item['kodcaw'] }}</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">{{ $item['pc_name'] }}</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">{{ number_format($item['amount'], 2) }}</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
<a href="{{ route('autoserahan.approve', ['id' => $item['id'], 'kodcaw' => $item['kodcaw'], 'teller' => $item['pc_name'], 'amaun' => $item['amount']]) }}" class="cursor-pointer bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm text-center">{{ $item['id'] }}</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm text-center">{{ $item['cawangan_name'] }}</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm text-center">
@if($item['action'] === 'create')
<span class="inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-800 ring-1 ring-green-600/20 ring-inset">
Create
</span>
@elseif($item['action'] === 'delete')
<span class="inline-flex items-center rounded-md bg-red-50 px-2 py-1 text-xs font-medium text-red-800 ring-1 ring-red-600/20 ring-inset">
Delete
</span>
@endif
</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm text-center">{{ $item['pc_name'] }}</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm text-center">{{ number_format($item['amount'], 2) }}</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm text-center">
<a href="{{ route('autoserahan.approve', ['id' => $item['id'], 'kodcaw' => $item['kodcaw'], 'teller' => $item['pc_name'], 'amaun' => $item['amount']]) }}"
onclick="return confirmApproval(event, this)"
class="cursor-pointer bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
<i class="fas fa-thumbs-up mr-1 text-md"></i> Lulus
</a>
<a href="{{ route('autoserahan.reject', ['id' => $item['id'], 'kodcaw' => $item['kodcaw'], 'teller' => $item['pc_name'], 'amaun' => $item['amount']]) }}" class="cursor-pointer bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
<a href="{{ route('autoserahan.reject', ['id' => $item['id'], 'kodcaw' => $item['kodcaw'], 'teller' => $item['pc_name'], 'amaun' => $item['amount']]) }}"
onclick="return confirmApproval(event, this)"
class="cursor-pointer bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
<i class="fas fa-thumbs-down mr-1 text-md"></i> Tolak
</a>
</td>
@@ -53,7 +69,7 @@
@else
<tbody>
<tr>
<td colspan="5" class="text-center py-5 text-gray-500 text-sm font-semibold">Tiada data</td>
<td colspan="5" class="text-center bg-white py-5 text-gray-500 text-sm font-semibold">Tiada data</td>
</tr>
</tbody>
@endif
@@ -65,4 +81,67 @@
</div>
</div>
</main>
@include('layouts.footer')
</div>
@push('additional_scripts')
<script>
async function requestPasswordAndSend(element) {
const {
value: katalaluan
} = await Swal.fire({
title: 'Masukkan Katalaluan Semula',
input: 'password',
inputPlaceholder: 'Katalaluan',
confirmButtonText: 'Hantar',
showCancelButton: true,
cancelButtonText: 'Batal',
allowOutsideClick: false
});
boolkatalaluan = 0;
if (katalaluan) {
$.ajax({
url: '/mintasemulakelulusan',
type: 'GET',
data: { passsemula: katalaluan },
success: function(response) {
boolkatalaluan = response;
if (boolkatalaluan == 1) {
Swal.fire({
title: 'Success',
text: 'Katalaluan Sah',
icon: 'success',
confirmButtonText: 'OK',
allowOutsideClick: false,
allowEscapeKey: false,
}).then((result) => {
if (result.isConfirmed) {
window.location.href = element.href;
}
});
} else {
Swal.fire('Error', 'Katalaluan Tidak Sah', 'error');
}
},
error: function(xhr, status, error) {
console.error('Error:', error);
Swal.fire('Error', 'Something went wrong!', 'error');
}
});
}else{
return false;
}
}
function confirmApproval(event, element) {
event.preventDefault();
requestPasswordAndSend(element);
}
</script>
@endpush
@endsection
+1 -1
View File
@@ -32,7 +32,7 @@
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
.sidebar {
height: 100%;