๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Lect & Tip/javascript, jQuery

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๊ทผ๋กœ๊ธฐ์ค€๋ฒ• ์—ฐ์ฐจ์ผ์ˆ˜ ๊ณ„์‚ฐ๊ธฐ ๋งŒ๋“ค๊ธฐ

by st๊ณต๊ฐ„ 2024. 6. 16.

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๊ทผ๋กœ๊ธฐ์ค€๋ฒ• ์—ฐ์ฐจ์ผ์ˆ˜ ๊ณ„์‚ฐ๊ธฐ ๋งŒ๋“ค๊ธฐ

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ทผ๋กœ๊ธฐ์ค€๋ฒ• ์—ฐ์ฐจ์ผ์ˆ˜ ๊ณ„์‚ฐ๊ธฐ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์—ฐ์ฐจํœด๊ฐ€ ๊ณ„์‚ฐ๊ธฐ๋Š” ๊ทผ๋กœ์ž์˜ ์ž…์‚ฌ์ผ, ๊ทผ๋กœ๊ธฐ๊ฐ„, ๊ทธ๋ฆฌ๊ณ  ์ถœ๊ทผ์œจ์„ ๊ธฐ์ค€์œผ๋กœ ์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜๋ฅผ ์ž๋™์œผ๋กœ ๊ณ„์‚ฐํ•ด์ฃผ๋Š” ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. ์ด ๊ธ€์—์„œ๋Š” ๊ฐ„๋‹จํ•œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋‹จ๊ณ„๋ณ„๋กœ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ทผ๋กœ๊ธฐ์ค€๋ฒ• ์—ฐ์ฐจ์ผ์ˆ˜ ๊ณ„์‚ฐ๊ธฐํ•„์š”ํ•œ ์ค€๋น„๋ฌผ

์—ฐ์ฐจํœด๊ฐ€ ๊ณ„์‚ฐ๊ธฐ๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ค€๋น„๋ฌผ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค:

  1. HTML ํŒŒ์ผ: ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ HTML ์ฝ”๋“œ
  2. CSS ํŒŒ์ผ: ์Šคํƒ€์ผ๋ง์„ ์œ„ํ•œ CSS ์ฝ”๋“œ
  3. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ: ์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋กœ์ง์„ ํฌํ•จํ•œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ

HTML ์ฝ”๋“œ ์ž‘์„ฑ

๋จผ์ €, HTML ํŒŒ์ผ์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด ํŒŒ์ผ์—๋Š” ์‚ฌ์šฉ์ž ์ž…๋ ฅ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํผ๊ณผ ๊ณ„์‚ฐ ๊ฒฐ๊ณผ๋ฅผ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๋Š” ์˜์—ญ์ด ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜ ๊ณ„์‚ฐ๊ธฐ</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="container">
        <h2>์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜ ๊ณ„์‚ฐ๊ธฐ</h2>
        <form id="annualLeaveForm">
            <label for="startDate">์ž…์‚ฌ์ผ:</label>
            <input type="date" id="startDate" required>
            <label for="workMonths">๊ทผ๋ฌด ๊ฐœ์›” ์ˆ˜:</label>
            <input type="number" id="workMonths" required>
            <label for="attendanceRate">์ถœ๊ทผ์œจ (%):</label>
            <input type="number" id="attendanceRate" required>
            <button type="button" onclick="calculateAnnualLeave()">๊ณ„์‚ฐํ•˜๊ธฐ</button>
        </form>
        <div id="result"></div>
    </div>
    <script src="script.js"></script>
</body>
</html>

CSS ์ฝ”๋“œ ์ž‘์„ฑ

๋‹ค์Œ์œผ๋กœ, ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋ณด๊ธฐ ์ข‹๊ฒŒ ์Šคํƒ€์ผ๋งํ•˜๊ธฐ ์œ„ํ•ด CSS ํŒŒ์ผ์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

/* styles.css */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 0;
}

.container {
    max-width: 600px;
    margin: 50px auto;
    padding: 20px;
    background-color: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
    text-align: center;
}

form {
    display: flex;
    flex-direction: column;
}

label {
    margin-top: 10px;
}

input {
    padding: 10px;
    margin-top: 5px;
}

button {
    margin-top: 20px;
    padding: 10px;
    background-color: #007BFF;
    color: #fff;
    border: none;
    cursor: pointer;
}

button:hover {
    background-color: #0056b3;
}

#result {
    margin-top: 20px;
    font-size: 1.2em;
    text-align: center;
}

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ ์ž‘์„ฑ

๋งˆ์ง€๋ง‰์œผ๋กœ, ์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋กœ์ง์„ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

// script.js
function calculateAnnualLeave() {
    const startDate = new Date(document.getElementById('startDate').value);
    const workMonths = parseInt(document.getElementById('workMonths').value);
    const attendanceRate = parseInt(document.getElementById('attendanceRate').value);

    let annualLeaveDays = 0;

    // ๊ทผ๋ฌด๊ธฐ๊ฐ„ 1๋…„ ๋ฏธ๋งŒ
    if (workMonths < 12) {
        annualLeaveDays = workMonths;
        if (attendanceRate >= 80) {
            annualLeaveDays = Math.min(11, annualLeaveDays); // ์ตœ๋Œ€ 11์ผ
        } else {
            annualLeaveDays = 0; // ์ถœ๊ทผ์œจ์ด 80% ๋ฏธ๋งŒ์ผ ๊ฒฝ์šฐ
        }
    } 
    // ๊ทผ๋ฌด๊ธฐ๊ฐ„ 1๋…„ ์ด์ƒ
    else {
        const fullYears = Math.floor(workMonths / 12);
        annualLeaveDays = 15 + Math.floor((fullYears - 1) / 2);
        annualLeaveDays = Math.min(25, annualLeaveDays); // ์ตœ๋Œ€ 25์ผ

        // 1๋…„ ๋ฏธ๋งŒ์˜ ๊ทผ๋ฌด๊ธฐ๊ฐ„ ๋™์•ˆ ์‚ฌ์šฉํ•œ ์—ฐ์ฐจ ๊ณต์ œ
        const remainingMonths = workMonths % 12;
        if (remainingMonths > 0 && attendanceRate >= 80) {
            annualLeaveDays -= remainingMonths;
        }
    }

    document.getElementById('result').innerText = `์ด ์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜: ${annualLeaveDays}์ผ`;
}

์ด์ œ ๋ชจ๋“  ์ค€๋น„๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด ์ฝ”๋“œ๋Š” ๊ทผ๋กœ์ž์˜ ์ž…์‚ฌ์ผ, ๊ทผ๋ฌด ๊ฐœ์›” ์ˆ˜, ์ถœ๊ทผ์œจ์„ ์ž…๋ ฅ๋ฐ›์•„ ์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ด์ค๋‹ˆ๋‹ค.

๊ฒฐ๋ก 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜ ๊ณ„์‚ฐ๊ธฐ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ด ๊ณ„์‚ฐ๊ธฐ๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ํŽธ๋ฆฌํ•˜๊ฒŒ ์—ฐ์ฐจํœด๊ฐ€์ผ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค๋‹ˆ๋‹ค. ์•ž์œผ๋กœ ์ด ๊ณ„์‚ฐ๊ธฐ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๊ทผ๋กœ์ž๋“ค์ด ์—ฐ์ฐจํœด๊ฐ€๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€