<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList" %>
<%@page import="model.CartMod" %>
<%@page import="model.CartProduct" %>
<%
   Object obj=session.getAttribute("giohang");
if(obj!=null){
       CartMod giohang=(CartMod)obj;
       ArrayList<CartProduct> Listpd=giohang.getGiohang();
       String user = (String)session.getAttribute("user");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="images/pay.css" />
<script type="text/javascript" src="js/pay.js"></script>
<script>
function printbill(){
	window.open("printbill.jsp","PrintBill","width=550px; height=450px;");
	
}
document.getElementById("titleCustomer").innerHTML = "Thanh Toán";
</script>
<title>Hoa Don Cua Toi</title>
</head>
<body>

<% if (user==null) {%>
<div align="Center" style="border:1px solid #cfcfcf;padding:20px 10px 20px 10px;background-color:#f3f3f3; width:410px ">
<a href="index.jsp?customer=attempt">Vui Lòng Đăng Nhập Để Thanh Toán Hóa Đơn</a>
</div>
<%} else {%>
<% if(Listpd.size() > 0){ String billlist = "";
%>
<Br>
<center>
<B>HÓA ĐƠN MUA HÀNG</B></center>
(Khách hàng: <%= user %>)
<br>
<br>
<table class = "tablext" border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="silver" cellpadding="3">
    <tr>
        <th style="background: #E3E3E3">STT</th>
        <th style="background: #E3E3E3">Mã Sản Phẩm</th>
        <th style="background: #E3E3E3">Tên Món Hàng</th>
        <th style="background: #E3E3E3">Đơn Giá</th>
        <th style="background: #E3E3E3">Số Lượng</th>
        <th style="background: #E3E3E3">Thành Tiền</th>
    </tr>
    <%int i=1;
    for(CartProduct pd:Listpd){   	
        String id=pd.getSanpham().getId();
        String name=pd.getSanpham().getName();
        double price=pd.getSanpham().getPrice();
        int quantity=pd.getSoluong();
        billlist+="#"+id+"x"+quantity+" ";
        double amount = price*quantity;
        %>
        <tr>
            <td align="center"><%=(i++)%></td>
            <td>#<%=id%></td>
            <td><%=name%></td>
            <td><%= Math.round(price)%> vnđ</td>
            <td><%= quantity%></td>
            <td><%= Math.round(amount)%> vnđ</td>
        </tr>
    <%}%>
    <tr>
        <td align="right" colspan="6">Tổng Cộng: <b><%= Math.round(giohang.Tongtien())%></b> vnđ
        <br><a href="javascript: printbill()"><i>(In hóa đơn này)</i></a>
        </td>
    </tr>
    </table>
	<br>
<% session.setAttribute("billlist",billlist); %>
<jsp:include page="pay.jsp"></jsp:include> 
	
	
	<br><br><br>
   <%} else {%> 
<div align="Center" style="border:1px solid #cfcfcf;padding:20px 10px 20px 10px;background-color:#f3f3f3; width:410px "><b>Không Có Món Hàng Nào Trong Giỏ Hàng Để Tính Tiền</b></div>
   <% }} }%>
   </body></html>
