441 lines
22 KiB
HTML
441 lines
22 KiB
HTML
<!DOCTYPE html>
|
|
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
|
layout:decorate="~{layout/layout}">
|
|
|
|
<div class="layer-wrap" th:fragment="modalFragment">
|
|
<form autocomplete="off" method="get" name="reqIncomeForm" data-modal-id=".modal-daily-income">
|
|
<input type="hidden" name="householdSeq" th:value="${seq}">
|
|
<input type="hidden" name="searchMonth">
|
|
<input type="hidden" name="groupNo">
|
|
<input type="hidden" name="id">
|
|
<input type="hidden" name="dailyId">
|
|
|
|
<input type="hidden" name="startYear" th:value="${startYear}"/>
|
|
<input type="hidden" name="startMonth" th:value="${startMonth}"/>
|
|
<input type="hidden" name="currentDate" th:value="${currentDate}"/>
|
|
<input type="hidden" name="selectedGroupNo" value=""/>
|
|
<div class="component-modal mypage-wrap modal01 modal-daily-income" data-props-dimm-click="true" data-state="close">
|
|
<div class="modal-dimm"></div>
|
|
<div class="modal-frame">
|
|
<div class="modal-container">
|
|
<div class="modal-header">
|
|
<h3 class="modal-tit">
|
|
일계부 수입
|
|
</h3>
|
|
</div>
|
|
<div class="modal-content">
|
|
<div class="modal-content-inner">
|
|
<table class="type-form confirm">
|
|
<colgroup>
|
|
<col width="8%" />
|
|
<col width="25.3%" />
|
|
<col width="8%" />
|
|
<col width="25.3%" />
|
|
<col width="8%" />
|
|
<col width="25.3%" />
|
|
</colgroup>
|
|
<tbody>
|
|
<tr>
|
|
<th>등록일</th>
|
|
<td colspan="2">
|
|
<div class="d-flex">
|
|
<div class="component-select">
|
|
<select class="select-list" name="targetYear" required>
|
|
|
|
</select>
|
|
</div>
|
|
<div class="component-select">
|
|
<select class="select-list" name="targetMonth" required>
|
|
|
|
</select>
|
|
</div>
|
|
<div class="component-select">
|
|
<select class="select-list" name="targetDayGroup" required>
|
|
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th>외상판매 여부</th>
|
|
<td class="radio-group">
|
|
<div class="component-input">
|
|
<label class="radio-inner">
|
|
<input type="radio" id="isCredit_N" name="credit" value="false" checked>
|
|
<span class="radio-item">
|
|
<span class="radio-txt">N</span>
|
|
</span>
|
|
</label>
|
|
</div>
|
|
<div class="component-input">
|
|
<label class="radio-inner">
|
|
<input type="radio" id="isCredit_Y" name="credit" value="true">
|
|
<span class="radio-item">
|
|
<span class="radio-txt">Y</span>
|
|
</span>
|
|
</label>
|
|
</div>
|
|
</td>
|
|
|
|
<th>재배형태</th>
|
|
<td>
|
|
<div class="component-select">
|
|
<select class="select-list" name="cropCode" required>
|
|
<option value="">선택</option>
|
|
<option th:each="item : ${recordCrop}"
|
|
th:value="${item.id}"
|
|
th:text="${item.codeText}">
|
|
</select>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th>수입의 종류<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
|
|
<td>
|
|
<div class="component-input">
|
|
<div class="input-field">
|
|
<input type="text" id="incomeKind" name="incomeKind" maxlength="30">
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<th>수입원<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
|
|
<td>
|
|
<div class="component-input">
|
|
<div class="input-field">
|
|
<input type="text" id="sourcePurpose" name="sourcePurpose" maxlength="30">
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th>수량</th>
|
|
<td>
|
|
<div class="component-input">
|
|
<div class="input-field">
|
|
<input type="number" inputmode="decimal" pattern="[0-9]*" id="quantity" name="quantity" min="1" max="9999999999"
|
|
maxlength="10" oninput="limitMaxLength(this);">
|
|
</div>
|
|
</div>
|
|
</td>
|
|
|
|
<th>단위</th>
|
|
<td colspan="2">
|
|
<div class="d-flex">
|
|
<div class="component-select">
|
|
<select class="select-list" name="unitCode" onchange="selectedUnit(this);" required>
|
|
<option value="">선택</option>
|
|
<option th:each="item : ${recordUnit}"
|
|
th:value="${item.id}"
|
|
th:text="${item.codeText}">
|
|
</select>
|
|
</div>
|
|
<div class="component-input unit-self-input">
|
|
<div class="input-field">
|
|
<input type="text" id="unitSelf" name="unitSelf" maxlength="30" disabled>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th>현금(원)<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
|
|
<td>
|
|
<div class="component-input">
|
|
<div class="input-field">
|
|
<input type="number" inputmode="numeric" pattern="[0-9]*" id="price" name="price" step="0" min="1" max="9999999999"
|
|
maxlength="10" oninput="limitMaxLength(this); priceDisabled(this, this.form.estimatedValue)">
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<th>현물(평가액)<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
|
|
<td>
|
|
<div class="component-input">
|
|
<div class="input-field">
|
|
<input type="number" inputmode="numeric" pattern="[0-9]*" id="estimatedValue" name="estimatedValue" step="0" min="1" max="9999999999"
|
|
maxlength="10" oninput="limitMaxLength(this); priceDisabled(this, this.form.price)">
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
<div class="component-btns bottom-btn-group">
|
|
<div class="btns-row align-right">
|
|
<button type="button" class="btn btn-primary" onclick="saveDailyIncome();">
|
|
<span class="btn-txt">등록</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<button type="button" class="modal-close"></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
<script th:inline="javascript">
|
|
// form 초기화
|
|
const resetDailyIncomeForm = () => {
|
|
const form = document.reqIncomeForm;
|
|
if (!form) return;
|
|
|
|
form.cropCode.value = '';
|
|
form.incomeKind.value = '';
|
|
form.sourcePurpose.value = '';
|
|
form.quantity.value = '';
|
|
form.unitCode.value = '';
|
|
form.unitSelf.value = '';
|
|
form.price.value = '';
|
|
form.estimatedValue.value = '';
|
|
|
|
const currentDateStr = form.currentDate ? form.currentDate.value : ''; // "2025-08-09"
|
|
const selectedGroupNo = form.selectedGroupNo ? form.selectedGroupNo.value : ''; // "2025-08-09"
|
|
const startYear = form.startYear ? parseInt(form.startYear.value, 10) : 2024;
|
|
const startMonth = form.startMonth ? parseInt(form.startMonth.value, 10) : 8;
|
|
|
|
// 오늘 Y/M/D 파싱
|
|
const ymd = /^(\d{4})-(\d{2})-(\d{2})$/.exec(currentDateStr);
|
|
const cur = ymd ? { y: +ymd[1], m: +ymd[2], d: +ymd[3] } : { y: null, m: null, d: null };
|
|
if (!cur.y || !cur.m || !cur.d) return;
|
|
|
|
// selectedGroupNo가 있으면 초기 연/월은 #recordMonthStr(value: "yyyyMM")에서 취득
|
|
let baseY = cur.y, baseM = cur.m;
|
|
if (selectedGroupNo) {
|
|
const rmSel = document.getElementById('recordMonthStr');
|
|
const rmVal = rmSel?.value || '';
|
|
const rm = /^(\d{4})(\d{2})$/.exec(rmVal);
|
|
if (rm) { baseY = +rm[1]; baseM = +rm[2]; }
|
|
}
|
|
|
|
// 연/월 셀렉트 요소
|
|
const yearSel = form.targetYear;
|
|
const monthSel = form.targetMonth;
|
|
const daySel = form.targetDayGroup;
|
|
|
|
// 일자 그룹 정의(1~17)
|
|
const DAY_GROUPS = [
|
|
{ groupNo: 1, startDay: 1, endDay: 2 },
|
|
{ groupNo: 2, startDay: 3, endDay: 4 },
|
|
{ groupNo: 3, startDay: 5, endDay: 6 },
|
|
{ groupNo: 4, startDay: 7, endDay: 7 },
|
|
{ groupNo: 5, startDay: 8, endDay: 9 },
|
|
{ groupNo: 6, startDay: 10, endDay: 11 },
|
|
{ groupNo: 7, startDay: 12, endDay: 13 },
|
|
{ groupNo: 8, startDay: 14, endDay: 14 },
|
|
{ groupNo: 9, startDay: 15, endDay: 16 },
|
|
{ groupNo: 10, startDay: 17, endDay: 18 },
|
|
{ groupNo: 11, startDay: 19, endDay: 20 },
|
|
{ groupNo: 12, startDay: 21, endDay: 21 },
|
|
{ groupNo: 13, startDay: 22, endDay: 23 },
|
|
{ groupNo: 14, startDay: 24, endDay: 25 },
|
|
{ groupNo: 15, startDay: 26, endDay: 27 },
|
|
{ groupNo: 16, startDay: 28, endDay: 29 },
|
|
{ groupNo: 17, startDay: 30, endDay: 31 },
|
|
];
|
|
const daysInMonth = (y, m) => new Date(y, m, 0).getDate();
|
|
const findGroupNoByDay = (day) => {
|
|
const g = DAY_GROUPS.find(g => day >= g.startDay && day <= g.endDay);
|
|
return g ? g.groupNo : null;
|
|
};
|
|
|
|
// 연도 옵션: startYear ~ currentDate.year
|
|
function fillYears(preselectYear) {
|
|
if (!yearSel) return;
|
|
yearSel.innerHTML = '';
|
|
for (let y = startYear; y <= cur.y; y++) {
|
|
const opt = document.createElement('option');
|
|
opt.value = String(y);
|
|
opt.textContent = `${y}년`;
|
|
yearSel.appendChild(opt);
|
|
}
|
|
// 선택: selectedGroupNo 있으면 baseY, 없으면 cur.y
|
|
const pickY = (typeof preselectYear === 'number') ? preselectYear : cur.y;
|
|
yearSel.value = String(pickY);
|
|
}
|
|
|
|
// 월 옵션: (startYear → startMonth~12), (cur.y → 1~cur.m), (그 외 과거연도 → 1~12)
|
|
function fillMonths(year, preselectMonth) {
|
|
if (!monthSel) return;
|
|
monthSel.innerHTML = '';
|
|
let from = 1, to = 12;
|
|
if (year === startYear) from = startMonth;
|
|
if (year === cur.y) to = cur.m;
|
|
|
|
for (let m = from; m <= to; m++) {
|
|
const opt = document.createElement('option');
|
|
opt.value = String(m);
|
|
opt.textContent = `${m}월`;
|
|
monthSel.appendChild(opt);
|
|
}
|
|
// 선택: selectedGroupNo 있으면 baseM, 없으면 cur.m (범위 밖이면 첫 항목)
|
|
const candidate = (typeof preselectMonth === 'number') ? preselectMonth : cur.m;
|
|
monthSel.value = (candidate >= from && candidate <= to)
|
|
? String(candidate)
|
|
: (monthSel.options[0]?.value || '');
|
|
}
|
|
|
|
// 일자그룹 옵션: 존재 & 미래 제외
|
|
function fillDayGroups(year, month, preselectGroupNo) {
|
|
if (!daySel) return;
|
|
daySel.innerHTML = '';
|
|
|
|
// "선택하세요" 옵션 추가
|
|
const placeholder = document.createElement('option');
|
|
placeholder.value = '';
|
|
placeholder.textContent = '선택하세요';
|
|
daySel.appendChild(placeholder);
|
|
|
|
const dim = daysInMonth(year, month);
|
|
const isCurYM = (year === cur.y && month === cur.m);
|
|
const maxDay = isCurYM ? cur.d : dim;
|
|
|
|
const candidates = DAY_GROUPS
|
|
.filter(g => g.endDay <= dim)
|
|
.filter(g => g.startDay <= maxDay);
|
|
|
|
candidates.forEach(g => {
|
|
const opt = document.createElement('option');
|
|
opt.value = String(g.groupNo);
|
|
opt.textContent = (g.startDay === g.endDay) ? `${g.startDay}일` : `${g.startDay}~${g.endDay}일`;
|
|
daySel.appendChild(opt);
|
|
});
|
|
|
|
// 선택 우선순위: 전달된 groupNo가 리스트에 있으면 → 그것, 아니면 첫 항목
|
|
let pick = preselectGroupNo ? String(preselectGroupNo) : '';
|
|
if (pick && ![...daySel.options].some(o => o.value === pick)) pick = '';
|
|
if (!pick) pick = daySel.options[0]?.value || '';
|
|
if (pick) daySel.value = pick;
|
|
}
|
|
|
|
// ----- 초기 세팅 -----
|
|
// 1) 연도/월 옵션은 currentDate 기준으로 생성
|
|
fillYears(selectedGroupNo ? baseY : undefined);
|
|
fillMonths(parseInt(yearSel.value, 10), selectedGroupNo ? baseM : undefined);
|
|
|
|
// 2) 일자그룹 선택값 계산
|
|
const initGroupNo = selectedGroupNo
|
|
? parseInt(selectedGroupNo, 10)
|
|
: findGroupNoByDay(cur.d);
|
|
|
|
fillDayGroups(parseInt(yearSel.value, 10), parseInt(monthSel.value, 10), initGroupNo);
|
|
|
|
// ----- 이벤트 -----
|
|
yearSel?.addEventListener('change', function () {
|
|
const y = parseInt(this.value, 10);
|
|
// selectedGroupNo가 있으면 월 선택은 baseM 유지 시도(범위 밖이면 첫 항목)
|
|
fillMonths(y, selectedGroupNo ? baseM : undefined);
|
|
// 일그룹: selectedGroupNo 우선(존재하지 않으면 폴백)
|
|
fillDayGroups(y, parseInt(monthSel.value, 10), selectedGroupNo ? parseInt(selectedGroupNo, 10) : undefined);
|
|
});
|
|
|
|
monthSel?.addEventListener('change', function () {
|
|
const y = parseInt(yearSel.value, 10);
|
|
fillDayGroups(y, parseInt(this.value, 10), selectedGroupNo ? parseInt(selectedGroupNo, 10) : undefined);
|
|
});
|
|
|
|
document.getElementById('isCredit_N').checked = true;
|
|
priceDisabledReset(form.price, form.estimatedValue);
|
|
}
|
|
|
|
// 일계부 상세 값 set
|
|
const setDailyIncomeFormData = (data) => {
|
|
const form = document.reqIncomeForm;
|
|
if (!form) return;
|
|
|
|
// 폼에 값 세팅
|
|
form.cropCode.value = data.cropCode || '';
|
|
form.incomeKind.value = data.incomeKind || '';
|
|
form.sourcePurpose.value = data.sourcePurpose || '';
|
|
form.quantity.value = data.quantity || '';
|
|
form.unitCode.value = data.unitCode || '';
|
|
form.unitSelf.value = data.unitSelf || '';
|
|
form.price.value = data.price || '';
|
|
form.estimatedValue.value = data.estimatedValue || '';
|
|
|
|
// 기타 UI 처리
|
|
selectedUnit(form.unitCode);
|
|
if (form.price.value !== '') {
|
|
priceDisabled(form.price, form.estimatedValue)
|
|
} else {
|
|
priceDisabled(form.estimatedValue, form.price)
|
|
}
|
|
|
|
// 라디오 버튼 처리
|
|
document.getElementById('isCredit_Y').checked = data.credit === true;
|
|
document.getElementById('isCredit_N').checked = data.credit === false;
|
|
}
|
|
</script>
|
|
|
|
<script th:inline="javascript">
|
|
// 일계부 등록 모달창 띄우기
|
|
const showDailyIncomeModal = (id) => {
|
|
const mf = document.reqIncomeForm;
|
|
mf.searchMonth.value = document.reqForm.recordMonth.value;
|
|
mf.groupNo.value = document.reqForm.groupNo.value;
|
|
mf.dailyId.value = document.reqForm.dailyId.value;
|
|
mf.id.value = (id === undefined) ? '' : id;
|
|
// if(id === undefined){
|
|
// mf.selectedGroupNo.value = null;
|
|
// } else {
|
|
mf.selectedGroupNo.value = document.reqForm.groupNo.value;
|
|
// }
|
|
|
|
resetDailyIncomeForm();
|
|
|
|
if (id !== null && id !== undefined) {
|
|
const obj = $(f).serializeObject();
|
|
obj.id = mf.id.value;
|
|
obj.searchMonth = obj.recordMonth;
|
|
|
|
ajaxUtil._ajaxAsyncMethod(
|
|
`/api/household/daily/income/${id}`,
|
|
obj,
|
|
function (rstData, status) {
|
|
setDailyIncomeFormData(rstData);
|
|
|
|
document.querySelector($(mf).data('modalId')).ui.open();
|
|
},
|
|
function () {
|
|
console.error('Do nothing error.')
|
|
},
|
|
'get'
|
|
);
|
|
|
|
} else {
|
|
document.querySelector($(mf).data('modalId')).ui.open();
|
|
}
|
|
}
|
|
|
|
const saveDailyIncome = () => {
|
|
const mf = document.reqIncomeForm;
|
|
let obj = $(mf).serializeObject();
|
|
obj.inputType = 'SELF';
|
|
obj.id = (obj.id === '' ? '0' : obj.id);
|
|
|
|
ajaxUtil._ajaxAsyncNoWaiting(
|
|
'/api/household/daily/income/save',
|
|
obj,
|
|
function () {
|
|
alert('등록이 완료되었습니다.');
|
|
|
|
document.querySelector($(mf).data('modalId')).ui.close();
|
|
|
|
getDailyRecordsView(f.dailyId.value, f.groupNo.value, f.dayGroupText.value);
|
|
},
|
|
function (code, rstData) {
|
|
console.error('Do nothing. code: '+ code, rstData);
|
|
},
|
|
);
|
|
}
|
|
</script>
|
|
</div>
|
|
</html> |