Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpung committed Jan 31, 2024
2 parents 280c086 + 41e1892 commit 5cd471d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 76 deletions.
21 changes: 4 additions & 17 deletions BlazorApp-Investment Tax Calculator/Components/DividendTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
@using Syncfusion.Blazor.Grids
@using Enumerations
@using System.Globalization
@using Services

@inject IDividendLists _dividendList
@inject SfGridToolBarHandlingService _toolbarHandlingService

<div class="bg-dark text-light">
<div class="row my-4">
Expand All @@ -18,7 +20,7 @@
<div class="row mt-3 me-3">
<div class="col">
<SfGrid ID="ImportedDividendGrid" @ref="importedDividendGrid" DataSource="@DividendViewModels"
AllowPaging="true" AllowSorting="true" AllowPdfExport="true" AllowExcelExport="true" AllowResizing="true" AllowFiltering=true
AllowPaging="true" AllowSorting="true" AllowPdfExport="true" AllowExcelExport="true" AllowResizing="true" AllowFiltering=true AllowTextWrap="true"
Toolbar="@(new List<string>() { "PdfExport", "ExcelExport", "Print"})">
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings>
<GridPageSettings PageSizes=@(new List<int>() {25, 50, 100}) PageSize="25"></GridPageSettings>
Expand Down Expand Up @@ -47,22 +49,7 @@

public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)

Check warning on line 50 in BlazorApp-Investment Tax Calculator/Components/DividendTable.razor

View workflow job for this annotation

GitHub Actions / build-project

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
if (args.Item.Id == "ImportedDividendGrid_pdfexport") //Id is combination of Grid's ID and itemname
{
var pdfExportProperties = new PdfExportProperties()
{
PageOrientation = PageOrientation.Landscape,
PageSize = PdfPageSize.A4,
IncludeTemplateColumn = true
};
await importedDividendGrid.ExportToPdfAsync(pdfExportProperties);
}
if (args.Item.Id == "ImportedDividendGrid_excelexport") //Id is combination of Grid's ID and itemname
{
ExcelExportProperties exportProperties = new ExcelExportProperties();
exportProperties.IncludeTemplateColumn = true;
await importedDividendGrid.ExportToExcelAsync(exportProperties);
}
_toolbarHandlingService.ToolbarClickHandler(args, importedDividendGrid);

Check warning on line 52 in BlazorApp-Investment Tax Calculator/Components/DividendTable.razor

View workflow job for this annotation

GitHub Actions / build-project

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
@using Syncfusion.Blazor.SplitButtons
@using Enumerations
@using BlazorApp_Investment_Tax_Calculator.Components
@using Services

@inject TradeCalculationResult tradeCalculationResult
@inject SfGridToolBarHandlingService _toolbarHandlingService

<div class="bg-dark text-light">
<div class="row my-4">
Expand All @@ -21,7 +23,7 @@
<div class="row me-3">
<div class="col">
<SfGrid ID="TradeMatchesGrid" @ref="tradeMatchesGrid" DataSource="@_tradeMatches"
AllowPaging="true" AllowSorting="true" AllowPdfExport="true" AllowExcelExport="true" AllowResizing="true" AllowFiltering="true"
AllowPaging="true" AllowSorting="true" AllowPdfExport="true" AllowExcelExport="true" AllowResizing="true" AllowFiltering="true" AllowTextWrap="true"
Toolbar="@(new List<string>() { "PdfExport", "ExcelExport", "Print" })">
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings>
<GridPageSettings PageSizes=@(new List<int>() {25, 50, 100}) PageSize="25"></GridPageSettings>
Expand All @@ -33,10 +35,12 @@
<GridColumn Field=@nameof(TradeMatchViewModel.MatchType) HeaderText="Match Type"></GridColumn>
<GridColumn Field=@nameof(TradeMatchViewModel.AcquistionTradeId) HeaderText="Acquisition trade ID"></GridColumn>
<GridColumn Field=@nameof(TradeMatchViewModel.DisposalTradeId) HeaderText="Disposal trade ID"></GridColumn>
<GridColumn Field=@nameof(TradeMatchViewModel.MatchDisposalQty) HeaderText="Matched disposal Quantity" Format="F2"></GridColumn>
<GridColumn Field=@nameof(TradeMatchViewModel.MatchAcquisitionQty) HeaderText="Matched Acquisition Quantity"></GridColumn>
<GridColumn Field=@nameof(TradeMatchViewModel.MatchDisposalQty) HeaderText="Matched Disposal Quantity"></GridColumn>
<GridColumn Field=@nameof(TradeMatchViewModel.DisposalProceed) HeaderText="Disposal Proceed"></GridColumn>
<GridColumn Field=@nameof(TradeMatchViewModel.AllowableCost) HeaderText="Allowable Cost"></GridColumn>
<GridColumn Field=@nameof(TradeMatchViewModel.Gain) HeaderText="Gain"></GridColumn>
<GridColumn Field=@nameof(TradeMatchViewModel.AdditionalInformation) HeaderText="Additional Information"></GridColumn>
</GridColumns>
</SfGrid>
</div>
Expand All @@ -56,22 +60,7 @@

