public FabricSKUIdCodeDto AutoCreateSKU(FabricSKUAutoCreateFormDto form)
        {
            var code          = "";
            var processType   = _dbContext.IPProcessType.FirstOrDefault(entity => entity.ProcessType == form.ProcessType);
            var processTypeId = 0;

            if (processType != null)
            {
                code         += processType.Code;
                processTypeId = processType.Id;
            }
            else
            {
                code         += "00";
                processTypeId = 0;
            }

            var yearCode = CodeConstructionHelper.GetYearCode(DateTime.Now.Year);

            code += yearCode;

            var sppNo = form.ProductionOrderNo.Substring(form.ProductionOrderNo.Length - 4);

            code += sppNo;

            var grade   = _dbContext.IPGrades.FirstOrDefault(entity => entity.Type == form.Grade);
            var gradeId = 0;

            if (grade != null)
            {
                code   += grade.Code;
                gradeId = grade.Id;
            }
            else
            {
                code   += "0";
                gradeId = 0;
            }

            var uom      = _dbContext.IPUnitOfMeasurements.FirstOrDefault(entity => entity.Unit == form.UOM);
            var category = _dbContext.IPCategories.FirstOrDefault(entity => entity.Name == "FABRIC");

            var model            = new ProductSKUModel();
            var productFabricSKU = new FabricProductSKUModel();

            if (uom != null && category != null)
            {
                model = new ProductSKUModel(code, code, uom.Id, category.Id, "");
                _unitOfWork.ProductSKUs.Insert(model);
                _unitOfWork.Commit();

                productFabricSKU = new FabricProductSKUModel(code, model.Id, 0, 0, 0, 0, 0, processTypeId, 0, gradeId, uom.Id);
                _unitOfWork.FabricSKUProducts.Insert(productFabricSKU);
                _unitOfWork.Commit();
            }
            return(new FabricSKUIdCodeDto()
            {
                FabricSKUId = productFabricSKU.Id, ProductSKUCode = code, ProductSKUId = model.Id
            });
        }
示例#2
0
        public JsonResult GetSKUInfo(long pId)
        {
            ProductInfo            product          = ServiceHelper.Create <IProductService>().GetProduct(pId);
            List <ProductSKUModel> productSKUModels = new List <ProductSKUModel>();

            foreach (SKUInfo sKUInfo in
                     from s in product.SKUInfo
                     where s.Stock > 0
                     select s)
            {
                ProductSKUModel productSKUModel = new ProductSKUModel()
                {
                    Price = sKUInfo.SalePrice,
                    SKUId = sKUInfo.Id,
                    Stock = (int)sKUInfo.Stock
                };
                productSKUModels.Add(productSKUModel);
            }
            foreach (ProductSKUModel productSKUModel1 in productSKUModels)
            {
                string[] strArrays = productSKUModel1.SKUId.Split(new char[] { '\u005F' });
                productSKUModel1.SKUId = string.Format("{0};{1};{2}", strArrays[1], strArrays[2], strArrays[3]);
            }
            return(Json(new { skuArray = productSKUModels }, JsonRequestBehavior.AllowGet));
        }
示例#3
0
 public ProductPackingDto(ProductPackingModel productPacking, ProductSKUModel product, UnitOfMeasurementModel uom, UnitOfMeasurementModel skuUOM, CategoryModel skuCategory)
 {
     Id             = productPacking.Id;
     Code           = productPacking.Code;
     Name           = productPacking.Name;
     LasModifiedUtc = productPacking.LastModifiedUtc;
     ProductSKU     = new ProductSKUDto(product, skuUOM, skuCategory);
     UOM            = new UnitOfMeasurementDto(uom);
     PackingSize    = productPacking.PackingSize;
 }
示例#4
0
 public ProductSKUDto(ProductSKUModel product, UnitOfMeasurementModel uom, CategoryModel category)
 {
     Id             = product.Id;
     Code           = product.Code;
     Name           = product.Name;
     Description    = product.Description;
     LasModifiedUtc = product.LastModifiedUtc;
     UOMId          = uom.Id;
     UOMUnit        = uom.Unit;
     UOM            = new UnitOfMeasurementDto(uom);
     Category       = new CategoryDto(category);
 }
        public object GetSKUInfo(long productId, long colloPid = 0)
        {
            var product = ServiceProvider.Instance <IProductService> .Create.GetProduct(productId);

            var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(productId);

            List <Himall.Model.CollocationSkuInfo> collProduct = null;

            if (colloPid != 0)
            {
                collProduct = ServiceProvider.Instance <ICollocationService> .Create.GetProductColloSKU(productId, colloPid);
            }
            decimal discount = 1M;

            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
            }
            var shopInfo = ShopApplication.GetShop(product.ShopId);

            var skuArray = new List <ProductSKUModel>();

            foreach (var sku in product.SKUInfo.Where(s => s.Stock > 0))
            {
                var             price   = sku.SalePrice * discount;
                ProductSKUModel skuMode = new ProductSKUModel
                {
                    Price = shopInfo.IsSelf ? price : sku.SalePrice,
                    SkuId = sku.Id,
                    Stock = (int)sku.Stock
                };

                if (limitBuy != null)
                {
                    var limitSku = ServiceProvider.Instance <ILimitTimeBuyService> .Create.Get(limitBuy.Id);

                    var limitSkuItem = limitSku.Details.Where(r => r.SkuId.Equals(sku.Id)).FirstOrDefault();
                    if (limitSkuItem != null)
                    {
                        skuMode.Price = limitSkuItem.Price;
                    }
                }
                skuArray.Add(skuMode);
            }
            //foreach (var item in skuArray)
            //{
            //    var str = item.SkuId.Split('_');
            //    item.SkuId = string.Format("{0};{1};{2}", str[1], str[2], str[3]);
            //}
            return(Json(new { Success = "true", SkuArray = skuArray }));
        }
