<?php

	include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	include $_SERVER['DOCUMENT_ROOT'].ADMIN_PATH.'common/auth_chk.php';

	$mp = "40";	//set top nav

?>
<? include("../inc/inc_top.php") ?>
<? include("../inc/inc_header.php") ?>

<?
	$cd_dealer = $_REQUEST["cd_dealer"];

	$sql ="SELECT
				*
				FROM aap_master
				WHERE cd_dealer='$cd_dealer' AND ds_delind='N'";

	$mode = "Add";

	$col=mysql_fetch_array(mysql_query($sql));
	if (!empty($col['cd_dealer'])){
		$cd_dealer = $col['cd_dealer'];
		$cd_dealerid = $col['cd_dealerid'];
		$cd_dealer_p = $col['cd_dealer_p'];
		$nm_pass = $col['nm_pass'];
		$ds_type = $col['ds_type'];
		$ds_level = $col['ds_level'];
		$nm_company = $col['nm_company'];
		$nm_name = $col['nm_name'];
		$nm_birth = $col['nm_birth'];
		$nm_tel_01 = $col['nm_tel_01'];
		$nm_tel_02 = $col['nm_tel_02'];
		$nm_tel_03 = $col['nm_tel_03'];
		$nm_hp_01 = $col['nm_hp_01'];
		$nm_hp_02 = $col['nm_hp_02'];
		$nm_hp_03 = $col['nm_hp_03'];
		$nm_fax_01 = $col['nm_fax_01'];
		$nm_fax_02 = $col['nm_fax_02'];
		$nm_fax_03 = $col['nm_fax_03'];
		$nm_email = $col['nm_email'];
		$nm_zip = $col['nm_zip'];
		$nm_addr = $col['nm_addr'];
		$nm_addr_sub = $col['nm_addr_sub'];
		$nm_etc_01 = $col['nm_etc_01'];
		$nm_etc_02 = $col['nm_etc_02'];
		$nm_etc_03 = $col['nm_etc_03'];
		$ds_status = $col['ds_status'];
		$nm_company_biz = $col['nm_company_biz'];
		$nm_name_biz = $col['nm_name_biz'];
		$nm_no_biz = $col['nm_no_biz'];
		$nm_date_biz = $col['nm_date_biz'];
		$nm_type_biz = $col['nm_type_biz'];
		$nm_condition_biz = $col['nm_condition_biz'];
		$nm_tel_biz_01 = $col['nm_tel_biz_01'];
		$nm_tel_biz_02 = $col['nm_tel_biz_02'];
		$nm_tel_biz_03 = $col['nm_tel_biz_03'];
		$nm_hp_biz_01 = $col['nm_hp_biz_01'];
		$nm_hp_biz_02 = $col['nm_hp_biz_02'];
		$nm_hp_biz_03 = $col['nm_hp_biz_03'];
		$nm_fax_biz_01 = $col['nm_fax_biz_01'];
		$nm_fax_biz_02 = $col['nm_fax_biz_02'];
		$nm_fax_biz_03 = $col['nm_fax_biz_03'];
		$nm_email_biz = $col['nm_email_biz'];
		$nm_zip_biz = $col['nm_zip_biz'];
		$nm_addr_biz = $col['nm_addr_biz'];
		$nm_addr_sub_biz = $col['nm_addr_sub_biz'];
		$dt_insert = $col['dt_insert'];
		$nm_insert = $col['nm_insert'];
		$dt_update = $col['dt_update'];
		$nm_update = $col['nm_update'];
		$ds_delind = $col['ds_delind'];
/*
		$arr_nm_info1 = explode("-",$nm_info1);
		if(count($arr_nm_info1) == 3){
			$nm_info11 = $arr_nm_info1[0];
			$nm_info12 = $arr_nm_info1[1];
			$nm_info13 = $arr_nm_info1[2];
		}else{
			$nm_info11 = "";
			$nm_info12 = "";
			$nm_info13 = "";
		}

		$arr_nm_info3 = explode("@",$nm_info3);
		if(count($arr_nm_info3) == 2){
			$nm_info31 = $arr_nm_info3[0];
			$nm_info32 = $arr_nm_info3[1];
		}else{
			$nm_info31 = "";
			$nm_info32 = "";
		}
		$nm_info3 = $col[nm_info3];
*/
		$mode = "Update";
	}else{
		$ds_level = "1";
	}

