Dev #55

Merged
DeepnaPooja merged 17 commits from dev into production 2026-10-07 10:47:55 +05:30
11 changed files with 9799 additions and 12 deletions
Showing only changes of commit c358764f4e - Show all commits
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,505 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace Distribution.Migrations
{
/// <inheritdoc />
public partial class AddItemTrackingConfig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "FK_ItemBatchId",
table: "StockMovements",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.AddColumn<Guid>(
name: "FK_ItemSerialNumberId",
table: "StockMovements",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.AddColumn<Guid>(
name: "FK_ItemBatchId",
table: "StockBalances",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.AddColumn<Guid>(
name: "FK_ItemSerialNumberId",
table: "StockBalances",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.AddColumn<bool>(
name: "AllowCustomWarrantyPeriod",
table: "Items",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "HasWarranty",
table: "Items",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "TracksBatches",
table: "Items",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "TracksExpiryDate",
table: "Items",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "TracksSerialNumbers",
table: "Items",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<int>(
name: "WarrantyPeriodDays",
table: "Items",
type: "int",
nullable: true);
migrationBuilder.CreateTable(
name: "ItemBatches",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
FK_ItemId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
BatchNumber = table.Column<string>(type: "varchar(255)", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ManufactureDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
ExpiryDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ItemBatches", x => x.Id);
table.ForeignKey(
name: "FK_ItemBatches_Items_FK_ItemId",
column: x => x.FK_ItemId,
principalTable: "Items",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "ItemSerialNumbers",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
FK_ItemId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
SerialNumber = table.Column<string>(type: "varchar(255)", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Status = table.Column<int>(type: "int", nullable: false),
CurrentLocationId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
CurrentLocationType = table.Column<int>(type: "int", nullable: true),
ReceivedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
WarrantyPeriodDaysOverride = table.Column<int>(type: "int", nullable: true),
WarrantyExpiresAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ItemSerialNumbers", x => x.Id);
table.ForeignKey(
name: "FK_ItemSerialNumbers_Items_FK_ItemId",
column: x => x.FK_ItemId,
principalTable: "Items",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "GoodsReceiptItemBatches",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
FK_GoodsReceiptItemId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
FK_ItemBatchId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
Quantity = table.Column<int>(type: "int", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GoodsReceiptItemBatches", x => x.Id);
table.ForeignKey(
name: "FK_GoodsReceiptItemBatches_GoodsReceiptItems_FK_GoodsReceiptIte~",
column: x => x.FK_GoodsReceiptItemId,
principalTable: "GoodsReceiptItems",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_GoodsReceiptItemBatches_ItemBatches_FK_ItemBatchId",
column: x => x.FK_ItemBatchId,
principalTable: "ItemBatches",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "GoodsReceiptItemSerials",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
FK_GoodsReceiptItemId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
FK_ItemSerialNumberId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GoodsReceiptItemSerials", x => x.Id);
table.ForeignKey(
name: "FK_GoodsReceiptItemSerials_GoodsReceiptItems_FK_GoodsReceiptIte~",
column: x => x.FK_GoodsReceiptItemId,
principalTable: "GoodsReceiptItems",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_GoodsReceiptItemSerials_ItemSerialNumbers_FK_ItemSerialNumbe~",
column: x => x.FK_ItemSerialNumberId,
principalTable: "ItemSerialNumbers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.UpdateData(
table: "Items",
keyColumn: "Id",
keyValue: new Guid("23000000-0000-0000-0000-000000000001"),
columns: new[] { "AllowCustomWarrantyPeriod", "HasWarranty", "TracksBatches", "TracksExpiryDate", "TracksSerialNumbers", "WarrantyPeriodDays" },
values: new object[] { false, false, false, false, false, null });
migrationBuilder.UpdateData(
table: "Items",
keyColumn: "Id",
keyValue: new Guid("23000000-0000-0000-0000-000000000002"),
columns: new[] { "AllowCustomWarrantyPeriod", "HasWarranty", "TracksBatches", "TracksExpiryDate", "TracksSerialNumbers", "WarrantyPeriodDays" },
values: new object[] { false, false, false, false, false, null });
migrationBuilder.UpdateData(
table: "Items",
keyColumn: "Id",
keyValue: new Guid("23000000-0000-0000-0000-000000000003"),
columns: new[] { "AllowCustomWarrantyPeriod", "HasWarranty", "TracksBatches", "TracksExpiryDate", "TracksSerialNumbers", "WarrantyPeriodDays" },
values: new object[] { false, false, false, false, false, null });
migrationBuilder.UpdateData(
table: "Items",
keyColumn: "Id",
keyValue: new Guid("23000000-0000-0000-0000-000000000004"),
columns: new[] { "AllowCustomWarrantyPeriod", "HasWarranty", "TracksBatches", "TracksExpiryDate", "TracksSerialNumbers", "WarrantyPeriodDays" },
values: new object[] { false, false, false, false, false, null });
migrationBuilder.UpdateData(
table: "StockBalances",
keyColumn: "Id",
keyValue: new Guid("61000000-0000-0000-0000-000000000001"),
columns: new[] { "FK_ItemBatchId", "FK_ItemSerialNumberId" },
values: new object[] { null, null });
migrationBuilder.UpdateData(
table: "StockBalances",
keyColumn: "Id",
keyValue: new Guid("61000000-0000-0000-0000-000000000002"),
columns: new[] { "FK_ItemBatchId", "FK_ItemSerialNumberId" },
values: new object[] { null, null });
migrationBuilder.UpdateData(
table: "StockBalances",
keyColumn: "Id",
keyValue: new Guid("61000000-0000-0000-0000-000000000003"),
columns: new[] { "FK_ItemBatchId", "FK_ItemSerialNumberId" },
values: new object[] { null, null });
migrationBuilder.UpdateData(
table: "StockMovements",
keyColumn: "Id",
keyValue: new Guid("62000000-0000-0000-0000-000000000001"),
columns: new[] { "FK_ItemBatchId", "FK_ItemSerialNumberId" },
values: new object[] { null, null });
migrationBuilder.UpdateData(
table: "StockMovements",
keyColumn: "Id",
keyValue: new Guid("62000000-0000-0000-0000-000000000002"),
columns: new[] { "FK_ItemBatchId", "FK_ItemSerialNumberId" },
values: new object[] { null, null });
migrationBuilder.UpdateData(
table: "StockMovements",
keyColumn: "Id",
keyValue: new Guid("62000000-0000-0000-0000-000000000003"),
columns: new[] { "FK_ItemBatchId", "FK_ItemSerialNumberId" },
values: new object[] { null, null });
migrationBuilder.InsertData(
table: "SysConfigs",
columns: new[] { "Key", "UpdatedAt", "UpdatedBy", "Value" },
values: new object[,]
{
{ "Feature.BatchTracking", new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, "false" },
{ "Feature.CustomWarrantyOverride", new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, "false" },
{ "Feature.DefaultWarrantyPeriodDays", new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, "0" },
{ "Feature.ExpiryDateTracking", new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, "false" },
{ "Feature.SerialNumberTracking", new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, "false" },
{ "Feature.WarrantyTracking", new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, "false" }
});
migrationBuilder.CreateIndex(
name: "IX_StockMovements_FK_ItemBatchId",
table: "StockMovements",
column: "FK_ItemBatchId");
migrationBuilder.CreateIndex(
name: "IX_StockMovements_FK_ItemSerialNumberId",
table: "StockMovements",
column: "FK_ItemSerialNumberId");
migrationBuilder.CreateIndex(
name: "IX_StockBalances_FK_ItemBatchId",
table: "StockBalances",
column: "FK_ItemBatchId");
migrationBuilder.CreateIndex(
name: "IX_StockBalances_FK_ItemId_LocationId_FK_ItemBatchId_FK_ItemSer~",
table: "StockBalances",
columns: new[] { "FK_ItemId", "LocationId", "FK_ItemBatchId", "FK_ItemSerialNumberId" },
unique: true);
// The old 2-column index must be dropped only after the new composite index exists,
// since MySQL won't drop an index that's the only one backing a FK (FK_ItemId here).
migrationBuilder.DropIndex(
name: "IX_StockBalances_FK_ItemId_LocationId",
table: "StockBalances");
migrationBuilder.CreateIndex(
name: "IX_StockBalances_FK_ItemSerialNumberId",
table: "StockBalances",
column: "FK_ItemSerialNumberId");
migrationBuilder.CreateIndex(
name: "IX_GoodsReceiptItemBatches_FK_GoodsReceiptItemId",
table: "GoodsReceiptItemBatches",
column: "FK_GoodsReceiptItemId");
migrationBuilder.CreateIndex(
name: "IX_GoodsReceiptItemBatches_FK_ItemBatchId",
table: "GoodsReceiptItemBatches",
column: "FK_ItemBatchId");
migrationBuilder.CreateIndex(
name: "IX_GoodsReceiptItemSerials_FK_GoodsReceiptItemId",
table: "GoodsReceiptItemSerials",
column: "FK_GoodsReceiptItemId");
migrationBuilder.CreateIndex(
name: "IX_GoodsReceiptItemSerials_FK_ItemSerialNumberId",
table: "GoodsReceiptItemSerials",
column: "FK_ItemSerialNumberId");
migrationBuilder.CreateIndex(
name: "IX_ItemBatches_FK_ItemId_BatchNumber",
table: "ItemBatches",
columns: new[] { "FK_ItemId", "BatchNumber" });
migrationBuilder.CreateIndex(
name: "IX_ItemSerialNumbers_FK_ItemId_SerialNumber",
table: "ItemSerialNumbers",
columns: new[] { "FK_ItemId", "SerialNumber" },
unique: true);
migrationBuilder.AddForeignKey(
name: "FK_StockBalances_ItemBatches_FK_ItemBatchId",
table: "StockBalances",
column: "FK_ItemBatchId",
principalTable: "ItemBatches",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_StockBalances_ItemSerialNumbers_FK_ItemSerialNumberId",
table: "StockBalances",
column: "FK_ItemSerialNumberId",
principalTable: "ItemSerialNumbers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_StockMovements_ItemBatches_FK_ItemBatchId",
table: "StockMovements",
column: "FK_ItemBatchId",
principalTable: "ItemBatches",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_StockMovements_ItemSerialNumbers_FK_ItemSerialNumberId",
table: "StockMovements",
column: "FK_ItemSerialNumberId",
principalTable: "ItemSerialNumbers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_StockBalances_ItemBatches_FK_ItemBatchId",
table: "StockBalances");
migrationBuilder.DropForeignKey(
name: "FK_StockBalances_ItemSerialNumbers_FK_ItemSerialNumberId",
table: "StockBalances");
migrationBuilder.DropForeignKey(
name: "FK_StockMovements_ItemBatches_FK_ItemBatchId",
table: "StockMovements");
migrationBuilder.DropForeignKey(
name: "FK_StockMovements_ItemSerialNumbers_FK_ItemSerialNumberId",
table: "StockMovements");
migrationBuilder.DropTable(
name: "GoodsReceiptItemBatches");
migrationBuilder.DropTable(
name: "GoodsReceiptItemSerials");
migrationBuilder.DropTable(
name: "ItemBatches");
migrationBuilder.DropTable(
name: "ItemSerialNumbers");
migrationBuilder.DropIndex(
name: "IX_StockMovements_FK_ItemBatchId",
table: "StockMovements");
migrationBuilder.DropIndex(
name: "IX_StockMovements_FK_ItemSerialNumberId",
table: "StockMovements");
migrationBuilder.DropIndex(
name: "IX_StockBalances_FK_ItemBatchId",
table: "StockBalances");
// Recreate the old 2-column index before dropping the composite one, since MySQL
// won't drop an index that's the only one backing the FK_ItemId FK constraint.
migrationBuilder.CreateIndex(
name: "IX_StockBalances_FK_ItemId_LocationId",
table: "StockBalances",
columns: new[] { "FK_ItemId", "LocationId" },
unique: true);
migrationBuilder.DropIndex(
name: "IX_StockBalances_FK_ItemId_LocationId_FK_ItemBatchId_FK_ItemSer~",
table: "StockBalances");
migrationBuilder.DropIndex(
name: "IX_StockBalances_FK_ItemSerialNumberId",
table: "StockBalances");
migrationBuilder.DeleteData(
table: "SysConfigs",
keyColumn: "Key",
keyValue: "Feature.BatchTracking");
migrationBuilder.DeleteData(
table: "SysConfigs",
keyColumn: "Key",
keyValue: "Feature.CustomWarrantyOverride");
migrationBuilder.DeleteData(
table: "SysConfigs",
keyColumn: "Key",
keyValue: "Feature.DefaultWarrantyPeriodDays");
migrationBuilder.DeleteData(
table: "SysConfigs",
keyColumn: "Key",
keyValue: "Feature.ExpiryDateTracking");
migrationBuilder.DeleteData(
table: "SysConfigs",
keyColumn: "Key",
keyValue: "Feature.SerialNumberTracking");
migrationBuilder.DeleteData(
table: "SysConfigs",
keyColumn: "Key",
keyValue: "Feature.WarrantyTracking");
migrationBuilder.DropColumn(
name: "FK_ItemBatchId",
table: "StockMovements");
migrationBuilder.DropColumn(
name: "FK_ItemSerialNumberId",
table: "StockMovements");
migrationBuilder.DropColumn(
name: "FK_ItemBatchId",
table: "StockBalances");
migrationBuilder.DropColumn(
name: "FK_ItemSerialNumberId",
table: "StockBalances");
migrationBuilder.DropColumn(
name: "AllowCustomWarrantyPeriod",
table: "Items");
migrationBuilder.DropColumn(
name: "HasWarranty",
table: "Items");
migrationBuilder.DropColumn(
name: "TracksBatches",
table: "Items");
migrationBuilder.DropColumn(
name: "TracksExpiryDate",
table: "Items");
migrationBuilder.DropColumn(
name: "TracksSerialNumbers",
table: "Items");
migrationBuilder.DropColumn(
name: "WarrantyPeriodDays",
table: "Items");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,148 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Distribution.Migrations
{
/// <inheritdoc />
public partial class AddDirectGoodsReceipt : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<Guid>(
name: "FK_PurchaseOrderId",
table: "GoodsReceipts",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci",
oldClrType: typeof(Guid),
oldType: "char(36)")
.OldAnnotation("Relational:Collation", "ascii_general_ci");
migrationBuilder.AddColumn<Guid>(
name: "FK_SupplierId",
table: "GoodsReceipts",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.AlterColumn<Guid>(
name: "FK_PurchaseOrderItemId",
table: "GoodsReceiptItems",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci",
oldClrType: typeof(Guid),
oldType: "char(36)")
.OldAnnotation("Relational:Collation", "ascii_general_ci");
migrationBuilder.AddColumn<Guid>(
name: "FK_ItemId",
table: "GoodsReceiptItems",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.UpdateData(
table: "GoodsReceiptItems",
keyColumn: "Id",
keyValue: new Guid("44000000-0000-0000-0000-000000000001"),
column: "FK_ItemId",
value: null);
migrationBuilder.UpdateData(
table: "GoodsReceiptItems",
keyColumn: "Id",
keyValue: new Guid("44000000-0000-0000-0000-000000000002"),
column: "FK_ItemId",
value: null);
migrationBuilder.UpdateData(
table: "GoodsReceipts",
keyColumn: "Id",
keyValue: new Guid("43000000-0000-0000-0000-000000000001"),
column: "FK_SupplierId",
value: null);
migrationBuilder.CreateIndex(
name: "IX_GoodsReceipts_FK_SupplierId",
table: "GoodsReceipts",
column: "FK_SupplierId");
migrationBuilder.CreateIndex(
name: "IX_GoodsReceiptItems_FK_ItemId",
table: "GoodsReceiptItems",
column: "FK_ItemId");
migrationBuilder.AddForeignKey(
name: "FK_GoodsReceiptItems_Items_FK_ItemId",
table: "GoodsReceiptItems",
column: "FK_ItemId",
principalTable: "Items",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_GoodsReceipts_Suppliers_FK_SupplierId",
table: "GoodsReceipts",
column: "FK_SupplierId",
principalTable: "Suppliers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_GoodsReceiptItems_Items_FK_ItemId",
table: "GoodsReceiptItems");
migrationBuilder.DropForeignKey(
name: "FK_GoodsReceipts_Suppliers_FK_SupplierId",
table: "GoodsReceipts");
migrationBuilder.DropIndex(
name: "IX_GoodsReceipts_FK_SupplierId",
table: "GoodsReceipts");
migrationBuilder.DropIndex(
name: "IX_GoodsReceiptItems_FK_ItemId",
table: "GoodsReceiptItems");
migrationBuilder.DropColumn(
name: "FK_SupplierId",
table: "GoodsReceipts");
migrationBuilder.DropColumn(
name: "FK_ItemId",
table: "GoodsReceiptItems");
migrationBuilder.AlterColumn<Guid>(
name: "FK_PurchaseOrderId",
table: "GoodsReceipts",
type: "char(36)",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
collation: "ascii_general_ci",
oldClrType: typeof(Guid),
oldType: "char(36)",
oldNullable: true)
.OldAnnotation("Relational:Collation", "ascii_general_ci");
migrationBuilder.AlterColumn<Guid>(
name: "FK_PurchaseOrderItemId",
table: "GoodsReceiptItems",
type: "char(36)",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
collation: "ascii_general_ci",
oldClrType: typeof(Guid),
oldType: "char(36)",
oldNullable: true)
.OldAnnotation("Relational:Collation", "ascii_general_ci");
}
}
}
@@ -427,12 +427,15 @@ namespace Distribution.Migrations
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<Guid>("FK_PurchaseOrderId")
b.Property<Guid?>("FK_PurchaseOrderId")
.HasColumnType("char(36)");
b.Property<Guid>("FK_ReceivedByUserId")
.HasColumnType("char(36)");
b.Property<Guid?>("FK_SupplierId")
.HasColumnType("char(36)");
b.Property<Guid>("FK_WarehouseId")
.HasColumnType("char(36)");
@@ -446,6 +449,8 @@ namespace Distribution.Migrations
b.HasIndex("FK_PurchaseOrderId");
b.HasIndex("FK_SupplierId");
b.HasIndex("FK_WarehouseId");
b.ToTable("GoodsReceipts");
@@ -478,7 +483,10 @@ namespace Distribution.Migrations
b.Property<Guid>("FK_GoodsReceiptId")
.HasColumnType("char(36)");
b.Property<Guid>("FK_PurchaseOrderItemId")
b.Property<Guid?>("FK_ItemId")
.HasColumnType("char(36)");
b.Property<Guid?>("FK_PurchaseOrderItemId")
.HasColumnType("char(36)");
b.Property<bool>("IsActive")
@@ -491,6 +499,8 @@ namespace Distribution.Migrations
b.HasIndex("FK_GoodsReceiptId");
b.HasIndex("FK_ItemId");
b.HasIndex("FK_PurchaseOrderItemId");
b.ToTable("GoodsReceiptItems");
@@ -518,6 +528,63 @@ namespace Distribution.Migrations
});
});
modelBuilder.Entity("Distribution.Models.GoodsReceiptItemBatch", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<Guid>("FK_GoodsReceiptItemId")
.HasColumnType("char(36)");
b.Property<Guid>("FK_ItemBatchId")
.HasColumnType("char(36)");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<int>("Quantity")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("FK_GoodsReceiptItemId");
b.HasIndex("FK_ItemBatchId");
b.ToTable("GoodsReceiptItemBatches");
});
modelBuilder.Entity("Distribution.Models.GoodsReceiptItemSerial", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<Guid>("FK_GoodsReceiptItemId")
.HasColumnType("char(36)");
b.Property<Guid>("FK_ItemSerialNumberId")
.HasColumnType("char(36)");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.HasKey("Id");
b.HasIndex("FK_GoodsReceiptItemId");
b.HasIndex("FK_ItemSerialNumberId");
b.ToTable("GoodsReceiptItemSerials");
});
modelBuilder.Entity("Distribution.Models.Invoice", b =>
{
b.Property<Guid>("Id")
@@ -600,6 +667,9 @@ namespace Distribution.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<bool>("AllowCustomWarrantyPeriod")
.HasColumnType("tinyint(1)");
b.Property<decimal?>("CostPrice")
.HasColumnType("decimal(65,30)");
@@ -624,6 +694,9 @@ namespace Distribution.Migrations
b.Property<Guid?>("FK_SubCategoryId")
.HasColumnType("char(36)");
b.Property<bool>("HasWarranty")
.HasColumnType("tinyint(1)");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
@@ -634,7 +707,6 @@ namespace Distribution.Migrations
.IsRequired()
.HasColumnType("longtext");
b.Property<decimal?>("ReorderLevel")
.HasColumnType("decimal(65,30)");
@@ -648,6 +720,18 @@ namespace Distribution.Migrations
b.Property<int>("SyncSource")
.HasColumnType("int");
b.Property<bool>("TracksBatches")
.HasColumnType("tinyint(1)");
b.Property<bool>("TracksExpiryDate")
.HasColumnType("tinyint(1)");
b.Property<bool>("TracksSerialNumbers")
.HasColumnType("tinyint(1)");
b.Property<int?>("WarrantyPeriodDays")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("FK_BaseUomId");
@@ -664,61 +748,157 @@ namespace Distribution.Migrations
new
{
Id = new Guid("23000000-0000-0000-0000-000000000001"),
AllowCustomWarrantyPeriod = false,
CreatedAt = new DateTime(2026, 8, 20, 0, 0, 0, 0, DateTimeKind.Unspecified),
Description = "Coca-Cola 500ml bottle",
FK_BaseUomId = new Guid("22000000-0000-0000-0000-000000000001"),
FK_BrandId = new Guid("21000000-0000-0000-0000-000000000001"),
FK_CategoryId = new Guid("20000000-0000-0000-0000-000000000001"),
HasWarranty = false,
IsActive = true,
Name = "Coca-Cola 500ml",
SalePrice = 60m,
Sku = "BEV-COKE-500",
SyncSource = 0
SyncSource = 0,
TracksBatches = false,
TracksExpiryDate = false,
TracksSerialNumbers = false
},
new
{
Id = new Guid("23000000-0000-0000-0000-000000000002"),
AllowCustomWarrantyPeriod = false,
CreatedAt = new DateTime(2026, 8, 20, 0, 0, 0, 0, DateTimeKind.Unspecified),
Description = "Coca-Cola 1.5L bottle",
FK_BaseUomId = new Guid("22000000-0000-0000-0000-000000000001"),
FK_BrandId = new Guid("21000000-0000-0000-0000-000000000001"),
FK_CategoryId = new Guid("20000000-0000-0000-0000-000000000001"),
HasWarranty = false,
IsActive = true,
Name = "Coca-Cola 1.5L",
SalePrice = 120m,
Sku = "BEV-COKE-1500",
SyncSource = 0
SyncSource = 0,
TracksBatches = false,
TracksExpiryDate = false,
TracksSerialNumbers = false
},
new
{
Id = new Guid("23000000-0000-0000-0000-000000000003"),
AllowCustomWarrantyPeriod = false,
CreatedAt = new DateTime(2026, 8, 20, 0, 0, 0, 0, DateTimeKind.Unspecified),
Description = "Lays Classic Salted 52g pack",
FK_BaseUomId = new Guid("22000000-0000-0000-0000-000000000001"),
FK_BrandId = new Guid("21000000-0000-0000-0000-000000000002"),
FK_CategoryId = new Guid("20000000-0000-0000-0000-000000000002"),
HasWarranty = false,
IsActive = true,
Name = "Lays Classic 52g",
SalePrice = 50m,
Sku = "SNK-LAYS-52",
SyncSource = 0
SyncSource = 0,
TracksBatches = false,
TracksExpiryDate = false,
TracksSerialNumbers = false
},
new
{
Id = new Guid("23000000-0000-0000-0000-000000000004"),
AllowCustomWarrantyPeriod = false,
CreatedAt = new DateTime(2026, 8, 20, 0, 0, 0, 0, DateTimeKind.Unspecified),
Description = "Lays Family Pack 150g",
FK_BaseUomId = new Guid("22000000-0000-0000-0000-000000000001"),
FK_BrandId = new Guid("21000000-0000-0000-0000-000000000002"),
FK_CategoryId = new Guid("20000000-0000-0000-0000-000000000002"),
HasWarranty = false,
IsActive = true,
Name = "Lays Family Pack 150g",
SalePrice = 150m,
Sku = "SNK-LAYS-FAM",
SyncSource = 0
SyncSource = 0,
TracksBatches = false,
TracksExpiryDate = false,
TracksSerialNumbers = false
});
});
modelBuilder.Entity("Distribution.Models.ItemBatch", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("BatchNumber")
.HasColumnType("varchar(255)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime?>("ExpiryDate")
.HasColumnType("datetime(6)");
b.Property<Guid>("FK_ItemId")
.HasColumnType("char(36)");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<DateTime?>("ManufactureDate")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.HasIndex("FK_ItemId", "BatchNumber");
b.ToTable("ItemBatches");
});
modelBuilder.Entity("Distribution.Models.ItemSerialNumber", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CurrentLocationId")
.HasColumnType("char(36)");
b.Property<int?>("CurrentLocationType")
.HasColumnType("int");
b.Property<Guid>("FK_ItemId")
.HasColumnType("char(36)");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("ReceivedAt")
.HasColumnType("datetime(6)");
b.Property<string>("SerialNumber")
.IsRequired()
.HasColumnType("varchar(255)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<DateTime?>("WarrantyExpiresAt")
.HasColumnType("datetime(6)");
b.Property<int?>("WarrantyPeriodDaysOverride")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("FK_ItemId", "SerialNumber")
.IsUnique();
b.ToTable("ItemSerialNumbers");
});
modelBuilder.Entity("Distribution.Models.LoadingSheet", b =>
{
b.Property<Guid>("Id")
@@ -2239,9 +2419,15 @@ namespace Distribution.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<Guid?>("FK_ItemBatchId")
.HasColumnType("char(36)");
b.Property<Guid>("FK_ItemId")
.HasColumnType("char(36)");
b.Property<Guid?>("FK_ItemSerialNumberId")
.HasColumnType("char(36)");
b.Property<Guid>("LocationId")
.HasColumnType("char(36)");
@@ -2256,7 +2442,11 @@ namespace Distribution.Migrations
b.HasKey("Id");
b.HasIndex("FK_ItemId", "LocationId")
b.HasIndex("FK_ItemBatchId");
b.HasIndex("FK_ItemSerialNumberId");
b.HasIndex("FK_ItemId", "LocationId", "FK_ItemBatchId", "FK_ItemSerialNumberId")
.IsUnique();
b.ToTable("StockBalances");
@@ -2303,9 +2493,15 @@ namespace Distribution.Migrations
b.Property<Guid>("CreatedBy")
.HasColumnType("char(36)");
b.Property<Guid?>("FK_ItemBatchId")
.HasColumnType("char(36)");
b.Property<Guid>("FK_ItemId")
.HasColumnType("char(36)");
b.Property<Guid?>("FK_ItemSerialNumberId")
.HasColumnType("char(36)");
b.Property<Guid?>("FromLocationId")
.HasColumnType("char(36)");
@@ -2332,8 +2528,12 @@ namespace Distribution.Migrations
b.HasKey("Id");
b.HasIndex("FK_ItemBatchId");
b.HasIndex("FK_ItemId");
b.HasIndex("FK_ItemSerialNumberId");
b.ToTable("StockMovements");
b.HasData(
@@ -2763,6 +2963,42 @@ namespace Distribution.Migrations
Key = "InvoiceCreationMode",
UpdatedAt = new DateTime(2026, 9, 17, 0, 0, 0, 0, DateTimeKind.Unspecified),
Value = "ModeB"
},
new
{
Key = "Feature.SerialNumberTracking",
UpdatedAt = new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Value = "false"
},
new
{
Key = "Feature.BatchTracking",
UpdatedAt = new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Value = "false"
},
new
{
Key = "Feature.ExpiryDateTracking",
UpdatedAt = new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Value = "false"
},
new
{
Key = "Feature.WarrantyTracking",
UpdatedAt = new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Value = "false"
},
new
{
Key = "Feature.CustomWarrantyOverride",
UpdatedAt = new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Value = "false"
},
new
{
Key = "Feature.DefaultWarrantyPeriodDays",
UpdatedAt = new DateTime(2026, 10, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Value = "0"
});
});
@@ -3256,8 +3492,12 @@ namespace Distribution.Migrations
b.HasOne("Distribution.Models.PurchaseOrder", "PurchaseOrder")
.WithMany()
.HasForeignKey("FK_PurchaseOrderId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("Distribution.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("FK_SupplierId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("Distribution.Models.Warehouse", "Warehouse")
.WithMany()
@@ -3267,6 +3507,8 @@ namespace Distribution.Migrations
b.Navigation("PurchaseOrder");
b.Navigation("Supplier");
b.Navigation("Warehouse");
});
@@ -3278,17 +3520,61 @@ namespace Distribution.Migrations
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("Distribution.Models.Item", "Item")
.WithMany()
.HasForeignKey("FK_ItemId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("Distribution.Models.PurchaseOrderItem", "PurchaseOrderItem")
.WithMany()
.HasForeignKey("FK_PurchaseOrderItemId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("GoodsReceipt");
b.Navigation("Item");
b.Navigation("PurchaseOrderItem");
});
modelBuilder.Entity("Distribution.Models.GoodsReceiptItemBatch", b =>
{
b.HasOne("Distribution.Models.GoodsReceiptItem", "GoodsReceiptItem")
.WithMany("Batches")
.HasForeignKey("FK_GoodsReceiptItemId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("Distribution.Models.ItemBatch", "ItemBatch")
.WithMany()
.HasForeignKey("FK_ItemBatchId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("GoodsReceiptItem");
b.Navigation("ItemBatch");
});
modelBuilder.Entity("Distribution.Models.GoodsReceiptItemSerial", b =>
{
b.HasOne("Distribution.Models.GoodsReceiptItem", "GoodsReceiptItem")
.WithMany("Serials")
.HasForeignKey("FK_GoodsReceiptItemId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("Distribution.Models.ItemSerialNumber", "ItemSerialNumber")
.WithMany()
.HasForeignKey("FK_ItemSerialNumberId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("GoodsReceiptItem");
b.Navigation("ItemSerialNumber");
});
modelBuilder.Entity("Distribution.Models.Invoice", b =>
{
b.HasOne("Distribution.Models.ShopPO", "ShopPO")
@@ -3331,6 +3617,28 @@ namespace Distribution.Migrations
b.Navigation("SubCategory");
});
modelBuilder.Entity("Distribution.Models.ItemBatch", b =>
{
b.HasOne("Distribution.Models.Item", "Item")
.WithMany()
.HasForeignKey("FK_ItemId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Item");
});
modelBuilder.Entity("Distribution.Models.ItemSerialNumber", b =>
{
b.HasOne("Distribution.Models.Item", "Item")
.WithMany()
.HasForeignKey("FK_ItemId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Item");
});
modelBuilder.Entity("Distribution.Models.LoadingSheet", b =>
{
b.HasOne("Distribution.Models.DeliveryRun", "Ride")
@@ -3746,24 +4054,52 @@ namespace Distribution.Migrations
modelBuilder.Entity("Distribution.Models.StockBalance", b =>
{
b.HasOne("Distribution.Models.ItemBatch", "ItemBatch")
.WithMany()
.HasForeignKey("FK_ItemBatchId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("Distribution.Models.Item", "Item")
.WithMany()
.HasForeignKey("FK_ItemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Distribution.Models.ItemSerialNumber", "ItemSerialNumber")
.WithMany()
.HasForeignKey("FK_ItemSerialNumberId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Item");
b.Navigation("ItemBatch");
b.Navigation("ItemSerialNumber");
});
modelBuilder.Entity("Distribution.Models.StockMovement", b =>
{
b.HasOne("Distribution.Models.ItemBatch", "ItemBatch")
.WithMany()
.HasForeignKey("FK_ItemBatchId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("Distribution.Models.Item", "Item")
.WithMany()
.HasForeignKey("FK_ItemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Distribution.Models.ItemSerialNumber", "ItemSerialNumber")
.WithMany()
.HasForeignKey("FK_ItemSerialNumberId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Item");
b.Navigation("ItemBatch");
b.Navigation("ItemSerialNumber");
});
modelBuilder.Entity("Distribution.Models.Store", b =>
@@ -3964,6 +4300,13 @@ namespace Distribution.Migrations
b.Navigation("Items");
});
modelBuilder.Entity("Distribution.Models.GoodsReceiptItem", b =>
{
b.Navigation("Batches");
b.Navigation("Serials");
});
modelBuilder.Entity("Distribution.Models.Invoice", b =>
{
b.Navigation("Payments");
+2
View File
@@ -44,4 +44,6 @@ namespace Distribution.Models
/// ModeB: Invoice created as a separate explicit step.
/// </summary>
public enum InvoiceCreationMode { ModeA, ModeB }
public enum SerialStatus { InStock, Sold, Returned, Damaged }
}
+7
View File
@@ -32,6 +32,13 @@ namespace Distribution.Models
/// <summary>Cost/purchase price, used to value free-goods scheme redemptions for getSchemeROI.</summary>
public decimal? CostPrice { get; set; }
public bool TracksSerialNumbers { get; set; } = false;
public bool TracksBatches { get; set; } = false;
public bool TracksExpiryDate { get; set; } = false;
public bool HasWarranty { get; set; } = false;
public int? WarrantyPeriodDays { get; set; }
public bool AllowCustomWarrantyPeriod { get; set; } = false;
public SyncSource SyncSource { get; set; } = SyncSource.Manual;
public int? ExternalErpItemId { get; set; }
public DateTime? LastSyncedAt { get; set; }
+20
View File
@@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Distribution.Models
{
/// <summary>
/// Backs both batch/lot tracking and expiry-only tracking for an item. BatchNumber is null
/// when the item tracks an expiry date but not a batch number (TracksExpiryDate without
/// TracksBatches).
/// </summary>
public class ItemBatch : Template
{
public Guid FK_ItemId { get; set; }
[ForeignKey("FK_ItemId")]
public Item Item { get; set; }
public string? BatchNumber { get; set; }
public DateTime? ManufactureDate { get; set; }
public DateTime? ExpiryDate { get; set; }
}
}
+26
View File
@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Distribution.Models
{
/// <summary>One row per physical serial-tracked unit. Quantity is always 1.</summary>
public class ItemSerialNumber : Template
{
public Guid FK_ItemId { get; set; }
[ForeignKey("FK_ItemId")]
public Item Item { get; set; }
public string SerialNumber { get; set; }
public SerialStatus Status { get; set; } = SerialStatus.InStock;
public Guid? CurrentLocationId { get; set; }
public LocationType? CurrentLocationType { get; set; }
public DateTime ReceivedAt { get; set; }
/// <summary>Snapshotted at receipt when Item.AllowCustomWarrantyPeriod is true; otherwise null and the system default applies when the warranty starts.</summary>
public int? WarrantyPeriodDaysOverride { get; set; }
/// <summary>Set when the serial is sold/delivered: sale date + (override ?? system default). Null while in stock or if Item.HasWarranty is false.</summary>
public DateTime? WarrantyExpiresAt { get; set; }
}
}
+10
View File
@@ -13,6 +13,16 @@ namespace Distribution.Models
public Guid LocationId { get; set; }
public LocationType LocationType { get; set; }
/// <summary>Null for items that don't track batches/expiry — no behavior change for existing items.</summary>
public Guid? FK_ItemBatchId { get; set; }
[ForeignKey("FK_ItemBatchId")]
public ItemBatch? ItemBatch { get; set; }
/// <summary>Null for items that don't track serial numbers.</summary>
public Guid? FK_ItemSerialNumberId { get; set; }
[ForeignKey("FK_ItemSerialNumberId")]
public ItemSerialNumber? ItemSerialNumber { get; set; }
public decimal Quantity { get; set; }
public DateTime UpdatedAt { get; set; } = DateTime.Now;
}
+10
View File
@@ -16,6 +16,16 @@ namespace Distribution.Models
public Guid? ToLocationId { get; set; }
public LocationType? ToLocationType { get; set; }
/// <summary>Null for items that don't track batches/expiry — no behavior change for existing items.</summary>
public Guid? FK_ItemBatchId { get; set; }
[ForeignKey("FK_ItemBatchId")]
public ItemBatch? ItemBatch { get; set; }
/// <summary>Null for items that don't track serial numbers. Quantity is always 1 when set.</summary>
public Guid? FK_ItemSerialNumberId { get; set; }
[ForeignKey("FK_ItemSerialNumberId")]
public ItemSerialNumber? ItemSerialNumber { get; set; }
public decimal Quantity { get; set; }
public MovementType Type { get; set; }