📄 GenerateTapFile.cshtml Documentation

Path: IrbyImaging/Views/Billing/GenerateTapFile.cshtml


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Models
  4. Layout & ViewBag Configuration
  5. Form Structure & HTML Helpers
  6. Validation & Error Handling
  7. API Endpoint Overview
  8. Third‑Party Integrations
  9. Styles & Scripts
  10. UML Diagram
  11. Sample Code Blocks
  12. Usage Example
  13. Conclusion

1. Overview & Purpose

This Razor view renders a Billing File Generator 🎯 form which allows users to select:

  • Carrier
  • Invoice Month
  • Invoice Year

and then generate a General Ledger (GL) / TAP file for invoice processing.

Key responsibilities:

  • Render a form bound to the IrbyImaging.UI.Models.Billing view model.
  • Provide client‑side validation.
  • Post user selections to the BillingController.Generate action.
  • Display any validation errors inline.

2. Dependencies & Technologies

Category Library / Framework Purpose
Server‑Side ASP.NET MVC, Razor View rendering & HTML helpers
CSS Framework Bootstrap 4+ Layout & responsive grid system
JavaScript jQuery, Bootstrap.bundle, MetisMenu UI interactions & menu control
UI Enhancements Simplebar, Node‑Waves Custom scrollbars & waves effect
File Upload Dropzone.js (Optional) drag‑and‑drop uploads
Layout Template _ATSLayout.cshtml Shared application layout

3. View Model & Data Models

View Model Type

@model IrbyImaging.UI.Models.Billing

Key Properties

Property Type Description
Carrier SelectList Populates the Invoice Carrier drop‑down.
CarriersTypeDetail IEnumerable<CarriersTypeDetailModel> Source for carrier details (used to build Carrier).
CarrierId int Selected carrier identifier.
InvoiceMonth Month (enum) Selected invoice month.
InvoiceYear int Selected invoice year.

Note: Month is an enum defined under IrbyImaging.UI.Models (e.g., January, February, ...).


4. Layout & ViewBag Configuration

At the top of the file, several ViewBag properties and the layout are set:

@{
    ViewBag.Title     = "Billing File";
    ViewBag.pTitle    = "Billing File";
    ViewBag.pageTitle = "Billing";
    Layout           = "~/Views/Shared/_ATSLayout.cshtml";
}
  • Layout: Uses a shared layout (_ATSLayout.cshtml) for consistent header/footer.
  • ViewBag: Supplies page titles for display in the layout and breadcrumb navigation.

5. Form Structure & HTML Helpers

The core of the view is a <form> that posts to the Generate action of the Billing controller.

