public Task <int> UpdateAsync(int id, DyeingPrintingAreaInputProductionOrderModel model)
        {
            var modelToUpdate = _dbSet.FirstOrDefault(s => s.Id == id);

            modelToUpdate.SetArea(model.Area, _identityProvider.Username, UserAgent);
            modelToUpdate.SetBalance(model.Balance, _identityProvider.Username, UserAgent);
            modelToUpdate.SetBuyer(model.BuyerId, model.Buyer, _identityProvider.Username, UserAgent);
            modelToUpdate.SetCartNo(model.CartNo, _identityProvider.Username, UserAgent);
            modelToUpdate.SetColor(model.Color, _identityProvider.Username, UserAgent);
            modelToUpdate.SetConstruction(model.Construction, _identityProvider.Username, UserAgent);
            modelToUpdate.SetGrade(model.Grade, _identityProvider.Username, UserAgent);
            modelToUpdate.SetHasOutputDocument(model.HasOutputDocument, _identityProvider.Username, UserAgent);
            modelToUpdate.SetMotif(model.Motif, _identityProvider.Username, UserAgent);
            modelToUpdate.SetProductionOrder(model.ProductionOrderId, model.ProductionOrderNo, model.ProductionOrderType, model.ProductionOrderOrderQuantity, _identityProvider.Username, UserAgent);
            modelToUpdate.SetRemark(model.Remark, _identityProvider.Username, UserAgent);
            modelToUpdate.SetStatus(model.Status, _identityProvider.Username, UserAgent);
            modelToUpdate.SetUnit(model.Unit, _identityProvider.Username, UserAgent);
            modelToUpdate.SetUomUnit(model.UomUnit, _identityProvider.Username, UserAgent);
            modelToUpdate.SetIsChecked(model.IsChecked, _identityProvider.Username, UserAgent);
            modelToUpdate.SetPackingInstruction(model.PackingInstruction, _identityProvider.Username, UserAgent);
            modelToUpdate.SetDeliveryOrderSales(model.DeliveryOrderSalesId, model.DeliveryOrderSalesNo, _identityProvider.Username, UserAgent);
            modelToUpdate.SetBalanceRemains(model.BalanceRemains, _identityProvider.Username, UserAgent);
            modelToUpdate.SetMaterial(model.MaterialId, model.MaterialName, _identityProvider.Username, UserAgent);
            modelToUpdate.SetMaterialConstruction(model.MaterialConstructionId, model.MaterialConstructionName, _identityProvider.Username, UserAgent);
            modelToUpdate.SetMaterialWidth(model.MaterialWidth, _identityProvider.Username, UserAgent);
            modelToUpdate.SetMachine(model.Machine, _identityProvider.Username, UserAgent);
            return(_dbContext.SaveChangesAsync());
        }
        public Task <int> InsertAsync(DyeingPrintingAreaInputProductionOrderModel model)
        {
            model.FlagForCreate(_identityProvider.Username, UserAgent);
            _dbSet.Add(model);

            return(_dbContext.SaveChangesAsync());
        }
        public async Task <int> Create(InputAvalTransformationViewModel viewModel)
        {
            int result = 0;

            var model = _repository.GetDbSet().AsNoTracking()
                        .FirstOrDefault(s => s.Area == DyeingPrintingArea.GUDANGAVAL && s.Date.Date == viewModel.Date.Date & s.Shift == viewModel.Shift && s.AvalType == viewModel.AvalType && s.IsTransformedAval);

            viewModel.AvalTransformationProductionOrders = viewModel.AvalTransformationProductionOrders.Where(s => s.IsSave).ToList();
            if (model == null)
            {
                int    totalCurrentYearData = _repository.ReadAllIgnoreQueryFilter().Count(s => s.IsTransformedAval && s.Area == DyeingPrintingArea.GUDANGAVAL && s.CreatedUtc.Year == viewModel.Date.Year);
                string bonNo = GenerateBonNo(totalCurrentYearData + 1, viewModel.Date);
                model = new DyeingPrintingAreaInputModel(viewModel.Date, viewModel.Area, viewModel.Shift, bonNo, viewModel.Group, viewModel.AvalType, true,
                                                         viewModel.TotalQuantity, viewModel.TotalWeight,
                                                         viewModel.AvalTransformationProductionOrders.Select(d => new DyeingPrintingAreaInputProductionOrderModel(viewModel.Area, d.BonNo, d.ProductionOrder.Id, d.ProductionOrder.No,
                                                                                                                                                                  d.ProductionOrder.Type, d.ProductionOrder.OrderQuantity, d.CartNo, d.Construction, d.Unit, d.Buyer, d.BuyerId, d.Color, d.Motif, d.AvalType, d.UomUnit, d.InputQuantity,
                                                                                                                                                                  false, d.Id, d.Material.Id, d.Material.Name, d.MaterialConstruction.Id, d.MaterialConstruction.Name, d.MaterialWidth, d.Machine, d.ProcessType.Id, d.ProcessType.Name,
                                                                                                                                                                  d.YarnMaterial.Id, d.YarnMaterial.Name, d.ProductSKUId, d.FabricSKUId, d.ProductSKUCode, d.HasPrintingProductSKU, d.ProductPackingId, d.FabricPackingId, d.ProductPackingCode, d.HasPrintingProductPacking, d.InputQuantity, d.FinishWidth)).ToList());

                result = await _repository.InsertAsync(model);

                var movementModel = new DyeingPrintingAreaMovementModel(viewModel.Date, viewModel.Area, DyeingPrintingArea.TRANSFORM, model.Id, model.BonNo, model.TotalAvalQuantity, model.TotalAvalWeight, model.AvalType);

                result += await _movementRepository.InsertAsync(movementModel);

                foreach (var item in model.DyeingPrintingAreaInputProductionOrders)
                {
                    var itemVM = viewModel.AvalTransformationProductionOrders.FirstOrDefault(s => s.Id == item.DyeingPrintingAreaOutputProductionOrderId);
                    result += await _inputProductionOrderRepository.UpdateFromOutputAsync(item.DyeingPrintingAreaOutputProductionOrderId, true);
                }
            }
            else
            {
                foreach (var item in viewModel.AvalTransformationProductionOrders)
                {
                    var modelItem = new DyeingPrintingAreaInputProductionOrderModel(viewModel.Area, item.BonNo, item.ProductionOrder.Id, item.ProductionOrder.No, item.ProductionOrder.Type,
                                                                                    item.ProductionOrder.OrderQuantity, item.CartNo, item.Construction, item.Unit, item.Buyer, item.BuyerId, item.Color, item.Motif, item.AvalType, item.UomUnit,
                                                                                    item.InputQuantity, false, item.Id, item.Material.Id, item.Material.Name, item.MaterialConstruction.Id, item.MaterialConstruction.Name,
                                                                                    item.MaterialWidth, item.Machine, item.ProcessType.Id, item.ProcessType.Name, item.YarnMaterial.Id, item.YarnMaterial.Name, item.ProductSKUId, item.FabricSKUId, item.ProductSKUCode, item.HasPrintingProductSKU, item.ProductPackingId, item.FabricPackingId, item.ProductPackingCode, item.HasPrintingProductPacking, item.InputQuantity, item.FinishWidth);

                    modelItem.DyeingPrintingAreaInputId = model.Id;

                    result += await _inputProductionOrderRepository.InsertAsync(modelItem);

                    result += await _inputProductionOrderRepository.UpdateFromOutputAsync(item.Id, true);
                }
                var movementModel = new DyeingPrintingAreaMovementModel(viewModel.Date, viewModel.Area, DyeingPrintingArea.TRANSFORM, model.Id, model.BonNo, viewModel.TotalQuantity, viewModel.TotalWeight, viewModel.AvalType);

                result += await _movementRepository.InsertAsync(movementModel);

                result += await _repository.UpdateHeaderAvalTransform(model, viewModel.TotalQuantity, viewModel.TotalWeight);
            }



            return(result);
        }
