From 3a30d72203fe1d03aa0ee855c5a9113d66e5a21f Mon Sep 17 00:00:00 2001 From: ajikamaludin Date: Sun, 24 Jul 2022 12:34:43 +0700 Subject: [PATCH] absensi done --- app/Http/Controllers/GeneralController.php | 5 + app/Http/Middleware/HandleInertiaRequests.php | 5 + resources/css/app.css | 4 + resources/js/Components/Modal.jsx | 4 +- resources/js/Layouts/Authenticated.jsx | 4 +- resources/js/Pages/Absensi/FormModal.jsx | 128 +++++++++++++++++ resources/js/Pages/Absensi/Index.jsx | 132 ++++++++++++++++++ resources/js/Pages/Jabatan/FormModal.jsx | 77 +++++++++- resources/js/Pages/Jabatan/Index.jsx | 39 +++++- resources/js/Services/Absensi.js | 57 ++++++++ resources/js/Utils/index.js | 4 + routes/web.php | 1 + 12 files changed, 454 insertions(+), 6 deletions(-) create mode 100644 resources/js/Pages/Absensi/FormModal.jsx create mode 100644 resources/js/Pages/Absensi/Index.jsx create mode 100644 resources/js/Services/Absensi.js create mode 100644 resources/js/Utils/index.js diff --git a/app/Http/Controllers/GeneralController.php b/app/Http/Controllers/GeneralController.php index 2610381..4fe801c 100644 --- a/app/Http/Controllers/GeneralController.php +++ b/app/Http/Controllers/GeneralController.php @@ -21,4 +21,9 @@ class GeneralController extends Controller { return Inertia::render('Karyawan/Index'); } + + public function absensi() + { + return Inertia::render('Absensi/Index'); + } } diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index 4c52ec1..cacc8d7 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -35,6 +35,11 @@ class HandleInertiaRequests extends Middleware public function share(Request $request) { return array_merge(parent::share($request), [ + 'app_creator' => [ + 'nama' => 'Aji Kamaludin', + 'email' => 'aji.kamaludin2021@gmail.com', + 'github' => 'github.com/ajikamaludin' + ], 'auth' => [ 'user' => session('user'), ], diff --git a/resources/css/app.css b/resources/css/app.css index b5c61c9..4a69c71 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -1,3 +1,7 @@ @tailwind base; @tailwind components; @tailwind utilities; + +.select { + @apply border mt-1 border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-28 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 +} \ No newline at end of file diff --git a/resources/js/Components/Modal.jsx b/resources/js/Components/Modal.jsx index 27d9f37..a904acb 100644 --- a/resources/js/Components/Modal.jsx +++ b/resources/js/Components/Modal.jsx @@ -1,13 +1,13 @@ import React from 'react' -export function Modal({ isOpen, toggleModal = () => {}, children }) { +export function Modal({ isOpen, toggleModal = () => {}, children, size = 'lg' }) { return (
-
+
+ + ) +} \ No newline at end of file diff --git a/resources/js/Pages/Absensi/Index.jsx b/resources/js/Pages/Absensi/Index.jsx new file mode 100644 index 0000000..aee2f30 --- /dev/null +++ b/resources/js/Pages/Absensi/Index.jsx @@ -0,0 +1,132 @@ +import React, { useEffect, useState } from 'react'; +import Authenticated from '@/Layouts/Authenticated'; +import { Head, useForm } from '@inertiajs/inertia-react'; +import { useModalState } from '@/Hooks' +import Button from '@/Components/Button'; +import FormModal from './FormModal'; +import { getByPeriode } from '@/Services/Absensi'; +import { toast } from 'react-toastify'; + +export default function Karyawan(props) { + const formModal = useModalState(false) + + const month = (new Date()).getMonth() + const year = (new Date()).getFullYear() + const months = [1,2,3,4,5,6,7,8,9,10,11,12] + const years = [+year-2, +year-1, year, +year+1, +year+2] + + const {data, setData} = useForm({ + month: month, + year: year + }) + + const onHandleChange = (event) => { + setData( + event.target.name, + event.target.type === 'checkbox' + ? event.target.checked + : event.target.value + ) + } + + const [absensi, setAbsensi] = useState({}) + const onClickShow = () => { + setAbsensi({}) + getByPeriode(`${data.month}_${data.year}`) + .then(items => { + if(items.length <= 0) { + toast.error("No data found") + return + } + setAbsensi(items[0]) + }) + } + + return ( + + + +
+
+
+
+
+
+

Periode Data :

+ + +
+
+ + +
+
+ + + + + + + + + + + + + + {absensi.data?.users?.map(item => ( + + + + + + + + + + ))} + +
+ NIK + + Nama + + Jenis Kelamin + + Jabatan + HadirSakitAlfa
+ {item.nik} + + {item.name} + + {item.jenisKelamin} + + {item.jabatan} + + {item.hadir} + + {item.sakit} + + {item.alfa} +
+
+
+
+
+ +
+ ); +} diff --git a/resources/js/Pages/Jabatan/FormModal.jsx b/resources/js/Pages/Jabatan/FormModal.jsx index e274372..92fed0f 100644 --- a/resources/js/Pages/Jabatan/FormModal.jsx +++ b/resources/js/Pages/Jabatan/FormModal.jsx @@ -10,9 +10,24 @@ export default function FormModal({ modalState, refresh }) { const [loading, setLoading] = useState(false) const { data, setData, reset } = useForm({ nama: '', - tunjangan: 0 + gajiPokok: 0, + tunjangan: 0, + feePenjualan: 0, + transport: 0, + uangMakan: 0, + bonus: 0, + total: 0 }) + const total = +data.gajiPokok + +data.tunjangan + +data.feePenjualan + +data.transport + +data.uangMakan + +data.bonus + + useEffect(() => { + setData({ + ...data, + total: total + }) + }, [total]) + useEffect(() => { if (modalState.isOpen === false) { reset() @@ -71,6 +86,18 @@ export default function FormModal({ modalState, refresh }) { handleChange={onHandleChange} /> + + + + + diff --git a/resources/js/Pages/Jabatan/Index.jsx b/resources/js/Pages/Jabatan/Index.jsx index cd2ed30..f229774 100644 --- a/resources/js/Pages/Jabatan/Index.jsx +++ b/resources/js/Pages/Jabatan/Index.jsx @@ -6,6 +6,7 @@ import Button from '@/Components/Button'; import FormModal from './FormModal'; import { getAll, deleteById } from '@/Services/Jabatan'; import { toast } from 'react-toastify'; +import { formatIDR } from '@/Utils'; export default function Jabatan(props) { const formModal = useModalState(false) @@ -53,9 +54,27 @@ export default function Jabatan(props) { Nama + + Gaji Pokok + Tunjangan + + Fee Penjualan + + + Tunjangan Transport + + + Uang Makan + + + Bonus + + + Total + @@ -66,7 +85,25 @@ export default function Jabatan(props) { {item.data.nama} - Rp. {item.data.tunjangan} + Rp. {formatIDR(item.data.gajiPokok)} + + + Rp. {formatIDR(item.data.tunjangan)} + + + Rp. {formatIDR(item.data.feePenjualan)} + + + Rp. {formatIDR(item.data.transport)} + + + Rp. {formatIDR(item.data.uangMakan)} + + + Rp. {formatIDR(item.data.bonus)} + + + Rp. {formatIDR(item.data.total)}
diff --git a/resources/js/Services/Absensi.js b/resources/js/Services/Absensi.js new file mode 100644 index 0000000..1fca1c9 --- /dev/null +++ b/resources/js/Services/Absensi.js @@ -0,0 +1,57 @@ +import db from "@/firebase"; +import { collection, getDocs, doc, addDoc, deleteDoc, updateDoc, query, where } from "firebase/firestore"; + +const COLLECTION = "absensi" + +async function getAll() { + const collect = collection(db, COLLECTION) + const data = await getDocs(collect) + const lists = data.docs.map(doc => { + return { + data: doc.data(), + id: doc.id + } + }) + return lists +} + +async function getByPeriode(periode) { + const collect = query(collection(db, COLLECTION), where("periode", "==", periode)) + const data = await getDocs(collect) + if (data.size <= 0) { + return [] + } + const lists = data.docs.map(doc => { + return { + data: doc.data(), + id: doc.id + } + }) + return lists +} + +async function create(payload) { + const docRef = await addDoc(collection(db, COLLECTION), payload) + return docRef.id +} + +async function update(payload, id){ + const docRef = doc(db, COLLECTION, id) + const result = await updateDoc(docRef, payload); + return result +} + +async function deleteById(id) { + console.log(id) + const docRef = doc(db, COLLECTION, id) + const result = await deleteDoc(docRef); + return result +} + +export { + getAll, + create, + update, + deleteById, + getByPeriode +} \ No newline at end of file diff --git a/resources/js/Utils/index.js b/resources/js/Utils/index.js new file mode 100644 index 0000000..074f4a6 --- /dev/null +++ b/resources/js/Utils/index.js @@ -0,0 +1,4 @@ +export function formatIDR(amount) { + const idFormatter = new Intl.NumberFormat('id-ID') + return idFormatter.format(amount) +} \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index fd7cfa4..d25d33f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -31,5 +31,6 @@ Route::middleware([IsSessionAuth::class])->group(function () { Route::get('/dashboard', [GeneralController::class, 'dashboard'])->name('dashboard'); Route::get('/jabatan', [GeneralController::class, 'jabatan'])->name('jabatan'); Route::get('/karyawan', [GeneralController::class, 'karyawan'])->name('karyawan'); + Route::get('/absensi', [GeneralController::class, 'absensi'])->name('absensi'); Route::post('/logout', [AuthController::class, 'destroy'])->name('logout'); });