📊 balancesHoursModal.cshtml Documentation

Welcome to the comprehensive documentation for IrbyImaging/Views/IView/balancesHoursModal.cshtml. This Razor View renders a modal grid displaying job-related labor hours, complete with export capabilities (CSV, Excel, Print) via DataTables. Below you’ll find a detailed overview, code breakdowns, usage examples, and more.


Table of Contents

  1. ✨ Overview & Purpose
  2. ⚙️ Dependencies & Technologies
  3. 📦 Model & ViewModel
  4. 🔑 Key Functional Areas
  5. 🔄 Data Flow & Binding
  6. 🚀 Usage Example
  7. 📝 Conclusion

✨ Overview & Purpose

balancesHoursModal.cshtml is an ASP.NET MVC Razor Partial View used to display a modal table of job balances and man-hours. It provides:

  • Tabular listing of job numbers, names, time periods, cost codes, and man-hours.
  • Export buttons for CSV, Excel, and Print.
  • Responsive and styled using DataTables and Bootstrap.

This component is typically invoked from a controller action or another view to present detailed labor-hour information in a modal dialog.


⚙️ Dependencies & Technologies

Technology / Library Version (approx.) Purpose
ASP.NET MVC Razor 5.x / Core 2.x+ Server-side View Engine
jQuery 3.5.x DOM manipulation
DataTables 1.10.25 Enhanced HTML tables (sorting, paging, export)
DataTables Buttons 1.7.1 Export buttons (CSV, Excel, Print)
JSZip 3.1.3 In-browser ZIP generation (Excel export)
pdfmake & vfs_fonts 0.1.53 PDF generation
Bootstrap 4 (CSS/JS) 4.x Table styling

Note: There are commented-out references to Syncfusion controls. They are currently disabled but indicate possible prior use of a Syncfusion Grid.


📦 Model & ViewModel

@model IrbyImaging.UI.Models.Balances
  • Model: Balances
    • Details: A collection (IEnumerable<Detail>) where each Detail contains:
      • JobNumber (string)
      • JobName (string)
      • ReportingYear (int)
      • ReportingMonth (int)
      • CostCode (string)
      • CostCodeDescription (string)
      • ManHours (decimal)

This model is populated in the corresponding controller action before rendering the view.


🔑 Key Functional Areas

4.1 HTML Layout & Razor Syntax

<div class="row" style="width:100%">
  <div id="ControlRegion">
    <!-- DataTables HTML table -->
    <table id="jobDatatable" class="table table-striped table-bordered dt-responsive nowrap">
      <thead>
        <tr>
          <th>Job Number</th>
          <th>Job Name</th>
          <th>Year</th>
          <th>Month</th>
          <th>Cost Code</th>
          <th>Description</th>
          <th>Man Hours</th>
        </tr>
      </thead>
      <tbody>
        @foreach (var item in Model.Details) {
          <tr>
            <td>@Html.DisplayFor(m => item.JobNumber)</td>
            <td>@Html.DisplayFor(m => item.JobName)</td>
            <td>@Html.DisplayFor(m => item.ReportingYear)</td>
            <td>@Html.DisplayFor(m => item.ReportingMonth)</td>
            <td>@Html.DisplayFor(m => item.CostCode)</td>
            <td>@Html.DisplayFor(m => item.CostCodeDescription)</td>
            <td>@Html.DisplayFor(m => item.ManHours)</td>
          </tr>
        }
      </tbody>
    </table>
  </div>
</div>
  • Uses Bootstrap classes for responsive, styled tables.
  • Loops through Model.Details to render each row.

4.2 DataTables Integration

  1. CSS references:
    <link href="~/lib/datatables/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
    <link href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css" rel="stylesheet" />
    <link href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.dataTables.min.css" rel="stylesheet" />
    
  2. JS references:
    <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.print.min.js"></script>
    
  3. Initialization:
    <script>
      $(document).ready(function () {
        $('#jobDatatable').DataTable({
          dom: 'Bfrtip',
          buttons: ['csv', 'excel', 'print']
        });
      });
    </script>
    
    • dom: 'Bfrtip' places the Buttons (B) at the top.
    • Buttons: CSV, Excel, Print.

4.3 Styling (CSS)

<style>
  /* Ensure table headers stick when printing or paginating */
  #jobDatatable { display: table-header-group; }
</style>
  • Forces the table header to be recognized properly for PDF/Print exports.

4.4 JavaScript Initialization

  • The script waits for jQuery document.ready event.
  • Binds DataTables with export buttons.
  • No custom event handlers beyond default DataTables APIs.

🔄 Data Flow & Binding

sequenceDiagram
  participant Controller
  participant ViewEngine
  participant View (balancesHoursModal.cshtml)
  participant DataTables (Browser)

  Controller->>ViewEngine: return PartialView("balancesHoursModal", model)
  ViewEngine->>View: render HTML + DataBindings
  View->>Browser: send HTML/CSS/JS
  Browser->>DataTables: init($('#jobDatatable'))
  DataTables->>Browser: render interactive table + Buttons
  1. Controller prepares Balances model.
  2. Razor Engine merges model into view.
  3. Browser loads HTML, CSS, JS.
  4. DataTables initializes, adds sorting, filtering, export.

🚀 Usage Example

Controller Snippet

public ActionResult ShowBalancesModal()
{
    var model = new Balances {
      Details = _balanceService.GetBalanceDetails(userId)
    };
    return PartialView("balancesHoursModal", model);
}

Invoking from a View

<!-- Trigger a Bootstrap Modal load via AJAX -->
<button id="openBalances" class="btn btn-primary">View Hours</button>

<script>
  $('#openBalances').click(function() {
    $('#myModal .modal-body')
      .load('@Url.Action("ShowBalancesModal")')
      .modal('show');
  });
</script>

📝 Conclusion

balancesHoursModal.cshtml is a self-contained Razor Partial View that delivers an interactive, exportable grid of job man-hours.
Key benefits:

  • Clean separation: MVC View with strongly typed model.
  • Rich features: Sorting, paging, export (CSV/Excel/Print).
  • Responsive: Leverages Bootstrap & DataTables.

Feel free to extend styling or hook into DataTables events (e.g., initComplete) to add custom behaviors! 🎉


End of Documentation