93f2f1bd3b
Major refactor replacing Sale/Order with ShopPO → Invoice → LoadingSheet flow. Removed legacy Sale/Order models and features; introduced ShopPO, ShopPOItem, Invoice, LoadingSheetOrder, and SysConfig models. Updated related entities, enums, repositories, and controllers. Added new migrations for schema changes and system config. Overhauled business logic and DI registrations. Updated documentation with migration plan.
118 lines
6.1 KiB
C#
118 lines
6.1 KiB
C#
using Distribution.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Distribution.Data.Seed;
|
|
|
|
public static class CommerceSeed
|
|
{
|
|
private static readonly Guid PriceList1Id = new("39000000-0000-0000-0000-000000000001");
|
|
private static readonly Guid PriceListItem1Id = new("40000000-0000-0000-0000-000000000001");
|
|
private static readonly Guid PriceListItem2Id = new("40000000-0000-0000-0000-000000000002");
|
|
|
|
private static readonly Guid Scheme1Id = new("48000000-0000-0000-0000-000000000001");
|
|
private static readonly Guid Scheme2Id = new("48000000-0000-0000-0000-000000000002");
|
|
|
|
private static readonly Guid SchemeBundleComponent1Id = new("49000000-0000-0000-0000-000000000001");
|
|
private static readonly Guid SchemeRedemption1Id = new("50000000-0000-0000-0000-000000000001");
|
|
|
|
private static readonly Guid Payment1Id = new("47000000-0000-0000-0000-000000000001");
|
|
|
|
private static readonly Guid SaleReturn1Id = new("51000000-0000-0000-0000-000000000001");
|
|
private static readonly Guid SaleReturnItem1Id = new("52000000-0000-0000-0000-000000000001");
|
|
private static readonly Guid CreditNote1Id = new("54000000-0000-0000-0000-000000000001");
|
|
|
|
private static readonly Guid Claim1Id = new("53000000-0000-0000-0000-000000000001");
|
|
|
|
public static void Apply(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<PriceList>().HasData(
|
|
new PriceList { Id = PriceList1Id, Name = "Western Province Price List", FK_RegionId = MasterDataSeed.WesternRegionId, EffectiveFrom = new DateTime(2026, 1, 1), EffectiveTo = new DateTime(2026, 12, 31), CreatedAt = new DateTime(2026, 8, 1), IsActive = true }
|
|
);
|
|
|
|
modelBuilder.Entity<PriceListItem>().HasData(
|
|
new PriceListItem { Id = PriceListItem1Id, FK_PriceListId = PriceList1Id, FK_ItemId = MasterDataSeed.Coke500ItemId, Price = 60m, MinPrice = 55m, CreatedAt = new DateTime(2026, 8, 1), IsActive = true },
|
|
new PriceListItem { Id = PriceListItem2Id, FK_PriceListId = PriceList1Id, FK_ItemId = MasterDataSeed.LaysClassicItemId, Price = 50m, MinPrice = 45m, CreatedAt = new DateTime(2026, 8, 1), IsActive = true }
|
|
);
|
|
|
|
modelBuilder.Entity<Scheme>().HasData(
|
|
new Scheme
|
|
{
|
|
Id = Scheme1Id,
|
|
Name = "Buy 10 Coke Get 1 Free",
|
|
RuleType = SchemeRuleType.BuyXGetY,
|
|
RuleConfig = null,
|
|
FK_TriggerItemId = MasterDataSeed.Coke500ItemId,
|
|
TriggerQty = 10,
|
|
FK_FreeItemId = MasterDataSeed.Coke500ItemId,
|
|
FreeQty = 1m,
|
|
FK_RegionId = MasterDataSeed.WesternRegionId,
|
|
EligibleSegment = null,
|
|
DateRangeFrom = new DateTime(2026, 8, 1),
|
|
DateRangeTo = new DateTime(2026, 12, 31),
|
|
AgentLimitExempt = false,
|
|
BaselineExpectedSales = 500000m,
|
|
CreatedAt = new DateTime(2026, 8, 1),
|
|
IsActive = true
|
|
},
|
|
new Scheme
|
|
{
|
|
Id = Scheme2Id,
|
|
Name = "Snack Combo Bundle",
|
|
RuleType = SchemeRuleType.FreeBundle,
|
|
RuleConfig = null,
|
|
FK_TriggerItemId = null,
|
|
TriggerQty = null,
|
|
FK_FreeItemId = MasterDataSeed.LaysFamilyItemId,
|
|
FreeQty = 1m,
|
|
FK_RegionId = MasterDataSeed.CentralRegionId,
|
|
EligibleSegment = null,
|
|
DateRangeFrom = new DateTime(2026, 8, 1),
|
|
DateRangeTo = new DateTime(2026, 12, 31),
|
|
AgentLimitExempt = false,
|
|
BaselineExpectedSales = null,
|
|
CreatedAt = new DateTime(2026, 8, 1),
|
|
IsActive = true
|
|
}
|
|
);
|
|
|
|
modelBuilder.Entity<SchemeBundleComponent>().HasData(
|
|
new SchemeBundleComponent { Id = SchemeBundleComponent1Id, FK_SchemeId = Scheme2Id, FK_ItemId = MasterDataSeed.LaysClassicItemId, Qty = 5 }
|
|
);
|
|
|
|
modelBuilder.Entity<SchemeRedemption>().HasData(
|
|
new SchemeRedemption { Id = SchemeRedemption1Id, FK_SchemeId = Scheme1Id, FK_ShopPOId = OperationsDataSeed.ShopPO1Id, FieldInvoiceId = null, DiscountAmount = 0m, FK_FreeItemId = MasterDataSeed.Coke500ItemId, FreeQty = 1m, FreeItemCostValue = 40m, RedeemedAt = new DateTime(2026, 8, 25, 9, 30, 0) }
|
|
);
|
|
|
|
modelBuilder.Entity<Payment>().HasData(
|
|
new Payment { Id = Payment1Id, FK_InvoiceId = OperationsDataSeed.Invoice1Id, Amount = 3000m, Method = PaymentMethod.Cash, CollectedAt = new DateTime(2026, 8, 25, 9, 30, 0), CollectedBy = MasterDataSeed.SalesRep1UserId, CreatedAt = new DateTime(2026, 8, 25, 9, 30, 0), IsActive = true }
|
|
);
|
|
|
|
modelBuilder.Entity<SaleReturn>().HasData(
|
|
new SaleReturn { Id = SaleReturn1Id, FK_ShopPOId = OperationsDataSeed.ShopPO1Id, Mode = ReturnMode.CreditDeduction, TotalCreditAmount = 300m, CreatedByUserId = MasterDataSeed.SalesRep1UserId, CreatedAt = new DateTime(2026, 8, 26), IsActive = true }
|
|
);
|
|
|
|
modelBuilder.Entity<SaleReturnItem>().HasData(
|
|
new SaleReturnItem { Id = SaleReturnItem1Id, FK_SaleReturnId = SaleReturn1Id, FK_ItemId = MasterDataSeed.Coke500ItemId, Quantity = 5m, ReasonCode = ReturnReasonCode.Damaged, UnitPrice = 60m, CreatedAt = new DateTime(2026, 8, 26), IsActive = true }
|
|
);
|
|
|
|
modelBuilder.Entity<CreditNote>().HasData(
|
|
new CreditNote { Id = CreditNote1Id, FK_SaleReturnId = SaleReturn1Id, Amount = 300m, IssuedAt = new DateTime(2026, 8, 26), CreatedAt = new DateTime(2026, 8, 26), IsActive = true }
|
|
);
|
|
|
|
modelBuilder.Entity<Claim>().HasData(
|
|
new Claim
|
|
{
|
|
Id = Claim1Id,
|
|
FK_AgencyUserId = OperationsExtrasSeed.RegionalAgency1UserId,
|
|
Details = "Distributor margin claim for Q3 promotional shortfall",
|
|
Status = ClaimStatus.Settled,
|
|
SettlementAmount = 15000m,
|
|
SettledByUserId = MasterDataSeed.RegionalManager1UserId,
|
|
SettledAt = new DateTime(2026, 8, 28),
|
|
CreatedAt = new DateTime(2026, 8, 27),
|
|
IsActive = true
|
|
}
|
|
);
|
|
}
|
|
}
|