create stock and stock logs
This commit is contained in:
@@ -1,60 +1,253 @@
|
||||
const productUrl = $("#product-container").data("url");
|
||||
|
||||
function createProductSelectOptions(callback) {
|
||||
$.ajax({
|
||||
url: productUrl,
|
||||
method: "GET",
|
||||
success: function (data) {
|
||||
let options = '<option value="">Pilih Produk</option>';
|
||||
data.forEach((product) => {
|
||||
options += `<option value="${product.id}">${product.name}</option>`;
|
||||
});
|
||||
callback(options);
|
||||
},
|
||||
error: function () {
|
||||
alert("Gagal memuat produk.");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
// Initial load only for the first row
|
||||
createProductSelectOptions((options) => {
|
||||
$(".product-select").first().html(options);
|
||||
});
|
||||
// Fungsi untuk mengambil data stok
|
||||
function fetchStockData() {
|
||||
const dealerId = $("#dealer").val();
|
||||
if (!dealerId) return;
|
||||
|
||||
// When adding a new row
|
||||
$(document).on("click", ".btn-add-row", function () {
|
||||
const row = `
|
||||
<div class="form-row align-items-end product-row">
|
||||
<div class="form-group col-md-4">
|
||||
<select name="product[]" class="form-control product-select">
|
||||
<option>Loading...</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<input type="text" name="system_quantity[]" class="form-control" placeholder="Stok sistem">
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<input type="text" name="physical_quantity[]" class="form-control" placeholder="Stok fisik">
|
||||
</div>
|
||||
<div class="form-group col-md-2">
|
||||
<button type="button" class="btn btn-danger btn-remove-row"><i class="flaticon2-delete"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
const productIds = $(".product-select")
|
||||
.map(function () {
|
||||
return $(this).val();
|
||||
})
|
||||
.get()
|
||||
.filter((id) => id !== "");
|
||||
|
||||
const $newRow = $(row);
|
||||
$("#product-container").append($newRow);
|
||||
if (productIds.length === 0) return;
|
||||
|
||||
// Load options only for the new select
|
||||
createProductSelectOptions((options) => {
|
||||
$newRow.find(".product-select").html(options);
|
||||
$.ajax({
|
||||
url: "/warehouse/opnames/get-stock-data",
|
||||
method: "POST",
|
||||
data: {
|
||||
_token: $('meta[name="csrf-token"]').attr("content"),
|
||||
dealer_id: dealerId,
|
||||
product_ids: productIds,
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.stocks) {
|
||||
$(".product-row").each(function () {
|
||||
const productId = $(this).find(".product-select").val();
|
||||
const systemQtyInput = $(this).find(".system-quantity");
|
||||
const physicalQtyInput = $(this).find(
|
||||
'input[name^="physical_quantity"]'
|
||||
);
|
||||
|
||||
// Simpan nilai physical quantity yang sudah ada
|
||||
const currentPhysicalQty = physicalQtyInput.val();
|
||||
|
||||
if (
|
||||
productId &&
|
||||
response.stocks[productId] !== undefined
|
||||
) {
|
||||
systemQtyInput.val(response.stocks[productId]);
|
||||
// Kembalikan nilai physical quantity jika ada
|
||||
if (currentPhysicalQty) {
|
||||
physicalQtyInput.val(currentPhysicalQty);
|
||||
}
|
||||
calculateDifference(systemQtyInput[0]);
|
||||
} else {
|
||||
systemQtyInput.val("0");
|
||||
calculateDifference(systemQtyInput[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
console.error("Error fetching stock data:", xhr.responseText);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Update stok saat dealer berubah
|
||||
$("#dealer").change(function () {
|
||||
fetchStockData();
|
||||
});
|
||||
|
||||
// Remove row
|
||||
$(document).on("click", ".btn-remove-row", function () {
|
||||
$(this).closest(".product-row").remove();
|
||||
// Update stok saat produk berubah
|
||||
$(document).on("change", ".product-select", function () {
|
||||
const row = $(this).closest("tr");
|
||||
const productId = $(this).val();
|
||||
const systemQtyInput = row.find(".system-quantity");
|
||||
const physicalQtyInput = row.find('input[name^="physical_quantity"]');
|
||||
|
||||
// Simpan nilai physical quantity yang sudah ada
|
||||
const currentPhysicalQty = physicalQtyInput.val();
|
||||
|
||||
if (productId) {
|
||||
fetchStockData();
|
||||
} else {
|
||||
systemQtyInput.val("0");
|
||||
// Kembalikan nilai physical quantity jika ada
|
||||
if (currentPhysicalQty) {
|
||||
physicalQtyInput.val(currentPhysicalQty);
|
||||
}
|
||||
calculateDifference(systemQtyInput[0]);
|
||||
}
|
||||
});
|
||||
|
||||
// Fungsi untuk menambah baris produk
|
||||
$("#btn-add-row").click(function () {
|
||||
const template = document.getElementById("product-row-template");
|
||||
const tbody = $("#product-table tbody");
|
||||
const newRow = template.content.cloneNode(true);
|
||||
const rowIndex = $(".product-row").length;
|
||||
|
||||
// Update name attributes with correct index
|
||||
$(newRow)
|
||||
.find('select[name="product[]"]')
|
||||
.attr("name", `product[${rowIndex}]`);
|
||||
$(newRow)
|
||||
.find('input[name="system_quantity[]"]')
|
||||
.attr("name", `system_quantity[${rowIndex}]`);
|
||||
$(newRow)
|
||||
.find('input[name="physical_quantity[]"]')
|
||||
.attr("name", `physical_quantity[${rowIndex}]`);
|
||||
$(newRow)
|
||||
.find('input[name="item_notes[]"]')
|
||||
.attr("name", `item_notes[${rowIndex}]`);
|
||||
|
||||
// Add system-quantity class dan pastikan readonly
|
||||
const systemQtyInput = $(newRow).find(
|
||||
'input[name="system_quantity[]"]'
|
||||
);
|
||||
systemQtyInput
|
||||
.addClass("system-quantity")
|
||||
.attr("readonly", true)
|
||||
.val("0");
|
||||
|
||||
// Reset semua nilai input di baris baru kecuali system quantity
|
||||
$(newRow).find("select").val("");
|
||||
$(newRow).find("input:not(.system-quantity)").val("");
|
||||
|
||||
tbody.append(newRow);
|
||||
updateRemoveButtons();
|
||||
});
|
||||
|
||||
// Fungsi untuk menghapus baris produk
|
||||
$(document).on("click", ".btn-remove-row", function () {
|
||||
$(this).closest("tr").remove();
|
||||
updateRemoveButtons();
|
||||
// Reindex semua baris setelah penghapusan
|
||||
reindexRows();
|
||||
});
|
||||
|
||||
// Fungsi untuk update status tombol hapus
|
||||
function updateRemoveButtons() {
|
||||
const rows = $(".product-row").length;
|
||||
$(".btn-remove-row").prop("disabled", rows <= 1);
|
||||
}
|
||||
|
||||
// Fungsi untuk reindex semua baris
|
||||
function reindexRows() {
|
||||
$(".product-row").each(function (index) {
|
||||
$(this)
|
||||
.find('select[name^="product"]')
|
||||
.attr("name", `product[${index}]`);
|
||||
$(this)
|
||||
.find('input[name^="system_quantity"]')
|
||||
.attr("name", `system_quantity[${index}]`);
|
||||
$(this)
|
||||
.find('input[name^="physical_quantity"]')
|
||||
.attr("name", `physical_quantity[${index}]`);
|
||||
$(this)
|
||||
.find('input[name^="item_notes"]')
|
||||
.attr("name", `item_notes[${index}]`);
|
||||
});
|
||||
}
|
||||
|
||||
// Update calculateDifference function
|
||||
function calculateDifference(input) {
|
||||
const row = $(input).closest("tr");
|
||||
const systemQty = parseFloat(row.find(".system-quantity").val()) || 0;
|
||||
const physicalQty =
|
||||
parseFloat(row.find('input[name^="physical_quantity"]').val()) || 0;
|
||||
const noteInput = row.find('input[name^="item_notes"]');
|
||||
|
||||
if (Math.abs(systemQty - physicalQty) > 0.01) {
|
||||
noteInput.addClass("is-invalid");
|
||||
noteInput.attr("required", true);
|
||||
noteInput.attr(
|
||||
"placeholder",
|
||||
"Catatan wajib diisi karena ada perbedaan stock"
|
||||
);
|
||||
row.addClass("table-warning");
|
||||
} else {
|
||||
noteInput.removeClass("is-invalid");
|
||||
noteInput.removeAttr("required");
|
||||
noteInput.attr("placeholder", "Catatan item");
|
||||
row.removeClass("table-warning");
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent manual editing of system quantity
|
||||
$(document).on("keydown", ".system-quantity", function (e) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
|
||||
$(document).on("paste", ".system-quantity", function (e) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Validasi form sebelum submit
|
||||
$("#opname-form").submit(function (e) {
|
||||
const dealerId = $("#dealer").val();
|
||||
if (!dealerId) {
|
||||
e.preventDefault();
|
||||
alert("Silakan pilih dealer terlebih dahulu!");
|
||||
return false;
|
||||
}
|
||||
|
||||
const products = $('select[name^="product"]')
|
||||
.map(function () {
|
||||
return $(this).val();
|
||||
})
|
||||
.get();
|
||||
|
||||
// Cek duplikasi produk
|
||||
const uniqueProducts = [...new Set(products)];
|
||||
if (products.length !== uniqueProducts.length) {
|
||||
e.preventDefault();
|
||||
alert("Produk tidak boleh duplikat!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cek produk kosong
|
||||
if (products.includes("")) {
|
||||
e.preventDefault();
|
||||
alert("Semua produk harus dipilih!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cek catatan untuk perbedaan stock
|
||||
let hasInvalidNotes = false;
|
||||
$(".product-row").each(function () {
|
||||
const systemQty =
|
||||
parseFloat(
|
||||
$(this).find('input[name^="system_quantity"]').val()
|
||||
) || 0;
|
||||
const physicalQty =
|
||||
parseFloat(
|
||||
$(this).find('input[name^="physical_quantity"]').val()
|
||||
) || 0;
|
||||
const note = $(this).find('input[name^="item_notes"]').val();
|
||||
|
||||
if (Math.abs(systemQty - physicalQty) > 0.01 && !note) {
|
||||
hasInvalidNotes = true;
|
||||
$(this).addClass("table-danger");
|
||||
}
|
||||
});
|
||||
|
||||
if (hasInvalidNotes) {
|
||||
e.preventDefault();
|
||||
alert(
|
||||
"Catatan wajib diisi untuk produk yang memiliki perbedaan stock!"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Initial stock data load if dealer is selected
|
||||
if ($("#dealer").val()) {
|
||||
fetchStockData();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {});
|
||||
@@ -1 +0,0 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {});
|
||||
@@ -109,10 +109,7 @@ $(document).on("click", ".btn-product-stock-dealers", function () {
|
||||
},
|
||||
columns: [
|
||||
{ data: "dealer_name", name: "dealer_name" },
|
||||
{ data: "system_stock", name: "system_stock" },
|
||||
{ data: "physical_stock", name: "physical_stock" },
|
||||
{ data: "difference", name: "difference" },
|
||||
{ data: "opname_date", name: "opname_date" },
|
||||
{ data: "quantity", name: "quantity" },
|
||||
],
|
||||
initComplete: function () {
|
||||
$("#dealerStockModal").modal("show");
|
||||
|
||||
@@ -2,58 +2,205 @@
|
||||
|
||||
@section('content')
|
||||
<div class="kt-portlet kt-portlet--mobile" id="kt_blockui_datatable">
|
||||
<div class="kt-portlet__head kt-portlet__head--lg">
|
||||
<div class="kt-portlet__head-label">
|
||||
<span class="kt-portlet__head-icon">
|
||||
<i class="kt-font-brand flaticon2-plus"></i>
|
||||
</span>
|
||||
<h3 class="kt-portlet__head-title">Tambah Opnames</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="kt-portlet__body">
|
||||
<form id="opname-form" action="{{ route('opnames.store') }}" method="POST">
|
||||
@csrf
|
||||
<div class="form-group">
|
||||
<label for="dealer">Dealer</label>
|
||||
<select name="dealer" id="dealer" class="form-control" required >
|
||||
<option value="">Pilih Dealer</option>
|
||||
@foreach($dealers as $dealer)
|
||||
<option value="{{ $dealer->id }}">{{ $dealer->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="product-container" data-url="{{ route('products.all') }}">
|
||||
<div class="form-row align-items-end product-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="product[]">Produk</label>
|
||||
<select name="product[]" class="form-control product-select" required >
|
||||
<option value="">Pilih Produk</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label>Stok Sistem</label>
|
||||
<input type="text" name="system_quantity[]" class="form-control" placeholder="Stok sistem" required >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label>Stok Fisik</label>
|
||||
<input type="text" name="physical_quantity[]" class="form-control" placeholder="Stok fisik" required >
|
||||
</div>
|
||||
<div class="form-group col-md-2">
|
||||
<button type="button" class="btn btn-success btn-add-row"><i class="flaticon2-plus"></i></button>
|
||||
</div>
|
||||
<div class="kt-portlet__head kt-portlet__head--lg">
|
||||
<div class="kt-portlet__head-label">
|
||||
<span class="kt-portlet__head-icon">
|
||||
<i class="kt-font-brand flaticon2-plus"></i>
|
||||
</span>
|
||||
<h3 class="kt-portlet__head-title">Tambah Opnames</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mt-4">
|
||||
<button type="submit" class="btn btn-primary">Simpan</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="kt-portlet__body">
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul class="mb-0">
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form id="opname-form" action="{{ route('opnames.store') }}" method="POST">
|
||||
@csrf
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="dealer">Dealer <span class="text-danger">*</span></label>
|
||||
@php
|
||||
$oldDealer = old('dealer');
|
||||
$dealerValue = is_array($oldDealer) ? '' : $oldDealer;
|
||||
@endphp
|
||||
<select name="dealer" id="dealer" class="form-control @error('dealer') is-invalid @enderror" required>
|
||||
<option value="">Pilih Dealer</option>
|
||||
@foreach($dealers as $dealer)
|
||||
<option value="{{ $dealer->id }}" {{ $dealerValue == $dealer->id ? 'selected' : '' }}>
|
||||
{{ $dealer->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('dealer')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="note">Catatan</label>
|
||||
@php
|
||||
$oldNote = old('note');
|
||||
$noteValue = is_array($oldNote) ? '' : $oldNote;
|
||||
@endphp
|
||||
<textarea name="note" id="note" class="form-control @error('note') is-invalid @enderror"
|
||||
rows="2" placeholder="Catatan opname">{{ $noteValue }}</textarea>
|
||||
@error('note')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="kt-separator kt-separator--border-dashed kt-separator--space-lg kt-separator--portlet-fit"></div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col">
|
||||
<h4>Detail Produk</h4>
|
||||
</div>
|
||||
<div class="col text-right">
|
||||
<button type="button" class="btn btn-success btn-sm" id="btn-add-row">
|
||||
<i class="flaticon2-plus"></i> Tambah Produk
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover" id="product-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th style="width: 35%">Produk <span class="text-danger">*</span></th>
|
||||
<th style="width: 15%">Stok Sistem <span class="text-danger">*</span></th>
|
||||
<th style="width: 15%">Stok Fisik <span class="text-danger">*</span></th>
|
||||
<th style="width: 30%">Catatan</th>
|
||||
<th style="width: 5%" class="text-center">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$oldProducts = old('product', []);
|
||||
$oldSystemQuantities = old('system_quantity', []);
|
||||
$oldPhysicalQuantities = old('physical_quantity', []);
|
||||
$oldItemNotes = old('item_notes', []);
|
||||
@endphp
|
||||
<tr class="product-row">
|
||||
<td>
|
||||
<select name="product[0]" class="form-control product-select @error('product.0') is-invalid @enderror" required>
|
||||
<option value="">Pilih Produk</option>
|
||||
@foreach($products as $product)
|
||||
<option value="{{ $product->id }}" {{ (isset($oldProducts[0]) && $oldProducts[0] == $product->id) ? 'selected' : '' }}>
|
||||
{{ $product->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('product.0')
|
||||
<div class="invalid-feedback d-block">{{ $message }}</div>
|
||||
@enderror
|
||||
</td>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<input type="number" name="system_quantity[0]"
|
||||
class="form-control system-quantity @error('system_quantity.0') is-invalid @enderror"
|
||||
step="0.01" min="0"
|
||||
value="{{ $oldSystemQuantities[0] ?? '0' }}"
|
||||
readonly>
|
||||
</div>
|
||||
@error('system_quantity.0')
|
||||
<div class="invalid-feedback d-block">{{ $message }}</div>
|
||||
@enderror
|
||||
</td>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<input type="number" name="physical_quantity[0]"
|
||||
class="form-control @error('physical_quantity.0') is-invalid @enderror"
|
||||
step="0.01" min="0"
|
||||
value="{{ $oldPhysicalQuantities[0] ?? '' }}"
|
||||
required
|
||||
onchange="calculateDifference(this)">
|
||||
</div>
|
||||
@error('physical_quantity.0')
|
||||
<div class="invalid-feedback d-block">{{ $message }}</div>
|
||||
@enderror
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="item_notes[0]"
|
||||
class="form-control @error('item_notes.0') is-invalid @enderror"
|
||||
value="{{ $oldItemNotes[0] ?? '' }}"
|
||||
placeholder="(wajib jika ada perbedaan stock)">
|
||||
@error('item_notes.0')
|
||||
<div class="invalid-feedback d-block">{{ $message }}</div>
|
||||
@enderror
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button type="button" class="btn btn-danger btn-sm btn-remove-row" disabled>
|
||||
<i class="flaticon2-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="kt-separator kt-separator--border-dashed kt-separator--space-lg kt-separator--portlet-fit"></div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary btn-md">
|
||||
Simpan
|
||||
</button>
|
||||
<a href="{{ route('opnames.index') }}" class="btn btn-secondary btn-md">
|
||||
Batal
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Template untuk baris produk baru -->
|
||||
<template id="product-row-template">
|
||||
<tr class="product-row">
|
||||
<td>
|
||||
<select name="product[]" class="form-control product-select" required>
|
||||
<option value="">Pilih Produk</option>
|
||||
@foreach($products as $product)
|
||||
<option value="{{ $product->id }}">{{ $product->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<input type="number" name="system_quantity[]" class="form-control system-quantity"
|
||||
step="0.01" min="0" value="0" readonly>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<input type="number" name="physical_quantity[]" class="form-control"
|
||||
step="0.01" min="0" value="" required
|
||||
onchange="calculateDifference(this)">
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="item_notes[]" class="form-control"
|
||||
value="" placeholder="(wajib jika ada perbedaan stock)">
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button type="button" class="btn btn-danger btn-sm btn-remove-row">
|
||||
<i class="flaticon2-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
@endsection
|
||||
|
||||
@section('javascripts')
|
||||
<script src="{{ mix('js/warehouse_management/opnames/create.js') }}"></script>
|
||||
<script src="{{ asset('js/warehouse_management/opnames/create.js') }}"></script>
|
||||
@endsection
|
||||
|
||||
@@ -2,16 +2,21 @@
|
||||
|
||||
@section('content')
|
||||
<div class="kt-portlet kt-portlet--mobile" id="kt_blockui_datatable">
|
||||
<div class="kt-portlet__head kt-portlet__head--lg">
|
||||
<div class="kt-portlet__head-label">
|
||||
<span class="kt-portlet__head-icon">
|
||||
<i class="kt-font-brand flaticon2-list-1"></i>
|
||||
</span>
|
||||
<h3 class="kt-portlet__head-title">
|
||||
Detail Opname
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="kt-portlet__head kt-portlet__head--lg">
|
||||
<div class="kt-portlet__head-label">
|
||||
<span class="kt-portlet__head-icon">
|
||||
<i class="kt-font-brand flaticon2-list-1"></i>
|
||||
</span>
|
||||
<h3 class="kt-portlet__head-title">
|
||||
Opname {{ $opname->dealer->name }} Tanggal {{ Carbon\Carbon::parse($opname->opname_date)->format('d M Y') }}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="kt-portlet__head-toolbar">
|
||||
<a href="{{ route('opnames.index') }}" class="btn btn-secondary">
|
||||
<i class="la la-arrow-left"></i> Kembali
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="kt-portlet__body">
|
||||
<div class="table-responsive">
|
||||
@@ -35,5 +40,5 @@
|
||||
@endsection
|
||||
|
||||
@section('javascripts')
|
||||
<script src="{{ mix('js/warehouse_management/opnames/detail.js') }}"></script>
|
||||
<script src="{{ asset('js/warehouse_management/opnames/detail.js') }}"></script>
|
||||
@endsection
|
||||
@@ -30,7 +30,7 @@
|
||||
<tr>
|
||||
<th>Dealer</th>
|
||||
<th>Pengguna</th>
|
||||
<th>Tanggal Opname</th>
|
||||
<th>Tanggal</th>
|
||||
<th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -42,5 +42,5 @@
|
||||
@endsection
|
||||
|
||||
@section('javascripts')
|
||||
<script src="{{ mix('js/warehouse_management/opnames/index.js') }}"></script>
|
||||
<script src="{{ asset('js/warehouse_management/opnames/index.js') }}"></script>
|
||||
@endsection
|
||||
@@ -75,5 +75,5 @@
|
||||
@endsection
|
||||
|
||||
@section('javascripts')
|
||||
<script src="{{mix('js/warehouse_management/product_categories/index.js')}}"></script>
|
||||
<script src="{{ asset('js/warehouse_management/product_categories/index.js') }}"></script>
|
||||
@endsection
|
||||
@@ -69,7 +69,3 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('javascripts')
|
||||
<script src="{{ mix('js/warehouse_management/products/create.js') }}"></script>
|
||||
@endsection
|
||||
@@ -71,8 +71,4 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('javascripts')
|
||||
<script src="{{ mix('js/warehouse_management/products/edit.js') }}"></script>
|
||||
@endsection
|
||||
@@ -57,13 +57,9 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Dealer</th>
|
||||
<th>System Stock</th>
|
||||
<th>Physical Stock</th>
|
||||
<th>Difference</th>
|
||||
<th>Opname Date</th>
|
||||
<th>Stok</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -72,5 +68,5 @@
|
||||
@endsection
|
||||
|
||||
@section('javascripts')
|
||||
<script src="{{ mix('js/warehouse_management/products/index.js') }}"></script>
|
||||
<script src="{{ asset('js/warehouse_management/products/index.js') }}"></script>
|
||||
@endsection
|
||||
@@ -0,0 +1,19 @@
|
||||
<div class="d-flex">
|
||||
<button type="button" class="btn btn-success btn-sm mr-2"
|
||||
onclick="showAdjustStockModal({{ $stock->id }}, 'add')"
|
||||
title="Tambah Stok">
|
||||
<i class="la la-plus"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" class="btn btn-warning btn-sm mr-2"
|
||||
onclick="showAdjustStockModal({{ $stock->id }}, 'reduce')"
|
||||
title="Kurangi Stok">
|
||||
<i class="la la-minus"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" class="btn btn-info btn-sm"
|
||||
onclick="showStockHistory({{ $stock->id }})"
|
||||
title="Lihat Riwayat">
|
||||
<i class="la la-history"></i>
|
||||
</button>
|
||||
</div>
|
||||
234
resources/views/warehouse_management/stocks/index.blade.php
Normal file
234
resources/views/warehouse_management/stocks/index.blade.php
Normal file
@@ -0,0 +1,234 @@
|
||||
@extends('layouts.backapp')
|
||||
|
||||
@section('content')
|
||||
<div class="kt-portlet kt-portlet--mobile">
|
||||
<div class="kt-portlet__head kt-portlet__head--lg">
|
||||
<div class="kt-portlet__head-label">
|
||||
<span class="kt-portlet__head-icon">
|
||||
<i class="kt-font-brand flaticon2-box"></i>
|
||||
</span>
|
||||
<h3 class="kt-portlet__head-title">Manajemen Stok</h3>
|
||||
</div>
|
||||
<div class="kt-portlet__head-toolbar">
|
||||
<div class="kt-portlet__head-actions">
|
||||
<a href="{{ route('opnames.create') }}" class="btn btn-primary">
|
||||
<i class="la la-plus"></i> Buat Opname
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="kt-portlet__body">
|
||||
<!-- Filter -->
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="dealer_filter">Filter Dealer</label>
|
||||
<select class="form-control" id="dealer_filter">
|
||||
<option value="">Semua Dealer</option>
|
||||
@foreach($dealers as $dealer)
|
||||
<option value="{{ $dealer->id }}">{{ $dealer->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="product_filter">Filter Produk</label>
|
||||
<select class="form-control" id="product_filter">
|
||||
<option value="">Semua Produk</option>
|
||||
@foreach($products as $product)
|
||||
<option value="{{ $product->id }}">{{ $product->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabel Stok -->
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover" id="stocks-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th>Dealer</th>
|
||||
<th>Produk</th>
|
||||
<th>Stok</th>
|
||||
<th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Adjust Stock -->
|
||||
<div class="modal fade" id="adjustStockModal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Adjust Stok</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form id="adjustStockForm">
|
||||
<div class="modal-body">
|
||||
<input type="hidden" id="stock_id" name="stock_id">
|
||||
<input type="hidden" id="adjust_type" name="type">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Jumlah</label>
|
||||
<div class="input-group">
|
||||
<input type="number" class="form-control" name="quantity"
|
||||
step="0.01" min="0.01" required>
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">pcs</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Catatan</label>
|
||||
<textarea class="form-control" name="note" rows="3" required></textarea>
|
||||
</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">Simpan</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Stock History -->
|
||||
<div class="modal fade" id="stockHistoryModal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Riwayat Stok</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered" id="history-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th>Tanggal</th>
|
||||
<th>User</th>
|
||||
<th>Perubahan</th>
|
||||
<th>Stok Lama</th>
|
||||
<th>Stok Baru</th>
|
||||
<th>Catatan</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('javascripts')
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Inisialisasi DataTable
|
||||
var table = $('#stocks-table').DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
ajax: {
|
||||
url: '{{ route("stocks.index") }}',
|
||||
data: function(d) {
|
||||
d.dealer_id = $('#dealer_filter').val();
|
||||
d.product_id = $('#product_filter').val();
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
{data: 'dealer_name', name: 'dealer_name'},
|
||||
{data: 'product_name', name: 'product_name'},
|
||||
{data: 'quantity', name: 'quantity'},
|
||||
{data: 'action', name: 'action', orderable: false, searchable: false}
|
||||
]
|
||||
});
|
||||
|
||||
// Filter change handler
|
||||
$('#dealer_filter, #product_filter').change(function() {
|
||||
table.ajax.reload();
|
||||
});
|
||||
|
||||
// Show adjust stock modal
|
||||
window.showAdjustStockModal = function(stockId, type) {
|
||||
$('#stock_id').val(stockId);
|
||||
$('#adjust_type').val(type);
|
||||
$('#adjustStockModal').modal('show');
|
||||
};
|
||||
|
||||
// Handle adjust stock form submit
|
||||
$('#adjustStockForm').submit(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
url: '{{ route("stocks.adjust") }}',
|
||||
method: 'POST',
|
||||
data: {
|
||||
_token: '{{ csrf_token() }}',
|
||||
stock_id: $('#stock_id').val(),
|
||||
type: $('#adjust_type').val(),
|
||||
quantity: $('input[name="quantity"]').val(),
|
||||
note: $('textarea[name="note"]').val()
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
$('#adjustStockModal').modal('hide');
|
||||
table.ajax.reload();
|
||||
toastr.success(response.message);
|
||||
} else {
|
||||
toastr.error(response.message);
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
toastr.error(xhr.responseJSON?.message || 'Terjadi kesalahan');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Show stock history
|
||||
window.showStockHistory = function(stockId) {
|
||||
$.get('{{ route("stocks.history") }}', {
|
||||
stock_id: stockId
|
||||
})
|
||||
.done(function(response) {
|
||||
var tbody = $('#history-table tbody');
|
||||
tbody.empty();
|
||||
|
||||
response.logs.forEach(function(log) {
|
||||
tbody.append(`
|
||||
<tr>
|
||||
<td>${log.date}</td>
|
||||
<td>${log.user}</td>
|
||||
<td>${log.change}</td>
|
||||
<td>${log.old_quantity}</td>
|
||||
<td>${log.new_quantity}</td>
|
||||
<td>${log.note}</td>
|
||||
</tr>
|
||||
`);
|
||||
});
|
||||
|
||||
$('#stockHistoryModal').modal('show');
|
||||
})
|
||||
.fail(function(xhr) {
|
||||
toastr.error('Gagal memuat riwayat stok');
|
||||
});
|
||||
};
|
||||
|
||||
// Reset form when modal is closed
|
||||
$('#adjustStockModal').on('hidden.bs.modal', function() {
|
||||
$('#adjustStockForm')[0].reset();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user