<% layout('../layouts/main') -%>

<!-- DataTables -->
<% stylesheet('/css/dataTables.bootstrap.min.css') %>

<!-- DataTables -->
<% script('/js/jquery.dataTables.min.js') %>
<% script('/js/dataTables.bootstrap.min.js') %>

<% block('custom_scripts', `
<script>
  $(document).ready(function() {
    var a = [];
    $("#example1 tbody tr").each(function() {
        a.push($(this).find("td:last-child").attr('value'));
    });
    if(a.includes("false")) {
        $('#done').attr("href","/order/orderStatus/re-evaluate/" + $('#orderId').val());
    } else {
        $('#done').attr("href","/order/orderStatus/confirm/" + $('#orderId').val());
    }
  })

  $(document).ready(function () {
      $('#example1').DataTable({
          "aoColumnDefs": [
             {'bSortable': false, 'aTargets': [9]},
//              //{"aTargets": [3], "sClass": "text-justify"},
//              {"sClass": "center", "aTargets": [1, 2]},
              {"width": "9%", "targets": [0]},
            //   {"width": "15%", "targets": [3]},
//              {"width": "8%", "targets": [8]},
//                  //{"width": "9%", "targets": [7]},
          ],
          "paging": false,
          "lengthChange": true,
          "searching": true,
          "ordering": true,
          "info": true,
          "autoWidth": false
      });
  });
</script>
`) %>


<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        Items Ordered
        <!--<small>advanced tables</small>-->
    </h1>
    <ol class="breadcrumb">
        <li><a href="/dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="/order"><i class="fa fa-dashboard"></i> Order</a></li>
        <li class="active">Items</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <% if (Object.prototype.hasOwnProperty.call(flash, 'success')) { %>
    <div class="alert alert-success alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <%= flash.success %>
    </div>
    <% } %>
    <% if (Object.prototype.hasOwnProperty.call(flash, 'error')) { %>
    <div class="alert alert-danger alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <%= flash.error %>
    </div>
    <% } %>
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <h3 class="box-title">List of Items</h3>
                    <input id="orderId" value="<%= order %>" type="hidden">
                    <div class="pull-right">
                        <a href="/order" class="btn btn-primary" role="button">Back</a>
                        <a id="done" href="<%= '/order/' + order %>" class="btn btn-primary" role="button">Done</a>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <table id="example1" class="table table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>Sl. No.</th>
                                <th>Item Type</th>
                                <th>Item Name</th>
                                <th>Customer Name</th>
                                <th>Start Date</th>
                                <th>End Date</th>
                                <th>Special Request</th>
                                <th>Quantity</th>
                                <th>Price</th>
                                <th>Available</th>
                            </tr>
                        </thead>
                        <tbody>
                            <% 
                            if(items){
                                for(var i=0; len=items.length, i < len; i++) {
                            %>
                            <tr>
                                <td>
                                    <%= (i+1) %>
                                </td>
                                <td>
                                    <%= items[i].type %>
                                </td>
                                <td>
                                    <%= items[i].item.name %>
                                </td>
                                <td>
                                    <%= items[i].item.clientname %>
                                </td>
                                <td>
                                    <%= items[i].item.startDate %>
                                </td>
                                <td>
                                    <%= items[i].item.endDate %>
                                </td>
                                <td>
                                    <%= items[i].item.sp_request %>
                                </td>
                                <td>
                                    <%= items[i].qty %>
                                </td>
                                <td>
                                    <%= items[i].price %>
                                </td>
                                <% if (items[i].available) { %>
                                <td class="text-center" value="true">
                                    <a href="<%= '/order/available/false/' + order + '/' + items[i]._id %>" class="btn btn-sm btn-success"><span
                                            class="glyphicon glyphicon-ok"></span></a>
                                </td>
                                <% } else { %>
                                <td class="text-center" value="false">
                                    <a href="<%= '/order/available/true/' + order + '/' + items[i]._id %>" class="btn btn-sm btn-danger"><span
                                            class="glyphicon glyphicon-remove"></span></a>
                                </td>
                                <% } %>
                            </tr>
                            <% 
                                }
                            }
                            %>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th>Sl. No.</th>
                                <th>Item Type</th>
                                <th>Item Name</th>
                                <th>Customer Name</th>
                                <th>Start Date</th>
                                <th>End Date</th>
                                <th>Special Request</th>
                                <th>Quantity</th>
                                <th>Price</th>
                                <th>Available</th>
                            </tr>
                        </tfoot>
                    </table>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->
</section>
<!-- /.content -->