<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");  

if(!isset($_SESSION["level"]) || $_SESSION["level"]>5) {
	sleep(1);
	header("Location:" . $WebSite . "login/login_form.php"); 
	exit;
}   

include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php';

// 첫 화면 표시 문구
$title_message = '견적 단가 관리'; 
?>

<title> <?=$title_message?> </title>

</head>

<body>	
	 
<?php
$option = isset($_REQUEST['option']) ? $_REQUEST['option'] : '';  
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';  
$header = isset($_REQUEST['header']) ? $_REQUEST['header'] : '';  

$tablename = 'estimate_units';
  	  
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();

$num = isset($_REQUEST["num"]) ? $_REQUEST["num"] : 0;

$csv_data = [
    ["스크린", "실리카", "33000", ""],
    ["스크린", "와이어", "33000", ""],
    ["슬랫", "환봉", "2000", ""],
    ["모터", "KD-150", "285000", ""],
    ["모터", "KD-300", "300000", ""],
];

if($num > 0) {
	try {
		$sql = "SELECT * FROM ". $DB . "." . $tablename . " WHERE num=?";
		$stmh = $pdo->prepare($sql);  
		$stmh->bindValue(1, $num, PDO::PARAM_INT);      
		$stmh->execute();            
		  
		$row = $stmh->fetch(PDO::FETCH_ASSOC); 	 
		include '_row.php';

	} catch (PDOException $Exception) {
		print "오류: ".$Exception->getMessage();
	}      	

	if($option !=='add') {
		$mode = 'update';
	} else {
		$mode = 'insert';		 	
		$item_name = '';
		$price = '';	
		$title_message = '견적 단가 추가화면'; 
		
		$parentnum = $num;
		$secondordnum = $num;
	}		 
} else {
	include '_request.php';
	
	$mode = 'insert';
	$item_name = '';
	$price = '';	
	$note = '';
}
?>	

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <title>견적 단가 관리</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        input[type="text"] {
            width: 100%;
            box-sizing: border-box;
            text-align: center;
        }
        .table th, .table td {
            text-align: center;
        }
        .card {
            margin-bottom: 20px;
        }
    </style>
</head>
<body>


<div class="container"> 

<div class="row justify-content-center align-items-center ">	        
		<div class="card align-middle " style="width: 55rem;">	
		<div class="card-body text-center">							
			<div class="row d-flex justify-content-center align-items-center mb-3" >					
				<div class="col-sm-1" >			
					<div class="d-flex p-1 mb-1  justify-content-start align-items-center ">				
					   <?=$mode?>								
				   </div>
				</div>			
				<div class="col-sm-9" >					
					<div class="d-flex p-1 mb-1  justify-content-center align-items-center ">	
				<h3>	<?=$title_message?>    </h3>   &nbsp; &nbsp;  &nbsp; &nbsp; 	
					<?php if($mode =='view') { ?>		
					<button type="button" class="btn btn-dark btn-sm me-1" onclick="location.href='write_form.php?mode=modify&num=<?=$num?>&tablename=<?=$tablename?>';" > <ion-icon name="color-wand-outline"></ion-icon> 수정 </button>
					<button id="copyBtn" class="btn btn-primary  btn-sm me-1" type="button"><i class="bi bi-copy"></i> 복사</button>										
					<?php } ?>		
				   <?php if($mode!=='view') { ?>
						<button id="saveBtn" class="btn  btn-dark btn-sm me-1 " type="button">
						<? if((int)$num>0) print ' <i class="bi bi-hdd-fill"></i> 저장';  else print ' <i class="bi bi-hdd-fill"></i> 저장'; ?></button>		   			
				   <?  } ?>		
										
						</div>
					</div>			
				<div class="col-sm-2" >					
					<button type="button" class="btn btn-outline-dark  btn-sm " onclick="self.close();" > <i class="bi bi-box-arrow-left"></i> 창닫기 </button>	&nbsp; 				
				</div>	
			   </div>	
			</div>
		</div>		
	</div>		
</div>	

<div class="container-fluid">
    <div class="row d-flex justify-content-center">
        <div class="col-12 col-md-10">
            <div class="card">
                <div class="card-header bg-primary text-white text-center">
                    스크린, 슬랫, 모터  
                </div>
                <div class="card-body">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th colspan="3">스크린</th>
                                <th colspan="2">슬랫</th>
                                <th colspan="3">모터</th>
                            </tr>
                            <tr>
                                <th>실리카</th>
                                <th>환봉</th>
                                <th>본체</th>
                                <th>조인트바</th>
                                <th>검사비</th>
                                <th style="width:160px;">모터세트</th>
                                <th>받침앵글</th>
                                <th>연동제어기</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><input type="text" class="form-control" name="silica" value="33,000"></td>
                                <td><input type="text" class="form-control" name="round_bar" value="2,000"></td>
                                <td><input type="text" class="form-control" name="body" value="45,000"></td>
                                <td><input type="text" class="form-control" name="joint_bar" value="5,000"></td>
                                <td><input type="text" class="form-control" name="inspection_fee" value="100,000"></td>
                                <td class="fw-bold">KD-150</td>
                                <td><input type="text" class="form-control" name="support_angle" value="285,000"></td>
                                <td><input type="text" class="form-control" name="control_unit" value="130,000"></td>
                            </tr>
							<tr>
								<td class="fw-bold"> 와이어</td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="fw-bold">KD-300</td>
								<td><input type="text" class="form-control" name="support_angle_300" value="300,000"></td>
								<td class="fw-bold">매립뒷박스</td>		
							</tr>
							<tr>
								<td><input type="text" class="form-control" name="silica_2" value="33,000"></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="fw-bold">KD-400</td>
								<td><input type="text" class="form-control" name="support_angle_400" value="330,000"></td>
								<td><input type="text" class="form-control" name="angle" value="10,000"></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="fw-bold">KD-500</td>
								<td><input type="text" class="form-control" name="support_angle_500" value="370,000"></td>
								<td class="fw-bold">앵글</td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="fw-bold">KD-600</td>
								<td><input type="text" class="form-control" name="support_angle_600" value="380,000"></td>
								<td><input type="text" class="form-control" name="inspection_fee_600" value="3,000"></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="fw-bold">KD-800</td>
								<td><input type="text" class="form-control" name="support_angle_800" value="550,000"></td>
								<td><input type="text" class="form-control" name="inspection_fee_800" value="4,000"></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="fw-bold">KD-1000</td>
								<td><input type="text" class="form-control" name="support_angle_1000" value="600,000"></td>
								<td><input type="text" class="form-control" name="inspection_fee_1000" value="4,500"></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="fw-bold">KD-1500</td>
								<td><input type="text" class="form-control" name="support_angle_1500" value="1,300,000"></td>
								<td><input type="text" class="form-control" name="inspection_fee_1500" value="5,000"></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="fw-bold">방폭모터(1000K)삼상</td>
								<td><input type="text" class="form-control" name="explosion_proof_motor_price" value="3,300,000"></td>
								<td></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="fw-bold">방폭제어기</td>
								<td><input type="text" class="form-control" name="explosion_proof_control_price" value="1,200,000"></td>
								<td></td>
							</tr>
                           
                        </tbody>
                    </table>
                </div>
            </div>

            <!-- 두 번째 카드 시작 -->
            <div class="card">
                <div class="card-header bg-primary text-white text-center">
                    가이드레일, 케이스(셔터박스), 하단마감재  
                </div>
                <div class="card-body">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th colspan="4">가이드레일</th>
                                <th colspan="3">케이스(셔터박스)</th>
                                <th colspan="5">하단마감재</th>
                            </tr>
                            <tr>
                                <th style="width:150px;">레일높이</th>
                                <th style="width:200px;">레일자재</th>
                                <th>레일자재</th>
                                <th>연기차단재</th>
                                <th style="width:150px;">사이즈</th>
                                <th>케이스자재</th>
                                <th>마구리</th>
                                <th>연기차단재</th>
                                 <th style="width:150px;">마감</th>
                                <th>하장바</th>
                                <th>엘바</th>
                                <th>보강평철</th>
                            </tr>
                        </thead>
                        <tbody>
<tr>
    <td>KSS01</td>
    <td class="fw-bold">벽면형120*70</td>
    <td><input type="text" class="form-control" name="rail_material_2" value="69,780"></td>
    <td><input type="text" class="form-control" name="smoke_control_1" value="5,080"></td>
    <td class="fw-bold">500*350</td>
    <td><input type="text" class="form-control" name="case_material_1" value="54,837"></td>
    <td><input type="text" class="form-control" name="maguri_1" value="14,865"></td>
    <td><input type="text" class="form-control" name="smoke_control_2" value="8,590"></td>
    <td>KSS01</td>
    <td><input type="text" class="form-control" name="lower_finishing_1" value="12,276"></td>
    <td><input type="text" class="form-control" name="elbar_1" value="4,158"></td>
    <td><input type="text" class="form-control" name="reinforced_plate_1" value="1,100"></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">측면형120*120</td>
    <td><input type="text" class="form-control" name="rail_material_4" value="91,674"></td>
    <td></td>
    <td class="fw-bold">500*380</td>
    <td><input type="text" class="form-control" name="case_material_2" value="56,457"></td>
    <td><input type="text" class="form-control" name="maguri_2" value="15,845"></td>
    <td></td>
    <td>KSE01, KWE01 <br> (EGI)</td>
    <td><input type="text" class="form-control" name="lower_finishing_2" value="5,346"></td>
    <td><input type="text" class="form-control" name="elbar_2" value="4,158"></td>
    <td><input type="text" class="form-control" name="reinforced_plate_2" value="1,100"></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">혼합형</td>
    <td><input type="text" class="form-control" name="rail_material_6" value="80,727"></td>
    <td></td>
    <td class="fw-bold">650*500</td>
    <td><input type="text" class="form-control" name="case_material_3" value="71,739"></td>
    <td><input type="text" class="form-control" name="maguri_3" value="24,666"></td>
    <td></td>
    <td>KWE01 <br>(SUS별도마감)</td>
    <td><input type="text" class="form-control" name="lower_finishing_3" value="17,484"></td>
    <td><input type="text" class="form-control" name="elbar_3" value="4,158"></td>
    <td><input type="text" class="form-control" name="reinforced_plate_3" value="1,100"></td>
</tr>
<tr>
    <td>KTE01<br>(SUS마감)</td>
    <td class="fw-bold">벽면형130*75</td>
    <td><input type="text" class="form-control" name="rail_material_8" value="97,158"></td>
    <td></td>
    <td class="fw-bold">650*550</td>
    <td><input type="text" class="form-control" name="case_material_4" value="74,439"></td>
    <td><input type="text" class="form-control" name="maguri_4" value="26,704"></td>
    <td></td>
    <td>KTE01<br>(EGI)</td>
    <td><input type="text" class="form-control" name="lower_finishing_4" value="5,805"></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">측면형130*125</td>
    <td><input type="text" class="form-control" name="rail_material_10" value="112,444"></td>
    <td></td>
    <td class="fw-bold">700*550</td>
    <td><input type="text" class="form-control" name="case_material_5" value="77,139"></td>
    <td><input type="text" class="form-control" name="maguri_5" value="28,473"></td>
    <td></td>
    <td>KTE01<br>(SUS별도마감)</td>
    <td><input type="text" class="form-control" name="lower_finishing_5" value="13,761"></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">혼합형</td>
    <td><input type="text" class="form-control" name="rail_material_12" value="102,761"></td>
    <td></td>
    <td class="fw-bold">700*600</td>
    <td><input type="text" class="form-control" name="case_material_6" value="79,839"></td>
    <td><input type="text" class="form-control" name="maguri_6" value="30,646"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>KTE01<br>(EGI마감)</td>
    <td class="fw-bold">벽면형130*75</td>
    <td><input type="text" class="form-control" name="rail_material_14" value="57,786"></td>
    <td></td>
    <td class="fw-bold">780*600</td>
    <td><input type="text" class="form-control" name="case_material_7" value="84,159"></td>
    <td><input type="text" class="form-control" name="maguri_7" value="33,692"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">측면형130*125</td>
    <td><input type="text" class="form-control" name="rail_material_16" value="72,766"></td>
    <td></td>
    <td class="fw-bold">780*650</td>
    <td><input type="text" class="form-control" name="case_material_8" value="86,859"></td>
    <td><input type="text" class="form-control" name="maguri_8" value="36,081"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>

