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
|
BEGIN
|
||||||
SET NOCOUNT ON;
|
SET NOCOUNT ON;
|
||||||
|
|
||||||
select Id, ProductName, [Description], RetailPrice, QuantityInStock
|
select Id, ProductName, [Description], RetailPrice, QuantityInStock, IsTaxable
|
||||||
from [dbo].[Product]
|
from [dbo].[Product]
|
||||||
order by ProductName;
|
order by ProductName;
|
||||||
END
|
END
|
@ -6,5 +6,6 @@
|
|||||||
[RetailPrice] MONEY NOT NULL,
|
[RetailPrice] MONEY NOT NULL,
|
||||||
[QuantityInStock] INT NOT NULL DEFAULT 1,
|
[QuantityInStock] INT NOT NULL DEFAULT 1,
|
||||||
[CreatedDate] DATETIME2 NOT NULL DEFAULT getutcdate(),
|
[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 string Description { get; set; }
|
||||||
public decimal RetailPrice { get; set; }
|
public decimal RetailPrice { get; set; }
|
||||||
public int QuantityInStock { 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 string Description { get; set; }
|
||||||
public decimal RetailPrice { get; set; }
|
public decimal RetailPrice { get; set; }
|
||||||
public int QuantityInStock { get; set; }
|
public int QuantityInStock { get; set; }
|
||||||
|
public bool IsTaxable { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,8 @@
|
|||||||
<Compile Include="Api\IAPIHelper.cs" />
|
<Compile Include="Api\IAPIHelper.cs" />
|
||||||
<Compile Include="Api\IProductEndPoint.cs" />
|
<Compile Include="Api\IProductEndPoint.cs" />
|
||||||
<Compile Include="Api\ProductEndPoint.cs" />
|
<Compile Include="Api\ProductEndPoint.cs" />
|
||||||
|
<Compile Include="Helpers\ConfigHelper.cs" />
|
||||||
|
<Compile Include="Helpers\IConfigHelper.cs" />
|
||||||
<Compile Include="Models\AuthenticatedUser.cs" />
|
<Compile Include="Models\AuthenticatedUser.cs" />
|
||||||
<Compile Include="Models\CartItemModel.cs" />
|
<Compile Include="Models\CartItemModel.cs" />
|
||||||
<Compile Include="Models\ILoggedInUserModel.cs" />
|
<Compile Include="Models\ILoggedInUserModel.cs" />
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="api" value="https://localhost:44372/" />
|
<add key="api" value="https://localhost:44372/" />
|
||||||
|
<add key="taxRate" value="8.75" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
using RMWPFInterfaceLibrary.Api;
|
using RMWPFInterfaceLibrary.Api;
|
||||||
|
using RMWPFInterfaceLibrary.Helpers;
|
||||||
using RMWPFInterfaceLibrary.Models;
|
using RMWPFInterfaceLibrary.Models;
|
||||||
using RMWPFUserInterface.Helpers;
|
using RMWPFUserInterface.Helpers;
|
||||||
using RMWPFUserInterface.ViewModels;
|
using RMWPFUserInterface.ViewModels;
|
||||||
@ -34,6 +35,7 @@ namespace RMWPFUserInterface
|
|||||||
.Singleton<IWindowManager, WindowManager>()
|
.Singleton<IWindowManager, WindowManager>()
|
||||||
.Singleton<IEventAggregator, EventAggregator>()
|
.Singleton<IEventAggregator, EventAggregator>()
|
||||||
.Singleton<ILoggedInUserModel, LoggedInUserModel>()
|
.Singleton<ILoggedInUserModel, LoggedInUserModel>()
|
||||||
|
.Singleton<IConfigHelper, ConfigHelper>()
|
||||||
.Singleton<IAPIHelper, APIHelper>();
|
.Singleton<IAPIHelper, APIHelper>();
|
||||||
|
|
||||||
GetType().Assembly.GetTypes()
|
GetType().Assembly.GetTypes()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
using RMWPFInterfaceLibrary.Api;
|
using RMWPFInterfaceLibrary.Api;
|
||||||
|
using RMWPFInterfaceLibrary.Helpers;
|
||||||
using RMWPFInterfaceLibrary.Models;
|
using RMWPFInterfaceLibrary.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -13,9 +14,11 @@ namespace RMWPFUserInterface.ViewModels
|
|||||||
public class SalesViewModel : Screen
|
public class SalesViewModel : Screen
|
||||||
{
|
{
|
||||||
IProductEndPoint _productEndPoint;
|
IProductEndPoint _productEndPoint;
|
||||||
public SalesViewModel(IProductEndPoint productEndPoint)
|
IConfigHelper _configHelper;
|
||||||
|
public SalesViewModel(IProductEndPoint productEndPoint, IConfigHelper configHelper)
|
||||||
{
|
{
|
||||||
_productEndPoint = productEndPoint;
|
_productEndPoint = productEndPoint;
|
||||||
|
_configHelper = configHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async void OnViewLoaded(object view)
|
protected override async void OnViewLoaded(object view)
|
||||||
@ -85,32 +88,52 @@ namespace RMWPFUserInterface.ViewModels
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
decimal subTotal = 0;
|
return CalculateSubTotal().ToString("C");
|
||||||
|
|
||||||
foreach (var item in Cart)
|
|
||||||
{
|
|
||||||
subTotal += item.Product.RetailPrice * item.QuantityInCart;
|
|
||||||
}
|
|
||||||
|
|
||||||
return subTotal.ToString("C");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private decimal CalculateSubTotal()
|
||||||
|
{
|
||||||
|
decimal subTotal = 0;
|
||||||
|
|
||||||
|
foreach (var item in Cart)
|
||||||
|
{
|
||||||
|
subTotal += item.Product.RetailPrice * item.QuantityInCart;
|
||||||
|
}
|
||||||
|
|
||||||
|
return subTotal;
|
||||||
|
}
|
||||||
|
|
||||||
public string Tax
|
public string Tax
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// replace with calulation;
|
return CalculateTax().ToString("C");
|
||||||
return "$0.00";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
public string Total
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// replace with calulation;
|
decimal total = CalculateSubTotal() + CalculateTax();
|
||||||
return "$0.00";
|
return total.ToString("C");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +172,8 @@ namespace RMWPFUserInterface.ViewModels
|
|||||||
SelectedProduct.QuantityInStock -= ItemQuantity;
|
SelectedProduct.QuantityInStock -= ItemQuantity;
|
||||||
ItemQuantity = 1;
|
ItemQuantity = 1;
|
||||||
NotifyOfPropertyChange(() => SubTotal);
|
NotifyOfPropertyChange(() => SubTotal);
|
||||||
|
NotifyOfPropertyChange(() => Tax);
|
||||||
|
NotifyOfPropertyChange(() => Total);
|
||||||
Cart.ResetBindings();
|
Cart.ResetBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,6 +191,8 @@ namespace RMWPFUserInterface.ViewModels
|
|||||||
public void RemoveFromCart()
|
public void RemoveFromCart()
|
||||||
{
|
{
|
||||||
NotifyOfPropertyChange(() => SubTotal);
|
NotifyOfPropertyChange(() => SubTotal);
|
||||||
|
NotifyOfPropertyChange(() => Tax);
|
||||||
|
NotifyOfPropertyChange(() => Total);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanCheckOut
|
public bool CanCheckOut
|
||||||
|
Loading…
Reference in New Issue
Block a user