Пример #4
0
        public async Task <int> Create(InputInspectionMaterialViewModel viewModel)
        {
            int result = 0;
            var model  = _repository.GetDbSet().AsNoTracking()
                         .FirstOrDefault(s => s.Area == DyeingPrintingArea.INSPECTIONMATERIAL && s.Date.Date == viewModel.Date.Date & s.Shift == viewModel.Shift);

            if (model == null)
            {
                int    totalCurrentYearData = _repository.ReadAllIgnoreQueryFilter().Count(s => s.Area == DyeingPrintingArea.INSPECTIONMATERIAL && s.CreatedUtc.Year == viewModel.Date.Year);
                string bonNo = GenerateBonNo(totalCurrentYearData + 1, viewModel.Date);
                model = new DyeingPrintingAreaInputModel(viewModel.Date, viewModel.Area, viewModel.Shift, bonNo, viewModel.Group, viewModel.InspectionMaterialProductionOrders.Select(s =>
                                                                                                                                                                                      new DyeingPrintingAreaInputProductionOrderModel(viewModel.Area, s.ProductionOrder.Id, s.ProductionOrder.No, s.ProductionOrder.Type, s.ProductionOrder.OrderQuantity,
                                                                                                                                                                                                                                      s.PackingInstruction, s.CartNo, s.Buyer, s.Construction, s.Unit, s.Color, s.Motif, s.UomUnit, s.InputQuantity, s.InputQuantity, false, s.BuyerId, 0, s.Material.Id, s.Material.Name,
                                                                                                                                                                                                                                      s.MaterialConstruction.Id, s.MaterialConstruction.Name, s.MaterialWidth, s.ProcessType.Id, s.ProcessType.Name, s.YarnMaterial.Id, s.YarnMaterial.Name, s.InputQuantity, s.FinishWidth, viewModel.Date, s.MaterialOrigin)).ToList());


                result = await _repository.InsertAsync(model);

                foreach (var item in model.DyeingPrintingAreaInputProductionOrders)
                {
                    var movementModel = new DyeingPrintingAreaMovementModel(model.Date, item.MaterialOrigin, model.Area, DyeingPrintingArea.IN, model.Id, model.BonNo, item.ProductionOrderId, item.ProductionOrderNo,
                                                                            item.CartNo, item.Buyer, item.Construction, item.Unit, item.Color, item.Motif, item.UomUnit, item.InputQuantity, item.Id, item.ProductionOrderType);

                    result += await _movementRepository.InsertAsync(movementModel);
                }
            }
            else
            {
                foreach (var item in viewModel.InspectionMaterialProductionOrders)
                {
                    var modelItem = new DyeingPrintingAreaInputProductionOrderModel(viewModel.Area, item.ProductionOrder.Id, item.ProductionOrder.No,
                                                                                    item.ProductionOrder.Type, item.ProductionOrder.OrderQuantity, item.PackingInstruction, item.CartNo, item.Buyer, item.Construction, item.Unit, item.Color,
                                                                                    item.Motif, item.UomUnit, item.InputQuantity, item.InputQuantity, false, item.BuyerId, 0, item.Material.Id, item.Material.Name,
                                                                                    item.MaterialConstruction.Id, item.MaterialConstruction.Name, item.MaterialWidth, item.ProcessType.Id, item.ProcessType.Name, item.YarnMaterial.Id, item.YarnMaterial.Name,
                                                                                    item.InputQuantity, item.FinishWidth, viewModel.Date, item.MaterialOrigin);

                    modelItem.DyeingPrintingAreaInputId = model.Id;

                    result += await _productionOrderRepository.InsertAsync(modelItem);

                    var movementModel = new DyeingPrintingAreaMovementModel(viewModel.Date, item.MaterialOrigin, viewModel.Area, DyeingPrintingArea.IN, model.Id, model.BonNo, item.ProductionOrder.Id, item.ProductionOrder.No,
                                                                            item.CartNo, item.Buyer, item.Construction, item.Unit, item.Color, item.Motif, item.UomUnit, item.InputQuantity, modelItem.Id, item.ProductionOrder.Type);

                    result += await _movementRepository.InsertAsync(movementModel);
                }
            }

            return(result);
        }
