Added Taxable to Products
Added the ability to tax products for sale
This commit is contained in:
parent
57d2ab60a7
commit
0957963cad
@ -3,7 +3,7 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
select Id, ProductName, [Description], RetailPrice, QuantityInStock
|
||||
select Id, ProductName, [Description], RetailPrice, QuantityInStock, IsTaxable
|
||||
from [dbo].[Product]
|
||||
order by ProductName;
|
||||
END
|
@ -6,5 +6,6 @@
|
||||
[RetailPrice] MONEY NOT NULL,
|
||||
[QuantityInStock] INT NOT NULL DEFAULT 1,
|
||||
[CreatedDate] DATETIME2 NOT NULL DEFAULT getutcdate(),
|
||||
[LastModified] DATETIME2 NOT NULL DEFAULT getutcdate()
|
||||
[LastModified] DATETIME2 NOT NULL DEFAULT getutcdate(),
|
||||
[IsTaxable] BIT NOT NULL DEFAULT 1
|
||||
)
|
||||
|
@ -12,5 +12,6 @@ namespace RMDataManagerLibrary.Models
|
||||
public string Description { get; set; }
|
||||
public decimal RetailPrice { get; set; }
|
||||
public int QuantityInStock { get; set; }
|
||||
public bool IsTaxable { get; set; }
|
||||
}
|
||||
}
|
26
RMWPFInterfaceLibrary/Helpers/ConfigHelper.cs
Normal file
26
RMWPFInterfaceLibrary/Helpers/ConfigHelper.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RMWPFInterfaceLibrary.Helpers
|
||||
{
|
||||
public class ConfigHelper : IConfigHelper
|
||||
{
|
||||
public decimal GetTaxRate()
|
||||
{
|
||||
string rateText = ConfigurationManager.AppSettings["taxRate"];
|
||||
|
||||
bool isValidTaxRate = Decimal.TryParse(rateText, out decimal output);
|
||||
|
||||
if (isValidTaxRate == false)
|
||||
{
|
||||
throw new ConfigurationErrorsException("The taxRate is not setup properly");
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
7
RMWPFInterfaceLibrary/Helpers/IConfigHelper.cs
Normal file
7
RMWPFInterfaceLibrary/Helpers/IConfigHelper.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace RMWPFInterfaceLibrary.Helpers
|
||||
{
|
||||
public interface IConfigHelper
|
||||
{
|
||||
decimal GetTaxRate();
|
||||
}
|
||||
}
|
@ -13,5 +13,6 @@ namespace RMWPFInterfaceLibrary.Models
|
||||
public string Description { get; set; }
|
||||
public decimal RetailPrice { get; set; }
|
||||
public int QuantityInStock { get; set; }
|
||||
public bool IsTaxable { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,8 @@
|
||||
<Compile Include="Api\IAPIHelper.cs" />
|
||||
<Compile Include="Api\IProductEndPoint.cs" />
|
||||
<Compile Include="Api\ProductEndPoint.cs" />
|
||||
<Compile Include="Helpers\ConfigHelper.cs" />
|
||||
<Compile Include="Helpers\IConfigHelper.cs" />
|
||||
<Compile Include="Models\AuthenticatedUser.cs" />
|
||||
<Compile Include="Models\CartItemModel.cs" />
|
||||
<Compile Include="Models\ILoggedInUserModel.cs" />
|
||||
|
@ -2,6 +2,7 @@
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="api" value="https://localhost:44372/" />
|
||||
<add key="taxRate" value="8.75" />
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Caliburn.Micro;
|
||||
using RMWPFInterfaceLibrary.Api;
|
||||
using RMWPFInterfaceLibrary.Helpers;
|
||||
using RMWPFInterfaceLibrary.Models;
|
||||
using RMWPFUserInterface.Helpers;
|
||||
using RMWPFUserInterface.ViewModels;
|
||||
@ -29,11 +30,12 @@ namespace RMWPFUserInterface
|
||||
{
|
||||
_container.Instance(_container)
|
||||
.PerRequest<IProductEndPoint, ProductEndPoint>();
|
||||
|
||||
|
||||
_container
|
||||
.Singleton<IWindowManager, WindowManager>()
|
||||
.Singleton<IEventAggregator, EventAggregator>()
|
||||
.Singleton<ILoggedInUserModel, LoggedInUserModel>()
|
||||
.Singleton<IConfigHelper, ConfigHelper>()
|
||||
.Singleton<IAPIHelper, APIHelper>();
|
||||
|
||||
GetType().Assembly.GetTypes()
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Caliburn.Micro;
|
||||
using RMWPFInterfaceLibrary.Api;
|
||||
using RMWPFInterfaceLibrary.Helpers;
|
||||
using RMWPFInterfaceLibrary.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -13,9 +14,11 @@ namespace RMWPFUserInterface.ViewModels
|
||||
public class SalesViewModel : Screen
|
||||
{
|
||||
IProductEndPoint _productEndPoint;
|
||||
public SalesViewModel(IProductEndPoint productEndPoint)
|
||||
IConfigHelper _configHelper;
|
||||
public SalesViewModel(IProductEndPoint productEndPoint, IConfigHelper configHelper)
|
||||
{
|
||||
_productEndPoint = productEndPoint;
|
||||
_configHelper = configHelper;
|
||||
}
|
||||
|
||||
protected override async void OnViewLoaded(object view)
|
||||
@ -84,33 +87,53 @@ namespace RMWPFUserInterface.ViewModels
|
||||
public string SubTotal
|
||||
{
|
||||
get
|
||||
{
|
||||
decimal subTotal = 0;
|
||||
|
||||
foreach (var item in Cart)
|
||||
{
|
||||
subTotal += item.Product.RetailPrice * item.QuantityInCart;
|
||||
}
|
||||
|
||||
return subTotal.ToString("C");
|
||||
{
|
||||
return CalculateSubTotal().ToString("C");
|
||||
}
|
||||
}
|
||||
|
||||
private decimal CalculateSubTotal()
|
||||
{
|
||||
decimal subTotal = 0;
|
||||
|
||||
foreach (var item in Cart)
|
||||
{
|
||||
subTotal += item.Product.RetailPrice * item.QuantityInCart;
|
||||
}
|
||||
|
||||
return subTotal;
|
||||
}
|
||||
|
||||
public string Tax
|
||||
{
|
||||
get
|
||||
{
|
||||
// replace with calulation;
|
||||
return "$0.00";
|
||||
return CalculateTax().ToString("C");
|
||||
}
|
||||
}
|
||||
|
||||
private decimal CalculateTax()
|
||||
{
|
||||
decimal taxAmount = 0;
|
||||
decimal TaxRate = _configHelper.GetTaxRate()/100;
|
||||
|
||||
foreach (var item in Cart)
|
||||
{
|
||||
if (item.Product.IsTaxable)
|
||||
{
|
||||
taxAmount += (item.Product.RetailPrice * item.QuantityInCart * TaxRate);
|
||||
}
|
||||
}
|
||||
|
||||
return taxAmount;
|
||||
}
|
||||
|
||||
public string Total
|
||||
{
|
||||
get
|
||||
{
|
||||
// replace with calulation;
|
||||
return "$0.00";
|
||||
decimal total = CalculateSubTotal() + CalculateTax();
|
||||
return total.ToString("C");
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,6 +172,8 @@ namespace RMWPFUserInterface.ViewModels
|
||||
SelectedProduct.QuantityInStock -= ItemQuantity;
|
||||
ItemQuantity = 1;
|
||||
NotifyOfPropertyChange(() => SubTotal);
|
||||
NotifyOfPropertyChange(() => Tax);
|
||||
NotifyOfPropertyChange(() => Total);
|
||||
Cart.ResetBindings();
|
||||
}
|
||||
|
||||
@ -166,6 +191,8 @@ namespace RMWPFUserInterface.ViewModels
|
||||
public void RemoveFromCart()
|
||||
{
|
||||
NotifyOfPropertyChange(() => SubTotal);
|
||||
NotifyOfPropertyChange(() => Tax);
|
||||
NotifyOfPropertyChange(() => Total);
|
||||
}
|
||||
|
||||
public bool CanCheckOut
|
||||
|
Loading…
Reference in New Issue
Block a user