Exemplo n.º 1
0
        public DockMilkCollectionDTO GetDockMilkCollectionById(int dockCollectionId)
        {
            DockMilkCollectionDTO dockMilkCollectionDTO = new DockMilkCollectionDTO();
            var dockMilkCollection = unitOfWork.DockMilkCollectionRepository.GetById(dockCollectionId);

            if (dockMilkCollection != null)
            {
                dockMilkCollectionDTO = DockMilkCollectionConvertor.ConvertToDockMilkCollectionDto(dockMilkCollection);
                //   vlcMilkCollectionDto = DockMilkCollectionConvertor.ConvertToDockMilkCollectionDto(vlcMilkCollection);
            }
            return(dockMilkCollectionDTO);
        }
Exemplo n.º 2
0
        public List <DockMilkCollectionDTO> GetAllDockMilkCollectionByPageCount(int?pageNumber, int?count)
        {
            List <DockMilkCollectionDTO> DockMilkCollectionList = new List <DockMilkCollectionDTO>();
            var DockMilkCollections = unitOfWork.DockMilkCollectionRepository.GetDockMilkCollectionByCount(pageNumber, count);

            if (DockMilkCollections != null)
            {
                foreach (var dock in DockMilkCollections)
                {
                    DockMilkCollectionList.Add(DockMilkCollectionConvertor.ConvertToDockMilkCollectionDto(dock));
                }
            }

            return(DockMilkCollectionList);
        }
Exemplo n.º 3
0
        public List <DockMilkCollectionDTO> GetAllDockMilkCollection()
        {
            List <DockMilkCollectionDTO> dockMilkCollectionList = new List <DockMilkCollectionDTO>();
            var dockMilkCollections = unitOfWork.DockMilkCollectionRepository.GetAll();

            if (dockMilkCollections != null)
            {
                foreach (var dockMilkCollection in dockMilkCollections)
                {
                    dockMilkCollectionList.Add(DockMilkCollectionConvertor.ConvertToDockMilkCollectionDto(dockMilkCollection));
                }
            }

            return(dockMilkCollectionList);
        }
Exemplo n.º 4
0
        public List <DockMilkCollectionDTO> GetDockCollectionByDateAndShift(DateTime collectionDate, int shift, int?pageNumber)
        {
            List <DockMilkCollectionDTO> dockMilkCollectionDTOList = new List <DockMilkCollectionDTO>();

            var dockMilkCollections = unitOfWork.DockMilkCollectionRepository.GetDockCollectionByDateShift(collectionDate, shift, pageNumber);

            if (dockMilkCollections != null)
            {
                foreach (var dockmilkCollection in dockMilkCollections)
                {
                    dockMilkCollectionDTOList.Add(DockMilkCollectionConvertor.ConvertToDockMilkCollectionDto(dockmilkCollection));
                }
            }

            return(dockMilkCollectionDTOList);
        }
