Files
sam-kd/output/viewConfirm.php
hskwon aca1767eb9 초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경
- DB 연결 하드코딩 → .env 기반으로 변경
- MySQL strict mode DATE 오류 수정
2025-12-10 20:14:31 +09:00

739 lines
28 KiB
PHP

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
$title_message = '납품확인서';
$tablename = 'output';
$item ='납품확인서';
$emailTitle ='납품확인서';
include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php';
?>
<title> <?=$title_message?> </title>
<link rel="stylesheet" href="css/style.css">
<style>
.table.font10, .table.font10 td, .table.font10 th {
font-size: 10px !important;
}
</style>
</head>
<body>
<?php
// JavaScript에서 전달된 변수들 받기
$num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '';
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";
// output_extra 테이블에서 데이터 불러오기
require_once $_SERVER['DOCUMENT_ROOT'] . '/output/load_output_extraTable.php';
}
} catch (PDOException $Exception) {
print "오류: " . $Exception->getMessage();
}
// JSON 문자열을 PHP 배열로 디코딩합니다.
//스크린발주서 읽기
$eList = json_decode($estimateList, true);
// 행의 수는 배열의 크기와 동일하므로, count() 함수를 사용하여 구합니다.
$surang = count($eList);
// 행의 수를 출력하거나 활용할 수 있습니다.
// echo "행의 수: " . $surang . "<br>";
$THscreenSu = $surang + 2 ;
$rowCounter = 1; // 아이템 행 카운터 초기값 0
// 디코딩된 데이터가 배열인지 확인합니다.
if (!is_array($eList)) {
echo "데이터가 정상적이지 않습니다. 확인바랍니다.";
exit;
}
else {
foreach ($eList as $item) {
$prodcode = $item['col4'];
$items1 = ['KSS01','KSS02','KSE01'];
$items2 = ['KWE01'];
// $prodcode가 $items1 배열에 있는 경우
if (in_array($prodcode, $items1)) {
$prodname = '국민방화 스크린 셔터';
}
// $prodcode가 $items2 배열에 있는 경우
elseif (in_array($prodcode, $items2)) {
$prodname = '국민방화 스크린 플러스 셔터';
} else {
$prodname = 'Unknown'; // $prodcode가 어느 배열에도 없는 경우
}
}
}
// 'mode' 파라미터로 현재 모드 결정 (기본: 전체)
$mode = $_GET['mode'] ?? 'serial';
// 2. 그룹화 준비
$allData = $eList;
$bySerial = [];
$byFloor = [];
foreach ($eList as $item) {
// JSON 내부 키 이름에 맞게 수정하세요!
$serial = $item['serial_num']; // 예: 일련번호 필드
$floor = $item['floor_level']; // 예: 층 정보 필드
$bySerial[$serial][] = $item;
$byFloor[$floor][] = $item;
}
// 3. 선택된 모드에 따라 출력할 배열 결정
switch ($mode) {
case 'serial':
$displayData = $bySerial;
break;
case 'floor':
$displayData = $byFloor;
break;
default:
$displayData = $allData;
break;
}
?>
<!-- ===== 4. 라디오 버튼 폼 ===== -->
<div class="container mt-2">
<form method="get" class="mb-4" id="modeForm">
<label>
<input type="radio" name="mode" value="all" <?= $mode==='all' ? 'checked' : '' ?>>
전체
</label>
<label class="ms-3">
<input type="radio" name="mode" value="serial" <?= $mode==='serial' ? 'checked' : '' ?>>
일련번호별
</label>
</form>
</div>
<div class="container mt-2">
<div class="d-flex align-items-center justify-content-end mt-1 m-1">
<button type="button" class="btn btn-dark btn-sm mx-3" onclick='location.reload();' title="새로고침"> <i class="bi bi-arrow-clockwise"></i> </button>
<button type="button" class="btn btn-dark btn-sm ms-1 me-1" onclick="generatePDF()"> PDF 저장 </button>
<button type="button" class="btn btn-dark btn-sm ms-1 me-1" onclick="sendmail();"> <i class="bi bi-envelope-arrow-up"></i> 전송 </button>
<button type="button" class="btn btn-secondary btn-sm ms-5 " onclick="self.close();"> <i class="bi bi-x-lg"></i> 닫기 </button>
</div>
</div>
<div id="content-to-print">
<br>
<div class="container mt-3">
<?php include $_SERVER['DOCUMENT_ROOT'] . '/output/common/company_detail.php'; ?>
<!-- 스크린 체크 되어 있으면 스크린 출력 -->
<?php if(isset($slatcheck) && $slatcheck === '1') { ?>
<div class="row mt-2 ">
<div class="d-flex align-items-center justify-content-start">
<?php echo $rowCounter . '. 스크린'; ?>
</div>
</div>
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/screen.php';
$rowCounter++;
}
if(isset($steel) && $steel === '1') {
// ===== 2. 부호별 절곡, 부자재 내역 (flat, 원본 데이터 기준) =====
$case_sizes = ['1219', '2438', '3000', '3500', '4000', '4150'];
$guiderail_sizes = ['2438', '3000', '3500', '4000', '4300'];
echo '<div class="row mt-2"> &nbsp; &nbsp;' . $rowCounter . '. 부호별 절곡, 부자재 내역 </div>';
echo '<div class="row mt-2 ">
<div class="d-flex align-items-center justify-content-start"> ';
// 가이드레일 정보 표시
if (trim($prodcode) == "KSS01") {
$result = $rowCounter . "-1. 가이드레일 - EGI 1.55T + 마감재 SUS 1.2T";
} elseif ($prodcode == "KSE01") {
$result = $rowCounter . "-1. 가이드레일 - EGI 1.55T + 마감재 EGI 1.15T";
} else {
$result = $rowCounter . "-1. 가이드레일 - EGI 1.55T + 마감재 EGI 1.15T + 별도마감재 SUS 1.15T";
}
echo $result;
echo '</div> </div>';
echo '<table class="table text-center font10">';
echo '<thead class="table-secondary">';
echo '<tr>';
echo '<th rowspan="2" >일련<br>번호</th>';
echo '<th rowspan="2" >층 부호</th>';
echo '<th colspan="6" style="background:#dbe7fa; ">케이스(셔터박스)</th>';
echo '<th rowspan="2" style="background:#dbe7fa; ">케이스용 <br> 연기차단재<br>W80</th>';
echo '<th rowspan="2" style="background:#dbe7fa; ">상부덮개<br>(1219<br>*380)</th>';
echo '</tr>';
echo '<tr>';
foreach ($case_sizes as $size) echo "<th style=\"background:#dbe7fa; width:7.5%;\">$size</th>";
echo '</tr>';
echo '</thead><tbody>';
foreach ($eList as $item) {
echo '<tr>';
echo '<td>' . htmlspecialchars($item['col1']) . '</td>';
echo '<td>' . htmlspecialchars($item['col2']) . ' '. htmlspecialchars($item['col3']) . '</td>';
$col = 38; // 케이스 시작번호
foreach ($case_sizes as $size) {
$colName = 'col' . $col;
echo '<td>' . (isset($item[$colName]) ? $item[$colName] : '') . '</td>';
$col++;
}
// 연기차단재 W80
echo '<td>' . (isset($item['col47']) ? htmlspecialchars($item['col47']) : '') . '</td>';
// 상부덮개 1219*389
echo '<td>' . (isset($item['col44']) ? htmlspecialchars($item['col44']) : '') . '</td>';
echo '</tr>';
}
echo '</tbody></table>';
echo '<div class="row mt-2 ">
<div class="d-flex align-items-center justify-content-start"> ';
// 가이드레일 정보 표시
$result = $rowCounter . "-2. 케이스 - EGI 1.55T";
echo $result;
echo '</div> </div>';
echo '<table class="table text-center font10">';
echo '<thead class="table-secondary">';
echo '<tr>';
echo '<th rowspan="2" class="w-10">일련 번호</th>';
echo '<th rowspan="2" >층 부호</th>';
echo '<th rowspan="2" style="background:#eaf6e7; ">가이드레일 유형</th>';
echo '<th colspan="5" style="background:#eaf6e7; ">가이드레일</th>';
echo '</tr>';
echo '<tr>';
foreach ($guiderail_sizes as $size) echo "<th style=\"background:#eaf6e7; width:8%;\">$size</th>";
echo '</tr>';
echo '</thead><tbody>';
foreach ($eList as $item) {
echo '<tr>';
echo '<td>' . htmlspecialchars($item['col1']) . '</td>';
echo '<td>' . htmlspecialchars($item['col2']) . ' '. htmlspecialchars($item['col3']) . '</td>';
echo '<td>' . (isset($item['col6']) ? htmlspecialchars($item['col6']) : '') . '</td>';
$col = 24; // 가이드레일 시작번호
foreach ($guiderail_sizes as $size) {
$colName = 'col' . $col;
echo '<td>' . (isset($item[$colName]) ? $item[$colName] : '') . '</td>';
$col++;
}
echo '</tr>';
}
echo '</tbody></table>';
?>
<!-- 절곡도 표현하기 가이드레일, 케이스 -->
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/guiderail_confirm.php'; ?> <!-- 납품확인서용 가이드레일 공통사항 발주서 등 -->
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/shutterbox_confirm.php'; ?> <!-- 납품확인서용 공통셔터박스 내용 -->
<?php
// 하단마감재 col 매핑
$hajangba_cols = [ 'col49', 'col50']; // 3000, 4000
$elba_cols = [ 'col52', 'col53']; // 3000, 4000
$plate_cols = [ 'col55', 'col56']; // 3000, 4000
$weight_cols = [ 'col58' ]; // 2000
echo '<div class="row mt-2"> &nbsp; &nbsp;' . $rowCounter . '-3. 하단마감재 - 하단마감재(SUS 1.55T) + 하단보강엘바(EGI 1.55T) + 하단 보강평철(EGI 1.15T) + 하단 무게평철(50*12T) </div>';
echo '<table class="table text-center font10">';
echo '<thead class="table-secondary">';
echo '<tr>';
echo '<th rowspan="2">일련번호</th>';
echo '<th rowspan="2">층 부호</th>';
echo '<th colspan="2">하장바</th>';
echo '<th colspan="2">엘바</th>';
echo '<th colspan="2">보강평철</th>';
echo '<th colspan="3">무게평철</th>';
echo '</tr>';
echo '<tr>';
echo '<th>3000</th><th>4000</th>';
echo '<th>3000</th><th>4000</th>';
echo '<th>3000</th><th>4000</th>';
echo '<th>2000</th>';
echo '</tr>';
echo '</thead><tbody>';
foreach ($eList as $item) {
echo '<tr>';
// ① 일련번호 (col1)
$val1 = $item['col1'] ?? '';
echo '<td>' . (($val1 === 0 || $val1 === '0') ? '' : htmlspecialchars($val1)) . '</td>';
// ② 층 부호 (col2, col3)
$val2 = $item['col2'] ?? '';
$val3 = $item['col3'] ?? '';
$output23 = '';
if (!($val2 === 0 || $val2 === '0')) {
$output23 .= htmlspecialchars($val2);
}
if (!($val3 === 0 || $val3 === '0')) {
if ($output23 !== '') {
$output23 .= ' ';
}
$output23 .= htmlspecialchars($val3);
}
echo '<td>' . $output23 . '</td>';
// 하단마감재(hajangba_cols)
foreach ($hajangba_cols as $col) {
$val = $item[$col] ?? '';
echo '<td>' . (($val === 0 || $val === '0') ? '' : htmlspecialchars($val)) . '</td>';
}
// 엘바(elba_cols)
foreach ($elba_cols as $col) {
$val = $item[$col] ?? '';
echo '<td>' . (($val === 0 || $val === '0') ? '' : htmlspecialchars($val)) . '</td>';
}
// 보강평철(plate_cols)
foreach ($plate_cols as $col) {
$val = $item[$col] ?? '';
echo '<td>' . (($val === 0 || $val === '0') ? '' : htmlspecialchars($val)) . '</td>';
}
// 무게평철(weight_cols)
foreach ($weight_cols as $col) {
$val = $item[$col] ?? '';
echo '<td>' . (($val === 0 || $val === '0') ? '' : htmlspecialchars($val)) . '</td>';
}
echo '</tr>';
}
echo '</tbody></table>';
$rowCounter++;
} // end of steel 체크
if(isset($partscheck) && $partscheck === '1') {
// 부자재 col 매핑
// 보조샤프트 인치, 길이, 수량 읽어오기
$subshaft_data = [];
foreach ($eList as $item) {
$inch = $item['col59_inch'];
$length = $item['col59_length'];
if (!empty($inch) && !empty($length)) {
$key = $inch . '_' . $length;
if (!isset($subshaft_data[$key])) {
$subshaft_data[$key] = [
'inch' => $inch,
'length' => $length,
'count' => 0
];
}
$subshaft_data[$key]['count'] += (int)$item['col59'];
}
}
// 정렬을 위해 키값으로 정렬
ksort($subshaft_data);
$subshaft_cols = array_values($subshaft_data);
$shaft_cols = [ 'col60', 'col61', 'col62', 'col63', 'col64', 'col65']; // 3in, 4in(3), 5in(2)
$shaft_inch_headers = ['4인치', '4인치', '4인치', '5인치', '5인치', '5인치'];
$shaft_length_headers = ['3000', '4500', '6000', '6000', '7000', '8200'];
$recanglePipe_cols = [ 'col68', 'col69'];
$pole_cols = ['col70'];
$angle_cols = ['col71'];
echo '<div class="row mt-2"> &nbsp; &nbsp;' . $rowCounter . '-1. 부자재 - 감기샤프트, 각파이프, 앵글 </div>';
echo '<table class="table text-center font10">';
echo '<thead class="table-secondary">';
// 1st row: group headers
echo '<tr>';
echo '<th rowspan="3">일련번호</th>';
echo '<th rowspan="3">층 부호</th>';
if (!empty($subshaft_cols)) {
echo '<th colspan="' . count($subshaft_cols) . '">보조샤프트</th>';
}
echo '<th colspan="6">감기샤프트</th>';
echo '<th colspan="2" rowspan="2">각파이프 <br>50*30*1.4T </th>';
echo '<th rowspan="2">마환봉 <br> 6mm </th>';
echo '<th rowspan="2">앵글 <br> 40*40*3T </th>';
echo '</tr>';
// 2nd row: inch headers
echo '<tr>';
if (!empty($subshaft_cols)) {
foreach ($subshaft_cols as $col) {
echo '<th>' . $col['inch'] . '</th>';
}
}
echo '<th colspan="3">4인치 (114.3 * 2)</th><th colspan="3">5인치 (139.8 * 2.9)</th>';
// foreach ($shaft_inch_headers as $inch) {
// echo '<th>' . $inch . '</th>';
// }
echo '</tr>';
// 3rd row: length headers
echo '<tr>';
if (!empty($subshaft_cols)) {
foreach ($subshaft_cols as $col) {
echo '<th>' . $col['length'] . '</th>';
}
}
foreach ($shaft_length_headers as $len) {
echo '<th>' . $len . '</th>';
}
echo '<th>3000</th><th>6000</th>';
echo '<th>3000</th>';
echo '<th>2500</th>';
echo '</tr>';
echo '</thead><tbody>';
foreach ($eList as $item) {
echo '<tr>';
// ① 일련번호 (col1)
$val1 = $item['col1'] ?? '';
echo '<td>' . (($val1 === 0 || $val1 === '0') ? '' : htmlspecialchars($val1)) . '</td>';
// ② 층 부호 (col2, col3)
$val2 = $item['col2'] ?? '';
$val3 = $item['col3'] ?? '';
$output23 = '';
if (!($val2 === 0 || $val2 === '0')) {
$output23 .= htmlspecialchars($val2);
}
if (!($val3 === 0 || $val3 === '0')) {
if ($output23 !== '') {
$output23 .= ' ';
}
$output23 .= htmlspecialchars($val3);
}
echo '<td>' . $output23 . '</td>';
// 보조샤프트 데이터 출력 (있는 경우에만)
if (!empty($subshaft_cols)) {
$subshaft_index = 0;
foreach ($subshaft_cols as $col) {
$col_name = 'col' . (59 + $subshaft_index);
$val = $item[$col_name] ?? '';
echo '<td>' . (($val === 0 || $val === '0') ? '' : htmlspecialchars($val)) . '</td>';
$subshaft_index++;
}
}
// 감기샤프트 데이터 출력
foreach ($shaft_cols as $col) {
$val = $item[$col] ?? '';
echo '<td>' . (($val === 0 || $val === '0') ? '' : htmlspecialchars($val)) . '</td>';
}
// 나머지 부자재 데이터 출력
foreach ($recanglePipe_cols as $col) {
$val = $item[$col] ?? '';
echo '<td>' . (($val === 0 || $val === '0') ? '' : htmlspecialchars($val)) . '</td>';
}
foreach ($pole_cols as $col) {
$val = $item[$col] ?? '';
echo '<td>' . (($val === 0 || $val === '0') ? '' : htmlspecialchars($val)) . '</td>';
}
foreach ($angle_cols as $col) {
$val = $item[$col] ?? '';
echo '<td>' . (($val === 0 || $val === '0') ? '' : htmlspecialchars($val)) . '</td>';
}
echo '</tr>';
}
echo '</tbody></table>';
// ───────────────────────────────────────────────────
// 2-5. 부자재 - 연동제어기(매립/노출), 뒷박스, 레일용 연기차단재, 케이스용 연기차단재, 받침용 앵글, 모터용량
// ───────────────────────────────────────────────────
echo '<div class="row mt-2"> &nbsp; &nbsp;' . $rowCounter . '-2. 부자재 - 모터용량, 받침용 앵글, 연동제어기, 뒷박스 </div>';
echo '<table class="table text-center font10">';
echo '<thead class="table-secondary">';
echo '<tr>';
echo ' <th>일련번호</th>';
echo ' <th>층 부호</th>';
echo ' <th>모터용량</th>';
echo ' <th>받침용 앵글</th>';
echo ' <th>연동제어기<br>(매립)</th>';
echo ' <th>연동제어기<br>(노출)</th>';
echo ' <th>뒷박스</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach ($eList as $item) {
echo '<tr>';
// ① 일련번호 (col1)
echo '<td>' . htmlspecialchars($item['col1']) . '</td>';
// ② 층 부호 (col2, col3)
echo '<td>' . htmlspecialchars($item['col2']) . ' ' . htmlspecialchars($item['col3']) . '</td>';
// *** 아래 colXX 부분을 실제 컬럼명으로 바꿔주세요 ***
// ⑪ 모터용량 → 예시: col19
echo '<td>' . (isset($item['col19']) ? htmlspecialchars($item['col19']) : '') . '</td>';
// ⑩ 받침용 앵글 → 예시: col20
echo '<td>' . (isset($item['col22']) ? htmlspecialchars($item['col22']) : '') . ' x 1 EA </td>';
// ③ 연동제어기(매립) → 예시: col15
echo '<td>' . (isset($item['col15']) ? htmlspecialchars($item['col15']) : '') . '</td>';
// ④ 연동제어기(노출) → 예시: col16
echo '<td>' . (isset($item['col16']) ? htmlspecialchars($item['col16']) : '') . '</td>';
// ⑤ 뒷박스 → 예시: col17
echo '<td>' . (isset($item['col17']) ? htmlspecialchars($item['col17']) : '') . '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
$rowCounter++;
} // end of partscheck 체크
// 부자재 표현하기 JSON 데이터를 디코딩
$etcListArray = json_decode($etcList, true);
if (is_array($etcListArray) && count($etcListArray) > 0) : ?>
<div class="row mt-2">
<div class="d-flex align-items-center justify-content-start">
3. 소모품(별도구매) - 방화실리콘, 세라크울, 제품검사비(인정표시)등은 추가사항으로 별도의 비용이 발생 함.
</div>
</div>
<?PHP endif; ?>
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/etc.php'; ?> <!-- 소모품 등 발주서 등등 공통 -->
</div>
<div class="container mb-5 mt-2">
<div class="d-flex align-items-center justify-content-center mb-5">
</div>
</div>
</div> <!-- end of container -->
<!-- 페이지로딩 -->
<script>
$(document).ready(function(){
var loader = document.getElementById('loadingOverlay');
loader.style.display = 'none';
});
function generatePDF() {
var workplace = '<?php echo $outworkplace; ?>';
var deadline = '<?php echo $indate; ?>';
var deadlineDate = new Date(deadline);
var formattedDate = "(" + String(deadlineDate.getFullYear()).slice(-2) + "." + ("0" + (deadlineDate.getMonth() + 1)).slice(-2) + "." + ("0" + deadlineDate.getDate()).slice(-2) + ")";
var result = 'KD납품확인서(' + workplace +')' + formattedDate + '.pdf';
var element = document.getElementById('content-to-print');
var opt = {
margin: [10, 3, 12, 3], // Top, right, bottom, left margins
filename: result,
image: { type: 'jpeg', quality: 1 },
html2canvas: { scale: 3 },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
pagebreak: { mode: [''] }
};
html2pdf().from(element).set(opt).save();
}
function generatePDF_server(callback) {
var workplace = '<?php echo $title_message; ?>';
var item = '<?php echo $emailTitle; ?>';
var today = new Date();
var formattedDate = "(" + String(today.getFullYear()).slice(-2) + "." + ("0" + (today.getMonth() + 1)).slice(-2) + "." + ("0" + today.getDate()).slice(-2) + ")";
var result = 'KD' + item +'(' + workplace + ')' + formattedDate + '.pdf';
var element = document.getElementById('content-to-print');
var opt = {
margin: [10, 3, 12, 3], // Top, right, bottom, left margins
filename: result,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
pagebreak: { mode: [''] }
};
html2pdf().from(element).set(opt).output('datauristring').then(function (pdfDataUri) {
var pdfBase64 = pdfDataUri.split(',')[1]; // Base64 인코딩된 PDF 데이터 추출
var formData = new FormData();
formData.append('pdf', pdfBase64);
formData.append('filename', result);
$.ajax({
type: 'POST',
url: '/email/save_pdf.php', // PDF 파일을 저장하는 PHP 파일
data: formData,
processData: false,
contentType: false,
success: function (response) {
var res = JSON.parse(response);
if (callback) {
callback(res.filename); // 서버에 저장된 파일 경로를 콜백으로 전달
}
},
error: function (xhr, status, error) {
Swal.fire('Error', 'PDF 저장에 실패했습니다.', 'error');
}
});
});
}
var ajaxRequest = null;
function sendmail() {
var secondordnum = '<?php echo $secondordnum; ?>'; // 서버에서 가져온 값
var item = '<?php echo $emailTitle; ?>';
if (!secondordnum) {
Swal.fire({
icon: 'warning',
title: '오류 알림',
text: '발주처 코드가 없습니다.'
});
return; // 함수 종료
}
if (typeof ajaxRequest !== 'undefined' && ajaxRequest !== null) {
ajaxRequest.abort();
}
ajaxRequest = $.ajax({
type: 'POST',
url: '/email/get_companyCode.php',
data: { secondordnum: secondordnum },
dataType: 'json',
success: function(response) {
console.log('response : ', response);
if (response.error) {
Swal.fire('Error', response.error, 'error');
} else {
var email = response.email;
var vendorName = response.vendor_name;
Swal.fire({
title: 'E메일 보내기',
text: vendorName + ' Email 주소확인',
icon: 'warning',
input: 'text', // input 창을 텍스트 필드로 설정
inputLabel: 'Email 주소 수정 가능',
inputValue: email, // 기존 이메일 주소를 기본값으로 설정
showCancelButton: true,
confirmButtonText: '보내기',
cancelButtonText: '취소',
reverseButtons: true,
inputValidator: (value) => {
if (!value) {
return '이메일 주소를 입력해주세요!';
}
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(value)) {
return '올바른 이메일 형식을 입력해주세요!';
}
}
}).then((result) => {
if (result.isConfirmed) {
const updatedEmail = result.value; // 입력된 이메일 주소 가져오기
generatePDF_server(function(filename) {
sendEmail(updatedEmail, vendorName, item, filename);
});
}
});
}
},
error: function(xhr, status, error) {
Swal.fire('Error', '전송중 오류가 발생했습니다.', 'error');
}
});
}
function sendEmail(recipientEmail, vendorName, item, filename) {
if (typeof ajaxRequest !== 'undefined' && ajaxRequest !== null) {
ajaxRequest.abort();
}
var today = new Date();
var formattedDate = "(" + String(today.getFullYear()).slice(-2) + "." + ("0" + (today.getMonth() + 1)).slice(-2) + "." + ("0" + today.getDate()).slice(-2) + ")";
ajaxRequest = $.ajax({
type: 'POST',
url: '/email/send_email.php', // 이메일 전송을 처리하는 PHP 파일
data: { email: recipientEmail, vendorName: vendorName, filename: filename, item: item, formattedDate: formattedDate },
success: function(response) {
console.log(response);
Swal.fire('Success', '정상적으로 전송되었습니다.', 'success');
},
error: function(xhr, status, error) {
Swal.fire('Error', '전송에 실패했습니다. 확인바랍니다.', 'error');
}
});
}
$(document).ready(function() {
// 라디오 버튼 변경 이벤트 처리
$('input[name="mode"]').change(function() {
var selectedMode = $(this).val();
var num = '<?php echo $num; ?>'; // 현재 보고 있는 문서 번호
// AJAX 요청
$.ajax({
url: window.location.pathname,
type: 'GET',
data: {
mode: selectedMode,
num: num
},
success: function(response) {
// 응답에서 필요한 섹션만 추출
var tempDiv = $('<div>').html(response);
// 모터 섹션 업데이트
var motorTitle = $('.row:contains("2. 모터")').first();
var motorSection = tempDiv.find('.row:contains("2. 모터")').nextUntil('.row:contains("3. 절곡품")');
motorTitle.nextUntil('.row:contains("3. 절곡품")').remove();
motorTitle.after(motorSection);
// 절곡품 섹션 업데이트
var guiderailTitle = $('.row:contains("3. 절곡품")').first();
var guiderailSection = tempDiv.find('.row:contains("3. 절곡품")').nextUntil('.row:contains("3-2. 하단마감재")');
guiderailTitle.nextUntil('.row:contains("3-2. 하단마감재")').remove();
guiderailTitle.after(guiderailSection);
// 하단마감재 섹션 업데이트
var bottomTitle = $('.row:contains("3-2. 하단마감재")').first();
var bottomSection = tempDiv.find('.row:contains("3-2. 하단마감재")').nextUntil('.row:contains("4. 부자재")');
bottomTitle.nextUntil('.row:contains("4. 부자재")').remove();
bottomTitle.after(bottomSection);
// 부자재 섹션 업데이트
var subgoodsTitle = $('.row:contains("4. 부자재")').first();
var subgoodsSection = tempDiv.find('.row:contains("4. 부자재")').nextUntil('.container.mb-5');
subgoodsTitle.nextUntil('.container.mb-5').remove();
subgoodsTitle.after(subgoodsSection);
// 디버깅을 위한 로그
// console.log('Motor section length:', motorSection.length);
// console.log('Guiderail section length:', guiderailSection.length);
// console.log('Bottom section length:', bottomSection.length);
// console.log('Subgoods section length:', subgoodsSection.length);
},
error: function(xhr, status, error) {
console.error('Error:', error);
Swal.fire('Error', '데이터를 불러오는데 실패했습니다.', 'error');
}
});
});
});
</script>
</body>
</html>