コード例 #1
0
        public async Task <GetGoodsReceivedNoteDto> CreateGoodsReceivedNoteAsync(CreateGoodsReceivedNoteDto goodsReceivedNoteDto)
        {
            //verify PO allowed to create GRN
            var order = await CheckPurchaseOrder(goodsReceivedNoteDto.PurchaseOrderId);

            CheckPurchaseOrderAllowedToCreateGRN(order);

            var currentUser       = Helper.GetCurrentUser(_userAccessor);
            var goodsReceivedNote = _mapper.Map <GoodsReceivedNote>(goodsReceivedNoteDto);

            goodsReceivedNote.CreatedBy      = currentUser.UserId;
            goodsReceivedNote.CreatedDate    = DateTime.Now;
            goodsReceivedNote.ApprovalStatus = Status.Pending;

            goodsReceivedNote = await _goodReceivedNote.AddGoodsReceivedNoteAsync(goodsReceivedNote);

            var items = await _purchaseOrderItem.GetPurchaseOrderItemsAsync(e => e.PurchaseOrderId == goodsReceivedNoteDto.PurchaseOrderId);

            foreach (var item in items)
            {
                var grnItem = new GoodsReceivedNoteItem
                {
                    GoodsReceivedNoteId = goodsReceivedNote.Id,
                    ItemId        = item.ItemId,
                    ItemUnitPrice = item.ItemUnitPrice,
                    Quantity      = item.Quantity
                };
                await _goodsReceivedNoteItem.AddGoodsReceivedNoteItemAsync(grnItem);
            }

            return(_mapper.Map <GetGoodsReceivedNoteDto>(goodsReceivedNote));
        }
コード例 #2
0
        public async Task <GoodsReceivedNoteItem> AddGoodsReceivedNoteItemAsync(GoodsReceivedNoteItem goodsReceivedNoteItem)
        {
            _context.Create(goodsReceivedNoteItem);
            await _context.CommitAsync();

            return(await _context.GoodsReceivedNoteItems
                   .Include(p => p.Item)
                   .Include(p => p.GoodsReceivedNote)
                   .FirstAsync(e => e.Id == goodsReceivedNoteItem.Id));
        }
コード例 #3
0
 public bool SaveGRN(GoodsReceivedNote GRNEntity)
 {
     using (var dbContext = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 dbContext.GoodsReceivedNotes.Add(GRNEntity);
                 foreach (POItemsView item in GRNEntity.POItemz)
                 {
                     var newEntity = new GoodsReceivedNoteItem()
                     {
                         Id = Guid.NewGuid(),
                         GoodsReceivedNoteId = GRNEntity.Id,
                         PurchaseOrderItemId = item.POItemId,
                         QuantityDelivered   = item.QtyDelivered,
                         QuantityDamaged     = item.QtyDamaged,
                         Comments            = item.comments,
                         IsInventory         = item.IsInventory
                     };
                     dbContext.GoodsReceivedNoteItems.Add(newEntity);
                 }
                 if ((dbContext.SaveChanges() > 0))
                 {
                     scope.Complete();
                     SessionData.CurrentSession.GoodsReceivedNoteList     = null;
                     SessionData.CurrentSession.GoodsReceivedNoteItemList = null;
                     SessionData.CurrentSession.PurchaseOrderList         = null;
                     SessionData.CurrentSession.ProcurementPlanList       = null;
                     return(true);
                 }
                 else
                 {
                     scope.Dispose(); return(false);
                 }
             }
             //catch (DbEntityValidationException e)
             //{
             //    foreach (var eve in e.EntityValidationErrors)
             //    {
             //        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
             //            eve.Entry.Entity.GetType().Name, eve.Entry.State);
             //        foreach (var ve in eve.ValidationErrors)
             //        {
             //            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
             //                ve.PropertyName, ve.ErrorMessage);
             //        }
             //    }
             //    throw;
             //}
             catch (Exception ex) { scope.Dispose(); throw ex; }
         }
     }
 }
