I can’t explain in detail why we have a seperate VAT on the channel, but I have heard that we had issues getting correct prices when we set the countries VAT rate other than 0.
Ok so I tested the IVatFactory and tried to manipulate the prices to out channels VAT, but the orderrows themselves are not changed:
{
"action": "Litium.Connect.Erp.Events.OrderConfirmed",
"properties": {
"RemoteIpAddress": "::1",
"Device": "PostmanRuntime/7.32.3"
},
"resource": {
"systemId": "870181aa-7620-4b50-96ec-a6b4fd4b73f3",
"item": {
"id": "LS10550",
"currencyCode": "SEK",
"grandTotal": 350,
"orderCreatedAt": "2023-09-14T11:54:41.2259485Z",
"channelId": "test",
"webSiteId": "test",
"countryCode": "SE",
"type": "salesOrder",
"clientIp": "127.0.0.1",
"comments": "||",
"additionalInfo": {},
"rows": [
{
"id": "1",
"type": "product",
"articleNumber": "1046263",
"descriptions": "USB-A - USB-C",
"unitPriceIncludingVat": 280,
"unitPriceExcludingVat": 280,
"quantity": 1,
"unitOfMeasurement": "st",
"vatRate": 25,
"totalIncludingVat": 280,
"totalExcludingVat": 280,
"additionalInfo": {}
}
],
"vatSummary": {
"0": 0
},
"promotions": [],
"payments": [
{
"id": "LSP11179",
"paymentProviderName": "DirectPayment",
"paymentMethodName": "DirectPay",
"paymentAccountId": "",
"totalAuthorizedAmount": 350,
"transactions": [
{
"id": "----------",
"type": "authorize",
"totalIncludingVat": 350,
"totalExcludingVat": 280,
"rows": [
{
"orderRowId": "1",
"type": "product",
"descriptions": "USB-A - USB-C",
"unitPriceIncludingVat": 350,
"unitPriceExcludingVat": 280,
"quantity": 1,
"vatRate": 25,
"totalIncludingVat": 350,
"totalExcludingVat": 280,
"additionalInfo": {}
}
]
},
{
"id": "LSP11179T1",
"totalIncludingVat": 350,
"totalExcludingVat": 280,
"rows": [
{
"orderRowId": "1",
"type": "product",
"descriptions": "USB-A - USB-C",
"unitPriceIncludingVat": 350,
"unitPriceExcludingVat": 280,
"quantity": 1,
"vatRate": 25,
"totalIncludingVat": 350,
"totalExcludingVat": 280,
"additionalInfo": {}
}
]
}
]
}
],
"shipments": [],
"customerInfo": {
"customerNumber": "K1129186",
"firstName": "Lucas",
"lastName": "Wiseby",
"email": "---------",
"organizationCustomerNumber": "K1129186",
"additionalInfo": {}
},
"billingAddress": {
"address1": "Testvägen 11",
"city": "Saltsjö Boo",
"country": "SE",
"zip": "13249",
"organizationName": "Test Litiumintegration AB"
},
"shippingInfo": [
{
"shippingMethod": "standardPackage",
"additionalInfo": {
"IsFreeShipping": true
},
"address": {
"careOf": "företag",
"address1": "hej",
"address2": "då",
"city": "Borås",
"country": "SE",
"phone": "123123123",
"zip": "123123",
"organizationName": "Test Litiumintegration AB"
}
}
],
"rmas": []
}
},
"metadata": {
"attempt": 1,
"eventSystemId": "fec6bb6b-ea55-4dc4-9d6b-6a19719e242a",
"registrationId": "orderconfirmedtest1"
}
}
As you can see, the transactions are correct but the “rows” stay the same.
This is my factory for testing:
using System.Linq;
using JetBrains.Annotations;
using Litium.Runtime.DependencyInjection;
using Litium.Sales;
using Litium.Sales.Calculator;
namespace Litium.Accelerator.Services;
[UsedImplicitly]
[ServiceDecorator(typeof(IVatRuleFactory))]
internal class CustomVatRuleFactory : IVatRuleFactory
{
private readonly IVatRuleFactory _parent;
private readonly BaseSalesVat _baseSalesVatRule;
public CustomVatRuleFactory(IVatRuleFactory _parent, BaseSalesVat baseSalesVatRule)
{
this._parent = _parent;
_baseSalesVatRule = baseSalesVatRule;
}
public IVatRule Create<T>(Order<T> order) where T : OrderRow
{
return _baseSalesVatRule;
}
}
[Service(ServiceType = typeof(BaseSalesVat))]
public class BaseSalesVat : IVatRule
{
public void CalculateVat<T>(Order<T> order) where T : OrderRow
{
CalculateVat(order, 25.0m);
}
private void CalculateVat<T>(Order<T> order, decimal vat) where T : OrderRow
{
foreach (var row in order.Rows)
{
row.VatRate = vat;
var rowVat = vat / 100 * row.TotalExcludingVat;
var rowUnitVat = vat / 100 * row.UnitPriceExcludingVat;
row.UnitPriceIncludingVat = row.UnitPriceExcludingVat + rowUnitVat;
row.TotalIncludingVat = row.TotalExcludingVat + rowVat;
row.VatDetails.Clear();
row.VatDetails.Add(new VatDetail
{
Vat = rowVat, VatRate = vat,
AmountIncludingVat = row.TotalIncludingVat
});
}
}
}