?>

<section id="contents">
	<h2>구매확정 리스트</h2>


	<div class="tbl_wrap">
		<table class="tbl_list2 ty2">
			<colgroup>
				<col width="12%">
				<col width="38%">
				<col width="12%">
				<col width="38%">
			</colgroup>
			<tr>
				<th>상호</th>
				<td><?=$nm_name?></td>
				<th>핸드폰</th>
				<td><?=$nm_hp_01."-".$nm_hp_02."-".$nm_hp_03?></td>
			</tr>
			<tr>
				<th>승인 상태</th>
				<td><?=($ds_status == "Z0") ? "승인":"미승인" ?></td>
				<th></th>
				<td></td>
			</tr>

			<!-- <tr>
				<th>상호</th>
				<td><?=$nm_company?></td>
				<th>핸드폰</th>
				<td><?=$nm_hp_01."-".$nm_hp_02."-".$nm_hp_03?></td>
			</tr>
			<tr>
				<th>대표</th>
				<td><?=$nm_name?></td>
				<th>연락처</th>
				<td><?=$nm_tel_01."-".$nm_tel_02."-".$nm_tel_03?></td>
			</tr>
			<tr>
				<th>팩스번호</th>
				<td><?=$nm_fax_01."-".$nm_fax_02."-".$nm_fax_03?></td>
				<th>승인 상태</th>
				<td><?=($ds_status == "Z0") ? "승인":"미승인" ?></td>
			</tr>
			<tr>
				<th>주소</th>
				<td colspan="3"><?=$nm_addr." ".$nm_addr_sub?></td>
			</tr> -->
		</table>
	</div>
	<div class="btn_right">
		<a href="<?=ADMIN_PATH?>member/aap_view.php?cd_dealer=<?=$cd_dealer?>" class="rnd_btn gray" style='width:190px;'>매입사 정보 자세히 보기</a>
	</div>


    	<h3><em>▶</em> 낙찰정보</h3>

<?

	$list_url = "purchase_view.php";

	$PageNo = $_REQUEST['pageno'];
	$PageSize = $_REQUEST['PageSize'];
	if (empty($PageNo)) {$PageNo=1;}else{$PageNo=$PageNo;}
	if (empty($PageSize)) {
		$PageSize=10; //목록개수설정
	}else{$PageSize=$PageSize;}

	$pagestartpoint=($PageNo-1)*$PageSize;
	$add_sql = "where s.ds_delind='N'";

	$searchtype = $_REQUEST['searchtype'];
	$searchword = $_REQUEST['searchword'];
	$ds_usertype = $_REQUEST['ds_usertype'];
	$ds_status = $_REQUEST['ds_status'];
	$dt_end_start = $_REQUEST['dt_end_start'];
	$dt_end_end = $_REQUEST['dt_end_end'];

	$cd_dealer = $_REQUEST['cd_dealer'];

	$ds_type = "A0";	//A0 : 매입
	$add_sql.=  "	and s.ds_type = '$ds_type' ";
	$add_sql.= "	and t.cd_dealer_p = '$cd_dealer' ";

	if($searchword != ""){
		if($searchtype=="" || $searchtype==null){
			$add_sql.=  "	and (s.nm_name like '$searchword%' or a.nm_number like '$searchword%') ";
		}else{
			$add_sql.=  "	and $searchtype like '$searchword%'";
		}
	}

	if($dt_end_start != "" && $dt_end_end != ""){
		$add_sql.=  "	and s.dt_end between '$dt_end_start' and '$dt_end_end' ";
	}

	if($ds_usertype != ""){
		$add_sql.=  "	and s.ds_usertype = '$ds_usertype'";
	}

	$add_sql.=  "	and s.ds_status in ('ZS') ";

	$sql = "select count(*)
					from sale_master s
					inner join tender_master t on (s.cd_sale = t.cd_sale and t.ds_status = 'Z0' AND t.ds_delind = 'N')
					inner join car_master a on ( s.cd_car = a.cd_car ) $add_sql";
	$totalrows = @mysql_result(mysql_query($sql),0,0);

?>
<form id="frmSearch" name="frmSearch" method="post">
<input type="hidden" id="PageSize" name="PageSize">
<input type="hidden" id="searchtype" name="searchtype">
<input type="hidden" id="cd_dealer" name="cd_dealer" value="<?=$cd_dealer?>">
	<table class="tbl_search">
		<colgroup>
			<col width="10%">
			<col width="35%">
			<col width="10%">
			<col width="*">
		</colgroup>
		<tr>
			<th>검색어</th>
			<td>
				<span class="select2" style="margin-right:5px;width:100px;" id="sel_searchtype">
					<select>
						<option value="">전체</option>
						<option value="d.nm_brand"<? if($searchtype =="d.nm_brand"){?> selected<?}?>>제조사</option>
						<option value="b.nm_model"<? if($searchtype =="b.nm_model"){?> selected<?}?>>모델명</option>
						<option value="a.nm_number"<? if($searchtype =="a.nm_number"){ ?> selected<?}?>>차량번호</option>
						<option value="t.nm_name"<? if($searchtype =="t.nm_name"){ ?> selected<?}?>>낙찰자</option>
					</select>
				</span>
				<input type="text" id="searchword" name="searchword" class="inp_txt" style="width:60%;" value="<?=$searchword?>">
			</td>
			<th>판매완료일</th>
			<td>
				<input type="text" class="inp_txt" style="width:34%;" id="dt_end_start" name="dt_end_start" value="<?=$dt_end_start?>">
				<span class="btn_cal" id="btn_cal1">달력보기</span>
				~
				<input type="text" class="inp_txt" style="width:34%;" id="dt_end_end" name="dt_end_end" value="<?=$dt_end_end?>">
				<span class="btn_cal" id="btn_cal2">달력보기</span>
				<input type="submit" class="rnd_btn ty3 gray" value="검색" title="검색">
				<div class="btn_right" style="margin-top:-28px">
					<a href="javascript:;" id="btn_download_excel" class="rnd_btn black" style='width:110px;'>엑셀 다운로드</a>
				</div>
			</td>
		</tr>
	</table>
</form>

    <div class="purchase_grade area_title">
    <!--span class="month">11월</span-->
    <span>총 낙찰 건수 : <em><?=$totalrows?>건</em></span>


		<!--span class="select" >
			<select>
				<option value="">10개 보기</option>
				<option value="">20개 보기</option>
				<option value="">30개 보기</option>
			</select>
		</span-->

    </div>

    <div class="tbl_wrap">
		<table class="tbl_list ty2">
			<colgroup>
				<col width="7%">
				<col width="10%">
				<col width="*">
				<col width="12%">
				<col width="8%">
				<col width="13%">
				<col width="20%">
				<col width="11%">
			</colgroup>
			<thead>
			<tr>
				<th>번호</th>
				<th>판매자</th>
				<th>차종</th>
				<th>차량번호</th>
				<th>판매지역</th>
				<th>판매금액</th>
				<th>낙찰자</th>
				<th>판매완료일</th>
			</tr>
			</thead>
<?
if($totalrows>0) {

	$r = mysql_query("SELECT
							a.*
							, b.nm_model
							, d.nm_brand
							, getCode('car_master','ds_type',a.ds_type) as nm_type
							, getCode('car_master','ds_open',a.ds_open) as nm_open
							, getCode('car_master','ds_sales',a.ds_sales) as nm_sales
							, getCode('car_master','ds_transmission',a.ds_transmission) as nm_transmission
							, getCode('member_master','ds_area',s.ds_area) as nm_area
							, getCode('sale_master','ds_status',s.ds_status) as nm_status
							, s.cd_sale
							, s.nm_name nm_name_sale
							, s.nm_recommend nm_recommend_sale
							, s.ds_status ds_status_sale
							, s.ds_status_contract ds_status_contract_sale
							, s.nm_price_final nm_price_final_sale
							, t.nm_name nm_name_tender
							, t.nm_price nm_price_tender
							, s.dt_end dt_end_sale
							FROM sale_master s
								inner join tender_master t on (s.cd_sale = t.cd_sale and t.ds_status = 'Z0' AND t.ds_delind = 'N')
								inner join car_master a on (s.cd_car = a.cd_car)
								left outer join car_model b on (a.cd_model = b.cd_model)
								left outer join car_brand d on (a.cd_brand = d.cd_brand)
								$add_sql $orderby LIMIT $pagestartpoint,$PageSize");

	$i=1;
	while($col = mysql_fetch_array($r)){

		$tmpNum =$totalrows-($PageSize*($PageNo-1));
		$no = ($tmpNum - $i)+1;

?>
			<tr>
				<td><?=$no?></td>
				<td><?=$col['nm_name_sale']?><!--a href="#" class="link" onclick="viewPopup('seller'); return false;"><?=$col['nm_name_sale']?></a--></td>
				<td><?=$col['nm_brand']." ".$col['nm_model']?></td>
				<td><?=$col['nm_number']?></td>
				<td><?=$col['nm_area']?></td>
				<td><?=$col['nm_price_final_sale']?>만원</td>
				<td><!--a href="#" class="link" onclick="viewPopup('dealer'); return false;">홍길동</a--><?=$col['nm_name_tender']?></td>
				<td><?=$col['dt_end_sale']?></td>
			</tr>
<?
		$i++;
	}
}else{
?>
			<tr>
				<td colspan="8">등록된 정보가 없습니다.</td>
			</tr>
<?
}
?>

		</table>
	</div>

	<div class="paging">
		<?
				$url = "./$list_url?searchtype=$searchtype&searchword=$searchword&cd_dealer=$cd_dealer";
				ListPg1($url ,$PageNo,$PageSize,10,$totalrows,$leftboard[1],$rootpath);
		?>
	</div>

    	<!-- layer popup -->
	<div class="layer_popup dealer_popup">
		<div class="close">팝업닫기</div>
		<div class="cont">
			<div class="dealer_pop_info">
				<div class="photo">
					<img src="/admin/img/@photo.jpg">
					<span><em>입찰담당자</em> 홍길동</span>
				</div>
				<dl>
					<dt>상호</dt>
					<dd>고진상사</dd>
					<dt>주소</dt>
					<dd>서울 성동구 성동</dd>
					<dt>연락처</dt>
					<dd>02-301-3432</dd>
					<dt>매입지역</dt>
					<dd>전체</dd>
				</dl>
			</div>
		</div>
	</div>


        	<!-- layer popup02 -->
	<div class="layer_popup seller_popup" style="top:10%; height:720px">
		<div class="close">팝업닫기</div>
		<div class="cont">

            <div class="tbl_wrap">
		<table class="tbl_list2 ty2">
			<colgroup>
				<col width="12%">
				<col width="38%">
				<col width="12%">
				<col width="38%">
			</colgroup>
			<tr>
				<th>이름</th>
				<td>홍길동</td>
				<th>회원</th>
				<td>비회원</td>
			</tr>
			<tr>
				<th>연락처</th>
				<td>010-1234-5678</td>
				<th>아이디</th>
				<td>jgfgjdjdlgkfjglk</td>
			</tr>
			<tr>
				<th>주소</th>
				<td>서울시 마포구 서교동</td>
				<th>판매지역</th>
				<td>서울</td>
			</tr>
			<tr>
				<th>차량번호</th>
				<td>28부5708</td>
				<th>제조사</th>
				<td>링컨</td>
			</tr>
			<tr>
				<th>모델</th>
				<td>MKX</td>
				<th>세부모델</th>
				<td>뉴MKX(10년~15년)</td>
			</tr>
			<tr>
				<th>등급</th>
				<td>3.7awd</td>
				<th>연식(최초등록일)</th>
				<td>2013년10월</td>
			</tr>
			<tr>
				<th>형식연도</th>
				<td>2013년</td>
				<th>배기량</th>
				<td>3700cc</td>
			</tr>
			<tr>
				<th>변속기</th>
				<td>오토</td>
				<th>연료</th>
				<td>가솔린</td>
			</tr>
			<tr>
				<th>색상</th>
				<td>검정</td>
				<th>주행거리</th>
				<td>78,012km</td>
			</tr>
			<tr>
				<th>사고유무</th>
				<td>
					<div class="radio_chk">
						<span class="check_wrap"><input type="radio" name="radiobutton" id="radio1"><i></i><label for="radio1">사고</label></span>
						<span class="check_wrap"><input type="radio" name="radiobutton" id="radio2"><i></i><label for="radio2">무사고</label></span>
						<span class="check_wrap"><input type="radio" name="radiobutton" id="radio3"><i></i><label for="radio3">모름</label></span>
					</div>
				</td>
				<th>추천인</th>
				<td>없음</td>
			</tr>
			<tr>
				<th>옵션</th>
				<td colspan="3">썬루프, 네비게이션, 통풍시트</td>
			</tr>
			<tr>
				<th>필수사진</th>
				<td colspan="3">
					<ul class="photo_list">
						<li>
							<img src="/admin/img/@img_car.jpg">
							<span>차량전면</span>
						</li>
						<li>
							<img src="/admin/img/@img_car.jpg">
							<span>차량후면</span>
						</li>
						<li>
							<img src="/admin/img/@img_car.jpg">
							<span>운전석 측면</span>
						</li>
						<li>
							<img src="/admin/img/@img_car.jpg">
							<span>조수석 측면</span>
						</li>
						<li>
							<img src="/admin/img/@img_car.jpg">
							<span>계기판</span>
						</li>
					</ul>
				</td>
			</tr>
			<tr>
				<th>추가사진</th>
				<td colspan="3">
					<ul class="photo_list">
						<li><img src="/admin/img/@img_car.jpg"></li>
						<li><img src="/admin/img/@img_car.jpg"></li>
					</ul>
				</td>
			</tr>
		</table>
	</div>


		</div>
	</div>





</section>


<form name="excelForm" id="excelForm" method="GET">
	<input type="hidden" name="searchtype" value="<?=$searchtype?>">
	<input type="hidden" name="searchword" value="<?=$searchword?>">
	<input type="hidden" name="ds_usertype" value="<?=$ds_usertype?>">
	<input type="hidden" name="dt_start" value="<?=$dt_start?>">
	<input type="hidden" name="dt_end" value="<?=$dt_end?>">
	<input type="hidden" name="cd_dealer" value="<?=$cd_dealer?>">
</form>

<script language="javascript" type="text/javascript">

	$("#dt_end_start").datepicker({ dateFormat: 'yy-mm-dd' });
	$("#dt_end_end").datepicker({ dateFormat: 'yy-mm-dd' });

	function setSearchDate(arg1, arg2){
		var dtStart = getSearchDate(arg1, arg2);
		var dtEnd = getSearchDate("day", 0);

		$("#dt_start").val(dtStart);
		$("#dt_end").val(dtEnd);
	}

	$(document).ready(function() {

		$("#btn_cal1").bind("click",function(){
			$("#dt_start").datepicker('show');
		});

		$("#btn_cal2").bind("click",function(){
			$("#dt_end").datepicker('show');
		});
		$("#sel_searchtype div.jq_sel ul li a").bind("click",function(){
			$("#searchtype").val($("#sel_searchtype option:selected").val());

		});

		$("#btn_download_excel").click(function(e) {
			var url = "purchase_view_excel.php?"+$("#excelForm").serialize();
			window.open(url, "excelWin");
		});

	});


	function fnSearch(){
		if($("#searchtype").val()!="" && $("#searchword").val()==""){
			alert("검색어를 입력하세요");
			return false;
		}
		$("#frmSearch").submit();
	}
</script>
<? include("../inc/inc_footer.php") ?>
<? include("../inc/inc_bottom.php") ?>
<?
mysql_close($connect);
?>
