Ejemplo 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);
        }
Ejemplo n.º 2
0
        //Post api/Customer

        public IHttpActionResult Post([FromBody] DockMilkCollectionDTO vLCMilkCollectionDTO)
        {
            try
            {
                if (vLCMilkCollectionDTO == null)
                {
                    Ok(ResponseHelper.CreateResponseDTOForException("Argument Null"));
                }
                //Create New Customer
                ResponseDTO responseDTO = _dockMilkCollectionService.AddDockMilkCollection(vLCMilkCollectionDTO);

                return(Ok(responseDTO));
            }
            catch (PlatformModuleException ex)
            {
                //Write Log Here
                return(Ok(ResponseHelper.CreateResponseDTOForException(ex.Message)));
            }
        }
Ejemplo n.º 3
0
        public static DockMilkCollectionDTO ConvertToDockMilkCollectionDto(DockMilkCollection dockMilkCollection)
        {
            DockMilkCollectionDTO dockMilkCollectionDTO = new DockMilkCollectionDTO();

            dockMilkCollectionDTO.DockMilkCollectionId = dockMilkCollection.DockMilkCollectionId;
            dockMilkCollectionDTO.VLCId              = dockMilkCollection.VLCId;
            dockMilkCollectionDTO.VLCName            = dockMilkCollection.VLC != null ? dockMilkCollection.VLC.VLCName : string.Empty;
            dockMilkCollectionDTO.CollectionDateTime = dockMilkCollection.CollectionDateTime;
            dockMilkCollectionDTO.TotalQuantity      = dockMilkCollection.TotalQuantity;
            dockMilkCollectionDTO.ShiftId            = (ShiftEnum)dockMilkCollection.ShiftId;
            dockMilkCollectionDTO.CollectionShift    = dockMilkCollectionDTO.ShiftId.ToString();
            dockMilkCollectionDTO.ReceiverName       = dockMilkCollection.ReceiverName;
            dockMilkCollectionDTO.RejectedQuantity   = dockMilkCollection.RejectedQuantity;
            dockMilkCollectionDTO.TotalCan           = dockMilkCollection.TotalCan.HasValue ? dockMilkCollection.TotalCan.Value : 0;
            dockMilkCollectionDTO.TotalRejectedCan   = dockMilkCollection.TotalRejectedCan;
            dockMilkCollectionDTO.Amount             = dockMilkCollection.Amount;
            dockMilkCollectionDTO.Commission         = dockMilkCollection.Commission;
            dockMilkCollectionDTO.TotalAmount        = dockMilkCollection.TotalAmount;
            dockMilkCollectionDTO.CreatedBy          = dockMilkCollection.CreatedBy;
            dockMilkCollectionDTO.CreatedDate        = dockMilkCollection.CreatedDate;
            dockMilkCollectionDTO.Comments           = dockMilkCollection.Comments;
            dockMilkCollectionDTO.IsDeleted          = dockMilkCollection.IsDeleted.GetValueOrDefault();
            dockMilkCollectionDTO.ModifiedBy         = dockMilkCollection.ModifiedBy;
            dockMilkCollectionDTO.ModifiedDate       = dockMilkCollection.ModifiedDate.GetValueOrDefault();
            dockMilkCollectionDTO.BillNumber         = dockMilkCollection.BillNumber;

            if (dockMilkCollection.DockMilkCollectionDtls != null && dockMilkCollection.DockMilkCollectionDtls.Count() > 0)
            {
                dockMilkCollectionDTO.dockMilkCollectionList = new List <DockMilkCollectionDtlDTO>();
                foreach (DockMilkCollectionDtl dockMilkCollectionDtl in dockMilkCollection.DockMilkCollectionDtls)
                {
                    dockMilkCollectionDTO.dockMilkCollectionList.Add(ConvertToDockMilkCollectionDtlDTO(dockMilkCollectionDtl));
                }
            }
            return(dockMilkCollectionDTO);
        }
Ejemplo n.º 4
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");
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
 public static void ConvertToDockMilkCollectionEntity(ref DockMilkCollection DockMilkCollection, DockMilkCollectionDTO DockMilkCollectionDTO, bool isUpdate)
 {
     if (isUpdate)
     {
         DockMilkCollection.DockMilkCollectionId = DockMilkCollectionDTO.DockMilkCollectionId;
     }
     DockMilkCollection.VLCId = DockMilkCollectionDTO.VLCId;
     if (DockMilkCollectionDTO.ShiftId > 0)
     {
         DockMilkCollection.ShiftId = (int)DockMilkCollectionDTO.ShiftId;
     }
     if (string.IsNullOrWhiteSpace(DockMilkCollectionDTO.Comments) == false)
     {
         DockMilkCollection.Comments = DockMilkCollectionDTO.Comments;
     }
     if (string.IsNullOrWhiteSpace(DockMilkCollectionDTO.ReceiverName) == false)
     {
         DockMilkCollection.ReceiverName = DockMilkCollectionDTO.ReceiverName;
     }
 }