From 6f89d682cabe9b938a4e2da915ab23eb7dab7637 Mon Sep 17 00:00:00 2001 From: ajikamaludin Date: Sun, 24 Jul 2022 22:21:39 +0700 Subject: [PATCH] done --- app/Http/Controllers/GeneralController.php | 5 + resources/js/Layouts/Authenticated.jsx | 107 +++++--- resources/js/Pages/Auth/Login.jsx | 3 +- resources/js/Pages/Gaji/UserGaji.jsx | 268 +++++++++++++++++++++ resources/js/Services/DataGaji.js | 57 ++++- resources/js/Services/User.js | 7 +- routes/web.php | 1 + 7 files changed, 406 insertions(+), 42 deletions(-) create mode 100644 resources/js/Pages/Gaji/UserGaji.jsx diff --git a/app/Http/Controllers/GeneralController.php b/app/Http/Controllers/GeneralController.php index b762872..db3158e 100644 --- a/app/Http/Controllers/GeneralController.php +++ b/app/Http/Controllers/GeneralController.php @@ -41,4 +41,9 @@ class GeneralController extends Controller { return Inertia::render('Gaji/Slip'); } + + public function userGaji() + { + return Inertia::render('Gaji/UserGaji'); + } } diff --git a/resources/js/Layouts/Authenticated.jsx b/resources/js/Layouts/Authenticated.jsx index 8ea343b..d511886 100644 --- a/resources/js/Layouts/Authenticated.jsx +++ b/resources/js/Layouts/Authenticated.jsx @@ -84,6 +84,7 @@ export default function Authenticated({ auth, children }) {
+ {auth.user.is_admin ? (
Dashboard @@ -107,6 +108,16 @@ export default function Authenticated({ auth, children }) { Slip Gaji
+ ) : ( +
+ + Dashboard + + + Data Gaji + +
+ )}
@@ -126,45 +137,63 @@ export default function Authenticated({ auth, children }) {
diff --git a/resources/js/Pages/Auth/Login.jsx b/resources/js/Pages/Auth/Login.jsx index 72c8408..698667c 100644 --- a/resources/js/Pages/Auth/Login.jsx +++ b/resources/js/Pages/Auth/Login.jsx @@ -29,7 +29,8 @@ export default function Login({ status, canResetPassword }) { name: user.name, username: user.username, password: user.password, - is_admin: user.is_admin + is_admin: user.is_admin, + id: user.id }) } else { setError('Username atau password tidak cocok') diff --git a/resources/js/Pages/Gaji/UserGaji.jsx b/resources/js/Pages/Gaji/UserGaji.jsx new file mode 100644 index 0000000..2dbd922 --- /dev/null +++ b/resources/js/Pages/Gaji/UserGaji.jsx @@ -0,0 +1,268 @@ +import React, { useEffect, useRef, 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 { getDataGajiByUser } from '@/Services/DataGaji'; +import { useReactToPrint } from 'react-to-print'; +import { formatIDR } from '@/Utils'; + +const ComponentToPrintOne = React.forwardRef(({ user, month, year }, ref) => { + const date = new Date() + return ( +
+
+

Koro Koro Family Karaoke

+

Slip Gaji Pegawai

+
+ + + + + + + + + + + + + + + + + + + + + + + +
Nama Karyawan : {user?.name}
NIK : {user?.nik}
Jabatan : {user?.jabatan}
Bulan : {month}
Tahun: {year}
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NoKeteranganJumlah
1Gaji PokokRp. {formatIDR(user?.gajiPokok)}
2Tunjangan JabatanRp. {formatIDR(user?.tunjangan)}
3Fee PenjualanRp. {formatIDR(user?.feePenjualan)}
4Tunjangan TransaportasiRp. {formatIDR(user?.transport)}
5Uang MakanRp. {formatIDR(user?.uangMakan)}
6BonusRp. {formatIDR(user?.bonus)}
7PotonganRp. {formatIDR(user?.potongan)}
Total GajiRp. {formatIDR(user?.total)}
+
+
+

Pegawai

+
{user?.name}
+
+
+

Pekanbaru, {date.getDate()}-{date.getMonth()}-{date.getFullYear()}

+

Finance

+
+
+
+
+ ) +}) + +export default function Gaji(props) { + const user = props.auth.user + const formModal = useModalState(false) + + const componentRefOne = useRef(); + const handlePrintOne = useReactToPrint({ + content: () => componentRefOne.current, + }); + + 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 [items, setItems] = useState([]) + + const onClickShow = () => {getDataGajiByUser(`${data.month}_${data.year}`, setItems, user.id)} + + const one = items[0] + + useEffect(() => { + getDataGajiByUser(`${data.month}_${data.year}`, setItems, user.id) + }, [data]) + + return ( + + + +
+
+
+
+
+ Data Gaji +
+
+
+

Periode Data :

+ + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + {items.map(item => ( + + + + + + + + + + + + + + + ))} + +
+ NIK + + Nama + + Jabatan + + Gaji Pokok + + Tunjangan + + Fee Penjualan + + Uang Transport + + Uang Makan + + Bonus + + Potongan + + Total +
+ {item.nik} + + {item.name} + + {item.jabatan} + + Rp. {formatIDR(item.gajiPokok)} + + Rp. {formatIDR(item.tunjangan)} + + Rp. {formatIDR(item.feePenjualan)} + + Rp. {formatIDR(item.transport)} + + Rp. {formatIDR(item.uangMakan)} + + Rp. {formatIDR(item.bonus)} + + Rp. {formatIDR(item.potongan)} + + Rp. {formatIDR(item.total)} + + +
+
+
+
+
+ +
+ ); +} diff --git a/resources/js/Services/DataGaji.js b/resources/js/Services/DataGaji.js index 105daf2..9633d26 100644 --- a/resources/js/Services/DataGaji.js +++ b/resources/js/Services/DataGaji.js @@ -51,6 +51,61 @@ async function getDataGaji(periode, setLists) { }) } +async function getDataGajiByUser(periode, setLists, userId) { + let potongan = [] + getJabatan() + .then(jabatans => { + getByPeriode(periode).then(items => { + if(items[0] == undefined) { + setLists([]) + toast.error("data tidak tersedia") + return + } + getPotongan() + .then(p => p.map(item => { + potongan.push(item) + })) + .finally(() => { + let alfa = potongan.find(pot => pot.data.jenis == 'alfa') + let sakit = potongan.find(pot => pot.data.jenis == 'sakit') + + let filtered = items[0].data.users.filter(user => user.id == userId) + if(filtered == undefined) { + toast.error("data tidak tersedia") + return + } + + let employees = filtered.map(employee => { + let jab = jabatans.find(item => item.id == employee.jabatan_id) + + let potong = 0 + if(alfa != undefined) { + potong += +alfa.data.potongan * +employee.alfa + } + if(sakit != undefined) { + potong += +sakit.data.potongan * +employee.sakit + } + + return { + ...employee, + gajiPokok: jab.data.gajiPokok, + tunjangan: jab.data.tunjangan, + feePenjualan: jab.data.feePenjualan, + transport: jab.data.transport, + uangMakan: jab.data.uangMakan, + bonus: jab.data.bonus, + potongan: potong, + total: +jab.data.total - +potong + } + }) + setLists(employees) + }) + + }) + }) +} + export { - getDataGaji + getDataGaji, + getDataGajiByUser } \ No newline at end of file diff --git a/resources/js/Services/User.js b/resources/js/Services/User.js index edd6e30..431c406 100644 --- a/resources/js/Services/User.js +++ b/resources/js/Services/User.js @@ -4,7 +4,12 @@ import { collection, getDocs } from "firebase/firestore"; async function getAllUsers() { const usersCollcetion = collection(db, 'users') const users = await getDocs(usersCollcetion) - const usersList = users.docs.map(doc => doc.data()) + const usersList = users.docs.map(doc => { + return { + ...doc.data(), + id: doc.id + } + }) return usersList } diff --git a/routes/web.php b/routes/web.php index fe0884e..33a1bdd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -35,5 +35,6 @@ Route::middleware([IsSessionAuth::class])->group(function () { Route::get('/setting-potong-gaji', [GeneralController::class, 'settingPotongGaji'])->name('setting.potongan.gaji'); Route::get('/data-gaji', [GeneralController::class, 'dataGaji'])->name('gaji'); Route::get('/slip-gaji', [GeneralController::class, 'slipGaji'])->name('slip.gaji'); + Route::get('/user-gaji', [GeneralController::class, 'userGaji'])->name('user.gaji'); Route::post('/logout', [AuthController::class, 'destroy'])->name('logout'); });