Beispiel #1
0
        public void SaveStoreBuveraGradeSize(StoreBuveraGradeSizeDTO storeBuveraGradeSizeDTO, bool inOrOut)
        {
            double sizeQuantity = 0;
            var    result       = this.UnitOfWork.Get <StoreBuveraGradeSize>().AsQueryable()
                                  .FirstOrDefault(e => e.StoreId == storeBuveraGradeSizeDTO.StoreId && e.GradeId == storeBuveraGradeSizeDTO.GradeId && e.SizeId == storeBuveraGradeSizeDTO.SizeId);


            if (result == null)
            {
                var storeBuveraGradeSize = new StoreBuveraGradeSize()
                {
                    GradeId   = storeBuveraGradeSizeDTO.GradeId,
                    SizeId    = storeBuveraGradeSizeDTO.SizeId,
                    StoreId   = storeBuveraGradeSizeDTO.StoreId,
                    Quantity  = storeBuveraGradeSizeDTO.Quantity,
                    TimeStamp = DateTime.Now
                };
                this.UnitOfWork.Get <StoreBuveraGradeSize>().AddNew(storeBuveraGradeSize);
                this.UnitOfWork.SaveChanges();
            }

            else
            {
                if (inOrOut)
                {
                    sizeQuantity = result.Quantity + storeBuveraGradeSizeDTO.Quantity;

                    result.StoreId   = storeBuveraGradeSizeDTO.StoreId;
                    result.SizeId    = storeBuveraGradeSizeDTO.SizeId;
                    result.GradeId   = storeBuveraGradeSizeDTO.GradeId;
                    result.Quantity  = sizeQuantity;
                    result.TimeStamp = DateTime.Now;
                    this.UnitOfWork.Get <StoreBuveraGradeSize>().Update(result);
                    this.UnitOfWork.SaveChanges();
                }
                else
                {
                    sizeQuantity = result.Quantity - storeBuveraGradeSizeDTO.Quantity;

                    result.StoreId   = storeBuveraGradeSizeDTO.StoreId;
                    result.SizeId    = storeBuveraGradeSizeDTO.SizeId;
                    result.GradeId   = storeBuveraGradeSizeDTO.GradeId;
                    result.Quantity  = sizeQuantity;
                    result.TimeStamp = DateTime.Now;
                    this.UnitOfWork.Get <StoreBuveraGradeSize>().Update(result);
                    this.UnitOfWork.SaveChanges();
                }
            }
        }
        public long SaveBatchOutPut(BatchOutPut batchOutPut, string userId)
        {
            List <StockGradeSize> stockGradeSizeList = new List <StockGradeSize>();
            double batchQuantity  = BatchQuantity(batchOutPut.BatchId);
            var    batchOutPutDTO = new DTO.BatchOutPutDTO()
            {
                BatchId         = batchOutPut.BatchId,
                BrandOutPut     = batchOutPut.BrandOutPut,
                FlourOutPut     = batchOutPut.FlourOutPut,
                BranchId        = batchOutPut.BranchId,
                SectorId        = batchOutPut.SectorId,
                Loss            = ComputeBatchLoss(batchOutPut.BrandOutPut, batchOutPut.FlourOutPut, batchQuantity),
                FlourPercentage = ComputePercentageBatchFlourOutPut(batchOutPut.FlourOutPut, batchQuantity),
                BrandPercentage = ComputePercentageBatchBrandOutPut(batchOutPut.BrandOutPut, batchQuantity),
                LossPercentage  = ComputePercentageBatchLoss(batchOutPut.BrandOutPut, batchOutPut.FlourOutPut, batchQuantity),
                Deleted         = batchOutPut.Deleted,
                CreatedBy       = batchOutPut.CreatedBy,
                CreatedOn       = batchOutPut.CreatedOn
            };

            var batchOutPutId = this._dataService.SaveBatchOutPut(batchOutPutDTO, userId);

            if (batchOutPut.Grades != null)
            {
                double totalBuveraQuantity = 0;
                if (batchOutPut.Grades.Any())
                {
                    List <BatchGradeSize> batchGradeSizeList = new List <BatchGradeSize>();

                    foreach (var grade in batchOutPut.Grades)
                    {
                        var gradeId = grade.GradeId;
                        if (grade.Denominations != null)
                        {
                            if (grade.Denominations.Any())
                            {
                                foreach (var denomination in grade.Denominations)
                                {
                                    var batchGradeSize = new BatchGradeSize()
                                    {
                                        GradeId       = gradeId,
                                        SizeId        = denomination.DenominationId,
                                        BatchOutPutId = batchOutPutId,
                                        Quantity      = denomination.Quantity,
                                        TimeStamp     = DateTime.Now
                                    };
                                    batchGradeSizeList.Add(batchGradeSize);

                                    var stockGradeSize = new StockGradeSize()
                                    {
                                        GradeId   = gradeId,
                                        SizeId    = denomination.DenominationId,
                                        Quantity  = denomination.Quantity,
                                        TimeStamp = DateTime.Now
                                    };
                                    stockGradeSizeList.Add(stockGradeSize);



                                    var inOrOut = false;
                                    //Method that updates buvera into storeBuveraGradeSize table(storeBuvera stock)
                                    var storeBuveraGradeSize = new StoreBuveraGradeSizeDTO()
                                    {
                                        StoreId  = batchOutPut.StoreId,
                                        GradeId  = batchGradeSize.GradeId,
                                        SizeId   = batchGradeSize.SizeId,
                                        Quantity = batchGradeSize.Quantity,
                                    };

                                    this._buveraDataService.SaveStoreBuveraGradeSize(storeBuveraGradeSize, inOrOut);
                                    totalBuveraQuantity = denomination.Quantity + totalBuveraQuantity;
                                }
                            }
                        }
                    }

                    var buveraDTO = new DTO.BuveraDTO()
                    {
                        TotalQuantity = totalBuveraQuantity,
                        BranchId      = batchOutPut.BranchId,
                        FromSupplier  = Convert.ToString(batchOutPut.StoreId),
                        ToReceiver    = Convert.ToString(batchOutPut.BatchId),
                        StoreId       = batchOutPut.StoreId,
                    };

                    var buveraId = this._buveraDataService.SaveBuvera(buveraDTO, userId);
                    this._dataService.PurgeBatchGradeSize(batchOutPutId);
                    this.SaveBatchGradeSizeList(batchGradeSizeList);
                }
            }
            UpdateBatchSupply(batchOutPut.BatchId, supplyStatusIdComplete, userId);
            if (batchOutPut.BrandOutPut != 0 && batchOutPut.FlourOutPut != 0)
            {
                var stock = new Stock()
                {
                    SectorId      = batchOutPut.SectorId,
                    BranchId      = batchOutPut.BranchId,
                    BatchId       = batchOutPut.BatchId,
                    InOrOut       = true,
                    StoreId       = batchOutPut.StoreId,
                    ProductId     = brandId,
                    ProductOutPut = batchOutPut.BrandOutPut,
                };
                _stockService.SaveStock(stock, userId);
                var flourStock = new Stock()
                {
                    SectorId       = batchOutPut.SectorId,
                    BranchId       = batchOutPut.BranchId,
                    BatchId        = batchOutPut.BatchId,
                    InOrOut        = true,
                    StoreId        = batchOutPut.StoreId,
                    ProductId      = flourId,
                    ProductOutPut  = batchOutPut.FlourOutPut,
                    StockGradeSize = stockGradeSizeList
                };
                _stockService.SaveStock(flourStock, userId);
            }

            return(batchOutPutId);
        }
        public long IssueBuvera(Buvera buvera, string userId)
        {
            bool inOrOut = false;

            var fromSupplierStore = GetStoreName(buvera.StoreId);
            var toReceiverStore   = GetStoreName(Convert.ToInt64(buvera.ToReceiver));

            var buveraDTO = new DTO.BuveraDTO()
            {
                BuveraId      = buvera.BuveraId,
                TotalCost     = buvera.TotalCost,
                TotalQuantity = buvera.TotalQuantity,
                BranchId      = buvera.BranchId,
                FromSupplier  = fromSupplierStore,
                ToReceiver    = toReceiverStore,
                StoreId       = Convert.ToInt64(buvera.ToReceiver),
                Deleted       = buvera.Deleted,
                CreatedBy     = buvera.CreatedBy,
                CreatedOn     = buvera.CreatedOn
            };

            var buveraId = this._dataService.SaveBuvera(buveraDTO, userId);

            if (buvera.Grades != null)
            {
                if (buvera.Grades.Any())
                {
                    List <BuveraGradeSize> buveraGradeSizeList = new List <BuveraGradeSize>();

                    foreach (var grade in buvera.Grades)
                    {
                        var gradeId = grade.GradeId;
                        if (grade.Denominations != null)
                        {
                            if (grade.Denominations.Any())
                            {
                                foreach (var denomination in grade.Denominations)
                                {
                                    var sizeRate = GetRateOfAParticularSize(denomination.DenominationId);

                                    var buveraGradeSize = new BuveraGradeSize()
                                    {
                                        GradeId   = gradeId,
                                        SizeId    = denomination.DenominationId,
                                        BuveraId  = buveraId,
                                        StoreId   = Convert.ToInt64(buvera.ToReceiver),
                                        Amount    = Convert.ToDouble(denomination.Quantity * sizeRate),
                                        Rate      = sizeRate,
                                        Quantity  = denomination.Quantity,
                                        TimeStamp = DateTime.Now
                                    };
                                    buveraGradeSizeList.Add(buveraGradeSize);

                                    inOrOut = true;
                                    //Method that adds buvera into storeBuveraGradeSize table(storeBuvera stock)
                                    var storeBuveraGradeSize = new StoreBuveraGradeSizeDTO()
                                    {
                                        StoreId  = Convert.ToInt64(buvera.ToReceiver),
                                        GradeId  = buveraGradeSize.GradeId,
                                        SizeId   = buveraGradeSize.SizeId,
                                        Quantity = buveraGradeSize.Quantity,
                                    };

                                    this._dataService.SaveStoreBuveraGradeSize(storeBuveraGradeSize, inOrOut);

                                    //Method that updates buvera into storeBuveraGradeSize table(storeBuvera stock)
                                    var fromStoreBuveraGradeSize = new StoreBuveraGradeSizeDTO()
                                    {
                                        StoreId  = buvera.StoreId,
                                        GradeId  = buveraGradeSize.GradeId,
                                        SizeId   = buveraGradeSize.SizeId,
                                        Quantity = buveraGradeSize.Quantity,
                                    };

                                    this._dataService.SaveStoreBuveraGradeSize(fromStoreBuveraGradeSize, false);
                                }
                            }
                        }
                    }
                    this._dataService.PurgeBuveraGradeSize(buveraId);
                    this.SaveBuveraGradeSizeList(buveraGradeSizeList);
                }
            }
            return(buveraId);
        }