Exemplo n.º 5
0
        public ResponseDTO AddDockMilkCollection(DockMilkCollectionDTO dockMilkCollectionDTO)
        {
            var vlc = unitOfWork.VLCRepository.GetById(dockMilkCollectionDTO.VLCId);

            if (vlc != null)
            {
                ResponseDTO        responseDTO        = new ResponseDTO();
                decimal            milkCommission     = GetCommissionForDockMilkCollection(vlc);
                DockMilkCollection dockMilkCollection = new DockMilkCollection();
                dockMilkCollection.DockMilkCollectionId = unitOfWork.DashboardRepository.NextNumberGenerator("DockMilkCollection");
                if (dockMilkCollectionDTO.CollectionDateTime != DateTime.MinValue)
                {
                    dockMilkCollection.CollectionDateTime = dockMilkCollectionDTO.CollectionDateTime;
                }
                else
                {
                    dockMilkCollection.CollectionDateTime = DateTimeHelper.GetISTDateTime();
                }

                dockMilkCollection.CreatedDate  = DateTimeHelper.GetISTDateTime();
                dockMilkCollection.ModifiedDate = DateTimeHelper.GetISTDateTime();
                dockMilkCollection.CreatedBy    = dockMilkCollectionDTO.ModifiedBy = "Admin";
                dockMilkCollection.IsDeleted    = false;
                DockMilkCollectionConvertor.ConvertToDockMilkCollectionEntity(ref dockMilkCollection, dockMilkCollectionDTO, false);
                if (dockMilkCollectionDTO.dockMilkCollectionList != null)
                {
                    foreach (var dockMilkCollectionDtlDto in dockMilkCollectionDTO.dockMilkCollectionList)

                    {
                        if (dockMilkCollectionDtlDto.Quantity > 0 && dockMilkCollectionDtlDto.ProductId > 0)
                        {
                            this.CheckForExistingCollectionDetailByDateShiftProduct(dockMilkCollection.CollectionDateTime.Date, dockMilkCollection.ShiftId, (int)dockMilkCollectionDtlDto.ProductId, dockMilkCollection.VLCId);
                            DockMilkCollectionDtl dockMilkCollectionDtl = new DockMilkCollectionDtl();
                            dockMilkCollectionDtl.DockMilkCollectionDtlI = unitOfWork.DashboardRepository.NextNumberGenerator("DockMilkCollectionDtl");
                            dockMilkCollectionDtl.DockMilkCollectionId   = dockMilkCollection.DockMilkCollectionId;
                            DockMilkCollectionConvertor.ConvertToDockMilkCollectionDtlEntity(ref dockMilkCollectionDtl, dockMilkCollectionDtlDto, false);
                            dockMilkCollectionDtl.RatePerUnit    = unitOfWork.MilkRateRepository.GetMilkRateByApplicableRate(vlc.ApplicableRate, dockMilkCollectionDtlDto.FAT.GetValueOrDefault(), dockMilkCollectionDtlDto.CLR.GetValueOrDefault());
                            dockMilkCollectionDtlDto.Amount      = dockMilkCollectionDtl.Amount = dockMilkCollectionDtl.RatePerUnit.GetValueOrDefault() * dockMilkCollectionDtlDto.Quantity;
                            dockMilkCollectionDtlDto.Commission  = dockMilkCollectionDtl.Commission = dockMilkCollectionDtlDto.Quantity * milkCommission;
                            dockMilkCollectionDtlDto.TotalAmount = dockMilkCollectionDtl.TotalAmount = dockMilkCollectionDtl.Commission.GetValueOrDefault() + dockMilkCollectionDtl.Amount;

                            unitOfWork.DockMilkCollectionDtlRepository.Add(dockMilkCollectionDtl);
                        }
                    }
                    dockMilkCollection.TotalCan         = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.TotalCan);
                    dockMilkCollection.TotalRejectedCan = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.TotalRejectedCan);
                    dockMilkCollection.Amount           = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.Amount);
                    dockMilkCollection.TotalQuantity    = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.Quantity);
                    dockMilkCollection.Commission       = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.Commission).GetValueOrDefault();
                    dockMilkCollection.TotalAmount      = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.TotalAmount).GetValueOrDefault();

                    dockMilkCollection.RejectedQuantity = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.RejectedQuantity);
                }
                else
                {
                    throw new PlatformModuleException("Dock Milk Collection Detail Not Found");
                }
                unitOfWork.DockMilkCollectionRepository.Add(dockMilkCollection);
                UpdateVLCPaymentDetailsForDockCollection(vlc, dockMilkCollection);
                string dockMessage  = string.Format(NatrajConfigurationHelper.DockCollectionMessage, dockMilkCollection.CollectionDateTime.Date, dockMilkCollection.TotalQuantity, dockMilkCollection.TotalAmount);
                var    natrajSMSLog = this.SendSMS(vlc.Contact, dockMessage);
                unitOfWork.SMSRepository.Add(natrajSMSLog);
                unitOfWork.SaveChanges();
                new SMSService().SendEmailInBackgroundThread(natrajSMSLog);

                unitOfWork.SaveChanges();
                responseDTO.Status  = true;
                responseDTO.Message = String.Format("Dock Milk Collection Detail Added Successfully ");
                responseDTO.Data    = this.GetDockCollectionByDateAndShift(DateTimeHelper.GetISTDateTime().Date, dockMilkCollection.ShiftId, 1);

                return(responseDTO);
            }
            else
            {
                throw new PlatformModuleException("VLC Collection Details Not Found");
            }
        }
