update pakan
This commit is contained in:
parent
dedf8458ac
commit
ff786d572a
|
|
@ -190,12 +190,11 @@ public function update(Request $request, $id)
|
||||||
|
|
||||||
$namaBarang = ucfirst(strtolower(trim($request->nama_barang)));
|
$namaBarang = ucfirst(strtolower(trim($request->nama_barang)));
|
||||||
|
|
||||||
$request->validate([
|
$validator = \Illuminate\Support\Facades\Validator::make($request->all(), [
|
||||||
'tanggal' => 'required|date|before_or_equal:today',
|
'tanggal' => 'required|date|before_or_equal:today',
|
||||||
'nama_barang' => 'required|string|max:100',
|
'nama_barang' => 'required|string|max:100',
|
||||||
'jenis_transaksi' => 'required|in:masuk,keluar',
|
'jenis_transaksi' => 'required|in:masuk,keluar',
|
||||||
'jumlah' => 'required|numeric|min:1|max:999999',
|
'jumlah' => 'required|numeric|min:1|max:999999',
|
||||||
// 'satuan' => 'required|string|max:50|in:karung',
|
|
||||||
'harga_satuan' => $request->jenis_transaksi === 'masuk'
|
'harga_satuan' => $request->jenis_transaksi === 'masuk'
|
||||||
? 'required|numeric|min:1|max:999999999'
|
? 'required|numeric|min:1|max:999999999'
|
||||||
: 'nullable',
|
: 'nullable',
|
||||||
|
|
@ -215,16 +214,19 @@ public function update(Request $request, $id)
|
||||||
'jumlah.min' => 'Jumlah minimal 1.',
|
'jumlah.min' => 'Jumlah minimal 1.',
|
||||||
'jumlah.max' => 'Jumlah terlalu besar.',
|
'jumlah.max' => 'Jumlah terlalu besar.',
|
||||||
|
|
||||||
// 'satuan.required' => 'Satuan wajib diisi.',
|
|
||||||
// 'satuan.string' => 'Satuan harus berupa teks.',
|
|
||||||
// 'satuan.max' => 'Satuan maksimal 50 karakter.',
|
|
||||||
|
|
||||||
'harga_satuan.required' => 'Harga satuan wajib diisi untuk transaksi masuk.',
|
'harga_satuan.required' => 'Harga satuan wajib diisi untuk transaksi masuk.',
|
||||||
'harga_satuan.numeric' => 'Harga satuan harus berupa angka.',
|
'harga_satuan.numeric' => 'Harga satuan harus berupa angka.',
|
||||||
'harga_satuan.min' => 'Harga satuan minimal 1.',
|
'harga_satuan.min' => 'Harga satuan minimal 1.',
|
||||||
'harga_satuan.max' => 'Harga satuan terlalu besar.',
|
'harga_satuan.max' => 'Harga satuan terlalu besar.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return back()
|
||||||
|
->withErrors($validator, 'edit')
|
||||||
|
->withInput()
|
||||||
|
->with('edit_id', $id);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DB::transaction(function () use ($request, $id, $namaBarang) {
|
DB::transaction(function () use ($request, $id, $namaBarang) {
|
||||||
|
|
@ -272,8 +274,9 @@ public function update(Request $request, $id)
|
||||||
return back()
|
return back()
|
||||||
->withErrors([
|
->withErrors([
|
||||||
'jumlah' => $e->getMessage()
|
'jumlah' => $e->getMessage()
|
||||||
])
|
], 'edit')
|
||||||
->withInput();
|
->withInput()
|
||||||
|
->with('edit_id', $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('pakan')->with('success', 'Transaksi berhasil diupdate');
|
return redirect()->route('pakan')->with('success', 'Transaksi berhasil diupdate');
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class="form-control form-control-sm">
|
||||||
<label class="small">Tahun</label>
|
<label class="small">Tahun</label>
|
||||||
<select name="tahun" class="form-control form-control-sm">
|
<select name="tahun" class="form-control form-control-sm">
|
||||||
<option value="">Semua</option>
|
<option value="">Semua</option>
|
||||||
@for ($th = now()->year - 2; $th <= now()->year + 1; $th++)
|
@for ($th = now()->year - 2; $th <= now()->year + 1; $th++)
|
||||||
<option value="{{ $th }}"
|
<option value="{{ $th }}"
|
||||||
{{ request('tahun') == $th ? 'selected' : '' }}>
|
{{ request('tahun') == $th ? 'selected' : '' }}>
|
||||||
{{ $th }}
|
{{ $th }}
|
||||||
|
|
@ -103,15 +103,16 @@ class="form-control form-control-sm">
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|
||||||
@if ($errors->has('delete'))
|
@if ($errors->has('delete'))
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
{{ $errors->first('delete') }}
|
{{ $errors->first('delete') }}
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
<!-- TABEL -->
|
<!-- TABEL -->
|
||||||
<div class="p-0 card-body">
|
<div class="p-0 card-body">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table mb-0" style="table-layout:fixed; width:100%;"> <thead class="table-light">
|
<table class="table mb-0" style="table-layout:fixed; width:100%;">
|
||||||
|
<thead class="table-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="text-center" style="width:60px;">No</th>
|
<th class="text-center" style="width:60px;">No</th>
|
||||||
<th style="width:150px;">Tanggal</th>
|
<th style="width:150px;">Tanggal</th>
|
||||||
|
|
@ -170,9 +171,8 @@ class="badge badge-{{ $item->jenis_transaksi == 'masuk' ? 'success' : 'danger' }
|
||||||
data-nama="{{ $item->nama_barang }}"
|
data-nama="{{ $item->nama_barang }}"
|
||||||
data-jenis="{{ $item->jenis_transaksi }}"
|
data-jenis="{{ $item->jenis_transaksi }}"
|
||||||
data-jumlah="{{ (int) $item->jumlah }}"
|
data-jumlah="{{ (int) $item->jumlah }}"
|
||||||
data-harga="{{ (int) $item->harga_satuan }}"
|
data-harga="{{ (int) $item->harga_satuan }}"
|
||||||
data-harga="{{ $item->harga_satuan }}"
|
{{-- data-harga="{{ $item->harga_satuan }}" --}} data-tanggal="{{ $item->tanggal }}">
|
||||||
data-tanggal="{{ $item->tanggal }}">
|
|
||||||
<i class="la la-edit"></i>
|
<i class="la la-edit"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
@ -279,8 +279,12 @@ class="form-control @error('jenis_transaksi') is-invalid @enderror" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Tanggal</label>
|
<label>Tanggal</label>
|
||||||
<input type="date" name="tanggal" class="form-control"
|
<input type="date" name="tanggal"
|
||||||
|
class="form-control @error('tanggal') is-invalid @enderror"
|
||||||
value="{{ old('tanggal', date('Y-m-d')) }}" max="{{ date('Y-m-d') }}" required>
|
value="{{ old('tanggal', date('Y-m-d')) }}" max="{{ date('Y-m-d') }}" required>
|
||||||
|
@error('tanggal')
|
||||||
|
<small class="text-danger">{{ $message }}</small>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Nama Barang</label>
|
<label>Nama Barang</label>
|
||||||
|
|
@ -347,7 +351,7 @@ class="form-control @error('jumlah') is-invalid @enderror"
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Harga (Rp)</label>
|
<label>Harga (Rp)</label>
|
||||||
|
|
||||||
<input type="text" name="harga_satuan" id="hargaTambah"
|
<input type="text" name="harga_satuan" id="hargaTambah"
|
||||||
class="form-control @error('harga_satuan') is-invalid @enderror"
|
class="form-control @error('harga_satuan') is-invalid @enderror"
|
||||||
inputmode="numeric" maxlength="12" value="{{ old('harga_satuan') }}">
|
inputmode="numeric" maxlength="12" value="{{ old('harga_satuan') }}">
|
||||||
@error('harga_satuan')
|
@error('harga_satuan')
|
||||||
|
|
@ -411,18 +415,23 @@ class="form-control @error('jenis_transaksi') is-invalid @enderror" required>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@error('jenis_transaksi')
|
@error('jenis_transaksi', 'edit')
|
||||||
<small class="text-danger">{{ $message }}</small>
|
<small class="text-danger">{{ $message }}</small>
|
||||||
@enderror
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Tanggal</label>
|
<label>Tanggal</label>
|
||||||
<input type="date" name="tanggal" id="tanggalEdit" class="form-control"
|
<input type="date" name="tanggal" id="tanggalEdit"
|
||||||
max="{{ date('Y-m-d') }}" required>
|
class="form-control @error('tanggal') is-invalid @enderror" max="{{ date('Y-m-d') }}"
|
||||||
|
required>
|
||||||
|
@error('tanggal', 'edit')
|
||||||
|
<small class="text-danger">{{ $message }}</small>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Nama Barang</label>
|
<label>Nama Barang</label>
|
||||||
<select name="nama_barang" id="namaEdit" class="form-control" required>
|
<select name="nama_barang" id="namaEdit"
|
||||||
|
class="form-control @error('nama_barang') is-invalid @enderror" required>
|
||||||
|
|
||||||
<option value="Jagung">Jagung</option>
|
<option value="Jagung">Jagung</option>
|
||||||
<option value="Katul">Katul</option>
|
<option value="Katul">Katul</option>
|
||||||
|
|
@ -431,6 +440,9 @@ class="form-control @error('jenis_transaksi') is-invalid @enderror" required>
|
||||||
<option value="Pakan Starter">Pakan Starter</option>
|
<option value="Pakan Starter">Pakan Starter</option>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
@error('nama_barang', 'edit')
|
||||||
|
<small class="text-danger">{{ $message }}</small>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -439,7 +451,10 @@ class="form-control @error('jenis_transaksi') is-invalid @enderror" required>
|
||||||
<label>Jumlah</label>
|
<label>Jumlah</label>
|
||||||
<input type="number" name="jumlah" id="jumlahEdit" max="999999" min="1"
|
<input type="number" name="jumlah" id="jumlahEdit" max="999999" min="1"
|
||||||
inputmode="numeric" maxlength="6"
|
inputmode="numeric" maxlength="6"
|
||||||
class="form-control" required>
|
class="form-control @error('jumlah') is-invalid @enderror" required>
|
||||||
|
@error('jumlah', 'edit')
|
||||||
|
<small class="text-danger">{{ $message }}</small>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
|
|
@ -453,8 +468,12 @@ class="form-control" required>
|
||||||
<div class="col-md-4 harga-edit">
|
<div class="col-md-4 harga-edit">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Harga Satuan (Rp)</label>
|
<label>Harga Satuan (Rp)</label>
|
||||||
<input type="text" name="harga_satuan" id="hargaEdit" class="form-control"
|
<input type="text" name="harga_satuan" id="hargaEdit"
|
||||||
|
class="form-control @error('harga_satuan') is-invalid @enderror"
|
||||||
inputmode="numeric" maxlength="12">
|
inputmode="numeric" maxlength="12">
|
||||||
|
@error('harga_satuan', 'edit')
|
||||||
|
<small class="text-danger">{{ $message }}</small>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -517,13 +536,14 @@ class="form-control" required>
|
||||||
@section('scripts')
|
@section('scripts')
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const baseUrl = "{{ route('pakan') }}";
|
const baseUrl = "{{ route('pakan') }}";
|
||||||
function formatRupiah(angka) {
|
|
||||||
|
function formatRupiah(angka) {
|
||||||
if (!angka) return '';
|
if (!angka) return '';
|
||||||
|
|
||||||
angka = angka.toString().replace(/\D/g, '');
|
angka = angka.toString().replace(/\D/g, '');
|
||||||
return angka.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
return angka.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TAMBAH */
|
/* TAMBAH */
|
||||||
function hitungTambah() {
|
function hitungTambah() {
|
||||||
|
|
@ -536,8 +556,8 @@ function hitungTambah() {
|
||||||
$('#totalTambah').val(
|
$('#totalTambah').val(
|
||||||
'Rp ' + (j * h).toLocaleString('id-ID')
|
'Rp ' + (j * h).toLocaleString('id-ID')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$('#hargaTambah').on('input', function() {
|
$('#hargaTambah').on('input', function() {
|
||||||
|
|
||||||
let angka = this.value.replace(/\D/g, '');
|
let angka = this.value.replace(/\D/g, '');
|
||||||
|
|
||||||
|
|
@ -547,18 +567,22 @@ function hitungTambah() {
|
||||||
|
|
||||||
this.value = formatRupiah(angka);
|
this.value = formatRupiah(angka);
|
||||||
hitungTambah();
|
hitungTambah();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* format harga tambah */
|
/* format harga tambah */
|
||||||
$('#jumlahTambah').on('input', hitungTambah);
|
$('#jumlahTambah').on('input', hitungTambah);
|
||||||
$('#jenisTambah').on('change', function() {
|
$('#jenisTambah').on('change', function() {
|
||||||
|
|
||||||
if (this.value === 'keluar') {
|
if (this.value === 'keluar') {
|
||||||
$('.harga-tambah').hide();
|
$('.harga-tambah').hide();
|
||||||
$('#hargaTambah,#totalTambah').val('');
|
$('#hargaTambah')
|
||||||
|
.val('')
|
||||||
|
.prop('disabled', true);
|
||||||
|
$('#totalTambah').val('');
|
||||||
} else {
|
} else {
|
||||||
$('.harga-tambah').show();
|
$('.harga-tambah').show();
|
||||||
|
$('#hargaTambah').prop('disabled', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -574,13 +598,13 @@ function hitungEdit() {
|
||||||
$('#totalEdit').val(
|
$('#totalEdit').val(
|
||||||
j && h ? 'Rp ' + (j * h).toLocaleString('id-ID') : ''
|
j && h ? 'Rp ' + (j * h).toLocaleString('id-ID') : ''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* realtime hitung */
|
/* realtime hitung */
|
||||||
$('#jumlahEdit, #hargaEdit').on('input', hitungEdit);
|
$('#jumlahEdit, #hargaEdit').on('input', hitungEdit);
|
||||||
|
|
||||||
/* format harga edit */
|
/* format harga edit */
|
||||||
$('#hargaEdit').on('input', function() {
|
$('#hargaEdit').on('input', function() {
|
||||||
|
|
||||||
let angka = this.value.replace(/\./g, '');
|
let angka = this.value.replace(/\./g, '');
|
||||||
|
|
||||||
|
|
@ -591,7 +615,7 @@ function hitungEdit() {
|
||||||
this.value = formatRupiah(angka);
|
this.value = formatRupiah(angka);
|
||||||
hitungEdit();
|
hitungEdit();
|
||||||
|
|
||||||
});
|
});
|
||||||
/* perubahan jenis transaksi edit */
|
/* perubahan jenis transaksi edit */
|
||||||
$('#jenisEdit').on('change', function() {
|
$('#jenisEdit').on('change', function() {
|
||||||
|
|
||||||
|
|
@ -608,19 +632,25 @@ function hitungEdit() {
|
||||||
/* modal edit dibuka */
|
/* modal edit dibuka */
|
||||||
$('#modalEditTransaksi').on('show.bs.modal', function(e) {
|
$('#modalEditTransaksi').on('show.bs.modal', function(e) {
|
||||||
|
|
||||||
|
// CEK: kalau ada error edit, JANGAN override input
|
||||||
|
let isError = {{ $errors->edit->any() ? 'true' : 'false' }};
|
||||||
|
|
||||||
|
if (isError) return; // STOP di sini, biar pakai old()
|
||||||
|
|
||||||
let btn = $(e.relatedTarget);
|
let btn = $(e.relatedTarget);
|
||||||
|
let id = btn.data('id');
|
||||||
|
|
||||||
$('#formEditTransaksi').attr('action', baseUrl + '/' + btn.data('id'));
|
$('#formEditTransaksi').attr('action', baseUrl + '/' + btn.data('id'));
|
||||||
|
|
||||||
// FIX NAMA BARANG
|
// FIX NAMA BARANG
|
||||||
$('#namaEdit').val(''); // RESET DULU
|
$('#namaEdit').val(''); // RESET DULU
|
||||||
|
|
||||||
let nama = btn.data('nama');
|
let nama = btn.data('nama');
|
||||||
$('#namaEdit option').each(function () {
|
$('#namaEdit option').each(function() {
|
||||||
if ($(this).val().toLowerCase() === String(nama).toLowerCase()) {
|
if ($(this).val().toLowerCase() === String(nama).toLowerCase()) {
|
||||||
$(this).prop('selected', true);
|
$(this).prop('selected', true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// jenis
|
// jenis
|
||||||
$('#jenisEdit').val(btn.data('jenis'));
|
$('#jenisEdit').val(btn.data('jenis'));
|
||||||
|
|
@ -629,20 +659,17 @@ function hitungEdit() {
|
||||||
$('#jumlahEdit').val(btn.data('jumlah'));
|
$('#jumlahEdit').val(btn.data('jumlah'));
|
||||||
|
|
||||||
// harga
|
// harga
|
||||||
let harga = parseInt(btn.data('harga')) || 0;
|
let harga = parseInt(btn.data('harga')) || 0;
|
||||||
|
|
||||||
|
$('#hargaEdit').val(harga ? formatRupiah(harga.toString()) : '');
|
||||||
|
|
||||||
$('#hargaEdit').val(harga ? formatRupiah(harga.toString()) : '');
|
|
||||||
// if (harga !== null && harga !== undefined && harga !== '') {
|
|
||||||
// $('#hargaEdit').val(formatRupiah(harga));} else {
|
|
||||||
// $('#hargaEdit').val('');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// tanggal
|
// tanggal
|
||||||
$('#tanggalEdit').val(btn.data('tanggal'));
|
$('#tanggalEdit').val(btn.data('tanggal'));
|
||||||
|
|
||||||
$('#jenisEdit').trigger('change');
|
$('#jenisEdit').trigger('change');
|
||||||
hitungEdit();
|
hitungEdit();
|
||||||
});
|
});
|
||||||
|
|
||||||
/* HAPUS */
|
/* HAPUS */
|
||||||
$('#modalHapusTransaksi').on('show.bs.modal', function(e) {
|
$('#modalHapusTransaksi').on('show.bs.modal', function(e) {
|
||||||
|
|
@ -686,15 +713,59 @@ function hitungEdit() {
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|
||||||
@if ($errors->any())
|
@if ($errors->any() && !$errors->edit->any())
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
$('#modalTransaksi').modal('show');
|
$('#modalTransaksi').modal('show');
|
||||||
hitungTambah();
|
|
||||||
|
|
||||||
|
let jenis = "{{ old('jenis_transaksi') }}";
|
||||||
|
|
||||||
|
if (jenis === 'keluar') {
|
||||||
|
$('.harga-tambah').hide();
|
||||||
|
$('#hargaTambah').prop('disabled', true);
|
||||||
|
} else {
|
||||||
|
$('.harga-tambah').show();
|
||||||
|
$('#hargaTambah').prop('disabled', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
hitungTambah();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@if ($errors->edit->any())
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
let id = "{{ session('edit_id') }}";
|
||||||
|
|
||||||
|
// SET ACTION WAJIB!
|
||||||
|
$('#formEditTransaksi').attr('action', "{{ route('pakan') }}/" + id);
|
||||||
|
|
||||||
|
$('#modalEditTransaksi').modal('show');
|
||||||
|
|
||||||
|
// isi pakai old input
|
||||||
|
$('#jenisEdit').val("{{ old('jenis_transaksi') }}");
|
||||||
|
$('#tanggalEdit').val("{{ old('tanggal') }}");
|
||||||
|
$('#jumlahEdit').val("{{ old('jumlah') }}");
|
||||||
|
|
||||||
|
let nama = "{{ old('nama_barang') }}";
|
||||||
|
$('#namaEdit option').each(function() {
|
||||||
|
if ($(this).val().toLowerCase() === nama.toLowerCase()) {
|
||||||
|
$(this).prop('selected', true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let harga = "{{ old('harga_satuan') }}";
|
||||||
|
if (harga) {
|
||||||
|
$('#hargaEdit').val(formatRupiah(harga));
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#jenisEdit').trigger('change');
|
||||||
|
hitungEdit();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endif
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue