[FO] 지출 CRUD, 수지출의 부호 추가 및 유효성체크

This commit is contained in:
김현주
2025-06-12 18:26:36 +09:00
parent 595c8a5e72
commit 31684352e1
24 changed files with 1388 additions and 28 deletions

View File

@@ -32,6 +32,7 @@
<div class="component-input">
<label class="switch-inner type-txt">
<span class="switch-label">수입</span>
<!-- TODO : DONE 유지여부 판단하기 -->
<input type="checkbox" name="incomeStatus" value="TARGET" data-target="income"
th:checked="${#strings.equals(dailyRecord.incomeStatus, 'TARGET') or #strings.equals(dailyRecord.incomeStatus, 'DONE')}">
<span class="switch-item">

View File

@@ -0,0 +1,205 @@
<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org" lang="ko">
<th:block>
<th:block th:if="${@systemProperties['spring.profiles.active'] eq 'local'}">
<div>
reqVO: [[${reqVO}]]
</div>
<div>
detail: [[${dailyRecord}]]
</div>
</th:block>
<div class="modal-content-inner">
<div class="component-btns type-tab"
th:if="${not detail.updated}">
<div class="btns-row">
<button type="button" class="btn active">수기 등록</button>
<!--/* TODO : 2차 오픈 */-->
<!--<button type="button" class="btn">영수증 등록</button>-->
</div>
</div>
<p class="form-desc">필지출력</p>
<form name="reqModalForm">
<input type="hidden" name="inputType" th:value="${#strings.defaultString(detail.inputType, 'SELF')}">
<input type="hidden" name="id" th:value="${detail.id}">
<section class="form-group">
<div class="segment-label">
<p class="label-txt">
외상 또는 카드 구입 여부
</p>
</div>
<div class="component-segment">
<div class="component-radio">
<label class="radio-inner">
<input type="radio" name="credit" value="true" th:checked="${detail.credit}">
<span class="radio-item">
<span class="radio-txt">예</span>
</span>
</label>
</div>
<div class="component-radio">
<label class="radio-inner">
<input type="radio" name="credit" value="false" th:checked="not ${detail.credit}">
<span class="radio-item">
<span class="radio-txt">아니오</span>
</span>
</label>
</div>
</div>
</section>
<hr>
<section class="form-group">
<div class="select-group">
<div class="select-label">
<p class="label-txt">
지출의 종류
<i class="ico-required-mark" role="img" aria-label="필수">*</i>
</p>
</div>
<div id="categoryCode" class="component-select bottom-sheet" data-props-default="지출 종류를 선택해 주세요" data-props-type="bottomSheet">
<input type="hidden1" name="categoryCode" th:value="${detail.categoryCode}" data-type="select">
<button type="button" class="select-box">
<span class="select-txt"></span>
</button>
<div class="select-options">
<div class="select-header">
<p>지출의 종류</p>
<button type="button" class="select-close">
<span class="hide-txt">닫기</span>
</button>
</div>
<div class="select-scroll">
<ul class="">
<li class="option"
th:each="uiCode : ${recordExpense}"
th:data-value="${uiCode.codeValue}"
th:text="${uiCode.codeText}"></li>
<li class="option" data-value="SELF">직접 입력</li>
</ul>
</div>
</div>
</div>
<div class="component-input input-invalid" data-option="직접 입력">
<div class="input-field">
<input type="text" id="categorySelf" name="categorySelf" th:value="${detail.categorySelf}" maxlength="30" placeholder="지출의 종류를 입력해 주세요">
</div>
<ul class="input-info">
<li>지출 종류를 입력해 주세요.</li>
</ul>
</div>
</div>
<div class="component-input">
<div class="input-label">
<label for="sourcePurpose" class="label-txt">
용도
<i class="ico-required-mark" role="img" aria-label="필수">*</i>
</label>
</div>
<div class="input-field">
<input type="text" id="sourcePurpose" name="sourcePurpose" th:value="${detail.sourcePurpose}" maxlength="30" placeholder="용도를 입력해 주세요">
</div>
</div>
</section>
<hr>
<section class="form-group">
<div class="component-input">
<div class="input-label">
<label for="quantity" class="label-txt">
수량
</label>
</div>
<div class="input-field">
<input type="number" inputmode="numeric" pattern="[0-9]*" id="quantity" name="quantity" th:value="${detail.quantity}" maxlength="10" placeholder="수량을 입력해 주세요">
</div>
<ul class="guide-info">
<li>예 : 2, 2.5</li>
</ul>
</div>
<div class="select-group">
<div class="select-label">
<p class="label-txt">
단위
</p>
</div>
<div id="unitCode" class="component-select bottom-sheet" data-props-default="단위를 선택해 주세요" data-props-type="bottomSheet">
<input type="hidden1" name="unitCode" th:value="${detail.unitCode}">
<button type="button" class="select-box">
<span class="select-txt"></span>
</button>
<div class="select-options">
<div class="select-header">
<p>단위</p>
<button type="button" class="select-close">
<span class="hide-txt">닫기</span>
</button>
</div>
<div class="select-scroll">
<ul class="">
<li class="option" th:each="uiCode : ${recordUnit}"
th:data-value="${uiCode.codeValue}"
th:text="${uiCode.codeText}"
th:selected="${uiCode.codeValue eq detail.unitCode ? 'current' : ''}"
></li>
</ul>
</div>
</div>
</div>
</div>
</section>
<hr>
<section class="form-group">
<div class="component-input">
<div class="input-label">
<label for="price" class="label-txt">
현금
<i class="ico-required-mark" role="img" aria-label="필수">*</i>
</label>
</div>
<div class="input-field type-price">
<input type="number" inputmode="numeric" pattern="[0-9]*" id="price" name="price" th:value="${detail.price}" maxlength="10" placeholder="금액을 입력해 주세요">
<span class="input-field-txt">원</span>
</div>
<ul class="guide-info">
<li>예 : 30000</li>
</ul>
</div>
<div class="component-input">
<div class="input-label">
<label for="estimatedValue" class="label-txt">
현물평가액
<i class="ico-required-mark" role="img" aria-label="필수">*</i>
</label>
</div>
<div class="input-field type-price">
<input type="number" inputmode="numeric" pattern="[0-9]*" id="estimatedValue" name="estimatedValue" th:value="${detail.estimatedValue}" maxlength="10" placeholder="금액을 입력해 주세요">
<span class="input-field-txt">원</span>
</div>
<ul class="guide-info">
<li>예 : 30000</li>
</ul>
</div>
</section>
</form>
<div class="component-btns">
<div class="btns-row">
<button type="button" class="btn btn-full btn-l btn-primary" onclick="formControl.createVaild();">
<span class="btn-txt">등록</span>
</button>
</div>
</div>
</div>
</th:block>
</html>

