<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorate="~{admin/layout/layout}" th:with="title='',active='home'">
<th:block layout:fragment="html_head">
	<script>
	
	function goPage(pageNo){
		var form = document.searchVO;
		form.page.value = pageNo;	
		form.action = "/cash/chargeWait";
		form.submit();
	}
	
	function goSearch(){
		
		var form = document.searchVO;
		form.page.value = 1;	
		form.action = "/cash/chargeWait";
		form.submit();
	}
	
		function creditStatusUpdate(creditIdx, status){
			
			
	        	 $.ajax({
	     			type : "post",
	     			url : "/cash/statusUpdate",
	     			data : {
	     				creditIdx:creditIdx,
	     				creditStatus:status	     				
	     				
	     			},
	     			async : false,
	     			dataType : "json",
	     			success : function(data) {
	     				if(data.RES=="SUCCESS"){
	     					$('#tr'+creditIdx).remove();
	     					alert("처리완료");
	     				}else{
	     					
	     				}
	     				
	     			}
	     		});
			
			
		}
	</script>
</th:block>
<th:block layout:fragment="content">

            <div class="container-fluid">
              <div class="page-name">
                  <h1>컴퍼니 관리</h1>
              </div>
              <ul class="tabletab">   
                <li><a th:class="${searchVO.creditStatus == '0' } ? active : ''" href="/cash/chargeWait?creditStatus=0" class="active" >지급신청</a></li>
                <li><a th:class="${searchVO.creditStatus == '2' } ? active : ''" href="/cash/chargeWait?creditStatus=2" class="" >지급대기</a></li>
                <li><a th:class="${searchVO.creditStatus == '1' } ? active : ''" href="/cash/chargeWait?creditStatus=1" class="" >지급완료</a></li>
                <li><a th:class="${searchVO.creditStatus == '-1' } ? active : ''" href="/cash/chargeWait?creditStatus=-1" class="" >지급거절</a></li>
              </ul>
              <form class="searchWrap-form" name="searchVO">
                  <input type="hidden" id="page" name="page" th:value="${searchVO.page}"/>
                  <input type="hidden" id="page" name="creditStatus" th:value="${searchVO.creditStatus}"/>
	              <div class="tableserachwrap">
		              <div>
		                  <ul class="tableserach">
		                    <li>
		                      <div class="input-group">
		                        <div>
		                          <label class="input-group-text">에이전시 아이디</label>
		                        </div>
		                        <input type="text" name="searchSiteId" th:value="${searchVO.searchSiteId}" >
		                      </div>
		                    </li>
		                    <li>
		                      <div class="input-group">
		                        <div>
		                          <label class="input-group-text">기간</label>
		                        </div>
		                        
		                        <input class="br0" type="date" name="startDate" th:value="${searchVO.startDate}"/>
		                     	<input type="date" name="endDate" th:value="${searchVO.endDate}"/>
		                      </div>
		                    </li>
		                    <li>
		                  		<a class="btn" href ="javascript:goSearch()">전체검색</a>
		              		</li>
		                  </ul>	  
	                  </div>
                  </div>              
              </form>

              <div class="table">
                <div class="head"><h6>PT 신청내역</h6></div>
                <div class="body">
                  
                  <div class="table-responsive">
                    <table>
                      <thead>
                        <tr>
                          <th>컴퍼니 아이디</th>
                          <th>처리 전 C</th>
                          <th>신청 C</th>
                          <th>수수료율</th>
                          <th>서브포인트</th>
                          <th>수수료</th>
                          <th>처리 후 PT</th>
                          <th>신청일</th>
                          <th>상태</th>
                          <th>옵션</th>
                        </tr>
                      </thead>
                      <tbody>
                      
                      	<th:block th:each="list,seq : ${list}">
							<tr th:id="|tr${list.creditIdx}|">
							
	                        <td th:text="${list.targetSiteId}">받는 에이전시명</td>	                      
	                  		<td th:text="|${#numbers.formatInteger(list.preCreditAmt, 0, 'COMMA')}|">충전 전 잔액</td>
	                        <td th:text="|${#numbers.formatInteger(list.creditAmt, 0, 'COMMA')}|">요청 크레딧</td>
	                        <td th:text="|${list.creditRate}%|">요율</td>
	                         <td th:text="|${#numbers.formatInteger(list.get('pointAmt'), 0, 'COMMA')}|">요율</td>
	                        <td  th:text="|${#numbers.formatInteger(list.cash, 0, 'COMMA')}|"></td>
	                        <td th:text="|${#numbers.formatInteger(list.preCreditAmt + list.creditAmt , 0, 'COMMA')}|">충전 후 잔액1</td>
	                        <td th:text="${#temporals.format(list.regDate, 'yyyy-MM-dd HH:mm:ss')}">요청 시각</td>
	                        
	                        <td>
	                        	<span th:if="${list.creditStatus eq '0' }" th:text="신청"></span>
	                        	<span th:if="${list.creditStatus eq '1' }" th:text="완료"></span>
	                        	<span th:if="${list.creditStatus eq '2' }" th:text="대기"></span>
	                        	<span th:if="${list.creditStatus eq '-1' }" th:text="거절"></span>
	                        </td>
	                
	                        <td>
	                        	<a th:if="${list.creditStatus eq '0' }" th:text="대기" th:href="|javascript:creditStatusUpdate(${list.creditIdx},2)|"></a>
	                        	
	                        		<th:block th:if="${list.creditStatus eq '2' }">
	                        			<a  th:text="승인" th:href="|javascript:creditStatusUpdate(${list.creditIdx},1)|"></a> | <a  th:text="거절" th:href="|javascript:creditStatusUpdate(${list.creditIdx},-1)|"></a>
	                        		
	                        		</th:block>
	                        	
	                        	
	                        	<span th:if="${list.creditStatus eq '1' }" th:text="완료"></span>
	                        </td>
	                        </tr>
						</th:block>
                                            
                        
                      </tbody>
                      
                    </table>
                      <th:block th:utext="${pageInfo}"></th:block>
                  </div>
                </div>
              </div>

            </div><!-- container-fluid -->

</th:block>
