aboutsummaryrefslogtreecommitdiffstats
path: root/src/Data/Database/Order.cs
blob: 02869b2b07f694f8e8b0f17f452b5b6f1e00788d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Linq;
using IOL.Helpers;
using IOL.VippsEcommerce.Models.Api;
using VSH.Data.Enums;
using VSH.Utilities;

namespace VSH.Data.Database;

public class Order : Base
{
	public string Comment { get; set; }
	public string OrderReference { get; set; }
	public OrderStatus Status { get; set; }
	public OrderPaymentType PaymentType { get; set; }
	public string VippsTransactionId { get; set; }
	public ETransactionStatus VippsTransactionStatus { get; set; }
	public EStatusEnum VippsStatus { get; set; }
	public ContactInformation ContactInfo { get; set; }
	public List<OrderProduct> Products { get; set; }

	public class ContactInformation
	{
		public string Name { get; set; }
		public string PhoneNumber { get; set; }
		public string EmailAddress { get; set; }
	}

	public decimal Total(bool includeTax = true) {
		if (!Products.Any())
			return default;
		var total = Products.Sum(product => product.PriceAtTimeOfOrder * product.NumberOfItems);
		if (includeTax)
			return total;
		var taxCut = total * 25 / 100;
		return total - taxCut;
	}

	public decimal Tax(bool includeTax = true) {
		if (!Products.Any())
			return default;
		var total = Products.Sum(product => product.PriceAtTimeOfOrder * product.NumberOfItems);
		var taxCut = total * 25 / 100;
		return taxCut;
	}

	public string GetAdminMailContent(string hostname) => @$"
Referanse: {OrderReference}
Lenke: {hostname}/kontoret/bestillinger?order={OrderReference}
Betalingsmetode: {EnumName.ForPaymentType(PaymentType)}
Status: {EnumName.ForOrderStatus(Status)}
Navn: {ContactInfo.Name}
E-postadresse: {ContactInfo.EmailAddress}
Telefon: {ContactInfo.PhoneNumber}
{(Comment.HasValue() ? "Kommentar:" + Comment : "")}
";

	public string GetCustomerMailContent(string hostname) => @$"
Hei {ContactInfo.Name}, tusen takk for din bestilling!
 til {hostname}/status/{OrderReference} for å  full oversikt over bestillinga.

Hvis du har spørsmål angående din ordre er det bare å svare  denne mailen  svarer vi  raskt vi kan.

Med venleg hilsen

Øystein og Bodil
Vinjesvingen Handel AS
915 61 900
";
}

public class OrderProduct
{
	public Guid Id { get; set; }

	public int NumberOfItems { get; set; }

	public decimal PriceAtTimeOfOrder { get; set; }

	public decimal Total(bool includeTax = true) {
		if (NumberOfItems == default || PriceAtTimeOfOrder == default)
			return default;
		var total = PriceAtTimeOfOrder * NumberOfItems;
		if (includeTax)
			return total;
		var taxCut = total * 25 / 100;
		return total - taxCut;
	}

	public decimal Tax(bool includeTax = true) {
		if (NumberOfItems == default || PriceAtTimeOfOrder == default)
			return default;
		var total = PriceAtTimeOfOrder * NumberOfItems;
		var taxCut = total * 25 / 100;
		return taxCut;
	}
}