148 lines
6.0 KiB
PHP
148 lines
6.0 KiB
PHP
@extends('layouts.app_operasi')
|
|
@section('content')
|
|
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8">
|
|
<div class="card">
|
|
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb pb-3">
|
|
<li class="breadcrumb-item"><a href="{{ url('/') }}">Home</a></li>
|
|
<li class="breadcrumb-item"><a href="{{ url('operasi/parameter') }}">Parameter</a></li>
|
|
<li class="breadcrumb-item"><a href="{{ url('operasi/marginmutu') }}">Margin Mutu Emas</a></li>
|
|
<li class="breadcrumb-item active" aria-current="page">Edit Margin Mutu</li>
|
|
</ol>
|
|
</nav>
|
|
<div class="card-body">
|
|
<h4 class="text-center mb-4">Edit Margin Mutu Emas</h4>
|
|
|
|
<form id="editMarginForm">
|
|
@csrf
|
|
<input type="hidden" id="recno" name="recno">
|
|
|
|
<div class="form-group">
|
|
<label for="karat">Karat</label>
|
|
<input type="text" class="form-control" id="karat" name="karat" readonly>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="keterangan">Keterangan</label>
|
|
<input type="text" class="form-control" id="keterangan" name="keterangan" readonly>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="teller">Teller (%)</label>
|
|
<input type="number" step="0.01" class="form-control" id="teller" name="teller" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="pc">PC (%)</label>
|
|
<input type="number" step="0.01" class="form-control" id="pc" name="pc" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="operasi">Operasi (%)</label>
|
|
<input readonly type="number" step="0.01" class="form-control" id="operasi" name="operasi" required>
|
|
</div>
|
|
|
|
<div class="text-center">
|
|
<button type="submit" class="btn btn-primary">Update</button>
|
|
<a href="{{ route('operasi.marginmutu') }}" class="btn btn-secondary">Cancel</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Get data from URL parameters
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
$('#recno').val(urlParams.get('recno'));
|
|
$('#karat').val(urlParams.get('karat'));
|
|
$('#keterangan').val(urlParams.get('keterangan'));
|
|
$('#teller').val(urlParams.get('teller'));
|
|
$('#pc').val(urlParams.get('pc'));
|
|
$('#operasi').val(urlParams.get('operasi'));
|
|
|
|
var username = '{{ Auth::user()->name }}';
|
|
|
|
$('#editMarginForm').on('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const formData = {
|
|
recno: $('#recno').val(),
|
|
karat: $('#karat').val(),
|
|
keterangan: $('#keterangan').val(),
|
|
teller: $('#teller').val(),
|
|
pc: $('#pc').val(),
|
|
operasi: $('#operasi').val(),
|
|
_token: $('input[name="_token"]').val(),
|
|
username : username
|
|
};
|
|
|
|
$.ajax({
|
|
url: '{{ config("api.url") }}/api/maxmutuemas/update',
|
|
type: 'POST',
|
|
data: formData,
|
|
success: function(response) {
|
|
if(response.status === 'success') {
|
|
Swal.fire({
|
|
title: 'Berjaya!',
|
|
text: 'Data berhasil diupdate!',
|
|
icon: 'success',
|
|
confirmButtonText: 'OK'
|
|
}).then((result) => {
|
|
window.location.href = '{{ route("operasi.marginmutu") }}';
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
title: 'Ralat!',
|
|
text: response.message,
|
|
icon: 'error',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
let errorMessage = 'Error updating data';
|
|
|
|
try {
|
|
let response = JSON.parse(xhr.responseText);
|
|
|
|
// If validation errors exist, show them
|
|
if (response.errors) {
|
|
let errorMessages = [];
|
|
Object.keys(response.errors).forEach(function(key) {
|
|
response.errors[key].forEach(function(error) {
|
|
errorMessages.push(error);
|
|
});
|
|
});
|
|
errorMessage = errorMessages.join('\n');
|
|
} else if (response.message) {
|
|
errorMessage = response.message;
|
|
}
|
|
} catch (e) {
|
|
// If JSON parsing fails, use the raw responseText
|
|
errorMessage = xhr.responseText || 'Unknown error occurred';
|
|
}
|
|
|
|
Swal.fire({
|
|
title: 'Ralat!',
|
|
text: errorMessage,
|
|
icon: 'error',
|
|
confirmButtonText: 'OK'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
$('input[type="number"]').on('keydown', function(e) {
|
|
if (['e', 'E', '+', '-'].includes(e.key)) e.preventDefault();
|
|
});
|
|
});
|
|
</script>
|
|
@endsection |