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

337 lines
13 KiB
PHP

<?php
// 셔터박스 데이터 초기화
$box_data = [];
// echo $WebSite;
// $eList를 순회하며 데이터 생성
foreach ($eList as $item) {
$boxSize = trim($item['col37']); // 셔터박스 크기
if ($boxSize == 'custom') {
$boxSize = trim($item['col37_custom']);
}
$boxdirection = $item['col37_boxdirection'];
$boxfrontbottom = $item['col37_frontbottom'];
$boxrailwidth = $item['col37_railwidth'];
$cover = intval($item['col45']); // 상부덮개 수량
$manguriSize = $item['col46'] ?? ''; // 마구리 size
$fincover = intval($item['col47']); // 측면부(마구리) 수량
$boxLengths = [
['length' => '1219', 'quantity' => intval($item['col39'])],
['length' => '2438', 'quantity' => intval($item['col40'])],
['length' => '3000', 'quantity' => intval($item['col41'])],
['length' => '3500', 'quantity' => intval($item['col42'])],
['length' => '4000', 'quantity' => intval($item['col43'])],
['length' => '4150', 'quantity' => intval($item['col44'])]
];
// 동일한 `size` 값이 이미 존재하는지 확인
$existingKey = array_search($boxSize, array_column($box_data, 'size'));
if ($existingKey === false) {
// 새로운 사이즈 추가
$box_data[] = [
'size' => $boxSize,
'sum' => 1,
'cover' => $cover,
'fincover' => $fincover,
'boxdirection' => $boxdirection,
'boxfrontbottom' => $boxfrontbottom,
'boxrailwidth' => $boxrailwidth,
'manguriSize' => $manguriSize,
'length_data' => array_map(function ($length) {
return ['length' => $length['length'], 'sum' => $length['quantity']];
}, $boxLengths)
];
} else {
// 기존 데이터에 값 누적
$box_data[$existingKey]['sum'] += 1;
$box_data[$existingKey]['cover'] += $cover;
$box_data[$existingKey]['fincover'] += $fincover;
// 길이 데이터 누적
foreach ($boxLengths as $index => $length) {
$box_data[$existingKey]['length_data'][$index]['sum'] += $length['quantity'];
}
}
}
function fetchImageData($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // HTTPS 인증 무시
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // 연결 시간 초과 설정
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // 리다이렉트 따라가기
$imageData = curl_exec($ch);
// if (curl_errno($ch)) {
// echo "DEBUG: cURL 오류 -> " . curl_error($ch) . "<br>";
// }
curl_close($ch);
return $imageData;
}
function drawImage($sourcePath, $savePath, $textData, $fontSize = 3) {
// URL을 로컬 경로로 변환
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
global $root_dir;
$relativePath = str_replace($root_dir, '', $savePath);
$localSavePath = $documentRoot . $relativePath;
// echo "DEBUG: 변환된 로컬 저장 경로 -> {$localSavePath}<br>";
// 폴더 생성
$saveDir = dirname($localSavePath);
if (!is_dir($saveDir)) {
if (!mkdir($saveDir, 0777, true)) {
echo "DEBUG: 폴더 생성 실패 -> {$saveDir}<br>";
return false;
}
} else {
chmod($saveDir, 0777);
// echo "DEBUG: 폴더 권한 설정 -> {$saveDir}<br>";
}
// 원본 이미지 데이터 가져오기 (cURL 사용)
// echo "DEBUG: 원본 이미지 경로 -> {$sourcePath}<br>";
$imageData = fetchImageData($sourcePath);
if (!$imageData) {
// echo "DEBUG: 원본 이미지 데이터를 가져올 수 없습니다.<br>";
return false;
}
// echo "DEBUG: 원본 이미지 데이터 로드 성공<br>";
// 이미지 로드 및 작업
$tempImage = tempnam(sys_get_temp_dir(), 'image');
file_put_contents($tempImage, $imageData);
$image = @imagecreatefromjpeg($tempImage);
unlink($tempImage);
if (!$image) {
echo "DEBUG: JPEG 이미지를 로드할 수 없습니다.<br>";
return false;
}
// echo "DEBUG: 이미지 리소스 생성 성공<br>";
// 텍스트 추가
$textColor = imagecolorallocate($image, 255, 0, 0); // 빨간색
foreach ($textData as $textItem) {
if (isset($textItem['text'], $textItem['x'], $textItem['y'])) {
imagestring(
$image,
$fontSize,
intval($textItem['x']),
intval($textItem['y']),
$textItem['text'],
$textColor
);
// echo "DEBUG: 텍스트 추가 -> '{$textItem['text']}' @ ({$textItem['x']}, {$textItem['y']})<br>";
}
}
// 이미지 저장
$result = @imagejpeg($image, $localSavePath);
// if ($result) {
// echo "DEBUG: 이미지 저장 성공 -> {$localSavePath}<br>";
// } else {
// echo "DEBUG: 이미지 저장 실패 -> {$localSavePath}<br>";
// }
imagedestroy($image);
return $result ? $localSavePath : false;
}
?>
<?php foreach ($box_data as $box): ?>
<?PHP
// echo '<pre>';
// print_r($box);
// echo '</pre>';
?>
<div class="row">
<div class="col-sm-12">
<div class="d-flex align-items-center justify-content-start">
<table class="table avoid-break" style="border-collapse: collapse;">
<thead class="table-secondary">
<tr>
<th class="text-center"><?php echo $box['size']; ?> 셔터박스 (점검구:<?=$box['boxdirection']?>) </th>
<th class="text-center">길이</th>
<th class="text-center">수량</th>
<th class="text-center">측면부<br>[마구리]</th>
<th class="text-center">수량</th>
<th class="text-center">상부덮개</th>
<th class="text-center">수량</th>
</tr>
</thead>
<tbody>
<?php
if($box['boxdirection'] == '밑면')
{
// 점검구 양면 이미지 생성
$sourcePath = $WebSite . 'img/box/source/box_bottom.jpg';
$saveName = 'box_' . str_replace('*', 'x', $box['size']) . '_bottom.jpg';
$savePath = $WebSite . 'img/box/' . $saveName;
list($boxwidth, $boxheight) = explode('*', $box['size']);
$TopcoverSize = $boxwidth - 111; // 텍스트로 추가할 값
// 여러 텍스트 데이터
$textData = [
['text' => $boxheight , 'x' => 15, 'y' => 85],
['text' => $TopcoverSize, 'x' => 100, 'y' => 2],
['text' => $box['boxfrontbottom'] , 'x' => 25, 'y' => 170],
['text' => $box['boxrailwidth'] , 'x' => 55, 'y' => 210],
['text' => ($boxwidth-$box['boxfrontbottom']-$box['boxrailwidth']-140) , 'x' => 120, 'y' => 175],
['text' => ($boxheight) , 'x' => 176, 'y' => 90],
['text' => ($boxwidth+5) , 'x' => 100, 'y' => 225],
['text' => ($boxheight+5) , 'x' => 135, 'y' => 250],
];
}
else if($box['boxdirection'] == '후면')
{
// 점검구 후면 이미지 생성
$sourcePath = $WebSite . 'img/box/source/box_rear.jpg';
$saveName = 'box_' . str_replace('*', 'x', $box['size']) . '_rear.jpg';
$savePath = $WebSite . 'img/box/' . $saveName;
list($boxwidth, $boxheight) = explode('*', $box['size']);
$TopcoverSize = $boxwidth - 111; // 텍스트로 추가할 값
$textData = [
['text' => $boxheight , 'x' => 15, 'y' => 85],
['text' => $TopcoverSize, 'x' => 100, 'y' => 2],
['text' => $box['boxfrontbottom'] , 'x' => 25, 'y' => 170],
['text' => $box['boxrailwidth'] , 'x' => 55, 'y' => 210],
['text' => ($boxwidth-$box['boxfrontbottom']-$box['boxrailwidth']) , 'x' => 120, 'y' => 165],
['text' => ($boxheight-140) , 'x' => 192, 'y' => 90],
['text' => ($boxwidth+5) , 'x' => 100, 'y' => 225],
['text' => ($boxheight+5) , 'x' => 135, 'y' => 250],
];
}
else // 없으면 양면으로 추정함 ($box['boxdirection'] == '양면')
{
// 점검구 양면 이미지 생성
$sourcePath = $WebSite . 'img/box/source/box_both.jpg';
$saveName = 'box_' . str_replace('*', 'x', $box['size']) . '_both.jpg';
$savePath = $WebSite . 'img/box/' . $saveName;
list($boxwidth, $boxheight) = explode('*', $box['size']);
$TopcoverSize = $boxwidth - 111; // 텍스트로 추가할 값
// 여러 텍스트 데이터
$textData = [
['text' => $boxheight , 'x' => 15, 'y' => 85],
['text' => $TopcoverSize, 'x' => 100, 'y' => 2],
['text' => $box['boxfrontbottom'] , 'x' => 25, 'y' => 170],
['text' => $box['boxrailwidth'] , 'x' => 55, 'y' => 210],
['text' => ($boxwidth-$box['boxfrontbottom']-$box['boxrailwidth']-140) , 'x' => 120, 'y' => 175],
['text' => ($boxheight-140) , 'x' => 192, 'y' => 90],
['text' => ($boxwidth+5) , 'x' => 100, 'y' => 225],
['text' => ($boxheight+5) , 'x' => 135, 'y' => 250],
];
}
drawImage($sourcePath, $savePath, $textData, 4);
// 길이 데이터 필터링
$filteredLengths = array_filter($box['length_data'], function ($length) {
return $length['sum'] > 0;
});
// echo '<pre>';
// print_r($filteredLengths);
// echo '</pre>';
$rowspan = count($filteredLengths); // 유효 길이의 개수만큼 rowspan 계산
$innerCount = 0;
?>
<?php foreach ($filteredLengths as $index => $length):
$innerCount ++ ;
?>
<tr>
<?php if ($innerCount === 1): ?>
<!-- 첫 번째 행에만 이미지를 출력 -->
<td class="text-center" rowspan="<?php echo $rowspan; ?>">
<img src="../img/box/<?php echo $saveName; ?>" alt="셔터박스" width="220">
</td>
<?php endif; ?>
<td class="text-center"><?php echo $length['length']; ?></td>
<td class="text-center"><?php echo $length['sum']; ?></td>
<?php if ($innerCount === 1): ?>
<!-- 첫 번째 행에만 측면부와 상부덮개 정보 출력 -->
<td class="text-center" rowspan="<?php echo $rowspan; ?>">
<?php echo $box['manguriSize']; ?>
</td>
<td class="text-center" rowspan="<?php echo $rowspan; ?>">
<?php echo $box['fincover']; ?>
</td>
<td class="text-center" rowspan="<?php echo $rowspan; ?>">
<?PHP
list($boxwidth, $boxheight) = explode('*', $box['size']); // 셔터박스 크기 분리
echo '1219*' . ($boxwidth-111);
?>
</td>
<td class="text-center" rowspan="<?php echo $rowspan; ?>">
<?php echo $box['cover']; ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endforeach; ?>
<!-- 셔터박스용 연기차단재(W80) -->
<?php
// 셔터박스용 연기차단재(W80)
if (True) {
// W80 기준 숫자 찾기
$smokeban80 = 0;
foreach ($eList as $item) {
$smokeban80 += floatval($item['col48']); // 철재는 48, 스크린은 47
}
// 테이블 출력 시작
echo '<div class="row">';
echo '<div class="d-flex align-items-center justify-content-start">';
echo '<table class="table avoid-break" style="border-collapse: collapse;">';
// 연기차단재 데이터 출력
echo '<tbody>';
echo '<tr>';
// 첫 번째 td (연기차단재 설명)
echo '<td rowspan="2" class="text-center fw-bold orangeBlackBold">';
echo '연기차단재(W80)<br> 전면부, 린텔부 <span class="text-danger">"양쪽에"</span> 설치';
echo '</td>';
// 두 번째 td (재료 설명)
echo '<td rowspan="2" class="text-center orangeBlackBold">';
echo 'EGI 0.8T +<br>화이바글라스코팅직물';
echo '</td>';
// 세 번째 td (이미지)
echo '<td rowspan="2" class="text-center ">';
echo '<img src="../img/part/smokeban.jpg" alt="연기차단재" width="150">';
echo '</td>';
// 네 번째 td (규격과 길이)
echo '<td class="text-center fw-bold orangeBlackBold">규격[L]</td>';
echo '<td class="text-center fw-bold"> L : 3,000</td>';
echo '</tr>';
// 다섯 번째 td (수량)
echo '<tr>';
echo '<td class="text-center fw-bold orangeBlackBold">수량</td>';
echo '<td class="text-center fw-bold">' . $smokeban80 . '</td>';
echo '</tr>';
echo '</tbody>';
echo '</table>';
echo '</div>';
echo '</div>';
}
?>