feat: show live estimated eBay Final Value Fee (12.8%) below price field

This commit is contained in:
2026-04-16 12:31:31 +01:00
parent 554a280caa
commit ded36a27cf
2 changed files with 41 additions and 3 deletions

View File

@@ -435,16 +435,21 @@
</StackPanel> </StackPanel>
</Button> </Button>
</Grid> </Grid>
<mah:NumericUpDown x:Name="BPriceBox" <mah:NumericUpDown x:Name="BPriceBox" ValueChanged="PriceBox_ValueChanged"
StringFormat="&#x00A3;{0:0.00}" StringFormat="&#x00A3;{0:0.00}"
Minimum="0" Maximum="99999" Minimum="0" Maximum="99999"
Interval="0.50" Interval="0.50"
Margin="0,0,0,4" Margin="0,0,0,4"
AutomationProperties.LabeledBy="{Binding ElementName=PriceLabel}"/> AutomationProperties.LabeledBy="{Binding ElementName=PriceLabel}"/>
<TextBlock x:Name="BPriceHint" <TextBlock x:Name="BPriceHint"
FontSize="12" Margin="0,0,0,12" FontSize="12" Margin="0,0,0,4"
Visibility="Collapsed" Visibility="Collapsed"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"/> Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
<TextBlock x:Name="BFeeLabel"
FontSize="12" Margin="0,0,0,12"
Visibility="Collapsed"
Foreground="{DynamicResource MahApps.Brushes.Gray5}"
AutomationProperties.Name="Estimated eBay listing fee"/>
<!-- Postage + Postcode --> <!-- Postage + Postcode -->
<Grid Margin="0,12,0,0"> <Grid Margin="0,12,0,0">
@@ -457,7 +462,7 @@
<TextBlock x:Name="PostageLabel" Text="Postage" <TextBlock x:Name="PostageLabel" Text="Postage"
Style="{StaticResource FieldLabel}" Style="{StaticResource FieldLabel}"
Margin="0,0,0,4"/> Margin="0,0,0,4"/>
<ComboBox x:Name="BPostageBox" <ComboBox x:Name="BPostageBox" SelectionChanged="PostageBox_SelectionChanged"
AutomationProperties.LabeledBy="{Binding ElementName=PostageLabel}"> AutomationProperties.LabeledBy="{Binding ElementName=PostageLabel}">
<ComboBoxItem Content="Royal Mail 1st Class" Tag="RoyalMailFirstClass"/> <ComboBoxItem Content="Royal Mail 1st Class" Tag="RoyalMailFirstClass"/>
<ComboBoxItem Content="Royal Mail 2nd Class" Tag="RoyalMailSecondClass" IsSelected="True"/> <ComboBoxItem Content="Royal Mail 2nd Class" Tag="RoyalMailSecondClass" IsSelected="True"/>

View File

@@ -428,6 +428,39 @@ public partial class NewListingView : UserControl
finally { SetPriceBusy(false); } finally { SetPriceBusy(false); }
} }
private void PriceBox_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
=> UpdateFeeEstimate();
private void PostageBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
=> UpdateFeeEstimate();
private static readonly Dictionary<string, decimal> PostageEstimates = new()
{
["RoyalMailFirstClass"] = 3.70m,
["RoyalMailSecondClass"] = 2.85m,
["RoyalMailTracked24"] = 4.35m,
["RoyalMailTracked48"] = 3.60m,
["CollectionOnly"] = 0m,
["FreePostage"] = 0m,
};
private void UpdateFeeEstimate()
{
if (BFeeLabel == null) return;
var price = (decimal)(BPriceBox?.Value ?? 0);
if (price <= 0) { BFeeLabel.Visibility = Visibility.Collapsed; return; }
var postageTag = (BPostageBox?.SelectedItem as ComboBoxItem)?.Tag?.ToString() ?? "";
PostageEstimates.TryGetValue(postageTag, out var postageEst);
const decimal fvfRate = 0.128m;
const decimal minFee = 0.30m;
var fee = Math.Max(Math.Round((price + postageEst) * fvfRate, 2), minFee);
var postageNote = postageEst > 0 ? $" + est. \u00A3{postageEst:F2} postage" : "";
BFeeLabel.Text = $"Est. eBay fee: \u00A3{fee:F2} (12.8% of \u00A3{price:F2}{postageNote})";
BFeeLabel.Visibility = Visibility.Visible;
}
private void SetPriceBusy(bool busy) private void SetPriceBusy(bool busy)
{ {
AiPriceBtn.IsEnabled = !busy; AiPriceBtn.IsEnabled = !busy;