@push('scripts')
    @include('lpj::assetsku.includenya')
    <script type="text/javascript">
        function buildSPKPDF(penawaran_id) {
            Swal.fire({
                title: 'Are you sure?',
                text: "Yakin Generate SPK ke PDF?",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Yes'
            }).then((result) => {
                if (result.isConfirmed) {
                    $.ajaxSetup({
                        headers: {
                            'X-CSRF-TOKEN': '{{ csrf_token()  }}'
                        }
                    });

                    $.ajax(`spk/${penawaran_id}`, {
                        type: 'PUT'
                    }).then((response) => {
                        // alert('ok Sukses');
                        swal.fire('Success!', 'File SPK berhasil di generate.', 'success').then(() => {
                            // window.location.reload();
                        });
                        $('#download-button').removeAttr('disabled');
                        $("#download-button").attr("href", response.spkpenawaran_path);

                    }).catch((error) => {
                        console.error('Error:', error);
                        Swal.fire('Error!', 'An error occurred while generate the PDF file.', 'error');
                    });
                }
            })
        }
    </script>
@endpush  