create update tourisms

This commit is contained in:
arifal
2025-02-18 02:45:39 +07:00
parent aff31e08ef
commit 1dd971fb73
16 changed files with 3233 additions and 2982 deletions

View File

@@ -199,7 +199,7 @@ class AdvertisementController extends Controller
public function downloadExcelAdvertisement()
{
$filePath = storage_path('app/public/templateFile/template_reklame.xlsx');
$filePath = storage_path('app/public/templates/template_reklame.xlsx');
// Cek apakah file ada
if (!file_exists($filePath)) {

View File

@@ -56,7 +56,14 @@ class TourismController extends Controller
*/
public function store(TourismRequest $request): Tourism
{
return Tourism::create($request->validated());
info($request);
$data = $request->validated();
$district_code = DB::table('districts')->where('district_name', $data['district_name'])->value('district_code');
$village_code = DB::table('villages')->where('village_name', $data['village_name'])->where('district_code', $district_code)->value('village_code');
$data['district_code'] = $district_code;
$data['village_code'] = $village_code;
return Tourism::create($data);
}
/**

View File

@@ -176,7 +176,7 @@ class UmkmController extends Controller
public function downloadExcelUmkm()
{
$filePath = storage_path('app/public/templateFile/template_umkm.xlsx');
$filePath = storage_path('app/public/templates/template_umkm.xlsx');
// Cek apakah file ada
if (!file_exists($filePath)) {

View File

@@ -38,6 +38,7 @@ class TourismController extends Controller
'village_name' => DB::table('villages')->orderBy('village_name')->pluck('village_name', 'village_code'),
'district_name' => DB::table('districts')->orderBy('district_name')->pluck('district_name', 'district_code'),
'business_type_id' => DB::table('business_type')->orderBy('business_type')->pluck('business_type', 'id'),
'business_scale_id' => DB::table('business_scale')->orderBy('business_scale')->pluck('business_scale', 'id'),
];
$fields = $this->getFields();
@@ -90,6 +91,7 @@ class TourismController extends Controller
{
return [
"business_name" => "Nama Usaha",
"business_form" => "Bentuk Usaha",
"project_name" => "Nama Project",
"business_address" => "Alamat Usaha",
"district_name" => "Kecamatan",
@@ -98,6 +100,13 @@ class TourismController extends Controller
"investment_amount" => "Jumlah Investasi",
"number_of_employee" => "TKI",
"business_type_id" => "Jenis Usaha",
"project_id" => "Priject ID",
"nib" => "NIB",
"jenis_proyek" => "Jenis Proyek",
"status_penanaman_modal" => "Status Penanaman Modal",
"uraian_resiko_proyek" => "Uraian Resiko Proyek",
"business_scale_id" => "Skala Bisnis/Usaha",
"terbit_oss" => "Terbit OSS",
];
}
@@ -105,6 +114,7 @@ class TourismController extends Controller
{
return [
"business_name" => "text",
"business_form" => "text",
"project_name" => "text",
"business_address" => "textarea",
"district_name" => "combobox",
@@ -113,6 +123,13 @@ class TourismController extends Controller
"investment_amount" => "text",
"number_of_employee" => "text",
"business_type_id" => "select",
"project_id" => "text",
"nib" => "text",
"jenis_proyek" => "text",
"status_penanaman_modal" => "text",
"uraian_resiko_proyek" => "text",
"business_scale_id" => "select",
"terbit_oss" => "date"
];
}
}

View File

@@ -22,20 +22,23 @@ class TourismRequest extends FormRequest
public function rules(): array
{
return [
'jenis_proyek' => 'string',
'jenis_proyek' => 'required|string',
'nib' => 'string',
'business_name' => 'required|string',
'status_penanaman_modal' => 'string',
'business_form' => 'string',
'uraian_resiko_proyek' => 'string',
'project_name' => 'required|string',
'project_id' => 'required|string',
'business_address' => 'required|string',
'district_code' => 'required|string',
'village_code' => 'required|string',
'district_name' => 'required|string',
'village_name' => 'required|string',
'land_area' => 'required|string',
'investment_amount' => 'required|string',
'number_of_employee' => 'required|string',
'business_type_id' => 'required|string',
'terbit_oss' => 'required|date',
'business_scale_id' => 'required',
];
}
}

View File

@@ -67,6 +67,13 @@ class UsersRoleMenuSeeder extends Seeder
"icon" => "mingcute:task-line",
"parent_id" => null,
"sort_order" => 5,
],
[
"name" => "Laporan",
"url" => "/laporan",
"icon" => "mingcute:task-line",
"parent_id" => null,
"sort_order" => 6,
]
];
@@ -84,6 +91,7 @@ class UsersRoleMenuSeeder extends Seeder
$settings = Menu::where('name', 'Settings')->first();
$dataSettings = Menu::where('name', 'Data Settings')->first();
$data = Menu::where('name', 'Data')->first();
$laporan = Menu::where('name', 'Laporan')->first();
// create children menu
$children_menus = [
@@ -155,7 +163,28 @@ class UsersRoleMenuSeeder extends Seeder
"url" => "business-industries.index",
"icon" => null,
"parent_id" => $data->id,
"sort_order" => 2,
"sort_order" => 3,
],
[
"name" => "UMKM",
"url" => "umkm.index",
"icon" => null,
"parent_id" => $data->id,
"sort_order" => 4,
],
[
"name" => "Pariwisata",
"url" => "tourisms.index",
"icon" => null,
"parent_id" => $data->id,
"sort_order" => 5,
],
[
"name" => "Lap Pariwisata",
"url" => "tourisms.index",
"icon" => null,
"parent_id" => $laporan->id,
"sort_order" => 1,
],
];
@@ -173,6 +202,9 @@ class UsersRoleMenuSeeder extends Seeder
$setting_pbg = Menu::where('name', 'PBG')->first();
$reklame = Menu::where('name', 'Reklame')->first();
$businessIndustries = Menu::where('name', 'Usaha atau Industri')->first();
$pariwisata = Menu::where('name', 'Pariwisata')->first();
$laporan_pariwisata = Menu::where('name', 'Lap Pariwisata')->first();
$umkm = Menu::where('name', 'UMKM')->first();
// Superadmin gets all menus
$superadmin->menus()->sync([
@@ -182,6 +214,7 @@ class UsersRoleMenuSeeder extends Seeder
$settings->id => ["allow_show" => true, "allow_create" => false, "allow_update" => false, "allow_destroy" => false],
$dataSettings->id => ["allow_show" => true, "allow_create" => false, "allow_update" => false, "allow_destroy" => false],
$data->id => ["allow_show" => true, "allow_create" => false, "allow_update" => false, "allow_destroy" => false],
$laporan->id => ["allow_show" => true, "allow_create" => false, "allow_update" => false, "allow_destroy" => false],
// children
$dashboard_pimpinan->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
$dashboard_pbg->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
@@ -193,6 +226,9 @@ class UsersRoleMenuSeeder extends Seeder
$setting_pbg->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
$reklame->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
$businessIndustries->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
$pariwisata->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
$laporan_pariwisata->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
$umkm->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true],
]);
// Admin gets limited menus

5883
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -17,6 +17,7 @@
},
"dependencies": {
"apexcharts": "^3.44.2",
"big.js": "^6.2.2",
"bootstrap": "^5.3.3",
"countup.js": "^2.3.2",
"dropzone": "^5.9.0",

View File

@@ -95,6 +95,33 @@
"__commonjsHelpers-C4iS2aBk.js"
]
},
"resources/js/business-industries/create.js": {
"file": "assets/create-CiRhiWZV.js",
"name": "create",
"src": "resources/js/business-industries/create.js",
"isEntry": true,
"imports": [
"_dropzone-B5tMhgFp.js",
"_global-config-9uDKFQ8j.js"
]
},
"resources/js/business-industries/index.js": {
"file": "assets/index-BIXijOG8.js",
"name": "index",
"src": "resources/js/business-industries/index.js",
"isEntry": true,
"imports": [
"_gridjs.umd-BiCNXlqL.js",
"_global-config-9uDKFQ8j.js",
"__commonjsHelpers-C4iS2aBk.js"
]
},
"resources/js/business-industries/update.js": {
"file": "assets/update-C8VOvIbF.js",
"name": "update",
"src": "resources/js/business-industries/update.js",
"isEntry": true
},
"resources/js/config.js": {
"file": "assets/config-DqV4EBmE.js",
"name": "config",
@@ -120,7 +147,7 @@
"isEntry": true
},
"resources/js/data-settings/index.js": {
"file": "assets/index-BOfsbw53.js",
"file": "assets/index-C4raIbBK.js",
"name": "index",
"src": "resources/js/data-settings/index.js",
"isEntry": true,
@@ -137,7 +164,7 @@
"isEntry": true
},
"resources/js/data/advertisements/data-advertisements.js": {
"file": "assets/data-advertisements-C_ZfB4RA.js",
"file": "assets/data-advertisements-oslZaKHh.js",
"name": "data-advertisements",
"src": "resources/js/data/advertisements/data-advertisements.js",
"isEntry": true,
@@ -157,16 +184,17 @@
]
},
"resources/js/data/advertisements/form-upload.js": {
"file": "assets/form-upload-Ci7Kyzc7.js",
"file": "assets/form-upload-tA9zPESO.js",
"name": "form-upload",
"src": "resources/js/data/advertisements/form-upload.js",
"isEntry": true,
"imports": [
"_dropzone-B5tMhgFp.js"
"_dropzone-B5tMhgFp.js",
"_global-config-9uDKFQ8j.js"
]
},
"resources/js/master/users/create.js": {
"file": "assets/create-RO4xgm-f.js",
"file": "assets/create-BfiYISiN.js",
"name": "create",
"src": "resources/js/master/users/create.js",
"isEntry": true
@@ -401,7 +429,7 @@
"isEntry": true
},
"resources/scss/style.scss": {
"file": "assets/style-H92i7DXd.css",
"file": "assets/style-vmU-kDl3.css",
"src": "resources/scss/style.scss",
"isEntry": true
}

Binary file not shown.

Binary file not shown.

View File

@@ -4,7 +4,6 @@ import "gridjs/dist/gridjs.umd.js";
import GlobalConfig from "../../global-config.js";
import GeneralTable from "../../table-generator.js";
const dataTourismsColumns = [
"Proyek ID",
"Jenis Proyek",
@@ -25,7 +24,7 @@ const dataTourismsColumns = [
{
name: "Actions",
widht: "120px",
formatter: function(cell, row) {
formatter: function (cell, row) {
const id = row.cells[16].data;
const model = "data/tourisms";
return gridjs.html(`
@@ -39,8 +38,8 @@ const dataTourismsColumns = [
<i class='bx bxs-trash' ></i></button>
</div>
`);
}
}
},
},
];
document.addEventListener("DOMContentLoaded", () => {
@@ -55,13 +54,13 @@ document.addEventListener("DOMContentLoaded", () => {
return data.data.map((item) => {
return [
item.project_id,
item.jenis_project,
item.jenis_proyek,
item.nib,
item.business_name,
item.terbit_oss,
item.status_penanaman_modal,
item.business_form,
item.uraian_resiko_project,
item.uraian_resiko_proyek,
item.project_name,
item.business_address,
item.district_name,
@@ -76,4 +75,4 @@ document.addEventListener("DOMContentLoaded", () => {
};
table.init();
})
});

View File

@@ -0,0 +1,193 @@
import GlobalConfig from "../../global-config";
document.addEventListener("DOMContentLoaded", function () {
const saveButton = document.querySelector(".modal-footer .btn-primary");
const modalButton = document.querySelector(".btn-modal");
const form = document.querySelector("form#create-update-form");
var authLogo = document.querySelector(".auth-logo");
if (!saveButton || !form) return;
saveButton.addEventListener("click", function () {
// Disable tombol dan tampilkan spinner
modalButton.disabled = true;
modalButton.innerHTML = `
<span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span>
Loading...
`;
const isEdit = saveButton.classList.contains("btn-edit");
const formData = new FormData(form);
const toast = document.getElementById("toastEditUpdate");
const toastBody = toast.querySelector(".toast-body");
const toastHeader = toast.querySelector(".toast-header small");
const data = {};
// Mengonversi FormData ke dalam JSON
formData.forEach((value, key) => {
data[key] = value;
});
// Log semua data dalam FormData
for (let pair of formData.entries()) {
console.log(pair[0] + ": " + pair[1]);
}
const url = form.getAttribute("action");
console.log("Ini adalah url dari form action", url);
const method = isEdit ? "PUT" : "POST";
fetch(url, {
method: method,
body: JSON.stringify(data),
headers: {
Authorization: `Bearer ${document
.querySelector('meta[name="api-token"]')
.getAttribute("content")}`,
"Content-Type": "application/json",
},
})
.then((response) => response.json())
.then((data) => {
console.log("Response data:", data);
if (!data.errors) {
// Remove existing icon (if any) before adding the new one
if (authLogo) {
// Hapus ikon yang sudah ada jika ada
const existingIcon = authLogo.querySelector(".bx");
if (existingIcon) {
authLogo.removeChild(existingIcon);
}
// Buat ikon baru
const icon = document.createElement("i");
icon.classList.add("bx", "bxs-check-square");
icon.style.fontSize = "25px";
icon.style.color = "green"; // Pastikan 'green' dalam bentuk string
// Tambahkan ikon ke dalam auth-logo
authLogo.appendChild(icon);
}
// Set success message for the toast
toastBody.textContent = isEdit
? "Data updated successfully!"
: "Data created successfully!";
toast.classList.add("show"); // Show the toast
setTimeout(() => {
toast.classList.remove("show"); // Hide the toast after 3 seconds
}, 3000);
setTimeout(() => {
window.location.href = "/data/tourisms";
}, 3000);
} else {
if (authLogo) {
// Hapus ikon yang sudah ada jika ada
const existingIcon = authLogo.querySelector(".bx");
if (existingIcon) {
authLogo.removeChild(existingIcon);
}
// Buat ikon baru
const icon = document.createElement("i");
icon.classList.add("bx", "bxs-error-alt");
icon.style.fontSize = "25px";
icon.style.color = "red"; // Pastikan 'green' dalam bentuk string
// Tambahkan ikon ke dalam auth-logo
authLogo.appendChild(icon);
}
// Set error message for the toast
toastBody.textContent =
"Error: " + (data.message || "Something went wrong");
toast.classList.add("show"); // Show the toast
// Enable button and reset its text on error
modalButton.disabled = false;
modalButton.innerHTML = isEdit ? "Update" : "Create";
setTimeout(() => {
toast.classList.remove("show"); // Hide the toast after 3 seconds
}, 3000);
}
})
.catch((error) => {
console.error("Error:", error);
if (authLogo) {
// Hapus ikon yang sudah ada jika ada
const existingIcon = authLogo.querySelector(".bx");
if (existingIcon) {
authLogo.removeChild(existingIcon);
}
// Buat ikon baru
const icon = document.createElement("i");
icon.classList.add("bx", "bxs-error-alt");
icon.style.fontSize = "25px";
icon.style.color = "red"; // Pastikan 'green' dalam bentuk string
// Tambahkan ikon ke dalam auth-logo
authLogo.appendChild(icon);
}
// Set error message for the toast
toastBody.textContent =
"An error occurred while processing your request.";
toast.classList.add("show"); // Show the toast
// Enable button and reset its text on error
modalButton.disabled = false;
modalButton.innerHTML = isEdit ? "Update" : "Create";
setTimeout(() => {
toast.classList.remove("show"); // Hide the toast after 3 seconds
}, 3000);
});
});
// Fungsi fetchOptions untuk autocomplete server-side
window.fetchOptions = function (field) {
let inputValue = document.getElementById(field).value;
console.log("Query Value:", inputValue); // Debugging log
if (inputValue.length < 2) return;
let districtValue = document.getElementById("district_name").value; // Ambil kecamatan terpilih
let url = `${
GlobalConfig.apiHost
}/api/combobox/search-options?query=${encodeURIComponent(
inputValue
)}&field=${field}`;
// Jika field desa, tambahkan kecamatan sebagai filter
if (field === "village_name") {
url += `&district=${encodeURIComponent(districtValue)}`;
}
fetch(url, {
method: "GET",
headers: {
Authorization: `Bearer ${document
.querySelector('meta[name="api-token"]')
.getAttribute("content")}`,
"Content-Type": "application/json",
},
})
.then((response) => response.json())
.then((data) => {
let dataList = document.getElementById(field + "Options");
dataList.innerHTML = "";
data.forEach((item) => {
let option = document.createElement("option");
option.value = item.name;
option.dataset.code = item.code;
dataList.appendChild(option);
});
})
.catch((error) => console.error("Error fetching options:", error));
};
document.querySelector(".btn-back").addEventListener("click", function () {
window.history.back();
});
});

View File

@@ -63,6 +63,8 @@
<input class="form-control" list="{{ $field }}Options" id="{{ $field }}" name="{{ $field }}"
value="{{ old($field, isset($modelInstance) ? $modelInstance->{$field} : '') }}" placeholder="Type to search..." oninput="fetchOptions('{{ $field }}')">
<datalist id="{{ $field }}Options"></datalist>
@elseif($fieldType == 'date')
<input type="date" id="{{ $field }}" name="{{ $field }}" class="form-control" value="{{ old($field, isset($modelInstance) ? $modelInstance->{$field} : '') }}">
@else
<input type="{{ $fieldType }}" id="{{ $field }}" name="{{ $field }}" class="form-control" value="{{ old($field, isset($modelInstance) ? $modelInstance->{$field} : '') }}">
@endif
@@ -123,5 +125,5 @@
@endsection
@section('scripts')
@vite(['resources/js/data/umkm/form-create-update.js'])
@vite(['resources/js/data/tourisms/form-create-update.js'])
@endsection

View File

@@ -77,5 +77,5 @@
@endsection
@section('scripts')
@vite(['resources/roles/role_menu.js'])
@vite(['resources/js/roles/role_menu.js'])
@endsection

View File

@@ -85,6 +85,6 @@ Route::group(['middleware' => 'auth'], function(){
// Report
Route::group(['prefix' => '/report'], function(){
// Resource route, kecuali create karena dibuat terpisah
Route::resource('/tourisms', ReportTourismController::class);
Route::resource('/tourisms-report', ReportTourismController::class);
});
});