@model IEnumerable<kendoBatchHeaderTest.Models.BatchHeader>

@{
    ViewBag.Title = "Transaction Review";
}

<h2>Batches to Review/Post</h2>

@(Html.Kendo().Grid(Model)
    .Name("BatchGrid")
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:700px" })
    .Columns(columns =>
                {
                    columns.Bound(b => b.BatchID)
                                        .Width("100")
                                        .Title("Batch ID");
                    columns.Bound(b => b.Created_DTTM)
                                        .Width("175")
                                        .Format("{0:MM/dd/yyyy hh:mm tt}")
                                        .Title("Created");
                    columns.Bound(b => b.PostingStatus)
                                        .Width("175")
                                        .Title("Status");
                }
            )
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(40)
        .Read(read => read.Action("FetchBatchCollection", "Home"))
    )
    .ClientDetailTemplateId("transactions")
    //.Events(events => events.DataBound("dataBound"))
)

<!-- Nested grid for transaction object, member of BatchHeader.TranCollection
     There can be many ITransaction objects per BatchHeader -->
<script id="transactions" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<kendoBatchHeaderTest.Models.Transaction>()
            .Name("TranGrid_#=BatchID#")  // makes the sub-grid name unique so that it will be displayed on each child row.
            //.Pageable()
            .Sortable()
            .Scrollable()
            .Pageable()
            .HtmlAttributes(new { style = "height:600px; width:950px" })
            .Columns(columns =>
                {
                    columns.Bound(b => b.BatchID)
                                        .Width("100")
                                        .Title("Batch ID")
                                        .Visible(false);
                    columns.Bound(b => b.TransactionID)
                                        .Width("100")
                                        .Title("Transaction ID");
                    columns.Bound(b => b.TransactionType)
                                        .Width("200")
                                        .Title("Type");
                    columns.Bound(b => b.PostingMessage)
                                       .Width("600")
                                       .Title("Posting Message");
                }
            )
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(5)
                .Read(read => read.Action("FetchTransactionCollection", "Home", new { batchID = "#=BatchID#" }))
            )
            .ClientDetailTemplateId("detailTransactions")
            //.Events(events => events.DataBound("dataBound"))
            .ToClientTemplate()
            )

</script>