View File

@@ -0,0 +1,368 @@
<!DOCTYPE html>
<html layout:decorate="~{layout/layout-none}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org" lang="ko">
<div layout:fragment="content" th:classappend="acco-wrap">
<th:block th:if="${@systemProperties['spring.profiles.active'] eq 'local'}">
<div>
reqVO: [[${reqVO}]]
</div>
<div>
dailyRecord: [[${dailyRecord}]]
</div>
</th:block>
<main id="content" role="main">
<div class="inner">
<hgroup class="tit-group">
<h3>
<th:block th:if="${dailyRecord.startDay eq dailyRecord.endDay}">
[[${#temporals.format(dailyRecord.startDate, 'M월 d일')}]], <br>
</th:block>
<th:block th:if="not ${dailyRecord.startDay eq dailyRecord.endDay}">
[[${#temporals.format(dailyRecord.startDate, 'M월 d')}]]~[[${#temporals.format(dailyRecord.endDate, 'd일')}]], <br>
</th:block>
<strong>지출 내역 [[${#lists.isEmpty(expenseList) ? 0 : #lists.size(expenseList)}]]건 등록</strong> <br>
되었습니다.
</h3>
<p>지출 내역을 등록해 주세요.</p>
</hgroup>
<form name="reqForm">
<input type="hidden" name="todayNone" value="N">
</form>
<!--/* 신규 등록 */-->
<th:block th:if="${#lists.isEmpty(expenseList)}">
<button type="button" class="btn btn-m btn-secondary btn-full button-modal01" data-testid="button-modal01"
th:disabled="${#strings.equals(dailyRecord.expenseStatus, 'TODAY_NONE')}">
<i class=" ico-small" aria-hidden="true"
th:classappend="${#strings.equals(dailyRecord.expenseStatus, 'TODAY_NONE') ? 'ico-add-disabled' : 'ico-add'}"></i>
<span class="btn-txt">추가 등록</span>
</button>
<div class="component-input align-center">
<label class="checkbox-inner" id="todayNone">
<input type="checkbox" name="todayNone"
th:checked="${#strings.equals(dailyRecord.expenseStatus, 'TODAY_NONE')}">
<span class="checkbox-item">
<span class="checkbox-txt">금일 등록내용 없음</span>
</span>
</label>
</div>
</th:block>
<!--/* 목록 */-->
<th:block th:unless="${#lists.isEmpty(expenseList)}">
<section class="regist-item-area">
<p class="total">
<span>총 <strong>[[${#lists.size(expenseList)}]]</strong>건</span>
<button type="button" class="btn-reset" onclick="formControl.resetConfirm()">
<i class="ico-reset ico-small" aria-hidden="true"></i>
<span>초기화</span>
</button>
</p>
<div class="item-list">
<div class="list-item"
th:each="item, itemStatus : ${expenseList}">
<div class="item-tit-group">
<p class="item-name">[[${item.categoryLabel}]] [[${item.categorySelf}]]</p>
<div class="btn-group">
<button type="button" class="delete" th:onclick="formControl.removeConfirm([[${item.id}]])"><span class="hide-txt">삭제</span></button>
<button type="button" class="edit" th:onclick="formControl.createModal([[${item.id}]])"><span class="hide-txt">수정</span></button>
</div>
</div>
<ul class="detail-list">
<li th:if="${item.credit != null}">
<p>외상 또는 카드 구입 여부</p>
<span th:text="${item.credit ? '예' : '아니오'}">아니오</span>
</li>
<li th:if="${not #strings.isEmpty(item.sourcePurpose)}">
<p>용도</p>
<span th:text="${item.sourcePurpose}">소비자</span>
</li>
<li th:if="${not #strings.isEmpty(item.quantity)}">
<p>수량</p>
<span th:text="|${item.quantity}${#strings.defaultString(item.unitLabel,'')}|">500g</span>
</li>
<li th:if="${not #strings.isEmpty(item.price)}">
<p>현금 </p>
<span th:text="|${#numbers.formatInteger(item.price, 1, 'COMMA')}원|">302,000원</span>
</li>
<li th:if="${not #strings.isEmpty(item.estimatedValue)}">
<p>현물평가액</p>
<span th:text="|${#numbers.formatInteger(item.estimatedValue, 1, 'COMMA')}원|">302,000원</span>
</li>
</ul>
</div>
</div>
<button type="button" class="btn btn-m btn-secondary btn-full button-modal01" data-testid="button-modal01">
<i class="ico-add ico-small" aria-hidden="true"></i>
<span class="btn-txt">추가 등록</span>
</button>
</section>
</th:block>
</div>
</main>
<!-- 하단 고정 버튼 -->
<div class="component-btns fixed">
<div class="btns-row">
<button type="button" class="btn btn-l btn-secondary" onclick="krip.daily.goToPrev();">
<span class="btn-txt">이전 단계로 이동</span>
</button>
<button type="button" class="btn btn-l btn-primary"
th:disabled="${not #strings.equals(dailyRecord.expenseStatus, 'TODAY_NONE') and #lists.isEmpty(expenseList)}">
<span class="btn-txt">다음 단계로 이동</span>
</button>
</div>
</div>
<!-- 모달 팝업 -->
<div class="layer-wrap">
<div class="component-modal acco-wrap modal01" data-props-dimm-click="true">
<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">
<!--/* form */-->
</div>
<button type="button" class="modal-close"></button>
</div>
</div>
</div>
</div>
<!-- //모달 팝업 -->
</div>
<section layout:fragment="script">
<script th:src="@{/static/ui/page/daily-record.js}"></script>
<script th:inline="javascript">
$(function() {
formControl.init();
});
let ENV = {
httpUrl: {
root: /*[[|/record/daily/${reqVO.searchMonth}/${reqVO.groupNo}|]]*/'rootUrl',
form: /*[[|/record/expense/${reqVO.searchMonth}/${reqVO.groupNo}/form/{id}|]]*/'formUrl',
create: /*[[|/api/record/expense/${reqVO.searchMonth}/${reqVO.groupNo}/form/{id}|]]*/'createUrl',
remove: /*[[|/api/record/expense/${reqVO.searchMonth}/${reqVO.groupNo}/remove|]]*/'removeUrl',
reset: /*[[|/api/record/expense/${reqVO.searchMonth}/${reqVO.groupNo}/reset|]]*/'resetUrl',
},
month: [[${reqVO.searchMonth}]],
groupNo: [[${reqVO.groupNo}]],
submitted: false,
};
let bind = {
form: {
selectorId: '.button-modal01',
selector: '.modal01',
},
selectbox: null,
}
let formControl = {
init() {
formControl._bindUI();
//formControl.createModal();
// TODO 등록된 건수가 0일 경우 버튼 비활성화
},
_bindUI() {
etUI.locales.ko = {
dialog: {
positive: '예',
negative: '아니오',
},
};
let $noneWrap = $('#todayNone');
$noneWrap.on('click', 'input[name="todayNone"]', function() {
let checked = $(this).is(':checked');
let $btn = $('.button-modal01');
$btn.attr('disabled', checked);
if (checked) {
$btn.find('i').addClass('ico-add-disabled');
$btn.find('i').removeClass('ico-add');
document.reqForm.todayNone.value = 'Y';
} else {
$btn.find('i').addClass('ico-add');
$btn.find('i').removeClass('ico-add-disabled');
document.reqForm.todayNone.value = 'N';
}
krip.daily.todayNone(ENV.month, ENV.groupNo, 'EXPENSE', checked);
});
let $formWrap = $(bind.form.selectorId);
$formWrap.on('click', function() {
formControl.createModal();
});
// const $btnModal01 = document.querySelector(".button-modal01");
// $btnModal01.addEventListener("click", function() {
// const modal01 = document.querySelector(".modal01").ui;
// modal01.open();
// });
},
_bindModelUI() {
let $formWrap = $(bind.form.selector).find('form');
$formWrap.on('keyup', 'input[name="price"]', function() {
// TODO : UI disabled
if ($(this).val() === '') {
$formWrap.find('input[name="estimatedValue"]').attr('disabled', false);
} else {
$formWrap.find('input[name="estimatedValue"]').val('').attr('disabled', true);
}
});
$formWrap.on('keyup', 'input[name="estimatedValue"]', function() {
// TODO : UI disabled
if ($(this).val() === '') {
$formWrap.find('input[name="price"]').attr('disabled', false);
} else {
$formWrap.find('input[name="price"]').val('').attr('disabled', true);
}
});
},
createModal(id) {
if (id === undefined) {
id = 0;
}
ajaxUtil._ajaxAsyncMethod(
ENV.httpUrl.form.replace('{id}', id),
{},
function(rstHtml, status) {
$('.modal01').find('.modal-content').html(rstHtml);
// TODO
etUI.components.SelectBox().core.init(document.querySelector('#categoryCode'));
etUI.components.SelectBox().core.init(document.querySelector('#unitCode'));
/*
etUI.components.SelectBox().core.init(document.querySelector('#categoryCode'), {
onChange: function() {
console.log('sssssssssss')
},
selectItemCallback: function() {
// TODO : console.log ?
console.log(1111)
}
});
etUI.components.SelectBox().core.init(document.querySelector('#unitCode'), {
onChange: function() {
console.log('sssssssssss')
},
selectItemCallback: function() {
console.log(3333)
}
});
*/
/*document.querySelector('#selectUnit').addEventListener('select:onChange', (e) => {
console.log(e.detail);
console.log(e.detail.value);
});
const selectbox2 = document.querySelector('.component-select');
selectbox2.addEventListener('select:onChange', (e) => {
console.log(e.detail);
console.log(e.detail.value);
});
*/
//document.queerySelector('#unitSelect')
const modal01 = document.querySelector(".modal01").ui;
modal01.open();
formControl._bindModelUI();
},
function(code, rstData) {
kri.logger.error('Do nothing. code: '+ code, rstData);
},
'get',
'html'
);
},
createVaild() {
const f = document.reqModalForm;
// TODO : setter
f.categoryCode.value = document.querySelector('#categoryCode').value !== undefined ? document.querySelector('#categoryCode').value : '';
f.unitCode.value = document.querySelector('#unitCode').value !== undefined ? document.querySelector('#unitCode').value : '';
formControl.create();
},
create() {
const f = document.reqModalForm;
const obj = $(f).serializeObject();
console.log(obj)
ajaxUtil._ajaxAsync(
ENV.httpUrl.create.replace('{id}', f.id.value ? f.id.value : '0'),
obj,
function (rstData, status) {
console.log('rstData', rstData)
location.reload();
/*
if (f.todayNone.value === 'Y') {
krip.daily.goToMain();
} else {
krip.daily.goToNext($('input:checked').eq(0).data('target'), ENV.month, ENV.groupNo);
}
*/
},
);
},
removeConfirm(id) {
etUI.dialog.alert({
title: "삭제 안내",
message: "등록하신 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.",
type: "confirm",
dialogType: "confirm",
callback: function () {
formControl.remove(id);
},
});
},
remove(id) {
console.log('remove', id)
ajaxUtil._ajaxAsync(
ENV.httpUrl.remove,
{ 'id': id },
function (rstData, status) {
location.reload();
},
);
},
resetConfirm() {
etUI.dialog.alert({
title: "초기화 안내",
message: "등록하신 모든 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.",
type: "confirm",
dialogType: "confirm",
callback: function () {
formControl.reset();
},
});
},
reset() {
ajaxUtil._ajaxAsync(
ENV.httpUrl.reset,
{},
function (rstData, status) {
location.reload();
},
);
},
};
</script>
</section>
</html>

View File

@@ -116,7 +116,7 @@
</div>
<div class="component-input input-invalid" data-option="직접 입력">
<div class="input-field">
<input type="text" id="categorySelf" name="categorySelf" th:value="${detail.categorySelf}" placeholder="수입의 종류를 입력해 주세요">
<input type="text" id="categorySelf" name="categorySelf" th:value="${detail.categorySelf}" maxlength="30" placeholder="수입의 종류를 입력해 주세요">
</div>
<ul class="input-info">
<li>수입 종류를 입력해 주세요.</li>
@@ -131,7 +131,7 @@
</label>
</div>
<div class="input-field">
<input type="text" id="sourcePurpose" name="sourcePurpose" th:value="${detail.sourcePurpose}" maxlength="50" placeholder="수입원을 입력해 주세요">
<input type="text" id="sourcePurpose" name="sourcePurpose" th:value="${detail.sourcePurpose}" maxlength="30" placeholder="수입원을 입력해 주세요">
</div>
</div>
</section>

View File

@@ -32,14 +32,16 @@
</form>
<!--/* 신규 등록 */-->
<th:block th:if="${#lists.isEmpty(incomeList)}">
<button type="button" class="btn btn-m btn-secondary btn-full button-modal01" data-testid="button-modal01">
<i class="ico-add ico-small" aria-hidden="true"></i>
<button type="button" class="btn btn-m btn-secondary btn-full button-modal01" data-testid="button-modal01"
th:disabled="${#strings.equals(dailyRecord.incomeStatus, 'TODAY_NONE')}">
<i class=" ico-small" aria-hidden="true"
th:classappend="${#strings.equals(dailyRecord.incomeStatus, 'TODAY_NONE') ? 'ico-add-disabled' : 'ico-add'}"></i>
<span class="btn-txt">추가 등록</span>
</button>
<div class="component-input align-center">
<label class="checkbox-inner" id="todayNone">
<input type="checkbox" name="todayNone">
<input type="checkbox" name="todayNone"
th:checked="${#strings.equals(dailyRecord.incomeStatus, 'TODAY_NONE')}">
<span class="checkbox-item">
<span class="checkbox-txt">금일 등록내용 없음</span>
</span>
@@ -81,7 +83,7 @@
</li>
<li th:if="${not #strings.isEmpty(item.quantity)}">
<p>수량</p>
<span th:text="|${item.quantity}${item.unitLabel}|">500g</span>
<span th:text="|${item.quantity}${#strings.defaultString(item.unitLabel,'')}|">500g</span>
</li>
<li th:if="${not #strings.isEmpty(item.price)}">
<p>현금 </p>
@@ -109,8 +111,8 @@
<button type="button" class="btn btn-l btn-secondary" onclick="krip.daily.goToPrev();">
<span class="btn-txt">이전 단계로 이동</span>
</button>
<!-- 비활성화 스타일/ 버튼 속성 disable 추가-->
<button type="button" class="btn btn-l btn-primary">
<button type="button" class="btn btn-l btn-primary"
th:disabled="${not #strings.equals(dailyRecord.incomeStatus, 'TODAY_NONE') and #lists.isEmpty(incomeList)}">
<span class="btn-txt">다음 단계로 이동</span>
</button>
</div>
@@ -145,11 +147,11 @@
let ENV = {
httpUrl: {
root: /*[[|/record/daily/${reqVO.searchMonth}/${reqVO.groupNo}|]]*/'rootUrl',
form: /*[[|/record/income/${reqVO.searchMonth}/${reqVO.groupNo}/form/{id}|]]*/'formUrl',
root: /*[[|/record/daily/${reqVO.searchMonth}/${reqVO.groupNo}|]]*/'rootUrl',
form: /*[[|/record/income/${reqVO.searchMonth}/${reqVO.groupNo}/form/{id}|]]*/'formUrl',
create: /*[[|/api/record/income/${reqVO.searchMonth}/${reqVO.groupNo}/form/{id}|]]*/'createUrl',
remove: /*[[|/api/record/income/${reqVO.searchMonth}/${reqVO.groupNo}/remove|]]*/'removeUrl',
reset: /*[[|/api/record/income/${reqVO.searchMonth}/${reqVO.groupNo}/reset|]]*/'resetUrl',
reset: /*[[|/api/record/income/${reqVO.searchMonth}/${reqVO.groupNo}/reset|]]*/'resetUrl',
},
month: [[${reqVO.searchMonth}]],
groupNo: [[${reqVO.groupNo}]],
@@ -159,10 +161,7 @@
let bind = {
form: {
selectorId: '.button-modal01',
selector: null,
// scheduleMSeq: null,
// scheduleDSeq: null,
// reserveSeq: null,
selector: '.modal01',
},
selectbox: null,
}
@@ -181,7 +180,7 @@
};
let $noneWrap = $('#todayNone');
$noneWrap.on('click', 'input[name="todayNone"]', function() {
$noneWrap.on('click', 'input[name="todayNone"]', function () {
let checked = $(this).is(':checked');
let $btn = $('.button-modal01');
$btn.attr('disabled', checked);
@@ -209,13 +208,31 @@
// modal01.open();
// });
},
_bindModelUI() {
let $formWrap = $(bind.form.selector).find('form');
$formWrap.on('keyup', 'input[name="price"]', function() {
// TODO : UI disabled
if ($(this).val() === '') {
$formWrap.find('input[name="estimatedValue"]').attr('disabled', false);
} else {
$formWrap.find('input[name="estimatedValue"]').val('').attr('disabled', true);
}
});
$formWrap.on('keyup', 'input[name="estimatedValue"]', function() {
// TODO : UI disabled
if ($(this).val() === '') {
$formWrap.find('input[name="price"]').attr('disabled', false);
} else {
$formWrap.find('input[name="price"]').val('').attr('disabled', true);
}
});
},
createModal(id) {
if (id === undefined) {
id = 0;
}
//
ajaxUtil._ajaxAsyncMethod(
ENV.httpUrl.form.replace('{id}', id),
{},
@@ -264,6 +281,7 @@
const modal01 = document.querySelector(".modal01").ui;
modal01.open();
formControl._bindModelUI();
},
function(code, rstData) {
kri.logger.error('Do nothing. code: '+ code, rstData);