📄 ViewInvoice.cshtml Documentation

Welcome to the comprehensive documentation for IrbyImaging/Views/Billing/ViewInvoice.cshtml. This Razor view is part of an ASP.NET Core MVC application and provides a rich interface for searching, viewing, exporting, and managing invoice records. Built with Syncfusion EJ2 TreeGrid and Bootstrap, it offers powerful filtering, sorting, paging, and export capabilities.


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Model
  4. Layout & ViewData
  5. Search Form
    • Filtering Fields
    • Anti‑Forgery & Validation
  6. Results Grid (Syncfusion TreeGrid)
    • Configuration & Options
    • Columns Definition
    • Toolbar & Export Actions
    • Templates for Edit/Delete
  7. JavaScript Interactions
    • Instant Search
    • Column Formatting (load())
    • Export Handler (toolbarClick)
    • Grid‑Lines Toggle (onChange)
  8. Styles & CSS
  9. Usage Examples
  10. Sequence Diagram (UML)
  11. Conclusion

1. Overview & Purpose

ViewInvoice.cshtml renders a page that allows users to:

  • Search invoices by carrier, date, customer info, job numbers, etc.
  • View search results in a hierarchical TreeGrid.
  • Export the grid data to Excel, CSV, PDF, or Print.
  • Navigate to create, edit, or delete invoice records.

This page is part of the Billing module and relies on the IrbyImaging.UI.Models.Billing view‑model to supply filter options and search results.


2. Dependencies & Technologies

Category Technology / Library
Front‑end Framework Bootstrap 4 (grid, form controls)
JavaScript Widgets Syncfusion EJ2 TreeGrid & Buttons
Date Picker Styles bootstrap-datepicker
Data Tables Styles DataTables.net (for DataTables CSS, although DataTables is not used)
Icons & Utility Libs MetisMenu, SimpleBar, Waves.js
ASP.NET Core MVC Razor Views, Tag Helpers (asp-for, asp-items, asp-action)
CSRF Protection @Html.AntiForgeryToken()

3. View Model & Data Model

Model Declaration

@model IrbyImaging.UI.Models.Billing

Key Properties in Billing view-model:

Property Type Description
Carrier IEnumerable Dropdown list of carriers
CarriersTypeDetail List<CarrierDetail> Raw list used to build filter options
InvoiceMonth Month (enum) Selected invoice month
InvoiceYear int Filter year
PhoneNumber string Customer phone filter
FirstName, LastName string Customer name filters
JDENumber, JobNumber string Employee / Job number filters
IsEmployeeNumberNull bool Flag to include empty Employee Number
IsJobNumberNull bool Flag to include empty Job Number
SearchResults IEnumerable<InvoiceDto> Results bound to the TreeGrid

4. Layout & ViewData