コード例 #4
0
 public bool IsGRNVerified(GoodsReceivedNote GRNentity)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             foreach (GoodsReceivedNoteItem item in GRNentity.ItemColl)
             {
                 GoodsReceivedNoteItem grit = context.GoodsReceivedNoteItems.FirstOrDefault(p => p.Id == item.Id);
                 if (context.Inventories.Count(p => p.ItemId == grit.PurchaseOrderItem.Item.Id && p.WareHouseId == grit.GoodsReceivedNote.WareHouseId) > 0)
                 {
                     if (grit.PurchaseOrderItem.Item.ItemCategory.CategoryCode == "C")
                     {
                         Model.Inventory invt = context.Inventories.FirstOrDefault(p => p.ItemId == grit.PurchaseOrderItem.Item.Id && p.WareHouseId == grit.GoodsReceivedNote.WareHouseId);
                         invt.Quantity += (long)item.QuantityDelivered;
                         ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(invt, System.Data.EntityState.Modified);
                     }
                 }
                 else
                 {
                     long qty = 0;
                     if (grit.PurchaseOrderItem.Item.ItemCategory.CategoryCode == "C")
                     {
                         qty = (long)item.QuantityDelivered;
                     }
                     Model.Inventory newinvetoryEntity =
                         new Model.Inventory()
                     {
                         Id = Guid.NewGuid(), ItemId = grit.PurchaseOrderItem.Item.Id, Quantity = qty, CountryProgrammeId = GRNentity.CountryProgrammeId, WareHouseId = (Guid)grit.GoodsReceivedNote.WareHouseId
                     };
                     context.Inventories.Add(newinvetoryEntity);
                 }
                 Model.GoodsReceivedNoteItem grnitm = context.GoodsReceivedNoteItems.FirstOrDefault(p => p.Id == item.Id);
                 grnitm.QuantityDamaged = item.QuantityDamaged; grnitm.QuantityDelivered = item.QuantityDelivered;
                 ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(grnitm, System.Data.EntityState.Modified);
                 context.SaveChanges();
             }
             Model.GoodsReceivedNote grn = context.GoodsReceivedNotes.FirstOrDefault(p => p.Id == GRNentity.Id);
             grn.Verified            = true;
             grn.ApprovedOn          = DateTime.Now;
             grn.ReceptionApprovedBy = GRNentity.ReceptionApprovedBy;
             ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(grn, System.Data.EntityState.Modified);
             if (context.SaveChanges() > 0)
             {
                 scope.Complete(); return(true);
             }
             else
             {
                 scope.Dispose(); return(false);
             }
         }
     }
 }
コード例 #5
0
 public void UpdateGRNItem(GoodsReceivedNoteItem grnItem)
 {
     using (var context = new SCMSEntities())
     {
         var existing = context.GoodsReceivedNoteItems.FirstOrDefault(p => p.Id == grnItem.Id);
         context.Entry(existing).CurrentValues.SetValues(grnItem);
         context.SaveChanges();
         SessionData.CurrentSession.PurchaseOrderList         = null;
         SessionData.CurrentSession.GoodsReceivedNoteList     = null;
         SessionData.CurrentSession.GoodsReceivedNoteItemList = null;
     }
 }
コード例 #6
0
 public void DeleteGRNItem(Guid GRNItemId)
 {
     using (var context = new SCMSEntities())
     {
         var grnItem = new GoodsReceivedNoteItem {
             Id = GRNItemId
         };
         context.GoodsReceivedNoteItems.Attach(grnItem);
         ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(grnItem, System.Data.EntityState.Deleted);
         context.SaveChanges();
         SessionData.CurrentSession.PurchaseOrderList         = null;
         SessionData.CurrentSession.GoodsReceivedNoteList     = null;
         SessionData.CurrentSession.GoodsReceivedNoteItemList = null;
     }
 }
