Skip to content

Commit

Permalink
Merge pull request #99 from alexpung/OptionTradeSupport
Browse files Browse the repository at this point in the history
Implement displaying of tax refund in a table
  • Loading branch information
alexpung authored Oct 3, 2024
2 parents 9146016 + a9c8145 commit e072efd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@using InvestmentTaxCalculator.Model
@using InvestmentTaxCalculator.ViewModel
@using InvestmentTaxCalculator.Model.Interfaces
@using Syncfusion.Blazor.Grids
@using InvestmentTaxCalculator.Model.TaxEvents
@using InvestmentTaxCalculator.Model.UkTaxModel
@using InvestmentTaxCalculator.Model.UkTaxModel.Stocks
@using InvestmentTaxCalculator.Enumerations
@using InvestmentTaxCalculator.Components
@using InvestmentTaxCalculator.Services
@using InvestmentTaxCalculator.Model.UkTaxModel.Options;

@inject TradeCalculationResult tradeCalculationResult
@inject SfGridToolBarHandlingService _toolbarHandlingService

<div class="bg-dark text-light">
<div class="row my-4">
<div class="col">
<h3>Tax refund</h3>
<p>This shows your overpaid tax due to writing option and not closing it in the same tax year.</p>
</div>
</div>
<div class="col">
<SfGrid ID="TaxRefundGrid" @ref="taxRefundGrid" DataSource="@_trades"
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="TaxRepay"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(TaxRepay.TaxYear) HeaderText="Tax Year"></GridColumn>
<GridColumn Field=@nameof(TaxRepay.RefundAmount) HeaderText="Refund Amount"></GridColumn>
<GridColumn Field=@nameof(TaxRepay.Reason) HeaderText="Reason"></GridColumn>
</GridColumns>
</SfGrid>
</div>
</div>

@code {
private SfGrid<TaxRepay> taxRefundGrid = new();
private IEnumerable<TaxRepay> _trades => tradeCalculationResult.CalculatedTrade
.OfType<OptionTradeTaxCalculation>()
.SelectMany(trade => trade.TaxRepayList);

public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
await _toolbarHandlingService.ToolbarClickHandler(args, taxRefundGrid);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ private void MatchNormalTrade(TradePairSorter<OptionTradeTaxCalculation> tradePa
TaxRepay refundPremium = new(
TaxYear: taxYear.ToTaxYear(tradePairSorter.LatterTrade.Date),
RefundAmount: allowableCost,
Reason: $"Sold option with ID:{tradePairSorter.EarlierTrade.Id} and position closed in later tax year {taxYear.ToTaxYear(tradePairSorter.LatterTrade.Date)}"
Reason: $"Sold option {tradePairSorter.EarlierTrade.AssetName}" +
$" with ID:{tradePairSorter.EarlierTrade.Id} on {tradePairSorter.EarlierTrade.Date:d}" +
$" and position closed in later tax year with trade ID:{tradePairSorter.LatterTrade.Id}"
);
tradePairSorter.DisposalTrade.TaxRepayList.Add(refundPremium);
allowableCost = WrappedMoney.GetBaseCurrencyZero();
Expand Down Expand Up @@ -230,7 +232,9 @@ private static bool RefundIfNotInSameYear(TradePairSorter<OptionTradeTaxCalculat
new TaxRepay(
taxYear.ToTaxYear(tradePairSorter.LatterTrade.Date),
allowableCost,
$"Sold option with ID:{tradePairSorter.EarlierTrade.Id} and it gets assigned in later tax year {taxYear.ToTaxYear(tradePairSorter.LatterTrade.Date)}"
$"Sold {tradePairSorter.EarlierTrade.AssetName} " +
$"option with ID:{tradePairSorter.EarlierTrade.Id} on {tradePairSorter.EarlierTrade.Date:d} " +
$"and it get assigned in later tax year with trade ID:{tradePairSorter.LatterTrade.Id}"
));
refunded = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

<CgtYearSummary></CgtYearSummary>
<TaxYearCgtAssetTypeReport></TaxYearCgtAssetTypeReport>
<TaxRefundTable></TaxRefundTable>

0 comments on commit e072efd

Please sign in to comment.