<tr>
    <td></td>
    <td class="fw-bold">혼합형</td>
    <td><input type="text" class="form-control" name="rail_material_18" value="65,276"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>KWE01<br>(SUS마감)</td>
    <td class="fw-bold">벽면형120*70</td>
    <td><input type="text" class="form-control" name="rail_material_20" value="79,952"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">측면형120*120</td>
    <td><input type="text" class="form-control" name="rail_material_22" value="104,046"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">혼합형</td>
    <td><input type="text" class="form-control" name="rail_material_24" value="91,999"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>KWE01<br>(EGI마감)</td>
    <td class="fw-bold">벽면형120*70</td>
    <td><input type="text" class="form-control" name="rail_material_26" value="45,884"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">측면형120*120</td>
    <td><input type="text" class="form-control" name="rail_material_28" value="64,878"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">혼합형</td>
    <td><input type="text" class="form-control" name="rail_material_30" value="55,381"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>KSE01</td>
    <td class="fw-bold">벽면형120*70</td>
    <td><input type="text" class="form-control" name="rail_material_32" value="45,884"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">측면형120*120</td>
    <td><input type="text" class="form-control" name="rail_material_34" value="64,878"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">혼합형</td>
    <td><input type="text" class="form-control" name="rail_material_36" value="55,381"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>와이드</td>
    <td class="fw-bold">벽면형180*70</td>
    <td><input type="text" class="form-control" name="rail_material_38" value="88,500"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">측면형180*120</td>
    <td><input type="text" class="form-control" name="rail_material_40" value="111,942"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="fw-bold">혼합형</td>
    <td><input type="text" class="form-control" name="rail_material_42" value="100,221"></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>

                        </tbody>
                    </table>
                </div>
            </div>

            <!-- 세 번째 카드 시작 -->
            <div class="card">
                <div class="card-header bg-primary text-white text-center">
                    감기샤프트, 무게평철, 각파이프, 앵글  
                </div>
                <div class="card-body">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th colspan="2">감기샤프트</th>
                                <th rowspan="2">무게평철</th>
                                <th rowspan="2">각파이프</th>
                                <th rowspan="2">앵글</th> 
                            </tr>
                            <tr>
                                <th style="width:200px;">인치</th>
                                <th>메인</th>                                
                            </tr>
                        </thead>
                        <tbody>
						<tr>
							<td class="fw-bold">3인치-300</td>
							<td><input type="text" class="form-control" name="main_1" value="3,000"></td>
							<td class="fw-bold">12T-1000</td>
							<td class="fw-bold">50*30-3000</td>
							<td class="fw-bold">40*40*3T-2500</td>                                
						</tr>
						<tr>
							<td class="fw-bold">3인치-500</td>
							<td><input type="text" class="form-control" name="main_2" value="5,000"></td>
							<td><input type="text" class="form-control" name="weight_plate_1" value="6,500"></td>
							<td><input type="text" class="form-control" name="angle_pipe_1" value="7,000"></td>
							<td><input type="text" class="form-control" name="angle_1" value="17,000"></td>								                                
						</tr>
						<tr>
							<td class="fw-bold">3인치-6000</td>
							<td><input type="text" class="form-control" name="main_3" value="43,000"></td>
							<td class="fw-bold">12T - 2000</td>
							<td class="fw-bold">50*30- 6000</td>
							<td class="fw-bold">50*50*4T-2500</td>		
						</tr>

							<tr>
								<td class="fw-bold">4인치-3000</td>
								<td><input type="text" class="form-control" name="main_4" value="28,000"></td>
								<td><input type="text" class="form-control" name="weight_plate_2" value="12,000"></td>
								<td><input type="text" class="form-control" name="angle_pipe_2" value="14,000"></td>
								<td><input type="text" class="form-control" name="angle_2" value="24,000"></td>
							</tr>
							<tr>
								<td class="fw-bold">4인치-4500</td>
								<td><input type="text" class="form-control" name="main_5" value="41,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="fw-bold">4인치-6000</td>
								<td><input type="text" class="form-control" name="main_6" value="55,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="fw-bold">5인치-6000</td>
								<td><input type="text" class="form-control" name="main_7" value="90,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="fw-bold">5인치-7000</td>
								<td><input type="text" class="form-control" name="main_8" value="105,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="fw-bold">5인치-8200</td>
								<td><input type="text" class="form-control" name="main_9" value="122,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="fw-bold">6인치-3000</td>
								<td><input type="text" class="form-control" name="main_10" value="48,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="fw-bold">6인치-6000</td>
								<td><input type="text" class="form-control" name="main_11" value="107,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="fw-bold">6인치-7000</td>
								<td><input type="text" class="form-control" name="main_12" value="124,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="fw-bold">6인치-8000</td>
								<td><input type="text" class="form-control" name="main_13" value="142,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td class="fw-bold">8인치-8200</td>
								<td><input type="text" class="form-control" name="main_14" value="265,000"></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 페이지로딩 -->
<script>
// 페이지 로딩
$(document).ready(function(){	
    var loader = document.getElementById('loadingOverlay');
    loader.style.display = 'none';
});
</script>
	 

<script>
    // 숫자 입력 필드에 대한 3자리 콤마 처리
    document.querySelectorAll('input[type="text"]').forEach(function(input) {
        input.addEventListener('input', function(e) {
            var value = e.target.value.replace(/,/g, '');
            if (!isNaN(value) && value !== '') {
                e.target.value = parseInt(value).toLocaleString();
            } else {
                e.target.value = '';
            }
        });
    });
</script>



</body>
</html>
                                
                                
				
								
