<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="mainapp.User"%>
<%@page import="mainapp.Factory"%>
<%@page import="java.util.Iterator"%>
<%@page import="mainapp.Production"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    Factory f = new Factory(Integer.parseInt(request.getParameter("factory_id")));
    ArrayList<Production> productions = f.getAllProductions();
%>
<h1 style="text-align: center"><% out.print(f.getName()); %> - Παραγωγή </h1>
<hr /><br />
<h6 class="form_error" style="text-align: center">
<%
    if (request.getParameterMap().containsKey("del")) {
        out.print("Η παραγωγή διαγράφηκε επιτυχώς");
    }
%>
</h6>
<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="10%">Λειτουργίες</th></tr>
    <%
        Iterator i;
        i = productions.iterator();
        Production p = null;
        while (i.hasNext()) {
            p = (Production)i.next();
            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 sold_icon = "";
            if (p.isSold()) 
                sold_icon = "<a class='orange' title='αναίρεση πώλησης' href='"+request.getContextPath()+"/UnsellProductionAction?production_id="+p.getID()+"'><i class='fa fa-minus-square'></i></a> ";
            else
                sold_icon = "<a class='green' title='πωλήθηκε' href='"+request.getContextPath()+"/SoldProductionAction?production_id="+p.getID()+"'><i class='fa fa-check-square'></i></a> ";
            out.print("<tr><td>"+
                    u.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='actions text-center'>"+
                    sold_icon+
                    "<a class='red' title='διαγραφή' href='"+request.getContextPath()+"/DeleteProductionAction?production_id="+p.getID()+"'><i class='fa fa-times'></i></a> "+
                    "</td></tr>");
        }
    %>
</table>
