<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="mainapp.User"%>
<%@page import="java.util.Iterator"%>
<%@page import="mainapp.Factory"%>
<%@page import="mainapp.Production"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
  ArrayList productions = new ArrayList();
  
  if (session.getAttribute("userId") != null)
    productions = Production.getAllProductionsForUser(Integer.parseInt((String)session.getAttribute("userId")));
%>
<table class="info-table">
    <tr><th>Εργοστάσιο</th><th>Ημ/νία</th><th>Ελιές(kg)</th><th>Λάδι(kg)</th>
        <th>Οξύτητα</th><th>BIO</th><th>Αλεστικά(&euro;)</th><th>Τιμή</th>
    <th width="15%"></th></tr>
    <%
        Iterator i;
        i = productions.iterator();
        Production p = null;
        while (i.hasNext()) {
            p = (Production)i.next();
            Factory factory = new Factory(p.getFactoryID());
            User u = new User(p.getProducerID());
            long ll = Long.parseLong(p.getTimestamp());
            Date date = new java.util.Date((long)ll*1000);
            DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
            
            String calcButton = "";
            if (p.isSold() == false)
                calcButton = "<a class='calc_button' href='javascript:void(0)' onclick='alert(\"Αξία παραγωγής με τρέχουσες τιμές: "+p.calculateSellingPrice()+" €\")'>Υπολογισμός Αξίας</a>";
            else 
                calcButton = "Πωλήθηκε";
            out.print("<tr><td>"+
                    factory.getName()+"</td><td>"+format.format(date)+"</td><td>"+
                    p.getOlivesWeight()+"</td><td>"+
                    p.getOilWeight()+"</td><td>"+
                    p.getAcidity()+"</td><td>"+
                    (p.isBio() ? "ναι" : "όχι")+"</td><td>"+
                    p.getCosts()+"</td><td>"+
                    p.getSoldPrice()+"</td>"+
                    "<td class='text-center'>"+
                    calcButton+
                    "</td></tr>");
        }
    %>
</table>