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

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>