@using (Html.BeginForm("Generate", "Billing", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="card">
        <div class="card-body">
            <h4 class="card-title mb-4">Create GL file for Invoice</h4>

            <!-- Carrier Selection -->
            <div class="row mb-4">
                <label asp-for="CarrierId" class="col-sm-1 col-form-label">Invoice Carrier</label>
                <div class="col-sm-2">
                    <select asp-for="CarrierId" class="form-control"
                            asp-items="@Model.Carrier"></select>
                    <span asp-validation-for="CarrierId" class="text-danger"></span>
                </div>
            </div>

            <!-- Month Selection -->
            <div class="row mb-4">
                <label asp-for="InvoiceMonth" class="col-sm-1 col-form-label">Invoice Month</label>
                <div class="col-sm-2">
                    <select asp-for="InvoiceMonth" class="form-control"
                            asp-items="@Html.GetEnumSelectList<Month>()"></select>
                    <span asp-validation-for="InvoiceMonth" class="text-danger"></span>
                </div>
            </div>

            <!-- Year Input -->
            <div class="row mb-4">
                <label asp-for="InvoiceYear" class="col-sm-1 col-form-label">Invoice Year</label>
                <div class="col-sm-1">
                    <input asp-for="InvoiceYear" class="form-control" />
                    <span asp-validation-for="InvoiceYear" class="text-danger"></span>
                </div>
            </div>

            <!-- Submit Button -->
            <div class="row justify-content-end">
                <div class="col-lg-12">
                    <button id="submitbtn" type="submit" class="btn btn-primary">
                        Generate
                    </button>
                </div>
            </div>
        </div>
    </div>
}

Highlights

  • Html.BeginForm(...) sets form target & enctype.
  • asp-for binds to model properties.
  • asp-items populates <select> lists.
  • asp-validation-for displays validation messages.

6. Validation & Error Handling

  • Client-side: ASP.NET unobtrusive validation (via asp-validation-for).
  • Server-side: The Generate action in the controller should check ModelState.IsValid and return the view with errors if any.
[HttpPost]
public IActionResult Generate(Billing model)
{
    if (!ModelState.IsValid)
    {
        // Return the same view with validation messages
        return View("GenerateTapFile", model);
    }
    // Proceed to generate file...
}

7. API Endpoint Overview

🔗 Endpoint

POST /Billing/Generate

Signature (Controller)

public class BillingController : Controller
{
    [HttpPost]
    public IActionResult Generate(IrbyImaging.UI.Models.Billing model)
    {
        // Business logic to build and return a TAP file
        // e.g., return File(stream, "application/octet-stream", "GL_2024_01.tap");
    }
}

8. Third‑Party Integrations

Library Usage
Dropzone (Commented out) File drag‑and‑drop support for large uploads.
Spin.js (Commented) Display loading spinner during generation upload.

Note: The view contains commented-out snippets for Dropzone and Spin.js. They can be enabled to provide richer UX during file operations.


9. Styles & Scripts

Styles

<link href="~/assets/libs/dropzone/min/dropzone.min.css" rel="stylesheet" />

Scripts

<!-- Core JS libraries -->
<script src="~/assets/libs/jquery/jquery.min.js"></script>
<script src="~/assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/assets/libs/metismenu/metisMenu.min.js"></script>
<script src="~/assets/libs/simplebar/simplebar.min.js"></script>
<script src="~/assets/libs/node-waves/waves.min.js"></script>

<!-- Dropzone for file uploads -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.5.1/dropzone.js"></script>

<!-- App initialization -->
<script src="~/assets/js/app.js"></script>

10. UML Diagram

@startuml
package "Views.Billing" {
  class GenerateTapFile.cshtml
}

package "Controllers" {
  class BillingController {
    + IActionResult Generate(Billing model)
  }
}

package "Models" {
  class Billing {
    + int CarrierId
    + Month InvoiceMonth
    + int InvoiceYear
    + SelectList Carrier
    + IEnumerable<CarriersTypeDetailModel> CarriersTypeDetail
  }
}

GenerateTapFile.cshtml --> BillingController : POST Generate()
GenerateTapFile.cshtml --> Billing : @model
@enduml

Flow:

  1. User fills form in GenerateTapFile.cshtml.
  2. Form is submitted to BillingController.Generate.
  3. Controller processes data and returns a TAP file or view with errors.

11. Sample Code Blocks

Controller Action

[HttpPost]
public IActionResult Generate(Billing model)
{
    if (!ModelState.IsValid)
    {
        // Re-populate dropdowns if needed
        model.Carrier = GetCarrierSelectList();
        return View("GenerateTapFile", model);
    }

    // 1. Query invoice data
    var records = billingService.GetInvoiceRecords(
        model.CarrierId, model.InvoiceMonth, model.InvoiceYear);

    // 2. Build TAP file in memory
    var tapBytes = tapGenerator.Generate(records);

    // 3. Return file for download
    return File(tapBytes, "application/octet-stream", 
                $"GL_{model.InvoiceYear}_{(int)model.InvoiceMonth}.tap");
}

Enum Definition

public enum Month
{
    January = 1,
    February,
    March,
    // ...
    December = 12
}

12. Usage Example

  1. Navigate to /Billing/GenerateTapFile.
  2. Select a carrier from the Invoice Carrier dropdown.
  3. Choose the invoice Month (e.g., January).
  4. Enter the Year (e.g., 2024).
  5. Click Generate.
  6. Download the generated *.tap file when prompted.

13. Conclusion

This GenerateTapFile.cshtml view is a crucial part of the billing workflow, providing users with a simple, validated form to generate GL/TAP files for invoice processing. It leverages ASP.NET MVC’s Razor, Html Helpers, and client‑side validation to ensure a robust user experience. Third‑party tools like Dropzone and Spin.js can be enabled to further enhance the upload/generation UX.

✨ Happy Billing! ✨