示例#6
0
        public void shouldSuccessInstantiate()
        {
            ProductSKUModel product = new ProductSKUModel("Code", "Name", 1, 1, "Description")
            {
                Id = 1,
            };

            UnitOfMeasurementModel uom = new UnitOfMeasurementModel()
            {
                Id = 1
            };

            CategoryModel category = new CategoryModel("Name", "Code")
            {
            };

            ProductSKUDto productSKUDto = new ProductSKUDto(product, uom, category)
            {
                Category = new CategoryDto(new CategoryModel("Name", "Code"))
            };


            ProductPackingModel productPackingModel = new ProductPackingModel(1, 1, 1, "Code", "Name", "description")
            {
            };

            ProductSKUModel productSKUModel = new ProductSKUModel("Code", "Name", 1, 1, "Description")
            {
            };

            UnitOfMeasurementModel uomModel = new UnitOfMeasurementModel("Unit")
            {
            };
            UnitOfMeasurementModel skuUOM            = new UnitOfMeasurementModel();
            CategoryModel          skuCategory       = new CategoryModel();
            ProductPackingDto      productPackingDto = new ProductPackingDto(productPackingModel, productSKUModel, uomModel, skuUOM, skuCategory);


            BarcodeInfo barcode = new BarcodeInfo(productSKUDto, productPackingDto);

            Assert.NotNull(barcode);
            Assert.Equal("Code", barcode.SKUCode);
            Assert.Equal("Name", barcode.SKUName);
            Assert.Equal("Code", barcode.PackingCode);
            Assert.Equal(1, barcode.PackingSize);
            Assert.Equal("Unit", barcode.PackingType);
        }
        public int CreateSKU(FabricSKUFormDto form)
        {
            var code = GenerateCode(form);

            if (_dbContext.ProductSKUs.Any(entity => entity.Code == code))
            {
                return(0);
            }

            var category = _dbContext.IPCategories.FirstOrDefault(entity => entity.Name == TYPE);

            var product = new ProductSKUModel(code, code, form.UOMId.GetValueOrDefault(), category.Id, "");

            _unitOfWork.ProductSKUs.Insert(product);
            _unitOfWork.Commit();

            var fabric = new FabricProductSKUModel(code, product.Id, form.WovenTypeId.GetValueOrDefault(), form.ConstructionId.GetValueOrDefault(), form.WidthId.GetValueOrDefault(), form.WarpId.GetValueOrDefault(), form.WeftId.GetValueOrDefault(), form.ProcessTypeId.GetValueOrDefault(), form.YarnTypeId.GetValueOrDefault(), form.GradeId.GetValueOrDefault(), form.UOMId.GetValueOrDefault());

            _unitOfWork.FabricSKUProducts.Insert(fabric);
            _unitOfWork.Commit();

            return(fabric.Id);
        }
