create crud product categories and partial update crud products with dealers stock
This commit is contained in:
109
resources/js/warehouse_management/product_categories/index.js
Normal file
109
resources/js/warehouse_management/product_categories/index.js
Normal file
@@ -0,0 +1,109 @@
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||||
},
|
||||
});
|
||||
let tableContainer = $("#product-categories-table");
|
||||
let url = tableContainer.data("url");
|
||||
let table = $("#product-categories-table").DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
ajax: url,
|
||||
columns: [
|
||||
{
|
||||
data: "DT_RowIndex",
|
||||
name: "DT_RowIndex",
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
},
|
||||
{ data: "name", name: "name" },
|
||||
{ data: "action", name: "action", orderable: false, searchable: false },
|
||||
],
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#addProductCategory").click(function () {
|
||||
$("#productCategoryForm")[0].reset();
|
||||
$("#category_id").val("");
|
||||
$("#modalTitle").text("Tambah Kategori");
|
||||
$("#productCategoryModal").modal("show");
|
||||
});
|
||||
|
||||
// Submit form (baik tambah maupun edit)
|
||||
$("#productCategoryForm").submit(function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
let id = $("#category_id").val();
|
||||
let url = id
|
||||
? `/warehouse/product_categories/${id}`
|
||||
: `/warehouse/product_categories`;
|
||||
let method = id ? "PUT" : "POST";
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: method,
|
||||
data: {
|
||||
name: $("#name").val(),
|
||||
_token: $('meta[name="csrf-token"]').attr("content"),
|
||||
...(id && { _method: "PUT" }),
|
||||
},
|
||||
success: function () {
|
||||
$("#productCategoryModal").modal("hide");
|
||||
$("#product-categories-table").DataTable().ajax.reload();
|
||||
},
|
||||
error: function (xhr) {
|
||||
alert("Gagal menyimpan data");
|
||||
console.error(xhr.responseText);
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
$(document).on("click", ".btn-edit-product-category", function () {
|
||||
const id = $(this).data("id");
|
||||
const url = $(this).data("url");
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: "GET",
|
||||
success: function (response) {
|
||||
$("#category_id").val(response.id);
|
||||
$("#name").val(response.name);
|
||||
$("#modalTitle").text("Edit Kategori");
|
||||
$("#productCategoryModal").modal("show");
|
||||
},
|
||||
error: function (xhr) {
|
||||
alert("Gagal mengambil data");
|
||||
console.error(xhr.responseText);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("click", ".btn-destroy-product-category", function () {
|
||||
Swal.fire({
|
||||
title: "Hapus nama kategori?",
|
||||
text: "Anda tidak akan bisa mengembalikannya!",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#d33",
|
||||
cancelButtonColor: "#dedede",
|
||||
confirmButtonText: "Hapus",
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
const url = $(this).data("action");
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: "POST",
|
||||
data: {
|
||||
_method: "DELETE",
|
||||
_token: $('meta[name="csrf-token"]').attr("content"),
|
||||
},
|
||||
success: function () {
|
||||
alert("Kategori berhasil dihapus.");
|
||||
$("#product-categories-table").DataTable().ajax.reload();
|
||||
},
|
||||
error: function (xhr) {
|
||||
alert("Gagal menghapus kategori.");
|
||||
console.error(xhr.responseText);
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
112
resources/js/warehouse_management/products/index.js
Normal file
112
resources/js/warehouse_management/products/index.js
Normal file
@@ -0,0 +1,112 @@
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||||
},
|
||||
});
|
||||
let tableContainer = $("#products-table");
|
||||
let url = tableContainer.data("url");
|
||||
let table = $("#products-table").DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
ajax: url,
|
||||
columns: [
|
||||
{
|
||||
data: "DT_RowIndex",
|
||||
name: "DT_RowIndex",
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
},
|
||||
{ data: "code", name: "code" },
|
||||
{ data: "name", name: "name" },
|
||||
{ data: "category_name", name: "category.name" },
|
||||
{ data: "total_stock", name: "total_stock" },
|
||||
{ data: "action", name: "action", orderable: false, searchable: false },
|
||||
],
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#addProductCategory").click(function () {
|
||||
$("#productCategoryForm")[0].reset();
|
||||
$("#category_id").val("");
|
||||
$("#modalTitle").text("Tambah Kategori");
|
||||
$("#productCategoryModal").modal("show");
|
||||
});
|
||||
|
||||
// Submit form (baik tambah maupun edit)
|
||||
$("#productCategoryForm").submit(function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
let id = $("#category_id").val();
|
||||
let url = id
|
||||
? `/warehouse/product_categories/${id}`
|
||||
: `/warehouse/product_categories`;
|
||||
let method = id ? "PUT" : "POST";
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: method,
|
||||
data: {
|
||||
name: $("#name").val(),
|
||||
_token: $('meta[name="csrf-token"]').attr("content"),
|
||||
...(id && { _method: "PUT" }),
|
||||
},
|
||||
success: function () {
|
||||
$("#productCategoryModal").modal("hide");
|
||||
$("#product-categories-table").DataTable().ajax.reload();
|
||||
},
|
||||
error: function (xhr) {
|
||||
alert("Gagal menyimpan data");
|
||||
console.error(xhr.responseText);
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
$(document).on("click", ".btn-edit-product-category", function () {
|
||||
const id = $(this).data("id");
|
||||
const url = $(this).data("url");
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: "GET",
|
||||
success: function (response) {
|
||||
$("#category_id").val(response.id);
|
||||
$("#name").val(response.name);
|
||||
$("#modalTitle").text("Edit Kategori");
|
||||
$("#productCategoryModal").modal("show");
|
||||
},
|
||||
error: function (xhr) {
|
||||
alert("Gagal mengambil data");
|
||||
console.error(xhr.responseText);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("click", ".btn-destroy-product-category", function () {
|
||||
Swal.fire({
|
||||
title: "Hapus nama kategori?",
|
||||
text: "Anda tidak akan bisa mengembalikannya!",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#d33",
|
||||
cancelButtonColor: "#dedede",
|
||||
confirmButtonText: "Hapus",
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
const url = $(this).data("action");
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: "POST",
|
||||
data: {
|
||||
_method: "DELETE",
|
||||
_token: $('meta[name="csrf-token"]').attr("content"),
|
||||
},
|
||||
success: function () {
|
||||
alert("Kategori berhasil dihapus.");
|
||||
$("#product-categories-table").DataTable().ajax.reload();
|
||||
},
|
||||
error: function (xhr) {
|
||||
alert("Gagal menghapus kategori.");
|
||||
console.error(xhr.responseText);
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user