public static string Update(string productName, int productId, int warehouseId, int quantityIn, int quantityOut, bool isArchive = true)
        {
            string error = "";
            IProductInboundRepository  productInboundRepository  = DependencyResolver.Current.GetService <IProductInboundRepository>();
            IProductOutboundRepository productOutboundRepository = DependencyResolver.Current.GetService <IProductOutboundRepository>();
            IInventoryRepository       inventoryRepository       = DependencyResolver.Current.GetService <IInventoryRepository>();

            var inbound = productInboundRepository.GetAllvwProductInboundDetail()
                          .Where(x => x.IsArchive && x.ProductId == productId && x.WarehouseDestinationId == warehouseId);

            var outbound = productOutboundRepository.GetAllvwProductOutboundDetail()
                           .Where(x => x.IsArchive && x.ProductId == productId && x.WarehouseSourceId == warehouseId);

            var inventory = (inbound.Count() == 0 ? 0 : inbound.Sum(x => x.Quantity)) - (outbound.Count() == 0 ? 0 : outbound.Sum(x => x.Quantity)) + quantityIn - quantityOut;

            var inventoryCurrent = inventoryRepository.GetInventoryByWarehouseIdAndProductId(warehouseId, productId);

            //Sau khi thay đổi dữ liệu phải đảm bảo tồn kho >= 0
            if (inventory >= 0)
            {
                if (isArchive)
                {
                    if (inventoryCurrent != null)
                    {
                        if (inventoryCurrent.Quantity != inventory)
                        {
                            inventoryCurrent.Quantity = inventory;
                            inventoryRepository.UpdateInventory(inventoryCurrent);
                        }
                    }
                    else
                    {
                        inventoryCurrent                = new Inventory();
                        inventoryCurrent.IsDeleted      = false;
                        inventoryCurrent.CreatedUserId  = WebSecurity.CurrentUserId;
                        inventoryCurrent.ModifiedUserId = WebSecurity.CurrentUserId;
                        inventoryCurrent.CreatedDate    = DateTime.Now;
                        inventoryCurrent.ModifiedDate   = DateTime.Now;
                        inventoryCurrent.WarehouseId    = warehouseId;
                        inventoryCurrent.ProductId      = productId;
                        inventoryCurrent.Quantity       = inventory;
                        inventoryRepository.InsertInventory(inventoryCurrent);
                    }
                }
            }
            else
            {
                error += string.Format("<br/>Dữ liệu tồn kho của sản phẩm \"{0}\" là {1}: không hợp lệ!", productName, inventory);
            }

            return(error);
        }
Esempio n. 2
0
 public InventoryController(
     IInventoryRepository _Inventory
     , IProductOrServiceRepository _Product
     , IWarehouseRepository _Warehouse
     , IProductInboundRepository _ProductInbound
     , IProductOutboundRepository _ProductOutbound
     , IPhysicalInventoryRepository _PhysicalInventory
     , IUserRepository _user
     )
 {
     WarehouseRepository         = _Warehouse;
     ProductRepository           = _Product;
     InventoryRepository         = _Inventory;
     ProductInboundRepository    = _ProductInbound;
     ProductOutboundRepository   = _ProductOutbound;
     userRepository              = _user;
     PhysicalInventoryRepository = _PhysicalInventory;
 }
 public InventoryController(
     IInventoryRepository _Inventory
     , IProductRepository _Product
     , IWarehouseRepository _Warehouse
     , IProductInboundRepository _ProductInbound
     , IProductOutboundRepository _ProductOutbound
     , IPhysicalInventoryRepository _PhysicalInventory
     , IUserRepository _user
     , ICategoryRepository categorys
     )
 {
     WarehouseRepository         = _Warehouse;
     ProductRepository           = _Product;
     InventoryRepository         = _Inventory;
     ProductInboundRepository    = _ProductInbound;
     ProductOutboundRepository   = _ProductOutbound;
     userRepository              = _user;
     PhysicalInventoryRepository = _PhysicalInventory;
     _categoryRepository         = categorys;
 }
Esempio n. 4
0
 public RequestInboundController(
     IRequestInboundRepository _RequestInbound
     , IUserRepository _user
     , IWarehouseRepository warehouse
     , IProductOrServiceRepository product
     , ICategoryRepository category
     , IProductOutboundRepository productOutbound
     , IProductInboundRepository productInbound
     , ITemplatePrintRepository templatePrint
     , IBranchRepository branch
     )
 {
     RequestInboundRepository  = _RequestInbound;
     userRepository            = _user;
     WarehouseRepository       = warehouse;
     ProductRepository         = product;
     categoryRepository        = category;
     productInboundRepository  = productInbound;
     productOutboundRepository = productOutbound;
     templatePrintRepository   = templatePrint;
     branchRepository          = branch;
 }
Esempio n. 5
0
 public PhysicalInventoryController(
     IInventoryRepository _Inventory
     , IProductRepository _Product
     , IWarehouseRepository _Warehouse
     , IProductInboundRepository _ProductInbound
     , IProductOutboundRepository _ProductOutbound
     , IPhysicalInventoryRepository _PhysicalInventory
     , IUserRepository _user
     , IWarehouseLocationItemRepository _WarehouseLocationItem
     , ICategoryRepository _CategoryRepository
     , ITemplatePrintRepository _templatePrint
     )
 {
     WarehouseRepository             = _Warehouse;
     ProductRepository               = _Product;
     InventoryRepository             = _Inventory;
     productInboundRepository        = _ProductInbound;
     productOutboundRepository       = _ProductOutbound;
     userRepository                  = _user;
     PhysicalInventoryRepository     = _PhysicalInventory;
     warehouseLocationItemRepository = _WarehouseLocationItem;
     categoryRepository              = _CategoryRepository;
     templatePrintRepository         = _templatePrint;
 }