Пример #1
0
        public async Task <int> Update(int id, StockOpnameWarehouseViewModel viewModel)
        {
            int result = 0;

            result = await this.UpdateStockOpname(id, viewModel);

            return(result);
        }
Пример #2
0
        public async Task <int> Create(StockOpnameWarehouseViewModel viewModel)
        {
            int result = 0;

            if (viewModel.Type == DyeingPrintingArea.STOCK_OPNAME)
            {
                result = await CreateStockOpname(viewModel);
            }

            return(result);
        }
Пример #3
0
        public async Task <StockOpnameWarehouseViewModel> ReadById(int id)
        {
            var model = await _stockOpnameRepository.ReadByIdAsync(id);

            if (model == null)
            {
                return(null);
            }

            StockOpnameWarehouseViewModel vm = await MapToViewModel(model);

            return(vm);
        }
Пример #4
0
        private async Task <int> CreateStockOpname(StockOpnameWarehouseViewModel viewModel)
        {
            int result = 0;
            var model  = _stockOpnameRepository.GetDbSet().AsNoTracking().FirstOrDefault(s => s.Area == DyeingPrintingArea.GUDANGJADI &&
                                                                                         s.Date.Date == viewModel.Date.Date &&
                                                                                         s.Type == DyeingPrintingArea.STOCK_OPNAME);

            //viewModel.WarehousesProductionOrders = viewModel.WarehousesProductionOrders.Where(s => s.IsSave).ToList();
            viewModel.WarehousesProductionOrders = viewModel.WarehousesProductionOrders.ToList();
            if (model == null)
            {
                int totalCurrentYearData = _stockOpnameRepository.ReadAllIgnoreQueryFilter()
                                           .Count(s => s.Area == DyeingPrintingArea.GUDANGJADI &&
                                                  s.CreatedUtc.Year == viewModel.Date.Year && s.Type == DyeingPrintingArea.STOCK_OPNAME);

                string bonNo = GenerateBonNo(totalCurrentYearData + 1, viewModel.Date, viewModel.Area);

                model = new DyeingPrintingStockOpnameModel(viewModel.Area, bonNo, viewModel.Date, viewModel.Type,
                                                           viewModel.WarehousesProductionOrders.Select(s =>
                                                                                                       new DyeingPrintingStockOpnameProductionOrderModel(
                                                                                                           s.Balance,
                                                                                                           s.BuyerId,
                                                                                                           s.Buyer,
                                                                                                           s.Color,
                                                                                                           s.Construction,
                                                                                                           s.DocumentNo,
                                                                                                           s.Grade,
                                                                                                           s.MaterialConstruction.Id,
                                                                                                           s.MaterialConstruction.Name,
                                                                                                           s.Material.Id,
                                                                                                           s.Material.Name,
                                                                                                           s.MaterialWidth,
                                                                                                           s.Motif,
                                                                                                           s.PackingInstruction,
                                                                                                           s.PackagingQty,
                                                                                                           s.Quantity,
                                                                                                           s.PackagingType,
                                                                                                           s.PackagingUnit,
                                                                                                           s.ProductionOrder.Id,
                                                                                                           s.ProductionOrder.No,
                                                                                                           s.ProductionOrder.Type,
                                                                                                           s.ProductionOrder.OrderQuantity,
                                                                                                           s.ProcessType.Id,
                                                                                                           s.ProcessType.Name,
                                                                                                           s.YarnMaterial.Id,
                                                                                                           s.YarnMaterial.Name,
                                                                                                           s.Remark,
                                                                                                           s.Status,
                                                                                                           s.Unit,
                                                                                                           s.UomUnit
                                                                                                           )).ToList());


                result = await _stockOpnameRepository.InsertAsync(model);

                //viewModel.WarehousesProductionOrders = viewModel.WarehousesProductionOrders
            }
            else
            {
                foreach (var item in viewModel.WarehousesProductionOrders)
                {
                    var modelItem = new DyeingPrintingStockOpnameProductionOrderModel(
                        item.Balance,
                        item.BuyerId,
                        item.Buyer,
                        item.Color,
                        item.Construction,
                        item.DocumentNo,
                        item.Grade,
                        item.MaterialConstruction.Id,
                        item.MaterialConstruction.Name,
                        item.Material.Id,
                        item.Material.Name,
                        item.MaterialWidth,
                        item.Motif,
                        item.PackingInstruction,
                        item.PackagingQty,
                        item.Quantity,
                        item.PackagingType,
                        item.PackagingUnit,
                        item.ProductionOrder.Id,
                        item.ProductionOrder.No,
                        item.ProductionOrder.Type,
                        item.ProductionOrder.OrderQuantity,
                        item.ProcessType.Id,
                        item.ProcessType.Name,
                        item.YarnMaterial.Id,
                        item.YarnMaterial.Name,
                        item.Remark,
                        item.Status,
                        item.Unit,
                        item.UomUnit
                        );

                    modelItem.DyeingPrintingStockOpnameId = model.Id;

                    result += await _stockOpnameProductionOrderRepository.InsertAsync(modelItem);
                }
            }

            return(result);
        }