示例#8
0
        public Task <int> Create(FormDto form)
        {
            if (_productSKURepository.ReadAll().Any(entity => entity.Name == form.Name))
            {
                var errorResult = new List <ValidationResult>()
                {
                    new ValidationResult("Nama tidak boleh duplikat", new List <string> {
                        "Name"
                    })
                };
                var validationContext = new ValidationContext(form, _serviceProvider, null);
                throw new ServiceValidationException(validationContext, errorResult);
            }

            if (_productSKURepository.ReadAll().Any(entity => entity.Code == form.Code))
            {
                var errorResult = new List <ValidationResult>()
                {
                    new ValidationResult("Kode tidak boleh duplikat", new List <string> {
                        "Kode"
                    })
                };
                var validationContext = new ValidationContext(form, _serviceProvider, null);
                throw new ServiceValidationException(validationContext, errorResult);
            }

            var model = new ProductSKUModel(
                form.Code,
                form.Name,
                form.UOMId.GetValueOrDefault(),
                form.CategoryId.GetValueOrDefault(),
                form.Description
                );

            return(_productSKURepository.InsertAsync(model));
        }
        public FabricSKUIdCodeDto AutoCreateSKU(FabricSKUAutoCreateFormDto form)
        {
            var code          = "";
            var processType   = _dbContext.IPProcessType.FirstOrDefault(entity => entity.ProcessType == form.ProcessType);
            var processTypeId = 0;

            if (processType != null)
            {
                code         += processType.Code;
                processTypeId = processType.Id;
            }
            else
            {
                code         += "00";
                processTypeId = 0;
            }

            var yearCode = CodeConstructionHelper.GetYearCode(DateTime.Now.Year);

            code += yearCode;

            var sppNo = form.ProductionOrderNo.Substring(form.ProductionOrderNo.Length - 4);

            code += sppNo;

            var grade   = _dbContext.IPGrades.FirstOrDefault(entity => entity.Type == form.Grade);
            var gradeId = 0;

            if (grade != null)
            {
                code   += grade.Code;
                gradeId = grade.Id;
            }
            else
            {
                code   += "0";
                gradeId = 0;
            }

            var uom      = _dbContext.IPUnitOfMeasurements.FirstOrDefault(entity => entity.Unit == form.UOM);
            var category = _dbContext.IPCategories.FirstOrDefault(entity => entity.Name == "FABRIC");

            var model            = new ProductSKUModel();
            var productFabricSKU = new FabricProductSKUModel();

            if (uom != null && category != null)
            {
                model = new ProductSKUModel(code, code, uom.Id, category.Id, "");
                _unitOfWork.ProductSKUs.Insert(model);
                _unitOfWork.Commit();

                productFabricSKU = new FabricProductSKUModel(code, model.Id, 0, 0, 0, 0, 0, processTypeId, form.yarnMaterialId, gradeId, uom.Id,
                                                             form.materialId, form.materialName, form.materialConstructionId, form.materialConstructionName,
                                                             form.yarnMaterialId, form.yarnMaterialName, form.ProductionOrderNo, form.uomUnit, form.motif, form.color, form.Grade, form.Width);

                _unitOfWork.FabricSKUProducts.Insert(productFabricSKU);
                _unitOfWork.Commit();
            }
            else
            {
                var errorResult = new List <ValidationResult>()
                {
                    new ValidationResult("Satuan dan Kategori SKU tidak ditemukan periksa data master", new List <string> {
                        "UOMCategory"
                    })
                };
                var validationContext = new ValidationContext(model, _serviceProvider, null);
                throw new ServiceValidationException(validationContext, errorResult);
            }
            return(new FabricSKUIdCodeDto()
            {
                FabricSKUId = productFabricSKU.Id, ProductSKUCode = code, ProductSKUId = model.Id
            });
        }
        public async Task GetIndex_Return_success()
        {
            var productPackingRepository    = new Mock <IRepository <ProductPackingModel> >();
            var productSKURepository        = new Mock <IRepository <ProductSKUModel> >();
            var unitOfMeasurementRepository = new Mock <IRepository <UnitOfMeasurementModel> >();
            var categoryRepository          = new Mock <IRepository <CategoryModel> >();

            var productPackingModel = new ProductPackingModel(1, 1, 1, "Code", "Name", "description")
            {
                Id     = 1,
                Active = true,
            };

            productPackingRepository.Setup(s => s.ReadAll())
            .Returns(new List <ProductPackingModel>()
            {
                productPackingModel
            }.AsQueryable().BuildMock().Object);

            var productSKUModel = new ProductSKUModel("Code", "Name", 1, 1, "Description")
            {
                Id     = 1,
                Active = true,
            };

            productSKURepository.Setup(s => s.ReadAll())
            .Returns(new List <ProductSKUModel>()
            {
                productSKUModel
            }.AsQueryable().BuildMock().Object);;


            var unitOfMeasurementModel = new UnitOfMeasurementModel("Unit")
            {
                Id     = 1,
                Active = true
            };

            unitOfMeasurementRepository.Setup(s => s.ReadAll())
            .Returns(new List <UnitOfMeasurementModel>()
            {
                unitOfMeasurementModel
            }.AsQueryable().BuildMock().Object);


            var service = GetService(GetServiceProvider(
                                         productPackingRepository.Object,
                                         productSKURepository.Object,
                                         categoryRepository.Object,
                                         unitOfMeasurementRepository.Object
                                         ).Object);

            IndexQueryParam queryParam = new IndexQueryParam()
            {
                order   = "",
                page    = 1,
                size    = 1,
                keyword = "Name"
            };

            var result = await service.GetIndex(queryParam);

            Assert.NotNull(result);
        }
 public DocumentItemDto(ProductSKUInventoryMovementModel item, ProductSKUModel product, UnitOfMeasurementModel uom, CategoryModel category)
 {
     Product = new ProductSKUDto(product, uom, category);
     Quantity = item.Quantity;
     Remark = item.Remark;
 }