<% content_for :page_menu do %>
 	<ul class="list-sidebar">
    <li class="item-sidebar"><a class="btn-sidebar" href="/cpanel/sites"><i class="fa fa-home" aria-hidden="true"></i><%= t("client_management.my_sites") %></a></li>
    <li class="item-sidebar"><a class="btn-sidebar" href="<%= cpanel_myprofile_path %>"><i class="fa fa-address-card" aria-hidden="true"></i><%= t("client_management.profile") %></a></li>
    <li class="item-sidebar active"><a class="btn-sidebar" href="<%= cpanel_myhistory_path %>"><i class="fa fa-history" aria-hidden="true"></i><%= t("client_management.history") %></a></li>
    <li class="item-sidebar"><a class="btn-sidebar" href="#"><i class="fa fa-question-circle-o" aria-hidden="true"></i><%= t("client_management.help_and_faq") %></a></li>
    <li class="item-sidebar"><a class="btn-sidebar" href="#"><i class="fa fa-user-circle-o" aria-hidden="true"></i><%= t("client_management.get_in_contact") %></a></li>
  </ul>
<% end %>
 <section class="cp-content col-md-10">
  <h2 class="cp-page-title">
    Contract info
  </h2>
  <div class="cp-contract-detail">
    <div class="sub-title ft">Contract info</div>
    <div class="line-contract">
      <span class="header-detail">Contract Number :</span>
      <span class="content-detail"><%= @contract.uid %></span>
    </div>
    <div class="line-contract">
      <span class="header-detail">Contract Date :</span>
      <span class="content-detail"><%= @contract.created_at.strftime("%d %B %Y") %></span>
    </div>
    <div class="line-contract">
      <span class="header-detail">Contract Status :</span>
      <span class="content-detail">
      <% if @contract.confirmed %>
      	<span class="cf-yes label label-success">Confirmed</span>
      <% else %>
      	<span class="cf-no label label-danger">Not-Confirmed</span>
      <% end %>
      </span>
    </div>
    <div class="sub-title">Request</div>
    <div class="line-contract">
      <span class="header-detail">Type :</span>
      <span class="content-detail"><%= @site_request.get_request_type %></span>
    </div>
    <% if @site_request.type == "existing" %>
	    <div class="sub-title">Site Info</div>
	    <div class="line-contract">
	      <span class="header-detail">Site ID :</span>
	      <span class="content-detail"><%= @site_request.get_site.uid %></span>
	    </div>
	    <div class="line-contract">
	      <span class="header-detail">Site Name :</span>
	      <span class="content-detail"><%= @site_request.get_site.title %></span>
	    </div>
	    <div class="line-contract">
	      <span class="header-detail">Site Domain :</span>
	      <span class="content-detail"><a href="<%= @site_request.get_site.site_domain %>" target="_blank"><%= @site_request.get_site.site_domain %></a></span>
	    </div>
    <% end %>
    <% if !@contract.contract_file.url.nil? || !@contract.signed_contract_file.url.nil? %>
	    <div class="sub-title">Contract Files</div>
	    <% if !@contract.contract_file.url.nil?  %>
		    <div class="line-contract">
		      <span class="header-detail">Contract :</span>
		      <span class="content-detail"><a href="<%= @contract.contract_file.url %>" target="_blank">Download</a></span>
		    </div>
		  <% end %>
		  <% if !@contract.signed_contract_file.url.nil?  %>
		    <div class="line-contract">
		      <span class="header-detail">Contract Signed :</span>
		      <span class="content-detail"><a href="<%= @contract.signed_contract_file.url %>" target="_blank">Download</a></span>
		    </div>
		  <% end %>
	  <% end %>

    <div class="sub-title">Quotaion</div>

    <div class="line-contract qt">
      <span class="header-detail">Item</span>
      <span class="content-detail">Cost in NTD.</span>
    </div>
		<% total_amount = 0 %>
		<% ["new_site_cost","hosting_with_rulingdigital_cost","service_cost","option_module_cost","customized_module_cost","template_cost","customized_template_cost","rwd_cost"].each do |attrib| %>
			<% amount = @contract.send(attrib.to_sym) %>
			<% if amount > 0 %>
		    <div class="line-contract qt">
		      <% if attrib == "option_module_cost" %>
		      	<span class="header-detail"><%= t("client_management.#{attrib}") %>
			      	<ol class="custom-module">
				      	<% rsm = RegisteredModule.find(@site_request.optional_modules) %>
								<% rsm.each do |rs|%>
									<li><%= rs.name %></li>
								<% end %>
							</ol>
						</span>
		      <% else %>
		      	<span class="header-detail">
		      		<%= t("client_management.#{attrib}") %>
		      		<% if attrib == "service_cost" %>
						 		for <%= @site_request.maintenance_years rescue 1 %> year(s)
							<% end %>	
		      	</span>
		      <% end %>
		      <span class="content-detail"><%= amount %></span>
		    </div>
		  <% end %>
		  <% total_amount = total_amount + amount %>
    <% end %>
		<% if !@contract.other.nil? || @contract.other_cost > 0 %>
	 		<div class="line-contract qt">
					<span class="header-detail">
						Other Requirements
						<div class="requirement-text">
							<%= nl2br(@contract.other) %>
						</div>
					</span>
					<span class="content-detail"><%= @contract.other_cost %></span>
			</div>
			<% total_amount = total_amount + @contract.other_cost %>
	 	<% end %>
		<div class="line-contract qt hr">
      <span class="header-detail">Total :</span>
      <span class="content-detail"><%= total_amount %></span>
    </div>
  
  <% if !@contract.confirmed %>
		<%= form_for @contract, :url => "/cpanel/contract/#{@contract.uid}/update_contract" do |f| %>
	    <div class="line-contract file">
	      <span class="header-detail">Signed Contract File :</span>
	      <span class="content-detail">
	        <%= f.file_field :signed_contract_file, :class=>"file-box" %>
	        <input class="btn btn-primary" name="commit" value="Upload" type="submit">
	      </span>
	    </div>
		<% end %>
	<% end %>

  	<div class="line-contract buttons">
    	<% if !@contract.confirmed && !@contract.signed_contract_file.url.nil? %>
      	<a href="/cpanel/contract/<%= @contract.uid %>/confirm?ref=contract_page&page=<%= params[:page] %>" class="btn btn-success confirm-btn">Confirm Contract</a>
    	<% end %>
    	<div class="pull-right">
      	<a href="#" class="btn btn-info">Export Contract</a>
      	<a href="<%= cpanel_mycontracts_path %>" class="btn btn-gray">Back to Contracts</a>
      </div>
    </div>
  </div>
</section>
<script type="text/javascript">
	$(".confirm-btn").on("click",function(){
		if(!confirm("Are you sure?")){
      return false;
    }
	})
</script>