@{
    ViewData["Title"] = "View";
    Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
  • Layout: _ATSLayout.cshtml provides the overall shell (navigation, footer, styles).
  • Title: Page title set to “View” (usually displayed in the browser tab and header).

5. Search Form

Wrapped in @using (Html.BeginForm()), posting back to the same action.

@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="card">
  <h4>Search Invoices</h4>
  <!-- Repeater pattern used for dynamic groups -->
  <div data-repeater-list="outer-group">
    <div data-repeater-item>
      <!-- Row 1: Carrier & Month -->
      <label>Document Type (Carrier)</label>
      <select asp-for="CarrierId" asp-items="@Model.Carrier"></select>

      <label>Invoice Month</label>
      <select asp-for="InvoiceMonth" asp-items="@Html.GetEnumSelectList<Month>()"></select>

      <!-- Row 2: Year & Phone -->
      ...
    </div>
  </div>
  <button type="submit" class="btn btn-primary">Search</button>
</div>

Filtering Fields

Field Binding UI Control
Document Type (Carrier) asp-for="CarrierId" <select>
Invoice Month asp-for="InvoiceMonth" <select>
Invoice Year asp-for="InvoiceYear" <input>
Phone Number asp-for="PhoneNumber" <input>
First Name / Last Name asp-for="FirstName" / LastName <input>
Employee Number (JDE) asp-for="JDENumber" <input>
Job Number asp-for="JobNumber" <input>
Is Employee Number Empty? asp-for="IsEmployeeNumberNull" <input type="checkbox">
Is Job Number Empty? asp-for="IsJobNumberNull" <input type="checkbox">

Anti‑Forgery & Validation

  • @Html.AntiForgeryToken() prevents CSRF attacks.
  • @Html.ValidationSummary(...) displays any model‑validation errors.

6. Results Grid (Syncfusion TreeGrid)

The search results are displayed using a Syncfusion EJ2 TreeGrid, bound to Model.SearchResults.

<ejs-treegrid id="TreeGrid"
    dataSource="Model.SearchResults"
    childMapping="Children"
    showColumnMenu="true"
    allowReordering="true"
    allowFiltering="true"
    allowSorting="true"
    allowTextWrap="true"
    allowPaging="true"
    width="100%"
    height="100%"
    toolbar="@(new List<string> { "ExcelExport", "CsvExport", "PdfExport", "Print" })"
    toolbarClick="toolbarClick"
    allowExcelExport="true"
    allowPdfExport="true">
  <e-treegrid-pagesettings pageSize="15"></e-treegrid-pagesettings>
  <e-treegrid-filtersettings type="Excel"></e-treegrid-filtersettings>
  <e-treegrid-columns>
    <!-- Column definitions go here -->
  </e-treegrid-columns>
</ejs-treegrid>

Column Definitions

Field Header Text Type Width Filtering Sorting Template
InvoiceYearMonth Invoice Year Month string 160 ✓ ✓ —
CarrierName Carrier string 130 ✓ ✓ —
PhoneNumber Phone Number string 120 ✓ ✓ —
JDENumber Employee# string 150 ✓ ✓ —
EmployeeName Name string 230 ✓ ✓ —
JobNumber Job Number string 140 ✓ ✓ —
JobName Job Name string 250 ✓ ✓ —
Charge Charge number 180 ✓ ✓ —
Edit Edit action 120 ✓ ✓ #edittemplate
Delete Delete action 120 ✓ ✓ #deletetemplate

Templates for Edit/Delete

<script id="edittemplate" type="text/x-template">
  <a target="_blank" href="/Billing/Edit/${Id}">Edit</a>
</script>
<script id="deletetemplate" type="text/x-template">
  <a target="_blank" href="/Billing/Delete/${Id}">Delete</a>
</script>
  • ${Id} is replaced with the invoice record’s identifier at runtime.

7. JavaScript Interactions

document.getElementById('Search').addEventListener('click', function () {
  var val = document.getElementById('searchText').value;
  var treegrid = document.getElementById('TreeGrid').ej2_instances[0];
  treegrid.search(val);
});
  • Purpose: Filters the TreeGrid in‑place based on the searchText input.

2. Column Formatting (load())

function load() {
  var treegridObj = document.getElementById("TreeGrid").ej2_instances[0];
  treegridObj.columns.forEach(col => {
    if (col.field === "JobDate" || col.field === "DocumentType") {
      col.format = { type: 'date', format: 'M/d/yyyy' };
    }
  });
}
  • Purpose: Applies a date format to specific columns when the grid loads.

3. Export Handler (toolbarClick(args))

var collapsedStatePersist = true;

function toolbarClick(args) {
  var treeGridObj = document.getElementById("TreeGrid").ej2_instances[0];

  if (args.item.id.endsWith('_excelexport')) {
    treeGridObj.excelExport({ isCollapsedStatePersist: collapsedStatePersist });
  } 
  else if (args.item.id.endsWith('_pdfexport')) {
    treeGridObj.pdfExport({ isCollapsedStatePersist: collapsedStatePersist });
  } 
  else if (args.item.id.endsWith('_csvexport')) {
    treeGridObj.csvExport();
  }
}
  • collapsedStatePersist determines if TreeGrid group states persist after export.

4. Grid‑Lines Toggle (onChange(e))

function onChange(e) {
  var treegrid = document.getElementById("TreeGrid").ej2_instances[0];
  treegrid.gridLines = e.value; // e.value could be 'Both', 'None', etc.
}
  • Purpose: Dynamically change the grid‑lines setting (solid lines, no lines, etc.).

8. Styles & CSS

@section styles {
  <link href="~/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" />
  <link href="~/libs/datatables.net-bs4/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
  <link href="~/libs/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css" rel="stylesheet" />
  <link href="~/libs/datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css" rel="stylesheet" />
}
<style>
  #property td div.e-checkbox-wrapper {
    padding-left: 0 !important;
    padding-top: 0 !important;
  }
</style>
  • Bootstrap‑datepicker: Styling for calendar pickers (if used elsewhere).
  • DataTables CSS: Included for consistency but the view uses Syncfusion TreeGrid.
  • Custom CSS: Tweaks checkbox padding within a hypothetical #property table.

9. Usage Examples

  1. Navigate to /Billing/View.
  2. Select a carrier from the Document Type dropdown.
  3. Pick a month (Invoice Month) and enter a year.
  4. Click Search.
  5. Browse results in the TreeGrid.

Example 2: Export to Excel

  1. After running a search, click the ExcelExport button in the grid toolbar.
  2. A .xlsx file downloads with all rows (including collapsed children if (persistState=true)).

10. Sequence Diagram (UML)

sequenceDiagram
  actor User
  participant Browser
  participant BillingController
  participant BillingService
  participant Database

  User->>Browser: GET /Billing/View
  Browser->>BillingController: HTTP GET
  BillingController->>BillingService: GetCarriers(), GetMonths()
  BillingService->>Database: SELECT Carriers, Types
  Database-->>BillingService: Carrier Data
  BillingService-->>BillingController: Billing model
  BillingController-->>Browser: Render ViewInvoice.cshtml(model)

  Note over Browser: User sees search form & grid
  User->>Browser: Fill filters & Submit (POST)
  Browser->>BillingController: HTTP POST with filters
  BillingController->>BillingService: SearchInvoices(filters)
  BillingService->>Database: SELECT Invoices WHERE filters
  Database-->>BillingService: Result set
  BillingService-->>BillingController: List<InvoiceDto>
  BillingController-->>Browser: Render ViewInvoice.cshtml(updated model)

11. Conclusion

🎯 ViewInvoice.cshtml offers a polished UI for managing invoice records within the Billing module:

  • Dynamic Search: Multiple filters, including nullable flags.
  • Rich Grid: Syncfusion EJ2 TreeGrid with paging, filtering, sorting, and line‑items.
  • Export: Excel, CSV, PDF, Print with state persistence.
  • CRUD Links: Quick navigation to Add, Edit, or Delete actions.

This page demonstrates how to integrate third‑party components (Syncfusion) into an ASP.NET Core MVC Razor view, providing advanced UI capabilities while maintaining server‑side security and model validation.


Happy coding! ✨