Exemplo n.º 6
0
        public ResponseDTO UpdateDockMilkCollection(DockMilkCollectionDTO dockMilkCollectionDTO)
        {
            ResponseDTO responseDTO = new ResponseDTO();
            //Will update the method when required

            var dockMilkCollection = unitOfWork.DockMilkCollectionRepository.GetById(dockMilkCollectionDTO.DockMilkCollectionId);
            var vlc = unitOfWork.VLCRepository.GetById(dockMilkCollection.VLCId);

            if (dockMilkCollection == null)
            {
                throw new PlatformModuleException(string.Format("Dock Milk Collection Detail Not Found with Collection Id {0}", dockMilkCollectionDTO.DockMilkCollectionId));
            }
            dockMilkCollection.ModifiedDate = DateTimeHelper.GetISTDateTime();
            dockMilkCollection.ModifiedBy   = "Admin";
            decimal milkCommission = GetCommissionForDockMilkCollection(vlc);

            DockMilkCollectionConvertor.ConvertToDockMilkCollectionEntity(ref dockMilkCollection, dockMilkCollectionDTO, true);


            if (dockMilkCollectionDTO.dockMilkCollectionList != null)
            {
                foreach (var dockCollectionDtlDTO in dockMilkCollectionDTO.dockMilkCollectionList)
                {
                    var dockMilkCollectionDtl = unitOfWork.DockMilkCollectionDtlRepository.GetById(dockCollectionDtlDTO.DockMilkCollectionDtlId);
                    if (dockMilkCollectionDtl != null && dockCollectionDtlDTO.Quantity > 0 && dockCollectionDtlDTO.ProductId > 0)
                    {
                        DockMilkCollectionConvertor.ConvertToDockMilkCollectionDtlEntity(ref dockMilkCollectionDtl, dockCollectionDtlDTO, false);
                        dockMilkCollectionDtl.RatePerUnit = unitOfWork.MilkRateRepository.GetMilkRateByApplicableRate(vlc.ApplicableRate, dockCollectionDtlDTO.FAT.GetValueOrDefault(), dockCollectionDtlDTO.CLR.GetValueOrDefault());
                        dockCollectionDtlDTO.Amount       = dockMilkCollectionDtl.Amount = dockMilkCollectionDtl.Amount = dockMilkCollectionDtl.RatePerUnit.GetValueOrDefault() * dockCollectionDtlDTO.Quantity;
                        dockCollectionDtlDTO.Commission   = dockMilkCollectionDtl.Commission = dockMilkCollectionDtl.Commission = dockCollectionDtlDTO.Quantity * milkCommission;
                        dockCollectionDtlDTO.TotalAmount  = dockMilkCollectionDtl.TotalAmount = dockMilkCollectionDtl.Commission.GetValueOrDefault() + dockMilkCollectionDtl.Amount;

                        unitOfWork.DockMilkCollectionDtlRepository.Update(dockMilkCollectionDtl);
                    }
                }

                dockMilkCollection.TotalCan         = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.TotalCan);
                dockMilkCollection.TotalRejectedCan = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.TotalRejectedCan);
                dockMilkCollection.Amount           = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.Amount);
                dockMilkCollection.TotalQuantity    = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.Quantity);
                dockMilkCollection.Commission       = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.Commission).GetValueOrDefault();
                dockMilkCollection.TotalAmount      = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.TotalAmount).GetValueOrDefault();

                dockMilkCollection.RejectedQuantity = dockMilkCollectionDTO.dockMilkCollectionList.Sum(s => s.RejectedQuantity);
            }
            else
            {
                throw new PlatformModuleException("Dock Milk Collection Details Not Found");
            }

            unitOfWork.DockMilkCollectionRepository.Update(dockMilkCollection);
            UpdateVLCPaymentDetailsForDockCollection(vlc, dockMilkCollection);


            string dockMessage  = string.Format(NatrajConfigurationHelper.DockCollectionMessage, dockMilkCollection.CollectionDateTime.Date, dockMilkCollection.TotalQuantity, dockMilkCollection.TotalAmount);
            var    natrajSMSLog = this.SendSMS(vlc.Contact, dockMessage);

            unitOfWork.SMSRepository.Add(natrajSMSLog);
            unitOfWork.SaveChanges();
            new SMSService().SendEmailInBackgroundThread(natrajSMSLog);

            unitOfWork.SaveChanges();
            responseDTO.Status  = true;
            responseDTO.Message = String.Format("Dock Milk Collection Detail Added Successfully ");
            responseDTO.Data    = this.GetDockCollectionByDateAndShift(DateTimeHelper.GetISTDateTime().Date, dockMilkCollection.ShiftId, 1);

            return(responseDTO);
        }