add tambah gaji dan slip gaji

This commit is contained in:
Naufalakram 2023-11-26 01:58:25 +08:00
parent 13cbb8ce02
commit 4b340095a6
6 changed files with 241 additions and 9 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1 +1,51 @@
[]
[
{
"date": "22/09/2023",
"absensi": [
{
"name": "Aran",
"jam_masuk": "00:04:01",
"jam_keluar": "13:14:01"
}
]
},
{
"date": "22/10/2023",
"absensi": [
{
"name": "Aran",
"jam_masuk": "00:04:01",
"jam_keluar": "13:14:01"
}
]
},
{
"date": "23/11/2023",
"absensi": [
{
"name": "Aran",
"jam_masuk": "00:04:01",
"jam_keluar": "13:14:01"
}
]
},
{
"date": "23/11/2023",
"absensi": [
{
"name": "Naufal",
"jam_masuk": "00:04:01",
"jam_keluar": "13:14:01"
}
]
},
{
"date": "25/11/2023",
"absensi": [
{
"name": "Aran",
"jam_masuk": "00:14:28"
}
]
}
]

View File

@ -1 +1 @@
[{"name": "Naufal", "nik": "1"}, {"name": "Aran", "nik": "12345"}]
[{"name": "Naufal", "nik": "1", "gaji": 50000}, {"name": "Aran", "nik": "12345", "gaji": 20000}]

View File

@ -63,6 +63,7 @@ def home():
@app.route('/cek_absensi')
def cek_absensi():
today_date = time.strftime("%d/%m/%Y")
this_month_and_year = time.strftime("%m/%Y")
all_data = None
len_all_data = 0
# open absensi file
@ -80,11 +81,39 @@ def cek_absensi():
all_data = last_data['absensi']
# get the length of the "absensi" data
len_all_data = len(all_data)
len_karyawan = 0
data_karyawan = None
# open the dataset file
with open(dataset, 'r') as f:
data_karyawan = json.load(f)
len_karyawan = len(data_karyawan)
this_month_absensi = []
# print(data)
for i in range(len_data):
# print(all_data[i])
if data[i]['date'][3:] == this_month_and_year:
this_month_absensi.append(data[i])
# print(this_month_absensi)
# print(data_karyawan)
# loop data_karyawan and then loop this_month_absensi to check if the name is exist, if exist then add the gaji
for i in range(len_karyawan):
pendapatan = 0
for j in range(len(this_month_absensi)):
for k in range(len(this_month_absensi[j]['absensi'])):
if data_karyawan[i]['name'] == this_month_absensi[j]['absensi'][k]['name']:
pendapatan += data_karyawan[i]['gaji']
data_karyawan[i]['pendapatan'] = pendapatan
print(data_karyawan)
return render_template('index2.html', data=all_data, length=len_all_data, today_date=today_date)
return render_template('index2.html', data=all_data, length=len_all_data, today_date=today_date, data_karyawan=data_karyawan, length_karyawan=len_karyawan , bulan_ini=this_month_and_year)
@app.route('/scan_face')
def scan_face():
@ -120,6 +149,7 @@ def tambah_karyawan():
def tambah_karyawan_post():
nama = request.form['nama']
nik = request.form['nik']
gaji = int(request.form['gaji'])
# print(nama)
# print(nik)
@ -130,7 +160,8 @@ def tambah_karyawan_post():
# insert the new data
data.append({
'name': nama,
'nik': nik
'nik': nik,
'gaji': gaji
})
# save the dataset file
@ -140,6 +171,9 @@ def tambah_karyawan_post():
# return the json
return {'status': 'OK'}
# dibawah ni untuk buka main2.py dan loading page
@app.route('/scan_face2')
def scan_face2():

View File

