-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from ucdavis/JCS/TxnReport
Jcs/txn report
- Loading branch information
Showing
7 changed files
with
286 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Sloth.Web.Models.TransactionViewModels; | ||
using System; | ||
|
||
namespace Sloth.Web.Helpers | ||
{ | ||
public class FilterHelpers | ||
{ | ||
public static void SanitizeTransactionsFilter(TransactionsFilterModel model) | ||
{ | ||
var fromUtc = (model.From ?? DateTime.Now.AddMonths(-1)).ToUniversalTime().Date; | ||
var throughUtc = (model.To ?? DateTime.Now).ToUniversalTime().AddDays(1).Date; | ||
|
||
if (fromUtc > DateTime.UtcNow || fromUtc < DateTime.UtcNow.AddYears(-100)) | ||
{ | ||
// invalid, so default to filtering from one month ago | ||
var from = DateTime.Now.AddMonths((-1)).Date; | ||
model.From = from; | ||
fromUtc = from.ToUniversalTime(); | ||
} | ||
else | ||
{ | ||
model.From = fromUtc.ToLocalTime(); | ||
} | ||
|
||
if (fromUtc >= throughUtc) | ||
{ | ||
// invalid, so default to filtering through one month after fromUtc | ||
throughUtc = fromUtc.AddMonths(1).AddDays(1).Date; | ||
model.To = throughUtc.AddDays(-1).ToLocalTime(); | ||
} | ||
else | ||
{ | ||
model.To = throughUtc.ToLocalTime(); | ||
} | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
Sloth.Web/Models/ReportViewModels/TransfersReportViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System; | ||
using System.ComponentModel; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Sloth.Core.Models; | ||
using System.Collections.Generic; | ||
using Sloth.Web.Models.TransactionViewModels; | ||
using System.Linq.Expressions; | ||
using System.Linq; | ||
|
||
namespace Sloth.Web.Models.ReportViewModels | ||
{ | ||
public class TransfersReportViewModel | ||
{ | ||
public TransactionsFilterModel Filter { get; set; } | ||
|
||
public IList<TransactionWithTransfers> Transactions { get; set; } | ||
} | ||
|
||
public class TransactionWithTransfers | ||
{ | ||
[DisplayName("Txn Id")] | ||
public string Id { get; set; } | ||
[DisplayName("Txn Id")] | ||
public string DisplayId => $"...{Id[^4..]}"; // last 4 characters of the id | ||
|
||
public string Status { get; set; } | ||
|
||
[DisplayName("Transaction Date")] | ||
public DateTime TransactionDate { get; set; } | ||
|
||
[DisplayName("Kfs Tracking Number")] | ||
public string KfsTrackingNumber { get; set; } | ||
[DisplayName("Document Number")] | ||
public string DocumentNumber { get; set; } | ||
|
||
[DisplayName("Processor Tracking Number")] | ||
public string ProcessorTrackingNumber { get; set; } | ||
|
||
[DisplayName("Merchant Tracking Number")] | ||
public string MerchantTrackingNumber { get; set; } | ||
[DisplayName("Transaction Description")] | ||
public string TxnDescription { get; set; } | ||
|
||
public string MetaDataString { get; set; } | ||
|
||
[DisplayName("Transaction Amount")] | ||
public decimal Amount { get; set; } | ||
|
||
[DisplayName("Transfer Count")] | ||
public int TransferCount { get; set; } | ||
|
||
public IList<Transfer> Transfers { get; set; } // don't need all the info in here, but it shouldn't be too big. | ||
|
||
public static Expression<Func<Transaction, TransactionWithTransfers>> Projection() | ||
{ | ||
|
||
return txn => new TransactionWithTransfers | ||
{ | ||
Id = txn.Id, | ||
Status = txn.Status, | ||
TransactionDate = txn.TransactionDate, | ||
KfsTrackingNumber = txn.KfsTrackingNumber, | ||
DocumentNumber = txn.DocumentNumber, | ||
ProcessorTrackingNumber = txn.ProcessorTrackingNumber, | ||
MerchantTrackingNumber = txn.MerchantTrackingNumber, | ||
TxnDescription = txn.Description, | ||
MetaDataString = string.Join(", ", txn.Metadata.Select(kv => $"{kv.Name}: {kv.Value}")), | ||
Amount = txn.Transfers.Where(a => a.Direction == Transfer.CreditDebit.Credit).Sum(a => a.Amount), | ||
TransferCount = txn.Transfers.Count, | ||
Transfers = txn.Transfers.OrderBy(a => a.Direction).ToList(), | ||
}; | ||
|
||
} | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
Sloth.Web/Views/Reports/DownloadableTransactions.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
@using Humanizer | ||
@using Sloth.Core.Extensions | ||
@using Sloth.Core.Resources | ||
@model Sloth.Web.Models.ReportViewModels.TransfersReportViewModel | ||
|
||
<div class="container"> | ||
<h2>@ViewBag.Title</h2> | ||
|
||
<h3>Filters</h3> | ||
<form class="row" id="transactionFilterForm" asp-controller="Reports" asp-action="DownloadableTransactions" method="get"> | ||
<div class="row justify-content-between filters-wrapper"> | ||
<div class="col-8 col-md-5"> | ||
<div id="filter-date-range" class="input-group"> | ||
<input name="from" type="text" class="form-control" placeholder="MM/DD/YYYY" asp-for="Filter.From" asp-format="{0:MM/dd/yyyy}" aria-label="" /> | ||
<span class="input-group-text">to</span> | ||
<input name="to" type="text" class="form-control" placeholder="MM/DD/YYYY" asp-for="Filter.To" asp-format="{0:MM/dd/yyyy}" aria-label="" /> | ||
</div> | ||
|
||
<button type="submit" class="btn btn-link mt-1">Apply filter</button> | ||
</div> | ||
|
||
</div> | ||
</form> | ||
|
||
<div class="responsive-table"> | ||
<table id="transactionsTable" class="table sloth-table active-table"> | ||
<thead> | ||
<tr> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().Id)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().DisplayId)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().Status)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().TransactionDate)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().KfsTrackingNumber)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().DocumentNumber)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().ProcessorTrackingNumber)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().MerchantTrackingNumber)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().TxnDescription)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().MetaDataString)</th> | ||
<th>@Html.DisplayNameFor(x => x.Transactions.FirstOrDefault().TransferCount)</th> | ||
<th>Total Amount</th> | ||
<th>Direction</th> | ||
<th>Description</th> | ||
<th>Amount</th> | ||
<th>Chart String</th> | ||
<th>Chart String</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var txn in Model.Transactions) | ||
{ | ||
@foreach (var transfer in txn.Transfers) | ||
{ | ||
<tr> | ||
<td>@txn.Id</td> | ||
<td>@txn.DisplayId</td> | ||
<td><span class="badge @(TransactionStatuses.GetBadgeClass(txn.Status))">@txn.Status.Humanize(LetterCasing.Title)</span></td> | ||
<td>@txn.TransactionDate.ToPacificTime()</td> | ||
<td>@txn.KfsTrackingNumber</td> | ||
<td>@txn.DocumentNumber</td> | ||
<td>@txn.ProcessorTrackingNumber</td> | ||
<td>@txn.MerchantTrackingNumber</td> | ||
<td>@txn.TxnDescription</td> | ||
<td>@txn.MetaDataString</td> | ||
<td>@txn.TransferCount</td> | ||
<td>@txn.Amount</td> | ||
<td><span class="badge @(Transfer.GetDirectionBadgeClass(transfer.Direction))">@transfer.Direction</span></td> | ||
<td>@transfer.Description</td> | ||
<td>@transfer.Amount</td> | ||
<td>@transfer.ShortFinancialSegmentString</td> | ||
<td>@transfer.FinancialSegmentString</td> | ||
</tr> | ||
} | ||
} | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
@section AdditionalScripts { | ||
<script> | ||
//setup datepickers | ||
$('#filter-date-range').datepicker({ | ||
inputs: $('#filter-date-range input'), | ||
keepEmptyValues: true, | ||
}); | ||
</script> | ||
|
||
<script> | ||
$('#transactionsTable').dataTable({ | ||
"dom": 'Bfrtip', | ||
"columnDefs": [ | ||
{ | ||
"targets": [0, 5, 6, 7, 9, 16], | ||
"visible": false, | ||
}, | ||
{ "type": "date", "targets": [3] }, | ||
], | ||
order: false, | ||
"buttons": [ | ||
{ | ||
extend: 'copyHtml5', | ||
exportOptions: { | ||
columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16] | ||
} | ||
}, | ||
{ | ||
extend: 'excelHtml5', | ||
exportOptions: { | ||
columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16] | ||
} | ||
}, | ||
{ | ||
extend: 'csvHtml5', | ||
exportOptions: { | ||
columns: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16] | ||
} | ||
}, | ||
], | ||
language: { | ||
searchPlaceholder: "Search Table", | ||
search: "", | ||
}, | ||
}); | ||
</script> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters