partial update products

This commit is contained in:
2025-06-04 16:58:50 +07:00
parent 215792ce63
commit 8305e44c42
35 changed files with 179 additions and 707 deletions

View File

@@ -125,8 +125,10 @@ $(document).on("click", ".btn-destroy-product-category", function () {
});
function loadParentCategories(selectedId = null) {
const selectElement = $("#parent_id");
let urlParents = selectElement.data("url");
$.ajax({
url: "/warehouse/categories/parents", // create this route
url: urlParents,
type: "GET",
success: function (data) {
$("#parent_id")

View File

@@ -1,43 +1 @@
document.addEventListener("DOMContentLoaded", function () {
const addBtn = document.getElementById("addDealerRow");
const dealerRows = document.getElementById("dynamicDealerRows");
// Get dealer data from Blade
const dealerDataDiv = document.getElementById("dealerData");
const dealers = JSON.parse(dealerDataDiv.getAttribute("data-dealers")); // 👈 this reads JSON from Blade
let rowCount = 0;
function createDealerRow(index) {
const dealerOptions = dealers
.map((d) => `<option value="${d.id}">${d.name}</option>`)
.join("");
return `
<div class="form-group row align-items-center dealer-row" data-index="${index}">
<div class="col-md-5">
<select name="dealer_stock[${index}][dealer_id]" class="form-control" required>
<option value="">-- Pilih Dealer --</option>
${dealerOptions}
</select>
</div>
<div class="col-md-4">
<input type="number" name="dealer_stock[${index}][quantity]" class="form-control" value="1" min="1" required>
</div>
<div class="col-md-3">
<button type="button" class="btn btn-danger btn-sm removeDealerRow">Hapus</button>
</div>
</div>
`;
}
addBtn.addEventListener("click", function () {
dealerRows.insertAdjacentHTML("beforeend", createDealerRow(rowCount));
rowCount++;
});
dealerRows.addEventListener("click", function (e) {
if (e.target.classList.contains("removeDealerRow")) {
e.target.closest(".dealer-row").remove();
}
});
});
document.addEventListener("DOMContentLoaded", function () {});

View File

@@ -1,48 +1 @@
document.addEventListener("DOMContentLoaded", function () {
let dealerRowContainer = document.getElementById("dynamicDealerRows");
let addDealerButton = document.getElementById("addDealerRow");
// Initial index from existing dealer rows
let rowIndex =
dealerRowContainer.querySelectorAll(".dealer-stock-row").length;
addDealerButton.addEventListener("click", function () {
const newRow = document.createElement("div");
newRow.className = "form-group row align-items-center dealer-stock-row";
newRow.innerHTML = `
<div class="col-md-6">
<select name="dealer_stock[${rowIndex}][dealer_id]" class="form-control">
<option value="">-- Pilih Dealer --</option>
${generateDealerOptions()}
</select>
</div>
<div class="col-md-4">
<input type="number" name="dealer_stock[${rowIndex}][quantity]" class="form-control" value="1" min="1" required placeholder="Jumlah Stok" />
</div>
<div class="col-md-2">
<button type="button" class="btn btn-danger btn-sm remove-dealer-row"> Hapus </button>
</div>
`;
dealerRowContainer.appendChild(newRow);
rowIndex++;
});
// Handle removal of dealer row
dealerRowContainer.addEventListener("click", function (event) {
if (
event.target &&
event.target.classList.contains("remove-dealer-row")
) {
event.target.closest(".dealer-stock-row").remove();
}
});
// Function to generate dealer <option> elements dynamically
function generateDealerOptions() {
const dealerDataDiv = document.getElementById("dealerData");
const dealers = JSON.parse(dealerDataDiv.getAttribute("data-dealers"));
return dealers
.map((d) => `<option value="${d.id}">${d.name}</option>`)
.join("");
}
});
document.addEventListener("DOMContentLoaded", function () {});

View File

@@ -1,20 +0,0 @@
$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
});
let tableContainer = $("#stock-mutations-table");
let url = tableContainer.data("url");
let table = $("#stock-mutations-table").DataTable({
processing: true,
serverSide: true,
ajax: url,
columns: [
{ data: "product_name", name: "product_name" },
{ data: "dealer_name", name: "dealer_name" },
{ data: "user_name", name: "user_name" },
{ data: "mutation_type_label", name: "mutation_type_label" },
{ data: "quantity", name: "quantity" },
{ data: "created_at", name: "created_at" },
],
});

View File

@@ -1,21 +0,0 @@
$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
});
let tableContainer = $("#stock-opnames-table");
let url = tableContainer.data("url");
let table = $("#stock-opnames-table").DataTable({
processing: true,
serverSide: true,
ajax: url,
columns: [
{ data: "product_name", name: "product_name" },
{ data: "dealer_name", name: "dealer_name" },
{ data: "user_name", name: "user_name" },
{ data: "system_quantity", name: "system_quantity" },
{ data: "physical_quantity", name: "physical_quantity" },
{ data: "difference", name: "difference" },
{ data: "opname_date", name: "opname_date" },
],
});

