- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
17 KiB
17 KiB
estimate_compare_head.php 개발자 가이드
📋 개요
estimate_compare_head.php는 방화셔터 견적 시스템의 견적 비교 페이지 헤더를 담당하는 핵심 PHP 컴포넌트입니다. 이 파일은 견적 비교 화면의 상단 부분을 구성하며, 견적 정보 조회, 헤더 출력, 금액 비교 테이블 등을 포함합니다.
🏗️ 파일 구조
📁 파일 위치
/estimate/common/estimate_compare_head.php
📊 파일 정보
- 파일 크기: 8.1KB (207 lines)
- 주요 언어: PHP + HTML + CSS
- 의존성: Bootstrap, jQuery, MySQL/PDO
- 주요 기능: 견적 정보 조회, 헤더 출력, 금액 비교
🔧 핵심 기능
1. 헤더 및 의존성 로드
<?php include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php'; ?>
<title> <?=$title_message?> </title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
2. 견적 정보 조회
$num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '';
$option = isset($_REQUEST['option']) ? $_REQUEST['option'] : ''; // 견적서와 산출서의 다른점을 표현하는 것
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/estimate/fetch_unitprice.php");
$pdo = db_connect();
try {
$sql = "select * from {$DB}.{$tablename} where num = ? ";
$stmh = $pdo->prepare($sql);
$stmh->bindValue(1, $num, PDO::PARAM_STR);
$stmh->execute();
$count = $stmh->rowCount();
if ($count < 1) {
print "검색결과가 없습니다.<br>";
} else {
$row = $stmh->fetch(PDO::FETCH_ASSOC);
include "_row.php";
}
} catch (PDOException $Exception) {
print "오류: " . $Exception->getMessage();
}
3. 견적 데이터 디코딩
// JSON 문자열을 PHP 배열로 디코딩합니다.
if($major_category == '스크린')
$decodedEstimateList = json_decode($estimateList, true);
else
$decodedEstimateList = json_decode($estimateSlatList, true);
// 디코딩된 데이터가 배열인지 확인합니다.
if (!is_array($decodedEstimateList)) {
echo "데이터가 정상적이지 않습니다. 확인바랍니다.";
exit;
}
echo '<script>';
echo 'var dataList = ' . json_encode($detailJson ?? []) . ';';
echo '</script>';
📋 폼 구조
🎯 숨겨진 입력 필드
<form id="board_form" name="board_form" method="post" enctype="multipart/form-data">
<input type="hidden" id="mode" name="mode" value="<?= isset($mode) ? $mode : '' ?>">
<input type="hidden" id="num" name="num" value="<?= isset($num) ? $num : '' ?>">
<input type="hidden" id="user_name" name="user_name" value="<?= isset($user_name) ? $user_name : '' ?>">
<input type="hidden" id="update_log" name="update_log" value="<?= isset($update_log) ? $update_log : null ?>">
<input type="hidden" id="tablename" name="tablename" value="<?= isset($tablename) ? $tablename : '' ?>">
<input type="hidden" id="header" name="header" value="<?= isset($header) ? $header : '' ?>">
<input type="hidden" id="detailJson" name="detailJson"> <!-- 라디오버튼 저장하려면 두개의 변수가 필요하다. -->
<input type="hidden" id="estimateSurang" name="estimateSurang"> <!-- 견적가 수량 -->
<input type="hidden" id="estimateTotal" name="estimateTotal"> <!-- 견적가 총액 -->
🎨 UI 구성 요소
📊 헤더 네비게이션
<div class="container-fluid mt-2">
<div class="row">
<div class="col-sm-12">
<div class="d-flex align-items-center justify-content-center mt-3 m-1 mb-4">
<span class="badge bg-secondary me-5 fs-5"> <?=$major_category?> 인정제품 견적비교 </span>
<button type="button" class="btn btn-dark btn-sm me-1 ms-1" onclick='location.reload();'>
<i class="bi bi-arrow-clockwise"></i>
</button>
<span style="display:none;">
<input type="checkbox" id="showEstimateCheckbox" <?php echo ($option == 'option') ? '' : 'checked'; ?>>
<label for="showEstimateCheckbox" class="me-3">산출내역서 보이기</label>
</span>
</div>
</div>
<div class="col-sm-12">
<div class="d-flex align-items-center justify-content-end mt-3 m-1 mb-4">
<button type="button" class="btn btn-secondary btn-sm ms-5" onclick="self.close();"> × 닫기 </button>
</div>
</div>
</div>
</div>
⚠️ 알림 메시지
<div class="d-flex align-items-center justify-content-center mt-2 mb-0">
<div class="alert alert-primary mb-2" role="alert">
검사비는 제주도를 제외하고, 5만원으로 수정, '산출내역 저장'버튼을 누른 후 저장해야 금액이 확정됩니다.
</div>
</div>
💰 금액 비교 테이블
<div class="d-flex align-items-center justify-content-end mt-0">
<table class="table table-bordered mt-0 text-end w-auto">
<thead class="table-secondary">
<tr>
<th class="text-center">최초 자동금액</th>
<th class="text-center">수정 금액</th>
<th class="text-center">차액</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" id="EstimateFirstSum" name="EstimateFirstSum" class="form-control text-end" readonly
value="<?= isset($EstimateFirstSum) && $EstimateFirstSum != 0 ? number_format($EstimateFirstSum) : $EstimateFirstSum ?>">
</td>
<td>
<input type="text" id="EstimateUpdatetSum" name="EstimateUpdatetSum" class="form-control text-end text-primary" readonly
value="<?= isset($EstimateUpdatetSum) && $EstimateUpdatetSum != 0 ? number_format($EstimateUpdatetSum) : $EstimateUpdatetSum ?>">
</td>
<td>
<input type="text" id="EstimateDiffer" name="EstimateDiffer" class="form-control text-end text-danger" readonly
value="<?= isset($EstimateDiffer) && $EstimateDiffer != 0 ? number_format($EstimateDiffer) : $EstimateDiffer ?>">
</td>
</tr>
</tbody>
</table>
</div>
📄 견적서 헤더
🏢 견적서 기본 정보
<div class="container-fluid mt-1">
<div class="d-flex align-items-center justify-content-center ">
<table class="table table-sm" style="border-collapse: collapse;">
<tbody>
<tr>
<td class="text-center fw-bold" style="width:8%;" >작성일자</td>
<td rowspan="2" class="text-center align-middle fw-bold fs-4" style="width:60%; border-top:none; border-bottom:none;" >
<?php
if($option!=='option')
echo '<span class="badge bg-primary"> ' . $title_message . ' </span> </td>';
else
echo '<span class="text-dark"> ' . $title_message_sub . ' </span> </td>';
?>
<td class="text-center fw-bold" style="width:10%;" >견적번호</td>
</tr>
<tr>
<td class="text-center" > <?=$indate?> </td>
<td class="text-center fw-bold text-primary" > <?=$pjnum?> </td>
</tr>
</tbody>
</table>
</div>
</div>
👥 업체 정보 테이블
<div class="d-flex align-items-center justify-content-center ">
<table class="table" style="border-collapse: collapse;">
<tbody>
<tr>
<td class="text-center fw-bold yellowBold " style="width:10%;">업체명</td>
<td class="text-center yellowBold " style="width:40%;"> <?=$secondord?> (귀하) </td>
<td rowspan="5" class="text-center align-middle fw-bold" style="width:5%; border-top:none; border-bottom:none;" >공 급 자</td>
<td class="text-center fw-bold lightgray " > 상호 </td>
<td class="text-center fw-bold" colspan="3" >㈜ 경동기업 </td>
</tr>
<tr>
<td class="text-center fw-bold">제품명</td>
<td class="text-center" > <?=$subTitle?> </td>
<td class="text-center fw-bold lightgray " style="width:10%;" >등록번호</td>
<td class="text-center" style="width:10%;"> 139-87-00333 </td>
<td class="text-center fw-bold lightgray " >대표자</td>
<td class="text-center fw-bold">
<div class="d-flex align-items-center justify-content-center ">
이 경 호
</div>
</td>
</tr>
<tr>
<td class="text-center fw-bold">현장명</td>
<td class="text-center fw-bold" > <?=$outworkplace?></td>
<td class="text-center fw-bold lightgray " > 사업장주소 </td>
<td colspan="3" class="text-center"> 경기도 김포시 통진읍 옹정로 45-22</td>
</tr>
<tr>
<td class="text-center fw-bold">담당자</td>
<td class="text-center"><?=$secondordman?></td>
<td class="text-center fw-bold lightgray " > 업 태 </td>
<td class="text-center" > 제조업 </td>
<td class="text-center fw-bold lightgray " >종목</td>
<td class="text-center" > 방화셔터, 금속창호 </td>
</tr>
<tr>
<td class="text-center fw-bold">연락처</td>
<td class="text-center"><?=$secondordmantel?></td>
<td class="text-center fw-bold lightgray " > TEL. </td>
<td class="text-center" > 031-983-5130</td>
<td class="text-center fw-bold lightgray " > FAX </td>
<td class="text-center" > 02-6911-6315 </td>
</tr>
</tbody>
</table>
</div>
💵 합계 금액 표시
<div class="d-flex align-items-center justify-content-center ">
<table class="table" style="border-collapse: collapse;">
<tbody>
<tr>
<td class="text-center fw-bold" style="width:250px;" >
합계금액(부가세 별도) <br>
아래와 같이 견적합니다
</td>
<td class="text-center align-middle fs-6 fw-bold" style="width:50px;"> 금 </td>
<td rowspan="5" class="text-end align-middle fw-bold fs-6" style="width:500px;">
<span id="koreantotalsum"> </span>
</td>
<td class="text-center fw-bold align-middle fs-6" style="width:50px;" > 원 </td>
<td class="align-middle text-end fs-6 fw-bold" style="width:250px;">
( ₩ <span id="totalsum"> </span> )
</td>
</tr>
</tbody>
</table>
</div>
📊 데이터 변수
🎯 주요 PHP 변수
$num: 견적 번호$option: 견적서/산출서 구분 옵션$major_category: 주요 카테고리 (스크린/철재)$title_message: 제목 메시지$title_message_sub: 서브 제목 메시지$indate: 입력 날짜$pjnum: 프로젝트 번호$secondord: 발주처명$subTitle: 제품명$outworkplace: 현장명$secondordman: 담당자명$secondordmantel: 연락처
💰 금액 관련 변수
$EstimateFirstSum: 최초 자동금액$EstimateUpdatetSum: 수정 금액$EstimateDiffer: 차액$estimateList: 스크린 견적 리스트 (JSON)$estimateSlatList: 철재 견적 리스트 (JSON)$detailJson: 상세 견적 데이터 (JSON)
🔧 개발자 사용법
📝 기본 사용법
// 파일 포함
include_once('/estimate/common/estimate_compare_head.php');
// 견적 번호 설정
$_REQUEST['num'] = '견적번호';
// 옵션 설정 (견적서/산출서)
$_REQUEST['option'] = 'option'; // 산출서 모드
🎯 데이터 조회
// 견적 정보 조회
$sql = "SELECT * FROM {$DB}.{$tablename} WHERE num = ?";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(1, $num, PDO::PARAM_STR);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
📊 JSON 데이터 처리
// 스크린/철재 구분하여 데이터 디코딩
if($major_category == '스크린') {
$decodedEstimateList = json_decode($estimateList, true);
} else {
$decodedEstimateList = json_decode($estimateSlatList, true);
}
// JavaScript 변수로 전달
echo '<script>';
echo 'var dataList = ' . json_encode($detailJson ?? []) . ';';
echo '</script>';
🚨 주의사항
⚠️ 필수 의존성
- PHP 7.4+
- MySQL/PDO
- Bootstrap 5.x
- jQuery 3.x
🔒 보안 고려사항
- SQL 인젝션 방지를 위한 prepared statements 사용
- 입력값 검증 및 이스케이프 처리
- 세션 기반 인증 확인
📱 성능 최적화
- 데이터베이스 쿼리 최적화
- JSON 데이터 크기 제한
- 불필요한 데이터베이스 호출 최소화
🐛 디버깅 가이드
🔍 일반적인 문제 해결
1. 견적 정보가 표시되지 않는 경우
// 데이터베이스 연결 확인
if (!$pdo) {
echo "데이터베이스 연결 실패";
exit;
}
// 쿼리 결과 확인
$stmt = $pdo->prepare($sql);
$stmt->bindValue(1, $num, PDO::PARAM_STR);
$stmt->execute();
$count = $stmt->rowCount();
echo "조회된 행 수: " . $count;
if ($count > 0) {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row); // 결과 확인
}
2. JSON 데이터 오류
// JSON 디코딩 오류 확인
$decodedEstimateList = json_decode($estimateList, true);
if (json_last_error() !== JSON_ERROR_NONE) {
echo "JSON 디코딩 오류: " . json_last_error_msg();
echo "원본 데이터: " . $estimateList;
}
3. 변수가 정의되지 않은 경우
// 변수 존재 여부 확인
if (!isset($title_message)) {
echo "title_message 변수가 정의되지 않았습니다.";
}
// 기본값 설정
$title_message = $title_message ?? '기본 제목';
$major_category = $major_category ?? '스크린';
📚 관련 파일
🔗 의존성 파일
load_header.php: 헤더 로드mydb.php: 데이터베이스 연결fetch_unitprice.php: 단가 조회 함수_row.php: 행 데이터 처리
🔗 연관 파일
compare_lastJS.php: 견적 비교 JavaScriptcompare_price_edit_table.php: 단가 수정 테이블common_screen.php: 스크린 테이블 생성common_slat.php: 철재 테이블 생성
🔗 CSS 클래스
yellowBold: 노란색 굵은 글씨lightgray: 연한 회색 배경table-secondary: 테이블 헤더 배경
🔗 JavaScript 변수
dataList: 견적 데이터 배열EstimateFirstSum: 최초 금액EstimateUpdatetSum: 수정 금액EstimateDiffer: 차액
🎯 향후 개선 방향
🔄 코드 리팩토링
- 클래스 기반 구조로 변경
- 설정 파일 분리
- 의존성 주입 패턴 도입
🎨 UI/UX 개선
- 반응형 디자인 개선
- 다크 모드 지원
- 접근성 향상
⚡ 성능 최적화
- 데이터베이스 쿼리 최적화
- 캐싱 시스템 도입
- 이미지 최적화
🔧 기능 확장
- 다국어 지원
- 템플릿 시스템 도입
- 실시간 업데이트
📊 견적서 구조
🎯 견적서 구성 요소
- 헤더 정보: 작성일자, 견적번호, 제목
- 업체 정보: 발주처 및 공급자 정보
- 금액 비교: 최초/수정/차액 표시
- 합계 금액: 한국어/숫자 금액 표시
📈 데이터 흐름
- 견적 번호 입력 → 데이터베이스 조회
- 견적 정보 로드 → 변수에 할당
- JSON 데이터 디코딩 → JavaScript 변수로 전달
- 헤더 출력 → HTML 렌더링
🔄 업데이트 프로세스
- 최초 견적 생성 → 자동 계산
- 수정 견적 입력 → 사용자 입력
- 차액 계산 → 자동 계산
- 저장 및 확정 → 데이터베이스 저장
📅 문서 버전: 1.0
👨💻 작성자: 개발팀
📝 최종 수정일: 2024-12-24
🔗 관련 문서: 견적 시스템 전체 가이드, common_addrowJS 개발자 가이드, common_screen 개발자 가이드, common_slat 개발자 가이드, compare_lastJS 개발자 가이드, compare_price_edit_table 개발자 가이드