-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCustomerOrder.cs
More file actions
426 lines (341 loc) · 14.5 KB
/
CustomerOrder.cs
File metadata and controls
426 lines (341 loc) · 14.5 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
using System;
using System.Collections.Generic;
using System.Linq;
using VirtoCommerce.CoreModule.Core.Common;
using VirtoCommerce.CoreModule.Core.Tax;
using VirtoCommerce.OrdersModule.Core.Extensions;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Security;
using VirtoCommerce.SearchModule.Core.Model;
namespace VirtoCommerce.OrdersModule.Core.Model
{
public class CustomerOrder : OrderOperation, IHasTaxDetalization, ISupportSecurityScopes, ITaxable, IHasLanguageCode, IHasDiscounts, IHasFeesDetalization, IHasRelevanceScore
{
public byte[] RowVersion { get; set; }
public string CustomerId { get; set; }
public string CustomerName { get; set; }
public string ChannelId { get; set; }
public string StoreId { get; set; }
public string StoreName { get; set; }
public string OrganizationId { get; set; }
public string OrganizationName { get; set; }
public string EmployeeId { get; set; }
public string EmployeeName { get; set; }
/// <summary>
/// The base shopping cart ID the order was created with
/// </summary>
public string ShoppingCartId { get; set; }
/// <summary>
/// This checkbox determines whether the order is a prototype
/// </summary>
public bool IsPrototype { get; set; }
/// <summary>
/// The order internal number provided by customer
/// </summary>
public string PurchaseOrderNumber { get; set; }
/// <summary>
/// Number of subscription associated with this order
/// </summary>
public string SubscriptionNumber { get; set; }
/// <summary>
/// The ID of subscription associated with this order
/// </summary>
public string SubscriptionId { get; set; }
public override string ObjectType { get; set; } = typeof(CustomerOrder).FullName;
public ICollection<Address> Addresses { get; set; }
public ICollection<PaymentIn> InPayments { get; set; }
public ICollection<LineItem> Items { get; set; }
public ICollection<Shipment> Shipments { get; set; }
public ICollection<FeeDetail> FeeDetails { get; set; }
public double? RelevanceScore { get; set; }
#region IHasDiscounts
public ICollection<Discount> Discounts { get; set; }
#endregion
/// <summary>
/// When a discount is applied to the order, the tax calculation has already been applied and is shown in the tax field.
/// Therefore, the discount will not be taking tax into account.
/// For instance, if the cart subtotal is $100, and the tax subtotal is $15, a 10% discount will yield a total of $105 ($100 subtotal – $10 discount + $15 tax).
/// </summary>
[Auditable]
public decimal DiscountAmount { get; set; }
#region ITaxDetailSupport Members
public ICollection<TaxDetail> TaxDetails { get; set; }
#endregion
#region ISupportSecurityScopes Members
public IEnumerable<string> Scopes { get; set; }
#endregion
/// <summary>
/// Order grand total
/// </summary>
[Auditable]
public virtual decimal Total { get; set; }
/// <summary>
/// Amount of the item prices
/// </summary>
public virtual decimal SubTotal { get; set; }
/// <summary>
/// Amount of the item prices with tax
/// </summary>
public virtual decimal SubTotalWithTax { get; set; }
/// <summary>
/// Amount of the item discount total
/// </summary>
public virtual decimal SubTotalDiscount { get; set; }
/// <summary>
/// Amount of the item discount total with tax
/// </summary>
public virtual decimal SubTotalDiscountWithTax { get; set; }
/// <summary>
/// Amount of the item tax total
/// </summary>
public virtual decimal SubTotalTaxTotal { get; set; }
/// <summary>
/// Amount of the shipment total
/// </summary>
public virtual decimal ShippingTotal { get; set; }
/// <summary>
/// Amount of the shipment total with tax
/// </summary>
public virtual decimal ShippingTotalWithTax { get; set; }
/// <summary>
/// Amount of the shipment prices
/// </summary>
public virtual decimal ShippingSubTotal { get; set; }
/// <summary>
/// Amount of the shipment prices with tax
/// </summary>
public virtual decimal ShippingSubTotalWithTax { get; set; }
/// <summary>
/// Amount of the shipment discount amounts
/// </summary>
public virtual decimal ShippingDiscountTotal { get; set; }
/// <summary>
/// Amount of the shipment discount amounts with tax
/// </summary>
public virtual decimal ShippingDiscountTotalWithTax { get; set; }
/// <summary>
/// Reserved for future needs
/// </summary>
public virtual decimal ShippingTaxTotal { get; set; }
/// <summary>
/// Amount of the payments totals
/// </summary>
public virtual decimal PaymentTotal { get; set; }
/// <summary>
/// Amount of the payment totals with tax
/// </summary>
public virtual decimal PaymentTotalWithTax { get; set; }
/// <summary>
/// Amount of the payment prices
/// </summary>
public virtual decimal PaymentSubTotal { get; set; }
/// <summary>
/// Amount of the payment prices with tax
/// </summary>
public virtual decimal PaymentSubTotalWithTax { get; set; }
/// <summary>
/// Amount of the payments discount amounts
/// </summary>
public virtual decimal PaymentDiscountTotal { get; set; }
/// <summary>
/// Amount of the payment discount amounts with tax
/// </summary>
public virtual decimal PaymentDiscountTotalWithTax { get; set; }
/// <summary>
/// Reserved for future needs
/// </summary>
public virtual decimal PaymentTaxTotal { get; set; }
/// <summary>
/// Amount of the discount amounts of items, shipments and payments, and the order discount amount
/// </summary>
public virtual decimal DiscountTotal { get; set; }
/// <summary>
/// Amount of the discount amounts with tax of items, shipments and payments, and the order discount amount with tax
/// </summary>
public virtual decimal DiscountTotalWithTax { get; set; }
/// <summary>
/// Any extra fees applied to the order. This value comes from the cart
/// </summary>
[Auditable]
public decimal Fee { get; set; }
/// <summary>
/// Order fee with applied tax factor
/// </summary>
public virtual decimal FeeWithTax { get; set; }
/// <summary>
/// Amount of the order fee, as well as any item, shipment, and payment fees
/// </summary>
public virtual decimal FeeTotal { get; set; }
/// <summary>
/// Total fee with applied tax factor
/// </summary>
public virtual decimal FeeTotalWithTax { get; set; }
/// <summary>
/// Reserved for future needs
/// </summary>
public virtual decimal HandlingTotal { get; set; }
/// <summary>
/// Reserved for future needs
/// </summary>
public virtual decimal HandlingTotalWithTax { get; set; }
public bool IsAnonymous { get; set; }
#region ITaxable Members
/// <summary>
/// Tax category or type
/// </summary>
[Auditable]
public string TaxType { get; set; }
/// <summary>
/// Amount of tax totals for items, shipments, and payments without the order discount amount with tax factor applied
/// </summary>
[Auditable]
public virtual decimal TaxTotal { get; set; }
[Auditable]
public decimal TaxPercentRate { get; set; }
#endregion
#region ILanguageSupport Members
public string LanguageCode { get; set; }
#endregion
public override void ReduceDetails(string responseGroup)
{
base.ReduceDetails(responseGroup);
// Reduce details according to the response group
var orderResponseGroup = EnumUtility.SafeParseFlags(responseGroup, CustomerOrderResponseGroup.Full);
if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithItems))
{
Items = null;
}
if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithShipments))
{
Shipments = null;
}
if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithInPayments))
{
InPayments = null;
}
if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithAddresses))
{
Addresses = null;
}
if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithDiscounts))
{
Discounts = null;
}
if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithPrices))
{
DiscountAmount = 0m;
DiscountTotal = 0m;
DiscountTotalWithTax = 0m;
Fee = 0m;
FeeTotal = 0m;
FeeTotalWithTax = 0m;
FeeWithTax = 0m;
HandlingTotal = 0m;
HandlingTotalWithTax = 0m;
PaymentDiscountTotal = 0m;
PaymentDiscountTotalWithTax = 0m;
PaymentSubTotal = 0m;
PaymentSubTotalWithTax = 0m;
PaymentTaxTotal = 0m;
PaymentTotal = 0m;
PaymentTotalWithTax = 0m;
ShippingDiscountTotal = 0m;
ShippingDiscountTotalWithTax = 0m;
ShippingSubTotal = 0m;
ShippingSubTotalWithTax = 0m;
ShippingTaxTotal = 0m;
ShippingTotal = 0m;
ShippingTotalWithTax = 0m;
SubTotal = 0m;
SubTotalDiscount = 0m;
SubTotalDiscountWithTax = 0m;
SubTotalTaxTotal = 0m;
SubTotalWithTax = 0m;
TaxPercentRate = 0m;
TaxTotal = 0m;
Total = 0m;
}
foreach (var shipment in Shipments ?? Array.Empty<Shipment>())
{
shipment.ReduceDetails(responseGroup);
}
foreach (var inPayment in InPayments ?? Array.Empty<PaymentIn>())
{
inPayment.ReduceDetails(responseGroup);
}
foreach (var item in Items ?? Array.Empty<LineItem>())
{
item.ReduceDetails(responseGroup);
}
}
public override void RestoreDetails(OrderOperation operation)
{
base.RestoreDetails(operation);
if (operation is not CustomerOrder order)
{
return;
}
DiscountAmount = order.DiscountAmount;
DiscountTotal = order.DiscountTotal;
DiscountTotalWithTax = order.DiscountTotalWithTax;
Fee = order.Fee;
FeeTotal = order.FeeTotal;
FeeTotalWithTax = order.FeeTotalWithTax;
FeeWithTax = order.FeeWithTax;
HandlingTotal = order.HandlingTotal;
HandlingTotalWithTax = order.HandlingTotalWithTax;
PaymentDiscountTotal = order.PaymentDiscountTotal;
PaymentDiscountTotalWithTax = order.PaymentDiscountTotalWithTax;
PaymentSubTotal = order.PaymentSubTotal;
PaymentSubTotalWithTax = order.PaymentSubTotalWithTax;
PaymentTaxTotal = order.PaymentTaxTotal;
PaymentTotal = order.PaymentTotal;
PaymentTotalWithTax = order.PaymentTotalWithTax;
ShippingDiscountTotal = order.ShippingDiscountTotal;
ShippingDiscountTotalWithTax = order.ShippingDiscountTotalWithTax;
ShippingSubTotal = order.ShippingSubTotal;
ShippingSubTotalWithTax = order.ShippingSubTotalWithTax;
ShippingTaxTotal = order.ShippingTaxTotal;
ShippingTotal = order.ShippingTotal;
ShippingTotalWithTax = order.ShippingTotalWithTax;
SubTotal = order.SubTotal;
SubTotalDiscount = order.SubTotalDiscount;
SubTotalDiscountWithTax = order.SubTotalDiscountWithTax;
SubTotalTaxTotal = order.SubTotalTaxTotal;
SubTotalWithTax = order.SubTotalWithTax;
TaxPercentRate = order.TaxPercentRate;
TaxTotal = order.TaxTotal;
Total = order.Total;
foreach (var shipment in order.Shipments ?? Array.Empty<Shipment>())
{
var targetShipment = Shipments?.FirstOrDefault(x => x.Id == shipment.Id);
targetShipment?.RestoreDetails(shipment);
}
foreach (var payment in order.InPayments ?? Array.Empty<PaymentIn>())
{
var targetPayment = InPayments?.FirstOrDefault(x => x.Id == payment.Id);
targetPayment?.RestoreDetails(payment);
}
foreach (var item in order.Items ?? Array.Empty<LineItem>())
{
var targetItem = Items?.FirstOrDefault(x => x.Id == item.Id);
targetItem?.RestoreDetails(item);
}
}
#region ICloneable members
public override object Clone()
{
var result = base.Clone() as CustomerOrder;
result.TaxDetails = TaxDetails?.Select(x => x.Clone()).OfType<TaxDetail>().ToList();
result.Addresses = Addresses?.Select(x => x.Clone()).OfType<Address>().ToList();
result.InPayments = InPayments?.Select(x => x.Clone()).OfType<PaymentIn>().ToList();
result.Items = Items?.Select(x => x.Clone()).OfType<LineItem>().ToList();
result.Shipments = Shipments?.Select(x => x.Clone()).OfType<Shipment>().ToList();
result.Discounts = Discounts?.Select(x => x.Clone()).OfType<Discount>().ToList();
result.FeeDetails = FeeDetails?.Select(x => x.Clone()).OfType<FeeDetail>().ToList();
result.FillChildOperations();
return result;
}
#endregion
}
}