View File

@@ -138,18 +138,18 @@
</div>
{{-- Submenu Items --}}
@can('view', $menus['dealer.index'])
@can('view', $menus['user.index'])
<li class="kt-menu__item" aria-haspopup="true">
<a href="{{ route('dealer.index') }}" class="kt-menu__link">
<a href="{{ route('user.index') }}" class="kt-menu__link">
<i class="fa fa-car" style="display: flex; align-items: center; margin-right: 10px;"></i>
<span class="kt-menu__link-text">Pengguna</span>
</a>
</li>
@endcan
@can('view', $menus['category.index'])
@can('view', $menus['roleprivileges.index'])
<li class="kt-menu__item" aria-haspopup="true">
<a href="{{ route('category.index') }}" class="kt-menu__link">
<a href="{{ route('roleprivileges.index') }}" class="kt-menu__link">
<i class="fa fa-users" style="display: flex; align-items: center; margin-right: 10px;"></i>
<span class="kt-menu__link-text">Role & Privileges</span>
</a>
@@ -163,9 +163,9 @@
</div>
{{-- Submenu Items --}}
@can('view', $menus['dealer.index'])
@can('view', $menus['work.index'])
<li class="kt-menu__item" aria-haspopup="true">
<a href="{{ route('dealer.index') }}" class="kt-menu__link">
<a href="{{ route('work.index') }}" class="kt-menu__link">
<i class="fa fa-car" style="display: flex; align-items: center; margin-right: 10px;"></i>
<span class="kt-menu__link-text">Pekerjaan</span>
</a>
@@ -181,9 +181,9 @@
</li>
@endcan
@can('view', $menus['work.index'])
@can('view', $menus['dealer.index'])
<li class="kt-menu__item" aria-haspopup="true">
<a href="{{ route('work.index') }}" class="kt-menu__link">
<a href="{{ route('dealer.index') }}" class="kt-menu__link">
<i class="fa fa-list" style="display: flex; align-items: center; margin-right: 10px;"></i>
<span class="kt-menu__link-text">Dealer</span>
</a>
@@ -224,9 +224,9 @@
</li>
@endcan
@can('view', $menus['work.index'])
@can('view', $menus['opnames.index'])
<li class="kt-menu__item" aria-haspopup="true">
<a href="{{ route('work.index') }}" class="kt-menu__link">
<a href="{{ route('opnames.index') }}" class="kt-menu__link">
<i class="fa fa-list" style="display: flex; align-items: center; margin-right: 10px;"></i>
<span class="kt-menu__link-text">Stock Opname</span>
</a>

View File

@@ -5,7 +5,7 @@
<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-line-chart"></i>
<i class="kt-font-brand flaticon2-list-1"></i>
</span>
<h3 class="kt-portlet__head-title">
Tabel Kategori Produk
@@ -58,7 +58,7 @@
</div>
<div class="mb-3">
<label for="parent_id" class="form-label">Induk Kategori (Opsional)</label>
<select class="form-control" id="parent_id" name="parent_id">
<select class="form-control" id="parent_id" name="parent_id" data-url="{{ route('product_categories.parents') }}">
<option value="">-- Tidak ada (Kategori Utama) --</option>
<!-- will be filled by JavaScript -->
</select>

View File

@@ -5,7 +5,7 @@
<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-line-chart"></i>
<i class="kt-font-brand flaticon2-plus"></i>
</span>
<h3 class="kt-portlet__head-title">Tambah Produk</h3>
</div>
@@ -59,18 +59,7 @@
@endforeach
</select>
</div>
{{-- Dynamic Dealer Stock Section --}}
<div id="dealerData" data-dealers='@json($dealers)'></div>
<div class="form-group">
<label><strong>Stok per Dealer</strong></label>
<div id="dynamicDealerRows"></div>
<button type="button" id="addDealerRow" class="btn btn-outline-primary mt-2">
Tambah Dealer
</button>
</div>
{{-- Submit --}}
<div class="form-group mt-4">
<button type="submit" class="btn btn-primary">Simpan</button>

View File