public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)

Check warning on line 61 in BlazorApp-Investment Tax Calculator/Components/MatchingDetailTable.razor

View workflow job for this annotation

GitHub Actions / build-project

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
if (args.Item.Id == "TradeMatchesGrid_pdfexport") //Id is combination of Grid's ID and itemname
{
var pdfExportProperties = new PdfExportProperties()
{
PageOrientation = PageOrientation.Landscape,
PageSize = PdfPageSize.A4,
IncludeTemplateColumn = true
};
await tradeMatchesGrid.ExportToPdfAsync(pdfExportProperties);
}
if (args.Item.Id == "TradeMatchesGrid_excelexport") //Id is combination of Grid's ID and itemname
{
ExcelExportProperties exportProperties = new ExcelExportProperties();
exportProperties.IncludeTemplateColumn = true;
await tradeMatchesGrid.ExportToExcelAsync(exportProperties);
}
_toolbarHandlingService.ToolbarClickHandler(args, tradeMatchesGrid);

Check warning on line 63 in BlazorApp-Investment Tax Calculator/Components/MatchingDetailTable.razor

View workflow job for this annotation

GitHub Actions / build-project

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
@using Syncfusion.Blazor.SplitButtons
@using Enumerations
@using BlazorApp_Investment_Tax_Calculator.Components
@using Services

@inject UkSection104Pools section104Pools
@inject SfGridToolBarHandlingService _toolbarHandlingService

<div class="bg-dark text-light">
<div class="row my-4">
Expand All @@ -20,20 +22,20 @@
<div class="row me-3">
<div class="col">
<SfGrid ID="Section104HistoryGrid" @ref="section104HistoryGrid" DataSource="@_section104HistoryViewModels"
AllowPaging="true" AllowSorting="true" AllowPdfExport="true" AllowExcelExport="true" AllowResizing="true" AllowFiltering="true"
AllowPaging="true" AllowSorting="true" AllowPdfExport="true" AllowExcelExport="true" AllowResizing="true" AllowFiltering="true" AllowTextWrap="true"
Toolbar="@(new List<string>() { "PdfExport", "ExcelExport", "Print" })">
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings>
<GridPageSettings PageSizes=@(new List<int>() {25, 50, 100}) PageSize="25"></GridPageSettings>
<GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Section104HistoryViewModel?"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Section104HistoryViewModel.AssetName) HeaderText="Asset Name"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.TradeId) HeaderText="Trade ID"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.Date) HeaderText="Date"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.Date) HeaderText="Date" Format="d"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.OldQuantity) HeaderText="Old Quantity"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.QuantityChange) HeaderText="Quantity Change"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.NewQuantity) HeaderText="New quantity"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.OldValue) HeaderText="Old value"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.ValueChange) HeaderText="Value change"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.NewQuantity) HeaderText="New Quantity"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.OldValue) HeaderText="Old Value"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.ValueChange) HeaderText="Value Change"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.NewValue) HeaderText="New Value"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.OldContractValue) HeaderText="Old Contract Value"></GridColumn>
<GridColumn Field=@nameof(Section104HistoryViewModel.ContractValueChange) HeaderText="Contract Value Change"></GridColumn>
Expand All @@ -52,22 +54,7 @@

