예제 #1
0
        public static string UpdateDCAPercentage()
        {
            IList<DcaMaterialAllocationDTO> listAllMaterial = ESalesUnityContainer.Container.Resolve<IDcaMaterialAllocationService>()
                        .GetAllMaterialAllocationDetails(0, DateTime.Now.Date);
            if (listAllMaterial.Count == 0)
            {
                UpdatePreviousDayaActualPercenatge();
                try
                {
                    IList<DcaMaterialAllocationDTO> listMaterialAllocations = new List<DcaMaterialAllocationDTO>();

                    IList<MaterialTypeDTO> lstMaterialTypeDTO = ESalesUnityContainer.Container.Resolve<IMaterialTypeService>().GetMaterialTypeList(true);
                    foreach (MaterialTypeDTO Material in lstMaterialTypeDTO)
                    {
                        IList<AgentDTO> lstAgentDTO = ESalesUnityContainer.Container.Resolve<IAgentService>().GetAgentList();

                        if (lstAgentDTO.Count > 0)
                        {
                            foreach (AgentDTO item in lstAgentDTO)
                            {

                                DcaMaterialAllocationDTO DCAMaterialAllocation = new DcaMaterialAllocationDTO();

                                DCAMaterialAllocation.DCAMA_Date = System.DateTime.Now.Date.AddDays(0);
                                DCAMaterialAllocation.DCAMA_Agent_Id = item.Agent_Id;
                                DCAMaterialAllocation.DCAMA_MaterialType_Id = Material.MaterialType_Id;

                                IList<AgentMaterialPercentageDTO> lstAgentMaterialPercentageDTO = ESalesUnityContainer.Container
                                  .Resolve<IAgentMaterialPercentageService>().GetAgentMaterialPercentByAgentId(item.Agent_Id);

                                IList<DcaMaterialAllocationDTO> listMaterial = ESalesUnityContainer.Container.Resolve<IDcaMaterialAllocationService>()
                                .GetAllMaterialAllocationDetails(Material.MaterialType_Id, DateTime.Now.Date.AddDays(-1));

                                DCAMaterialAllocation.DCAMA_TodayPercentage = (from F in lstAgentMaterialPercentageDTO
                                                                               where F.AMP_MaterialType_Id == Material.MaterialType_Id
                                                                               select F.AMP_Percentage).FirstOrDefault()
                                                                                +
                                                                                (from F in listMaterial
                                                                                 where F.DCAMA_Agent_Id == item.Agent_Id
                                                                                 select F.DCAMA_ActualVariance).FirstOrDefault()
                                                                                ;
                                DCAMaterialAllocation.DCAMA_CreatedDate = DateTime.Now;
                                DCAMaterialAllocation.DCAMA_LastUpdatedDate = DateTime.Now;
                                listMaterialAllocations.Add(DCAMaterialAllocation);
                            }
                        }
                    }

                    ESalesUnityContainer.Container.Resolve<IDcaMaterialAllocationService>()
                                        .SaveAndUpdateDCAMaterialDetails(listMaterialAllocations);
                }

                catch (Exception ex)
                {

                }
                return "Updation Compleated";
            }
            else
            {
                return "Updation Not Compleated";
            }
        }
예제 #2
0
        private void UpdateDCADailyPercentage()
        {
            IList<DcaMaterialAllocationDTO> lstMaterialAllocations = new List<DcaMaterialAllocationDTO>();

            IList<MaterialTypeDTO> lstMaterialType = ESalesUnityContainer.Container.Resolve<IMaterialTypeService>()
                .GetMaterialTypeList(true);

            foreach (MaterialTypeDTO material in lstMaterialType)
            {
                IList<AgentDTO> lstAgent = ESalesUnityContainer.Container.Resolve<IAgentService>().GetAgentList();
                if (lstAgent.Count > 0)
                {
                    foreach (AgentDTO item in lstAgent)
                    {
                        DcaMaterialAllocationDTO DCAMaterialAllocation = new DcaMaterialAllocationDTO();

                        DCAMaterialAllocation.DCAMA_Date = System.DateTime.Now.Date.AddDays(0);
                        DCAMaterialAllocation.DCAMA_Agent_Id = item.Agent_Id;
                        DCAMaterialAllocation.DCAMA_MaterialType_Id = material.MaterialType_Id;

                        IList<AgentMaterialPercentageDTO> lstAgentMaterialPercentageDTO = ESalesUnityContainer.Container
                          .Resolve<IAgentMaterialPercentageService>().GetAgentMaterialPercentByAgentId(item.Agent_Id);

                        IList<DcaMaterialAllocationDTO> listMaterial = ESalesUnityContainer.Container.Resolve<IDcaMaterialAllocationService>()
                        .GetMaterialAllocationDetails(material.MaterialType_Id, DateTime.Now.Date.AddDays(-1));
                        DCAMaterialAllocation.DCAMA_TodayPercentage = (from F in lstAgentMaterialPercentageDTO
                                                                        where F.AMP_MaterialType_Id == material.MaterialType_Id
                                                                        select F.AMP_Percentage).FirstOrDefault()
                                                                        +
                                                                        (from F in listMaterial
                                                                         where F.DCAMA_Agent_Id == item.Agent_Id
                                                                         select F.DCAMA_CurrentVariance).FirstOrDefault()
                                                                        ;
                        lstMaterialAllocations.Add(DCAMaterialAllocation);
                    }
                }
            }

            ESalesUnityContainer.Container.Resolve<IDcaMaterialAllocationService>()
                                .SaveAndUpdateDCAMaterialDetails(lstMaterialAllocations);
        }