<!-- Nested grid for detail transaction object. There is only one per transaction object but there are many different transaction types -->
<script id="detailTransactions" type="text/kendo-tmpl">
    #if (data.TransactionType == 0) { # 
        @(Html.Kendo().Grid<kendoBatchHeaderTest.Models.IssueTransaction>()
                .Name("IssueTran_#BatchID#_#TransactionID#_#TransactionType#")
                .HtmlAttributes(new { style = "height:100px; width:900px" })
                .Columns( columns =>
                        {
                            columns.Template(@<text></text>)
                                                .Width("100px")
                                                .ClientTemplate("<a href='/Home/IssueDetails/#=BatchID#_#=TransactionID#'>Details</a>");
                            columns.Bound(b => b.BatchID)
                                                .Visible(false);                                       
                            columns.Bound(b => b.ID)
                                                .Visible(false);
                            columns.Bound(b => b.StoreroomID)
                                               .Width("200")
                                               .Title("Storeroom");
                            columns.Bound(b => b.ItemID)
                                               .Width("300")
                                               .Title("Item ID");
                            columns.Bound(b => b.QuantityIssued)
                                               .Width("100")
                                               .Title("Qty Issued");
                            columns.Bound(b => b.IssueUnitOfMeasure)
                                               .Width("100")
                                               .Title("UOM");
                            columns.Bound(b => b.IssuedToEmployee)
                                               .Width("200")
                                               .Title("Issued To");
                            columns.Bound(b => b.IssueValue)
                                               .Width("100")
                                               .Title("Value");
                            columns.Bound(b => b.WorkOrderID)
                                               .Width("100")
                                               .Title("WorkOrder");
                            columns.Bound(b => b.EntityID)
                                               .Width("200")
                                               .Title("Entity");
                        }
                 )
                .Scrollable()
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(1)
                    .Read(read => read.Action("FetchDetailTransaction", "Home",
                                                new
                                                {
                                                    batchID = "#=BatchID#",
                                                    tranID = "#=TransactionID#",
                                                    trantype = "#=TransactionType#"
                                                }
                                             )
                    )
                )
                .ToClientTemplate()
        )
    #} else if(data.TransactionType == 1) { #
        @(Html.Kendo().Grid<kendoBatchHeaderTest.Models.CycleCountTran>()
                .Name("CycleCountTran_#BatchID#_#TransactionID#_#TransactionType#")
                .HtmlAttributes(new { style = "height:100px; width:900px; v-align:top" })
                .Columns( columns =>
                        {
                            columns.Template(@<text></text>)
                                                .Width("100px")
                                                .ClientTemplate("<a href='/Home/CycleCountDetails/#=BatchID#_#=TransactionID#'>Details</a>");
                            columns.Bound(b => b.BatchID)
                                                .Visible(false);
                            columns.Bound(b => b.ID)
                                                .Visible(false);
                            columns.Bound(b => b.StoreroomID)
                                               .Width("200")
                                               .Title("Storeroom");
                            columns.Bound(b => b.ItemID)
                                               .Width("300")
                                               .Title("Item ID");
                            columns.Bound(b => b.QuantityCounted)
                                               .Width("100")
                                               .Title("Qty Counted");
                            columns.Bound(b => b.CountUnitOfMeasure)
                                               .Width("100")
                                               .Title("UOM");
                            columns.Bound(b => b.QuantityExpected)
                                               .Width("100")
                                               .Title("Qty Expected");
                            columns.Bound(b => b.QuantityVariance)
                                               .Width("100")
                                               .Title("QuantityVariance");
                            columns.Bound(b => b.DateCounted)
                                               .Width("200")
                                               .Title("DateCounted");
                        }
                 )
                .Scrollable()
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(1)
                    .Read(read => read.Action("FetchDetailTransaction", "Home",
                                                new
                                                {
                                                    batchID = "#=BatchID#",
                                                    tranID = "#=TransactionID#",
                                                    trantype = "#=TransactionType#"
                                                }
                                             )
                    )
                )
                .ToClientTemplate()
        )
    #} else if(data.TransactionType == 2) { #
        @(Html.Kendo().Grid<kendoBatchHeaderTest.Models.LocationChangeTran>()
                .Name("LocChangeTran_#BatchID#_#TransactionID#_#TransactionType#")
                .HtmlAttributes(new { style = "height:100px; width:900px" })
                .Columns( columns =>
                        {
                            columns.Template(@<text></text>)
                                                .Width("100px")
                                                .ClientTemplate("<a href='/Home/LocChangeDetails/#=BatchID#_#=TransactionID#'>Details</a>");
                            columns.Bound(b => b.BatchID)
                                                .Visible(false);
                            columns.Bound(b => b.ID)
                                                .Visible(false);
                            columns.Bound(b => b.StoreroomID)
                                               .Width("100")
                                               .Title("Storeroom");
                            columns.Bound(b => b.ItemID)
                                               .Width("300")
                                               .Title("Item ID");
                            columns.Bound(b => b.OldPrimaryLocation)
                                               .Width("200")
                                               .Title("Old Primary  Location");
                            columns.Bound(b => b.NewPrimaryLocation)
                                               .Width("200")
                                               .Title("New Primary Location");
                            columns.Bound(b => b.OldSecondaryLocation)
                                               .Width("200")
                                               .Title("Old Secondary Location");
                            columns.Bound(b => b.NewSecondaryLocation)
                                               .Width("200")
                                               .Title("New Secondary Location");
                            columns.Bound(b => b.OldTertiaryLocation)
                                               .Width("200")
                                               .Title("Old Tertiary Location");
                            columns.Bound(b => b.NewTertiaryLocation)
                                               .Width("200")
                                               .Title("New Tertiary Location");
                        }
                 )
                .Scrollable()
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(1)
                    .Read(read => read.Action("FetchDetailTransaction", "Home",
                                                new
                                                {
                                                    batchID = "#=BatchID#",
                                                    tranID = "#=TransactionID#",
                                                    trantype = "#=TransactionType#"
                                                }
                                             )
                    )
                )
                .ToClientTemplate()
        )
    #} #
</script>

<script type="text/javascript">
   function dataBound() {
        this.expandRow(this.tbody.find("tr.k-master-row").first());
    }
</script>
        