Пример #5
0
        private async Task <StockOpnameWarehouseViewModel> MapToViewModel(DyeingPrintingStockOpnameModel model)
        {
            var vm = new StockOpnameWarehouseViewModel();

            vm = new StockOpnameWarehouseViewModel()
            {
                Active = model.Active,
                Id     = model.Id,
                Area   = model.Area,
                BonNo  = model.BonNo,
                Type   = DyeingPrintingArea.STOCK_OPNAME,
                Bon    = new IndexViewModel
                {
                    Area  = model.Area,
                    BonNo = model.BonNo,
                    Date  = model.Date,
                    Id    = model.Id
                },
                CreatedAgent               = model.CreatedAgent,
                CreatedBy                  = model.CreatedBy,
                CreatedUtc                 = model.CreatedUtc,
                Date                       = model.Date,
                DeletedAgent               = model.DeletedAgent,
                DeletedBy                  = model.DeletedBy,
                DeletedUtc                 = model.DeletedUtc,
                IsDeleted                  = model.IsDeleted,
                LastModifiedAgent          = model.LastModifiedAgent,
                LastModifiedBy             = model.LastModifiedBy,
                LastModifiedUtc            = model.LastModifiedUtc,
                WarehousesProductionOrders = model.DyeingPrintingStockOpnameProductionOrders.Select(s => new StockOpnameWarehouseProductionOrderViewModel()
                {
                    Active          = s.Active,
                    LastModifiedUtc = s.LastModifiedUtc,
                    Balance         = s.Balance,
                    Buyer           = s.Buyer,
                    BuyerId         = s.BuyerId,
                    Color           = s.Color,
                    Construction    = s.Construction,
                    CreatedAgent    = s.CreatedAgent,
                    CreatedBy       = s.CreatedBy,
                    CreatedUtc      = s.CreatedUtc,
                    DeletedAgent    = s.DeletedAgent,
                    DeletedBy       = s.DeletedBy,
                    DeletedUtc      = s.DeletedUtc,
                    Grade           = s.Grade,
                    GradeProduct    = new GradeProduct()
                    {
                        Type = s.Grade
                    },
                    PackingInstruction = s.PackingInstruction,
                    Remark             = s.Remark,
                    Status             = s.Status,
                    Id                = s.Id,
                    IsDeleted         = s.IsDeleted,
                    LastModifiedAgent = s.LastModifiedAgent,
                    LastModifiedBy    = s.LastModifiedBy,
                    Motif             = s.Motif,

                    ProductionOrder = new ProductionOrder()
                    {
                        Id            = s.ProductionOrderId,
                        No            = s.ProductionOrderNo,
                        OrderQuantity = s.ProductionOrderOrderQuantity,
                        Type          = s.ProductionOrderType
                    },
                    Unit          = s.Unit,
                    MaterialWidth = s.MaterialWidth,
                    Material      = new Material()
                    {
                        Id   = s.MaterialId,
                        Name = s.MaterialName
                    },
                    MaterialConstruction = new MaterialConstruction()
                    {
                        Name = s.MaterialConstructionName,
                        Id   = s.MaterialConstructionId
                    },
                    YarnMaterial = new CommonViewModelObjectProperties.YarnMaterial()
                    {
                        Id   = s.YarnMaterialId,
                        Name = s.YarnMaterialName
                    },
                    ProcessType = new CommonViewModelObjectProperties.ProcessType()
                    {
                        Id   = s.ProcessTypeId,
                        Name = s.ProcessTypeName
                    },
                    UomUnit = s.UomUnit,
                    Uom     = new UnitOfMeasurement()
                    {
                        Unit = s.PackagingUnit
                    },
                    PackagingQty      = s.PackagingQty,
                    PackagingType     = s.PackagingType,
                    PackagingUnit     = s.PackagingUnit,
                    ProductionOrderNo = s.ProductionOrderNo,
                    QtyOrder          = s.ProductionOrderOrderQuantity,
                    DocumentNo        = s.DocumentNo,
                    Quantity          = s.PackagingLength,
                }).ToList()
            };
            //foreach (var item in vm.WarehousesProductionOrders)
            //{
            //    var inputData = await _inputProductionOrderRepository.ReadByIdAsync(item.DyeingPrintingAreaInputProductionOrderId);
            //    if (inputData != null)
            //    {
            //        item.BalanceRemains = inputData.BalanceRemains + item.Balance;
            //    }
            //}


            return(vm);
        }
