- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
453 lines
18 KiB
PHP
453 lines
18 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">
|
|
</head>
|
|
<body>
|
|
|
|
<?php
|
|
// JavaScript에서 전달된 변수들 받기
|
|
$num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '';
|
|
$lotNum = isset($_REQUEST['lotNum']) ? $_REQUEST['lotNum'] : '';
|
|
$outdate = isset($_REQUEST['outdate']) ? $_REQUEST['outdate'] : ''; // 출고일
|
|
|
|
// 출고일이 존재할 경우에만 다음날 계산
|
|
if ($outdate) {
|
|
// 출고일을 DateTime 객체로 변환
|
|
$date = new DateTime($outdate);
|
|
|
|
// 1일 더하기
|
|
$date->modify('+1 day');
|
|
|
|
// 형식화된 날짜 (예: Y-m-d 형식)로 출력
|
|
$outdateplusone = $date->format('Y-m-d');
|
|
} else {
|
|
// 출고일이 없을 경우 기본값
|
|
$outdateplusone = '';
|
|
}
|
|
|
|
$orderdate = isset($_REQUEST['orderdate']) ? $_REQUEST['orderdate'] : ''; // 발주일
|
|
$prodCode = isset($_REQUEST['prodCode']) ? $_REQUEST['prodCode'] : ''; // prodCode 받기
|
|
$warrantyNum = isset($_REQUEST['warrantyNum']) ? $_REQUEST['warrantyNum'] : ''; // warrantyNum 받기
|
|
|
|
// 추가된 변수 받기
|
|
$delivery = isset($_REQUEST['delivery']) ? $_REQUEST['delivery'] : ''; // 배송 옵션 받기
|
|
$outworkplace = isset($_REQUEST['outworkplace']) ? $_REQUEST['outworkplace'] : ''; // 출고 작업장 받기
|
|
$outputplace = isset($_REQUEST['outputplace']) ? $_REQUEST['outputplace'] : ''; // 배송 주소지
|
|
|
|
|
|
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 ;
|
|
|
|
// 디코딩된 데이터가 배열인지 확인합니다.
|
|
if (!is_array($eList)) {
|
|
echo "데이터가 정상적이지 않습니다. 확인바랍니다.";
|
|
exit;
|
|
}
|
|
|
|
else {
|
|
foreach ($eList as $item) {
|
|
$prodcode = $item['col4'];
|
|
$items1 = ['KSS01','KSE01'];
|
|
$items2 = ['KWE01'];
|
|
|
|
// $prodcode가 $items1 배열에 있는 경우
|
|
if (in_array($prodcode, $items1)) {
|
|
$prodname = '국민방화 스크린 셔터';
|
|
}
|
|
// $prodcode가 $items2 배열에 있는 경우
|
|
elseif (in_array($prodcode, $items2)) {
|
|
$prodname = '국민방화 스크린 플러스 셔터';
|
|
} else {
|
|
$prodname = 'Unknown'; // $prodcode가 어느 배열에도 없는 경우
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|
|
|
|
<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">
|
|
<div class="row">
|
|
<div class="d-flex align-items-center justify-content-center">
|
|
<table class="table " style="border-collapse: collapse;">
|
|
<thead>
|
|
<tr>
|
|
<th colspan="5" rowspan="3" class="text-center" style="width:70%;">
|
|
<div class="row">
|
|
<div class="col-sm-2">
|
|
<img src="../img/kdlogo.png" alt="경동기업" class="me-1" style="width:100%; height:auto;">
|
|
</div>
|
|
<div class="col-sm-10">
|
|
<div class="d-flex align-items-center justify-content-center m-1">
|
|
<span class="text-dark ms-2 me-2 fs-2" > 납 </span>
|
|
<span class="text-dark ms-2 me-2 fs-2" > 품 </span>
|
|
<span class="text-dark ms-2 me-2 fs-2" > 확 </span>
|
|
<span class="text-dark ms-2 me-2 fs-2" > 인 </span>
|
|
<span class="text-dark ms-2 fs-2" > 서 </span>
|
|
</div>
|
|
<br>
|
|
<div class="d-flex align-items-center justify-content-center mt-2">
|
|
<span class="text-dark ms-2 " style="font-size:10px;" > 전화 : 031-983-5130 | 팩스 : 02-6911-6315 | 이메일 : kd5130@naver.com </span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</th>
|
|
<th class="text-center " style="width:5%;">로트번호</th>
|
|
<th colspan="3" class="text-center text-primary fw-bold fs-6" > <?=$lotNum?> </th>
|
|
</tr>
|
|
<tr>
|
|
<th class="text-center fw-bold" style="height:80px;">결 재</th>
|
|
<th colspan="3" rowspan="2" class="text-center fs-5" style="width : 70px; height:22px; padding:2px;"> 경 동 기 업
|
|
<img src="../img/KDstamp.png" alt="도장" style="width:45px; height:45px;">
|
|
<!-- <span class="ms-3 fs-6"> (인) </span> -->
|
|
</th>
|
|
</tr>
|
|
<tr>
|
|
</tr>
|
|
<tr>
|
|
<th class="text-center blueBlackBold" >상 품 명</th>
|
|
<th class="text-center blueBlackBold"><?=$prodname?></th>
|
|
<th class="text-center blueBlackBold">제품명</th>
|
|
<th class="text-center blueBlackBold"><?=$prodcode?></th>
|
|
<th class="text-center blueBlackBold">인정번호</th>
|
|
<th colspan="4" class="text-center blueBlackBold fw-bold"><?=$warrantyNum?></th>
|
|
</tr>
|
|
</thead>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="d-flex align-items-center justify-content-start ">
|
|
<table class="table table-bordered" style="border-collapse: collapse;">
|
|
<thead>
|
|
<tr>
|
|
<th colspan="2" class="text-center align-middle lightgray" style="width:33%;">신 청 업 체</th>
|
|
<th colspan="2" class="text-center align-middle lightgray" style="width:33%;">신 청 내 용</th>
|
|
<th colspan="2" class="text-center align-middle lightgray" style="width:33%;">납 품 정 보</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th class="text-center align-middle lightgray">발주일</th>
|
|
<th class="text-center"><?=specialDate($orderdate)?></th>
|
|
<th class="text-center align-middle lightgray">현 장 명</th>
|
|
<th colspan="3" class="text-center text-primary fw-bold"><?=$outworkplace?> </th>
|
|
</tr>
|
|
<tr>
|
|
<th class="text-center align-middle lightgray">발주처</th>
|
|
<th class="text-center"><?=$secondord?> </th>
|
|
<th class="text-center align-middle lightgray">납기요청일</th>
|
|
<th colspan="1" class="text-center text-primary fw-bold"><?=specialDate($outdateplusone)?> </th>
|
|
<th class="text-center align-middle lightgray">인수담당자</th>
|
|
<th colspan="1" class="text-center text-primary fw-bold"><?=$orderman?> </th>
|
|
</tr>
|
|
<tr>
|
|
<th class="text-center align-middle lightgray">발주 담당자</th>
|
|
<th class="text-center"><?=$orderman?></th>
|
|
<th class="text-center align-middle lightgray">출고일</th>
|
|
<th colspan="1" class="text-center text-primary fw-bold"><?=specialDate($outdate)?> </th>
|
|
<th class="text-center align-middle lightgray">인수자연락처</th>
|
|
<th class="text-center text-primary fw-bold"><?=$_SESSION['hp']?> </th>
|
|
</tr>
|
|
<tr>
|
|
<th class="text-center align-middle lightgray">담당자 연락처</th>
|
|
<th class="text-center text-dark fw-bold"><?=$_SESSION['hp']?> </th>
|
|
<th class="text-center align-middle lightgray">셔터총수량</th>
|
|
<th class="text-center"> <?=$surang ?> (개소) </th>
|
|
<th class="text-center align-middle lightgray">배 송 방 법</th>
|
|
<th class="text-center"> <?=$delivery ?> </th>
|
|
</tr>
|
|
<tr>
|
|
<th class="text-center align-middle lightgray">배송지 주소</th>
|
|
<th colspan="5" class="text-center"><?=$outputplace?></th>
|
|
</tr>
|
|
</thead>
|
|
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row mt-2 ">
|
|
<div class="d-flex align-items-center justify-content-start">
|
|
1. 스크린
|
|
</div>
|
|
</div>
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/screen.php'; ?> <!-- 스크린, 발주서, 출고증, 확인서 등등 공통 -->
|
|
<div class="row mt-2 ">
|
|
<div class="d-flex align-items-center justify-content-start">
|
|
2. 모터
|
|
</div>
|
|
</div>
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/motor.php'; ?> <!-- 모터, 발주서, 출고증, 확인서 등등 공통 -->
|
|
|
|
<div class="row mt-2 ">
|
|
<div class="d-flex align-items-center justify-content-start">
|
|
3. 절곡품
|
|
<br>
|
|
<?php
|
|
// 가이드레일 정보 표시
|
|
if (trim($prodcode) == "KSS01") {
|
|
$result = "3-1. 가이드레일 - EGI 1.55T + 마감재 SUS 1.2T";
|
|
} elseif ($prodcode == "KSE01") {
|
|
$result = "3-1. 가이드레일 - EGI 1.55T + 마감재 EGI 1.15T";
|
|
} else {
|
|
$result = "3-1. 가이드레일 - EGI 1.55T + 마감재 EGI 1.15T + 별도마감재 SUS 1.15T";
|
|
}
|
|
echo $result;
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/guiderail.php'; ?> <!-- 가이드레일 공통사항 발주서 등 -->
|
|
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/shutterbox.php'; ?> <!-- 출고증, 발주서 등등 공통셔터박스 내용 -->
|
|
|
|
<div class="row mt-2">
|
|
<div class="d-flex justify-content-start">
|
|
|
|
3-2. 하단마감재 <br>
|
|
<?php
|
|
if (trim($prodcode) == "KSS01") {
|
|
$result = "하단마감재(SUS 1.55T) + 하단보강엘바(EGI 1.55T) + 하단 보강평철(EGI 1.15T) + 하단 무게평철(50*12T)";
|
|
} else {
|
|
$result = "하단마감재(EGI 1.55T) + 하단보강엘바(EGI 1.55T) + 하단 보강평철(EGI 1.15T) + 하단 무게평철(50*12T)";
|
|
}
|
|
echo $result . '</div></div>' ;
|
|
?>
|
|
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/bottom.php'; ?> <!-- 하단마감재 발주서 등등 공통 -->
|
|
|
|
<div class="row mt-2">
|
|
<div class="d-flex justify-content-start">
|
|
4. 부자재 - 감기샤프트, 각파이프, 앵글, 마환봉
|
|
</div>
|
|
</div>
|
|
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/subgoods.php'; ?> <!-- 부자재 발주서 등등 공통 -->
|
|
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $tablename . '/common/etc.php'; ?> <!-- 소모품 등 발주서 등등 공통 -->
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<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 -->
|
|
|
|
</body>
|
|
</html>
|
|
|
|
<!-- 페이지로딩 -->
|
|
<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: 0.98 },
|
|
html2canvas: { scale: 1 },
|
|
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');
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
</script>
|