");
// 제목
contents.append("
견 적 서
");
// estimateTemplate 키는 대문자/소문자 모두 체크
// 수신처는 contractInfo에서 고객사명 가져오기
String recipient = CommonUtils.checkNull(contractInfo.get("customer_name"));
if("".equals(recipient)) recipient = CommonUtils.checkNull(contractInfo.get("CUSTOMER_NAME"));
// 없으면 estimateTemplate에서 가져오기
if("".equals(recipient)) recipient = CommonUtils.checkNull(estimateTemplate.get("recipient"));
if("".equals(recipient)) recipient = CommonUtils.checkNull(estimateTemplate.get("RECIPIENT"));
String contactPerson = CommonUtils.checkNull(estimateTemplate.get("contact_person"));
if("".equals(contactPerson)) contactPerson = CommonUtils.checkNull(estimateTemplate.get("CONTACT_PERSON"));
String estimateNo = CommonUtils.checkNull(estimateTemplate.get("estimate_no"));
if("".equals(estimateNo)) estimateNo = CommonUtils.checkNull(estimateTemplate.get("ESTIMATE_NO"));
String executorDate = CommonUtils.checkNull(estimateTemplate.get("executor"));
if("".equals(executorDate)) executorDate = CommonUtils.checkNull(estimateTemplate.get("EXECUTOR"));
if("".equals(executorDate)) executorDate = CommonUtils.checkNull(estimateTemplate.get("executor_date"));
if("".equals(executorDate)) executorDate = CommonUtils.checkNull(estimateTemplate.get("EXECUTOR_DATE"));
// 담당자 정보
String managerName = CommonUtils.checkNull(estimateTemplate.get("manager_name"));
if("".equals(managerName)) managerName = CommonUtils.checkNull(estimateTemplate.get("MANAGER_NAME"));
if("".equals(managerName)) managerName = "영업부";
String managerContact = CommonUtils.checkNull(estimateTemplate.get("manager_contact"));
if("".equals(managerContact)) managerContact = CommonUtils.checkNull(estimateTemplate.get("MANAGER_CONTACT"));
// 헤더 섹션 (왼쪽: 기본정보, 오른쪽: 회사정보)
contents.append(""); // header-section 닫기
// 인사말 및 담당자 정보
contents.append("
");
contents.append("
");
contents.append("견적을 요청해 주셔서 대단히 감사합니다.
");
contents.append("하기와 같이 견적서를 제출합니다.");
contents.append("
");
contents.append("
");
contents.append("담당자 : " + managerName + "
");
if(!"".equals(managerContact)) {
contents.append("연락처 : " + managerContact + "
");
}
contents.append("부가세 별도");
contents.append("
");
contents.append("
");
// 견적 품목
if(estimateItems != null && !estimateItems.isEmpty()){
contents.append("
");
contents.append("");
contents.append("");
contents.append("번호 NO. | ");
contents.append("품 명 DESCRIPTION | ");
contents.append("규 격 SPECIFICATION | ");
contents.append("수량 Q'TY | ");
contents.append("단위 UNIT | ");
contents.append("단 가 UNIT PRICE | ");
contents.append("금 액 AMOUNT | ");
contents.append("비고 | ");
contents.append("
");
contents.append("");
contents.append("");
long totalAmount = 0;
for(int i = 0; i < estimateItems.size(); i++){
Map item = estimateItems.get(i);
String amount = CommonUtils.checkNull(item.get("amount"));
if(!"".equals(amount)){
try {
totalAmount += Long.parseLong(amount.replace(",", ""));
} catch(Exception e){}
}
contents.append("");
contents.append("| " + (i + 1) + " | ");
contents.append("" + CommonUtils.checkNull(item.get("description")) + " | ");
contents.append("" + CommonUtils.checkNull(item.get("specification")) + " | ");
contents.append("" + CommonUtils.checkNull(item.get("quantity")) + " | ");
contents.append("" + CommonUtils.checkNull(item.get("unit")) + " | ");
contents.append("" + CommonUtils.checkNull(item.get("unit_price")) + " | ");
contents.append("" + CommonUtils.checkNull(item.get("amount")) + " | ");
contents.append("" + CommonUtils.checkNull(item.get("note")) + " | ");
contents.append("
");
}
// 계 (총 합계) - 통화 기호 포함
String totalAmountStr = CommonUtils.checkNull(estimateTemplate.get("total_amount"));
if("".equals(totalAmountStr)) totalAmountStr = CommonUtils.checkNull(estimateTemplate.get("TOTAL_AMOUNT"));
// DB에 저장된 합계가 없으면 계산한 값 사용
if("".equals(totalAmountStr)){
totalAmountStr = String.format("%,d", totalAmount);
}
// 통화 기호 가져오기
String currencyName = CommonUtils.checkNull(estimateTemplate.get("contract_currency_name"));
if("".equals(currencyName)) currencyName = CommonUtils.checkNull(estimateTemplate.get("CONTRACT_CURRENCY_NAME"));
String currencySymbol = "₩"; // 기본값
if(currencyName.indexOf("달러") >= 0 || "USD".equals(currencyName)) {
currencySymbol = "$";
} else if(currencyName.indexOf("유로") >= 0 || "EUR".equals(currencyName)) {
currencySymbol = "€";
} else if(currencyName.indexOf("엔") >= 0 || "JPY".equals(currencyName)) {
currencySymbol = "¥";
} else if(currencyName.indexOf("위안") >= 0 || "CNY".equals(currencyName)) {
currencySymbol = "¥";
}
contents.append("");
contents.append("| 계 | ");
contents.append("" + currencySymbol + totalAmountStr + " | ");
contents.append(" | ");
contents.append("
");
// 원화환산 공급가액 - 제거 (화면에서도 숨김 처리)
// 테이블 내 비고 (항상 표시)
String noteRemarks = CommonUtils.checkNull(estimateTemplate.get("note_remarks"));
if("".equals(noteRemarks)) noteRemarks = CommonUtils.checkNull(estimateTemplate.get("NOTE_REMARKS"));
System.out.println("===== 비고 내용 확인 =====");
System.out.println("noteRemarks: [" + noteRemarks + "]");
System.out.println("========================");
contents.append("");
contents.append("| ");
contents.append(" <비고> ");
contents.append("" + noteRemarks + " ");
contents.append(" | ");
contents.append("
");
// 참조사항 (NOTE1~4)
String note1 = CommonUtils.checkNull(estimateTemplate.get("note1"));
if("".equals(note1)) note1 = CommonUtils.checkNull(estimateTemplate.get("NOTE1"));
if("".equals(note1)) note1 = "1. 견적유효기간: 일";
String note2 = CommonUtils.checkNull(estimateTemplate.get("note2"));
if("".equals(note2)) note2 = CommonUtils.checkNull(estimateTemplate.get("NOTE2"));
if("".equals(note2)) note2 = "2. 납품기간: 발주 후 1주 이내";
String note3 = CommonUtils.checkNull(estimateTemplate.get("note3"));
if("".equals(note3)) note3 = CommonUtils.checkNull(estimateTemplate.get("NOTE3"));
if("".equals(note3)) note3 = "3. VAT 별도";
String note4 = CommonUtils.checkNull(estimateTemplate.get("note4"));
if("".equals(note4)) note4 = CommonUtils.checkNull(estimateTemplate.get("NOTE4"));
if("".equals(note4)) note4 = "4. 결제 조건 : 기존 결제조건에 따름.";
// 참조사항 행 추가
contents.append("");
contents.append("| ");
contents.append(" <참조사항> ");
contents.append("" + note1 + " ");
contents.append("" + note2 + " ");
contents.append("" + note3 + " ");
contents.append("" + note4 + " ");
contents.append(" | ");
contents.append("
");
// 하단 회사명 행 추가
contents.append("");
contents.append("| ");
contents.append("㈜알피에스");
contents.append(" | ");
contents.append("
");
contents.append("");
contents.append("
");
}
contents.append("
"); // estimate-container 닫기
contents.append("");
contents.append("");
return contents.toString();
}
/**
* 이미지 파일을 Base64로 인코딩
* @param imagePath 이미지 파일 경로
* @return Base64 인코딩된 문자열 (data:image/png;base64,...)
*/
private String encodeImageToBase64(String imagePath) {
try {
File imageFile = new File(imagePath);
if(!imageFile.exists()) {
return "";
}
java.io.FileInputStream fis = new java.io.FileInputStream(imageFile);
byte[] imageBytes = new byte[(int) imageFile.length()];
fis.read(imageBytes);
fis.close();
// Apache Commons Codec 사용 (Java 7 호환)
String base64 = org.apache.commons.codec.binary.Base64.encodeBase64String(imageBytes);
// 파일 확장자로 MIME 타입 결정
String mimeType = "image/png";
if(imagePath.toLowerCase().endsWith(".jpg") || imagePath.toLowerCase().endsWith(".jpeg")) {
mimeType = "image/jpeg";
} else if(imagePath.toLowerCase().endsWith(".gif")) {
mimeType = "image/gif";
}
return "data:" + mimeType + ";base64," + base64;
} catch(Exception e) {
System.out.println("이미지 Base64 인코딩 실패: " + e.getMessage());
e.printStackTrace();
return "";
}
}
/**
* 영업정보 조회 (수주등록용)
* @param contractObjId
* @return
*/
public Map