Пример #5
0
        public void Should_Empty_GenerateExcel()
        {
            var repoMock         = new Mock <IDyeingPrintingAreaOutputRepository>();
            var movementRepoMock = new Mock <IDyeingPrintingAreaMovementRepository>();
            var summaryRepoMock  = new Mock <IDyeingPrintingAreaSummaryRepository>();
            var sppRepoMock      = new Mock <IDyeingPrintingAreaInputProductionOrderRepository>();
            var inputRepoMock    = new Mock <IDyeingPrintingAreaInputRepository>();
            var outputSpp        = new Mock <IDyeingPrintingAreaOutputProductionOrderRepository>();
            var outRepoMock      = new Mock <IDyeingPrintingAreaOutputRepository>();
            var serviceMock      = new Mock <StockWarehouseService>();

            var x = Model;

            x.Id = 1;
            foreach (var y in x.DyeingPrintingAreaInputProductionOrders)
            {
                y.Id = 1;
                y.DyeingPrintingAreaInputId = 1;
            }

            inputRepoMock.Setup(s => s.ReadAll())
            .Returns(new List <DyeingPrintingAreaInputModel>()
            {
                x
            }.AsQueryable());
            var a = OutputModel;

            a.Id = 1;
            foreach (var t in a.DyeingPrintingAreaOutputProductionOrders)
            {
                t.Id = 1;
                t.DyeingPrintingAreaOutputId = 1;
            }
            //var test = OutputModel.DyeingPrintingAreaOutputProductionOrders.FirstOrDefault();
            //test.DyeingPrintingAreaOutputId = 1;
            //OutputModel.DyeingPrintingAreaOutputProductionOrders = test;
            repoMock.Setup(s => s.ReadAll())
            .Returns(new List <DyeingPrintingAreaOutputModel>()
            {
                a
            }.AsQueryable());

            outRepoMock.Setup(s => s.ReadAll())
            .Returns(new List <DyeingPrintingAreaOutputModel>()
            {
                a
            }.AsQueryable());

            var testmodel = new DyeingPrintingAreaInputProductionOrderModel("PACKING", 1, "sd", "sd", "a", "a", "a", "a", "a", "a", "a", "a", 10, true, 10, "A", int.Parse("1"), 1, 1, "a", 1, "a", 1, "a", "1", 1, "a", 1, "a", 1, 1, "a", false, 1, 1, "a", false, 1, "a", DateTimeOffset.Now, "a");

            testmodel.Id = 1;
            sppRepoMock.Setup(s => s.ReadAll())
            .Returns(
                //new List<DyeingPrintingAreaInputProductionOrderModel> {
                x.DyeingPrintingAreaInputProductionOrders.ToList().AsQueryable()
                //}.AsQueryable()
                );

            var data = new List <DyeingPrintingAreaMovementModel>()
            {
                ModelAwalOut, ModelAwalIn, ModelIn, ModelOut, ModelAdjIn, ModelAdjOut, ModelAwalAdjIn, ModelAwalAdjOut
            };

            movementRepoMock.Setup(s => s.ReadAll())
            .Returns(data.AsQueryable());


            outputSpp.Setup(s => s.ReadAll())
            .Returns(a.DyeingPrintingAreaOutputProductionOrders.AsQueryable());
            //serviceMock.Setup(s => s.GetReportData(new DateTimeOffset(DateTime.Now), "PACKING"))
            //    .Returns(new List<ReportStockWarehouseViewModel>(new List<ReportStockWarehouseViewModel>() { ViewModel1 }));
            //var service = GetService(GetServiceProvider(inputRepoMock.Object, movementRepoMock.Object, summaryRepoMock.Object, sppRepoMock.Object).Object);
            var service = GetService(GetServiceProvider(inputRepoMock.Object, movementRepoMock.Object, summaryRepoMock.Object, sppRepoMock.Object, outRepoMock.Object, outputSpp.Object).Object);
            //var service = new StockWarehouseService(serviceMock.Object);

            var result = service.GenerateExcel(ModelIn.Date, "TRANSIT", 7, ModelIn.Unit, ModelIn.PackingType, ModelIn.Construction, ModelIn.Buyer, ModelIn.ProductionOrderId, ModelIn.InventoryType);


            Assert.NotNull(result);
        }
        private FabricQualityControlViewModel MapToViewModel(FabricQualityControlModel model, DyeingPrintingAreaInputProductionOrderModel dpModel)
        {
            FabricQualityControlViewModel vm = new FabricQualityControlViewModel()
            {
                InspectionMaterialId = model.DyeingPrintingAreaInputId,
                Active                              = model.Active,
                Buyer                               = dpModel?.Buyer,
                CartNo                              = dpModel?.CartNo,
                Code                                = model.Code,
                Color                               = dpModel?.Color,
                Construction                        = dpModel?.Construction,
                CreatedAgent                        = model.CreatedAgent,
                CreatedBy                           = model.CreatedBy,
                CreatedUtc                          = model.CreatedUtc,
                DateIm                              = model.DateIm,
                DeletedAgent                        = model.DeletedAgent,
                DeletedBy                           = model.DeletedBy,
                DeletedUtc                          = model.DeletedUtc,
                InspectionMaterialBonNo             = model.DyeingPrintingAreaInputBonNo,
                InspectionMaterialProductionOrderId = model.DyeingPrintingAreaInputProductionOrderId,
                Group                               = model.Group,
                Id                  = model.Id,
                IsDeleted           = model.IsDeleted,
                IsUsed              = model.IsUsed,
                LastModifiedAgent   = model.LastModifiedAgent,
                LastModifiedBy      = model.LastModifiedBy,
                LastModifiedUtc     = model.LastModifiedUtc,
                MachineNoIm         = model.MachineNoIm,
                OperatorIm          = model.OperatorIm,
                OrderQuantity       = dpModel?.Balance,
                PackingInstruction  = dpModel?.PackingInstruction,
                PointLimit          = model.PointLimit,
                PointSystem         = model.PointSystem,
                ProductionOrderNo   = model.ProductionOrderNo,
                ProductionOrderType = dpModel?.ProductionOrderType,
                ShiftIm             = dpModel?.DyeingPrintingAreaInput.Shift,
                UId                 = model.UId,
                Uom                 = dpModel?.UomUnit,
                ProductionOrderId   = dpModel?.ProductionOrderId,
                FabricGradeTests    = model.FabricGradeTests.Select(s => new FabricGradeTestViewModel()
                {
                    Active               = s.Active,
                    AvalALength          = s.AvalALength,
                    AvalBLength          = s.AvalBLength,
                    AvalConnectionLength = s.AvalConnectionLength,
                    CreatedAgent         = s.CreatedAgent,
                    CreatedBy            = s.CreatedBy,
                    CreatedUtc           = s.CreatedUtc,
                    DeletedAgent         = s.DeletedAgent,
                    DeletedBy            = s.DeletedBy,
                    DeletedUtc           = s.DeletedUtc,
                    FabricGradeTest      = s.FabricGradeTest,
                    FinalArea            = s.FinalArea,
                    FinalGradeTest       = s.FinalGradeTest,
                    FinalLength          = s.FinalLength,
                    FinalScore           = s.FinalScore,
                    Grade             = s.Grade,
                    Id                = s.Id,
                    InitLength        = s.InitLength,
                    IsDeleted         = s.IsDeleted,
                    LastModifiedAgent = s.LastModifiedAgent,
                    LastModifiedBy    = s.LastModifiedBy,
                    LastModifiedUtc   = s.LastModifiedUtc,
                    PcsNo             = s.PcsNo,
                    PointLimit        = s.PointLimit,
                    PointSystem       = s.PointSystem,
                    SampleLength      = s.SampleLength,
                    Score             = s.Score,
                    Type              = s.Type,
                    Width             = s.Width,
                    Criteria          = s.Criteria.Select(c => new CriteriaViewModel()
                    {
                        Code  = c.Code,
                        Group = c.Group,
                        Id    = c.Id,
                        Index = c.Index,
                        Name  = c.Name,
                        Score = new Score()
                        {
                            A = c.ScoreA,
                            B = c.ScoreB,
                            C = c.ScoreC,
                            D = c.ScoreD
                        }
                    }).ToList()
                }).ToList()
            };

            return(vm);
        }
        public async Task <int> Reject(InputShippingViewModel viewModel)
        {
            int result = 0;
            var groupedProductionOrders = viewModel.ShippingProductionOrders.GroupBy(s => s.Area);

            if (viewModel.ShippingType != DyeingPrintingArea.ZONAGUDANG)
            {
                return(result);
            }

            foreach (var item in groupedProductionOrders)
            {
                var model = _repository.GetDbSet().AsNoTracking()
                            .FirstOrDefault(s => s.Area == item.Key && s.Date.Date == viewModel.Date.Date & s.Shift == viewModel.Shift);

                if (model == null)
                {
                    int    totalCurrentYearData = _repository.ReadAllIgnoreQueryFilter().Count(s => s.Area == item.Key && s.CreatedUtc.Year == viewModel.Date.Year);
                    string bonNo = GenerateBonNo(totalCurrentYearData + 1, viewModel.Date, item.Key);
                    model = new DyeingPrintingAreaInputModel(viewModel.Date, item.Key, viewModel.Shift, bonNo, viewModel.Group,
                                                             item.Select(s => new DyeingPrintingAreaInputProductionOrderModel(item.Key, s.ProductionOrder.Id,
                                                                                                                              s.ProductionOrder.No, s.ProductionOrder.Type, s.PackingInstruction, s.CartNo, s.Buyer, s.Construction, s.Unit, s.Color, s.Motif, s.UomUnit,
                                                                                                                              s.InputQuantity, false, s.Packing, s.PackingType, s.InputQtyPacking, s.Grade, s.ProductionOrder.OrderQuantity, s.BuyerId, s.Id, s.Remark, s.InputQuantity,
                                                                                                                              s.Material.Id, s.Material.Name, s.MaterialConstruction.Id, s.MaterialConstruction.Name, s.MaterialWidth, s.ProcessType.Id, s.ProcessType.Name, s.YarnMaterial.Id, s.YarnMaterial.Name, s.ProductSKUId, s.FabricSKUId, s.ProductSKUCode,
                                                                                                                              s.HasPrintingProductSKU, s.ProductPackingId, s.FabricPackingId, s.ProductPackingCode, s.HasPrintingProductPacking, s.PackingLength, s.InputQuantity, s.InputQtyPacking, s.FinishWidth, s.DateIn)).ToList());


                    result = await _repository.InsertAsync(model);

                    result += await _outputSPPRepository.UpdateFromInputAsync(item.Select(s => s.Id).ToList(), true, DyeingPrintingArea.TOLAK);

                    foreach (var detail in item)
                    {
                        var itemModel = model.DyeingPrintingAreaInputProductionOrders.FirstOrDefault(s => s.DyeingPrintingAreaOutputProductionOrderId == detail.Id);
                        result += await _productionOrderRepository.UpdateFromNextAreaInputAsync(detail.DyeingPrintingAreaInputProductionOrderId, detail.InputQuantity, detail.InputQtyPacking);

                        var movementModel = new DyeingPrintingAreaMovementModel(viewModel.Date, item.Key, DyeingPrintingArea.IN, model.Id, model.BonNo, detail.ProductionOrder.Id, detail.ProductionOrder.No,
                                                                                detail.CartNo, detail.Buyer, detail.Construction, detail.Unit, detail.Color, detail.Motif, detail.UomUnit, detail.InputQuantity, itemModel.Id, detail.ProductionOrder.Type,
                                                                                detail.Grade, null, detail.PackingType, detail.InputQtyPacking, detail.Packing, detail.PackingLength);

                        result += await _movementRepository.InsertAsync(movementModel);
                    }
                }
                else
                {
                    foreach (var detail in item)
                    {
                        var modelItem = new DyeingPrintingAreaInputProductionOrderModel(item.Key, detail.ProductionOrder.Id, detail.ProductionOrder.No, detail.ProductionOrder.Type,
                                                                                        detail.PackingInstruction, detail.CartNo, detail.Buyer, detail.Construction, detail.Unit, detail.Color, detail.Motif, detail.UomUnit,
                                                                                        detail.InputQuantity, false, detail.Packing, detail.PackingType, detail.InputQtyPacking, detail.Grade, detail.ProductionOrder.OrderQuantity, detail.BuyerId,
                                                                                        detail.Id, detail.Remark, detail.InputQuantity,
                                                                                        detail.Material.Id, detail.Material.Name, detail.MaterialConstruction.Id, detail.MaterialConstruction.Name, detail.MaterialWidth, detail.ProcessType.Id, detail.ProcessType.Name, detail.YarnMaterial.Id, detail.YarnMaterial.Name, detail.ProductSKUId, detail.FabricSKUId, detail.ProductSKUCode,
                                                                                        detail.HasPrintingProductSKU, detail.ProductPackingId, detail.FabricPackingId, detail.ProductPackingCode, detail.HasPrintingProductPacking, detail.PackingLength,
                                                                                        detail.InputQuantity, detail.InputQtyPacking, detail.FinishWidth, detail.DateIn);

                        modelItem.DyeingPrintingAreaInputId = model.Id;

                        result += await _productionOrderRepository.InsertAsync(modelItem);

                        result += await _productionOrderRepository.UpdateFromNextAreaInputAsync(detail.DyeingPrintingAreaInputProductionOrderId, detail.InputQuantity, detail.InputQtyPacking);

                        var movementModel = new DyeingPrintingAreaMovementModel(viewModel.Date, item.Key, DyeingPrintingArea.IN, model.Id, model.BonNo, detail.ProductionOrder.Id, detail.ProductionOrder.No,
                                                                                detail.CartNo, detail.Buyer, detail.Construction, detail.Unit, detail.Color, detail.Motif, detail.UomUnit, detail.InputQuantity, modelItem.Id, detail.ProductionOrder.Type,
                                                                                detail.Grade, null, detail.PackingType, detail.InputQtyPacking, detail.Packing, detail.PackingLength);

                        result += await _movementRepository.InsertAsync(movementModel);
                    }
                    result += await _outputSPPRepository.UpdateFromInputAsync(item.Select(s => s.Id).ToList(), true, DyeingPrintingArea.TOLAK);
                }
            }

            return(result);
        }
        public async Task <int> Create(InputShippingViewModel viewModel)
        {
            int result = 0;

            var model = _repository.GetDbSet().AsNoTracking()
                        .FirstOrDefault(s => s.Area == DyeingPrintingArea.SHIPPING && s.Date.Date == viewModel.Date.Date & s.Shift == viewModel.Shift && s.ShippingType == viewModel.ShippingType);

            if (model == null)
            {
                int    totalCurrentYearData = _repository.ReadAllIgnoreQueryFilter().Count(s => s.Area == DyeingPrintingArea.SHIPPING && s.CreatedUtc.Year == viewModel.Date.Year);
                string bonNo = GenerateBonNo(totalCurrentYearData + 1, viewModel.Date, viewModel.Area);
                model = new DyeingPrintingAreaInputModel(viewModel.Date, viewModel.Area, viewModel.Shift, bonNo, viewModel.Group, viewModel.ShippingType, viewModel.ShippingProductionOrders.Select(s =>
                                                                                                                                                                                                    new DyeingPrintingAreaInputProductionOrderModel(viewModel.Area, s.DeliveryOrder.Id, s.DeliveryOrder.No, s.ProductionOrder.Id, s.ProductionOrder.No, s.ProductionOrder.Type,
                                                                                                                                                                                                                                                    s.ProductionOrder.OrderQuantity, s.Buyer, s.Construction, s.PackingType, s.Color, s.Motif, s.Grade, s.InputQtyPacking, s.Packing, s.InputQuantity, s.UomUnit, false, s.InputQuantity, s.Unit,
                                                                                                                                                                                                                                                    s.BuyerId, s.Id, s.Material.Id, s.Material.Name, s.MaterialConstruction.Id, s.MaterialConstruction.Name, s.MaterialWidth, s.CartNo, s.Remark, s.ProcessType.Id, s.ProcessType.Name,
                                                                                                                                                                                                                                                    s.YarnMaterial.Id, s.YarnMaterial.Name, s.ProductSKUId, s.FabricSKUId, s.ProductSKUCode, s.HasPrintingProductSKU, s.ProductPackingId, s.FabricPackingId,
                                                                                                                                                                                                                                                    s.ProductPackingCode, s.HasPrintingProductPacking, s.PackingLength, s.InputQuantity, s.InputQtyPacking, s.DeliveryOrderRetur.Id, s.DeliveryOrderRetur.No, s.FinishWidth, viewModel.Date)).ToList());


                result = await _repository.InsertAsync(model);

                //result += await _outputRepository.UpdateFromInputAsync(viewModel.OutputId, true);
                if (viewModel.ShippingType == DyeingPrintingArea.ZONAGUDANG)
                {
                    result += await _outputSPPRepository.UpdateFromInputAsync(viewModel.ShippingProductionOrders.Select(s => s.Id).ToList(), true, DyeingPrintingArea.TERIMA);
                }

                foreach (var item in model.DyeingPrintingAreaInputProductionOrders)
                {
                    var itemVM = viewModel.ShippingProductionOrders.FirstOrDefault(s => s.Id == item.DyeingPrintingAreaOutputProductionOrderId);
                    if (viewModel.ShippingType == DyeingPrintingArea.ZONAGUDANG)
                    {
                        result += await _productionOrderRepository.UpdateFromNextAreaInputAsync(itemVM.DyeingPrintingAreaInputProductionOrderId, item.InputQuantity, item.InputPackagingQty);
                    }

                    var movementModel = new DyeingPrintingAreaMovementModel(viewModel.Date, viewModel.Area, DyeingPrintingArea.IN, model.Id, model.BonNo, item.ProductionOrderId, item.ProductionOrderNo,
                                                                            item.CartNo, item.Buyer, item.Construction, item.Unit, item.Color, item.Motif, item.UomUnit, item.InputQuantity, item.Id, item.ProductionOrderType, item.Grade,
                                                                            null, item.PackagingType, item.InputPackagingQty, item.PackagingUnit, item.PackagingLength);

                    result += await _movementRepository.InsertAsync(movementModel);
                }
            }
            else
            {
                foreach (var item in viewModel.ShippingProductionOrders)
                {
                    var modelItem = new DyeingPrintingAreaInputProductionOrderModel(viewModel.Area, item.DeliveryOrder.Id, item.DeliveryOrder.No, item.ProductionOrder.Id,
                                                                                    item.ProductionOrder.No, item.ProductionOrder.Type, item.ProductionOrder.OrderQuantity, item.Buyer, item.Construction, item.PackingType, item.Color, item.Motif,
                                                                                    item.Grade, item.InputQtyPacking, item.Packing, item.InputQuantity, item.UomUnit, false, item.InputQuantity, item.Unit, item.BuyerId, item.Id,
                                                                                    item.Material.Id, item.Material.Name, item.MaterialConstruction.Id, item.MaterialConstruction.Name, item.MaterialWidth, item.CartNo, item.Remark,
                                                                                    item.ProcessType.Id, item.ProcessType.Name, item.YarnMaterial.Id, item.YarnMaterial.Name, item.ProductSKUId, item.FabricSKUId, item.ProductSKUCode,
                                                                                    item.HasPrintingProductSKU, item.ProductPackingId, item.FabricPackingId, item.ProductPackingCode, item.HasPrintingProductPacking, item.PackingLength, item.InputQuantity,
                                                                                    item.InputQtyPacking, item.DeliveryOrderRetur.Id, item.DeliveryOrderRetur.No, item.FinishWidth, viewModel.Date);

                    modelItem.DyeingPrintingAreaInputId = model.Id;

                    result += await _productionOrderRepository.InsertAsync(modelItem);

                    if (viewModel.ShippingType == DyeingPrintingArea.ZONAGUDANG)
                    {
                        result += await _productionOrderRepository.UpdateFromNextAreaInputAsync(item.DyeingPrintingAreaInputProductionOrderId, item.InputQuantity, item.InputQtyPacking);
                    }

                    var movementModel = new DyeingPrintingAreaMovementModel(viewModel.Date, viewModel.Area, DyeingPrintingArea.IN, model.Id, model.BonNo, item.ProductionOrder.Id, item.ProductionOrder.No,
                                                                            item.CartNo, item.Buyer, item.Construction, item.Unit, item.Color, item.Motif, item.UomUnit, item.InputQuantity, modelItem.Id, item.ProductionOrder.Type,
                                                                            item.Grade, null, item.PackingType, item.InputQtyPacking, item.Packing, item.PackingLength);

                    result += await _movementRepository.InsertAsync(movementModel);
                }
                if (viewModel.ShippingType == DyeingPrintingArea.ZONAGUDANG)
                {
                    result += await _outputSPPRepository.UpdateFromInputAsync(viewModel.ShippingProductionOrders.Select(s => s.Id).ToList(), true, DyeingPrintingArea.TERIMA);
                }
            }



            return(result);
        }