@ -51,7 +51,7 @@
<div id="wrapper">
<div class="main-content container">
<div class="row small-spacing">
<div class="col-xs-2 col-md-2"></div>
<div class="col-xs-8 col-md-8">
@ -99,6 +99,59 @@
</div>
<div class="row small-spacing">
<div class="col-xs-2 col-md-2"></div>
<div class="col-xs-8 col-md-8">
<div class="box-content card">
<h4 class="box-title">Bulan/Tahun : {{bulan_ini}}</h4>
<div class="card-content">
<table id="example" class="table table-striped table-bordered display" style="width:100%">
<thead>
<tr>
<td><b>Nama</b></td>
<td><b>Gaji/Hari</b></td>
<td><b>Pendapatan/Bulan</b></td>
<td><b>Aksi</b></td>
</tr>
</thead>
<tbody>
{%if data_karyawan %}
{% for i in range(0, length_karyawan) %}
<tr>
<td>{{data_karyawan[i]['name']}}</td>
<td class="gajinya">{{data_karyawan[i]['gaji']}}</td>
<td class="gajinya">{{data_karyawan[i]['pendapatan']}}</td>
<td>
<!-- create a button to print slip gaji -->
<button type="button" class="btn btn-xs btn-primary"
onclick="printDiv(`{{data_karyawan[i]['name']}}`,`{{data_karyawan[i]['gaji']}}`,`{{data_karyawan[i]['pendapatan']}}`)">Print
Slip Gaji</button>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="3" class="text-center">Tidak ada data</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
</div>
<div class="col-xs-2 col-md-2"></div>
</div>
@ -144,6 +197,60 @@
window.location.href = "{{url_for('tambah_karyawan')}}";
}
}
// create a function that addn thousand separator using comma
function addThousandSeparator(number) {
// Convert the number to a string
let numStr = number.toString();
// Use a regular expression to add commas as thousand separators
numStr = numStr.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return numStr;
}
// Get all <td> elements with the class "ini dia"
const tdElements = document.querySelectorAll('td.gajinya');
// Iterate through each <td> element
tdElements.forEach(td => {
// Get the current value of the <td>
let currentValue = parseFloat(td.textContent);
// Check if the value is a valid number
if (!isNaN(currentValue)) {
// Update the content of the <td> with the formatted value
td.textContent = 'Rp. ' + addThousandSeparator(currentValue);
}
});
function addThousandSeparators(value) {
return value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
function printDiv(name, gaji, pendapatan) {
console.log(name, gaji, pendapatan);
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title>DIV Contents</title>');
printWindow.document.write('</head><body >');
printWindow.document.write('<h1>Slip Gaji</h1>');
printWindow.document.write('<p>Nama : ' + name + '</p>');
printWindow.document.write('<p>Gaji : Rp.' + addThousandSeparator(gaji) + '</p>');
printWindow.document.write('<p>Pendapatan : Rp. ' + addThousandSeparator(pendapatan) + '</p>');
printWindow.document.write('<p>Tanggal : {{today_date}}</p>');
printWindow.document.write('<p>Terima kasih atas kerja keras anda</p>');
// ttd
printWindow.document.write('<br><br><br><br>');
printWindow.document.write('<p>TTD</p>');
printWindow.document.write('<p>Naufal</p>');
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
}
</script>
</body>

View File

@ -88,6 +88,14 @@
<input type="text" class="form-control" id="nama" name="nama"
placeholder="Masukkan Nama Karyawan">
</div>
<div class="form-group">
<label for="nik">Gaji Karyawan / Hari</label>
<input type="text" class="form-control" id="gaji" name="gaji"
oninput="this.value = this.value.replace(/[^0-9]/g, '').replace(/\B(?=(\d{3})+(?!\d))/g, ',');"
placeholder="Masukkan Gaji/Hari Karyawan" minlength="6" maxlength="7">
</div>
<div class="form-group text-center">
<button type="button" onclick="tambah_data()"
class="btn btn-primary btn-sm waves-effect waves-light">
@ -113,6 +121,7 @@
<td><b>No</b></td>
<td><b>NIK</b></td>
<td><b>Nama</b></td>
<td><b>Gaji/Hari</b></td>
</tr>
</thead>
@ -125,6 +134,7 @@
<td>{{i+1}}</td>
<td>{{data[i]['nik']}}</td>
<td>{{data[i]['name']}}</td>
<td class="gajinya">{{data[i]['gaji']}}</td>
</tr>
{% endfor %}
{% endif %}
@ -189,7 +199,8 @@
var nik = $('#nik').val();
var nama = $('#nama').val();
if (nik == '' || nama == '') {
var gaji = $('#gaji').val();
if (nik == '' || nama == '' || gaji == '') {
swal({
title: "Gagal",
text: "Data tidak boleh kosong",
@ -199,12 +210,15 @@
closeOnConfirm: false
});
} else {
// remove comma from gaji
gaji = gaji.replace(/,/g, '');
$.ajax({
url: "http://127.0.0.1:5000/tambah_karyawan",
type: "POST",
data: {
nik: nik,
nama: nama
nama: nama,
gaji: gaji
},
success: function (data) {
// console.log(data)
@ -216,6 +230,33 @@
});
}
}
// create a function that addn thousand separator using comma
function addThousandSeparator(number) {
// Convert the number to a string
let numStr = number.toString();
// Use a regular expression to add commas as thousand separators
numStr = numStr.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return numStr;
}
// Get all <td> elements with the class "ini dia"
const tdElements = document.querySelectorAll('td.gajinya');
// Iterate through each <td> element
tdElements.forEach(td => {
// Get the current value of the <td>
let currentValue = parseFloat(td.textContent);
// Check if the value is a valid number
if (!isNaN(currentValue)) {
// Update the content of the <td> with the formatted value
td.textContent = 'Rp. ' + addThousandSeparator(currentValue);
}
});
</script>
</body>