거래명세서 수정

This commit is contained in:
leeheejin
2025-11-13 17:26:28 +09:00
parent 7195dfb5f1
commit 67f694be65

View File

@@ -571,6 +571,62 @@ function fn_fillData(data) {
$("#totalText").text(total.toString());
$("#totalNum").text(fn_num(total));
// contenteditable 셀 변경 시 합계 자동 업데이트
fn_attachCellListeners();
}
// 품목 테이블의 셀 변경 감지 및 합계 재계산
function fn_attachCellListeners() {
// 품목 테이블의 모든 contenteditable 셀에 이벤트 리스너 추가
$("#itemsBody td[contenteditable='true']").off('blur').on('blur', function() {
fn_recalculateTotal();
});
}
// 합계 재계산 함수
function fn_recalculateTotal() {
console.log("=== 합계 재계산 ===");
var totalQuantity = 0;
var totalSupply = 0;
var totalVat = 0;
// 품목 테이블의 각 행을 순회하며 합계 계산
$("#itemsBody tr").each(function() {
var cells = $(this).find("td");
if(cells.length >= 6) {
// 수량 (3번째 열, index 2)
var quantityText = $(cells[2]).text().trim().replace(/,/g, '');
var quantity = parseInt(quantityText) || 0;
// 공급가액 (5번째 열, index 4)
var supplyText = $(cells[4]).text().trim().replace(/,/g, '');
var supply = parseInt(supplyText) || 0;
// 세액 (6번째 열, index 5)
var vatText = $(cells[5]).text().trim().replace(/,/g, '');
var vat = parseInt(vatText) || 0;
totalQuantity += quantity;
totalSupply += supply;
totalVat += vat;
}
});
console.log("재계산된 총 수량:", totalQuantity);
console.log("재계산된 총 공급가액:", totalSupply);
console.log("재계산된 총 세액:", totalVat);
// tfoot의 합계 행 업데이트
$("#totalQuantity").text(totalQuantity);
$("#totalSupplyPrice").text(fn_num(totalSupply));
$("#totalVat").text(fn_num(totalVat));
// 상단 합계 금액 업데이트
var total = totalSupply + totalVat;
$("#totalText").text(total.toString());
$("#totalNum").text(fn_num(total));
}
function fn_num(n) {