Implement Inventory Management Service with CRUD operations for warehouses and inventory items, stock operations, and bulk processing capabilities.
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 1m48s

This commit is contained in:
masoodafar-web
2026-01-02 00:45:37 +03:30
parent f0117eb1d5
commit 1cf501711f
50 changed files with 10699 additions and 101 deletions
@@ -0,0 +1,105 @@
using CMSMicroservice.Domain.Common;
using CMSMicroservice.Domain.Enums;
using CMSMicroservice.Domain.Entities.DiscountShop;
namespace CMSMicroservice.Domain.Entities;
/// <summary>
/// موجودی کالا در انبار
/// </summary>
public class InventoryItem : BaseAuditableEntity
{
// ========== شناسه محصول (یکی از دو فیلد زیر پر است) ==========
/// <summary>
/// شناسه محصول فروشگاه معمولی
/// </summary>
public long? ProductId { get; set; }
/// <summary>
/// محصول فروشگاه معمولی
/// </summary>
public Product? Product { get; set; }
/// <summary>
/// شناسه محصول فروشگاه تخفیفی
/// </summary>
public long? DiscountProductId { get; set; }
/// <summary>
/// محصول فروشگاه تخفیفی
/// </summary>
public DiscountProduct? DiscountProduct { get; set; }
// ========== نوع محصول ==========
/// <summary>
/// نوع محصول (معمولی یا تخفیفی)
/// </summary>
public ProductType ProductType { get; set; }
// ========== موجودی ==========
/// <summary>
/// موجودی فعلی (منبع اصلی)
/// </summary>
public int Quantity { get; set; }
/// <summary>
/// مقدار رزرو شده برای سفارشات pending
/// </summary>
public int ReservedQuantity { get; set; }
/// <summary>
/// موجودی قابل فروش (محاسباتی)
/// </summary>
public int AvailableQuantity => Quantity - ReservedQuantity;
// ========== تنظیمات انبار ==========
/// <summary>
/// آستانه هشدار کم‌موجودی
/// </summary>
public int LowStockThreshold { get; set; } = 10;
/// <summary>
/// نقطه سفارش مجدد
/// </summary>
public int ReorderPoint { get; set; } = 5;
/// <summary>
/// حداکثر موجودی مجاز
/// </summary>
public int MaxStockLevel { get; set; } = 1000;
// ========== آمار ==========
/// <summary>
/// تاریخ آخرین ورود کالا
/// </summary>
public DateTime? LastRestockedAt { get; set; }
/// <summary>
/// تاریخ آخرین فروش
/// </summary>
public DateTime? LastSoldAt { get; set; }
// ========== انبار (برای آینده) ==========
/// <summary>
/// شناسه انبار (پیش‌فرض: انبار اصلی)
/// </summary>
public long WarehouseId { get; set; } = 1;
/// <summary>
/// انبار
/// </summary>
public Warehouse? Warehouse { get; set; }
// ========== Navigation Properties ==========
/// <summary>
/// حرکات انبار مرتبط با این آیتم
/// </summary>
public ICollection<StockMovement> StockMovements { get; set; } = new List<StockMovement>();
}
@@ -38,6 +38,11 @@ public class ManualPayment : BaseAuditableEntity
/// </summary>
public string? ReferenceNumber { get; set; }
/// <summary>
/// مسیر تصویر فیش واریزی (اختیاری)
/// </summary>
public string? ImagePath { get; set; }
/// <summary>
/// وضعیت تایید
/// </summary>
@@ -0,0 +1,77 @@
using CMSMicroservice.Domain.Common;
using CMSMicroservice.Domain.Enums;
namespace CMSMicroservice.Domain.Entities;
/// <summary>
/// حرکات انبار (تاریخچه تغییرات موجودی)
/// </summary>
public class StockMovement : BaseAuditableEntity
{
// ========== ارتباط با InventoryItem ==========
/// <summary>
/// شناسه آیتم انبار
/// </summary>
public long InventoryItemId { get; set; }
/// <summary>
/// آیتم انبار
/// </summary>
public InventoryItem InventoryItem { get; set; } = null!;
// ========== نوع حرکت ==========
/// <summary>
/// نوع حرکت انبار
/// </summary>
public StockMovementType MovementType { get; set; }
// ========== مقادیر ==========
/// <summary>
/// مقدار تغییر (مثبت برای ورود، منفی برای خروج)
/// </summary>
public int Quantity { get; set; }
/// <summary>
/// موجودی قبل از این حرکت
/// </summary>
public int QuantityBefore { get; set; }
/// <summary>
/// موجودی بعد از این حرکت
/// </summary>
public int QuantityAfter { get; set; }
// ========== مراجع ==========
/// <summary>
/// شناسه سفارش (برای فروش/برگشت در فروشگاه معمولی)
/// </summary>
public long? OrderId { get; set; }
/// <summary>
/// شناسه سفارش تخفیفی (برای فروش/برگشت در فروشگاه تخفیفی)
/// </summary>
public long? DiscountOrderId { get; set; }
/// <summary>
/// شماره مرجع (مثل شماره فاکتور ورود کالا)
/// </summary>
public string? ReferenceNumber { get; set; }
// ========== توضیحات ==========
/// <summary>
/// یادداشت و توضیحات اضافی
/// </summary>
public string? Note { get; set; }
// ========== کاربر ==========
/// <summary>
/// شناسه کاربری که این عملیات را انجام داده
/// </summary>
public long? PerformedByUserId { get; set; }
}
@@ -0,0 +1,45 @@
using CMSMicroservice.Domain.Common;
namespace CMSMicroservice.Domain.Entities;
/// <summary>
/// انبار (برای آینده - چند انبار)
/// </summary>
public class Warehouse : BaseAuditableEntity
{
// ========== اطلاعات اصلی ==========
/// <summary>
/// نام انبار
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// کد انبار
/// </summary>
public string Code { get; set; } = null!;
/// <summary>
/// آدرس انبار
/// </summary>
public string? Address { get; set; }
// ========== تنظیمات ==========
/// <summary>
/// انبار پیش‌فرض سیستم
/// </summary>
public bool IsDefault { get; set; }
/// <summary>
/// وضعیت فعال/غیرفعال
/// </summary>
public bool IsActive { get; set; } = true;
// ========== Navigation Properties ==========
/// <summary>
/// آیتم‌های موجودی در این انبار
/// </summary>
public ICollection<InventoryItem> InventoryItems { get; set; } = new List<InventoryItem>();
}
@@ -0,0 +1,17 @@
namespace CMSMicroservice.Domain.Enums;
/// <summary>
/// نوع محصول در سیستم
/// </summary>
public enum ProductType
{
/// <summary>
/// محصول فروشگاه معمولی
/// </summary>
RegularProduct = 1,
/// <summary>
/// محصول فروشگاه تخفیفی
/// </summary>
DiscountProduct = 2
}
@@ -0,0 +1,75 @@
namespace CMSMicroservice.Domain.Enums;
/// <summary>
/// نوع حرکت انبار
/// </summary>
public enum StockMovementType
{
// ========== ورودی ==========
/// <summary>
/// موجودی اولیه محصول
/// </summary>
InitialStock = 1,
/// <summary>
/// ورود کالا به انبار (خرید از تامین‌کننده)
/// </summary>
Restock = 2,
/// <summary>
/// برگشت کالا از مشتری
/// </summary>
Return = 3,
/// <summary>
/// انتقال کالا از انبار دیگر
/// </summary>
TransferIn = 4,
// ========== خروجی ==========
/// <summary>
/// فروش کالا به مشتری
/// </summary>
Sale = 10,
/// <summary>
/// ضایعات (کالای خراب شده)
/// </summary>
Damaged = 11,
/// <summary>
/// مفقودی انبار
/// </summary>
Lost = 12,
/// <summary>
/// انتقال کالا به انبار دیگر
/// </summary>
TransferOut = 13,
// ========== تعدیل ==========
/// <summary>
/// تعدیل افزایشی موجودی (انبارگردانی مثبت)
/// </summary>
AdjustmentPlus = 20,
/// <summary>
/// تعدیل کاهشی موجودی (انبارگردانی منفی)
/// </summary>
AdjustmentMinus = 21,
// ========== رزرو ==========
/// <summary>
/// رزرو موجودی برای سفارش pending
/// </summary>
Reserved = 30,
/// <summary>
/// آزادسازی رزرو (لغو سفارش)
/// </summary>
Released = 31
}