Пример #6
0
        private async Task <int> UpdateStockOpname(int id, StockOpnameWarehouseViewModel viewModel)
        {
            string type;
            int    result  = 0;
            var    dbModel = await _stockOpnameRepository.ReadByIdAsync(id);

            var model = new DyeingPrintingStockOpnameModel(
                viewModel.Area,
                viewModel.BonNo,
                viewModel.Date,
                viewModel.Type,
                viewModel.WarehousesProductionOrders.Select(s => new DyeingPrintingStockOpnameProductionOrderModel(
                                                                s.Balance,
                                                                s.BuyerId,
                                                                s.Buyer,
                                                                s.Color,
                                                                s.Construction,
                                                                s.DocumentNo,
                                                                s.Grade,
                                                                s.MaterialConstruction.Id,
                                                                s.MaterialConstruction.Name,
                                                                s.Material.Id,
                                                                s.Material.Name,
                                                                s.MaterialWidth,
                                                                s.Motif,
                                                                s.PackingInstruction,
                                                                s.PackagingQty,
                                                                s.Quantity,
                                                                s.PackagingType,
                                                                s.PackagingUnit,
                                                                s.ProductionOrder.Id,
                                                                s.ProductionOrder.No,
                                                                s.ProductionOrder.Type,
                                                                s.ProductionOrder.OrderQuantity,
                                                                s.ProcessType.Id,
                                                                s.ProcessType.Name,
                                                                s.YarnMaterial.Id,
                                                                s.YarnMaterial.Name,
                                                                s.Remark,
                                                                s.Status,
                                                                s.Unit,
                                                                s.UomUnit
                                                                )

            {
                Id = s.Id
            }).ToList());


            Dictionary <int, double>  dictBalance    = new Dictionary <int, double>();
            Dictionary <int, decimal> dictQtyPacking = new Dictionary <int, decimal>();

            foreach (var item in dbModel.DyeingPrintingStockOpnameProductionOrders)
            {
                var lclModel = model.DyeingPrintingStockOpnameProductionOrders.FirstOrDefault(s => s.Id == item.Id);
                if (lclModel != null)
                {
                    var diffBalance    = lclModel.Balance - item.Balance;
                    var diffQtyPacking = lclModel.PackagingQty - item.PackagingQty;
                    dictBalance.Add(lclModel.Id, diffBalance);
                    dictQtyPacking.Add(lclModel.Id, diffQtyPacking);
                }
            }

            var deletedData = dbModel.DyeingPrintingStockOpnameProductionOrders.Where(s => !model.DyeingPrintingStockOpnameProductionOrders.Any(d => d.Id == s.Id)).ToList();

            // result = await _outputRepository.UpdateAdjustmentData(id, model, dbModel);
            if (dbModel != null)
            {
                result = await _stockOpnameRepository.UpdateAsync(id, model);
            }


            return(result);
        }