Files
sam-kd/estimate/screen_view_original.php

1825 lines
88 KiB
PHP
Raw Normal View History

<?php
// 전체 SET 내역 표시 일련번호, 종류, 부호, 제품명, 오픈사이즈 등 전체금액 나오는 부분
// 2025/05/23 모터 견적가 포함 검색 추가
// 견적서, 거래명세표는 테이블형태가 다름, 거래명세표는 부가세 부분 표시하고 합계를 나타냄
if(True) {
$data = [];
$counter = 0;
$index = 0;
$sums = []; // 각 행의 합을 저장할 배열
// 전체 반복 찾기
foreach ($decodedEstimateList as $item) {
if (isset($item['col5']) && !empty($item['col5'])) {
// 각 행별 합계 재계산
// 검사비 10만원 처음 들어감
$sums[$counter] = $inspectionFee;
$su = floatval($item['col14']);
$itemTitle = floatval($item['col5']);
if($itemTitle == '실리카')
$itemTitle = '스크린';
else
$itemTitle = '와이어';
// 행의 나머지 데이터를 설정
$row = [];
$row['col1'] = $counter + 1;
$row['col2'] = $itemTitle ;
$row['col3'] = $item['col3'] ?? ''; // col2는 item의 col3 값을 사용
$row['col4'] = $item['col4'] ?? ''; // col3은 item의 col4 값을 사용
$row['col5'] = $item['col8']; // 필요한 값으로 설정
$row['col6'] = $item['col9'];
$row['col7'] = $item['col14']; // 수량
$row['col8'] = 'SET'; // 빈 값으로 재계산 (필요에 따라 채움)
// $data 배열에 행을 추가합니다.
$data[] = $row;
$counter++;
}
}
echo '<div class="d-flex align-items-center justify-content-center ">';
echo '<table id="tableDetail" class="table" style="border-collapse: collapse;">';
echo '<thead>';
echo '<tr>';
echo '<th rowspan="2" class="text-center">일련<br>번호</th>';
echo '<th rowspan="2" class="text-center">종류</th>';
echo '<th rowspan="2" class="text-center">부호</th>';
echo '<th rowspan="2" class="text-center">제품명</th>';
echo '<th colspan="2" class="text-center">오픈사이즈</th>';
echo '<th rowspan="2" class="text-center">수량</th>';
echo '<th rowspan="2" class="text-center">단위</th>';
echo '<th rowspan="2" class="text-center">단가</th>';
if($selectWork !== '거래명세표') { // 견적서
echo '<th class="text-center">합계</th>';
} else { // 거래명세표
echo '<th colspan="3" class="text-center">금액</th>';
}
echo '</tr>';
echo '<tr>';
echo '<th class="text-center">가로</th>';
echo '<th class="text-center">세로</th>';
if($selectWork !== '거래명세표') { // 견적서
echo '<th class="text-center">금액</th>';
} else { // 거래명세표
echo '<th class="text-center">공급가액</th>';
echo '<th class="text-center">부가세</th>';
echo '<th class="text-center">합계</th>';
}
echo '</tr>';
echo '</thead>';
echo '<tbody>';
$col7_sum = 0; // col7 수량 합계
$col89_sum = 0; // col8 + col9 합계
$col10_sum = 0;
$row_count = 0;
foreach ($data as $row) {
echo '<tr class="calculation-row calculation-firstrow" data-row="' . $row_count . '" data-serial="' . $row_count . '">';
if($selectWork !== '거래명세표') { // 견적서
$innercount = 10;
} else { // 거래명세표
$innercount = 12;
}
for ($i = 1; $i <= $innercount; $i++) {
switch ($i) {
case 1:
echo '<td class="text-center ">' . $row['col1'] . '</td>';
break;
case 4:
echo '<td class="text-center yellowBold ">' . htmlspecialchars($row['col' . $i]) . '</td>';
break;
case 6:
echo '<td class="text-center text-primary fw-bold ">' . htmlspecialchars($row['col' . $i]) . '</td>';
break;
case 7:
echo '<td class="text-center text-primary fw-bold total-su-input" data-serial="' . $row_count . '">' . htmlspecialchars($row['col' . $i]) . '</td>';
break;
case 9:
echo '<td class="text-end text-dark total-unit-price-input" data-serial="' . $row_count . '" ></td>'; // 단가가 들어가는 셀
break;
case 10:
echo '<td class="text-end subtotal-cell" data-serial="' . $row_count . '" ></td>'; // 공급가액
break;
case 11:
echo '<td class="text-end vat-cell" data-serial="' . $row_count . '" ></td>'; // VAT
break;
case 12:
echo '<td class="text-end text-primary subtotalamount-cell" data-serial="' . $row_count . '" ></td>'; // 합계 금액
break;
default:
echo '<td class="text-center ">' . htmlspecialchars($row['col' . $i]) . '</td>';
break;
}
}
echo '</tr>';
$row_count++;
$estimateSurang = $col7_sum += intval($row['col7']);
}
// 소계 행 추가
echo '<tr>';
echo '<td class="text-center" colspan="6">소계</td>';
echo '<td class="text-center text-primary fw-bold">' . $col7_sum. '</td>';
echo '<td class="text-center" colspan="2"></td>';
if($selectWork !== '거래명세표') { // 견적서
echo '<td id="subtotal" class="text-end fw-bold grand-total"></td>';
} else { // 거래명세표
echo '<td id="subtotal" class="text-end fw-bold grand-total"></td>';
echo '<td id="subtotalvat" class="text-end fw-bold grand-vat"></td>';
echo '<td id="subtotalamount" class="text-end text-primary fw-bold grand-sum"></td>';
}
echo '</tr>';
if($option == 'option') { // 견적서 보기를 누르면 비고 표시
echo '<tr>';
echo '<td colspan="1">';
echo '비고';
echo '</td>';
echo '<td colspan="'. ($innercount-1) .'" class="text-start fw-bold" style="white-space: normal; word-wrap: break-word;">';
echo '<div class="d-flex flex-wrap">';
echo $comment;
echo '</div>';
echo '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
echo '</div>';
}
// 세부 산출내역서
echo '<br>';
echo '<div class="Estimateview">';
echo '<div class="d-flex align-items-center justify-content-center mt-2 mb-2">';
echo '<h3 class="mb-2"> 세부 산출내역서 </h3></div>';
echo '<div id="shutterboxMsg" class="d-flex align-items-center justify-content-center mt-2 mb-2" style="display:none;">';
echo '</div>';
echo '<div class="d-flex align-items-center justify-content-center ">';
echo '<table id="detailTable" class="table p-3" style="border-collapse: collapse;">';
echo '<thead>';
echo '<tr>';
echo '<th class="text-center lightgray w50px">일련<br>번호</th>';
echo '<th class="text-center lightgray w300px">항목</th>';
echo '<th class="text-center lightgray w50px">수량</th>';
echo '<th class="text-center lightgray w50px">단위</th>';
echo '<th class="text-center lightgray w250px">산출식</th>';
echo '<th class="text-center lightgray w80px">면적(㎡) <br> 길이(㎜)</th>';
echo '<th class="text-center lightgray w100px">면적(㎡) <br> 길이(㎜) 단가</th>';
echo '<th class="text-center lightgray w100px">단가</th>';
echo '<th class="text-center lightgray w120px">합계</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
$row_count = 0;
$total_sum = 0; // 전체 합계를 계산할 변수
$counter = 0;
$index = 0;
$subtotal_array = [] ; // 소계 누계
$subtotal_surang_array = [] ; // 수량 누계
$row_array = [] ; // 각 행별 행카운트 배열
// 전체 반복 찾기
foreach ($decodedEstimateList as $column) {
$subtotal = 0; // 각 일련번호별 소계
$rowCount = 0; // 행의 수
if (isset($column['col5']) && !empty($column['col5'])) {
$su = floatval($column['col14']); // 수량
// 가이드레일 및 기타 부품 단가 초기화
$guidrail_price = 0;
$bottomBarPrices = 0; // 하단마감재 단가
$LBarPrices = 0; // L바 단가
$bottomPlatePrices = 0; // 보강평철 단가
$guiderailSmokeBanPrices = 0; // 가이드레일용 연기차단재 단가
$boxSmokeBanPrices = 0; // 케이스용 연기차단재 단가
$maguriPrices = 0; // 마구리 단가
$finishing = $column['col7']; // 마감 (SUS, EGI) (스크린/철재 동일한 위치)
$guideType = $column['col6']; // 벽면형(120*70), 혼합형
$modelCode = $column['col4']; // 모델코드
$maguriCol = $column['col45']; // 마구리 size (스크린 45위치, 철재 46위치)
// 데이터베이스 테이블 이름 설정 (BDmodels)
$tablename = 'BDmodels';
try {
$sql = "SELECT * FROM " . $DB . "." . $tablename;
$stmh = $pdo->prepare($sql);
$stmh->execute();
$count = $stmh->rowCount();
if ($count < 1) {
print "검색결과가 없습니다.<br>";
} else {
// 케이스 단가 정보를 저장할 배열
$shutterBoxprices = [];
// 가이드레일 단가를 저장할 배열 (모델코드, 마감, spec 기준으로 저장)
$guidrailPrices = [];
// 정규표현식 패턴 (숫자 형식만 매칭)
$pattern = '/\d{2,4}\*\d{2,4}/';
// 전체 데이터를 반복 처리
while ($row = $stmh->fetch(PDO::FETCH_ASSOC)) {
$prodcode = $row['model_name'] ?? ''; // 모델코드
$spec = $row['spec'] ?? ''; // '120*70' 형태
$seconditem = $row['seconditem'] ?? ''; // 제품 분류
$load_finishingType = $row['finishing_type'] ?? ''; // 마감형태
$unitprice = $row['unitprice'] ?? 0;
// 단가에서 숫자와 소수점만 남기기
$unitprice_clean = preg_replace('/[^0-9.]/', '', $unitprice);
$unitprice_value = floatval($unitprice_clean);
// 케이스 단가 저장
if ($seconditem == '케이스' && $unitprice_value > 0) {
$shutterBoxprices[$spec] = $unitprice_value;
}
// 가이드레일 단가 저장 (모델코드 + 마감 + spec 기준으로 저장)
if ($seconditem == '가이드레일') {
$key = $prodcode . '|' . $load_finishingType . '|' . $spec;
$guidrailPrices[$key] = $unitprice_value;
}
// 하단마감재 단가 설정
if ($prodcode == $modelCode && $seconditem == '하단마감재' && $finishing == $load_finishingType) {
if ($unitprice_value > 0) {
$bottomBarPrices = $unitprice_value;
}
}
// 가이드레일용 연기차단재
if ($seconditem == '가이드레일용 연기차단재' && $unitprice_value > 0) {
$guiderailSmokeBanPrices = $unitprice_value;
}
// 케이스용 연기차단재
if ($seconditem == '케이스용 연기차단재' && $unitprice_value > 0) {
$boxSmokeBanPrices = $unitprice_value;
}
// L-BAR KDSS01은 다른규격 가져옴
if ($prodcode == $modelCode && $seconditem == 'L-BAR' && $unitprice_value > 0) {
$LBarPrices = $unitprice_value;
}
// 보강평철
if ($seconditem == '보강평철' && $unitprice_value > 0) {
$bottomPlatePrices = $unitprice_value;
}
// 마구리 (마구리+규격 650*550)
if ($seconditem == '마구리' && $spec == $maguriCol && $unitprice_value > 0) {
$maguriPrices = $unitprice_value;
}
}
// 가이드레일 단가 계산
$baseKey = $modelCode . '|' . $finishing; // 기본 키 생성
if (strpos($guideType, '혼합형') !== false) {
// 혼합형 처리 (예: 혼합형(130*75)(130*125))
preg_match_all($pattern, $guideType, $matches);
if (!empty($matches[0]) && count($matches[0]) == 2) {
$wallKey = $baseKey . '|' . $matches[0][0];
$sideKey = $baseKey . '|' . $matches[0][1];
$wallPrice = $guidrailPrices[$wallKey] ?? 0;
$sidePrice = $guidrailPrices[$sideKey] ?? 0;
$guidrail_price = ($wallPrice + $sidePrice); // 1개 세트 가격
}
} else if (strpos($guideType, '벽면형') !== false) {
// 벽면형 또는 측면형 처리 (예: 벽면형(120*70))
preg_match($pattern, $guideType, $match);
if (!empty($match[0])) {
$guideSpec = $match[0];
$guideKey = $baseKey . '|' . $guideSpec;
$guidrail_price = ($guidrailPrices[$guideKey] ?? 0) * 2; // 2개 세트 가격
}
}
else {
$guidrail_price = 0;
}
}
} catch (PDOException $Exception) {
print "오류: " . $Exception->getMessage();
}
// 각 행별 합계 재계산
// 주자재 계산
if($slatcheck == '1') {
$tablename = 'price_raw_materials';
$query = "SELECT itemList FROM {$DB}.$tablename WHERE is_deleted IS NULL OR is_deleted = 0 ORDER BY registedate DESC LIMIT 1"; // 최신 1개의 데이터만 가져오기
$stmt = $pdo->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // 모든 행을 가져옴
$price_raw_materials = 0;
$price_jointbar = 0;
// 모든 행을 순회하면서 원하는 데이터를 찾음
foreach ($rows as $row) {
$itemList = json_decode($row['itemList'], true);
$price_raw_materials = slatPrice($itemList, '스크린', '실리카');
if(!empty($price_raw_materials) )
break;
}
}
// 견적서를 스크린 900 높이로 계산함. 기본 350 + 550 추가로 더해줌
$height = !empty($column['col11_SH']) ? floatval($column['col11_SH']) : floatval($column['col11']);
$width = !empty($column['col10_SW']) ? floatval($column['col10_SW']) : floatval($column['col10']);
$calculateHeight = $height + 550;
$area = $width * $calculateHeight / 1000000;
if($motor == '1') {
// 모터가격 계산
$tablename = 'price_motor';
$query = "SELECT itemList FROM {$DB}.$tablename WHERE (is_deleted IS NULL OR is_deleted = 0) ORDER BY NUM LIMIT 1";
$stmt = $pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$itemList = json_decode($row['itemList'], true);
// 모터 스펙 정리 (예: 400K → 400)
$motorSpec = $column['col19'];
$motorSpec = preg_replace('/[a-zA-Z]/', '', $motorSpec);
$price = getPriceForMotor($motorSpec, $itemList);
// 모터 공급사 확인
$motor_supplier = $column['col18_brand'];
// 모터단가 초기화
$motorUnit_price = 0;
if ($motor_supplier === '경동(견적가포함)') {
$su = floatval($column['col14']); // 수량
$motorUnit_price = round($price);
// 모터 가격 합산
$sums[$counter] += $motorUnit_price * $su;
}
// 매립 연동제어기 가격 계산
$price_controller = 0;
$price1 = calculateControllerSpec($column['col15'], $itemList, '매립형');
if($price1 > 0 && !empty($column['col15']))
{
$price_controller += $price1;
$controller_amount += $price1 * intval($column['col15']); // 매립형 개수 곱하기
$sums[$counter] += $controller_amount; // 매립 연동제어기 가격 합산
}
// 노출 연동제어기 가격 계산
$price2 = calculateControllerSpec($column['col16'], $itemList, '노출형');
if($price2 > 0 && !empty($column['col16']))
{
$price_controller += $price2;
$controller_amount += $price2 * intval($column['col16']); // 노출형 개수 곱하기
$sums[$counter] += $controller_amount; // 노출 연동제어기 가격 합산
}
// 뒷박스 계산
$backbox_price = 0;
$backbox_price = calculateControllerSpec($column['col17'], $itemList, '뒷박스');
if($backbox_price > 0 && !empty($column['col17']))
{
$price_controller += $backbox_price;
$controller_amount += $backbox_price;
$sums[$counter] += $controller_amount;
}
}
// 모터 받침용 앵글 가계
$tablename = 'price_angle';
$query = "SELECT itemList FROM {$DB}.$tablename where is_deleted IS NULL or is_deleted = 0 ORDER BY NUM LIMIT 1";
$stmt = $pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$itemList = json_decode($row['itemList'], true);
// 스크린용 앵글 가격가져오기
$price_bottomangle = calculateAngle($column['col14'], $itemList, '스크린용'); // 수량, 리스트, 스크린용
// print_r($itemList );
// print_r($price_bottomangle );
// 4인치 3T (스크린용) 철재는 4T
$mainangle_price = calculateMainAngle($column['col14'], $itemList, '앵글3T' , '2.5' );
$mainangle_surang = intval(str_replace(',', '', $column['col71'])); // 앵글 수량
// BOM에서 제품코드별로 가져와야 합니다.
$tablename = 'bendingfee';
$query = "SELECT * FROM {$DB}.$tablename WHERE is_deleted IS NULL OR is_deleted = 0 ORDER BY NUM";
$stmt = $pdo->prepare($query);
$stmt->execute();
// echo '<pre>';
// print_r($guidrail_price);
// echo '</pre>';
// 케이스 크기
if ($column['col36'] === 'custom') {
$dimension = $column['col36_custom']; // 사용자 제작 사이즈
} else {
$dimension = $column['col36']; // 케이스 500*380
}
// echo '<pre>';
// print_r($dimension);
// echo '</pre>';
// 단가 계산
if (array_key_exists($dimension, $shutterBoxprices)) {
$price = ($shutterBoxprices[$dimension] / 1000) ;
} else {
$price = 0; // 조건이 맞지 않는 경우 0으로 설정
}
// $data 배열에 행을 추가합니다.
$data[] = $row;
$rowCount = 1;
// 디버그모드 설정
$debug = true;
$debug = false;
// 일련번호, 검사비
$subtotal += $inspectionFee * $su;
if($debug)print_r($subtotal . '<br>') ;
// calculation-row 클래스와 일련번호(serial)를 가진 tr 태그 추가
if($inspectionFee > 0 )
{
echo '<tr class="calculation-row" data-serial="' . $counter . '">'; // 검사비가 포함되어야 하면 data-serial="' . $counter . '">';로 선언해야 한다.
echo '<td class="text-center" id="dynamicRowspan-' . $counter . '">' . ($counter+1) . '</td>';
echo '<td class="text-center"> 검사비 </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 및 기타 필드
echo '<td class="text-center"> SET </td>';
// 산출식 입력 필드 (예: 수량 * 단가 등으로 계산하는 필드)
echo '<td class="text-center"><input type="text" class="text-left noborder-input calc-formula" value="" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 길이(㎜) 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-center area-length-input length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 면적(㎡) 길이(㎜) 단가 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-center area-price-input number-input" value="" data-row="' . $counter . '" data-type="area_price" oninput="inputNumber(this)" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" class="noborder-input text-end unit-price-input number-input" value="' . number_format($inspectionFee) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format($inspectionFee * $su) . '</td>';
echo '</tr>';
$rowCount++;
}
// 주자재(스크린) 가격
$screen_price = round(floatval($price_raw_materials * round($area,2)) );
$subtotal += $screen_price * $su;
if($debug)print_r($subtotal . '<br>') ;
if($screen_price > 0 )
{
if($inspectionFee < 1) { // 검사비가 없을때 1열을 만들어줘야 한다
echo '<tr class="calculation-row" data-serial="' . $counter . '">'; // 검사비가 포함되어야 하면 data-serial="' . $counter . '">';로 선언해야 한다.
echo '<td class="text-center" id="dynamicRowspan-' . $counter . '">' . ($counter+1) . '</td>';
echo '<td class="text-center">주자재(스크린) </td>';
}
else {
// calculation-row 클래스와 일련번호(serial)를 가진 tr 태그 추가
echo '<tr class="calculation-row" data-serial="' . $counter . '">'; // 검사비가 포함되어야 하면 data-serial="' . $counter . '">';로 선언해야 한다.
echo '<td class="text-center">주자재(스크린)</td>';
}
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 및 기타 필드
echo '<td class="text-center"> SET </td>';
// 산출식 입력 필드 (예: 수량 * 단가 등으로 계산하는 필드)
echo '<td class="text-center"><input type="text" class="text-left noborder-input calc-formula" value="" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드
echo '<td class="text-center"><input type="text" name="area-length-input[]" class="noborder-input text-center area-length-input length-input number-input" value="' . number_format($area, 2) . '" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="' . number_format($price_raw_materials) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 스크린 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($screen_price) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format($screen_price * $su) . '</td>';
echo '</tr>';
$rowCount++;
}
// 모터
$subtotal += $motorUnit_price * $su;
if($debug)print_r($subtotal . '<br>') ;
if ($motorUnit_price > 0) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center">모터</td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input이 아님)
echo '<td class="text-center">SET</td>';
// 산출식 입력 필드 (예: 수량 * 단가 등으로 계산하는 필드)
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="' . $motorSpec . 'KG" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드 (없으면 빈 입력)
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 모터 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($motorUnit_price) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format($motorUnit_price * $su) . '</td>';
echo '</tr>';
$rowCount++;
}
// 연동제어기
$controller_price = $price_controller;
// 매립,노출/뒷박스 수중 가장 큰 수를 표시함
$controller_su = max(intval($column['col15']), intval($column['col16']),intval($column['col17']));
$subtotal += round($controller_price) * $controller_su;
if($debug)print_r($subtotal . '<br>') ;
if ($controller_price > 0 ) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
// 뒷박스 유무에 따라 다른 문장 출력
if($backbox_price > 0) {
echo '<td class="text-center item-name">매립/노출 연동제어기(뒷박스 포함)</td>';
}
else {
echo '<td class="text-center item-name">매립/노출 연동제어기</td>';
}
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($controller_su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input이 아님)
echo '<td class="text-center">SET</td>';
// 산출식 입력 필드 (예: 수량 * 단가 등으로 계산하는 필드)
echo '<td class="text-center"><input type="text" class="noborder-input text-left calc-formula" value="" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드 (없으면 빈 입력)
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 연동제어기 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($controller_price) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format($controller_amount ) . '</td>';
echo '</tr>';
$rowCount++;
}
// 케이스
if ($column['col36'] === 'custom') {
$shutterBox = $column['col36_custom']; // 사용자 제작 사이즈
} else {
$shutterBox = $column['col36']; // 케이스 500*380
}
$shutter_price = round($shutterBoxprices[$shutterBox],2);
$basicbox_price = round($shutterBoxprices['500*380'],2); // 기본 500*380 가격;
list($boxwidth, $boxheight) = explode('*', $shutterBox);
// echo '<br>';
// echo '<pre>';
// print_r($shutterBoxprices);
// echo '</pre>';
if ($shutter_price < 1 && $steel == '1') { // 절곡체크가 되었을때
$basicbox_pricePermeter = $basicbox_price/(500*380/1000);
$shutter_price = $basicbox_pricePermeter * floatval($boxwidth) * floatval($boxheight) / 1000;
if($basicbox_price>$shutter_price )
$shutter_price = $basicbox_price ;
$shutterboxMsg = $shutterBox . ' 케이스 크기 정의 없음, m당 기본사이즈 500*380 가격 (크기가 작아도 최소가격은 표준가격임) : ' . number_format($basicbox_price) . '(원)' ;
$shutterboxMsg .= ' m당 단가 : ' . number_format($basicbox_pricePermeter) . '(원)' ;
$shutterboxMsg .= ' m단위로 설정된 단가 : ' . number_format($shutter_price) . '(원)' ;
// echo $shutterBox . ' 케이스 크기에 대한 단가가 정의되지 않았습니다. 단가를 생성해주세요. [절곡BOM] 메뉴 이용! <br> '. ' 1m당 기본사이즈 500*380 가격 : ' . number_format($basicbox_price) . '(원)' ;
// echo '<br> m당 단가 : ' . number_format($basicbox_pricePermeter) . '(원)' ;
// echo '<br> m단위로 설정된 단가 : ' . number_format($shutter_price) . '(원)' ;
}
$total_length = round(floatval($column['col37']) / 1000,2);
// print_r($total_length);
// echo '<br>';
// print_r($shutter_price * $total_length);
$subtotal += round($shutter_price * $total_length);
if($debug)print_r($subtotal . '<br>') ;
if($total_length > 0 && $steel == '1') {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center">케이스</td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input이 아님)
echo '<td class="text-center">SET</td>';
// 산출식 입력 필드 (예: 수량 * 단가 등으로 계산하는 필드)
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="' . $dimension . '" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드
echo '<td class="text-center"><input type="text" name="area-length-input[]" class="noborder-input text-center area-length-input number-input" value="' . number_format($total_length, 2) . '" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="' . number_format($shutter_price) . '" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 케이스 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($shutter_price * $total_length) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format($shutter_price * $total_length) . '</td>';
echo '</tr>';
$rowCount++;
}
// 케이스 연기차단재 1식으로 표현함 수량과 관계없이 연산해야 함.
// $total_ea = intval($column['col47']);
// $total_length = round(floatval($column['col37']) / 1000, 2);
// $subtotal += round($boxSmokeBanPrices * $total_length);
if($debug)print_r($subtotal . '<br>') ;
if($total_length > 0 && $steel == '1') {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center">케이스용 연기차단재</td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center"> 식 </td>';
// 산출식 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="W80" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드
echo '<td class="text-center"><input type="text" name="area-length-input[]" class="noborder-input text-center area-length-input number-input" value="' . number_format($total_length , 2) . '" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="' . number_format($boxSmokeBanPrices) . '" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($boxSmokeBanPrices ) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format($boxSmokeBanPrices * $total_length ) . '</td>';
echo '</tr>';
$rowCount++;
}
//마구리
$subtotal += round($maguriPrices * $su);
if($maguriPrices > 0 && $steel == '1')
{
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center">케이스 마구리</td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center">SET</td>';
// 산출식 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="' . $column['col45'] . '" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드
echo '<td class="text-center"><input type="text" name="area-length-input[]" class="noborder-input text-center area-length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($maguriPrices) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($maguriPrices * $su)) . '</td>';
echo '</tr>';
$rowCount++;
}
// 모터 받침용 앵글
$angle_price = $price_bottomangle;
$subtotal += round($angle_price * $su * 4);
if($angle_price > 0 && !empty($column['col22']) && !($slatcheck === '1' && $motor !== '1' && $steel !== '1' && $partscheck !== '1'))
{
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center">모터 받침용 앵글</td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su * 4) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (EA는 input에서 제외)
echo '<td class="text-center">EA</td>';
// 산출식 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="' . $column['col22'] . '" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드 (빈 값)
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($angle_price) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($angle_price * $su * 4)) . '</td>';
echo '</tr>';
$rowCount++;
}
// 가이드레일
// 혼합형이 아니면 1SET는 *2를 적용 혼합형은 예외임 단가는 이미 2개를 1세트로 단가표가 구성되어 있으니 유의할 것 절곡BOM참조
$total_length = round(floatval($column['col23']) / 1000,2);
$subtotal += round($guidrail_price * $total_length * $su);
// print_r($guidrail_price * $total_length);
if ($total_length > 0 && strpos($column['col6'], '없음') === false) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center"> 가이드레일 </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center"> SET </td>';
// 산출식 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="' . $column['col6'] . ' ' . $column['col7'] . '" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="' . number_format($total_length, 2) . '" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드 (빈 값)
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($guidrail_price) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($guidrail_price * $total_length)) . '</td>';
echo '</tr>';
$rowCount++;
}
//가이드레일용 연기차단재 레일 높이 + 250 적용해서 만드는 것임
//가이드레일용 연기차단재 레일 높이 + 250 적용해서 만드는 것임
$total_length = floatval($column['col23']) / 1000 ;
$guiderailSmokeBanPricesTotal = round($guiderailSmokeBanPrices * $total_length ) * 2 * $su; // 결과값에 수량 곱하기 실제 컬럼은 5개로 나오는데, 계산과정을 담기위해 $su 곱하기 공식으로 사용한다.
$subtotal += $guiderailSmokeBanPricesTotal ;
if ($total_length > 0 && (!empty($column['col24']) || !empty($column['col25']) || !empty($column['col26']) || !empty($column['col27']) || !empty($column['col28']))) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center"> 레일용 연기차단재 </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su * 2) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center"> SET </td>';
// 산출식 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="W50" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="' . number_format($total_length , 2) . '" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드 (빈 값)
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="' . number_format($guiderailSmokeBanPrices) . '" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($guiderailSmokeBanPricesTotal / ($su * 2)) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format($guiderailSmokeBanPricesTotal) . '</td>';
echo '</tr>';
$rowCount++;
}
// 하단마감재(하장바)
$total_length = intval($column['col48']) ;
$total_length = $total_length / 1000;
$subtotal += round($bottomBarPrices * $total_length * $su);
if ($total_length > 0 && (!empty($column['col49']) || !empty($column['col50'])) ) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center"> 하장바 </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center"> SET </td>';
// 산출식 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="'. $column['col7'] . '" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="' . number_format($total_length, 2) . '" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드 (빈 값)
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($bottomBarPrices) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round(($bottomBarPrices * $total_length))) . '</td>';
echo '</tr>';
$rowCount++;
}
// 하단마감재(L바)
// 혼합형이 아니면 1SET는 *2를 적용
$total_length = intval($column['col51']) ; // 2개가 1SET , 하지만 단가가 2개가 1세트로 계산된 단가임 주의요함
$total_length = $total_length / 1000;
$subtotal += round($LBarPrices * $total_length * $su);
if ($total_length > 0 && (!empty($column['col52']) || !empty($column['col53'])) ) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center"> L바 </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center"> SET </td>';
// 산출식 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="2개가 1SET 단가로 적용" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="' . number_format($total_length, 2) . '" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드 (빈 값)
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($LBarPrices) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($LBarPrices * $total_length)) . '</td>';
echo '</tr>';
$rowCount++;
}
// 하단마감재(보강평철)
// 조건에 따른 가격 계산
$total_length = intval($column['col54']) ;
$total_length = $total_length / 1000;
$subtotal += round($bottomPlatePrices * $total_length * $su);
if ($total_length > 0 && (!empty($column['col55']) || !empty($column['col56'])) ) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center"> 보강평철 </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center"> SET </td>';
// 산출식 입력 필드
echo '<td class="text-center"><input type="text" class="noborder-input text-end calc-formula" value="2000" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 입력 필드
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="' . number_format($total_length, 2) . '" data-row="' . $counter . '" data-type="area_length" oninput="inputNumber(this)" /></td>';
// 원자재 단가 입력 필드 (빈 값)
echo '<td class="text-end"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" oninput="inputNumber(this)" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($bottomPlatePrices) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($bottomPlatePrices * $total_length * $su)) . '</td>';
echo '</tr>';
$rowCount++;
}
// 감기샤프트
$tablename = 'price_shaft';
$query = "SELECT itemList FROM {$DB}.$tablename WHERE is_deleted IS NULL OR is_deleted = 0 ORDER BY NUM LIMIT 1";
$stmt = $pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$itemList = json_decode($row['itemList'], true);
$sum_shaft_price = 0;
$shaft_counts = []; // 각 사이즈별 카운트를 저장할 배열
// 각각의 샤프트 계산
addShaftPrice($column['col59'], $itemList, '3', '300', $sum_shaft_price, $shaft_counts);
addShaftPrice($column['col60'], $itemList, '4', '3000', $sum_shaft_price, $shaft_counts);
addShaftPrice($column['col61'], $itemList, '4', '4500', $sum_shaft_price, $shaft_counts);
addShaftPrice($column['col62'], $itemList, '4', '6000', $sum_shaft_price, $shaft_counts);
addShaftPrice($column['col63'], $itemList, '5', '6000', $sum_shaft_price, $shaft_counts);
addShaftPrice($column['col64'], $itemList, '5', '7000', $sum_shaft_price, $shaft_counts);
addShaftPrice($column['col65'], $itemList, '5', '8200', $sum_shaft_price, $shaft_counts);
// 샤프트 수량을 텍스트로 변환
$shaft_count_text = [];
foreach ($shaft_counts as $length => $count) {
$countstr = $count * $su;
$shaft_count_text[] = "{$length}x{$countstr}EA";
}
$shaft_count_text = implode(', ', $shaft_count_text);
$subtotal += round($sum_shaft_price);
if ($sum_shaft_price > 0 ) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center"> 감기샤프트 </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($su) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center"> 식 </td>';
// 산출식 입력 필드 (샤프트 수량 텍스트)
echo '<td class="text-end"><input type="text" class="noborder-input text-end calc-formula" value="' . $shaft_count_text . '" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" /></td>';
// 원자재 단가 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format(round($sum_shaft_price/$su)) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($sum_shaft_price)) . '</td>';
echo '</tr>';
$rowCount++;
}
// 무게평철12T (2000)
// 무게평철 기준 단가 (2000mm당 12000원)
$basePrice = 12000;
$size = intval(str_replace(',', '', $column['col8'])) * 2; // 스크린 길이 * 2
$itemsep = (substr($column['col4'], 0, 2) === 'KS' || substr($column['col4'], 0, 2) === 'KW') ? '스크린' : '철재';
// 단계별 가격 계산 및 수량 저장을 위한 배열
$weight_plate_counts = [];
$priceFactor = intval($column['col57']); // 무게평철 수량
// // 스크린 하단 무게평철의 단계별 가격 계산 및 수량 저장
// if ($itemsep == '스크린') {
// if ($size <= 2000) {
// $priceFactor = 1;
// } elseif ($size <= 4000) {
// $priceFactor = 2;
// } elseif ($size <= 6000) {
// $priceFactor = 3;
// } elseif ($size <= 8000) {
// $priceFactor = 4;
// } elseif ($size <= 10000) {
// $priceFactor = 5;
// } elseif ($size <= 12000) {
// $priceFactor = 6;
// } elseif ($size <= 14000) {
// $priceFactor = 7;
// } elseif ($size <= 16000) {
// $priceFactor = 8;
// } elseif ($size <= 18000) {
// $priceFactor = 9;
// } elseif ($size <= 20000) {
// $priceFactor = 10;
// }
// $priceFactor *= $su;
// // 단계별 개수 저장
// if ($priceFactor > 0) {
// $weight_plate_counts[2000] = $priceFactor ; // 2000, 2000 x 1, ...,형식으로 저장
// }
// }
$weight_plate_counts[2000] = $priceFactor ;
// 최종 단가 계산
$weight_plate_price = $basePrice * $priceFactor;
// 무게평철 수량을 텍스트로 변환
$weight_plate_count_text = [];
foreach ($weight_plate_counts as $length => $count) {
$weight_plate_count_text[] = "{$length}x{$count}EA";
}
$weight_plate_count_text = implode(', ', $weight_plate_count_text);
$total_length = intval(str_replace(',', '', $column['col57']));
$subtotal += round($weight_plate_price);
if ($weight_plate_price > 0) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
// 항목 이름
echo '<td class="text-center"> 무게평철12T (2000) </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($total_length) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center"> EA </td>';
// 산출식 입력 필드 (무게평철 수량 텍스트)
echo '<td class="text-end"><input type="text" class="noborder-input text-end calc-formula" value="' . $weight_plate_count_text . '" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" /></td>';
// 원자재 단가 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format(round($weight_plate_price / $total_length)) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($weight_plate_price)) . '</td>';
echo '</tr>';
$rowCount++;
}
// 환봉(3000) 기준 단가 (3000mm당 2000원)
$round_bar_price = 2000;
$round_bar_surang = intval(str_replace(',', '', $column['col70']));
// 3000mm 길이의 환봉 개수 저장
$round_bar_counts = [];
if ($round_bar_surang > 0) {
$round_bar_counts[3000] = $round_bar_surang;
}
// 환봉 수량을 텍스트로 변환
$round_bar_count_text = [];
foreach ($round_bar_counts as $length => $count) {
$round_bar_count_text[] = "{$length}x{$count}EA";
}
$round_bar_count_text = implode(', ', $round_bar_count_text);
if ($round_bar_surang < 1) {
$round_bar_price = 0;
}
$subtotal += round($round_bar_price * $round_bar_surang);
if ($round_bar_surang > 0) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
// 항목 이름
echo '<td class="text-center"> 환봉(3000) </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($round_bar_surang) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (SET은 input에서 제외)
echo '<td class="text-center"> EA </td>';
// 산출식 입력 필드 (환봉 수량 텍스트)
echo '<td class="text-end"><input type="text" class="noborder-input text-end calc-formula" value="' . $round_bar_count_text . '" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" /></td>';
// 원자재 단가 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($round_bar_price) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($round_bar_price * $round_bar_surang)) . '</td>';
echo '</tr>';
$rowCount++;
}
// 각파이프 3000/6000 계산 (중복 제거, 한 번만 합산/출력)
$tablename = 'price_pipe';
$query = "SELECT itemList FROM {$DB}.$tablename WHERE is_deleted IS NULL OR is_deleted = 0 ORDER BY NUM LIMIT 1";
$stmt = $pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$itemList = json_decode($row['itemList'], true);
$pipe_price_3000 = calculatePipe($itemList, '1.4', '3000');
$pipe_price_6000 = calculatePipe($itemList, '1.4', '6000');
$pipe_price_3000_surang = intval(str_replace(',', '', $column['col68']));
$pipe_price_6000_surang = intval(str_replace(',', '', $column['col69']));
// 합산 및 출력은 한 번만!
$subtotal += round($pipe_price_3000 * $pipe_price_3000_surang + $pipe_price_6000 * $pipe_price_6000_surang);
if ($pipe_price_3000_surang > 0) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center"> 각파이프(3000) </td>';
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($pipe_price_3000_surang) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
echo '<td class="text-center"> EA </td>';
echo '<td class="text-end"><input type="text" class="noborder-input text-end calc-formula" value="3000x' . $pipe_price_3000_surang . 'EA" data-row="' . $counter . '" data-type="formula" /></td>';
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" /></td>';
echo '<td class="text-center"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" /></td>';
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($pipe_price_3000) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($pipe_price_3000 * $pipe_price_3000_surang)) . '</td>';
echo '</tr>';
$rowCount++;
}
if ($pipe_price_6000_surang > 0) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
echo '<td class="text-center"> 각파이프(6000) </td>';
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($pipe_price_6000_surang) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
echo '<td class="text-center"> EA </td>';
echo '<td class="text-end"><input type="text" class="noborder-input text-end calc-formula" value="6000x' . $pipe_price_6000_surang . 'EA" data-row="' . $counter . '" data-type="formula" /></td>';
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" /></td>';
echo '<td class="text-center"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" /></td>';
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format($pipe_price_6000) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($pipe_price_6000 * $pipe_price_6000_surang)) . '</td>';
echo '</tr>';
$rowCount++;
}
$tablename = 'price_angle';
$query = "SELECT itemList FROM {$DB}.$tablename WHERE is_deleted IS NULL OR is_deleted = 0 ORDER BY NUM LIMIT 1";
$stmt = $pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$itemList = json_decode($row['itemList'], true);
// 4인치 3T (스크린용), 철재는 4T
$mainangle_price = calculateMainAngle(1, $itemList, '앵글3T', '2.5');
$mainangle_surang = intval(str_replace(',', '', $column['col71'])); // 수량
// 앵글 수량을 텍스트로 변환
$angle_counts = [];
if ($mainangle_surang > 0) {
$angle_counts[] = "2500x{$mainangle_surang}EA";
}
$angle_count_text = implode(', ', $angle_counts);
if ($mainangle_surang < 1) {
$mainangle_price = 0;
}
// 앵글
$subtotal += round($mainangle_price * $mainangle_surang);
if ($mainangle_surang > 0) {
echo '<tr class="calculation-row" data-serial="' . $counter . '">';
// 항목 이름
echo '<td class="text-center"> 앵글3T (2500) </td>';
// 수량 입력 필드
echo '<td class="text-center"><input type="text" name="su[]" class="noborder-input text-center su-input number-input" value="' . number_format($mainangle_surang) . '" data-row="' . $counter . '" data-type="su" oninput="inputNumber(this)" /></td>';
// 단위 필드 (EA)
echo '<td class="text-center"> EA </td>';
// 산출식 입력 필드 (앵글 수량 텍스트)
echo '<td class="text-end"><input type="text" class="noborder-input text-end calc-formula" value="' . $angle_count_text . '" data-row="' . $counter . '" data-type="formula" /></td>';
// 면적(㎡) 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="length[]" class="noborder-input text-center area-length-input length-input number-input" value="" data-row="' . $counter . '" data-type="area_length" /></td>';
// 원자재 단가 필드 (빈 값)
echo '<td class="text-center"><input type="text" name="area-price-input[]" class="noborder-input text-end area-price-input number-input" value="" data-row="' . $counter . '" data-type="raw_materials_price" /></td>';
// 단가 입력 필드
echo '<td class="text-end"><input type="text" name="unit-price-input[]" class="noborder-input text-end unit-price-input number-input" value="' . number_format(round($mainangle_price)) . '" data-row="' . $counter . '" data-type="unit_price" oninput="inputNumber(this)" /></td>';
// 합계 필드 (자동 계산, 입력 불가)
echo '<td class="text-end total-price" id="total-price-' . $counter . '">' . number_format(round($mainangle_price * $mainangle_surang)) . '</td>';
echo '</tr>';
$rowCount++;
}
echo '<tr data-serial="' . $counter . '" class="subtotal-row">';
echo '<td class="text-center" colspan="7"><strong>소계</strong></td>';
echo '<td class="text-end fw-bold subtotal-cell" data-serial="' . $counter . '"> </td>';
echo '</tr>';
array_push($subtotal_array, round($subtotal,2)) ;
array_push($subtotal_surang_array, $su) ;
array_push($row_array, $rowCount) ; // 행 합치기를 위한 행수
// 전체 합계에 소계를 더함
$total_sum += round($subtotal);
// 디버그용 출력
// echo 'subtotal '. $subtotal .'<br>';
// echo 'total_sum '. $total_sum .'<br>';
$rowCount++;
}
$counter++ ; // 전체 행카운트
}
echo '</tbody>';
echo '<tfoot>';
echo '<tr class="grand-total-row">';
echo '<td class="text-center lightgray" colspan="8"><strong>전체 합계</strong></td>';
echo '<td class="text-end lightgray fw-bold grand-total"> </td>';
echo '</tr>';
echo '</tfoot>';
echo '</table>';
echo '</div>';
echo '</div>';
$row_array_json = json_encode($row_array);
$korean_total_sum = number_to_korean(round($total_sum));
// echo 'korean total sum '. $korean_total_sum .'';
// PHP 배열을 JSON으로 변환
$subtotal_json = json_encode($subtotal_array);
$subtotal_surang_json = json_encode($subtotal_surang_array);
// 세부내역서 ####################################################################################
// 세부내역서 ####################################################################################
// 세부내역서 ####################################################################################
// 업체발송용에서는 2.1은 나오게 해야 한다.
if (True)
{
$data = [];
$counter = 0;
foreach ($decodedEstimateList as $item) {
if (isset($item['col5']) && !empty($item['col5'])) {
$counter++;
// 각 col 값을 배열에 추가합니다.
$row = [];
$row['col1'] = '2.1 <br> 본체(스크린)';
$row['col2'] = $item['col3'] ?? ''; // 부호
$row['col3'] = $item['col5'] ?? ''; // 실리카
if($steel ==='1') {
$row['col4'] = $item['col7'] ?? ''; // SUS
$row['col5'] = $item['col7'] ?? ''; // SUS
}
else {
$row['col4'] = '';
$row['col5'] = '';
}
$row['col6'] = $item['col8']; // 오픈 가로
$row['col7'] = $item['col9']; // 오픈 세로
$row['col8'] = $item['col10']; // 제작 가로
$row['col9'] = $item['col11']; // 제작 세로
$row['col10'] = $item['col14']; // 수량
if ($item['col36'] === 'custom') {
$row['col11'] = $item['col36_custom']; // 사용자 제작 사이즈
} else {
$row['col11'] = $item['col36']; // 케이스 500*380
}
// $data 배열에 행을 추가합니다.
$data[] = $row;
}
}
echo '<br>';
echo '<div class=" d-flex align-items-center justify-content-center listview">';
echo '<h3 class="listview vendor-send mb-2"> 소요자재 내역 </h3> ';
echo '</div>';
echo '<div class="d-flex align-items-center justify-content-center listview vendor-send">';
echo '<table class="table avoid-break vendor-send" style="border-collapse: collapse;">';
echo '<thead>';
echo '<tr>';
echo '<th rowspan="2" class="text-center">구분</th>';
echo '<th rowspan="2" class="text-center">부호</th>';
echo '<th rowspan="2" class="text-center">종류</th>';
echo '<th colspan="2" class="text-center">가이드레일</th>';
echo '<th colspan="2" class="text-center">오픈사이즈</th>';
echo '<th colspan="2" class="text-center yellowredBold">제작사이즈</th>';
echo '<th rowspan="2" class="text-center ">수량</th>';
echo '<th rowspan="2" class="text-center blueBold ">케이스</th>';
echo '</tr>';
echo '<tr>';
echo '<th class="text-center">마감유형</th>';
echo '<th class="text-center">설치유형</th>';
echo '<th class="text-center">가로</th>';
echo '<th class="text-center">세로</th>';
echo '<th class="text-center yellowredBold">가로</th>';
echo '<th class="text-center yellowredBold">세로</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
$col7_sum = 0; // col7 합계
$col10_sum = 0; // col10 합계
$col89_sum = 0; // col8 + col9 합계
$rowspan_applied = false; // rowspan이 적용되었는지 확인하는 플래그
$row_count = count($data); // 총 행 수
foreach ($data as $row) {
echo '<tr>';
// 첫 번째 열에만 rowspan 적용
if (!$rowspan_applied) {
echo '<td class="text-center fw-bold" rowspan="' . $row_count . '">' . $row['col1'] . '</td>';
$rowspan_applied = true;
}
// 나머지 열 출력 (색상을 부여하는 코드)
for ($i = 2; $i <= 11; $i++) { // col1은 이미 출력했으므로 col2부터 시작
switch ($i) {
case 9:
case 8:
// col3에 yellowBold 클래스를 적용하여 출력
echo '<td class="text-center text-primary yellowBold">' . htmlspecialchars($row['col' . $i]) . '</td>';
break;
case 11:
// col5에 blueBold 클래스를 적용하여 출력
echo '<td class="text-center text-primary greenredBold">' . htmlspecialchars($row['col' . $i]) . '</td>';
break;
default:
// 기본적으로 fw-bold 클래스를 적용하여 출력
echo '<td class="text-center text-primary fw-bold">' . htmlspecialchars($row['col' . $i]) . '</td>';
break;
}
}
// 쉼표를 제거하고 숫자형으로 변환하여 합계 계산
$col7_sum += floatval(str_replace(',', '', $row['col7']));
$col10_sum += floatval(str_replace(',', '', $row['col10']));
$col89_sum += floatval(str_replace(',', '', $row['col8'])) + floatval(str_replace(',', '', $row['col9']));
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
echo '</div>';
}
// 모터 부분
if ($motorUnit_price > 0 || $price_controller > 0 || $price_bottomangle > 0) {
// 함수 호출을 통해 계산된 값을 가져옴
$specifications = calculateMotorSpecifications($decodedEstimateList);
// echo '<pre>';
// print_r($specifications);
// echo '</pre>';
// 초기화
$col1_sum = $col2_sum = $col3_sum = $col4_sum = $col5_sum = $col6_sum = 0;
$col7_sum = $col8_sum = $col9_sum = $col10_sum = $col11_sum = $col12_sum = 0;
$motor_supplier = $column['col18_brand'];
if ($motor_supplier === '경동(견적가포함)' || $motor_supplier === '대한') {
// 각 합계 값을 변수에 저장
$col1_sum = $specifications['col1_sum'];
$col2_sum = $specifications['col2_sum'];
$col3_sum = $specifications['col3_sum'];
$col4_sum = $specifications['col4_sum'];
$col5_sum = $specifications['col5_sum'];
$col6_sum = $specifications['col6_sum'];
$col7_sum = $specifications['col7_sum'];
$col8_sum = $specifications['col8_sum'];
$col9_sum = $specifications['col9_sum'];
$col10_sum = $specifications['col10_sum'];
$col11_sum = $specifications['col11_sum'];
}
if($motor == '1') { // 모터체크박스
$col12_sum = $specifications['col12_sum'];
}
else {
$col12_sum = 0;
}
echo ' <div class="d-flex align-items-center justify-content-center listview" >';
echo '<table class="table avoid-break Novendor-send" style="border-collapse: collapse;">';
echo '<thead>';
echo '<tr>';
echo '<th rowspan="3" class="text-center"> 2.2 <br> 모터 </th>';
echo '<th colspan="7" class="text-center"> 모터종류(KG)</th>';
echo '<th colspan="3" class="text-center"> 연동제어기 </th>';
echo '<th class="text-center">브라켓트</th>';
echo '<th class="text-center">앵글</th>';
echo '</tr>';
echo '<tr>';
echo '<th class="text-center">150</th>';
echo '<th class="text-center">300</th>';
echo '<th class="text-center">400</th>';
echo '<th class="text-center">500</th>';
echo '<th class="text-center">600</th>';
echo '<th class="text-center">800</th>';
echo '<th class="text-center">1000</th>';
echo '<th class="text-center">매립</th>';
echo '<th class="text-center">노출</th>';
echo '<th class="text-center">뒷박스</th>';
echo '<th class="text-center">수량</th>';
echo '<th class="text-center">수량</th>';
echo '</tr>';
echo '<tr>';
echo '<th class="text-center text-primary fw-bold">' . ($col1_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col2_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col3_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col4_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col5_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col6_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col7_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col8_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col9_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col10_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col11_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($col12_sum ?: '') . '</th>';
echo '</tr>';
echo '</thead>';
echo '</table>';
echo '</div>';
}
// 절곡 부분
if (True) {
$data = [];
// 누적 합계를 저장할 변수들
$row3_1_sum = 0;
$row3_2_sum = 0;
$row3_3_sum = 0;
$row3_4_sum = 0;
$row3_5_sum = 0;
// 누적 합계를 저장할 변수들
$row5_1_sum = 0;
$row5_2_sum = 0;
$row5_3_sum = 0;
$row5_4_sum = 0;
$row5_5_sum = 0;
$row5_6_sum = 0;
$row5_7_sum = 0; // col39의 합
$row5_8_sum = 0; // col41의 합
$row7_1_sum = 0; // 하단마감재
$row7_2_sum = 0; //
$row7_3_sum = 0; //
$row8_1_sum = 0; // 하단마감재
$row8_2_sum = 0; //
$row8_3_sum = 0; //
$row10_1_sum = 0;
$row10_2_sum = 0;
$row10_3_sum = 0;
$row10_4_sum = 0;
$row10_5_sum = 0;
$row10_6_sum = 0;
foreach ($decodedEstimateList as $item) {
$ValidLength = floatval($item['col23'] ?? 0); // 가이드레일의 제작 길이
$surang = floatval($item['col14'] ?? 0); // 수량
// 가이드레일
$row3_1_sum += floatval($item['col24'] ?? 0);
$row3_2_sum += floatval($item['col25'] ?? 0);
$row3_3_sum += floatval($item['col26'] ?? 0);
$row3_4_sum += floatval($item['col27'] ?? 0);
$row3_5_sum += floatval($item['col28'] ?? 0);
// 케이스
$row5_1_sum += floatval($item['col38'] ?? 0);
$row5_2_sum += floatval($item['col39'] ?? 0);
$row5_3_sum += floatval($item['col40'] ?? 0);
$row5_4_sum += floatval($item['col41'] ?? 0);
$row5_5_sum += floatval($item['col42'] ?? 0);
$row5_6_sum += floatval($item['col43'] ?? 0);
// 5열 7행 상부덮개, 마구리
$row5_7_sum += floatval($item['col44'] ?? 0);
$row5_8_sum += floatval($item['col46'] ?? 0);
// 레일용 연기차단재 / 케이스용 연기차단재
$row10_1_sum += floatval($item['col31'] ?? 0);
$row10_2_sum += floatval($item['col32'] ?? 0);
$row10_3_sum += floatval($item['col33'] ?? 0);
$row10_4_sum += floatval($item['col34'] ?? 0);
$row10_5_sum += floatval($item['col35'] ?? 0);
$row10_6_sum += floatval($item['col47'] ?? 0);
// 추가 항목들
$row7_1_sum += floatval($item['col49'] ?? 0); // 하단마감재 3000
$row8_1_sum += floatval($item['col50'] ?? 0); // 하단마감재 4000
$row7_2_sum += floatval($item['col52'] ?? 0); // 엘바 3000
$row8_2_sum += floatval($item['col53'] ?? 0); // 엘바 4000
$row7_3_sum += floatval($item['col55'] ?? 0); // 하단마감재 보강평철 3000
$row8_3_sum += floatval($item['col56'] ?? 0); // 하단마감재 보강평철 4000
}
// 테이블 출력
echo '<div class="d-flex align-items-center justify-content-center listview">';
echo '<table class="table avoid-break Novendor-send" style="border-collapse: collapse;">';
echo '<thead>';
echo '<tr>';
echo '<th rowspan="10" class="text-center"> 2.3 <br> 절곡 </th>';
echo '<th colspan="2" class="text-center"> (1) 가이드레일 <br> (EGI 1.6T/ SUS 1.2T) </th>';
echo '<th colspan="2" class="text-center"> (2) 케이스 <br> (EGI 1.6T) </th>';
echo '<th colspan="3" class="text-center"> (3) 하단마감재 <br> (SUS 1.2T) </th>';
echo '<th colspan="3" class="text-center"> (4) 연기차단재 </th>';
echo '</tr>';
echo '<tr>'; // 2행
echo '<th class="text-center">사이즈</th>';
echo '<th class="text-center">수량</th>';
echo '<th class="text-center">사이즈</th>';
echo '<th class="text-center">수량</th>';
echo '<th class="text-center">분류</th>';
echo '<th class="text-center">3000</th>';
echo '<th class="text-center">4000</th>';
echo '<th class="text-center">분류</th>';
echo '<th class="text-center">사이즈</th>';
echo '<th class="text-center">수량</th>';
echo '</tr>';
echo '<tr>'; // 3행
echo '<th class="text-center">2438</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row3_1_sum ?: '') . '</th>';
echo '<th class="text-center">1219</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row5_1_sum ?: '') . '</th>';
echo '<th rowspan="3" class="text-center"> 하단마감재 <br> (SUS 1.2T) </th>';
echo '<th rowspan="3" class="text-center text-primary fw-bold">' . ($row7_1_sum ?: '') . '</th>';
echo '<th rowspan="3" class="text-center text-primary fw-bold">' . ($row8_1_sum ?: '') . '</th>';
echo '<th rowspan="5" class="text-center">레일용</th>';
echo '<th rowspan="1" class="text-center text-dark fw-bold">2438 </th>';
echo '<th rowspan="1" class="text-center text-primary fw-bold">' . ($row10_1_sum ?: '') . '</th>';
echo '</tr>';
echo '<tr>'; // 4행
echo '<th class="text-center">3000</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row3_2_sum ?: '') . '</th>';
echo '<th class="text-center">2438</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row5_2_sum ?: '') . '</th>';
echo '<th rowspan="1" class="text-center text-dark fw-bold"> 3000 </th>';
echo '<th rowspan="1" class="text-center text-primary fw-bold">' . ($row10_2_sum ?: '') . '</th>';
echo '</tr>';
echo '<tr>'; // 5행
echo '<th class="text-center">3500</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row3_3_sum ?: '') . '</th>';
echo '<th class="text-center">3000</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row5_3_sum ?: '') . '</th>';
echo '<th rowspan="1" class="text-center text-dark fw-bold"> 3500 </th>';
echo '<th rowspan="1" class="text-center text-primary fw-bold">' . ($row10_3_sum ?: '') . '</th>';
echo '</tr>';
echo '<tr>'; // 6행
echo '<th class="text-center">4000</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row3_4_sum ?: '') . '</th>';
echo '<th class="text-center">3500</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row5_4_sum ?: '') . '</th>';
echo '<th rowspan="3" class="text-center"> 하단보강엘바 <br> (EGI 1.2T) </th>';
echo '<th rowspan="3" class="text-center text-primary fw-bold">' . ($row7_2_sum ?: '') . '</th>';
echo '<th rowspan="3" class="text-center text-primary fw-bold">' . ($row8_2_sum ?: '') . '</th>';
echo '<th rowspan="1" class="text-center text-dark fw-bold"> 4000 </th>';
echo '<th rowspan="1" class="text-center text-primary fw-bold">' . ($row10_4_sum ?: '') . '</th>';
echo '</tr>';
echo '<tr>'; // 7행
echo '<th class="text-center">4300</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row3_5_sum ?: '') . '</th>';
echo '<th class="text-center">4000</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row5_5_sum ?: '') . '</th>';
echo '<th rowspan="1" class="text-center text-dark fw-bold"> 4300 </th>';
echo '<th rowspan="1" class="text-center text-primary fw-bold">' . ($row10_5_sum ?: '') . '</th>';
echo '</tr>';
echo '<tr>'; // 8행
echo '<th class="text-center" rowspan="3" colspan="2" ></th>';
echo '<th class="text-center">4150</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row5_6_sum ?: '') . '</th>';
echo '<th rowspan="1" class="text-center">케이스용</th>';
echo '<th rowspan="1" class="text-center">3000</th>';
echo '<th rowspan="1" class="text-center text-primary fw-bold">' . ($row10_6_sum ?: '') . '</th>';
echo '</tr>';
echo '<tr>';
echo '<th class="text-center">상부덮개</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row5_7_sum ?: '') . '</th>';
echo '<th rowspan="2" class="text-center"> 하단보강평철 </th>';
echo '<th rowspan="2" class="text-center text-primary fw-bold">' . ($row7_3_sum ?: '') . '</th>';
echo '<th rowspan="2" class="text-center text-primary fw-bold">' . ($row8_3_sum ?: '') . '</th>';
echo '</tr>';
echo '<tr>';
echo '<th class="text-center">마구리</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row5_8_sum ?: '') . '</th>';
echo '</tr>';
echo '</thead>';
echo '</table>';
echo '</div>';
}
// 감기샤프트 및 부자재
if (true) {
// 초기화
$row2_4_sum = $row3_4_sum = $row4_4_sum = $row5_4_sum = $row6_4_sum = 0;
$row7_4_sum = $row8_4_sum = $row9_4_sum = $row10_4_sum = $row11_4_sum = 0;
$row12_4_sum = $row13_4_sum = $row2_7_sum = $row4_7_sum = $row5_7_sum = 0;
$row6_7_sum = $row7_7_sum = $row8_7_sum = 0;
$col59InchLengthSummary = [];
foreach ($decodedEstimateList as $item) {
// 감기샤프트 길이별 수량
$row4_4_sum += floatval($item['col60']);
$row5_4_sum += floatval($item['col61']);
$row6_4_sum += floatval($item['col62']);
$row7_4_sum += floatval($item['col63']);
$row8_4_sum += floatval($item['col64']);
$row9_4_sum += floatval($item['col65']);
$row2_7_sum += floatval($item['col57']);
$row4_7_sum += floatval($item['col70']);
$row6_7_sum += floatval($item['col68']);
$row7_7_sum += floatval($item['col69']);
$row8_7_sum += floatval($item['col71']);
// 보조 샤프트(2인치 등) 인치+길이 조합별 수량 누적
$inch = isset($item['col59_inch']) ? trim($item['col59_inch']) : '기타';
$length = isset($item['col59_length']) ? trim($item['col59_length']) : '미지정';
$qty = floatval($item['col59']);
$key = $inch . '_' . $length;
if (!isset($col59InchLengthSummary[$key])) $col59InchLengthSummary[$key] = 0;
$col59InchLengthSummary[$key] += $qty;
}
echo '<div class="d-flex align-items-center justify-content-center">';
echo '<table class="table avoid-break Novendor-send" style="border-collapse: collapse;">';
echo '<thead>';
// 1행 제목
echo '<tr>';
echo '<th rowspan="7" class="text-center"> 2.4 <br> 부자재 </th>';
echo '<th colspan="' . (count($col59InchLengthSummary) ?: 2) . '" class="text-center"> 감기샤프트 <br> (보조) </th>';
echo '<th colspan="12" class="text-center"> 감기샤프트 </th>';
echo '</tr>';
// 2행 (보조 인치)
echo '<tr>';
foreach ($col59InchLengthSummary as $key => $qty) {
[$inch, $length] = explode('_', $key);
echo '<th class="text-center">' . $inch . '</th>';
}
echo '<th colspan="3" class="text-center">4인치</th>';
echo '<th colspan="3" class="text-center">5인치</th>';
echo '</tr>';
// 3행 (보조 길이 + 일반 길이)
echo '<tr>';
foreach ($col59InchLengthSummary as $key => $qty) {
[$inch, $length] = explode('_', $key);
echo '<th class="text-center">' . ($length ?: '') . '</th>';
}
echo '<th class="text-center">3000</th>';
echo '<th class="text-center">4500</th>';
echo '<th class="text-center">6000</th>';
echo '<th class="text-center">6000</th>';
echo '<th class="text-center">7000</th>';
echo '<th class="text-center">8200</th>';
echo '</tr>';
// 4행 (보조 수량 + 일반 수량)
echo '<tr>';
foreach ($col59InchLengthSummary as $key => $qty) {
echo '<th class="text-center text-primary fw-bold">' . ($qty ?: '') . '</th>';
}
echo '<th class="text-center text-primary fw-bold">' . ($row4_4_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row5_4_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row6_4_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row7_4_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row8_4_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row9_4_sum ?: '') . '</th>';
echo '</tr>';
// 5행 부자재 구분
echo '<tr>';
echo '<th colspan="2" class="text-center"> 무게평철 <br> (50*12T) </th>';
echo '<th colspan="2" class="text-center"> 환봉 </th>';
echo '<th colspan="2" class="text-center"> 각파이프 </th>';
echo '<th colspan="2" class="text-center"> 앵글 </th>';
echo '</tr>';
// 6행 부자재 규격
echo '<tr>';
echo '<th colspan="2" class="text-center"> 2000 </th>';
echo '<th colspan="2" class="text-center"> 3000 </th>';
echo '<th class="text-center"> 3000 </th>';
echo '<th class="text-center"> 6000 </th>';
echo '<th colspan="2" class="text-center"> 2500 </th>';
echo '</tr>';
// 7행 부자재 수량
echo '<tr>';
echo '<th colspan="2" class="text-center text-primary fw-bold">' . ($row2_7_sum ?: '') . '</th>';
echo '<th colspan="2" class="text-center text-primary fw-bold">' . ($row4_7_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row6_7_sum ?: '') . '</th>';
echo '<th class="text-center text-primary fw-bold">' . ($row7_7_sum ?: '') . '</th>';
echo '<th colspan="2" class="text-center text-primary fw-bold">' . ($row8_7_sum ?: '') . '</th>';
echo '</tr>';
echo '</thead>';
echo '</table>';
echo '</div>';
}
// echo '</div>';
// 비고
if($option == 'option') {
echo '<div class="d-flex align-items-center justify-content-center mt-1 mb-5 vendor-send">';
echo '<table class="table" style="border-collapse: collapse;">';
echo '<thead>';
echo '<tr>';
echo '<th class="text-center"> 특이사항 </th>';
echo '<th colspan="5" class="text-start">
해당 견적서의 유효기간은 <span class="text-danger" style="text-decoration: underline;"> 발행일 기준 1개월 </span> 입니다. <br>
견적금액의 50% 입금하시면 발주가 진행됩니다.
</th>';
echo '</tr>';
echo '<tr>'; // 2행
echo '<th class="text-center">결제방법</th>';
echo '<th class="text-center">계좌이체</th>';
echo '<th colspan="2" class="text-center">계좌정보</th>';
echo '<th colspan="2" class="text-center">국민은행 796801-00-039630</th>';
echo '</tr>';
echo '<tr>'; // 3행
echo '<th class="text-center">담당자</th>';
echo '<th class="text-center"> ' . $orderman . ' ' . $position . '</th>';
echo '<th colspan="1" class="text-center">연락처</th>';
echo '<th colspan="1" class="text-center">070-4351-5275</th>';
echo '<th colspan="1" class="text-center">E-mail</th>';
echo '<th colspan="1" class="text-center"> <span class="text-primary" > kd5130@naver.com </span> </th>';
echo '</tr>';
echo '</thead>';
echo '</table>';
echo '</div>';
}
// rowspan 처리를 위한 JavaScript 변수 전달
echo '<script>';
echo 'var rowArrayData = ' . $row_array_json . ';';
echo '</script>';
?>
</div> <!-- end of container -->