public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)

Check warning on line 55 in BlazorApp-Investment Tax Calculator/Components/Section104HistoryTable.razor

View workflow job for this annotation

GitHub Actions / build-project

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 55 in BlazorApp-Investment Tax Calculator/Components/Section104HistoryTable.razor

View workflow job for this annotation

GitHub Actions / build-project

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
if (args.Item.Id == "Section104HistoryGrid_pdfexport") //Id is combination of Grid's ID and itemname
{
var pdfExportProperties = new PdfExportProperties()
{
PageOrientation = PageOrientation.Landscape,
PageSize = PdfPageSize.A4,
IncludeTemplateColumn = true
};
await section104HistoryGrid.ExportToPdfAsync(pdfExportProperties);
}
if (args.Item.Id == "Section104HistoryGrid_excelexport") //Id is combination of Grid's ID and itemname
{
ExcelExportProperties exportProperties = new ExcelExportProperties();
exportProperties.IncludeTemplateColumn = true;
await section104HistoryGrid.ExportToExcelAsync(exportProperties);
}
_toolbarHandlingService.ToolbarClickHandler(args, section104HistoryGrid);

Check warning on line 57 in BlazorApp-Investment Tax Calculator/Components/Section104HistoryTable.razor

View workflow job for this annotation

GitHub Actions / build-project

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 57 in BlazorApp-Investment Tax Calculator/Components/Section104HistoryTable.razor

View workflow job for this annotation

GitHub Actions / build-project

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
@using Model.UkTaxModel.Stocks
@using Enumerations
@using BlazorApp_Investment_Tax_Calculator.Components
@using Services

@inject TradeCalculationResult tradeCalculationResult
@inject SfGridToolBarHandlingService _toolbarHandlingService

<div class="bg-dark text-light">
<div class="row my-4">
Expand All @@ -19,7 +21,7 @@
<div class="row me-3">
<div class="col">
<SfGrid ID="DisposalCalculationGrid" @ref="disposalCalculationGrid" DataSource="@_trades"
AllowPaging="true" AllowSorting="true" AllowPdfExport="true" AllowExcelExport="true" AllowResizing="true" AllowFiltering="true"
AllowPaging="true" AllowSorting="true" AllowPdfExport="true" AllowExcelExport="true" AllowResizing="true" AllowFiltering="true" AllowTextWrap="true"
Toolbar="@(new List<string>() { "PdfExport", "ExcelExport", "Print" })">
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings>
<GridPageSettings PageSizes=@(new List<int>() {25, 50, 100}) PageSize="25"></GridPageSettings>
Expand All @@ -36,15 +38,15 @@
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.SameDayMatchQty) HeaderText="Same day"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.BedAndBreakfastMatchQty) HeaderText="Bed and Breakfast"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.Section104MatchQty) HeaderText="Section 104"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.CoveredShortMatchQty) HeaderText="Cover short sale"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.UnmatchedQty) HeaderText="Unmatched shares"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.CoveredShortMatchQty) HeaderText="Cover Short Sale"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.UnmatchedQty) HeaderText="Unmatched Shares"></GridColumn>
</GridColumns>
</GridColumn>
<GridColumn HeaderText="Calculation Result">
<GridColumns>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.TotalProceed) HeaderText="Total Proceeeds"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.TotalAllowableCost) HeaderText="Allowable Cost"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.ContractValue) HeaderText="Contract value (Future only)"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.ContractValue) HeaderText="Contract Value (Future only)"></GridColumn>
<GridColumn Field=@nameof(TradeTaxCalculationViewModel.Gain) HeaderText="Gain (Loss)"></GridColumn>
</GridColumns>
</GridColumn>
Expand All @@ -62,21 +64,6 @@

public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)

Check warning on line 65 in BlazorApp-Investment Tax Calculator/Components/TaxCalculationTable.razor

View workflow job for this annotation

GitHub Actions / build-project

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 65 in BlazorApp-Investment Tax Calculator/Components/TaxCalculationTable.razor

View workflow job for this annotation

GitHub Actions / build-project

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
if (args.Item.Id == "DisposalCalculationGrid_pdfexport") //Id is combination of Grid's ID and itemname
{
var pdfExportProperties = new PdfExportProperties()
{
PageOrientation = PageOrientation.Landscape,
PageSize = PdfPageSize.A4,
IncludeTemplateColumn = true
};
await disposalCalculationGrid.ExportToPdfAsync(pdfExportProperties);
}
if (args.Item.Id == "DisposalCalculationGrid_excelexport") //Id is combination of Grid's ID and itemname
{
ExcelExportProperties exportProperties = new ExcelExportProperties();
exportProperties.IncludeTemplateColumn = true;
await disposalCalculationGrid.ExportToExcelAsync(exportProperties);
}
_toolbarHandlingService.ToolbarClickHandler(args, disposalCalculationGrid);

Check warning on line 67 in BlazorApp-Investment Tax Calculator/Components/TaxCalculationTable.razor

View workflow job for this annotation

GitHub Actions / build-project

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 67 in BlazorApp-Investment Tax Calculator/Components/TaxCalculationTable.razor

View workflow job for this annotation

GitHub Actions / build-project

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}
}
2 changes: 2 additions & 0 deletions BlazorApp-Investment Tax Calculator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
// app services
builder.Services.AddSingleton<DividendExportService>();
builder.Services.AddSingleton<FileParseController>();
builder.Services.AddSingleton<YearOptions>();
builder.Services.AddSingleton<ToastService>();
builder.Services.AddSingleton<SfGridToolBarHandlingService>();

// UK tax specific components - replace if you want to calculate some other countries.
builder.Services.AddSingleton<UkCalculationResultExportService>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Syncfusion.Blazor.Grids;

namespace Services;

public class SfGridToolBarHandlingService
{
public async Task ToolbarClickHandler<T>(Syncfusion.Blazor.Navigations.ClickEventArgs args, SfGrid<T> table)
{
if (args.Item.Id.EndsWith("pdfexport"))
{
var pdfExportProperties = new PdfExportProperties()
{
PageOrientation = PageOrientation.Landscape,
PageSize = PdfPageSize.A4,
IncludeTemplateColumn = true
};
await table.ExportToPdfAsync(pdfExportProperties);
}
if (args.Item.Id.EndsWith("excelexport"))
{
ExcelExportProperties exportProperties = new()
{
IncludeTemplateColumn = true
};
await table.ExportToExcelAsync(exportProperties);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ public record TradeMatchViewModel(TradeMatch TradeMatch)
public string MatchType { get; } = TradeMatch.TradeMatchType.GetDescription();
public int? AcquistionTradeId { get; } = TradeMatch.MatchedBuyTrade?.Id;
public int? DisposalTradeId { get; } = TradeMatch.MatchedSellTrade?.Id;
public decimal MatchAcquisitionQty { get; } = TradeMatch.MatchAcquisitionQty;
public decimal MatchDisposalQty { get; } = TradeMatch.MatchDisposalQty;
public decimal DisposalProceed { get; } = TradeMatch.BaseCurrencyMatchDisposalProceed.Amount;
public decimal AllowableCost { get; } = TradeMatch.BaseCurrencyMatchAllowableCost.Amount;
public decimal Gain { get; } = TradeMatch.MatchGain.Amount;
public string AdditionalInformation { get; } = TradeMatch.AdditionalInformation;

}

0 comments on commit 5cd471d

Please sign in to comment.