updated absensi, branch
This commit is contained in:
@@ -13,9 +13,4 @@ router.use('/attedances', AbsensRouter)
|
||||
router.use('/branches', BranchRouter)
|
||||
router.use('/user-management', userManagement)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = router
|
||||
|
||||
@@ -33,8 +33,6 @@ router.post("/forgot-password", apiKey, function name(req, res) {
|
||||
controller.resetPassword(req, res, token);
|
||||
});
|
||||
|
||||
|
||||
|
||||
module.exports = router
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ router.post('/', apiKey, jwt, (req, res) => {
|
||||
controller.create(req, res)
|
||||
})
|
||||
|
||||
|
||||
router.get('/', apiKey, jwt, (req, res) => {
|
||||
controller.index(req, res)
|
||||
})
|
||||
|
||||
@@ -67,19 +67,9 @@ const create = async (req, res) => {
|
||||
}
|
||||
|
||||
if (attendance && attendance.clock_in) {
|
||||
// 🕛 Jika jam antara 12–15 → lunch_in
|
||||
if (currentHour >= 12 && currentHour < 15 && !attendance.lunch_in) {
|
||||
attendance.lunch_in = now.toDate();
|
||||
await attendance.save({ transaction: t });
|
||||
await t.commit();
|
||||
return response.success(res, attendance, 'Absen masuk setelah makan siang berhasil');
|
||||
}
|
||||
if (currentHour < 12 && !attendance.lunch_in) {
|
||||
await t.rollback();
|
||||
return response.failed(res, 400, 'Belum waktunya absen setelah makan siang');
|
||||
}
|
||||
|
||||
// 🕒 Jika jam >= 15 → otomatis clock_out
|
||||
// 🕛 Jika branch tidak mengaktifkan absen siang
|
||||
if (!branch.lunch_attendance) {
|
||||
// Langsung lewati logika absen siang dan lanjut ke clock_out
|
||||
if (currentHour >= 15 && !attendance.clock_out) {
|
||||
attendance.clock_out = now.toDate();
|
||||
|
||||
@@ -91,24 +81,71 @@ const create = async (req, res) => {
|
||||
await attendance.save({ transaction: t });
|
||||
await t.commit();
|
||||
|
||||
return response.success(res, {
|
||||
return response.success(
|
||||
res,
|
||||
{
|
||||
...attendance.toJSON(),
|
||||
branch_name: branch.name,
|
||||
clock_in: moment(attendance.clock_in).tz('Asia/Jakarta').format('YYYY-MM-DD HH:mm:ss'),
|
||||
clock_out: moment(attendance.clock_out).tz('Asia/Jakarta').format('YYYY-MM-DD HH:mm:ss'),
|
||||
work_duration: attendance.work_duration,
|
||||
}, 'Absen pulang berhasil');
|
||||
},
|
||||
'Absen pulang berhasil'
|
||||
);
|
||||
}
|
||||
|
||||
if (currentHour < 15 && !attendance.clock_out) {
|
||||
await t.rollback();
|
||||
return response.failed(res, 400, 'Belum waktunya absen pulang');
|
||||
}
|
||||
} else {
|
||||
// 🕛 Jika branch pakai absen siang
|
||||
if (currentHour >= 12 && currentHour < 15 && !attendance.lunch_in) {
|
||||
attendance.lunch_in = now.toDate();
|
||||
await attendance.save({ transaction: t });
|
||||
await t.commit();
|
||||
return response.success(res, attendance, 'Absen masuk setelah makan siang berhasil');
|
||||
}
|
||||
|
||||
if (currentHour < 12 && !attendance.lunch_in) {
|
||||
await t.rollback();
|
||||
return response.failed(res, 400, 'Belum waktunya absen setelah makan siang');
|
||||
}
|
||||
|
||||
if (currentHour >= 15 && !attendance.clock_out) {
|
||||
attendance.clock_out = now.toDate();
|
||||
|
||||
const durationMs = moment(attendance.clock_out).diff(moment(attendance.clock_in));
|
||||
const hours = Math.floor(durationMs / (1000 * 60 * 60));
|
||||
const minutes = Math.floor((durationMs % (1000 * 60 * 60)) / (1000 * 60));
|
||||
attendance.work_duration = `${hours} jam ${minutes} menit`;
|
||||
|
||||
await attendance.save({ transaction: t });
|
||||
await t.commit();
|
||||
|
||||
return response.success(
|
||||
res,
|
||||
{
|
||||
...attendance.toJSON(),
|
||||
branch_name: branch.name,
|
||||
clock_in: moment(attendance.clock_in).tz('Asia/Jakarta').format('YYYY-MM-DD HH:mm:ss'),
|
||||
clock_out: moment(attendance.clock_out).tz('Asia/Jakarta').format('YYYY-MM-DD HH:mm:ss'),
|
||||
work_duration: attendance.work_duration,
|
||||
},
|
||||
'Absen pulang berhasil'
|
||||
);
|
||||
}
|
||||
|
||||
if (currentHour < 15 && attendance.lunch_in && !attendance.clock_out) {
|
||||
await t.rollback();
|
||||
return response.failed(res, 400, 'Belum waktunya absen pulang');
|
||||
}
|
||||
}
|
||||
|
||||
await t.rollback();
|
||||
return response.failed(res, 400, 'Sudah melakukan absen hari ini');
|
||||
}
|
||||
|
||||
|
||||
// === Jika sudah absen masuk tapi belum pulang ===
|
||||
// if (attendance && attendance.clock_in && !attendance.clock_out) {
|
||||
// attendance.clock_out = now.toDate(); // waktu WIB
|
||||
@@ -137,7 +174,6 @@ const create = async (req, res) => {
|
||||
return response.failed(res, 400, `Lokasi di luar area kantor (${distance.toFixed(2)} meter)`);
|
||||
}
|
||||
|
||||
|
||||
let finalPhotoUrl = null;
|
||||
|
||||
if (req.file) {
|
||||
|
||||
@@ -31,6 +31,11 @@ module.exports = (sequelize) => {
|
||||
type: DataTypes.DECIMAL(20, 15),
|
||||
allowNull: false,
|
||||
},
|
||||
lunch_attendance: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
allowNull: true
|
||||
},
|
||||
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
|
||||
Reference in New Issue
Block a user