@@ -5,9 +5,9 @@
<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-line-chart"></i>
<i class="kt-font-brand flaticon2-edit"></i>
</span>
<h3 class="kt-portlet__head-title">Tambah Produk</h3>
<h3 class="kt-portlet__head-title">Ubah Produk</h3>
</div>
</div>
@@ -32,6 +32,14 @@
<input type="text" name="unit" id="unit" class="form-control" value="{{ old('unit', $product->unit) }}" required>
</div>
<div class="form-group">
<label for="active"><strong>Status Produk</strong></label>
<select name="active" class="form-control" required>
<option value="1">Aktif</option>
<option value="0">Tidak Aktif</option>
</select>
</div>
<div class="form-group">
<label for="description"><strong>Deskripsi</strong></label>
<textarea name="description" id="description" class="form-control" rows="3">{{ old('description', $product->description) }}</textarea>
@@ -55,36 +63,6 @@
</select>
</div>
{{-- Stok per Dealer --}}
<div id="dealerData" data-dealers='@json($dealers)'></div>
<div class="form-group">
<label><strong>Stok per Dealer</strong></label>
<div id="dynamicDealerRows">
@foreach($product->dealers as $index => $dealer)
<div class="form-group row align-items-center dealer-stock-row">
<div class="col-md-6">
<select name="dealer_stock[{{ $index }}][dealer_id]" class="form-control">
<option value="">-- Pilih Dealer --</option>
@foreach ($dealers as $d)
<option value="{{ $d->id }}" {{ $d->id == $dealer->id ? 'selected' : '' }}>
{{ $d->name }}
</option>
@endforeach
</select>
</div>
<div class="col-md-4">
<input type="number" name="dealer_stock[{{ $index }}][quantity]" value="{{ $dealer->pivot->quantity }}" class="form-control" placeholder="Jumlah Stok" />
</div>
<div class="col-md-2">
<button type="button" class="btn btn-danger btn-sm remove-dealer-row">Hapus</button>
</div>
</div>
@endforeach
</div>
<button type="button" id="addDealerRow" class="btn btn-outline-primary mt-2"> Tambah Dealer</button>
</div>
{{-- Submit --}}
<div class="form-group mt-4">
<button type="submit" class="btn btn-primary">Simpan</button>

View File

@@ -5,7 +5,7 @@
<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-line-chart"></i>
<i class="kt-font-brand flaticon2-list-1"></i>
</span>
<h3 class="kt-portlet__head-title">
Tabel Produk

View File

@@ -5,7 +5,7 @@
<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-line-chart"></i>
<i class="kt-font-brand flaticon2-list-1"></i>
</span>
<h3 class="kt-portlet__head-title">
Tabel Mutasi Stock Produk

View File

@@ -0,0 +1,56 @@
@extends('layouts.backapp')
@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 Opname
</h3>
</div>
</div>
<div class="kt-portlet__body">
<form action="{{ route('opnames.store') }}" method="POST" id="opnameForm">
@csrf
<div class="form-group">
<label for="product"><strong>Produk</strong></label>
<input type="text" class="form-control" name="product" />
</div>
<div class="form-group">
<label for="dealer"><strong>Dealer</strong></label>
<input type="text" class="form-control" name="dealer" />
</div>
<div class="form-group">
<label for="system_quantity"><strong>Total Sistem</strong></label>
<input type="number" class="form-control" name="system_quantity" />
</div>
<div class="form-group">
<label for="phisycal_quantity"><strong>Total Sistem</strong></label>
<input type="number" class="form-control" name="phisycal_quantity" />
</div>
<div class="form-group">
<label for="difference"><strong>Perbedaan</strong></label>
<input type="number" class="form-control" name="difference" />
</div>
<div class="form-group mt-4">
<button type="submit" class="btn btn-primary">Simpan</button>
<a href="{{ route('opnames.index') }}" class="btn btn-secondary">Batal</a>
</div>
</form>
</div>
</div>
@endsection
@section('javascripts')
<script src="{{mix('js/warehouse_management/stock_opnames/create.js')}}"></script>
@endsection

View File

@@ -5,13 +5,13 @@
<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-line-chart"></i>
<i class="kt-font-brand flaticon2-list-1"></i>
</span>
<h3 class="kt-portlet__head-title">
Tabel Mutasi Stock Produk
Tabel Stock Opname
</h3>
</div>
@can('create', $menus['mutations.index'])
@can('create', $menus['opnames.index'])
<div class="kt-portlet__head-toolbar">
<div class="kt-portlet__head-wrapper">
<div class="kt-portlet__head-actions">