コード例 #7
0
        public GoodsReceivedNoteItemRepositoryFixture()
        {
            MockGoodsReceivedNoteItemService = new Mock <IGoodsReceivedNoteItemService>();

            var unitOfMeasure1 = new UnitOfMeasure {
                Id = 1, Code = "kg", Description = ""
            };
            var unitOfMeasure2 = new UnitOfMeasure {
                Id = 2, Code = "g", Description = ""
            };
            var unitOfMeasure3 = new UnitOfMeasure {
                Id = 3, Code = "l", Description = ""
            };
            var unitOfMeasure4 = new UnitOfMeasure {
                Id = 4, Code = "ml", Description = ""
            };
            var unitOfMeasure5 = new UnitOfMeasure {
                Id = 5, Code = "none", Description = ""
            };

            var stockType1 = new StockType {
                Id = 1, Type = "Grocery"
            };
            var stockType2 = new StockType {
                Id = 2, Type = "Beverage"
            };
            var stockType3 = new StockType {
                Id = 3, Type = "Stationery"
            };

            var stockItems = new List <StockItem>
            {
                new StockItem {
                    Id = 20025, TypeId = 1, Type = stockType1, Name = "Rice", ItemUnit = 10, UnitOfMeasureId = 1, UnitOfMeasure = unitOfMeasure1
                },
                new StockItem {
                    Id = 20026, TypeId = 1, Type = stockType1, Name = "Chilli Powder", ItemUnit = 250, UnitOfMeasureId = 2, UnitOfMeasure = unitOfMeasure2
                },
                new StockItem {
                    Id = 20050, TypeId = 2, Type = stockType2, Name = "Water", ItemUnit = 1, UnitOfMeasureId = 3, UnitOfMeasure = unitOfMeasure3
                },
                new StockItem {
                    Id = 20024, TypeId = 3, Type = stockType3, Name = "Blue Pen", ItemUnit = 1, UnitOfMeasureId = 5, UnitOfMeasure = unitOfMeasure5
                },
                new StockItem {
                    Id = 20023, TypeId = 5, Type = stockType1, Name = "Rice", ItemUnit = 10, UnitOfMeasureId = 1, UnitOfMeasure = unitOfMeasure1
                },
            };

            GoodsReceivedNoteItems = new List <GoodsReceivedNoteItem>
            {
                new GoodsReceivedNoteItem {
                    Id = 1,
                    GoodsReceivedNoteId = 101,
                    Item          = stockItems.First(d => d.Id == 20025),
                    ItemId        = 20025,
                    ItemUnitPrice = 540,
                    Quantity      = 5,
                    Nbt           = 0.1m,
                    Vat           = 0.1m,
                    Discount      = 0.1m
                },
                new GoodsReceivedNoteItem {
                    Id = 2,
                    GoodsReceivedNoteId = 202,
                    Item          = stockItems.First(d => d.Id == 20026),
                    ItemId        = 20026,
                    ItemUnitPrice = 30,
                    Quantity      = 10,
                    Nbt           = 0.1m,
                    Vat           = 0.1m,
                    Discount      = 0.1m
                },
                new GoodsReceivedNoteItem {
                    Id = 3,
                    GoodsReceivedNoteId = 101,
                    Item          = stockItems.First(d => d.Id == 20050),
                    ItemId        = 20050,
                    ItemUnitPrice = 50,
                    Quantity      = 5,
                    Nbt           = 0.1m,
                    Vat           = 0.1m,
                    Discount      = 0.1m
                },
                new GoodsReceivedNoteItem {
                    Id = 4,
                    GoodsReceivedNoteId = 202,
                    Item          = stockItems.First(d => d.Id == 20024),
                    ItemId        = 20024,
                    ItemUnitPrice = 260,
                    Quantity      = 6,
                    Nbt           = 0.1m,
                    Vat           = 0.1m,
                    Discount      = 0.1m
                }
            };

            CreateGoodsReceivedNoteItemDto = new CreateGoodsReceivedNoteItemDto
            {
                GoodsReceivedNoteId = 202,
                ItemId        = 20023,
                ItemUnitPrice = 350,
                Quantity      = 5
            };

            CreatedNewGoodsReceivedNoteItem = new GoodsReceivedNoteItem
            {
                Id = 5,
                GoodsReceivedNoteId = 202,
                Item          = stockItems.First(d => d.Id == 20023),
                ItemId        = 20023,
                ItemUnitPrice = 350,
                Quantity      = 5
            };

            EditGoodsReceivedNoteItemDto = new EditGoodsReceivedNoteItemDto
            {
                GoodsReceivedNoteId = 101,
                ItemId        = 20025,
                ItemUnitPrice = 650,
                Quantity      = 7
            };
        }
コード例 #8
0
 public async Task DeleteGoodsReceivedNoteItemAsync(GoodsReceivedNoteItem goodsReceivedNoteItem)
 {
     _context.Delete(goodsReceivedNoteItem);
     await _context.CommitAsync();
 }
コード例 #9
0
 public async Task UpdateGoodsReceivedNoteItemAsync(GoodsReceivedNoteItem goodsReceivedNoteItem)
 {
     _context.Modify(goodsReceivedNoteItem);
     await _context.CommitAsync();
 }