<!-- 감기샤프트 -->
<?php
// 감기샤프트와 부속자재 출력
if (True) {
    // 감기샤프트 데이터를 누적하기 위한 배열
    $shaft_data = [        
        '4인치_3000' => intval(0),
        '4인치_4500' => intval(0),
        '4인치_6000' => intval(0),
        '5인치_6000' => intval(0),
        '5인치_7000' => intval(0),
        '5인치_8200' => intval(0),
        '6인치_3000' => intval(0),
        '6인치_6000' => intval(0),
        '6인치_7000' => intval(0),
        '6인치_8000' => intval(0),
        '8인치_8200' => intval(0)
    ];

    // 부속자재 데이터를 누적하기 위한 배열
    $subs_data = [
        '각파이프_3000' => intval(0),
        '각파이프_6000' => intval(0),
        '앵글_2500' => intval(0),
        '조인트바_300' => intval(0)
    ];

    // 데이터를 누적하여 합산
    foreach ($eList as $item) {        
        $shaft_data['4인치_3000'] += intval($item['col61']);
        $shaft_data['4인치_4500'] += intval($item['col62']);
        $shaft_data['4인치_6000'] += intval($item['col63']);
        $shaft_data['5인치_6000'] += intval($item['col64']);
        $shaft_data['5인치_7000'] += intval($item['col65']);
        $shaft_data['5인치_8200'] += intval($item['col66']);
        $shaft_data['6인치_3000'] += intval($item['col67']);
        $shaft_data['6인치_6000'] += intval($item['col68']);
        $shaft_data['6인치_7000'] += intval($item['col69']);
        $shaft_data['6인치_8000'] += intval($item['col70']);
        $shaft_data['8인치_8200'] += intval($item['col71']);        
        
        // 부속자재 누적
        $subs_data['각파이프_3000'] += intval($item['col74']);
        $subs_data['각파이프_6000'] += intval($item['col75']);        
        $subs_data['조인트바_300'] += intval($item['col76']);
        $subs_data['앵글_2500'] += intval($item['col77']);
    }

    // HTML 구조 시작
    echo '<div class="row">';
    
    // 감기샤프트 부분
    echo '<div class="col-sm-6 justify-content-start">';
    echo '<table class="table avoid-break" style="border-collapse: collapse;">';
    echo '<thead>';
    echo '<tr><th colspan="2" class="text-center lightgray">감기샤프트</th></tr>';
    echo '<tr><th class="text-center lightgray">규격</th><th class="text-center lightgray">수량</th></tr>';
    echo '</thead>';
    echo '<tbody>';

    // 감기샤프트 데이터 출력
    foreach ($shaft_data as $label => $quantity) {
        if ($quantity > 0) {
            echo '<tr>';
            echo '<td class="text-center blueBold">' . str_replace('_', ' ', $label) . '</td>';
            echo '<td class="text-center fw-bold">' . $quantity . '</td>';
            echo '</tr>';
        }
    }

    echo '</tbody>';
    echo '</table>';
    echo '</div>'; // 감기샤프트 부분 끝

    // 부속자재 부분
    echo '<div class="col-sm-6 ">';
    echo '<table class="table avoid-break" style="border-collapse: collapse;">';
    echo '<thead>';
    echo '<tr><th colspan="3" class="text-center lightgray">부속자재</th></tr>';
    echo '<tr><th class="text-center lightgray">구성품</th><th class="text-center lightgray">길이</th><th class="text-center lightgray">수량</th></tr>';
    echo '</thead>';
    echo '<tbody>';

	// 각파이프 (길이별로 행을 따로 출력, 첫 번째 셀에 rowspan 적용)
	$pipe_rowspan = 0;
	if ($subs_data['각파이프_3000'] > 0) {
		$pipe_rowspan++;
	}
	if ($subs_data['각파이프_6000'] > 0) {
		$pipe_rowspan++;
	}

	if ($pipe_rowspan > 0) {
		echo '<tr>';			
		echo '<td class="text-center blueBold" rowspan="' . $pipe_rowspan . '">각파이프</td>';
		
		if ($subs_data['각파이프_3000'] > 0) {			
			echo '<td class="text-center fw-bold">3000</td>';
			echo '<td class="text-center fw-bold">' . $subs_data['각파이프_3000'] . '</td>';
			echo '</tr>';
		}
		if ($subs_data['각파이프_6000'] > 0) {			
			// 6000 길이용 각파이프			
			echo '<td class="text-center fw-bold">6000</td>';
			echo '<td class="text-center fw-bold">' . $subs_data['각파이프_6000'] . '</td>';
			echo '</tr>';
		}
	}


    // 조인트바
    if ($subs_data['조인트바_300'] > 0) {
        echo '<tr>';
        echo '<td class="text-center blueBold">조인트바</td>';
        echo '<td class="text-center fw-bold">300</td>';
        echo '<td class="text-center fw-bold">' . $subs_data['조인트바_300'] . '</td>';
        echo '</tr>';
    }

    // 앵글
    if ($subs_data['앵글_2500'] > 0) {
        echo '<tr>';
        echo '<td class="text-center blueBold">앵글<br>(50*50*3T)</td>';
        echo '<td class="text-center fw-bold">2500</td>';
        echo '<td class="text-center fw-bold">' . $subs_data['앵글_2500'] . '</td>';
        echo '</tr>';
    }

    echo '</tbody>';
    echo '</table>';
    echo '</div>'; // 부속자재 부분 끝

    echo '</div>'; // row 끝
    echo '</div>'; // row 끝
}
?>
