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.
153 lines
7.1 KiB
C#
153 lines
7.1 KiB
C#
using Distribution.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Distribution.Data.Seed;
|
|
|
|
public static class OperationsDataSeed
|
|
{
|
|
internal static readonly Guid ClosedSaleRunId = new("31000000-0000-0000-0000-000000000001");
|
|
internal static readonly Guid ActiveDeliveryRunId = new("31000000-0000-0000-0000-000000000002");
|
|
|
|
// Kept for OperationsExtrasSeed stock movement reference (ReferenceId on MovementType.Sale)
|
|
internal static readonly Guid Sale1Id = new("32000000-0000-0000-0000-000000000001");
|
|
|
|
internal static readonly Guid ShopPO1Id = new("33000000-0000-0000-0000-000000000001");
|
|
internal static readonly Guid ShopPO2Id = new("33000000-0000-0000-0000-000000000002");
|
|
|
|
internal static readonly Guid ShopPOItem1Id = new("34000000-0000-0000-0000-000000000001");
|
|
internal static readonly Guid ShopPOItem2Id = new("34000000-0000-0000-0000-000000000002");
|
|
internal static readonly Guid ShopPOItem3Id = new("34000000-0000-0000-0000-000000000003");
|
|
|
|
internal static readonly Guid Invoice1Id = new("34500000-0000-0000-0000-000000000001");
|
|
|
|
internal static readonly Guid LoadingSheet1Id = new("35000000-0000-0000-0000-000000000001");
|
|
|
|
internal static readonly Guid LoadingSheetItem1Id = new("36000000-0000-0000-0000-000000000001");
|
|
internal static readonly Guid LoadingSheetItem2Id = new("36000000-0000-0000-0000-000000000002");
|
|
|
|
internal static readonly Guid DeliveryTask1Id = new("37000000-0000-0000-0000-000000000001");
|
|
|
|
public static void Apply(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<DeliveryRun>().HasData(
|
|
new DeliveryRun
|
|
{
|
|
Id = ClosedSaleRunId,
|
|
Status = RideStatus.Closed,
|
|
FK_VehicleId = MasterDataSeed.VanVehicleId,
|
|
FK_DriverProfileId = MasterDataSeed.Driver1ProfileId,
|
|
Meterstart = 10500,
|
|
Meterend = 10550,
|
|
StartedAt = new DateTime(2026, 8, 25, 8, 0, 0),
|
|
ClosedAt = new DateTime(2026, 8, 25, 14, 0, 0),
|
|
CreatedAt = new DateTime(2026, 8, 25, 7, 30, 0),
|
|
IsActive = true
|
|
},
|
|
new DeliveryRun
|
|
{
|
|
Id = ActiveDeliveryRunId,
|
|
Status = RideStatus.Open,
|
|
FK_VehicleId = MasterDataSeed.TruckVehicleId,
|
|
FK_DriverProfileId = MasterDataSeed.Driver2ProfileId,
|
|
Meterstart = 20300,
|
|
Meterend = 0,
|
|
StartedAt = new DateTime(2026, 8, 30, 9, 0, 0),
|
|
ClosedAt = null,
|
|
CreatedAt = new DateTime(2026, 8, 30, 8, 45, 0),
|
|
IsActive = true
|
|
}
|
|
);
|
|
|
|
modelBuilder.Entity<ShopPO>().HasData(
|
|
new ShopPO
|
|
{
|
|
Id = ShopPO1Id,
|
|
FK_StoreId = MasterDataSeed.FortStoreId,
|
|
RaisedById = MasterDataSeed.SalesRep1UserId,
|
|
InvoiceId = Invoice1Id,
|
|
TotalAmount = 3000m,
|
|
Status = ShopPOStatus.Fulfilled,
|
|
ConfirmedAt = new DateTime(2026, 8, 25, 8, 30, 0),
|
|
ConfirmedBy = MasterDataSeed.Supervisor1UserId,
|
|
FulfilledAt = new DateTime(2026, 8, 25, 13, 0, 0),
|
|
CreatedAt = new DateTime(2026, 8, 25, 9, 0, 0),
|
|
IsActive = true
|
|
},
|
|
new ShopPO
|
|
{
|
|
Id = ShopPO2Id,
|
|
FK_StoreId = MasterDataSeed.KandyStoreId,
|
|
RaisedById = MasterDataSeed.SalesRep2UserId,
|
|
InvoiceId = null,
|
|
TotalAmount = 1200m,
|
|
Status = ShopPOStatus.Pending,
|
|
ConfirmedAt = null,
|
|
ConfirmedBy = null,
|
|
FulfilledAt = null,
|
|
CreatedAt = new DateTime(2026, 8, 30, 10, 0, 0),
|
|
IsActive = true
|
|
}
|
|
);
|
|
|
|
modelBuilder.Entity<ShopPOItem>().HasData(
|
|
new ShopPOItem { Id = ShopPOItem1Id, FK_ShopPOId = ShopPO1Id, FK_ItemId = MasterDataSeed.Coke500ItemId, Quantity = 30, QuantityFulfilled = 30, UnitPrice = 60m, CreatedAt = new DateTime(2026, 8, 25, 9, 0, 0), IsActive = true },
|
|
new ShopPOItem { Id = ShopPOItem2Id, FK_ShopPOId = ShopPO1Id, FK_ItemId = MasterDataSeed.LaysClassicItemId, Quantity = 24, QuantityFulfilled = 24, UnitPrice = 50m, CreatedAt = new DateTime(2026, 8, 25, 9, 0, 0), IsActive = true },
|
|
new ShopPOItem { Id = ShopPOItem3Id, FK_ShopPOId = ShopPO2Id, FK_ItemId = MasterDataSeed.Coke1500ItemId, Quantity = 10, QuantityFulfilled = 0, UnitPrice = 120m, CreatedAt = new DateTime(2026, 8, 30, 10, 0, 0), IsActive = true }
|
|
);
|
|
|
|
modelBuilder.Entity<Invoice>().HasData(
|
|
new Invoice
|
|
{
|
|
Id = Invoice1Id,
|
|
FK_ShopPOId = ShopPO1Id,
|
|
Status = InvoiceStatus.Finalized,
|
|
PaymentStatus = PaymentStatus.Paid,
|
|
CreatedBy = MasterDataSeed.SalesRep1UserId,
|
|
PrintedAt = new DateTime(2026, 8, 25, 8, 45, 0),
|
|
PrintedBy = MasterDataSeed.SalesRep1UserId,
|
|
FinalizedAt = new DateTime(2026, 8, 25, 9, 0, 0),
|
|
FinalizedBy = MasterDataSeed.Supervisor1UserId,
|
|
TotalAmount = 3000m,
|
|
CreatedAt = new DateTime(2026, 8, 25, 8, 30, 0),
|
|
IsActive = true
|
|
}
|
|
);
|
|
|
|
modelBuilder.Entity<LoadingSheet>().HasData(
|
|
new LoadingSheet
|
|
{
|
|
Id = LoadingSheet1Id,
|
|
FK_RideId = ClosedSaleRunId,
|
|
Status = LoadingSheetStatus.Confirmed,
|
|
PopulatedBy = MasterDataSeed.Supervisor1UserId,
|
|
PopulatedAt = new DateTime(2026, 8, 25, 7, 30, 0),
|
|
ConfirmedAt = new DateTime(2026, 8, 25, 7, 45, 0),
|
|
ConfirmedBy = MasterDataSeed.Supervisor1UserId,
|
|
CreatedAt = new DateTime(2026, 8, 25, 7, 30, 0),
|
|
IsActive = true
|
|
}
|
|
);
|
|
|
|
modelBuilder.Entity<LoadingSheetItem>().HasData(
|
|
new LoadingSheetItem { Id = LoadingSheetItem1Id, FK_LoadingSheetId = LoadingSheet1Id, FK_ItemId = MasterDataSeed.Coke500ItemId, FK_WarehouseId = MasterDataSeed.ColomboWarehouseId, QuantityDispatched = 50m, CreatedAt = new DateTime(2026, 8, 25, 7, 30, 0), IsActive = true },
|
|
new LoadingSheetItem { Id = LoadingSheetItem2Id, FK_LoadingSheetId = LoadingSheet1Id, FK_ItemId = MasterDataSeed.LaysClassicItemId, FK_WarehouseId = MasterDataSeed.ColomboWarehouseId, QuantityDispatched = 30m, CreatedAt = new DateTime(2026, 8, 25, 7, 30, 0), IsActive = true }
|
|
);
|
|
|
|
modelBuilder.Entity<DeliveryTask>().HasData(
|
|
new DeliveryTask
|
|
{
|
|
Id = DeliveryTask1Id,
|
|
FK_RideId = ActiveDeliveryRunId,
|
|
FK_ShopPOId = ShopPO2Id,
|
|
Sequence = 1,
|
|
Status = DeliveryTaskStatus.Pending,
|
|
CustomerConfirmed = false,
|
|
ConfirmedAt = null,
|
|
Note = null,
|
|
CreatedAt = new DateTime(2026, 8, 30, 10, 5, 0),
|
|
IsActive = true
|
|
}
|
|
);
|
|
}
|
|
}
|